Use new call helper for all OANDA commands

Mark Veidemanis 2 years ago
parent c773b93675
commit 0c52cbd0f8
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -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

@ -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 = []

Loading…
Cancel
Save