|
|
|
@ -295,9 +295,10 @@ def execute_strategy(callback, strategy):
|
|
|
|
|
user = strategy.user
|
|
|
|
|
account = strategy.account
|
|
|
|
|
hook = callback.hook
|
|
|
|
|
signal = callback.signal
|
|
|
|
|
base = callback.base
|
|
|
|
|
quote = callback.quote
|
|
|
|
|
direction = hook.direction
|
|
|
|
|
direction = signal.direction
|
|
|
|
|
|
|
|
|
|
# Don't be silly
|
|
|
|
|
if callback.exchange != account.exchange:
|
|
|
|
@ -359,6 +360,7 @@ def execute_strategy(callback, strategy):
|
|
|
|
|
user=user,
|
|
|
|
|
account=account,
|
|
|
|
|
hook=hook,
|
|
|
|
|
signal=signal,
|
|
|
|
|
symbol=symbol,
|
|
|
|
|
type=type,
|
|
|
|
|
time_in_force=strategy.time_in_force,
|
|
|
|
@ -381,8 +383,22 @@ def execute_strategy(callback, strategy):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_callback(callback):
|
|
|
|
|
log.info(f"Received callback for {callback.hook}")
|
|
|
|
|
strategies = Strategy.objects.filter(hooks=callback.hook, enabled=True)
|
|
|
|
|
log.info(f"Received callback for {callback.hook} - {callback.signal}")
|
|
|
|
|
|
|
|
|
|
# Scan for entry
|
|
|
|
|
log.debug("Scanning for entry strategies...")
|
|
|
|
|
strategies = Strategy.objects.filter(entry_signals=callback.signal, enabled=True)
|
|
|
|
|
log.debug(f"Matched strategies: {strategies}")
|
|
|
|
|
for strategy in strategies:
|
|
|
|
|
log.debug(f"Executing strategy {strategy}")
|
|
|
|
|
if callback.hook.user != strategy.user:
|
|
|
|
|
log.error("Ownership differs between callback and strategy.")
|
|
|
|
|
continue
|
|
|
|
|
execute_strategy(callback, strategy)
|
|
|
|
|
|
|
|
|
|
# Scan for exit
|
|
|
|
|
log.debug("Scanning for entry strategies...")
|
|
|
|
|
strategies = Strategy.objects.filter(exit_signals=callback.signal, enabled=True)
|
|
|
|
|
log.debug(f"Matched strategies: {strategies}")
|
|
|
|
|
for strategy in strategies:
|
|
|
|
|
log.debug(f"Executing strategy {strategy}")
|
|
|
|
|