How to reduce the ping response from the server

There is a link to get data via the API, https://api.binance.com/api/v1/depth?symbol=BTCUSDT it works with a constraint. you can receive no more than 1 request per second. (1 thread!) This is not a limitation, but a large ping, because the site works through Amazon CloudFront servers. Like Cloudflare. And all the information goes through it. Because of this, as I understand it, a large chain is obtained: The request comes from the user on

Api.binance.com > Amazon CloudFront > Primary server responds > Amazon CloudFront > api.binance.com > user.

How can I bypass Amazon CloudFront protection and find direct addresses? Or shorten the chain, reduce the ping of the server response. For example so:

User > Amazon CloudFront > The primary server returns the response > Amazon CloudFront > User.

Or even somehow go to the direct server and get a response from it. without Amazon CloudFront. There are any options?

I know that people bypass this protection and achieve a ping [0.050 sec] of about 20 responses per second. [1 thread]

I write in C#, I work with the server like this:

string userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0";
string url = "https://api.binance.com/api/v1/depth?symbol=BTCUSDT";
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest) System.Net.WebRequest.Create(url);
request.Method = "GET";
request.UserAgent = userAgent;
request.Headers.Add("Accept-Language", "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3");
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse) request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string resultGet = reader.ReadToEnd();
response.Close();
reader.Close();
return resultGet;

Using threads, we got the following code. But with it, the delay only gets longer. Here I run {[6] in parallel]}

    static List<float> list = new List<float> { };
    static List<Thread> threads = new List<Thread>();   // Список потоков
    static int threadCount = 50;                        // Число потоков
    static ManualResetEvent startEvent = new ManualResetEvent(false);   // Событие для старта рабочих потоков
    static volatile int starterCount = 0;               // Счётчик запущенных потоков. volatile показывает, что переменная будет изменяться в различных потоках и её не надо оптимизировать
    static object LockObject = new object();            // Блокировка для изменения переменной starterCount
    static int count = 0;

    static void Main(string[] args)
    {
        // Создаём пул потоков
        for (int i = 0; i < threadCount; i++)
        {
            Thread thread = new Thread(Work);
            threads.Add(thread);
        }
        // На старт — запускаем стартовые потоки и ждём их запуска
        foreach (var thread in threads)
            new Thread(Starting).Start(thread);
        while (starterCount < threadCount) Thread.Sleep(1);
        // Внимание — к этому моменту все стартовые потоки запустились и ожидают на WaitOne()
        Thread.Sleep(100);
        // Марш — установка события отпускает приостановленные потоки
        startEvent.Set();

        Console.Read();

        float sum = 0;
        foreach(var i in list)
        {
            sum += i;
        }

        float srznach = sum / 50f;

    }

    static void Work()
    {
        System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch();
        st.Start();

        string userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0";
        string url = "https://api.binance.com/api/v1/depth?symbol=BTCUSDT";
        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
        System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
        request.Method = "GET";
        request.UserAgent = userAgent;
        request.Headers.Add("Accept-Language", "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3");
        System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
        string resultGet = reader.ReadToEnd();
        response.Close();
        reader.Close();

        st.Stop();

        float s = st.ElapsedMilliseconds / 1000f;
        list.Add(s);
        count++;
        Console.WriteLine(s.ToString()+" "+ count.ToString());
    }


    static void Starting(object paramThread)
    {
        lock (LockObject)
        {
            starterCount++;
        }
        startEvent.WaitOne();
        (paramThread as Thread).Start();
    }

When starting each new thread, ping only increases:

сек  |   номер потока

1,237 1
1,784 2
2,062 3
2,586 4
2,975 5
3,394 6
3,674 7
3,593 8
3,94 9
4,236 10
4,514 11
4,38 12
4,776 13
4,844 14
5,066 15
5,112 16
5,342 17
5,615 18
5,923 19
5,995 20
6,196 21
6,267 22
6,465 23
6,554 24
6,745 25
6,808 26
7,097 27
7,358 28
7,553 29
7,645 30
7,812 31
7,932 32
8,204 33
8,206 34
8,461 35
8,473 36
8,736 37
8,746 38
9,009 39
9,096 40
9,301 41
9,382 42
9,582 43
9,862 44
10,123 45
10,398 46
10,674 47
11,471 48
11,856 49
12,141 50
Author: KABAN PUNK, 2018-05-17

1 answers

Specifically, the ping depends on:

  • From an Internet service provider
  • From how far the server to which we connect is removed
  • From the load of your Internet channel

You yourself are unlikely to be able to do anything, because it does not depend on you in any way.
As an option, place your server close to the service that you are going to connect to, or try to change the provider and Internet speed.

 1
Author: And, 2018-05-17 03:14:49