Hello,
I am kicking the tires as it were with QC Lean. I have installed and executed the 'BasicTemplateForexAlgorithm', which worked a treat. I have made some very minor changes and I am having issues with using Oanda market.
class BasicTemplateForexAlgorithm(QCAlgorithm):
def Initialize(self):
# Set the Broker and Time Zone
self.SetBrokerageModel(BrokerageName.OandaBrokerage, AccountType.Margin)
self.SetTimeZone(TimeZones.Utc)
# Set the cash we'd like to use for our backtest
self.SetCash(10000)
# No trades until 7 days of data is backfilled
self.SetWarmUp(timedelta(7))
# self.BrokerageModel(BrokerageName.OandaBrokerage, AccountType.Cash)
# Start and end dates for the backtest.
self.SetStartDate(2013, 10, 7)
self.SetEndDate(2014, 10, 11)
# Add FOREX contract you want to trade
# find available contracts here https://www.quantconnect.com/data#forex/oanda/cfd
self.AddForex("EURUSD", Resolution.Minute, Market.Oanda)
self.History(5, Resolution.Daily)
self.History(5, Resolution.Hour)
self.History(5, Resolution.Minute)
history = self.History(TimeSpan.FromSeconds(5), Resolution.Second)
for data in sorted(history, key=lambda x: x.Time):
for key in data.Keys:
self.Log(str(key.Value) + ": " + str(data.Time) + " > " + str(data[key].Value))
def OnData(self, data):
# Print to console to verify that data is coming in
for key in data.Keys:
self.Log(str(key.Value) + ": " + str(data.Time) + " > " + str(data[key].Value))
if not self.Portfolio.Invested:
self.MarketOrder("EURUSD", 1000)
The above generates:
20201222 10:51:01.288 ERROR:: WorkerThread.<.ctor>b__7_0(): WorkerThread(): exception thrown when running task Python.Runtime.PythonException: AttributeError : Oanda
at Python.Runtime.PyObject.Invoke (Python.Runtime.PyTuple args, Python.Runtime.PyDict kw) [0x00033] in <c56ab175820d412caf052e079c2ab9ef>:0
at Python.Runtime.PyObject.InvokeMethod (System.String name, Python.Runtime.PyTuple args, Python.Runtime.PyDict kw) [0x00007] in <c56ab175820d412caf052e079c2ab9ef>:0
at Python.Runtime.PyObject.TryInvokeMember (System.Dynamic.InvokeMemberBinder binder, System.Object[] args, System.Object& result) [0x0003e] in <c56ab175820d412caf052e079c2ab9ef>:0
at (wrapper dynamic-method) System.Object.CallSite.Target(System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0] (System.Runtime.CompilerServices.CallSite site, T0 arg0) [0x00108] in <c5bd4c865d5d48d3b3ebe4d522fd6bd7>:0
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper.Initialize () [0x00045] in <85af64086f2a462698351dd6ddf624f9>:0
at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler+<>c__DisplayClass25_0.<Setup>b__0 () [0x00001] in <4a2f8a2099ea4690a33d7568fdba771c>:0
at QuantConnect.Util.WorkerThread.<.ctor>b__7_0 () [0x00036] in <38bf31a5ef9c46f496bcfa88c8e08a07>:0
I am not sure why it is throwing an AttributeError. Any and all help would be much appreciated. I would also like to enquire if Oanda integration has a facility for stop loss, trailing stop, and TP.
Thank you for your time,
-Jace
Jason
Was an issue with my import statements; if you use the import statements as noted here: Docu Mention
The above code will not work.
Jason
Further issue:
20201222 15:04:27.573 ERROR:: ZipDataCacheProvider.Fetch(): Inner try/catch Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: P. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue () [0x002b3] in <dc86da7fc46c487ba6c7ab826da479cc>:0 at Newtonsoft.Json.JsonTextReader.Read () [0x0004c] in <dc86da7fc46c487ba6c7ab826da479cc>:0 at Newtonsoft.Json.Linq.JObject.Load (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Linq.JsonLoadSettings settings) [0x00013] in <dc86da7fc46c487ba6c7ab826da479cc>:0 at Newtonsoft.Json.Linq.JObject.Parse (System.String json, Newtonsoft.Json.Linq.JsonLoadSettings settings) [0x0000c] in <dc86da7fc46c487ba6c7ab826da479cc>:0 at Newtonsoft.Json.Linq.JObject.Parse (System.String json) [0x00000] in <dc86da7fc46c487ba6c7ab826da479cc>:0 at QuantConnect.Api.Api.DownloadData (QuantConnect.Symbol symbol, QuantConnect.Resolution resolution, System.DateTime date) [0x000c1] in <d3ce367ea7764a358efd7f892ca445ba>:0 at QuantConnect.Lean.Engine.DataFeeds.ApiDataProvider.DownloadData (System.String filepath, QuantConnect.Symbol symbol, System.DateTime date, QuantConnect.Resolution resolution) [0x00037] in <4a2f8a2099ea4690a33d7568fdba771c>:0 at QuantConnect.Lean.Engine.DataFeeds.ApiDataProvider.Fetch (System.String key) [0x0002b] in <4a2f8a2099ea4690a33d7568fdba771c>:0 at QuantConnect.Lean.Engine.DataFeeds.ZipDataCacheProvider.CacheAndCreateStream (System.String filename, System.String entryName) [0x00003] in <4a2f8a2099ea4690a33d7568fdba771c>:0 at QuantConnect.Lean.Engine.DataFeeds.ZipDataCacheProvider.Fetch (System.String key) [0x00063] in <4a2f8a2099ea4690a33d7568fdba771c>:0
I have changed config.json to:
 "data-provider": "QuantConnect.Lean.Engine.DataFeeds.ApiDataProvider",
I have entered my Job-ID and API Key. I have "checked" out the data to my account. Not sure what is the issue.
Is there a way to get history through QC Lean directly from Oanda's API? They offer tick resolution to their customers. However, I am ok with minute resolution as well.
-Jace
Derek Melchin
Hi Jason,
We were unable to reproduce the error above. Please attach the full BasicTemplateForexAlgorithm file.
To setup TP and SL orders, refer to this related thread.
We don't currently offer tick resolution data through the Data Library.
Best,
Derek Melchin
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.
Jason
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!