|
|
import requests |
|
|
import json |
|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import datetime |
|
|
from st_aggrid import AgGrid, GridOptionsBuilder, JsCode |
|
|
|
|
|
url_pos = "https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition" |
|
|
url = "https://www.binance.com/fr/futures-activity/leaderboard/user?encryptedUid=EE56F412D7DAB7DBAFCEC2147FA2D223" |
|
|
url_perf = "https://www.binance.com/bapi/futures/v2/public/future/leaderboard/getOtherPerformance" |
|
|
url_name = "https://www.binance.com/bapi/futures/v2/public/future/leaderboard/getOtherLeaderboardBaseInfo" |
|
|
headers = { |
|
|
'Content-Type': 'application/json', |
|
|
} |
|
|
|
|
|
def get_data(id: str): |
|
|
payload = json.dumps({ |
|
|
"encryptedUid": id, |
|
|
"tradeType": "PERPETUAL" |
|
|
}) |
|
|
|
|
|
response = requests.request("POST", url_pos, headers=headers, data=payload) |
|
|
|
|
|
x = response.json()["data"]["otherPositionRetList"] |
|
|
itog = [] |
|
|
for i in x: |
|
|
if 'updateTime' in i.keys(): |
|
|
|
|
|
i.pop('updateTime') |
|
|
i.pop('yellow') |
|
|
i.pop('tradeBefore') |
|
|
i["updateTimeStamp"] = datetime.datetime.fromtimestamp(i["updateTimeStamp"]//1000) |
|
|
i["roe"] = i["roe"]*100 |
|
|
i["roe"] = round(i["roe"], 2) |
|
|
i["entryPrice"] = round(i["entryPrice"], 3) |
|
|
i["markPrice"] = round(i["markPrice"], 3) |
|
|
i["pnl"] = round(i["pnl"], 2) |
|
|
|
|
|
itog.append(pd.DataFrame.from_dict([i])) |
|
|
itog = pd.concat(itog , axis=0, ignore_index=True)[["symbol", "amount", "leverage","entryPrice","markPrice", "pnl", "roe","updateTimeStamp"]] |
|
|
return itog |
|
|
|
|
|
|
|
|
def get_name(id: str): |
|
|
payload = json.dumps({ |
|
|
"encryptedUid": id |
|
|
}) |
|
|
|
|
|
response = requests.request("POST", url_name, headers=headers, data=payload) |
|
|
x = response.json()["data"]["nickName"] |
|
|
return x |
|
|
|
|
|
|
|
|
def get_table(id, name): |
|
|
df = get_data(id) |
|
|
gd= GridOptionsBuilder.from_dataframe(df) |
|
|
cellstyle_jscode = JsCode(""" |
|
|
function(params){ |
|
|
if (params.value < '0') { |
|
|
return{ |
|
|
'color': 'red' |
|
|
} |
|
|
} |
|
|
if (params.value > '0') { |
|
|
return{ |
|
|
'color': 'green' |
|
|
} |
|
|
} |
|
|
} |
|
|
""") |
|
|
gd.configure_default_column(min_column_width=1) |
|
|
gd.configure_columns(column_names= ["pnl", "roe", "amount"], cellStyle= cellstyle_jscode) |
|
|
grid_options = gd.build() |
|
|
st.header(name) |
|
|
return AgGrid(df, gridOptions=grid_options, allow_unsafe_jscode=True, fit_columns_on_grid_load=True) |
|
|
|
|
|
with open("./links.txt", 'r') as f: |
|
|
links = f.readlines() |
|
|
links = [i.strip().replace("https://www.binance.com/fr/futures-activity/leaderboard/user?encryptedUid=", "") for i in links] |
|
|
links = {get_name(i):i for i in links} |
|
|
|
|
|
print(links) |
|
|
|
|
|
|
|
|
st.set_page_config(layout="wide") |
|
|
|
|
|
op = st.multiselect("traders", options=links.keys()) |
|
|
print(op) |
|
|
for i, name in enumerate(op): |
|
|
get_table(links[name], name) |
|
|
|
|
|
|