diff --git a/core/exchanges/__init__.py b/core/exchanges/__init__.py index 67ad84d..cee8b2b 100644 --- a/core/exchanges/__init__.py +++ b/core/exchanges/__init__.py @@ -3,6 +3,7 @@ from abc import ABC, abstractmethod from alpaca.common.exceptions import APIError from glom import glom from oandapyV20.exceptions import V20Error +from pydantic.error_wrappers import ValidationError from core.lib import schemas from core.util import logs @@ -131,7 +132,12 @@ class BaseExchange(ABC): def validate_response(self, response, method): schema = self.get_schema(method) # Return a dict of the validated response - response_valid = schema(**response).dict() + try: + response_valid = schema(**response).dict() + except ValidationError as e: + log.error(f"Error validating {method} response: {response}") + log.error(f"Errors: {e}") + raise GenericAPIError("Error validating response") return response_valid def call(self, method, *args, **kwargs): @@ -198,6 +204,10 @@ class BaseExchange(ABC): def post_trade(self, trade): pass + @abstractmethod + def close_trade(self, trade_id): + pass + @abstractmethod def get_trade(self, trade_id): pass