The exchange module bridges the MongoDB candle storage layer and theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/backtest-kit/uzse-backtest-app/llms.txt
Use this file to discover all available pages before exploring further.
backtest-kit framework by registering a custom exchange adapter named "mongo-exchange". Once registered, backtest-kit can query UZSE candlestick data stored in the candle-items collection using the same interface it would use against any live exchange — enabling Pine Script strategy backtesting and chart analysis entirely from local data without external API calls.
addExchangeSchema
addExchangeSchema is the backtest-kit registration function that binds a named exchange to a user-supplied candle-fetching callback. The UZSE app calls it once at module load time with the "mongo-exchange" name and a MongoDB-backed implementation.
backtest-kit
Parameters
Unique name used to identify this exchange within
backtest-kit. All three module entry points register under "mongo-exchange".Async callback invoked by
backtest-kit whenever it needs candle data. Receives the four arguments below and must return a Promise that resolves to an array of OHLCV objects.getCandles Arguments
Ticker symbol matching documents in
candle-items, e.g. "HMKB". Passed directly as the symbol field in the MongoDB query filter.One of the eleven supported timeframes (
"1m" … "1d"). Passed directly as the interval field in the MongoDB query filter.Only candles with
timestamp >= since.getTime() are returned. Converted to a millisecond integer via .getTime() before being used in the $gte query operator.Maximum number of candle documents to return. Applied via Mongoose’s
.limit() after sorting by timestamp ascending.MongoDB Adapter Implementation
The following is the exact implementation shared by all three module entry points (editor.module.ts, dump.module.ts, pine.module.ts):
{ timestamp: 1, open: 1, high: 1, low: 1, close: 1, volume: 1, _id: 0 } ensures that only the OHLCV fields are transferred from MongoDB — Mongoose metadata, symbol, interval, and the auto-timestamp fields are excluded from the returned objects.
Return Type
Each element of the returned array has the following shape:Module Entry Points
All three module files contain identicaladdExchangeSchema registrations. They serve as entry points for different backtest-kit execution contexts:
| File | Context |
|---|---|
editor.module.ts | Interactive chart editor (npm start) |
dump.module.ts | Data dump / export pipeline |
pine.module.ts | Pine Script strategy execution |
Each file imports
"../config/setup" as a side-effect, which initialises the Mongoose connection before CandleModel is used. The setup module reads MONGO_URI from the environment; if unset it defaults to mongodb://localhost:27017/backtest.How It Is Loaded
The editor registers the module automatically when the application is started:backtest-kit’s runner. The adapter must be registered before any backtest-kit function that requests candle data is called.
Ensure
MONGO_URI is set in your environment (or .env file) before importing any of the three module files. The setup side-effect import runs synchronously at module load time, so the connection is established as part of the import chain.