Skip to content

Commit

Permalink
[Exchanges] add is_authenticated_request
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Dec 7, 2024
1 parent 79471fd commit 7bee003
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Trading/Exchange/binance/binance_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
6 changes: 6 additions & 0 deletions Trading/Exchange/bingx/bingx_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
13 changes: 12 additions & 1 deletion Trading/Exchange/coinbase/coinbase_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Trading/Exchange/kucoin/kucoin_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions Trading/Exchange/okx/okx_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7bee003

Please sign in to comment.