2
2
3
3
import pandas as pd
4
4
5
-
6
5
pd .options .plotting .backend = "plotly"
7
- from constants import ALL_MARKET_NAMES
8
- from datafetch .api_fetch import get_trades_for_range_pandas
9
- from datafetch .s3_fetch import load_s3_trades_data
10
6
import numpy as np
11
7
import pytz
12
8
import streamlit as st
13
9
10
+ from constants import ALL_MARKET_NAMES
11
+ from datafetch .api_fetch import get_trades_for_range_pandas
12
+ from datafetch .s3_fetch import load_s3_trades_data
13
+
14
14
15
15
def dedupdf (all_markets , market_name , lookahead = 60 ):
16
16
df1 = all_markets .copy ()
@@ -50,8 +50,11 @@ def dedupdf(all_markets, market_name, lookahead=60):
50
50
"date" ,
51
51
]
52
52
).reset_index (drop = True )
53
- oracle_series = df1 .groupby ("ts" )["oraclePrice" ].last ()
53
+ oracle_series = pd . to_numeric ( df1 .groupby ("ts" )["oraclePrice" ].last () )
54
54
55
+ df1 ["quoteAssetAmountFilled" ] = pd .to_numeric (df1 ["quoteAssetAmountFilled" ])
56
+ df1 ["baseAssetAmountFilled" ] = pd .to_numeric (df1 ["baseAssetAmountFilled" ])
57
+ df1 ["oraclePrice" ] = pd .to_numeric (df1 ["oraclePrice" ])
55
58
df1 ["markPrice" ] = df1 ["quoteAssetAmountFilled" ] / df1 ["baseAssetAmountFilled" ]
56
59
df1 ["buyPrice" ] = np .nan
57
60
df1 ["sellPrice" ] = np .nan
@@ -60,10 +63,12 @@ def dedupdf(all_markets, market_name, lookahead=60):
60
63
]
61
64
df1 ["sellPrice" ] = df1 .loc [df1 ["takerOrderDirection" ] == "short" , "markPrice" ]
62
65
63
- df1 ["takerPremium" ] = (df1 ["markPrice" ] - df1 ["oraclePrice" ]) * (
64
- 2 * (df1 ["takerOrderDirection" ] == "long" ) - 1
66
+ df1 ["takerPremium" ] = (
67
+ pd .to_numeric (df1 ["markPrice" ]) - pd .to_numeric (df1 ["oraclePrice" ])
68
+ ) * (2 * (df1 ["takerOrderDirection" ] == "long" ) - 1 )
69
+ df1 ["takerPremiumDollar" ] = pd .to_numeric (df1 ["takerPremium" ]) * pd .to_numeric (
70
+ df1 ["baseAssetAmountFilled" ]
65
71
)
66
- df1 ["takerPremiumDollar" ] = df1 ["takerPremium" ] * df1 ["baseAssetAmountFilled" ]
67
72
df1 ["takerPremiumNextMinute" ] = (
68
73
df1 ["markPrice" ]
69
74
- df1 ["ts" ].apply (
@@ -217,8 +222,8 @@ def make_clickable(link):
217
222
"takerPremium" : "mean" ,
218
223
"takerPremiumNextMinute" : "mean" ,
219
224
"takerPremiumDollar" : "sum" ,
220
- "takerFee" : " sum" ,
221
- "makerFee" : " sum" ,
225
+ "takerFee" : lambda x : pd . to_numeric ( x ). sum () ,
226
+ "makerFee" : lambda x : pd . to_numeric ( x ). sum () ,
222
227
}
223
228
)
224
229
)
@@ -245,8 +250,8 @@ def make_clickable(link):
245
250
"takerPremium" : "mean" ,
246
251
"takerPremiumNextMinute" : "mean" ,
247
252
"takerPremiumDollar" : "sum" ,
248
- "takerFee" : " sum" ,
249
- "makerFee" : " sum" ,
253
+ "takerFee" : lambda x : pd . to_numeric ( x ). sum () ,
254
+ "makerFee" : lambda x : pd . to_numeric ( x ). sum () ,
250
255
}
251
256
)
252
257
)
@@ -267,12 +272,11 @@ def make_clickable(link):
267
272
st .dataframe (df2 )
268
273
269
274
if user_type != "vAMM" :
270
-
271
275
zol1 , zol2 , zol3 = st .columns (3 )
272
276
273
- takerfee = solperp ["takerFee" ].sum ()
274
- makerfee = solperp ["makerFee" ].sum ()
275
- fillerfee = solperp ["fillerReward" ].sum ()
277
+ takerfee = pd . to_numeric ( solperp ["takerFee" ]) .sum ()
278
+ makerfee = pd . to_numeric ( solperp ["makerFee" ]) .sum ()
279
+ fillerfee = pd . to_numeric ( solperp ["fillerReward" ]) .sum ()
276
280
277
281
showprem = zol3 .radio ("show premiums in plot" , [True , False ], 1 )
278
282
showmarkoutfees = zol3 .radio (
@@ -401,7 +405,7 @@ def make_clickable(link):
401
405
st .metric (
402
406
"vAMM volume:" ,
403
407
"$" + f"{ vamm_maker_trades ['quoteAssetAmountFilled' ].sum ().round (2 ):,} " ,
404
- f"{ vamm_maker_trades ['quoteAssetAmountFilled' ].sum ().round (2 )/ solperp ['quoteAssetAmountFilled' ].sum ().round (2 )* 100 :,.2f} % of maker volume" ,
408
+ f"{ vamm_maker_trades ['quoteAssetAmountFilled' ].sum ().round (2 ) / solperp ['quoteAssetAmountFilled' ].sum ().round (2 ) * 100 :,.2f} % of maker volume" ,
405
409
)
406
410
tabs = st .tabs (["plot" , "table" ])
407
411
0 commit comments