diff --git a/core/exchanges/common.py b/core/exchanges/common.py index ab8f206..4776920 100644 --- a/core/exchanges/common.py +++ b/core/exchanges/common.py @@ -16,3 +16,9 @@ def get_balance_hook(user_id, user_name, account_id, account_name, balance): "balance": balance, }, ) + + +def convert_open_trades(open_trades): + """ + Convert a list of open trades into a list of Trade-like objects. + """ diff --git a/core/exchanges/oanda.py b/core/exchanges/oanda.py index ae62306..2f146c7 100644 --- a/core/exchanges/oanda.py +++ b/core/exchanges/oanda.py @@ -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