Hi,
I created an account a couple days ago, went through the BootCamp, the documentation, and looked a bit in the source code (I am not familiar in C# however). I really like the fact that LEAN is open-source; I am planning on using the managed version for now since I'm a beginner, but I still want to know now if I can make it run locally (and test on a custom data source). Two of my goals were: add some custom data source that is pulled from an exchange API and add a brokerage class for Alpaca. I have some questions related to that which I wasn't able to find clear answers for in the docs:
- If I understand correctly, the engine (both in Live and Backtesting) has several data subscriptions. As the time frontier progresses, the different data subscriptions return data objects (ticks or timebars) that are sent to the onData functions of the algorithm. If needed, I could add consolidators to group the tick data into higher resolution bars. Am I describing correctly how the engine works? Does that mean that for live trading we don't necessarily need tick data? i.e. our live trading source could directly send us bars? (or does it send us ticks that I would need to consolidate myself)
- If I want to use python code to add custom data to my algorithm, i have to put the python code directly in the algorithm file, like this? I wanted to use the ccxt library to get data from multiple exchanges, but I cannot split the python code into multiple files? If I wanted to do it properly in C#, i would have to create new BaseData classes like this?
- Could someone give me pointers as to where to look to undertstand how the data handling works? To add a custom data source, the docs just mention adding `AddData` and `CustomData : BaseData`, but is there some docs explaining how the broader logic of DataSources/DataFeeds/DataSubscriptions work?
- It says here that with Resolution.Tick, the custom data source will be polled constantly. Does that mean that the connection has to be open via a websocket? Or can it be anything, even a file, and LEAN deals with converting it into a stream. What about for live trading? I notice that the Tiingo example is for daily calls to the api, but how does it work for live trading and constant polling?
- The docs mention 'quote ticks', are those top of the book quotes, or can they be L2 quotes as well? (or would i have to write a custom class that overrides BaseData)
- I wanted to contribute by adding an implementation of a Brokerage class for Alpaca, but I was a bit discouraged after seeing how complicated the InteractiveBrokers implementation looked. Also the IB Brokerage class seems to include methods to get live and historical data. Is that because during live trading LEAN switches to using the broker's data as a data source? Is it a requirement to have those?
Thanks in advance for the help, I hope this thread can help others as well
Derek Melchin
Hi Charles,
(1)
> Am I describing correctly how the engine works?
Yes
> Does that mean that for live trading we don't necessarily need tick data? i.e. our live trading source could directly send us bars? (or does it send us ticks that I would need to consolidate myself)
Correct
(2) The custom data class definition doesn't need to be inside the algorithm class definition. Refer to the example here.
(3) We are in the process of updating our documentation. For assistance setting up a custom data source, refer to the link above.
(4)
> Does that mean that the connection has to be open via a websocket? Or can it be anything, even a file, and LEAN deals with converting it into a stream
A remote file is sufficient.
> I notice that the Tiingo example is for daily calls to the api, but how does it work for live trading and constant polling?
As new Tiingo news objects are received throughout the day, the data is automatically passed to the algorithm.
(5) They are quotes for the top of the book. We don't currently support level 2 data.
(6)
> I wanted to contribute by adding an implementation of a Brokerage class for Alpaca
We recently removed the Alpaca brokerage. Refer to this related thread.
> I was a bit discouraged after seeing how complicated the InteractiveBrokers implementation looked.
Refer to our brokerage development guide.
> the IB Brokerage class seems to include methods to get live and historical data. Is that because during live trading LEAN switches to using the broker's data as a data source?
When deploying to live trading, we can select the data provider. It's possible to use QC data but place trades through IB.
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.
Charles Bournhonesque
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!