Implement adjusting positions and begin writing live tests for AMS
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user