From 4175c5c01861cd93ea835d5f8b12f64773f6adcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Sun, 17 Nov 2024 10:41:30 -0300 Subject: [PATCH] OKX pauses --- changelog.txt | 4 +++- exchange_wrapper.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index c59f6b2..eac1736 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,6 @@ -2024.11.13: Fixed bug handling timestamps. +2024.11.13: +. Fixed bug handling timestamps. +. Added a couple of pauses for OKX. 2024.11.11: . Refactored boost check to optimize CPU usage. diff --git a/exchange_wrapper.py b/exchange_wrapper.py index fd469fb..1efb1ea 100755 --- a/exchange_wrapper.py +++ b/exchange_wrapper.py @@ -775,6 +775,32 @@ class broker: return "insufficient" in error_text.lower() or "BALANCE_NOT_ENOUGH" in error_text or "Low available balance" in error_text + def price_too_high_error(self, error_object): + ''' + Checks if the error is a price too high error. + Receives an error object. + Returns True if the error is a price too high error, False otherwise. + + :param error_object: The error object. + :return: Boolean value + ''' + + return "the highest price limit for buy orders is" in str(error_object).lower() + + + def price_too_low_error(self, error_object): + ''' + Checks if the error is a price too low error. + Receives an error object. + Returns True if the error is a price too low error, False otherwise. + + :param error_object: The error object. + :return: Boolean value + ''' + + return "the lowest price limit for sell orders is" in str(error_object).lower() + + def new_limit_order(self,symbol,size,side,price,no_retries=False): ''' Sends a new limit order. @@ -809,6 +835,10 @@ class broker: #instead of guesstimating the fees, it's easier and more precise to query the exchange for the remaining base currency #and send the order with that amount. tries-=1 + elif self.price_too_high_error(e): #In high volatility moments, OKX sometimes just needs a bit of extra thinking time. + time.sleep(self.wait_time) + elif self.price_too_low_error(e): + time.sleep(self.wait_time) if no_retries: break tries-=1