coinrising / okex-api-v5

241 stars 115 forks source link

okex.exceptions.OkexAPIException: API Request Error(code=50004): Endpoint request timeout. #3

Open angelo-pauli opened 2 years ago

angelo-pauli commented 2 years ago

Hello Everyone,

I have created a trading bot with python. My program executes like expected for quite a while and then crashes with this error:

Traceback (most recent call last): File "STARLELON.py", line 62, in <module> balance = accountAPI.get_account() File "/home/dev/test/okex-api-v5/okex/Account_api.py", line 22, in get_account return self._request_with_params(GET, ACCOUNT_INFO, params) File "/home/dev/test/okex-api-v5/okex/client.py", line 58, in _request_with_params return self._request(method, request_path, params) File "/home/dev/test/okex-api-v5/okex/client.py", line 50, in _request raise exceptions.OkexAPIException(response) okex.exceptions.OkexAPIException: API Request Error(code=50004): Endpoint request timeout.

I have tried changing the domain from okex to the new one but that didn't change something. I am not really sure how to solve this.

Regards, Angelo

Kalindro commented 2 years ago

From my experience these errors happen all the time with all the exchanges, I've never found reliable resolution, and it's a matter of catching this exact exception and retrying when it occurs.

angelo-pauli commented 2 years ago

Okay in my python file what is an easy way to remove this exception? Should I do it in my bot file or in your exceptions.py file?

Kalindro commented 2 years ago

Just to make sure, I'm not connected to this project, I'm just a random user :P They way I handle timeouts and request errors is below, I just "ignore" them

from okex.exceptions import OkexAPIException
from requests.exceptions import ChunkedEncodingError, ConnectionError

try:
    while True:
          main()
except ChunkedEncodingError as Error:
    print(f"(Connection reset: {Error}")
    time.sleep(2.5)

except ConnectionError as Error:
    print(f"(Connection reset: {Error}")
    time.sleep(2.5)

except OkexAPIExceptionas Error:
    print(f"(Okexerror: {Error}")
    time.sleep(2.5)

You can also invoke the client again for timeout exceptions, so just adding also trade_client = TradeAPI(api_key=public_key, api_secret_key=secret_key, passphrase=passphrase, flag="0") to the said exception.

That's my take on this at least, but I'm a newb a bit, maybe your case is different, I do this for occasional errors that happen every sometime, not every time I connect. You can let me know if you know any more elegant way to handle it.

nanotecked commented 2 years ago

i set my time (clock) of my system as close as possible to the time of: https://time.is/ and it solved my problem for me, but Im not sure if the sync of any moment in the time will not be the same as the server and in the future i will have the same problem and have to change my clock aigan; so that guess to me to create a method to autosync the clock in future idk, but atm it worked for me =)

Kalindro commented 2 years ago

That's a good idea, on the other hand, you may be working with different exchanges at the same time and if you sync for one, you won't be synced for the other one so some doodling has to be done sooner or late