I am trying to use Rest SubscriptionTransportMedium in my custom data setup. Attached you can find the algo.
I am getting the error. It says Runtime Error: KeyNotFoundException : 'RADFDATA.Radf' wasn't found in the Slice object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("RADFDATA.Radf")
It is the strange error becuase, for test, I use always the same url, which always returns the same output.
Derek Melchin
Hi Mislav,
The attached backtest shows how we can use `RemoteFile` to read from the URL above.
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.
Mislav Sagovac
Derek Melchin , thanks for help. I have added logs to the code. They doesn't show any data. I have also changed the start dae but should't effect the returned data.
I have 3 questions:
1) Why do we use RemoteFile instead of Rest, when we want to send GET request on every time stamp? I want to send request GET requests in both backtest and live trading.
2) Why my attached code deosn't return any data?
3) Is it possible to change source url on every time stamp? More concretly, I would like to change date query argument in evey time stamp.
Derek Melchin
Hi Mislav,
#1 - To send GET requests, we should use Rest instead. However, when using Rest with the URL provided, an access error is thrown. Generally, this means we need to add login credentials to the URL endpoint.
#2 - The data that's returned from the URL is timestamped to 2020-12-31 15:00:00, so we need to start the backtest before this date to have the data point passed to the OnData method.
#3 - Yes, this can be done by manipulating the `date` argument that's passed to the `GetSource` method.
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.
Mislav Sagovac
Hi Derek,
1) I made this AI endpoint by myself using R plumber API (
https://www.rplumber.io/). It is hosted on Digital Ocean. If it works with RemoteFile, I don't understand why it doesn't work with Rest when it is the same endpoint. I can try try to add login creds, but I am not sure if that will help.
2) I figure out that part.
3) I don't know how to do that. I want to change date on every OnData step. but I define my `GetSource` in Initialize on the beginning. How can I provide date on each step, that is change source url on every step?
Mislav Sagovac
UPDATE:
I have figures out how to change date in url object. I can just use date argument in `GetSource` method:
def GetSource(self, config, date, isLive): source = "http://207.154.227.4/alphar/radf_point?symbols=SPY&date=" + str(date.date()) + "&window=100&price_lag=1&use_log=1" return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile)
I have read on the community that this function is called every day. But I would need hour resolution, that is, I would need to call this function every hour.Â
If I get it right,  SubscriptionTransportMedium.RemoteFile is meant to be used for backtesting, not live trading. And it not meant to be called multiple times in a day. In backtest, I can make it work probbably by importing data every day, but I am not sure how to than transform the code to work in live trading.
If I deploy the algo to live trading, can I make remote file to call dataevery hour?
I still don't understand why Rest doesnt work. I have aked question on digital ocean community, because th eAPI is hosted on their droplet.
Â
Â
Derek Melchin
Hi Mislav,
RemoteFile can be used for live trading. Refer to the source code here and this related thread. To have the GetSource method called every hour, we need to use `Resolution.Hour` when calling `AddData`.
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.
Mislav Sagovac
I still can't make it work.
If I want to get the current data from my url I have to set data query parameter to last time, in my case last hour. But the problem si that date parameter in GetSource(self, config, date, isLive) always return 00:00:00 time. If I get it right RemoteFile returns data only if source (url) canges. To change my url, I need need to change date parameter, but not sure how to provide exact date (say 2021-05-12 10:00:00) and not 2021-05-12 00:00:00.
I would like to add one note. I tried the code in paper trading (with minute resolution), and on sime time stamps
Jared Broad
Hey @Mislav; please send in a support ticket so we can investigate.Â
Best, Jared
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.
Mislav Sagovac
How can I use self.ttime (current time) as input to custom data.?
I have tried withdate paramter in GetSource but it always return 00:00:00 time. That is, it returns only dates and not imes.
How can I use Qc objects as arguemnta to custom data in general?
Â
Derek Melchin
Hi Mislav,
We can access the QCAlgorithm instance from inside a custom data reader by adding a static method.
However, we don't recommend doing this to gather the current time. The data stream runs ahead of the algorithm, so the algorithm time doesn't progress as the data is being read. See the attached backtest for reference.
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.
Mislav Sagovac
Unfortunatelly, I can't make it work. I think I will give it up for now. I really giveit a try, I developed R code, than I made API endpoint that calculates everythng inside that R function, than I subscribe to market data because I can't send data through POST request in QC, than I wrote Custom data to subscribe to that endpoint (GET request), but it doesn't work. The code needs some time, than there is delay between current bar (say 15:00) and custom data bar (say 15:01). I don't understand why bar doesn't way for API endpoint to finish.... Rest doesn't work for some reason...
I will POST solution if I ever find one.
Mislav Sagovac
Derek Melchin Can you please try to put my strategy to paper trading? I an't understant why I am gettingnot found for my Custom data every time. I have traied everything but it doesn't work.
Mislav Sagovac
Here is the code:
Derek Melchin
Hi Mislav,
Here is a simplified version we have tested in live mode:
backtest_b6ff1c068dc1a15a295b8f12d20ffefb.html
We just needed to set the time zone of the data source to UTC:
and set `EndTime` to `utcnow`:
Now you will have to fix the backtest part because
is not in UTC.
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.
Mislav Sagovac
I answered to the support via email, but I am sending the code with comments here too:
Mislav Sagovac
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!