The exchange module is the integration layer between the MongoDB candle store and the backtest-kit toolchain. Rather than hardwiring a connection to a live exchange API, backtest-kit exposes anDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/uzse-backtest-app/llms.txt
Use this file to discover all available pages before exploring further.
addExchangeSchema registration function that lets you supply any async data source — in this case, a MongoDB query against locally built OHLCV candles. Every tool in the project (the visual editor, the Pine Script runner, and the data dump utility) registers the same "mongo-exchange" schema through this mechanism, so all three share an identical data contract.
The Three Module Files
All three module files in themodules/ directory are thin wrappers that call addExchangeSchema with the same implementation. They exist as separate entry points so each tool can load only what it needs at startup:
editor.module.ts
Loaded by the visual editor when you run
npm start. Registers the "mongo-exchange" schema so the chart UI can fetch candles for any selected symbol and timeframe.pine.module.ts
Loaded when running Pine Script backtests programmatically. Provides the same MongoDB-backed candle feed to the
@backtest-kit/pinets execution engine.dump.module.ts
Loaded for data export and dump operations. Allows external scripts to pull OHLCV data from MongoDB through the standard backtest-kit candle interface.
Full Module Code
Each of the three module files contains the following implementation (shown here aseditor.module.ts):
The
import "../config/setup" line at the top of each module file handles the MongoDB connection automatically. config/setup.ts calls mongoose.connect() using the MONGO_URI environment variable when it is imported, so no explicit connection management is needed in the module itself. The database is ready by the time getCandles is first invoked.addExchangeSchema API Reference
A unique string identifier for this data source within the backtest-kit registry. This project uses
"mongo-exchange". The visual editor references this name when resolving which getCandles function to call for a given chart.An async function that accepts four parameters and returns an array of OHLCV candle objects. backtest-kit calls this function whenever the editor or backtest engine needs market data.Parameters:Return value: An array of plain objects with the following shape, matching the Candle Schema:
The ticker symbol to query, e.g.
"HMKB" or "UZ7011340005". Must match the symbol field stored in the candle-items collection.The candlestick timeframe string, e.g.
"1m", "1h", "1d". Must match the interval field in the candle-items collection. See Timeframes Reference for all valid values.A JavaScript
Date object representing the earliest timestamp to include. The query converts this to milliseconds via since.getTime() and applies a $gte filter on the timestamp field.The maximum number of candles to return. Passed directly to Mongoose’s
.limit() method. The editor controls this value based on the visible chart window.MongoDB Query Details
ThegetCandles implementation constructs a Mongoose query with the following characteristics:
| Aspect | Detail |
|---|---|
| Filter | { symbol, interval, timestamp: { $gte: since.getTime() } } |
| Projection | Returns only timestamp, open, high, low, close, volume; excludes _id |
| Sort | Ascending by timestamp ({ timestamp: 1 }) |
| Limit | Capped at the limit argument provided by the caller |
| Lean | .lean() is called to return plain JS objects instead of Mongoose documents, improving throughput |
timestamp field is stored as a Unix millisecond integer in MongoDB. since.getTime() converts the Date argument to the same unit before comparison.
Adapting to a Different Data Source
TheaddExchangeSchema contract only requires that getCandles returns an array of { timestamp, open, high, low, close, volume } objects. The internal implementation can use any data retrieval mechanism.
Related Pages
Visual Editor
Start the backtest-kit chart editor that loads
editor.module.ts on launch.Pine Script
Apply Pine Script v6 indicators to the candle data served by this module.
Candle Schema
See the full MongoDB document structure for the OHLCV records queried here.
MongoDB Infrastructure
Configure and run the MongoDB instance that backs the exchange module.