v3/myTrades: Determining Cost Basis from Trade History

My software has a requirement to get the Dollar Cost Average price (VWAP) from a list of filled orders over the past several weeks or months. When doing this we need to make over 100 requests per market and it takes an unnecessarily long time. Even if I cache all the results locally that’s still a lot of requests for each trading pair.

Please allow us to query more than one day at a time of order fill information or provide better way of grabbing trade history for a symbol. (Maybe via Websocket?)

Ideally, I’d like to get all filled orders within the last month, you can do this on most other exchanges. {"code":-1127,"msg":"More than 24 hours between startTime and endTime."}

Or can anyone think of a better way to make this work than having to make a request for every 24h period since startTime?

thanks @jaggedsoft

The image was deleted as it’s not allowed to promote any trading software here.

  1. Returning a large data set from one single restful request is NOT a good idea.
    a. Server takes many time to look up from database
    b. Server takes many time to prepare these data before returning response.
    c. Transferring large data over the networking need more time.
    d. In general the client has to wait a long time for the response. If google map give you a blank page before downloading the whole map, I guess a user will think there is a connection issue or just close the page.

Client shouldn’t expect to get all data from one request, It “seems” very easy to implement from server, it “seems” offering a convenience to the users.
No, it’s not. You will regret to open an 500MB csv file in the 4G memory PC.

By passing the time window, paginating the order history is still the best and only way to work.

  1. if you have the listenKey, connect to the websocket stream, that’s fast and convenient.

Thanks for your response.

if you have the listenKey, connect to the websocket stream, that’s fast and convenient.

You’re referring to the execution report? This only helps you with current orders, not ones that happened last week. How would you find your average entry price in the recent past? Otherwise good advice, everyone should be depending on WebSocket whenever possible.

Returning a large data set from one single restful request is NOT a good idea.

How have the other top-tier exchanges solved this issue? Binance is the only one with this limitation. On the web interface you can also clearly and easily see your trade history. Why not with your API as well? Your web interface allows searching one week between startTime and endTime, which is an acceptable solution and way more reasonable than 24 hours. This would reduce 50 requests down to 7.

Solution

For anyone else who might come across this thread, the only solution appears to be using allOrders:

If you know the market name, such as BNBUSDT, call allOrders with no startTime or endTime. Instead set limit:1000 and it will return up to 1000 items, you just have to filter the cancelled and open orders out of your results.

An alternative way would be paging by tradeId and leaving startTime and endTime out due to their limitations. {"code":-1127,"msg":"More than 24 hours between startTime and endTime."}

Using allOrders or myTrades endpoints you can make 240 requests per minute to download any past history. If you need to export your past trade history as csv you can do it from the website: https://www.binance.com/en/my/orders/exchange/tradeorder Once you have all the necessary price history then you should be using WebSockets to keep everything up to date in realtime.

For historical data, by following the request limit rule, you will get the whole trade data eventually.

We’re always improving our design and features set, so in the future, larger queries like yours might be easier.

1 Like