Back

How to load Oanda Cfd data using python

Hey guys, 
I have been trying to include Oanda Cfd data in my algorithm for hours, but did not manage to get it right. 
I think I have done it how it was described in the documentation but it still does not work.

I would appreciate if you could let me know how I can get Oanda Cfd data. Forex data works flawless by the way. 

import numpy as np

class BasicTemplateAlgorithm(QCAlgorithm):

def Initialize(self):

self.SetBrokerageModel(BrokerageName.OandaBrokerage)

self.SetCash(1000000)
self.SetStartDate(2007,01,01)
self.SetEndDate(2017,01,01)
self.SetWarmup(200)

self.AddCfd("XAUUSD", Resolution.Minute, Market.Oanda)

def OnData(self, data):

bar = data["XAUUSD"]
cfd = self.Securities["XAUUSD"]

if not self.Portfolio.Invested:
self.SetHoldings(cfd, 1)

Kind regards 

Update Backtest








The cfd variable is a Securities object, while SetHoldings accepts a Symbol object. Since the Security object has a member called Symbol that is a Symbol object, we just need to make the following change in your code: 

self.SetHoldings(cfd.Symbol, 1)
1

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