How to fetch all loan/repay records from Margin Account API

We need to fetch all the loan and repay records from the following endpoints:

Cross margin
/sapi/v1/margin/loan?asset={{symbol}}
/sapi/v1/margin/repay?asset={{symbol}}

Isolated margin
/sapi/v1/margin/loan?asset={{symbol}}&isolatedSymbol={{symbol_pair}}
/sapi/v1/margin/repay?asset={{symbol}}&isolatedSymbol={{symbol_pair}}

Because of the change from 2021-10-14 which restricts the maximum query period to 30 days for these endpoints, we are forced to send several thousand requests in a 30-day loop for every symbol/asset separately to make sure we get all records. This is practically not possible because of the strict IP rate limitations with the Binance API.

Does anyone have any good solution for how to get all the loan + repay records?

Thanks in advance!

Hi @cryptovkng, unfortunately at the moment there’s no additional endpoints or special conditions to query Loan and Repay history besides the ones already mentioned through API.

From now on, it would be best if you could storage those values locally for future consulting (the websocket gives “balanceUpdate” and “outboundAccountPosition” events when loan/repay happens.)

Websockets is unpractical for any 3rd party application.
Would it be possible to at least update the documentation to add the information on each endpoint affected?

Thanks for the quick reply @aisling.

We are completely dependent on fetching the entire history from the REST API endpoints listed, but as I said this is not practically possible right now because of the 30-day max query period introduced not long ago. We cannot use Websocket in this case for our application. It’s very unfortunate that Binance introduces such limitations which break third-party integrations.

Any chance you can escalate this internally to see whether Binance can remove this 30-day query limit?

Even if you spam the API with thousands of requests, how do you get the assets? The exchangeInfo endpoint only provides market pairs, not separate assets. Is there a better way than deriving them from the market pairs?