Handle errors in checking for open positions

This commit is contained in:
Mark Veidemanis 2022-12-07 07:20:47 +00:00
parent af69b886ba
commit 575b6a240f
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 11 additions and 1 deletions

View File

@ -19,7 +19,15 @@ def crossfilter(account, symbol, direction, func):
:param func: Whether we are checking entries or exits
:return: dict of action and opposing position, or False
"""
position_info = account.client.get_position_info(symbol)
try:
position_info = account.client.get_position_info(symbol)
except GenericAPIError as e:
if "No position exists for the specified instrument" in str(e):
log.debug("No position exists for this symbol")
return False
else:
log.error(f"Error getting position info: {e}")
return None
if direction == "buy":
opposing_side = "short"
elif direction == "sell":
@ -377,6 +385,8 @@ def execute_strategy(callback, strategy, func):
# Callback now verified
if func == "exit":
check_exit = crossfilter(account, symbol, direction, func)
if check_exit is None:
return
if not check_exit:
log.debug("Exit conditions not met.")
return