Implement adjusting positions and begin writing live tests for AMS

This commit is contained in:
2023-02-20 07:20:03 +00:00
parent a840be3834
commit 9e22abe057
5 changed files with 249 additions and 9 deletions

View File

@@ -95,7 +95,23 @@ class ActiveManagement(object):
sendmsg(self.strategy.user, msg, title=f"AMS: {action}")
def adjust_position_size(self, trade_id, new_size):
pass # TODO
# Get old size
old_size = None
for trade in self.trades:
if trade["id"] == trade_id:
old_size = D(trade["currentUnits"])
symbol = trade["symbol"]
break
if old_size is None:
log.error(f"Could not find trade ID {trade_id} in active management")
return
# Reduce only
assert old_size > new_size
difference = old_size - new_size
# Close the difference
self.strategy.account.client.close_trade(trade_id, difference, symbol)
def adjust_protection(self, trade_id, new_protection):
pass # TODO