I would like to start my algorithm loading the opened positions I already have in my demo account, I have two long and one short, that I can query with https://api-fxpractice.oanda.com/v3/accounts/101-XXX-AAAAAA-0XX/openPositions,

{ "positions": [ { "instrument": "EUR_USD", "long": { "units": "2", "averagePrice": "1.11041", "pl": "0.0000", "resettablePL": "0.0000", "financing": "-0.0016", "dividend": "0.0000", "guaranteedExecutionFees": "0.0000", "tradeIDs": [ "5", "7" ], "unrealizedPL": "0.0106" }, "short": { "units": "-1", "averagePrice": "1.11027", "pl": "0.0000", "resettablePL": "0.0000", "financing": "0.0000", "dividend": "0.0000", "guaranteedExecutionFees": "0.0000", "tradeIDs": [ "9" ], "unrealizedPL": "-0.0058" }, "pl": "0.0000", "resettablePL": "0.0000", "financing": "-0.0016", "commission": "0.0000", "dividend": "0.0000", "guaranteedExecutionFees": "0.0000", "unrealizedPL": "0.0048", "marginUsed": "0.0666" } ], "lastTransactionID": "19" }

but when using Lean I get only the longs.

20191102 09:23:25.931 Trace:: BrokerageSetupHandler.Setup(): Fetching holdings from brokerage... 20191102 09:24:38.046 Trace:: BrokerageSetupHandler.Setup(): Has existing holding: EURUSD: 2 @ $1.11041 - Market: $1.116545

Debugging the code I see the response in OandaRestApiV20::GetAccountHoldings() returns both longs and shorts, but then in the OandaRestApiV20::ConvertHolding(Position position) only long or shorts are returned  (line 684).

I see the Transaction.GetOpenOrders() does not return open positions too and there not a Transaction.GetOpenPositions() api (and the brokerage class is not exposed in the algorithm).

How can I initialize correctly my algorithm with the currently opened positions? 

 

Author