Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket: Could not connect: HTTP/1.1 504 Gateway Time-out #150

Closed
Marc008 opened this issue May 18, 2018 · 8 comments
Closed

WebSocket: Could not connect: HTTP/1.1 504 Gateway Time-out #150

Marc008 opened this issue May 18, 2018 · 8 comments

Comments

@Marc008
Copy link

Marc008 commented May 18, 2018

Hello,

I'm not sure if this is a bug, or I'm abusing the API (however I don't get any 429 or 418 HTTP codes), but I'm getting a lot of 504 Gateway Time-out when trying to pull data through WebSocket.

My code is like this:

try {
    $Binance->kline(getSymbols(), "1m", function($Binance, $symbol, $chart) {
        global $RabbitMQ;

        if ($chart->x == true) {
            $message = json_encode($chart, JSON_PRESERVE_ZERO_FRACTION);

            $queue = 'tickers';
            $RabbitMQ->publishMsg($queue, $message);
        }
    });
} catch(Exception $e) {
    echo 'Message: ' .$e->getMessage();
}

getSymbols() get the entire list of symbols from Binance (315 pairs) and convert them to an array.

I have been running this script for an entire day in local, then I moved it to a server and I started to get this errors. I thought it could be because I was using the same Binance key/secret in both environments at the same time, so I asked for another key/secrets from a different Binance account. It's weird because since I have done this I haven't been able to run the script in the remote server, and I have had to try for more than 1 hour to make it run in local.

Are 315 symbols too much to ask? If not, would it be possible to check the disconnections (or failure to connect) and try again? It looks like it's a matter of trying, because the error sometimes talks about one pair, then about a different one:

kline(MDABTC,1m)) Could not connect: HTTP/1.1 504 Gateway Time-out
Server: awselb/2.0
Date: Fri, 18 May 2018 07:51:35 GMT
Content-Type: text/html
Content-Length: 148
Connection: keep-alive

<title>504 Gateway Time-out</title>

504 Gateway Time-out

My PHP version is: PHP 7.0.27-0+deb9u1 (cli), running in Debian 9.4 kernel: 4.9.0-4-amd64 #1 SMP Debian 4.9.65-3+deb9u1

Thanks in advance.

@jaggedsoft
Copy link
Owner

This is an issue on the binance side I believe, unless you actually are abusing the api and sending too many requests and get a 418/429 error

Perhaps there is a better way to handle this type of event but I can't think of one off the top of my head
One thing that I have tried, and it may have prevented this problem altogether, is switch your nameserver to cloudflare's 1.1.1.1
See this guide: https://1.1.1.1/

@jaggedsoft
Copy link
Owner

Is there any update on this?

@Marc008
Copy link
Author

Marc008 commented Jun 3, 2018

Hello,

I'm still getting errors. I'm running the script with supervisorctl, so it restarts each time that crash.

I'm pretty sure I'm not abusing the API because the error is 500, not 429/418. Maybe it's some kind of overload on Binance. Sometimes the script run for more than 4 days, which is strange because I thought that Binance shuts down the connection each 24h.

Thanks.

@Marc008
Copy link
Author

Marc008 commented Jun 25, 2018

Hello,

I have some more info today. As I said I put the script under supervisor so it would be relaunched whenever it dies. Today we noticed that the prices weren't being updated, so checking the logs I saw that since 7 hours ago, the response from Binance stopped being "504 Gateway Time-out" to "403 Forbidden" and has been in that way since then:

kline(BCPTETH,1m)) Could not connect: HTTP/1.1 504 Gateway Time-out
Server: awselb/2.0
Date: Mon, 25 Jun 2018 07:47:43 GMT
Content-Type: text/html
Content-Length: 148
Connection: keep-alive

<title>504 Gateway Time-out</title>

504 Gateway Time-out

kline(ENGETH,1m)) Could not connect: HTTP/1.1 504 Gateway Time-out
Server: awselb/2.0
Date: Mon, 25 Jun 2018 07:47:54 GMT
Content-Type: text/html
Content-Length: 148
Connection: keep-alive

<title>504 Gateway Time-out</title>

504 Gateway Time-out

kline(MTLBTC,1m)) Could not connect: HTTP/1.1 403 Forbidden
Server: awselb/2.0
Date: Mon, 25 Jun 2018 07:47:55 GMT
Content-Type: text/html
Content-Length: 134
Connection: keep-alive

<title>403 Forbidden</title>

403 Forbidden

@jaggedsoft
Copy link
Owner

It becomes forbidden after making too many requests

https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
code 429 is issued when you are going over the rate limit
code 418 indicates you've been ip banned
403 means forbidden, which may happen if you've made way too many requests in too short of a time

most of the heavy lifting can be done by websockets, which are free to use

todo: implement accountInfo function which confirms you are IP banned

@GalacticSun
Copy link

Not sure if it's related, but Binance did perform a system upgrade and had an extended downtime yesterday (~6hrs). Could this account for your errors? https://support.binance.com/hc/en-us/sections/115000202591-Latest-News

@Marc008
Copy link
Author

Marc008 commented Jun 29, 2018

Nope, it wasn't. Once the maintenance starter I just stopped receiving any data, no error either. The error that I reported was several hours before.

@dmzoneill
Copy link
Collaborator

no update in 14 days, please re-open the ticket if you have further information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants