Search code examples
pythonpandasdataframebinancecryptocurrency

How Can I Convert 2 list of data in html table


I was Trying To Get All Of My Future Open Position at Binance in Python This is my code-

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)

and i get this as output

{'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}

Now How Can I Get These Value In Html Table


Solution

  • You could use the Pandas function to_html.

    df = pd.DataFrame([b for b in pos_info if float(b['positionAmt']) > 0])
    df.to_html('output.html', index=False)
    

    Output 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