Hello,
Does anyone know if it’s possible to fetch FTX perpetual future funding rates within the QuantConnect environment?
I know it’s available in the FTX API (https://docs.ftx.com/?csharp#get-funding-rates) but I am a bit lost trying to import custom data, so I was hoping there is an easier way given FTX is supported by QuantConnect.
Fred Painchaud
Hi Pi,
Crypto perpetual futures are not handled yet, in general. The only means I see right now to bring funding rates inside QC/LEAN is through custom data and of course the usage of the FTX API, or the usage of the FTX API alone and glue code between your algo and FTX (which then is more work).
Re custom data, I believe you would need to use the “streaming” type. Looks like you code your algos in C# (re the C# FTX API ref). If you go for glue code, you would need to implement a small client to fetch the data with the FTX API and save it inside say CSV files on Dropbox, and then fetch that data with the “remote” type of custom data.
In both cases, you would need to code a class holding the data.
If you find that too confusing, I don't see any other more easy way right now. Sorry.
Fred
Pi..R
Thanks a lot Fred, I am gonna give a go at using custom data with “streaming” type. I will share my progress here.
Pi..R
Hi again Fred,
I am trying to get the funding rate of BTC using custom data (I used this example to help me with the code: https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/CustomDataBitcoinAlgorithm.cs), but I am getting an error saying data wasn't found in the Slice object. Any clue what I am getting wrong in the attached backtest?
Louis Szeto
Hi Pi..R and Fred
It should be a RemoteFile since it does not use WSS communication, with an UnfoldingDataCollection file type that abstracts multiple data points into a one-liner. The received JSON also required deserialization at its root level. We filter out the “result” attribute for our data point in Reader method. The multiple data points would need to be returned as BaseDataCollection to work properly. Please refer to the attach backtest for details.
Best
Louis
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.
Pi..R
Hi Louis,
Thanks a lot for that, this is awesome! I would very much appreciate your (paid) help to refine the code a bit further and allow storing the funding rate in a symbolData object for a multi-symbol algo. Let me know if interested, (maybe we can arrange a 1h tutoring session, I know QC used to do that) you can shot me an email at 3.1415rx@gmail.com.
Thanks!
Fred Painchaud
Superb Louis!!!
Pi..R
Hi again, I have tried make Louis code multi symbol in the backtest attached, but with my poor coding skills, I am stuck.
I have a list of symbols in “UserVar” and I am storing a bunch of information for each in a dictionary of symbolData objects that is created in the Initialize() method and access every 4H in the OnData() block when data is consolidated.
Problem #1: In the Initialize() block, I also call the “AddData<FundingRate>” method for each symbol in my list. The main issue is that at the moment the “source” in the "FundingRate" class is static and set to BTC “https://ftx.com/api/funding_rates?future=BTC-PERP”; I would need to pass “symbolData.BaseSymbol” to be used instead of “BTC” for each symbol, but I don't know how to do that.
Problem #2: I need to figure out how to retrieve the FundingRate data for each symbol so I can update “symbolData.FundingRate”. Maybe I also have to store the FundingRate objects for each symbol into a dictionary, but it might be there is a more efficient way to do that.
I can probably figure out #2 by myself, but would appreciate any help with #1 (QCC bounty on offer 😊).
Louis Szeto
Hi Pi.R
See the attached backtest as an example.
Best
Louis
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.
Pi..R
Thanks a lot Louis!
I am almost there, I have added line 64 an instruction so each crypto in cryptos is added to the ‘_fundingRates’ dictionary you created line 52, but I can’t figure out how to update each individual funding rate value in the dictionary in the ‘OnData’ block.
I have tried playing around the ‘data.Get<FundingRate>()’ you used in your original foreach loop, but without success. Can you indicate how to do that?
Pi..R
I found a way to store the funding rate for each symbolData object using your foreach loop, maybe not the most efficient way to do, but it works. Sharing here in case it can help others, that trivial:
Thanks a lot for your help Louis!
Pi..R
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!