Handle errors in checking for open positions
This commit is contained in:
parent
af69b886ba
commit
575b6a240f
|
@ -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…
Reference in New Issue