Compare commits

...

2 Commits

4 changed files with 30 additions and 7 deletions

View File

@ -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.
"""

View File

@ -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)
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)
return response
responses.append(response)
return responses

View File

@ -32,6 +32,11 @@ class ElasticMock:
class LiveBase:
@classmethod
def tearDownClass(cls):
cls.account.client.close_all_positions()
super(LiveBase, cls).tearDownClass()
@classmethod
def setUpClass(cls):
super(LiveBase, cls).setUpClass()

View File

@ -78,3 +78,8 @@ class LiveTradingTestCase(ElasticMock, LiveBase, TestCase):
if not found:
self.fail("Could not find the trade in the list of open trades")
def test_convert_open_trades(self):
"""
Test converting open trades response to Trade-like format.
"""