rosacastillo
commited on
Commit
·
ac8ae1f
1
Parent(s):
887436d
updating all files except the tools big file
Browse files- app.py +16 -14
- data/all_trades_profitability.parquet +2 -2
- data/daily_info.parquet +2 -2
- data/invalid_trades.parquet +2 -2
- data/service_map.pkl +2 -2
- data/summary_profitability.parquet +2 -2
- data/tools_accuracy.csv +2 -2
- scripts/__init__.py +0 -0
- scripts/profitability.py +10 -8
- scripts/pull_data.py +1 -1
- scripts/staking.py +6 -2
- scripts/web3_utils.py +9 -1
- tabs/metrics.py +4 -4
- tabs/staking.py +16 -5
- tabs/trades.py +22 -70
app.py
CHANGED
@@ -201,20 +201,20 @@ with demo:
|
|
201 |
with gr.Row():
|
202 |
with gr.Column(scale=1):
|
203 |
gr.Markdown(
|
204 |
-
"# Weekly percentage of winning for
|
205 |
)
|
206 |
-
|
207 |
integrated_plot_winning_trades_per_market_by_week_v2(
|
208 |
-
trades_df=trades_df, trader_filter="
|
209 |
)
|
210 |
)
|
211 |
with gr.Column(scale=1):
|
212 |
gr.Markdown(
|
213 |
-
"# Weekly percentage of winning for
|
214 |
)
|
215 |
-
|
216 |
integrated_plot_winning_trades_per_market_by_week_v2(
|
217 |
-
trades_df=trades_df, trader_filter="
|
218 |
)
|
219 |
)
|
220 |
|
@@ -251,7 +251,9 @@ with demo:
|
|
251 |
|
252 |
# Agentic traders graph
|
253 |
with gr.Row():
|
254 |
-
gr.Markdown(
|
|
|
|
|
255 |
with gr.Row():
|
256 |
trade_a_details_selector = gr.Dropdown(
|
257 |
label="Select a trade metric",
|
@@ -273,7 +275,7 @@ with demo:
|
|
273 |
new_a_plot = plot_trade_metrics(
|
274 |
metric_name=trade_detail,
|
275 |
trades_df=trades_df,
|
276 |
-
trader_filter="
|
277 |
)
|
278 |
return new_a_plot
|
279 |
|
@@ -283,10 +285,10 @@ with demo:
|
|
283 |
outputs=[a_trade_details_plot],
|
284 |
)
|
285 |
|
286 |
-
# Non-
|
287 |
with gr.Row():
|
288 |
gr.Markdown(
|
289 |
-
"# Weekly trading metrics for trades coming from Non-
|
290 |
)
|
291 |
with gr.Row():
|
292 |
trade_na_details_selector = gr.Dropdown(
|
@@ -300,7 +302,7 @@ with demo:
|
|
300 |
na_trade_details_plot = plot_trade_metrics(
|
301 |
metric_name=default_trade_metric,
|
302 |
trades_df=trades_df,
|
303 |
-
trader_filter="
|
304 |
)
|
305 |
with gr.Column(scale=1):
|
306 |
trade_details_text = get_trade_metrics_text()
|
@@ -309,7 +311,7 @@ with demo:
|
|
309 |
new_a_plot = plot_trade_metrics(
|
310 |
metric_name=trade_detail,
|
311 |
trades_df=trades_df,
|
312 |
-
trader_filter="
|
313 |
)
|
314 |
return new_a_plot
|
315 |
|
@@ -323,13 +325,13 @@ with demo:
|
|
323 |
with gr.Row():
|
324 |
gr.Markdown("# Trades conducted at the Pearl markets")
|
325 |
with gr.Row():
|
326 |
-
|
327 |
trades_df=trades_df, market_creator="pearl"
|
328 |
)
|
329 |
with gr.Row():
|
330 |
gr.Markdown("# Trades conducted at the Quickstart markets")
|
331 |
with gr.Row():
|
332 |
-
|
333 |
trades_df=trades_df, market_creator="quickstart"
|
334 |
)
|
335 |
with gr.Row():
|
|
|
201 |
with gr.Row():
|
202 |
with gr.Column(scale=1):
|
203 |
gr.Markdown(
|
204 |
+
"# Weekly percentage of winning for trades based on 🌊 Olas traders"
|
205 |
)
|
206 |
+
olas_winning_trades = (
|
207 |
integrated_plot_winning_trades_per_market_by_week_v2(
|
208 |
+
trades_df=trades_df, trader_filter="Olas"
|
209 |
)
|
210 |
)
|
211 |
with gr.Column(scale=1):
|
212 |
gr.Markdown(
|
213 |
+
"# Weekly percentage of winning for trades based on non-Olas traders"
|
214 |
)
|
215 |
+
non_Olas_winning_trades = (
|
216 |
integrated_plot_winning_trades_per_market_by_week_v2(
|
217 |
+
trades_df=trades_df, trader_filter="non_Olas"
|
218 |
)
|
219 |
)
|
220 |
|
|
|
251 |
|
252 |
# Agentic traders graph
|
253 |
with gr.Row():
|
254 |
+
gr.Markdown(
|
255 |
+
"# Weekly trading metrics for trades coming from 🌊 Olas traders"
|
256 |
+
)
|
257 |
with gr.Row():
|
258 |
trade_a_details_selector = gr.Dropdown(
|
259 |
label="Select a trade metric",
|
|
|
275 |
new_a_plot = plot_trade_metrics(
|
276 |
metric_name=trade_detail,
|
277 |
trades_df=trades_df,
|
278 |
+
trader_filter="Olas",
|
279 |
)
|
280 |
return new_a_plot
|
281 |
|
|
|
285 |
outputs=[a_trade_details_plot],
|
286 |
)
|
287 |
|
288 |
+
# Non-Olasic traders graph
|
289 |
with gr.Row():
|
290 |
gr.Markdown(
|
291 |
+
"# Weekly trading metrics for trades coming from Non-Olas traders"
|
292 |
)
|
293 |
with gr.Row():
|
294 |
trade_na_details_selector = gr.Dropdown(
|
|
|
302 |
na_trade_details_plot = plot_trade_metrics(
|
303 |
metric_name=default_trade_metric,
|
304 |
trades_df=trades_df,
|
305 |
+
trader_filter="non_Olas",
|
306 |
)
|
307 |
with gr.Column(scale=1):
|
308 |
trade_details_text = get_trade_metrics_text()
|
|
|
311 |
new_a_plot = plot_trade_metrics(
|
312 |
metric_name=trade_detail,
|
313 |
trades_df=trades_df,
|
314 |
+
trader_filter="non_Olas",
|
315 |
)
|
316 |
return new_a_plot
|
317 |
|
|
|
325 |
with gr.Row():
|
326 |
gr.Markdown("# Trades conducted at the Pearl markets")
|
327 |
with gr.Row():
|
328 |
+
staking_pearl_trades_by_week = plot_staking_trades_per_market_by_week(
|
329 |
trades_df=trades_df, market_creator="pearl"
|
330 |
)
|
331 |
with gr.Row():
|
332 |
gr.Markdown("# Trades conducted at the Quickstart markets")
|
333 |
with gr.Row():
|
334 |
+
staking_qs_trades_by_week = plot_staking_trades_per_market_by_week(
|
335 |
trades_df=trades_df, market_creator="quickstart"
|
336 |
)
|
337 |
with gr.Row():
|
data/all_trades_profitability.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:9ff7a9001dceeac25cf151e9b8cff55beafe610387c42e093d004e2712206e6b
|
3 |
+
size 3884891
|
data/daily_info.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:d6d36bd873a5fe9564f556eda0210078a0e9c3d0dd81fec2158cf029ed462573
|
3 |
+
size 911119
|
data/invalid_trades.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:88697b4baf7652f32c3413f1fc168f534f2472281761fa4e5208751f1a0bae56
|
3 |
+
size 123705
|
data/service_map.pkl
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:574e816f13aee41f153346e0590bbaeb5115578faa6aa9129dbda8b49b4d7fd2
|
3 |
+
size 90733
|
data/summary_profitability.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:20a70aff0b89a48381a0cf73ffb65ae9a41002b81bec1dd1ded9e454b86e9245
|
3 |
+
size 112166
|
data/tools_accuracy.csv
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:5aa2346a2dba117d4285bcc997eae04b935b32d1290226d74a270c25db358fd0
|
3 |
+
size 1341
|
scripts/__init__.py
ADDED
File without changes
|
scripts/profitability.py
CHANGED
@@ -32,12 +32,7 @@ from get_mech_info import (
|
|
32 |
update_tools_parquet,
|
33 |
update_all_trades_parquet,
|
34 |
)
|
35 |
-
from utils import
|
36 |
-
wei_to_unit,
|
37 |
-
convert_hex_to_int,
|
38 |
-
JSON_DATA_DIR,
|
39 |
-
DATA_DIR,
|
40 |
-
)
|
41 |
from staking import label_trades_by_staking
|
42 |
|
43 |
DUST_THRESHOLD = 10000000000000
|
@@ -426,9 +421,16 @@ def run_profitability_analysis(
|
|
426 |
all_trades_df = update_all_trades_parquet(all_trades_df)
|
427 |
|
428 |
# debugging purposes
|
429 |
-
all_trades_df.to_parquet(JSON_DATA_DIR / "all_trades_df.parquet")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
430 |
|
431 |
-
# all_trades_df = pd.read_parquet(JSON_DATA_DIR / "all_trades_df.parquet")
|
432 |
# filter invalid markets. Condition: "is_invalid" is True
|
433 |
invalid_trades = all_trades_df.loc[all_trades_df["is_invalid"] == True]
|
434 |
if len(invalid_trades) == 0:
|
|
|
32 |
update_tools_parquet,
|
33 |
update_all_trades_parquet,
|
34 |
)
|
35 |
+
from utils import wei_to_unit, convert_hex_to_int, JSON_DATA_DIR, DATA_DIR, TMP_DIR
|
|
|
|
|
|
|
|
|
|
|
36 |
from staking import label_trades_by_staking
|
37 |
|
38 |
DUST_THRESHOLD = 10000000000000
|
|
|
421 |
all_trades_df = update_all_trades_parquet(all_trades_df)
|
422 |
|
423 |
# debugging purposes
|
424 |
+
all_trades_df.to_parquet(JSON_DATA_DIR / "all_trades_df.parquet", index=False)
|
425 |
+
|
426 |
+
# filter trades coming from non-Olas traders that are placing no mech calls
|
427 |
+
no_mech_calls_mask = (all_trades_df["staking"] == "non_Olas") & (
|
428 |
+
all_trades_df.loc["num_mech_calls"] == 0
|
429 |
+
)
|
430 |
+
no_mech_calls_df = all_trades_df.loc[no_mech_calls_mask]
|
431 |
+
no_mech_calls_df.to_parquet(TMP_DIR / "no_mech_calls_trades.parquet", index=False)
|
432 |
+
all_trades_df = all_trades_df.loc[~no_mech_calls_mask]
|
433 |
|
|
|
434 |
# filter invalid markets. Condition: "is_invalid" is True
|
435 |
invalid_trades = all_trades_df.loc[all_trades_df["is_invalid"] == True]
|
436 |
if len(invalid_trades) == 0:
|
scripts/pull_data.py
CHANGED
@@ -80,7 +80,7 @@ def only_new_weekly_analysis():
|
|
80 |
rpc = RPC
|
81 |
# Run markets ETL
|
82 |
logging.info("Running markets ETL")
|
83 |
-
mkt_etl(MARKETS_FILENAME)
|
84 |
logging.info("Markets ETL completed")
|
85 |
|
86 |
# Mech events ETL
|
|
|
80 |
rpc = RPC
|
81 |
# Run markets ETL
|
82 |
logging.info("Running markets ETL")
|
83 |
+
# mkt_etl(MARKETS_FILENAME)
|
84 |
logging.info("Markets ETL completed")
|
85 |
|
86 |
# Mech events ETL
|
scripts/staking.py
CHANGED
@@ -168,7 +168,7 @@ def get_trader_address_staking(trader_address: str, service_map: dict) -> str:
|
|
168 |
break
|
169 |
|
170 |
if found_key == -1:
|
171 |
-
return "
|
172 |
owner = service_map[found_key]["owner_address"]
|
173 |
return check_owner_staking_contract(owner_address=owner)
|
174 |
|
@@ -182,6 +182,7 @@ def label_trades_by_staking(trades_df: pd.DataFrame, start: int = None) -> pd.Da
|
|
182 |
last_key = max(keys)
|
183 |
else:
|
184 |
last_key = start
|
|
|
185 |
update_service_map(start=last_key)
|
186 |
all_traders = trades_df.trader_address.unique()
|
187 |
trades_df["staking"] = ""
|
@@ -199,6 +200,9 @@ def label_trades_by_staking(trades_df: pd.DataFrame, start: int = None) -> pd.Da
|
|
199 |
if __name__ == "__main__":
|
200 |
# create_service_map()
|
201 |
trades_df = pd.read_parquet(DATA_DIR / "all_trades_profitability.parquet")
|
202 |
-
|
|
|
|
|
|
|
203 |
print(trades_df.staking.value_counts())
|
204 |
trades_df.to_parquet(DATA_DIR / "all_trades_profitability.parquet", index=False)
|
|
|
168 |
break
|
169 |
|
170 |
if found_key == -1:
|
171 |
+
return "non_Olas"
|
172 |
owner = service_map[found_key]["owner_address"]
|
173 |
return check_owner_staking_contract(owner_address=owner)
|
174 |
|
|
|
182 |
last_key = max(keys)
|
183 |
else:
|
184 |
last_key = start
|
185 |
+
print(f"last service key = {last_key}")
|
186 |
update_service_map(start=last_key)
|
187 |
all_traders = trades_df.trader_address.unique()
|
188 |
trades_df["staking"] = ""
|
|
|
200 |
if __name__ == "__main__":
|
201 |
# create_service_map()
|
202 |
trades_df = pd.read_parquet(DATA_DIR / "all_trades_profitability.parquet")
|
203 |
+
print("before labeling")
|
204 |
+
print(trades_df.staking.value_counts())
|
205 |
+
label_trades_by_staking(trades_df=trades_df, start=8)
|
206 |
+
print("after labeling")
|
207 |
print(trades_df.staking.value_counts())
|
208 |
trades_df.to_parquet(DATA_DIR / "all_trades_profitability.parquet", index=False)
|
scripts/web3_utils.py
CHANGED
@@ -137,8 +137,16 @@ def updating_timestamps(rpc: str, tools_filename: str):
|
|
137 |
)
|
138 |
t_map.update(new_timestamps)
|
139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
with open(DATA_DIR / "t_map.pkl", "wb") as f:
|
141 |
-
pickle.dump(
|
142 |
|
143 |
# clean and release all memory
|
144 |
del tools
|
|
|
137 |
)
|
138 |
t_map.update(new_timestamps)
|
139 |
|
140 |
+
# filtering old timestamps
|
141 |
+
cutoff_date = datetime(2024, 9, 9)
|
142 |
+
filtered_map = {
|
143 |
+
k: v
|
144 |
+
for k, v in t_map.items()
|
145 |
+
if datetime.strptime(v, "%Y-%m-%d %H:%M:%S") < cutoff_date
|
146 |
+
}
|
147 |
+
|
148 |
with open(DATA_DIR / "t_map.pkl", "wb") as f:
|
149 |
+
pickle.dump(filtered_map, f)
|
150 |
|
151 |
# clean and release all memory
|
152 |
del tools
|
tabs/metrics.py
CHANGED
@@ -145,14 +145,14 @@ def plot_trade_metrics(
|
|
145 |
yaxis_title = "Gross profit per trade (xDAI)"
|
146 |
|
147 |
color_discrete = ["purple", "darkgoldenrod", "darkgreen"]
|
148 |
-
if trader_filter == "
|
149 |
trades_filtered = get_boxplot_metrics(
|
150 |
-
column_name, trades_df.loc[trades_df["staking"] != "
|
151 |
)
|
152 |
color_discrete = ["darkviolet", "goldenrod", "green"]
|
153 |
-
elif trader_filter == "
|
154 |
trades_filtered = get_boxplot_metrics(
|
155 |
-
column_name, trades_df.loc[trades_df["staking"] == "
|
156 |
)
|
157 |
else:
|
158 |
trades_filtered = get_boxplot_metrics(column_name, trades_df)
|
|
|
145 |
yaxis_title = "Gross profit per trade (xDAI)"
|
146 |
|
147 |
color_discrete = ["purple", "darkgoldenrod", "darkgreen"]
|
148 |
+
if trader_filter == "Olas":
|
149 |
trades_filtered = get_boxplot_metrics(
|
150 |
+
column_name, trades_df.loc[trades_df["staking"] != "non_Olas"]
|
151 |
)
|
152 |
color_discrete = ["darkviolet", "goldenrod", "green"]
|
153 |
+
elif trader_filter == "non_Olas":
|
154 |
trades_filtered = get_boxplot_metrics(
|
155 |
+
column_name, trades_df.loc[trades_df["staking"] == "non_Olas"]
|
156 |
)
|
157 |
else:
|
158 |
trades_filtered = get_boxplot_metrics(column_name, trades_df)
|
tabs/staking.py
CHANGED
@@ -39,21 +39,32 @@ def plot_staking_trades_per_market_by_week(
|
|
39 |
all_filtered_trades = all_filtered_trades.loc[
|
40 |
all_filtered_trades["market_creator"] == market_creator
|
41 |
]
|
42 |
-
|
|
|
43 |
if market_creator != "all":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
all_filtered_trades["staking"] = all_filtered_trades["staking"].replace(
|
45 |
-
{market_creator: "staking_traders", "
|
46 |
)
|
47 |
colour_sequence = ["gray", market_colour, "black"]
|
48 |
categories_sorted = {
|
49 |
-
"staking": ["non_staking_traders", "staking_traders", "
|
50 |
}
|
51 |
else:
|
52 |
all_filtered_trades["staking"] = all_filtered_trades["staking"].replace(
|
53 |
{
|
54 |
"pearl": "staking_pearl_traders",
|
55 |
"quickstart": "staking_quickstart_traders",
|
56 |
-
"
|
57 |
}
|
58 |
)
|
59 |
colour_sequence = ["gray", "darkviolet", "goldenrod", "black"]
|
@@ -62,7 +73,7 @@ def plot_staking_trades_per_market_by_week(
|
|
62 |
"non_staking_traders",
|
63 |
"staking_pearl_traders",
|
64 |
"staking_quickstart_traders",
|
65 |
-
"
|
66 |
]
|
67 |
}
|
68 |
trades = get_overall_by_staking_traders(all_filtered_trades)
|
|
|
39 |
all_filtered_trades = all_filtered_trades.loc[
|
40 |
all_filtered_trades["market_creator"] == market_creator
|
41 |
]
|
42 |
+
print(f"Checking values for market creator={market_creator}")
|
43 |
+
print(all_filtered_trades.staking.value_counts())
|
44 |
if market_creator != "all":
|
45 |
+
if market_creator == "pearl":
|
46 |
+
# remove the staking data from quickstart
|
47 |
+
all_filtered_trades = all_filtered_trades.loc[
|
48 |
+
all_filtered_trades["staking"] != "quickstart"
|
49 |
+
]
|
50 |
+
else:
|
51 |
+
# remove the staking data from pearl
|
52 |
+
all_filtered_trades = all_filtered_trades.loc[
|
53 |
+
all_filtered_trades["staking"] != "pearl"
|
54 |
+
]
|
55 |
all_filtered_trades["staking"] = all_filtered_trades["staking"].replace(
|
56 |
+
{market_creator: "staking_traders", "non_Olas": "non_Olas_traders"}
|
57 |
)
|
58 |
colour_sequence = ["gray", market_colour, "black"]
|
59 |
categories_sorted = {
|
60 |
+
"staking": ["non_staking_traders", "staking_traders", "non_Olas_traders"]
|
61 |
}
|
62 |
else:
|
63 |
all_filtered_trades["staking"] = all_filtered_trades["staking"].replace(
|
64 |
{
|
65 |
"pearl": "staking_pearl_traders",
|
66 |
"quickstart": "staking_quickstart_traders",
|
67 |
+
"non_Olas": "non_Olas_traders",
|
68 |
}
|
69 |
)
|
70 |
colour_sequence = ["gray", "darkviolet", "goldenrod", "black"]
|
|
|
73 |
"non_staking_traders",
|
74 |
"staking_pearl_traders",
|
75 |
"staking_quickstart_traders",
|
76 |
+
"non_Olas_traders",
|
77 |
]
|
78 |
}
|
79 |
trades = get_overall_by_staking_traders(all_filtered_trades)
|
tabs/trades.py
CHANGED
@@ -165,7 +165,7 @@ def integrated_plot_trades_per_market_by_week_v2(trades_df: pd.DataFrame) -> gr.
|
|
165 |
)
|
166 |
# Create binary staking category
|
167 |
all_filtered_trades["staking_type"] = all_filtered_trades["staking"].apply(
|
168 |
-
lambda x: "
|
169 |
)
|
170 |
|
171 |
# Group by week, market_creator and staking_type
|
@@ -194,34 +194,34 @@ def integrated_plot_trades_per_market_by_week_v2(trades_df: pd.DataFrame) -> gr.
|
|
194 |
"all": "darkgreen",
|
195 |
}
|
196 |
|
197 |
-
# Process both
|
198 |
for market in ["pearl", "quickstart", "all"]:
|
199 |
market_data = trades[trades["market_creator"] == market]
|
200 |
|
201 |
-
# First add '
|
202 |
-
|
203 |
-
|
204 |
-
x=
|
205 |
-
y=
|
206 |
-
name=f"{market}-
|
207 |
marker_color=market_colors[market],
|
208 |
offsetgroup=market, # Keep the market grouping
|
209 |
showlegend=True,
|
210 |
)
|
211 |
|
212 |
-
# Then add '
|
213 |
-
|
214 |
-
|
215 |
-
x=
|
216 |
-
y=
|
217 |
-
name=f"{market}-
|
218 |
marker_color=market_darker_colors[market],
|
219 |
offsetgroup=market, # Keep the market grouping
|
220 |
-
base=
|
221 |
showlegend=True,
|
222 |
)
|
223 |
|
224 |
-
final_traces.extend([
|
225 |
|
226 |
# Create new figure with the combined traces
|
227 |
fig = go.Figure(data=final_traces)
|
@@ -292,7 +292,7 @@ def integrated_plot_winning_trades_per_market_by_week_v2(
|
|
292 |
)
|
293 |
# Create binary staking category
|
294 |
all_filtered_trades["staking_type"] = all_filtered_trades["staking"].apply(
|
295 |
-
lambda x: "
|
296 |
)
|
297 |
if trader_filter == "all":
|
298 |
final_df = get_overall_winning_by_market_trades(all_filtered_trades)
|
@@ -309,10 +309,10 @@ def integrated_plot_winning_trades_per_market_by_week_v2(
|
|
309 |
# Convert back to string format
|
310 |
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
311 |
color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
|
312 |
-
if trader_filter == "
|
313 |
-
final_df = final_df[final_df["staking_type"] == "
|
314 |
-
elif trader_filter == "
|
315 |
-
final_df = final_df[final_df["staking_type"] == "
|
316 |
color_discrete_sequence = ["purple", "darkgoldenrod", "darkgreen"]
|
317 |
|
318 |
fig = px.bar(
|
@@ -329,58 +329,10 @@ def integrated_plot_winning_trades_per_market_by_week_v2(
|
|
329 |
yaxis_title="Weekly % of winning trades",
|
330 |
legend=dict(yanchor="top", y=0.5),
|
331 |
)
|
332 |
-
|
333 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
334 |
# Update layout to force x-axis category order (hotfix for a sorting issue)
|
335 |
fig.update_layout(xaxis={"categoryorder": "array", "categoryarray": all_dates})
|
336 |
return gr.Plot(
|
337 |
value=fig,
|
338 |
)
|
339 |
-
|
340 |
-
|
341 |
-
def plot_winning_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
342 |
-
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
343 |
-
return gr.BarPlot(
|
344 |
-
value=trades_df,
|
345 |
-
x="month_year_week",
|
346 |
-
y="winning_trade",
|
347 |
-
show_label=True,
|
348 |
-
interactive=True,
|
349 |
-
show_actions_button=True,
|
350 |
-
tooltip=["month_year_week", "winning_trade"],
|
351 |
-
height=HEIGHT,
|
352 |
-
width=WIDTH,
|
353 |
-
)
|
354 |
-
|
355 |
-
|
356 |
-
def plot_winning_trades_per_market_by_week(
|
357 |
-
trades_df: pd.DataFrame, market_type: str
|
358 |
-
) -> gr.Plot:
|
359 |
-
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
360 |
-
# if market_type is "all then no filter is applied"
|
361 |
-
if market_type == "quickstart":
|
362 |
-
trades = trades_df.loc[trades_df["market_creator"] == "quickstart"]
|
363 |
-
color_sequence = ["goldenrod"]
|
364 |
-
|
365 |
-
elif market_type == "pearl":
|
366 |
-
trades = trades_df.loc[trades_df["market_creator"] == "pearl"]
|
367 |
-
color_sequence = ["purple"]
|
368 |
-
else:
|
369 |
-
trades = trades_df
|
370 |
-
color_sequence = ["darkgreen"]
|
371 |
-
|
372 |
-
fig = px.bar(
|
373 |
-
trades,
|
374 |
-
x="month_year_week",
|
375 |
-
y="winning_trade",
|
376 |
-
color_discrete_sequence=color_sequence,
|
377 |
-
title=market_type + " winning trades",
|
378 |
-
)
|
379 |
-
fig.update_layout(
|
380 |
-
xaxis_title="Week",
|
381 |
-
yaxis_title="Weekly % of winning trades",
|
382 |
-
)
|
383 |
-
fig.update_xaxes(tickformat="%b %d\n%Y")
|
384 |
-
return gr.Plot(
|
385 |
-
value=fig,
|
386 |
-
)
|
|
|
165 |
)
|
166 |
# Create binary staking category
|
167 |
all_filtered_trades["staking_type"] = all_filtered_trades["staking"].apply(
|
168 |
+
lambda x: "non_Olas" if x == "non_Olas" else "Olas"
|
169 |
)
|
170 |
|
171 |
# Group by week, market_creator and staking_type
|
|
|
194 |
"all": "darkgreen",
|
195 |
}
|
196 |
|
197 |
+
# Process both Olas and non-Olas traces for each market together
|
198 |
for market in ["pearl", "quickstart", "all"]:
|
199 |
market_data = trades[trades["market_creator"] == market]
|
200 |
|
201 |
+
# First add 'Olas' trace
|
202 |
+
olas_data = market_data[market_data["staking_type"] == "Olas"]
|
203 |
+
olas_trace = go.Bar(
|
204 |
+
x=olas_data["month_year_week"],
|
205 |
+
y=olas_data["trades"],
|
206 |
+
name=f"{market}-Olas",
|
207 |
marker_color=market_colors[market],
|
208 |
offsetgroup=market, # Keep the market grouping
|
209 |
showlegend=True,
|
210 |
)
|
211 |
|
212 |
+
# Then add 'non_Olas' trace with base set to olas values
|
213 |
+
non_Olas_data = market_data[market_data["staking_type"] == "non_Olas"]
|
214 |
+
non_Olas_trace = go.Bar(
|
215 |
+
x=non_Olas_data["month_year_week"],
|
216 |
+
y=non_Olas_data["trades"],
|
217 |
+
name=f"{market}-non_Olas",
|
218 |
marker_color=market_darker_colors[market],
|
219 |
offsetgroup=market, # Keep the market grouping
|
220 |
+
base=olas_data["trades"], # Stack on top of olas trace
|
221 |
showlegend=True,
|
222 |
)
|
223 |
|
224 |
+
final_traces.extend([olas_trace, non_Olas_trace])
|
225 |
|
226 |
# Create new figure with the combined traces
|
227 |
fig = go.Figure(data=final_traces)
|
|
|
292 |
)
|
293 |
# Create binary staking category
|
294 |
all_filtered_trades["staking_type"] = all_filtered_trades["staking"].apply(
|
295 |
+
lambda x: "non_Olas" if x == "non_Olas" else "Olas"
|
296 |
)
|
297 |
if trader_filter == "all":
|
298 |
final_df = get_overall_winning_by_market_trades(all_filtered_trades)
|
|
|
309 |
# Convert back to string format
|
310 |
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
311 |
color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
|
312 |
+
if trader_filter == "Olas":
|
313 |
+
final_df = final_df[final_df["staking_type"] == "Olas"]
|
314 |
+
elif trader_filter == "non_Olas":
|
315 |
+
final_df = final_df[final_df["staking_type"] == "non_Olas"]
|
316 |
color_discrete_sequence = ["purple", "darkgoldenrod", "darkgreen"]
|
317 |
|
318 |
fig = px.bar(
|
|
|
329 |
yaxis_title="Weekly % of winning trades",
|
330 |
legend=dict(yanchor="top", y=0.5),
|
331 |
)
|
332 |
+
|
333 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
334 |
# Update layout to force x-axis category order (hotfix for a sorting issue)
|
335 |
fig.update_layout(xaxis={"categoryorder": "array", "categoryarray": all_dates})
|
336 |
return gr.Plot(
|
337 |
value=fig,
|
338 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|