Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decrease latency on Binance API orderbook calls? [closed]

I am currently attempting to decrease latency when calling the orderbook with the Binance API.

I am getting a ping of ~7ms but the orderbook call takes ~200ms to download. I am using a VM hosted in the same AWS farm that Binance uses, and I am running on a network speed of ~800mbps. I do not understand why the orderbook call takes nearly two orders of magnitude more time to receive than the time it takes to ping the server when the size of the orderbook is relatively small.

Any help or insight into either the network, or restrictions imposed by Binance would be greatly appreciated.

like image 286
PierceT Avatar asked Sep 16 '25 02:09

PierceT


1 Answers

Important distinction:

  • Ping: goes to the nearest CDN edge node, which responds to you; you don't get anywhere near a Binance server.

  • API request: goes to the nearest CDN edge node, gets routed to the Binance server, gets processed, then the response is routed back to you.

Binance servers are hosted on AWS in Tokyo. If you place your host there, the latency will be about 12-15ms (2ms from when Binance sent the response.)

To lower the average latency, you may try to post idempotent requests in parallel, and then use the response that arrives first. It's rude but it gets the job done.

As a random note, client order IDs are reusable, which makes them useless as a method of making orders idempotent. (However, if you use fixed order sizes, you could preemptively lock all the rest of your funds, then hammer Binance with order placements knowing a duplicate order couldn't succeed since you wouldn't have funds.)

like image 56
Tiana Avatar answered Sep 17 '25 20:09

Tiana