Print the response if validation fails

This commit is contained in:
Mark Veidemanis 2023-01-02 18:41:49 +00:00
parent e0ea4c86fa
commit 2fa61fb195
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 11 additions and 1 deletions

View File

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