cyberosa commited on
Commit
79bdafd
·
1 Parent(s): 4fd6aee

updating data and graphs

Browse files
app.py CHANGED
@@ -13,6 +13,7 @@ from tabs.dist_gap import (
13
  get_distribution_plot,
14
  get_correlation_map,
15
  get_kde_with_trades,
 
16
  )
17
 
18
 
@@ -130,7 +131,15 @@ with demo:
130
  kde_trades_plot = get_kde_with_trades(markets_data)
131
 
132
  with gr.Row():
133
- gr.Markdown("# Correlation analysis between variables")
 
 
 
 
 
 
 
 
134
 
135
  with gr.Row():
136
  correlation_plot = get_correlation_map(markets_data)
 
13
  get_distribution_plot,
14
  get_correlation_map,
15
  get_kde_with_trades,
16
+ get_regplot_with_mean_trade_size,
17
  )
18
 
19
 
 
131
  kde_trades_plot = get_kde_with_trades(markets_data)
132
 
133
  with gr.Row():
134
+ gr.Markdown("# Relationship with mean trade size")
135
+
136
+ with gr.Row():
137
+ reg_plot = get_regplot_with_mean_trade_size(markets_data)
138
+
139
+ with gr.Row():
140
+ gr.Markdown(
141
+ "# Correlation analysis between the metric and market variables"
142
+ )
143
 
144
  with gr.Row():
145
  correlation_plot = get_correlation_map(markets_data)
live_data/markets_live_data.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9f1aefc2dd441883aca8a95db7715a511b763a5b486307a903dcea30df7ef828
3
- size 27422
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e0451385c1de2891fe1ab7fff8b3e5a5f797f351b2ca799266e65adec57a9b9
3
+ size 34357
live_data/markets_live_data_sample.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e601332794f53f1c65384434aa7bbcad617853f3aa7f89eeb68640f36edc7b14
3
- size 22201
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8592b33790b8209ebd8de3ac3108e76f25a3e02fc5720dc0a8984fe47e09cad1
3
+ size 27990
notebooks/analysis_of_markets_data.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/market_trades.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7466aaeee89b4eb10c8b3902231126fc480c8829e792071784b7b38be56a9208
3
+ size 20405
scripts/live_markets_data.py CHANGED
@@ -231,6 +231,7 @@ def transform_fpmms(fpmms: pd.DataFrame, filename: str, current_timestamp: int)
231
  # computation of token distributions
232
  fpmms["token_first_amount"] = fpmms.outcomeTokenAmounts.apply(lambda x: int(x[0]))
233
  fpmms["token_second_amount"] = fpmms.outcomeTokenAmounts.apply(lambda x: int(x[1]))
 
234
  fpmms["total_tokens"] = fpmms.apply(
235
  lambda x: x.token_first_amount + x.token_second_amount, axis=1
236
  )
 
231
  # computation of token distributions
232
  fpmms["token_first_amount"] = fpmms.outcomeTokenAmounts.apply(lambda x: int(x[0]))
233
  fpmms["token_second_amount"] = fpmms.outcomeTokenAmounts.apply(lambda x: int(x[1]))
234
+ fpmms["liquidityMeasure"] = fpmms["liquidityMeasure"].apply(lambda x: int(x))
235
  fpmms["total_tokens"] = fpmms.apply(
236
  lambda x: x.token_first_amount + x.token_second_amount, axis=1
237
  )
scripts/live_traders_data.py CHANGED
@@ -12,8 +12,9 @@ from utils import (
12
  )
13
  from utils import SUBGRAPH_API_KEY, _to_content
14
  from queries import omen_trader_votes_query
 
15
 
16
- logger = logging.getLogger(__name__)
17
 
18
  headers = {
19
  "Accept": "application/json, multipart/mixed",
@@ -90,25 +91,6 @@ def transform_trades(trades_json: dict) -> pd.DataFrame:
90
  return df
91
 
92
 
93
- def compute_from_timestamp_value(
94
- fpmm_id: str, opening_timestamp: int, fpmms: pd.DataFrame
95
- ) -> Optional[int]:
96
- """Function to find the latest timestamp registered for a specific market"""
97
- try:
98
- market_data = fpmms.loc[fpmms["id"] == fpmm_id]
99
- # how many previous samples do we have?
100
- if len(market_data) == 1:
101
- # take the opening Timestamp of the Market
102
- return opening_timestamp
103
- timestamps = (market_data.tokens_timestamp.values).sort()
104
- # the last value is the current timestamp so we need to take the previous one
105
- return timestamps[-2]
106
- except Exception as e:
107
- logger.error(
108
- f"Error when trying to get the from timestamp value of the market id {fpmm_id}"
109
- )
110
- return None
111
-
112
 
113
  def compute_votes_distribution(market_trades: pd.DataFrame):
114
  """Function to compute the distribution of votes for the trades of a market"""
@@ -129,8 +111,8 @@ def add_trading_info(fpmms: pd.DataFrame, current_timestamp: int) -> None:
129
  # Iterate over the markets
130
  for i, fpmm in tqdm(fpmms.iterrows(), total=len(fpmms), desc="Analysing trades"):
131
  # update the trades for this market and at this specific current_timestamp
132
- logger.debug(f"current timestamp = {current_timestamp} and market timestamp={fpmm["tokens_timestamp"]}")
133
- to_update = fpmm["open"] and fpmm["tokens_timestamp"] == current_timestamp
134
  if not to_update: # jump closed markets or old data
135
  logger.debug("Jumping this row")
136
  continue
@@ -141,12 +123,18 @@ def add_trading_info(fpmms: pd.DataFrame, current_timestamp: int) -> None:
141
  fpmm_id=market_id,
142
  )
143
  market_trades = transform_trades(market_trades_json)
144
- if len(market_trades) == 0:
145
- logger.info("No trades for this market")
146
- continue
147
-
148
  fpmms.at[i,"total_trades"] = len(market_trades)
149
- first_outcome, second_outcome = compute_votes_distribution(market_trades)
 
 
 
 
 
 
 
 
 
 
150
  logger.info(
151
  f"first outcome votes ={first_outcome}, second outcome votes = {second_outcome}"
152
  )
 
12
  )
13
  from utils import SUBGRAPH_API_KEY, _to_content
14
  from queries import omen_trader_votes_query
15
+ from live_markets_data import logger
16
 
17
+ #logger = logging.getLogger(__name__)
18
 
19
  headers = {
20
  "Accept": "application/json, multipart/mixed",
 
91
  return df
92
 
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  def compute_votes_distribution(market_trades: pd.DataFrame):
96
  """Function to compute the distribution of votes for the trades of a market"""
 
111
  # Iterate over the markets
112
  for i, fpmm in tqdm(fpmms.iterrows(), total=len(fpmms), desc="Analysing trades"):
113
  # update the trades for this market and at this specific current_timestamp
114
+ logger.debug(f"current timestamp = {current_timestamp} and market timestamp={fpmm["sample_timestamp"]}")
115
+ to_update = fpmm["open"] and fpmm["sample_timestamp"] == current_timestamp
116
  if not to_update: # jump closed markets or old data
117
  logger.debug("Jumping this row")
118
  continue
 
123
  fpmm_id=market_id,
124
  )
125
  market_trades = transform_trades(market_trades_json)
 
 
 
 
126
  fpmms.at[i,"total_trades"] = len(market_trades)
127
+
128
+ if len(market_trades) > 0:
129
+ # adding average trade size
130
+ market_trades["collateralAmountUSD"] = market_trades.collateralAmountUSD.apply(lambda x: round(float(x),3))
131
+ mean_trade_size = market_trades.collateralAmountUSD.mean()
132
+ first_outcome, second_outcome = compute_votes_distribution(market_trades)
133
+ else:
134
+ logger.info("No trades for this market")
135
+ mean_trade_size = 0.0
136
+ first_outcome, second_outcome = 50.0, 50.0
137
+ fpmms.at[i,"mean_trade_size"] = mean_trade_size
138
  logger.info(
139
  f"first outcome votes ={first_outcome}, second outcome votes = {second_outcome}"
140
  )
tabs/dist_gap.py CHANGED
@@ -36,18 +36,27 @@ def get_kde_with_trades(markets_data: pd.DataFrame):
36
  return gr.Plot(value=plot.get_figure())
37
 
38
 
 
 
 
 
 
 
 
39
  def get_correlation_map(markets_data: pd.DataFrame):
40
  """Function to paint the correlation between different variables"""
41
 
42
- columns_of_interest = ["total_trades", "dist_gap_perc", "days_to_resolution"]
 
 
 
 
 
43
  data = markets_data[columns_of_interest]
44
 
45
  # Compute the correlation matrix
46
  correlation_matrix = data.corr()
47
 
48
- # Create a figure and axis
49
- # plt.figure(figsize=(10, 8))
50
-
51
  # Create the heatmap
52
  heatmap = sns.heatmap(
53
  correlation_matrix,
 
36
  return gr.Plot(value=plot.get_figure())
37
 
38
 
39
+ def get_regplot_with_mean_trade_size(markets_data: pd.DataFrame):
40
+ """Function to Plot data and a linear regression model fit"""
41
+ regplot = sns.regplot(live_fpmms, x="dist_gap_perc", y="mean_trade_size")
42
+ plt.ylabel("Mean trade size in USD")
43
+ return gr.Plot(value=regplot.get_figure())
44
+
45
+
46
  def get_correlation_map(markets_data: pd.DataFrame):
47
  """Function to paint the correlation between different variables"""
48
 
49
+ columns_of_interest = [
50
+ "total_trades",
51
+ "dist_gap_perc",
52
+ "liquidityMeasure",
53
+ "mean_trade_size",
54
+ ]
55
  data = markets_data[columns_of_interest]
56
 
57
  # Compute the correlation matrix
58
  correlation_matrix = data.corr()
59
 
 
 
 
60
  # Create the heatmap
61
  heatmap = sns.heatmap(
62
  correlation_matrix,