cyberosa
commited on
Commit
·
309bf92
1
Parent(s):
e6a431c
adding new column and new dist gap graph
Browse files- app.py +9 -12
- live_data/markets_live_data.parquet +2 -2
- scripts/live_markets_data.py +0 -2
- scripts/live_traders_data.py +29 -17
- scripts/queries.py +1 -1
- tabs/dist_gap.py +9 -2
app.py
CHANGED
@@ -11,6 +11,7 @@ from tabs.dist_gap import (
|
|
11 |
get_distribution_plot,
|
12 |
get_correlation_map,
|
13 |
get_kde_with_trades,
|
|
|
14 |
get_dist_gap_time_evolution,
|
15 |
)
|
16 |
|
@@ -123,18 +124,14 @@ with demo:
|
|
123 |
kde_plot = get_distribution_plot(markets_data)
|
124 |
|
125 |
with gr.Row():
|
126 |
-
gr.
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
# )
|
135 |
-
|
136 |
-
# with gr.Row():
|
137 |
-
# reg_plot = get_regplot_with_mean_trade_size(markets_data)
|
138 |
|
139 |
with gr.Row():
|
140 |
gr.Markdown(
|
|
|
11 |
get_distribution_plot,
|
12 |
get_correlation_map,
|
13 |
get_kde_with_trades,
|
14 |
+
get_kde_with_total_bet_amount,
|
15 |
get_dist_gap_time_evolution,
|
16 |
)
|
17 |
|
|
|
124 |
kde_plot = get_distribution_plot(markets_data)
|
125 |
|
126 |
with gr.Row():
|
127 |
+
with gr.Column(min_width=350):
|
128 |
+
gr.Markdown("# Relationship with number of trades")
|
129 |
+
kde_trades_plot = get_kde_with_trades(markets_data)
|
130 |
+
with gr.Column(min_width=350):
|
131 |
+
gr.Markdown("# Relationship with total bet amount")
|
132 |
+
kde_total_bet_amount_plot = get_kde_with_total_bet_amount(
|
133 |
+
markets_data
|
134 |
+
)
|
|
|
|
|
|
|
|
|
135 |
|
136 |
with gr.Row():
|
137 |
gr.Markdown(
|
live_data/markets_live_data.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e254bb09afa15f82a81192c5063d26e420b32d93f9ffb56a65afd4d9d28a27eb
|
3 |
+
size 30562
|
scripts/live_markets_data.py
CHANGED
@@ -233,8 +233,6 @@ def transform_fpmms(fpmms: pd.DataFrame, filename: str, current_timestamp: int)
|
|
233 |
fpmms["open"] = True
|
234 |
fpmms["total_trades"] = 0
|
235 |
fpmms["dist_gap_perc"] = 0.0
|
236 |
-
fpmms["votes_first_outcome_perc"] = 0.0
|
237 |
-
fpmms["votes_second_outcome_perc"] = 0.0
|
238 |
fpmms["first_outcome"] = fpmms.question.apply(lambda x: x["outcomes"][0])
|
239 |
fpmms["second_outcome"] = fpmms.question.apply(lambda x: x["outcomes"][1])
|
240 |
# computation of token distributions
|
|
|
233 |
fpmms["open"] = True
|
234 |
fpmms["total_trades"] = 0
|
235 |
fpmms["dist_gap_perc"] = 0.0
|
|
|
|
|
236 |
fpmms["first_outcome"] = fpmms.question.apply(lambda x: x["outcomes"][0])
|
237 |
fpmms["second_outcome"] = fpmms.question.apply(lambda x: x["outcomes"][1])
|
238 |
# computation of token distributions
|
scripts/live_traders_data.py
CHANGED
@@ -2,7 +2,7 @@ import requests
|
|
2 |
import logging
|
3 |
import pandas as pd
|
4 |
from collections import defaultdict
|
5 |
-
from typing import Any, Optional
|
6 |
from tqdm import tqdm
|
7 |
from utils import (
|
8 |
OMEN_SUBGRAPH_URL,
|
@@ -11,7 +11,7 @@ from utils import (
|
|
11 |
DATA_DIR,
|
12 |
)
|
13 |
from utils import SUBGRAPH_API_KEY, _to_content
|
14 |
-
from queries import
|
15 |
|
16 |
|
17 |
|
@@ -31,7 +31,7 @@ def _query_omen_xdai_subgraph(
|
|
31 |
id_gt = ""
|
32 |
|
33 |
while True:
|
34 |
-
query =
|
35 |
fpmm_creator=CREATOR.lower(),
|
36 |
first=BATCH_SIZE,
|
37 |
id_gt=id_gt,
|
@@ -102,16 +102,17 @@ def compute_votes_distribution(market_trades: pd.DataFrame, logger):
|
|
102 |
percentage_index_1 = round((sum_outcome_index_1 / total_trades) * 100, 2)
|
103 |
return (100 - percentage_index_1), percentage_index_1
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
-
def compute_price_weighted_perc(
|
107 |
"""It computes the price weighted distribution with the percentages of each outcome"""
|
108 |
logger.info("Computing the price weighted distribution")
|
109 |
-
# trades for outcome 0
|
110 |
-
trades_outcome_0 = market_trades.loc[market_trades["outcomeIndex"]==0]
|
111 |
-
logger.debug(f"Total trades for outcome 0 = {len(trades_outcome_0)}")
|
112 |
-
# trades for outcome 1
|
113 |
-
trades_outcome_1 = market_trades.loc[market_trades["outcomeIndex"]==1]
|
114 |
-
logger.debug(f"Total trades for outcome 1 = {len(trades_outcome_1)}")
|
115 |
total_usd_outcome_0 = sum(trades_outcome_0.collateralAmountUSD)
|
116 |
total_usd_outcome_1 = sum(trades_outcome_1.collateralAmountUSD)
|
117 |
total_usd = total_usd_outcome_0 + total_usd_outcome_1
|
@@ -123,7 +124,7 @@ def compute_price_weighted_perc(market_trades: pd.DataFrame, logger):
|
|
123 |
def add_trading_info(fpmms: pd.DataFrame, current_timestamp: int, logger) -> None:
|
124 |
"""Function to update only the information related with the current timestamp"""
|
125 |
|
126 |
-
logger.info("Adding
|
127 |
fpmms["liquidityMeasure"] = fpmms["liquidityMeasure"].apply(lambda x: int(x))
|
128 |
# Iterate over the markets
|
129 |
for i, fpmm in tqdm(fpmms.iterrows(), total=len(fpmms), desc="Analysing trades"):
|
@@ -145,14 +146,25 @@ def add_trading_info(fpmms: pd.DataFrame, current_timestamp: int, logger) -> Non
|
|
145 |
if len(market_trades) > 0:
|
146 |
# adding average trade size
|
147 |
market_trades["collateralAmountUSD"] = market_trades.collateralAmountUSD.apply(lambda x: round(float(x),3))
|
|
|
148 |
mean_trade_size = market_trades.collateralAmountUSD.mean()
|
149 |
total_bet_amount = sum(market_trades.collateralAmountUSD)
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
else:
|
152 |
logger.info("No trades for this market")
|
153 |
-
mean_trade_size = 0.0
|
154 |
-
|
155 |
-
first_outcome
|
|
|
156 |
fpmms.at[i,"mean_trade_size"] = mean_trade_size
|
157 |
fpmms.at[i,"total_bet_amount"] = total_bet_amount
|
158 |
logger.info(
|
@@ -160,8 +172,8 @@ def add_trading_info(fpmms: pd.DataFrame, current_timestamp: int, logger) -> Non
|
|
160 |
)
|
161 |
fpmms.at[i,"price_weighted_first_outcome_perc"] = first_outcome
|
162 |
fpmms.at[i,"price_weighted_second_outcome_perc"] = second_outcome
|
163 |
-
|
164 |
-
|
165 |
fpmms.at[i,"dist_gap_perc"] = metric
|
166 |
logger.debug("Dataset after adding trading info")
|
167 |
logger.debug(fpmms.head())
|
|
|
2 |
import logging
|
3 |
import pandas as pd
|
4 |
from collections import defaultdict
|
5 |
+
from typing import Any, Optional, Tuple
|
6 |
from tqdm import tqdm
|
7 |
from utils import (
|
8 |
OMEN_SUBGRAPH_URL,
|
|
|
11 |
DATA_DIR,
|
12 |
)
|
13 |
from utils import SUBGRAPH_API_KEY, _to_content
|
14 |
+
from queries import omen_market_trades_query
|
15 |
|
16 |
|
17 |
|
|
|
31 |
id_gt = ""
|
32 |
|
33 |
while True:
|
34 |
+
query = omen_market_trades_query.substitute(
|
35 |
fpmm_creator=CREATOR.lower(),
|
36 |
first=BATCH_SIZE,
|
37 |
id_gt=id_gt,
|
|
|
102 |
percentage_index_1 = round((sum_outcome_index_1 / total_trades) * 100, 2)
|
103 |
return (100 - percentage_index_1), percentage_index_1
|
104 |
|
105 |
+
def compute_bought_tokens_distribution(trades_outcome_0: pd.DataFrame, trades_outcome_1: pd.DataFrame) -> Tuple:
|
106 |
+
"""Function to compute the distribution of bought tokens from the trades on each outcome """
|
107 |
+
total_tokens_outcome_0 = sum(trades_outcome_0.outcomeTokensTraded)
|
108 |
+
total_tokens_outcome_1 = sum(trades_outcome_1.outcomeTokensTraded)
|
109 |
+
total_bought_tokens = total_tokens_outcome_0 + total_tokens_outcome_1
|
110 |
+
percentage_bought_outcome_0 = round((total_tokens_outcome_0/total_bought_tokens)*100, 2)
|
111 |
+
return percentage_bought_outcome_0, 100 - percentage_bought_outcome_0
|
112 |
|
113 |
+
def compute_price_weighted_perc(trades_outcome_0: pd.DataFrame, trades_outcome_1: pd.DataFrame, logger) -> Tuple:
|
114 |
"""It computes the price weighted distribution with the percentages of each outcome"""
|
115 |
logger.info("Computing the price weighted distribution")
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
total_usd_outcome_0 = sum(trades_outcome_0.collateralAmountUSD)
|
117 |
total_usd_outcome_1 = sum(trades_outcome_1.collateralAmountUSD)
|
118 |
total_usd = total_usd_outcome_0 + total_usd_outcome_1
|
|
|
124 |
def add_trading_info(fpmms: pd.DataFrame, current_timestamp: int, logger) -> None:
|
125 |
"""Function to update only the information related with the current timestamp"""
|
126 |
|
127 |
+
logger.info("Adding price weighted distribution per market")
|
128 |
fpmms["liquidityMeasure"] = fpmms["liquidityMeasure"].apply(lambda x: int(x))
|
129 |
# Iterate over the markets
|
130 |
for i, fpmm in tqdm(fpmms.iterrows(), total=len(fpmms), desc="Analysing trades"):
|
|
|
146 |
if len(market_trades) > 0:
|
147 |
# adding average trade size
|
148 |
market_trades["collateralAmountUSD"] = market_trades.collateralAmountUSD.apply(lambda x: round(float(x),3))
|
149 |
+
market_trades["outcomeTokensTraded"] = market_trades.outcomeTokensTraded.apply(lambda x: int(x))
|
150 |
mean_trade_size = market_trades.collateralAmountUSD.mean()
|
151 |
total_bet_amount = sum(market_trades.collateralAmountUSD)
|
152 |
+
# trades for outcome 0
|
153 |
+
trades_outcome_0 = market_trades.loc[market_trades["outcomeIndex"]==0]
|
154 |
+
logger.debug(f"Total trades for outcome 0 = {len(trades_outcome_0)}")
|
155 |
+
# trades for outcome 1
|
156 |
+
trades_outcome_1 = market_trades.loc[market_trades["outcomeIndex"]==1]
|
157 |
+
logger.debug(f"Total trades for outcome 1 = {len(trades_outcome_1)}")
|
158 |
+
first_outcome, second_outcome = compute_price_weighted_perc(trades_outcome_0, trades_outcome_1, logger)
|
159 |
+
bought_tokens_first, bought_tokens_second = compute_bought_tokens_distribution(trades_outcome_0, trades_outcome_1)
|
160 |
+
metric = abs(fpmm["first_token_perc"] - first_outcome)
|
161 |
+
logger.info(f"metric for this market {metric}")
|
162 |
else:
|
163 |
logger.info("No trades for this market")
|
164 |
+
mean_trade_size = total_bet_amount = 0.0
|
165 |
+
bought_tokens_first = bought_tokens_second = 0.0
|
166 |
+
first_outcome = second_outcome = 0.0
|
167 |
+
metric = 0.0
|
168 |
fpmms.at[i,"mean_trade_size"] = mean_trade_size
|
169 |
fpmms.at[i,"total_bet_amount"] = total_bet_amount
|
170 |
logger.info(
|
|
|
172 |
)
|
173 |
fpmms.at[i,"price_weighted_first_outcome_perc"] = first_outcome
|
174 |
fpmms.at[i,"price_weighted_second_outcome_perc"] = second_outcome
|
175 |
+
fpmms.at[i,"bought_tokens_first_perc"] = bought_tokens_first
|
176 |
+
fpmms.at[i,"bought_tokens_second_perc"] = bought_tokens_second
|
177 |
fpmms.at[i,"dist_gap_perc"] = metric
|
178 |
logger.debug("Dataset after adding trading info")
|
179 |
logger.debug(fpmms.head())
|
scripts/queries.py
CHANGED
@@ -72,7 +72,7 @@ FPMMS_WITH_TOKENS_QUERY = Template(
|
|
72 |
)
|
73 |
|
74 |
|
75 |
-
|
76 |
"""
|
77 |
{
|
78 |
fpmmTrades(
|
|
|
72 |
)
|
73 |
|
74 |
|
75 |
+
omen_market_trades_query = Template(
|
76 |
"""
|
77 |
{
|
78 |
fpmmTrades(
|
tabs/dist_gap.py
CHANGED
@@ -5,8 +5,8 @@ import seaborn as sns
|
|
5 |
from seaborn import FacetGrid
|
6 |
import plotly.express as px
|
7 |
|
8 |
-
HEIGHT =
|
9 |
-
WIDTH =
|
10 |
|
11 |
|
12 |
def get_dist_gap_time_evolution(market_id: str, all_markets: pd.DataFrame):
|
@@ -64,6 +64,13 @@ def get_kde_with_trades(markets_data: pd.DataFrame):
|
|
64 |
return gr.Plot(value=plot.get_figure())
|
65 |
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
def get_regplot_with_mean_trade_size(markets_data: pd.DataFrame):
|
68 |
"""Function to Plot data and a linear regression model fit between the metric and the mean trade size"""
|
69 |
regplot = sns.regplot(markets_data, x="dist_gap_perc", y="mean_trade_size")
|
|
|
5 |
from seaborn import FacetGrid
|
6 |
import plotly.express as px
|
7 |
|
8 |
+
HEIGHT = 300
|
9 |
+
WIDTH = 600
|
10 |
|
11 |
|
12 |
def get_dist_gap_time_evolution(market_id: str, all_markets: pd.DataFrame):
|
|
|
64 |
return gr.Plot(value=plot.get_figure())
|
65 |
|
66 |
|
67 |
+
def get_kde_with_total_bet_amount(markets_data: pd.DataFrame):
|
68 |
+
"""Function to paint the density plot of the metric in terms of the total bet amount"""
|
69 |
+
plot = sns.kdeplot(markets_data, x="dist_gap_perc", y="total_bet_amount", fill=True)
|
70 |
+
plt.ylabel("Total bet amount per market")
|
71 |
+
return gr.Plot(value=plot.get_figure())
|
72 |
+
|
73 |
+
|
74 |
def get_regplot_with_mean_trade_size(markets_data: pd.DataFrame):
|
75 |
"""Function to Plot data and a linear regression model fit between the metric and the mean trade size"""
|
76 |
regplot = sns.regplot(markets_data, x="dist_gap_perc", y="mean_trade_size")
|