Use new call helper for all OANDA commands

This commit is contained in:
Mark Veidemanis 2022-11-04 07:20:12 +00:00
parent c773b93675
commit 0c52cbd0f8
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 9 additions and 12 deletions

View File

@ -99,7 +99,8 @@ class BaseExchange(object):
if hasattr(self.schema, to_camel): if hasattr(self.schema, to_camel):
schema = getattr(self.schema, to_camel) schema = getattr(self.schema, to_camel)
else: else:
raise NoSchema self.log.error(f"Method cannot be validated: {to_camel}")
raise NoSchema(f"Method cannot be validated: {to_camel}")
return schema return schema
def call_method(self, method, *args, **kwargs): def call_method(self, method, *args, **kwargs):
@ -139,8 +140,7 @@ class BaseExchange(object):
# Return a dict of the validated response # Return a dict of the validated response
response_valid = schema(**response).dict() response_valid = schema(**response).dict()
except NoSchema: except NoSchema:
self.log.error(f"Method cannot be validated: {method}") self.log.debug(f"No schema: {response}")
self.log.debug(f"Response: {response}")
if STRICT_VALIDATION: if STRICT_VALIDATION:
raise raise
# Return the response as is # Return the response as is
@ -156,9 +156,9 @@ class BaseExchange(object):
except NoSuchMethod: except NoSuchMethod:
self.log.error(f"Method not found: {method}") self.log.error(f"Method not found: {method}")
raise raise
except Exception as e: # except Exception as e:
self.log.error(f"Error calling method: {e}") # self.log.error(f"Error calling method: {e}")
raise GenericAPIError(e) # raise GenericAPIError(e)
def get_account(self): def get_account(self):
raise NotImplementedError raise NotImplementedError

View File

@ -18,8 +18,7 @@ class OANDAExchange(BaseExchange):
def get_account(self): def get_account(self):
r = accounts.AccountDetails(self.account_id) r = accounts.AccountDetails(self.account_id)
self.client.request(r) return self.call(r)
return r.response
def get_supported_assets(self): def get_supported_assets(self):
return False return False
@ -38,8 +37,7 @@ class OANDAExchange(BaseExchange):
def get_trade(self, trade_id): def get_trade(self, trade_id):
r = accounts.TradeDetails(accountID=self.account_id, tradeID=trade_id) r = accounts.TradeDetails(accountID=self.account_id, tradeID=trade_id)
self.client.request(r) return self.call(r)
return r.response
def update_trade(self, trade): def update_trade(self, trade):
raise NotImplementedError raise NotImplementedError
@ -54,8 +52,7 @@ class OANDAExchange(BaseExchange):
def get_position_info(self, symbol): def get_position_info(self, symbol):
r = positions.PositionDetails(self.account_id, symbol) r = positions.PositionDetails(self.account_id, symbol)
self.client.request(r) return self.call(r)
return r.response
def get_all_positions(self): def get_all_positions(self):
items = [] items = []