Back

Initialize algorithm with Oanda opened positions

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? 

 

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Stefano Piovesan ,

Lean does not support two (opposing) positions of the same instrument.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed