I have a polygon api and am trying to understand how I can use it for either local backtesting or live trading that's hosted on my own PC via lean. How do I incorporate the code into my algorithm?
I found this post, however creating the config.json file as described here leads to build errors.
Fred Painchaud
Hi Axist,
Unfortunately, a detailed answer is too long. It's a bit like asking “How do you build a car?”…
For data live feeds, the best is to use the websockets' channels. For instance, for stocks:
https://polygon.io/docs/stocks/ws_getting-started
For Python, also check out the client-python, https://github.com/polygon-io/client-python.
For integration into LEAN, the principle is that you need to use Custom Data to code the glue between LEAN and your websockets. You can look at https://www.quantconnect.com/docs/v2/writing-algorithms/importing-data/key-concepts to get the basic principles but the explanations are for backtesting, live trading.
For high-level coding in Python on websockets, I recommend using websockets, https://websockets.readthedocs.io/en/stable/.
You can also interface LEAN with REST endpoints. But then each data request is an HTTP request. With websockets, it's a long-lived connection spitting data. More appropriate for live trading.
Fred
Yuri Lopukhov
Fred Painchaud I am pretty sure he is referring the polygon integration that exists in Lean and is mentioned on the forum link he has shared. Not sure why are you suggesting him to build the full car, while there is one already.
Axist I can't really help with this though, as I haven't tried to set it up yet and I would appreciate some kind of tutorial myself. New documentation has a stub for this here:
https://www.quantconnect.com/docs/v2/lean-engine/getting-started
You can also try seeking help in Discord channel:
https://discord.com/channels/846109296973840424/846131651201466429
Axist
I see this here:
https://lean-api-docs.netlify.app/PolygonDataDownloader_8cs_source.html
However no idea how to use/invoke it into my algorithm. Seems to be zero documentation on it as well.
Debating giving up and just trying to understand how I might code the websockets
Yuri Lopukhov
You should be able to download data with lean toolkit, there is a very limited documentation here. I don‘t know if it will work in real-time. You may want to ask for help in lean discord channel.
Derek Melchin
Hi Axist,
To use the Polygon data feed in a local live trading algorithm, see Polygon in the LEAN CLI docs.
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.
Axist
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!