Skip to content
All library documents

Collecting and Sharing Exchange K-Line Data with MongoDB

Article FMZ digest · Author: 善

Summary

This guide describes a Python collector that reads completed K-line bars from an exchange through the FMZ platform and stores them in MongoDB. Other trading robots can then read the stored records as a shared data source, reducing repeated exchange requests and providing historical bars for pairs or intervals that may not be available in the platform’s built-in backtest data. The collector writes initial history and adds a bar when a new period begins. The example also shows how the platform can synthesize a custom interval, such as a three-minute bar, from its configured market data.

The article demonstrates separate collector and reader robots, including plotting the retrieved records, and explains basic database setup. Its limits are clear: the sample reader fetches every stored record repeatedly, which can become inefficient as the collection grows, and the collector omits the currently forming bar. The author suggests querying only newer records or adapting the collector when real-time bar updates are needed. The examples illustrate data plumbing rather than a trading signal or a performance-tested strategy.

Key ideas

  • A persistent market-data store lets multiple robots share collected bars without each requesting them from the exchange.
  • The example saves completed K-line records in MongoDB and allows another robot to retrieve and plot them.
  • The platform can synthesize custom bar intervals from the configured market data.
  • Repeatedly loading the full collection can impair performance as stored history grows.
  • The sample excludes the forming bar, so real-time bar data requires a modification.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.