Begin implementing exit executor for strategies

This commit is contained in:
Mark Veidemanis 2022-12-01 19:33:06 +00:00
parent bdae8ab093
commit 682d141b8a
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 19 additions and 3 deletions

View File

@ -295,9 +295,10 @@ def execute_strategy(callback, strategy):
user = strategy.user user = strategy.user
account = strategy.account account = strategy.account
hook = callback.hook hook = callback.hook
signal = callback.signal
base = callback.base base = callback.base
quote = callback.quote quote = callback.quote
direction = hook.direction direction = signal.direction
# Don't be silly # Don't be silly
if callback.exchange != account.exchange: if callback.exchange != account.exchange:
@ -359,6 +360,7 @@ def execute_strategy(callback, strategy):
user=user, user=user,
account=account, account=account,
hook=hook, hook=hook,
signal=signal,
symbol=symbol, symbol=symbol,
type=type, type=type,
time_in_force=strategy.time_in_force, time_in_force=strategy.time_in_force,
@ -381,8 +383,22 @@ def execute_strategy(callback, strategy):
def process_callback(callback): def process_callback(callback):
log.info(f"Received callback for {callback.hook}") log.info(f"Received callback for {callback.hook} - {callback.signal}")
strategies = Strategy.objects.filter(hooks=callback.hook, enabled=True)
# 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}") log.debug(f"Matched strategies: {strategies}")
for strategy in strategies: for strategy in strategies:
log.debug(f"Executing strategy {strategy}") log.debug(f"Executing strategy {strategy}")