Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

I have this code: print(client.getaccounttrades(symbol=symbol)) And it returning me them…

  1. User

    I have this code: print(client.get_account_trades(symbol=symbol))

    And it returning me them : [{'symbol': 'BCHUSDT', 'id': 619335915, 'orderId': 24392236068, 'side': 'BUY', 'price': '231.51', 'qty': '0.108', 'realizedPnl': '0', 'marginAsset': 'USDT', 'quoteQty': '25.00308', 'commission': '0.01250154', 'commissionAsset': 'USDT', 'time': 1700570202533, 'positionSide': 'BOTH', 'buyer': True, 'maker': False}, {'symbol': 'BCHUSDT', 'id': 619335990, 'orderId': 24392240943, 'side': 'SELL', 'price': '231.54', 'qty': '0.108', 'realizedPnl': '0.00324000', 'marginAsset': 'USDT', 'quoteQty': '25.00632', 'commission': '0.01250316', 'commissionAsset': 'USDT', 'time': 1700570226127, 'positionSide': 'BOTH', 'buyer': False, 'maker': False}]

    I need code which will return me latest trade

  2. Assistant

    If you want to retrieve the latest trade from the list, you can use indexing. The last trade in the list will have the highest index, so you can use [-1] to access it. Here's an example:

    latest_trade = client.get_account_trades(symbol=symbol)[-1]
    print(latest_trade)
    

    This code will print the latest trade in the list.

  3. User

    Okay, now code which will print me latest_trade order_id

  4. Assistant

    To print the "orderId" of the latest trade, you can access the corresponding key in the latest_trade dictionary. Here's how you can modify the code to achieve that:

    latest_trade = client.get_account_trades(symbol=symbol)[-1]
    print(latest_trade['orderId'])
    

    This code will print the "orderId" value of the latest trade.

  5. User

    And origClientOrderId

  6. Assistant

    To print the "origClientOrderId" of the latest trade, you can modify the code as follows:

    latest_trade = client.get_account_trades(symbol=symbol)[-1]
    print(latest_trade['origClientOrderId'])
    

    This code will print the value of the "origClientOrderId" key in the latest_trade dictionary, representing the original client order ID of the latest trade.