Simplify active management by only specifying trade IDs for violations
This commit is contained in:
@@ -44,6 +44,21 @@ class ActiveManagement(object):
|
||||
|
||||
def handle_violation(self, check_type, action, trade, **kwargs):
|
||||
print("VIOLATION", check_type, action, trade, kwargs)
|
||||
# TODO: close/notify for:
|
||||
# - trading time
|
||||
# - trends
|
||||
# - position size
|
||||
# - protection
|
||||
# - asset groups
|
||||
# - crossfilter
|
||||
# - max open trades
|
||||
# - max open trades per symbol
|
||||
# - max loss
|
||||
# - max risk
|
||||
|
||||
# TODO: adjust for:
|
||||
# - position size
|
||||
# - protection
|
||||
|
||||
def check_trading_time(self, trade):
|
||||
open_ts = trade["open_time"]
|
||||
@@ -51,7 +66,7 @@ class ActiveManagement(object):
|
||||
trading_time_pass = checks.within_trading_times(self.strategy, open_ts_as_date)
|
||||
if not trading_time_pass:
|
||||
self.handle_violation(
|
||||
"trading_time", self.policy.when_trading_time_violated, trade
|
||||
"trading_time", self.policy.when_trading_time_violated, trade["id"]
|
||||
)
|
||||
|
||||
def check_trends(self, trade):
|
||||
@@ -59,7 +74,9 @@ class ActiveManagement(object):
|
||||
symbol = trade["symbol"]
|
||||
trends_pass = checks.within_trends(self.strategy, symbol, direction)
|
||||
if not trends_pass:
|
||||
self.handle_violation("trends", self.policy.when_trends_violated, trade)
|
||||
self.handle_violation(
|
||||
"trends", self.policy.when_trends_violated, trade["id"]
|
||||
)
|
||||
|
||||
def check_position_size(self, trade):
|
||||
"""
|
||||
@@ -91,7 +108,7 @@ class ActiveManagement(object):
|
||||
self.handle_violation(
|
||||
"position_size",
|
||||
self.policy.when_position_size_violated,
|
||||
trade,
|
||||
trade["id"],
|
||||
{"size": expected_trade_size},
|
||||
)
|
||||
|
||||
@@ -152,7 +169,10 @@ class ActiveManagement(object):
|
||||
|
||||
if violations:
|
||||
self.handle_violation(
|
||||
"protection", self.policy.when_protection_violated, trade, violations
|
||||
"protection",
|
||||
self.policy.when_protection_violated,
|
||||
trade["id"],
|
||||
violations
|
||||
)
|
||||
|
||||
def check_asset_groups(self, trade):
|
||||
@@ -165,7 +185,7 @@ class ActiveManagement(object):
|
||||
)
|
||||
if not allowed:
|
||||
self.handle_violation(
|
||||
"asset_group", self.policy.when_asset_groups_violated, trade
|
||||
"asset_group", self.policy.when_asset_groups_violated, trade["id"]
|
||||
)
|
||||
|
||||
def get_sorted_trades_copy(self, trades, reverse=True):
|
||||
@@ -226,7 +246,7 @@ class ActiveManagement(object):
|
||||
if close_trades:
|
||||
for trade in close_trades:
|
||||
self.handle_violation(
|
||||
"crossfilter", self.policy.when_crossfilter_violated, trade
|
||||
"crossfilter", self.policy.when_crossfilter_violated, trade["id"]
|
||||
)
|
||||
|
||||
def check_max_open_trades(self, trades):
|
||||
@@ -241,7 +261,7 @@ class ActiveManagement(object):
|
||||
self.handle_violation(
|
||||
"max_open_trades",
|
||||
self.policy.when_max_open_trades_violated,
|
||||
trade,
|
||||
trade["id"],
|
||||
)
|
||||
|
||||
def check_max_open_trades_per_symbol(self, trades):
|
||||
@@ -267,7 +287,7 @@ class ActiveManagement(object):
|
||||
self.handle_violation(
|
||||
"max_open_trades_per_symbol",
|
||||
self.policy.when_max_open_trades_violated,
|
||||
trade,
|
||||
trade["id"],
|
||||
)
|
||||
|
||||
def check_max_loss(self):
|
||||
@@ -312,7 +332,7 @@ class ActiveManagement(object):
|
||||
if close_trades:
|
||||
for trade in close_trades:
|
||||
self.handle_violation(
|
||||
"max_risk", self.policy.when_max_risk_violated, trade
|
||||
"max_risk", self.policy.when_max_risk_violated, trade["id"]
|
||||
)
|
||||
|
||||
def run_checks(self):
|
||||
|
||||
Reference in New Issue
Block a user