From 0c52cbd0f849dd46a2211e674041f881c00254cd Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 4 Nov 2022 07:20:12 +0000 Subject: [PATCH] Use new call helper for all OANDA commands --- core/exchanges/__init__.py | 12 ++++++------ core/exchanges/oanda.py | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/core/exchanges/__init__.py b/core/exchanges/__init__.py index 1af7dba..970705a 100644 --- a/core/exchanges/__init__.py +++ b/core/exchanges/__init__.py @@ -99,7 +99,8 @@ class BaseExchange(object): if hasattr(self.schema, to_camel): schema = getattr(self.schema, to_camel) else: - raise NoSchema + self.log.error(f"Method cannot be validated: {to_camel}") + raise NoSchema(f"Method cannot be validated: {to_camel}") return schema def call_method(self, method, *args, **kwargs): @@ -139,8 +140,7 @@ class BaseExchange(object): # Return a dict of the validated response response_valid = schema(**response).dict() except NoSchema: - self.log.error(f"Method cannot be validated: {method}") - self.log.debug(f"Response: {response}") + self.log.debug(f"No schema: {response}") if STRICT_VALIDATION: raise # Return the response as is @@ -156,9 +156,9 @@ class BaseExchange(object): except NoSuchMethod: self.log.error(f"Method not found: {method}") raise - except Exception as e: - self.log.error(f"Error calling method: {e}") - raise GenericAPIError(e) + # except Exception as e: + # self.log.error(f"Error calling method: {e}") + # raise GenericAPIError(e) def get_account(self): raise NotImplementedError diff --git a/core/exchanges/oanda.py b/core/exchanges/oanda.py index bbf12c0..3719912 100644 --- a/core/exchanges/oanda.py +++ b/core/exchanges/oanda.py @@ -18,8 +18,7 @@ class OANDAExchange(BaseExchange): def get_account(self): r = accounts.AccountDetails(self.account_id) - self.client.request(r) - return r.response + return self.call(r) def get_supported_assets(self): return False @@ -38,8 +37,7 @@ class OANDAExchange(BaseExchange): def get_trade(self, trade_id): r = accounts.TradeDetails(accountID=self.account_id, tradeID=trade_id) - self.client.request(r) - return r.response + return self.call(r) def update_trade(self, trade): raise NotImplementedError @@ -54,8 +52,7 @@ class OANDAExchange(BaseExchange): def get_position_info(self, symbol): r = positions.PositionDetails(self.account_id, symbol) - self.client.request(r) - return r.response + return self.call(r) def get_all_positions(self): items = []