Implement closing all positions
This commit is contained in:
parent
9dda0e8b4a
commit
b8b39ea8d3
|
@ -16,3 +16,9 @@ def get_balance_hook(user_id, user_name, account_id, account_name, balance):
|
||||||
"balance": balance,
|
"balance": balance,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def convert_open_trades(open_trades):
|
||||||
|
"""
|
||||||
|
Convert a list of open trades into a list of Trade-like objects.
|
||||||
|
"""
|
||||||
|
|
|
@ -151,10 +151,17 @@ class OANDAExchange(BaseExchange):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def close_all_positions(self):
|
def close_all_positions(self):
|
||||||
# all_positions = self.get_all_positions()
|
all_positions = self.get_all_positions()
|
||||||
|
responses = []
|
||||||
# for position in all_positions["itemlist"]:
|
for position in all_positions:
|
||||||
# print("POS ITER", position)
|
side = position["side"]
|
||||||
r = positions.PositionClose(accountID=self.account_id)
|
symbol = position["symbol"]
|
||||||
response = self.call(r)
|
data = {
|
||||||
return response
|
f"{side}Units": "ALL",
|
||||||
|
}
|
||||||
|
r = positions.PositionClose(
|
||||||
|
accountID=self.account_id, instrument=symbol, data=data
|
||||||
|
)
|
||||||
|
response = self.call(r)
|
||||||
|
responses.append(response)
|
||||||
|
return responses
|
||||||
|
|
Loading…
Reference in New Issue