From a18c150fe2779fd0269c64ab419ff04f6b3e5929 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 22 Dec 2022 07:20:49 +0000 Subject: [PATCH] Begin implementing get all open trades --- core/exchanges/__init__.py | 4 +++ core/exchanges/oanda.py | 4 +++ core/lib/schemas/oanda_s.py | 59 +++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/core/exchanges/__init__.py b/core/exchanges/__init__.py index 2efa4b5..67ad84d 100644 --- a/core/exchanges/__init__.py +++ b/core/exchanges/__init__.py @@ -218,6 +218,10 @@ class BaseExchange(ABC): def get_all_positions(self): pass + @abstractmethod + def get_all_open_trades(self): + pass + @abstractmethod def close_position(self, side, symbol): pass diff --git a/core/exchanges/oanda.py b/core/exchanges/oanda.py index c2de8f4..af7a8d7 100644 --- a/core/exchanges/oanda.py +++ b/core/exchanges/oanda.py @@ -129,6 +129,10 @@ class OANDAExchange(BaseExchange): items.append(item) return items + def get_all_open_trades(self): + r = trades.OpenTrades(accountID=self.account_id) + return self.call(r) + def close_position(self, side, symbol): data = { f"{side}Units": "ALL", diff --git a/core/lib/schemas/oanda_s.py b/core/lib/schemas/oanda_s.py index efff6eb..2efd88b 100644 --- a/core/lib/schemas/oanda_s.py +++ b/core/lib/schemas/oanda_s.py @@ -492,6 +492,65 @@ class Trade(BaseModel): guaranteedExecutionFee: str quoteGuaranteedExecutionFee: str halfSpreadCost: str + # takeProfitOrder: TakeProfitOrder | None + takeProfitOrder: dict | None + stopLossOrder: dict | None + trailingStopLossOrder: dict | None + + +{ + "trades": [ + { + "id": "14480", + "instrument": "EUR_USD", + "price": "1.06345", + "openTime": "2022-12-22T08:57:10.459593310Z", + "initialUnits": "100", + "initialMarginRequired": "2.9226", + "state": "OPEN", + "currentUnits": "100", + "realizedPL": "0.0000", + "financing": "0.0000", + "dividendAdjustment": "0.0000", + "unrealizedPL": "-0.0158", + "marginUsed": "2.9228", + } + ], + "lastTransactionID": "14480", +} + + +class OpenTrades(BaseModel): + trades: list[Trade] + lastTransactionID: str + + +OpenTradesSchema = { + "itemlist": ( + "trades", + [ + { + "id": "tradeID", + "instrument": "instrument", + "price": "price", + "openTime": "openTime", + "initialUnits": "initialUnits", + "initialMarginRequired": "initialMarginRequired", + "state": "state", + "currentUnits": "currentUnits", + "realizedPL": "realizedPL", + "financing": "financing", + "dividendAdjustment": "dividendAdjustment", + "unrealizedPL": "unrealizedPL", + "marginUsed": "marginUsed", + "takeProfitOrder": "takeProfitOrder", + "stopLossOrder": "stopLossOrder", + "trailingStopLossOrder": "trailingStopLossOrder", + } + ], + ), + "lastTransactionID": "lastTransactionID", +} class HomeConversionFactors(BaseModel):