sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.14k stars 2.23k forks source link

Binance alternative urls for better performance #697

Open xtile opened 3 years ago

xtile commented 3 years ago

Hi!

Have you considered to support alternative binance api urls?

Like API_URL = 'https://apiX.binance.{}/api'

where X belongs to ["", "1", "2", "3"]

Here is the example on how it works for me:

cmach@cmach1:~$ ping api.binance.com PING d3h36i1mno13q3.cloudfront.net (52.84.150.34) 56(84) bytes of data. 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=1 ttl=237 time=99.9 ms 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=2 ttl=237 time=100.0 ms 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=3 ttl=237 time=100 ms 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=4 ttl=237 time=100.0 ms 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=5 ttl=237 time=100 ms 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=6 ttl=237 time=100.0 ms 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=7 ttl=237 time=99.9 ms 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=8 ttl=237 time=99.9 ms 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=9 ttl=237 time=100.0 ms 64 bytes from 52.84.150.34 (52.84.150.34): icmp_seq=10 ttl=237 time=100 ms ^C --- d3h36i1mno13q3.cloudfront.net ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 9010ms rtt min/avg/max/mdev = 99.911/99.965/100.016/0.034 ms

cmach@cmach1:~$ ping api3.binance.com PING d1rtiksidvgi3p.cloudfront.net (52.84.226.14) 56(84) bytes of data. 64 bytes from server-52-84-226-14.sin2.r.cloudfront.net (52.84.226.14): icmp_seq=1 ttl=247 time=0.894 ms 64 bytes from server-52-84-226-14.sin2.r.cloudfront.net (52.84.226.14): icmp_seq=2 ttl=247 time=0.473 ms 64 bytes from server-52-84-226-14.sin2.r.cloudfront.net (52.84.226.14): icmp_seq=3 ttl=247 time=0.380 ms 64 bytes from server-52-84-226-14.sin2.r.cloudfront.net (52.84.226.14): icmp_seq=4 ttl=247 time=0.362 ms 64 bytes from server-52-84-226-14.sin2.r.cloudfront.net (52.84.226.14): icmp_seq=5 ttl=247 time=0.491 ms 64 bytes from server-52-84-226-14.sin2.r.cloudfront.net (52.84.226.14): icmp_seq=6 ttl=247 time=0.385 ms ^C --- d1rtiksidvgi3p.cloudfront.net ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5085ms rtt min/avg/max/mdev = 0.362/0.497/0.894/0.183 ms

I have tried from several locations, including Singapore, Tokyo and Amsterdam) and every time alternative urls work much faster.

RastislavMirek commented 3 years ago

+1

oliver-zehentleitner commented 3 years ago

Does this work for websockets too?

selimozbas commented 3 years ago

+1 and what is difference v1 and v3?

oliver-zehentleitner commented 3 years ago

its not a version, they are different sites

selimozbas commented 3 years ago

I know that is different sites. I mean api version. when I check the official binance docs, I see api v1, v2, v3

xtile commented 3 years ago

+1 and what is difference v1 and v3?

your question does not relate to this topic.

Though, as far as I remember, v3 is for spot trading (api moved on v3 two years ago from v1). So so its just a matter of version number.

kasper747 commented 3 years ago

If you want to improve your ping, use local instances and run your execution there. I did extensive testing and here are the results. It looks like they have local servers in Tokyo and New Jersey. So you can get as low as 10ms including already the calculation from the server. It's not just ping. 100ms for just a ping is definitely too high.

time for price request Using this server provider: https://www.vultr.com/?ref=8815565-6G. You get 100$ credits with them. Much simplier to use than AWS.