From 7bee003ae8d1d1a3faa4a4d17906ea4428997934 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Sat, 7 Dec 2024 16:06:05 +0100 Subject: [PATCH] [Exchanges] add is_authenticated_request --- Trading/Exchange/binance/binance_exchange.py | 12 ++++++++++++ Trading/Exchange/bingx/bingx_exchange.py | 6 ++++++ Trading/Exchange/coinbase/coinbase_exchange.py | 13 ++++++++++++- Trading/Exchange/kucoin/kucoin_exchange.py | 7 +++++++ Trading/Exchange/okx/okx_exchange.py | 7 +++++++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Trading/Exchange/binance/binance_exchange.py b/Trading/Exchange/binance/binance_exchange.py index 415d45550..bbca73529 100644 --- a/Trading/Exchange/binance/binance_exchange.py +++ b/Trading/Exchange/binance/binance_exchange.py @@ -161,6 +161,18 @@ def get_additional_connector_config(self): } return config + def is_authenticated_request(self, url: str, method: str, headers: dict, body) -> bool: + signature_identifier = "signature=" + return bool( + ( + url + and signature_identifier in url # for GET & DELETE requests + ) or ( + body + and signature_identifier in body # for other requests + ) + ) + async def get_balance(self, **kwargs: dict): if self.exchange_manager.is_future: balance = [] diff --git a/Trading/Exchange/bingx/bingx_exchange.py b/Trading/Exchange/bingx/bingx_exchange.py index 946af2261..7fe51363e 100644 --- a/Trading/Exchange/bingx/bingx_exchange.py +++ b/Trading/Exchange/bingx/bingx_exchange.py @@ -57,6 +57,12 @@ async def get_my_recent_trades(self, symbol=None, since=None, limit=None, **kwar return await super().get_my_recent_trades(symbol=symbol, since=since, limit=limit, **kwargs) return await super().get_closed_orders(symbol=symbol, since=since, limit=limit, **kwargs) + def is_authenticated_request(self, url: str, method: str, headers: dict, body) -> bool: + signature_identifier = "signature=" + return bool( + url + and signature_identifier in url + ) class BingxCCXTAdapter(exchanges.CCXTAdapter): diff --git a/Trading/Exchange/coinbase/coinbase_exchange.py b/Trading/Exchange/coinbase/coinbase_exchange.py index ea17848b4..da6857750 100644 --- a/Trading/Exchange/coinbase/coinbase_exchange.py +++ b/Trading/Exchange/coinbase/coinbase_exchange.py @@ -169,7 +169,7 @@ async def get_account_id(self, **kwargs: dict) -> str: self.logger.exception( err, True, f"Error when fetching {self.get_name()} account id: {err} ({err.__class__.__name__}). " - f"This is not normal, endpoint might be deprecated, see" + f"This is not normal, endpoint might be deprecated, see " f"https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-users. " f"Using generated account id instead" ) @@ -264,6 +264,17 @@ def _get_ohlcv_params(self, time_frame, input_limit, **kwargs): kwargs["limit"] = limit return kwargs + def is_authenticated_request(self, url: str, method: str, headers: dict, body) -> bool: + signature_identifier = "CB-ACCESS-SIGN" + oauth_identifier = "Authorization" + return bool( + headers + and ( + signature_identifier in headers + or oauth_identifier in headers + ) + ) + def is_market_open_for_order_type(self, symbol: str, order_type: trading_enums.TraderOrderType) -> bool: """ Override if necessary diff --git a/Trading/Exchange/kucoin/kucoin_exchange.py b/Trading/Exchange/kucoin/kucoin_exchange.py index 0fb38cbe4..5009b2e9b 100644 --- a/Trading/Exchange/kucoin/kucoin_exchange.py +++ b/Trading/Exchange/kucoin/kucoin_exchange.py @@ -261,6 +261,13 @@ def should_log_on_ddos_exception(self, exception) -> bool: """ return Kucoin.INSTANT_RETRY_ERROR_CODE not in str(exception) + def is_authenticated_request(self, url: str, method: str, headers: dict, body) -> bool: + signature_identifier = "KC-API-SIGN" + return bool( + headers + and signature_identifier in headers + ) + def get_order_additional_params(self, order) -> dict: params = {} if self.exchange_manager.is_future: diff --git a/Trading/Exchange/okx/okx_exchange.py b/Trading/Exchange/okx/okx_exchange.py index 27194e590..53c720b27 100644 --- a/Trading/Exchange/okx/okx_exchange.py +++ b/Trading/Exchange/okx/okx_exchange.py @@ -181,6 +181,13 @@ def get_supported_exchange_types(cls) -> list: trading_enums.ExchangeTypes.FUTURE, ] + def is_authenticated_request(self, url: str, method: str, headers: dict, body) -> bool: + signature_identifier = "OK-ACCESS-SIGN" + return bool( + headers + and signature_identifier in headers + ) + def _fix_limit(self, limit: int) -> int: return min(self.MAX_PAGINATION_LIMIT, limit) if limit else limit