Commit
·
f7ad8ae
1
Parent(s):
5752e4d
new weekly data and fixes on the pipeline due to new year format
Browse files- data/all_trades_profitability.parquet +2 -2
- data/daily_info.parquet +2 -2
- data/error_by_markets.parquet +2 -2
- data/invalid_trades.parquet +2 -2
- data/tools_accuracy.csv +2 -2
- data/unknown_traders.parquet +2 -2
- data/winning_df.parquet +2 -2
- notebooks/analysis.ipynb +0 -0
- notebooks/invalid_markets.ipynb +80 -3
- scripts/cleaning_old_info.py +18 -0
- scripts/get_mech_info.py +5 -0
- scripts/markets.py +3 -0
- scripts/mech_request_utils.py +1 -0
- scripts/profitability.py +12 -6
- scripts/pull_data.py +6 -1
- scripts/tools_metrics.py +1 -1
- tabs/metrics.py +2 -2
- tabs/staking.py +2 -2
- tabs/tool_win.py +5 -4
- tabs/trades.py +5 -5
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:08d3f27f13f20022a8aa176e3f84559a38c001d03753fd13101eae15ab4a1123
|
| 3 |
+
size 6500230
|
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:689d0f6abf1886fb0b089db0294e07c551485005fabbaf73ea36083d6388ce5f
|
| 3 |
+
size 78026
|
data/error_by_markets.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:7832acf3c67797c32225d4c253d651ffcbd4aba4bb19354ea00ad0c1d7200cc1
|
| 3 |
+
size 13489
|
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:6156d839803a0c09606450ead26fb3b31ef6ef30bf3507ccbd0dc0399ad366f7
|
| 3 |
+
size 152273
|
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:ab13e55237b5f9bee0012eab8976b0ea3ef1518f0071a081d9052f97061315a7
|
| 3 |
+
size 1100
|
data/unknown_traders.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:3620eaba76778060f41059fb2b6ff6e92a6000eedfd9a9119b703f84cdda11ff
|
| 3 |
+
size 194084
|
data/winning_df.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:1ad71600af38478d3dc275bf7ad0f3cd3cd46d44d1bf54f06bb6f9d9540cc041
|
| 3 |
+
size 13714
|
notebooks/analysis.ipynb
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/invalid_markets.ipynb
CHANGED
|
@@ -115,11 +115,88 @@
|
|
| 115 |
},
|
| 116 |
{
|
| 117 |
"cell_type": "code",
|
| 118 |
-
"execution_count":
|
| 119 |
"metadata": {},
|
| 120 |
"outputs": [],
|
| 121 |
"source": [
|
| 122 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
]
|
| 124 |
},
|
| 125 |
{
|
|
@@ -139,7 +216,7 @@
|
|
| 139 |
}
|
| 140 |
],
|
| 141 |
"source": [
|
| 142 |
-
"len(
|
| 143 |
]
|
| 144 |
},
|
| 145 |
{
|
|
|
|
| 115 |
},
|
| 116 |
{
|
| 117 |
"cell_type": "code",
|
| 118 |
+
"execution_count": 3,
|
| 119 |
"metadata": {},
|
| 120 |
"outputs": [],
|
| 121 |
"source": [
|
| 122 |
+
"invalid_trades = pd.read_parquet(\"../data/invalid_trades.parquet\")"
|
| 123 |
+
]
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"cell_type": "code",
|
| 127 |
+
"execution_count": 4,
|
| 128 |
+
"metadata": {},
|
| 129 |
+
"outputs": [
|
| 130 |
+
{
|
| 131 |
+
"name": "stdout",
|
| 132 |
+
"output_type": "stream",
|
| 133 |
+
"text": [
|
| 134 |
+
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 135 |
+
"RangeIndex: 2589 entries, 0 to 2588\n",
|
| 136 |
+
"Data columns (total 22 columns):\n",
|
| 137 |
+
" # Column Non-Null Count Dtype \n",
|
| 138 |
+
"--- ------ -------------- ----- \n",
|
| 139 |
+
" 0 trader_address 2589 non-null object \n",
|
| 140 |
+
" 1 market_creator 2589 non-null object \n",
|
| 141 |
+
" 2 trade_id 2589 non-null object \n",
|
| 142 |
+
" 3 creation_timestamp 2589 non-null datetime64[ns, UTC]\n",
|
| 143 |
+
" 4 title 2589 non-null object \n",
|
| 144 |
+
" 5 market_status 2589 non-null object \n",
|
| 145 |
+
" 6 collateral_amount 2589 non-null float64 \n",
|
| 146 |
+
" 7 outcome_index 2589 non-null object \n",
|
| 147 |
+
" 8 trade_fee_amount 2589 non-null float64 \n",
|
| 148 |
+
" 9 outcomes_tokens_traded 2589 non-null float64 \n",
|
| 149 |
+
" 10 current_answer 2589 non-null int64 \n",
|
| 150 |
+
" 11 is_invalid 2589 non-null bool \n",
|
| 151 |
+
" 12 winning_trade 2589 non-null bool \n",
|
| 152 |
+
" 13 earnings 2589 non-null float64 \n",
|
| 153 |
+
" 14 redeemed 2589 non-null bool \n",
|
| 154 |
+
" 15 redeemed_amount 2589 non-null float64 \n",
|
| 155 |
+
" 16 num_mech_calls 2589 non-null int64 \n",
|
| 156 |
+
" 17 mech_fee_amount 2589 non-null float64 \n",
|
| 157 |
+
" 18 net_earnings 2589 non-null float64 \n",
|
| 158 |
+
" 19 roi 2573 non-null float64 \n",
|
| 159 |
+
" 20 staking 0 non-null object \n",
|
| 160 |
+
" 21 nr_mech_calls 0 non-null float64 \n",
|
| 161 |
+
"dtypes: bool(3), datetime64[ns, UTC](1), float64(9), int64(2), object(7)\n",
|
| 162 |
+
"memory usage: 392.0+ KB\n"
|
| 163 |
+
]
|
| 164 |
+
}
|
| 165 |
+
],
|
| 166 |
+
"source": [
|
| 167 |
+
"invalid_trades.info()"
|
| 168 |
+
]
|
| 169 |
+
},
|
| 170 |
+
{
|
| 171 |
+
"cell_type": "code",
|
| 172 |
+
"execution_count": 5,
|
| 173 |
+
"metadata": {},
|
| 174 |
+
"outputs": [
|
| 175 |
+
{
|
| 176 |
+
"data": {
|
| 177 |
+
"text/plain": [
|
| 178 |
+
"Timestamp('2024-09-09 02:55:15+0000', tz='UTC')"
|
| 179 |
+
]
|
| 180 |
+
},
|
| 181 |
+
"execution_count": 5,
|
| 182 |
+
"metadata": {},
|
| 183 |
+
"output_type": "execute_result"
|
| 184 |
+
}
|
| 185 |
+
],
|
| 186 |
+
"source": [
|
| 187 |
+
"min(invalid_trades.creation_timestamp)"
|
| 188 |
+
]
|
| 189 |
+
},
|
| 190 |
+
{
|
| 191 |
+
"cell_type": "code",
|
| 192 |
+
"execution_count": 6,
|
| 193 |
+
"metadata": {},
|
| 194 |
+
"outputs": [],
|
| 195 |
+
"source": [
|
| 196 |
+
"cutoff_date = \"2024-10-30\"\n",
|
| 197 |
+
"min_date_utc = pd.to_datetime(cutoff_date, format=\"%Y-%m-%d\", utc=True)\n",
|
| 198 |
+
"invalid_trades = invalid_trades.loc[invalid_trades[\"creation_timestamp\"]> min_date_utc]\n",
|
| 199 |
+
"invalid_trades.to_parquet(\"../data/invalid_trades.parquet\", index=False)"
|
| 200 |
]
|
| 201 |
},
|
| 202 |
{
|
|
|
|
| 216 |
}
|
| 217 |
],
|
| 218 |
"source": [
|
| 219 |
+
"len(invalid_trades)"
|
| 220 |
]
|
| 221 |
},
|
| 222 |
{
|
scripts/cleaning_old_info.py
CHANGED
|
@@ -79,6 +79,24 @@ def clean_old_data_from_parquet_files(cutoff_date: str):
|
|
| 79 |
except Exception as e:
|
| 80 |
print(f"Error cleaning fpmmTrades file {e}")
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
if __name__ == "__main__":
|
| 84 |
clean_old_data_from_parquet_files("2024-10-25")
|
|
|
|
| 79 |
except Exception as e:
|
| 80 |
print(f"Error cleaning fpmmTrades file {e}")
|
| 81 |
|
| 82 |
+
# clean invalid trades parquet
|
| 83 |
+
try:
|
| 84 |
+
invalid_trades = pd.read_parquet(DATA_DIR / "invalid_trades.parquet")
|
| 85 |
+
|
| 86 |
+
invalid_trades["creation_timestamp"] = pd.to_datetime(
|
| 87 |
+
invalid_trades["creation_timestamp"], utc=True
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
print(f"length before filtering {len(invalid_trades)}")
|
| 91 |
+
invalid_trades = invalid_trades.loc[
|
| 92 |
+
invalid_trades["creation_timestamp"] > min_date_utc
|
| 93 |
+
]
|
| 94 |
+
print(f"length after filtering {len(invalid_trades)}")
|
| 95 |
+
invalid_trades.to_parquet(DATA_DIR / "invalid_trades.parquet", index=False)
|
| 96 |
+
|
| 97 |
+
except Exception as e:
|
| 98 |
+
print(f"Error cleaning fpmmTrades file {e}")
|
| 99 |
+
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|
| 102 |
clean_old_data_from_parquet_files("2024-10-25")
|
scripts/get_mech_info.py
CHANGED
|
@@ -133,11 +133,16 @@ def update_fpmmTrades_parquet(trades_filename: str) -> pd.DataFrame:
|
|
| 133 |
print(f"Error reading new trades parquet file {e}")
|
| 134 |
return None
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
# ensure creationTimestamp compatibility
|
| 137 |
try:
|
| 138 |
new_trades_df["creationTimestamp"] = new_trades_df["creationTimestamp"].apply(
|
| 139 |
lambda x: transform_to_datetime(x)
|
| 140 |
)
|
|
|
|
| 141 |
except Exception as e:
|
| 142 |
print(f"Transformation not needed")
|
| 143 |
try:
|
|
|
|
| 133 |
print(f"Error reading new trades parquet file {e}")
|
| 134 |
return None
|
| 135 |
|
| 136 |
+
# lowercase and strip creator_address
|
| 137 |
+
new_trades_df["trader_address"] = (
|
| 138 |
+
new_trades_df["trader_address"].str.lower().str.strip()
|
| 139 |
+
)
|
| 140 |
# ensure creationTimestamp compatibility
|
| 141 |
try:
|
| 142 |
new_trades_df["creationTimestamp"] = new_trades_df["creationTimestamp"].apply(
|
| 143 |
lambda x: transform_to_datetime(x)
|
| 144 |
)
|
| 145 |
+
|
| 146 |
except Exception as e:
|
| 147 |
print(f"Transformation not needed")
|
| 148 |
try:
|
scripts/markets.py
CHANGED
|
@@ -309,6 +309,7 @@ def add_market_creator(tools: pd.DataFrame) -> None:
|
|
| 309 |
return
|
| 310 |
tools["market_creator"] = ""
|
| 311 |
# traverse the list of traders
|
|
|
|
| 312 |
traders_list = list(tools.trader_address.unique())
|
| 313 |
for trader_address in traders_list:
|
| 314 |
market_creator = ""
|
|
@@ -317,6 +318,7 @@ def add_market_creator(tools: pd.DataFrame) -> None:
|
|
| 317 |
market_creator = trades.iloc[0]["market_creator"] # first value is enough
|
| 318 |
except Exception:
|
| 319 |
print(f"ERROR getting the market creator of {trader_address}")
|
|
|
|
| 320 |
continue
|
| 321 |
# update
|
| 322 |
tools.loc[tools["trader_address"] == trader_address, "market_creator"] = (
|
|
@@ -324,6 +326,7 @@ def add_market_creator(tools: pd.DataFrame) -> None:
|
|
| 324 |
)
|
| 325 |
# filter those tools where we don't have market creator info
|
| 326 |
tools = tools.loc[tools["market_creator"] != ""]
|
|
|
|
| 327 |
return tools
|
| 328 |
|
| 329 |
|
|
|
|
| 309 |
return
|
| 310 |
tools["market_creator"] = ""
|
| 311 |
# traverse the list of traders
|
| 312 |
+
tools_no_market_creator = 0
|
| 313 |
traders_list = list(tools.trader_address.unique())
|
| 314 |
for trader_address in traders_list:
|
| 315 |
market_creator = ""
|
|
|
|
| 318 |
market_creator = trades.iloc[0]["market_creator"] # first value is enough
|
| 319 |
except Exception:
|
| 320 |
print(f"ERROR getting the market creator of {trader_address}")
|
| 321 |
+
tools_no_market_creator += 1
|
| 322 |
continue
|
| 323 |
# update
|
| 324 |
tools.loc[tools["trader_address"] == trader_address, "market_creator"] = (
|
|
|
|
| 326 |
)
|
| 327 |
# filter those tools where we don't have market creator info
|
| 328 |
tools = tools.loc[tools["market_creator"] != ""]
|
| 329 |
+
print(f"Number of tools with no market creator info = {tools_no_market_creator}")
|
| 330 |
return tools
|
| 331 |
|
| 332 |
|
scripts/mech_request_utils.py
CHANGED
|
@@ -244,6 +244,7 @@ def collect_missing_delivers(request_id: int, block_number: int) -> Dict[str, An
|
|
| 244 |
return items[0]
|
| 245 |
except Exception as e:
|
| 246 |
print(f"Error while getting the response: {e}")
|
|
|
|
| 247 |
|
| 248 |
return mech_delivers
|
| 249 |
|
|
|
|
| 244 |
return items[0]
|
| 245 |
except Exception as e:
|
| 246 |
print(f"Error while getting the response: {e}")
|
| 247 |
+
# TODO count how many mech requests without a deliver do we have
|
| 248 |
|
| 249 |
return mech_delivers
|
| 250 |
|
scripts/profitability.py
CHANGED
|
@@ -27,7 +27,6 @@ import os
|
|
| 27 |
from web3_utils import query_conditional_tokens_gc_subgraph
|
| 28 |
from get_mech_info import (
|
| 29 |
DATETIME_60_DAYS_AGO,
|
| 30 |
-
update_fpmmTrades_parquet,
|
| 31 |
update_tools_parquet,
|
| 32 |
update_all_trades_parquet,
|
| 33 |
)
|
|
@@ -221,13 +220,16 @@ def analyse_trader(
|
|
| 221 |
return trades_df
|
| 222 |
|
| 223 |
# Iterate over the trades
|
|
|
|
|
|
|
| 224 |
for i, trade in tqdm(trades.iterrows(), total=len(trades), desc="Analysing trades"):
|
| 225 |
try:
|
| 226 |
market_answer = trade["fpmm.currentAnswer"]
|
| 227 |
trading_day = trade["creation_date"]
|
| 228 |
trade_id = trade["id"]
|
| 229 |
if not daily_info and not market_answer:
|
| 230 |
-
print(f"Skipping trade {i} because currentAnswer is NaN")
|
|
|
|
| 231 |
continue
|
| 232 |
# Parsing and computing shared values
|
| 233 |
collateral_amount = wei_to_unit(float(trade["collateralAmount"]))
|
|
@@ -243,9 +245,10 @@ def analyse_trader(
|
|
| 243 |
|
| 244 |
# Skip non-closed markets
|
| 245 |
if not daily_info and market_status != MarketState.CLOSED:
|
| 246 |
-
print(
|
| 247 |
-
|
| 248 |
-
)
|
|
|
|
| 249 |
continue
|
| 250 |
if current_answer is not None:
|
| 251 |
current_answer = convert_hex_to_int(current_answer)
|
|
@@ -316,6 +319,10 @@ def analyse_trader(
|
|
| 316 |
print(trade)
|
| 317 |
continue
|
| 318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
return trades_df
|
| 320 |
|
| 321 |
|
|
@@ -380,7 +387,6 @@ def run_profitability_analysis(
|
|
| 380 |
|
| 381 |
# # merge previous files if requested
|
| 382 |
if merge:
|
| 383 |
-
update_fpmmTrades_parquet(trades_filename)
|
| 384 |
all_trades_df = update_all_trades_parquet(all_trades_df)
|
| 385 |
|
| 386 |
# debugging purposes
|
|
|
|
| 27 |
from web3_utils import query_conditional_tokens_gc_subgraph
|
| 28 |
from get_mech_info import (
|
| 29 |
DATETIME_60_DAYS_AGO,
|
|
|
|
| 30 |
update_tools_parquet,
|
| 31 |
update_all_trades_parquet,
|
| 32 |
)
|
|
|
|
| 220 |
return trades_df
|
| 221 |
|
| 222 |
# Iterate over the trades
|
| 223 |
+
trades_answer_nan = 0
|
| 224 |
+
trades_no_closed_market = 0
|
| 225 |
for i, trade in tqdm(trades.iterrows(), total=len(trades), desc="Analysing trades"):
|
| 226 |
try:
|
| 227 |
market_answer = trade["fpmm.currentAnswer"]
|
| 228 |
trading_day = trade["creation_date"]
|
| 229 |
trade_id = trade["id"]
|
| 230 |
if not daily_info and not market_answer:
|
| 231 |
+
# print(f"Skipping trade {i} because currentAnswer is NaN")
|
| 232 |
+
trades_answer_nan += 1
|
| 233 |
continue
|
| 234 |
# Parsing and computing shared values
|
| 235 |
collateral_amount = wei_to_unit(float(trade["collateralAmount"]))
|
|
|
|
| 245 |
|
| 246 |
# Skip non-closed markets
|
| 247 |
if not daily_info and market_status != MarketState.CLOSED:
|
| 248 |
+
# print(
|
| 249 |
+
# f"Skipping trade {i} because market is not closed. Market Status: {market_status}"
|
| 250 |
+
# )
|
| 251 |
+
trades_no_closed_market += 1
|
| 252 |
continue
|
| 253 |
if current_answer is not None:
|
| 254 |
current_answer = convert_hex_to_int(current_answer)
|
|
|
|
| 319 |
print(trade)
|
| 320 |
continue
|
| 321 |
|
| 322 |
+
print(f"Number of trades where currentAnswer is NaN = {trades_answer_nan}")
|
| 323 |
+
print(
|
| 324 |
+
f"Number of trades where the market is not closed = {trades_no_closed_market}"
|
| 325 |
+
)
|
| 326 |
return trades_df
|
| 327 |
|
| 328 |
|
|
|
|
| 387 |
|
| 388 |
# # merge previous files if requested
|
| 389 |
if merge:
|
|
|
|
| 390 |
all_trades_df = update_all_trades_parquet(all_trades_df)
|
| 391 |
|
| 392 |
# debugging purposes
|
scripts/pull_data.py
CHANGED
|
@@ -15,6 +15,7 @@ from utils import (
|
|
| 15 |
)
|
| 16 |
from get_mech_info import (
|
| 17 |
get_mech_events_since_last_run,
|
|
|
|
| 18 |
update_json_files,
|
| 19 |
)
|
| 20 |
from update_tools_accuracy import compute_tools_accuracy
|
|
@@ -99,6 +100,10 @@ def only_new_weekly_analysis():
|
|
| 99 |
trades_filename="new_fpmmTrades.parquet",
|
| 100 |
from_timestamp=int(latest_timestamp.timestamp()),
|
| 101 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
# Run tools ETL
|
| 103 |
logging.info("Generate and parse the tools content")
|
| 104 |
# generate only new file
|
|
@@ -122,7 +127,7 @@ def only_new_weekly_analysis():
|
|
| 122 |
|
| 123 |
save_historical_data()
|
| 124 |
try:
|
| 125 |
-
clean_old_data_from_parquet_files("2024-
|
| 126 |
except Exception as e:
|
| 127 |
print("Error cleaning the oldest information from parquet files")
|
| 128 |
print(f"reason = {e}")
|
|
|
|
| 15 |
)
|
| 16 |
from get_mech_info import (
|
| 17 |
get_mech_events_since_last_run,
|
| 18 |
+
update_fpmmTrades_parquet,
|
| 19 |
update_json_files,
|
| 20 |
)
|
| 21 |
from update_tools_accuracy import compute_tools_accuracy
|
|
|
|
| 100 |
trades_filename="new_fpmmTrades.parquet",
|
| 101 |
from_timestamp=int(latest_timestamp.timestamp()),
|
| 102 |
)
|
| 103 |
+
# merge with previous file
|
| 104 |
+
print("Merging with previous fpmmTrades file")
|
| 105 |
+
update_fpmmTrades_parquet(trades_filename="new_fpmmTrades.parquet")
|
| 106 |
+
|
| 107 |
# Run tools ETL
|
| 108 |
logging.info("Generate and parse the tools content")
|
| 109 |
# generate only new file
|
|
|
|
| 127 |
|
| 128 |
save_historical_data()
|
| 129 |
try:
|
| 130 |
+
clean_old_data_from_parquet_files("2024-11-06")
|
| 131 |
except Exception as e:
|
| 132 |
print("Error cleaning the oldest information from parquet files")
|
| 133 |
print(f"reason = {e}")
|
scripts/tools_metrics.py
CHANGED
|
@@ -61,7 +61,7 @@ def prepare_tools(tools: pd.DataFrame) -> pd.DataFrame:
|
|
| 61 |
tools = tools.sort_values(by="request_time", ascending=True)
|
| 62 |
|
| 63 |
tools["request_month_year_week"] = (
|
| 64 |
-
pd.to_datetime(tools["request_time"]).dt.to_period("W").dt.strftime("%b-%d")
|
| 65 |
)
|
| 66 |
# preparing the tools graph
|
| 67 |
# adding the total
|
|
|
|
| 61 |
tools = tools.sort_values(by="request_time", ascending=True)
|
| 62 |
|
| 63 |
tools["request_month_year_week"] = (
|
| 64 |
+
pd.to_datetime(tools["request_time"]).dt.to_period("W").dt.strftime("%b-%d-%Y")
|
| 65 |
)
|
| 66 |
# preparing the tools graph
|
| 67 |
# adding the total
|
tabs/metrics.py
CHANGED
|
@@ -86,12 +86,12 @@ def plot_trade_metrics(
|
|
| 86 |
# Convert string dates to datetime and sort them
|
| 87 |
all_dates_dt = sorted(
|
| 88 |
[
|
| 89 |
-
datetime.strptime(date, "%b-%d")
|
| 90 |
for date in trades_filtered["month_year_week"].unique()
|
| 91 |
]
|
| 92 |
)
|
| 93 |
# Convert back to string format
|
| 94 |
-
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
| 95 |
fig = px.box(
|
| 96 |
trades_filtered,
|
| 97 |
x="month_year_week",
|
|
|
|
| 86 |
# Convert string dates to datetime and sort them
|
| 87 |
all_dates_dt = sorted(
|
| 88 |
[
|
| 89 |
+
datetime.strptime(date, "%b-%d-%Y")
|
| 90 |
for date in trades_filtered["month_year_week"].unique()
|
| 91 |
]
|
| 92 |
)
|
| 93 |
# Convert back to string format
|
| 94 |
+
all_dates = [date.strftime("%b-%d-%Y") for date in all_dates_dt]
|
| 95 |
fig = px.box(
|
| 96 |
trades_filtered,
|
| 97 |
x="month_year_week",
|
tabs/staking.py
CHANGED
|
@@ -78,12 +78,12 @@ def plot_staking_trades_per_market_by_week(
|
|
| 78 |
# Convert string dates to datetime and sort them
|
| 79 |
all_dates_dt = sorted(
|
| 80 |
[
|
| 81 |
-
datetime.strptime(date, "%b-%d")
|
| 82 |
for date in trades["month_year_week"].unique()
|
| 83 |
]
|
| 84 |
)
|
| 85 |
# Convert back to string format
|
| 86 |
-
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
| 87 |
|
| 88 |
fig = px.bar(
|
| 89 |
trades,
|
|
|
|
| 78 |
# Convert string dates to datetime and sort them
|
| 79 |
all_dates_dt = sorted(
|
| 80 |
[
|
| 81 |
+
datetime.strptime(date, "%b-%d-%Y")
|
| 82 |
for date in trades["month_year_week"].unique()
|
| 83 |
]
|
| 84 |
)
|
| 85 |
# Convert back to string format
|
| 86 |
+
all_dates = [date.strftime("%b-%d-%Y") for date in all_dates_dt]
|
| 87 |
|
| 88 |
fig = px.bar(
|
| 89 |
trades,
|
tabs/tool_win.py
CHANGED
|
@@ -14,7 +14,7 @@ def prepare_tools(tools: pd.DataFrame) -> pd.DataFrame:
|
|
| 14 |
tools = tools.sort_values(by="request_time", ascending=True)
|
| 15 |
|
| 16 |
tools["request_month_year_week"] = (
|
| 17 |
-
pd.to_datetime(tools["request_time"]).dt.to_period("W").dt.strftime("%b-%d")
|
| 18 |
)
|
| 19 |
# preparing the tools graph
|
| 20 |
# adding the total
|
|
@@ -38,7 +38,7 @@ def get_overall_winning_rate_by_market(wins_df: pd.DataFrame) -> pd.DataFrame:
|
|
| 38 |
|
| 39 |
|
| 40 |
def sort_key(date_str):
|
| 41 |
-
month,
|
| 42 |
month_order = [
|
| 43 |
"Jan",
|
| 44 |
"Feb",
|
|
@@ -54,8 +54,9 @@ def sort_key(date_str):
|
|
| 54 |
"Dec",
|
| 55 |
]
|
| 56 |
month_num = month_order.index(month) + 1
|
| 57 |
-
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
def integrated_plot_tool_winnings_overall_per_market_by_week(
|
|
|
|
| 14 |
tools = tools.sort_values(by="request_time", ascending=True)
|
| 15 |
|
| 16 |
tools["request_month_year_week"] = (
|
| 17 |
+
pd.to_datetime(tools["request_time"]).dt.to_period("W").dt.strftime("%b-%d-%Y")
|
| 18 |
)
|
| 19 |
# preparing the tools graph
|
| 20 |
# adding the total
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def sort_key(date_str):
|
| 41 |
+
month, day, year = date_str.split("-")
|
| 42 |
month_order = [
|
| 43 |
"Jan",
|
| 44 |
"Feb",
|
|
|
|
| 54 |
"Dec",
|
| 55 |
]
|
| 56 |
month_num = month_order.index(month) + 1
|
| 57 |
+
day = int(day)
|
| 58 |
+
year = int(year)
|
| 59 |
+
return (year, month_num, day) # year, month, day
|
| 60 |
|
| 61 |
|
| 62 |
def integrated_plot_tool_winnings_overall_per_market_by_week(
|
tabs/trades.py
CHANGED
|
@@ -21,7 +21,7 @@ def prepare_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
|
| 21 |
trades_df["creation_timestamp"].dt.to_period("M").astype(str)
|
| 22 |
)
|
| 23 |
trades_df["month_year_week"] = (
|
| 24 |
-
trades_df["creation_timestamp"].dt.to_period("W").dt.strftime("%b-%d")
|
| 25 |
)
|
| 26 |
trades_df["winning_trade"] = trades_df["winning_trade"].astype(int)
|
| 27 |
return trades_df
|
|
@@ -179,12 +179,12 @@ def integrated_plot_trades_per_market_by_week_v2(trades_df: pd.DataFrame) -> gr.
|
|
| 179 |
# Convert string dates to datetime and sort them
|
| 180 |
all_dates_dt = sorted(
|
| 181 |
[
|
| 182 |
-
datetime.strptime(date, "%b-%d")
|
| 183 |
for date in trades["month_year_week"].unique()
|
| 184 |
]
|
| 185 |
)
|
| 186 |
# Convert back to string format
|
| 187 |
-
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
| 188 |
# Combine the traces
|
| 189 |
final_traces = []
|
| 190 |
market_colors = {"pearl": "darkviolet", "quickstart": "goldenrod", "all": "green"}
|
|
@@ -308,12 +308,12 @@ def integrated_plot_winning_trades_per_market_by_week_v2(
|
|
| 308 |
# Convert string dates to datetime and sort them
|
| 309 |
all_dates_dt = sorted(
|
| 310 |
[
|
| 311 |
-
datetime.strptime(date, "%b-%d")
|
| 312 |
for date in final_df["month_year_week"].unique()
|
| 313 |
]
|
| 314 |
)
|
| 315 |
# Convert back to string format
|
| 316 |
-
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
| 317 |
color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
|
| 318 |
if trader_filter == "Olas":
|
| 319 |
final_df = final_df[final_df["staking_type"] == "Olas"]
|
|
|
|
| 21 |
trades_df["creation_timestamp"].dt.to_period("M").astype(str)
|
| 22 |
)
|
| 23 |
trades_df["month_year_week"] = (
|
| 24 |
+
trades_df["creation_timestamp"].dt.to_period("W").dt.strftime("%b-%d-%Y")
|
| 25 |
)
|
| 26 |
trades_df["winning_trade"] = trades_df["winning_trade"].astype(int)
|
| 27 |
return trades_df
|
|
|
|
| 179 |
# Convert string dates to datetime and sort them
|
| 180 |
all_dates_dt = sorted(
|
| 181 |
[
|
| 182 |
+
datetime.strptime(date, "%b-%d-%Y")
|
| 183 |
for date in trades["month_year_week"].unique()
|
| 184 |
]
|
| 185 |
)
|
| 186 |
# Convert back to string format
|
| 187 |
+
all_dates = [date.strftime("%b-%d-%Y") for date in all_dates_dt]
|
| 188 |
# Combine the traces
|
| 189 |
final_traces = []
|
| 190 |
market_colors = {"pearl": "darkviolet", "quickstart": "goldenrod", "all": "green"}
|
|
|
|
| 308 |
# Convert string dates to datetime and sort them
|
| 309 |
all_dates_dt = sorted(
|
| 310 |
[
|
| 311 |
+
datetime.strptime(date, "%b-%d-%Y")
|
| 312 |
for date in final_df["month_year_week"].unique()
|
| 313 |
]
|
| 314 |
)
|
| 315 |
# Convert back to string format
|
| 316 |
+
all_dates = [date.strftime("%b-%d-%Y") for date in all_dates_dt]
|
| 317 |
color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
|
| 318 |
if trader_filter == "Olas":
|
| 319 |
final_df = final_df[final_df["staking_type"] == "Olas"]
|