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

ConnectionError(ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))) #360

Open
aleksGr opened this issue Jun 26, 2021 · 21 comments
Labels
enhancement New feature or request

Comments

@aleksGr
Copy link

aleksGr commented Jun 26, 2021

sometimes i get this error:

2021-06-26 03:32:33 | ETHUSDT | 1h | Current Price: 1827.29
ConnectionError(ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')))
Traceback (most recent call last):
File "/usr/local/lib/python3.9/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

the error may appear after a few minutes, or the next day

i am using docker:
docker run --name ETH -v /root/pycryptobot/config.json:/app/config.json -d ghcr.io/whittlem/pycryptobot/pycryptobot:latest --selllowerpcnt -2 --smartswitch 1 --disablebullonly; docker logs -f ETH

conf.json

{
"binance" : {
"api_url" : "https://api.binance.com",
"api_key" : "",
"api_secret" : "",
"config" : {
"base_currency" : "ETH",
"quote_currency" : "USDT",
"granularity" : "1h",
"live" : 1,
"verbose" : 1,
"sellatloss" : 1
}
},
"telegram" : {
"token" : "",
"client_id" : ""
}
}

this is normal? or am I doing something wrong?
I have been using the bot for 2 days, and during this time it has not made a single transaction on the exchange, thanks

@rockyrobinls29
Copy link

I've just got this error also upon starting a bot with the latest version of pycryptobot.
I did notice that pip upgraded to a newer version of urllib compared to previous versions of pycryptobot.
Could this be the cause of the error?

@rockyrobinls29
Copy link

Just tried downgrading urllib to version 1.26.0 with pycryptobot version 2.38.0 and no longer have the above issue.

@rockyrobinls29
Copy link

Scrub the above message- the error is back!

@hellresistor
Copy link
Contributor

hellresistor commented Jun 27, 2021

i am getting that error to after bot running some hours.
Dint get if is random issue or like a long bot running time?

PS: I not using Docker! using .venv session

@itsdarkerinnit
Copy link

itsdarkerinnit commented Jun 28, 2021

Yeah, i'm getting this error as well every few hours.

2021-06-28 22:57:06 | RUNEUSDT | 1h | Current Price: 6.409
ConnectionError(ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')))
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.local/lib/python3.9/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

Some times it doesn't crash, it outputs this error but resumes trading after 1 minutes.

Exception: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Error on creating instance of AuthAPI Client. Trying again... Attempt: 0
Your connection to the exchange has gone down, will retry in 1 minute!

Forgot to mention this is on binance exchange don't know if it happens with coinbase pro as well.

No docker, no python venv, just using pure python3.9 pycryptobot.py.

@jensb89
Copy link

jensb89 commented Jun 29, 2021

Have the same error on my Pi in a venv environment.
I will now set the poll cycle to 2min instead of 1min. I noticed my old coinBase Bot (not updated for some time) also uses 2min update cycle. I think the error is from Binance, maybe it's too many API calls?

Will let you know if this solves the error for me, for now it's running :)

@hellresistor
Copy link
Contributor

i am using 15m

@jensb89
Copy link

jensb89 commented Jun 30, 2021

i am using 15m

I didn't mean the granularity, but the polling time. The bot runs in a scheduler with a 60s delay, i.e. it makes an API call every minute to get new prices.

But unfortunately increasing it to 2min didn't help much, had another error this morning :(

@itsdarkerinnit
Copy link

i am using 15m

I didn't mean the granularity, but the polling time. The bot runs in a scheduler with a 60s delay, i.e. it makes an API call every minute to get new prices.

But unfortunately increasing it to 2min didn't help much, had another error this morning :(

How can I define this pool time in config? Can't find a reference to it.
Thanks

@jensb89
Copy link

jensb89 commented Jun 30, 2021

You can't specify it in the config, it's hardcoded here as far as I know:

s.enter(60, 1, executeJob, (sc, app, state))

s.enter(60, 1, executeJob, (sc, app, state))

The 60 is the delay time in seconds of the scheduler.

@itsdarkerinnit
Copy link

itsdarkerinnit commented Jul 2, 2021

I'm thinking this has nothing to do with the bot, but with the exchange itself. I figure they have a client timeout. If Binance has a system that resets the peer(us) connection when it fails to respond in a certain amount of time, then their system will terminate the connection after X amount of fails or delays in XX hours. And on our side we see Connection reset by peer, peer as in remote system meaning Binance terminated the connection, not the bot.
-- I have no clue if this is true, haven't even read binance's api docs, and not sure if this is specified there, Dyor. --

Following what @jensb89 said (thanks), I did the opposite.
So instead of increasing pool time I reduced it to basically half, which is 30 (do or die) (line 753 of pycryptobot.py like this:
s.enter(30, 1, executeJob, (sc, app, state)) ) , and what'ya know, my bot is running live for more than 48h now and connection hasn't dropped yet.
I also checked the log to make sure it hadn't lost the connection at some point and then reconnected but and no sign of 1 single fail.

I'm sure this is just a temporary fix, but I suggest for this to be implemented as an option in config.json "pooltime": '60', in the next release, otherwise doing a git pull will overwrite this change...this is assuming it's the real deal which I think it is.

@jensb89
Copy link

jensb89 commented Jul 3, 2021

That's an interesting idea :) I will try this as well 👍

I guess it shouldn't be too hard to implement this as a config option as well.

@itsdarkerinnit
Copy link

itsdarkerinnit commented Jul 3, 2021

welp!
happened again..after 50+ hours of not crashing... CRITICAL ConnectionError(ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')))
Output on telegram:

xxx, [03.07.21 01:15]
Auto restarting bot for RUNEUSDT after exception: ConnectionError(ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')))

xxx, [03.07.21 01:17]
Bot for RUNEUSDT got an exception: ConnectionError(ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')))

So...back to start again with this... I really thought I had it.

But hey..at least it ran for over 2 full days straight without crashing, i'm partially happy.

@jensb89
Copy link

jensb89 commented Jul 5, 2021

Can confirm, mine also crashed again after around 2 days. Really strange ...

I guess another problem is that the auto restart also doesn't seem to work. Maybe we could catch the Connection error and automatically retry a few times?! Not sure that's the best idea though...

@hellresistor
Copy link
Contributor

i am testing this method.. A solution, but not THE solution.

https://github.com/yanone/raspberrypycryptobot#running-pycryptobot-on-boot

@itsdarkerinnit
Copy link

Can confirm, mine also crashed again after around 2 days. Really strange ...

I guess another problem is that the auto restart also doesn't seem to work. Maybe we could catch the Connection error and automatically retry a few times?! Not sure that's the best idea though...

apparently it now saves the position after crashing, so if you run it on screen like I do, just do a loop and it restarts automatically while true; do python3.9 pycryptobot.py && break; done until you cancel it.

@whittlem
Copy link
Owner

Is this problem only with Binance? I am just wondering if Binance are throttling API calls. How many bots are you running concurrently? Firstly, are any of you coinbase pro users?

@jensb89
Copy link

jensb89 commented Jul 13, 2021

@whittlem : I think it affects only Binance. I have one Binance and one Coinbase Bot (on an older repo commit though). So far never had problems with the Coinbase bot. Also Binance is running fine sometimes for days or weeks without any error and then this error shows up multiple times a day. I guess it's on Binance ...

@itsdarkerinnit
Copy link

itsdarkerinnit commented Jul 16, 2021

@whittlem this happens with one and with multiple bots running.
I'm only on Binance, but it according to the telegram chat group it also happens with Coinbase although with less frequency.

Side question: Can RSI be added to the bot as a signal? personally I think would be a great indicator for buy/sell signal. I use it with manual trades and the loss is lower than relying on ema crossing alone. but then again manual trades aren't automated trades.
An example is the plugin on tradingview called RSI+ made by D7R, different language I know but it's an example.

@loomsen
Copy link
Collaborator

loomsen commented Aug 2, 2021

@pitbullgti Please create a feature request for RSI if you're interested in it.

Regarding this conversation, these errors can happen due to multiple reasons. Flaky connection on the user side, not so graceful configuration on the other side (I think it is fair to assume, that coinbase and binance run a plethora of replicas for their API with autoscaling enabled, it might just happen that you hit a pod that got killed just now).

Possible enhancement: retry failed connections wrapping them in a try except block in python?

@loomsen loomsen added the enhancement New feature or request label Aug 2, 2021
@Sarakyzhou
Copy link

Just tried downgrading urllib to version 1.26.0 with pycryptobot version 2.38.0 and no longer have the above issue.

Thank you so much for solving my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants