Implement closing positions and refuse to post rejected trades

This commit is contained in:
2022-12-01 20:36:58 +00:00
parent 5c2eeae043
commit 66a18a6406
3 changed files with 34 additions and 2 deletions

View File

@@ -117,6 +117,16 @@ class OANDAExchange(BaseExchange):
items.append(item)
return items
def close_position(self, side, symbol):
data = {
f"{side}Units": "ALL",
}
r = positions.PositionClose(
accountID=self.account_id, instrument=symbol, data=data
)
response = self.call(r)
return response
def close_all_positions(self):
# all_positions = self.get_all_positions()
@@ -124,5 +134,4 @@ class OANDAExchange(BaseExchange):
# print("POS ITER", position)
r = positions.PositionClose(accountID=self.account_id)
response = self.call(r)
print("CLOSE ALL POSITIONS", response)
return response