Position funding fee tracking

Hello,

I am trying to implement position funding fee tracking based on ACCOUNT_UPDATE websocket event (as per Binance API Documentation, reason FUNDING_FEE) but unfortunately I have encountered certain difficulties:

  • In case there are multiple crossed positions for different assets the websocket event is received multiple times (for each possition/asset), but there is no way how to identify which position/asset the specific event belongs to because there is neither position message nor asset symbol.

I know I can retrieve position funding fee from its income history, but I would rather prefer to rely on websockets only, if there was any way how to get the position funding fee (?) Or at least the symbol from the event…

  • As per the documentation, funding fee is calculated as Size * MarkPrice * FundingRate. I can reliably retrieve the correct FundingRate, but I cannot figure out what value of MarkPrice is used for the calculation? I have determined from the position history (by reverse division) that the used mark price is very close to Close price of the MarkPrice minute candle preceding the funding time (e.g. for 8:00 UTC funding the mark price is almost 1M 7:59 candle’s Close price; the differences do not seem to be caused by rounding).

Thus, I am really curious what MarkPrice value exactly is used for funding fee calcuation? Even if it could not be retrieved from candle history or any other API call…

  • And lastly, is there any somewhat “guaranteed” deadline time for funding fee websocket events? I.e. when it is safe to assume there will be no more incoming events (for the current funding)?

I guess/hope I could workaround the existing limitations by accumulating position funding fees and then calculate individual fees based on size ratios, but I would need to know when it is safe to do so; with the shortest delay.

Thank you for your patience.

Regards

  • In case there are multiple crossed positions for different assets the websocket event is received multiple times (for each possition/asset), but there is no way how to identify which position/asset the specific event belongs to because there is neither position message nor asset symbol.

FUNDING_FEE events from cross position cannot be correlated to the specific position using the websocket.

  • As per the documentation, funding fee is calculated as Size * MarkPrice * FundingRate. I can reliably retrieve the correct FundingRate, but I cannot figure out what value of MarkPrice is used for the calculation? I have determined from the position history (by reverse division) that the used mark price is very close to Close price of the MarkPrice minute candle preceding the funding time (e.g. for 8:00 UTC funding the mark price is almost 1M 7:59 candle’s Close price; the differences do not seem to be caused by rounding).

The specific mark price used is not provided by the server but it can be deduced by reverse engineering using the funding rate and balance change. Using the kline endpoint only provides an estimate as the mark price used may fall anywhere between the openPrice and closePrice of the kline.

  • And lastly, is there any somewhat “guaranteed” deadline time for funding fee websocket events? I.e. when it is safe to assume there will be no more incoming events (for the current funding)?

There is no official “deadline” for the latency of the events.

Thanks for the prompt response!

Ok, but for crossed positions I do not know which balance change (in FUNDING_FEE event) relates to which position/asset.

Edit: Would it be at least possible to correlate websocket events with a certain position timestamp or numerical order?

Thanks.

Unfortunately, this also cannot be done via the websocket for cross positions.

1 Like