Recreating futures balance before order execution

Hi, I inspect my USDT Futures trade history and try to calculate the USDT wallet balance before order execution.
Imagine my order BTCUSDT was executed at 2020-12-30 12:13:45

  • I take USDT snapshot balance from the previous day: get snapshot 2020-12-30 + 1 day

  • sum all income from incomes where income time >= 2020-12-30 00:00:00 and < 2020-12-30 12:13:45

  • order.executedqty * order.price
    Then I sum up all three numbers and expect to get wallet balance.
    I see that order.executedqty * order.price is greater than “total balance” at some cases.
    This I don’t understand. Example:

    USDT snapshot balance 2020-12-30 + 1 day = 0.53742687
    income during day 2020-12-30 before 12:13:45 (order creation time) -5.69070634
    order.executedqty * order.price = 8.196
    total_balance = 3.04272053 = 0.53742687 -5.69070634 + 8.196

how is it possible? order is greater than balance

Hi.
May I clarify some points of your question:

  1. What is your order? Is it a SELL order exchanging BTC to USDT?
  2. What kind of the income is considered?
  3. Is there any other trade that USDT is involved in that specific period of time?
  4. How did you get the final balance after the order execution?

Hi ishuen!
Thanks for your response

  1. USDT Futures, That is buy / sell
  2. All income: deposit, withdraw, pnl, comission
  3. How can I figure it out using API? I work with filled orders only, with historical data
  4. I have no idea. That’s the question. My goal is to “recreate” balance amount at order creation. I want to know what was the proportion of oder and balance? Did trader decided to go all in user 100% of balance or did he put only 55% of it?

Hi.
Can you try this endpoint GET /fapi/v1/income ( https://binance-docs.github.io/apidocs/futures/en/#get-income-history-user_data ) and see if there are some records with incomeType = FUNDING_FEE? Probably that’s the reason of mismatch.

1 Like

I think I follow what do I do wrong.
I take order price and qty and multiply it, but I don’t know what was the leverage for order…

Please check this endpoint GET /fapi/v2/positionRisk ( https://binance-docs.github.io/apidocs/futures/en/#position-information-v2-user_data ). You will be able to find the leverage for each position.