Implement closing all positions
This commit is contained in:
@@ -151,10 +151,17 @@ class OANDAExchange(BaseExchange):
|
||||
return response
|
||||
|
||||
def close_all_positions(self):
|
||||
# all_positions = self.get_all_positions()
|
||||
|
||||
# for position in all_positions["itemlist"]:
|
||||
# print("POS ITER", position)
|
||||
r = positions.PositionClose(accountID=self.account_id)
|
||||
response = self.call(r)
|
||||
return response
|
||||
all_positions = self.get_all_positions()
|
||||
responses = []
|
||||
for position in all_positions:
|
||||
side = position["side"]
|
||||
symbol = position["symbol"]
|
||||
data = {
|
||||
f"{side}Units": "ALL",
|
||||
}
|
||||
r = positions.PositionClose(
|
||||
accountID=self.account_id, instrument=symbol, data=data
|
||||
)
|
||||
response = self.call(r)
|
||||
responses.append(response)
|
||||
return responses
|
||||
|
||||
Reference in New Issue
Block a user