Collecting and Sharing Kline Data with MongoDB
Summary
This tutorial describes a simple market-data collector for quantitative research and strategy backtesting. A Python trading bot requests exchange candlesticks and stores completed bars in MongoDB, initially writing the available history and then appending the most recently completed bar when a new interval begins. A separate strategy reads the stored records and plots them, allowing multiple bots to use a shared data source rather than each querying the exchange. The article also explains how the platform can construct a requested bar interval, such as three-minute bars, from exchange data.
The examples show the collector and reader running as separate bots and demonstrate shared chart data. The author presents the code as a basic illustration, not a production data pipeline. In particular, the reader fetches the entire collection repeatedly, which may slow down as records accumulate; the article suggests querying only new records as an improvement. The collector also omits the currently forming bar, and handling real-time updates would require changes. Database setup, retention, data validation, and recovery are not explored in depth.
Key ideas
- A collector can persist completed exchange bars in MongoDB for later strategy use.
- Multiple bots can read one shared database instead of making duplicate market-data requests.
- The example writes historical bars first, then appends a completed bar when a new interval appears.
- A platform can synthesize bar intervals that an exchange does not provide directly.
- Repeatedly loading the full collection can become inefficient as stored data grows.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.