如何转换 html table 中的 2 个数据列表
How Can I Convert 2 list of data in html table
我试图在 Python 中获得我在 Binance 的所有未平仓头寸 这是我的代码 -
from binance.client import Client
client = Client("api key", "secret key")
import pandas as pd
import html
pos_info = client.futures_position_information()
for b in pos_info:
if float(b['positionAmt']) > 0:
print(b)
我得到这个作为输出
{'symbol': 'ETHUSDT', 'positionAmt': '0.283', 'entryPrice': '3520.15', 'markPrice': '3473.53457777', 'unRealizedProfit': '-13.19216449', 'liquidationPrice': '3184.27536722', 'leverage': '10', 'maxNotionalValue': '4000000', 'marginType': 'isolated', 'isolatedMargin': '86.36610623', 'isAutoAddMargin': 'false', 'positionSide': 'BOTH', 'notional': '983.01028550', 'isolatedWallet': '99.55827072', 'updateTime': 1648860967577}
{'symbol': 'SANDUSDT', 'positionAmt': '274', 'entryPrice': '3.642445620438', 'markPrice': '3.63380000', 'unRealizedProfit': '-2.36889988', 'liquidationPrice': '3.31094684', 'leverage': '10', 'maxNotionalValue': '250000', 'marginType': 'isolated', 'isolatedMargin': '97.53375892', 'isAutoAddMargin': 'false', 'positionSide': 'BOTH', 'notional': '995.66120000', 'isolatedWallet': '99.90265880', 'updateTime': 1648864488900}
现在如何在 Html Table
中获取这些值
a = pd.DataFrame()
for b in pos_info:
if float(b['positionAmt']) > 0:
a.append(b, ignore_index=True)
您可以使用 Pandas 函数 to_html
。
df = pd.DataFrame([b for b in pos_info if float(b['positionAmt']) > 0])
df.to_html('output.html', index=False)
输出table:
symbol
positionAmt
entryPrice
markPrice
unRealizedProfit
liquidationPrice
leverage
maxNotionalValue
marginType
isolatedMargin
isAutoAddMargin
positionSide
notional
isolatedWallet
updateTime
ETHUSDT
0.283
3520.15
3473.53457777
-13.19216449
3184.27536722
10
4000000
isolated
86.36610623
false
BOTH
983.01028550
99.55827072
1648860967577
SANDUSDT
274
3.642445620438
3.63380000
-2.36889988
3.31094684
10
250000
isolated
97.53375892
false
BOTH
995.66120000
99.90265880
1648864488900
我试图在 Python 中获得我在 Binance 的所有未平仓头寸 这是我的代码 -
from binance.client import Client
client = Client("api key", "secret key")
import pandas as pd
import html
pos_info = client.futures_position_information()
for b in pos_info:
if float(b['positionAmt']) > 0:
print(b)
我得到这个作为输出
{'symbol': 'ETHUSDT', 'positionAmt': '0.283', 'entryPrice': '3520.15', 'markPrice': '3473.53457777', 'unRealizedProfit': '-13.19216449', 'liquidationPrice': '3184.27536722', 'leverage': '10', 'maxNotionalValue': '4000000', 'marginType': 'isolated', 'isolatedMargin': '86.36610623', 'isAutoAddMargin': 'false', 'positionSide': 'BOTH', 'notional': '983.01028550', 'isolatedWallet': '99.55827072', 'updateTime': 1648860967577}
{'symbol': 'SANDUSDT', 'positionAmt': '274', 'entryPrice': '3.642445620438', 'markPrice': '3.63380000', 'unRealizedProfit': '-2.36889988', 'liquidationPrice': '3.31094684', 'leverage': '10', 'maxNotionalValue': '250000', 'marginType': 'isolated', 'isolatedMargin': '97.53375892', 'isAutoAddMargin': 'false', 'positionSide': 'BOTH', 'notional': '995.66120000', 'isolatedWallet': '99.90265880', 'updateTime': 1648864488900}
现在如何在 Html Table
中获取这些值a = pd.DataFrame()
for b in pos_info:
if float(b['positionAmt']) > 0:
a.append(b, ignore_index=True)
您可以使用 Pandas 函数 to_html
。
df = pd.DataFrame([b for b in pos_info if float(b['positionAmt']) > 0])
df.to_html('output.html', index=False)
输出table:
symbol | positionAmt | entryPrice | markPrice | unRealizedProfit | liquidationPrice | leverage | maxNotionalValue | marginType | isolatedMargin | isAutoAddMargin | positionSide | notional | isolatedWallet | updateTime |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ETHUSDT | 0.283 | 3520.15 | 3473.53457777 | -13.19216449 | 3184.27536722 | 10 | 4000000 | isolated | 86.36610623 | false | BOTH | 983.01028550 | 99.55827072 | 1648860967577 |
SANDUSDT | 274 | 3.642445620438 | 3.63380000 | -2.36889988 | 3.31094684 | 10 | 250000 | isolated | 97.53375892 | false | BOTH | 995.66120000 | 99.90265880 | 1648864488900 |