Handle errors in checking for open positions

master
Mark Veidemanis 1 year ago
parent af69b886ba
commit 575b6a240f
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

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

Loading…
Cancel
Save