GOKULSINGHSHAH123
commited on
Commit
•
510a7ae
1
Parent(s):
1af2ab2
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,8 @@ file_mapping = {
|
|
26 |
"usdm": "usdm_trade_history.csv",
|
27 |
"coinm": "coinm_trade_history.csv",
|
28 |
"copyLeaderboard": "copyLeaderboard_trade_history.csv",
|
29 |
-
"okx": "okx_history.csv"
|
|
|
30 |
}
|
31 |
|
32 |
# Streamlit App
|
@@ -73,7 +74,8 @@ df['positionClosed'] = False
|
|
73 |
|
74 |
if option =="copyLeaderboard":
|
75 |
uid_input = int(st.text_input("Enter U_IDs to filter"))
|
76 |
-
|
|
|
77 |
else:
|
78 |
uid_input = str.upper(st.text_input("Enter U_IDs to filter"))
|
79 |
|
@@ -106,7 +108,11 @@ if df is not None and uid_input:
|
|
106 |
modified_positions = data['Modified']
|
107 |
# modified_positions = modified_positions[0]
|
108 |
if isinstance(modified_positions, dict) and 'amount' in modified_positions:
|
109 |
-
|
|
|
|
|
|
|
|
|
110 |
if isinstance(amount, (int, float)): # Check if amount is a number
|
111 |
amounts =amount
|
112 |
# Check if 'ClosedTrades' key exists and extract amounts
|
@@ -114,7 +120,10 @@ if df is not None and uid_input:
|
|
114 |
closed_trades = data['ClosedTrades']
|
115 |
closed_trades =closed_trades[0]
|
116 |
if isinstance(closed_trades, dict) and 'amount' in closed_trades:
|
117 |
-
|
|
|
|
|
|
|
118 |
if isinstance(amount, (int, float)): # Check if amount is a number
|
119 |
amounts = amount
|
120 |
|
@@ -158,7 +167,10 @@ if df is not None and uid_input:
|
|
158 |
symbol = trade_list[i]['symbol']
|
159 |
side ="buy" if trade_list[i]['amount']>0 else "sell"
|
160 |
amount = trade_list[i]['amount']
|
161 |
-
|
|
|
|
|
|
|
162 |
trade_list[i]['side'] =side
|
163 |
trade_list[i]['changeInAmount'] = changeInAmount
|
164 |
trade_list[i]['i'] = i
|
@@ -176,7 +188,11 @@ if df is not None and uid_input:
|
|
176 |
new_position = entry.get('NewPosition', {})
|
177 |
# Extract symbol and amount
|
178 |
symbol = new_position.get('symbol')
|
179 |
-
|
|
|
|
|
|
|
|
|
180 |
if option != "copyLeaderBoard":
|
181 |
if start==False:
|
182 |
start_time = new_position.get('updateTime')
|
@@ -426,7 +442,21 @@ if df is not None and uid_input:
|
|
426 |
'Weighted Score Ratio': df_history['weightedScoreRatio'], # New field
|
427 |
'Transaction Value in USDT': df_history['amount'] * df_history['markPrice'], # New calculation
|
428 |
'Profit/Loss Ratio': (df_history['markPrice'] - df_history['entryPrice']) / df_history['entryPrice'] # New calculation
|
429 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
430 |
|
431 |
if 'closed' in df_history.columns:
|
432 |
df_transformed['Position closed'] = df_history['closed']
|
@@ -479,6 +509,17 @@ if df is not None and uid_input:
|
|
479 |
key=button_key
|
480 |
):
|
481 |
show_position_history(row['i'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
482 |
else:
|
483 |
if st.button(
|
484 |
f"{row['symbol']} : Long: {side}, Entry Price: {row['entryPrice']}, "
|
|
|
26 |
"usdm": "usdm_trade_history.csv",
|
27 |
"coinm": "coinm_trade_history.csv",
|
28 |
"copyLeaderboard": "copyLeaderboard_trade_history.csv",
|
29 |
+
"okx": "okx_history.csv",
|
30 |
+
"buybit": "buybit.csv"
|
31 |
}
|
32 |
|
33 |
# Streamlit App
|
|
|
74 |
|
75 |
if option =="copyLeaderboard":
|
76 |
uid_input = int(st.text_input("Enter U_IDs to filter"))
|
77 |
+
if option =="buybit":
|
78 |
+
uid_input = (st.text_input("Enter U_IDs to filter"))
|
79 |
else:
|
80 |
uid_input = str.upper(st.text_input("Enter U_IDs to filter"))
|
81 |
|
|
|
108 |
modified_positions = data['Modified']
|
109 |
# modified_positions = modified_positions[0]
|
110 |
if isinstance(modified_positions, dict) and 'amount' in modified_positions:
|
111 |
+
if option =="okx":
|
112 |
+
print("reached")
|
113 |
+
amount = modified_positions.get('amount')/modified_positions.get('markPrice')
|
114 |
+
else:
|
115 |
+
amount = modified_positions.get('amount')
|
116 |
if isinstance(amount, (int, float)): # Check if amount is a number
|
117 |
amounts =amount
|
118 |
# Check if 'ClosedTrades' key exists and extract amounts
|
|
|
120 |
closed_trades = data['ClosedTrades']
|
121 |
closed_trades =closed_trades[0]
|
122 |
if isinstance(closed_trades, dict) and 'amount' in closed_trades:
|
123 |
+
if option == "okx":
|
124 |
+
amount = closed_trades.get('amount')/closed_trades.get('markPrice')
|
125 |
+
else:
|
126 |
+
amount = closed_trades.get('amount')
|
127 |
if isinstance(amount, (int, float)): # Check if amount is a number
|
128 |
amounts = amount
|
129 |
|
|
|
167 |
symbol = trade_list[i]['symbol']
|
168 |
side ="buy" if trade_list[i]['amount']>0 else "sell"
|
169 |
amount = trade_list[i]['amount']
|
170 |
+
if option =="okx":
|
171 |
+
amount = trade_list[i]['amount']/trade_list[i]['markPrice']
|
172 |
+
else:
|
173 |
+
symbol = trade_list[i]['symbol']
|
174 |
trade_list[i]['side'] =side
|
175 |
trade_list[i]['changeInAmount'] = changeInAmount
|
176 |
trade_list[i]['i'] = i
|
|
|
188 |
new_position = entry.get('NewPosition', {})
|
189 |
# Extract symbol and amount
|
190 |
symbol = new_position.get('symbol')
|
191 |
+
|
192 |
+
if option =="okx":
|
193 |
+
amount = new_position.get('amount')/new_position.get('markPrice')
|
194 |
+
else:
|
195 |
+
amount = new_position.get('amount')
|
196 |
if option != "copyLeaderBoard":
|
197 |
if start==False:
|
198 |
start_time = new_position.get('updateTime')
|
|
|
442 |
'Weighted Score Ratio': df_history['weightedScoreRatio'], # New field
|
443 |
'Transaction Value in USDT': df_history['amount'] * df_history['markPrice'], # New calculation
|
444 |
'Profit/Loss Ratio': (df_history['markPrice'] - df_history['entryPrice']) / df_history['entryPrice'] # New calculation
|
445 |
+
})
|
446 |
+
if option == "okx":
|
447 |
+
df_transformed = pd.DataFrame({
|
448 |
+
'Pair/Asset': df_history['symbol'],
|
449 |
+
'is long': df_history['side'],
|
450 |
+
'Current size after change': df_history['usdAmount'],
|
451 |
+
'Change in size in Asset': df_history['changeInAmount'],
|
452 |
+
'Change in size in USDT': df_history['changeInAmount'] * -(df_history['markPrice']),
|
453 |
+
'Entry price': df_history['entryPrice'],
|
454 |
+
'Exit price': df_history['markPrice'],
|
455 |
+
'pnl in usdt': df_history['pnl'],
|
456 |
+
'pnl in %': df_history['roe'],
|
457 |
+
'Leverage': df_history['leverage'],
|
458 |
+
'updatedTime': df_history['updateTime']
|
459 |
+
})
|
460 |
|
461 |
if 'closed' in df_history.columns:
|
462 |
df_transformed['Position closed'] = df_history['closed']
|
|
|
509 |
key=button_key
|
510 |
):
|
511 |
show_position_history(row['i'])
|
512 |
+
|
513 |
+
if option =="okx":
|
514 |
+
if st.button(
|
515 |
+
f"{row['symbol']} : Long: {side}, Entry Price: {row['entryPrice']}, "
|
516 |
+
f"Market Price: {row['markPrice']}, Amount: {row['usdAmount']}, "
|
517 |
+
f"Leverage: {row['leverage']}, TradeTakenAt: {row['updateTime']}, "
|
518 |
+
f"lastUpdated: {lastUpdated(row['i'])}, isClosed: {is_closed}",
|
519 |
+
key=button_key
|
520 |
+
):
|
521 |
+
show_position_history(row['i'])
|
522 |
+
|
523 |
else:
|
524 |
if st.button(
|
525 |
f"{row['symbol']} : Long: {side}, Entry Price: {row['entryPrice']}, "
|