Documentation 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.
build-candles.ts is the final step in the data pipeline. It reads every trade for a given ISIN from the trade-results collection, aggregates them into 1-minute buckets, forward-fills every gap (intraday minutes with no activity and entire non-trading days), and then fans the filled 1-minute series out into 10 additional higher timeframes — writing all resulting candles to the candle-items collection.
Usage
Parameters
The display ticker symbol stored on each candle document, used by the backtest-kit editor to query candles.
Example:
Example:
HMKBThe ISIN code used to look up trades in the
Example:
trade-results collection.Example:
UZ7011340005Example
Supported Timeframes
The script generates candles for all 11 timeframes in a single pass:| Interval | Minutes |
|---|---|
1m | 1 |
3m | 3 |
5m | 5 |
15m | 15 |
30m | 30 |
1h | 60 |
2h | 120 |
4h | 240 |
6h | 360 |
8h | 480 |
1d | 1440 |
Algorithm
The candle-building process follows five numbered steps, each building on the output of the previous.Aggregating Real Minutes
Each trade is placed into a 1-minute bucket using
floor(time, 1m). Multiple trades within the same minute are combined into a single OHLCV candle:- open — price of the first trade in the bucket
- high / low — maximum / minimum price across all trades
- close — price of the last trade in the bucket
- volume — sum of
quantity(number of securities, not UZS value)
Filling Intraday Gaps
A continuous 1-minute series is generated from
00:00 to 23:59 for every day in the range. Minutes that have no real trades are filled with:- OHLC =
closeof the most recent preceding real candle - volume =
0
Filling Non-Trading Days
Days on which the exchange was closed (weekends, public holidays) contain no trades at all. All 1,440 minutes of such a day receive:
- OHLC =
closeof the last day that had real trades - volume =
0
lastClose) is tracked across the entire day loop so it propagates correctly through consecutive non-trading days.Aggregating Higher Timeframes
All 11 timeframes (including 1m) are accumulated simultaneously in a single pass over the filled 1-minute series for each day. Each higher-timeframe bucket is keyed by
floor(timestamp, N minutes):- open — from the first 1m candle of the period
- high / low — max / min across all 1m candles in the period
- close — from the last 1m candle of the period
- volume — sum of volume across all 1m candles in the period
insertMany call.Idempotency
The
candle-items collection has a compound unique index on { symbol, interval, timestamp }. If a candle for a given symbol, timeframe, and timestamp already exists, the insertMany skips it (using ordered: false) rather than throwing an error. The script tallies both inserted and skipped counters and prints them at the end.MongoDB Collection
Candles are stored in thecandle-items collection with the following document shape (from Candle.schema.ts):
{ symbol: 1, interval: 1, timestamp: 1 }.
Progress Output
The script writes a single auto-updating line to stdout per day, showing live progress:If you have a pre-built candle dump (e.g.
backtest.candle-items.json), you can bypass the build step entirely and import directly with mongoimport: