How to get the value of portfolios if using margin trading?

Hi! I am creating a service for calculating the profitability of a trader’s trade.

I need to calculate the profitability on historical data, and if it seems clear for the spot:
we take all deposits / withdraws, buy and sell orders and consider that we entered 1 BTC, bought 10 ETH, then sold for EOC, I can get a historical ticker for EOC in BTC and understand how much was spent and received. BTC is at this level, but how do you deal with margin trading?

For margin trading, there are load and interest involved. So similar to spot, you will have to query the loan, repay and interest history, then calculate the profit based on these data.

The endpoints are:

  • GET /sapi/v1/margin/loan
  • GET /sapi/v1/margin/repay
  • GET /sapi/v1/margin/interestHistory

And please find the document at

https://binance-docs.github.io/apidocs/spot/en/#query-repay-record-user_data