The UZSE Backtest App uses two MongoDB collections inside a singleDocumentation 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.
backtest database. The first collection — trade-results — holds every raw executed trade scraped from the Uzbekistan Stock Exchange. The second — candle-items — holds pre-computed OHLCV candles in 11 timeframes derived from those trades. Data always flows in one direction: from UZSE’s HTML pages, through the trade-results store, into candle-items, and finally into the backtest-kit editor for Pine Script analysis.
Database
| Setting | Value |
|---|---|
| Database name | backtest |
| Connection string env var | MONGO_URI |
| Collections | trade-results, candle-items |
Collection Summary
| Collection | Model | Purpose | Key Index |
|---|---|---|---|
trade-results | TradeModel | Raw executed trades scraped from UZSE | { hash } unique, { symbol, time } compound |
candle-items | CandleModel | OHLCV candles across 11 timeframes | { symbol, interval, timestamp } unique |
Data Flow
Scrape UZSE HTML trade pages → trade-results
The The
download-trades.ts script fetches paginated HTML from the UZSE trade history endpoint for a given ISIN and date range. Each executed trade row is parsed, normalised (including the Russian-language date string), and written to disk as a JSON file.import-trades.ts script then reads those files and performs a bulk upsert into trade-results. Each document is fingerprinted with a SHA1 hash (over symbol|time|tradePrice|quantity|volume|pageIndex|rowIndex|urlKey). The { hash } unique index silently skips any trade that already exists in the database.Aggregate + gap-fill → candle-items (11 timeframes)
The The script accepts both the display symbol (
build-candles.ts script reads trade-results day by day for a given ISIN, builds a gapless 1-minute series (filling intraday gaps and non-trading days with synthetic flat candles), then aggregates all 11 timeframes in a single forward pass per day.HMKB) and the ISIN (UZ7011340005) because the two collections use different symbol namespaces: trade-results stores the ISIN, while candle-items stores the human-readable ticker. All 11 timeframes for all days are written in bulk with insertMany({ ordered: false }) — the { symbol, interval, timestamp } unique index ensures duplicates are skipped rather than errored.Query candle-items → backtest-kit editor
The The result is a continuous OHLCV array with no gaps, ready for Pine Script indicator evaluation.
editor.module.ts registers a mongo-exchange adapter with backtest-kit using addExchangeSchema. When a Pine Script strategy requests candle data, the adapter queries candle-items by (symbol, interval, timestamp >= since), sorted ascending with a limit:Symbol Namespace Mapping
The two collections use different identifiers for the same security:| Collection | Symbol field | Example value | Meaning |
|---|---|---|---|
trade-results | symbol (ISIN) | UZ7011340005 | International Securities Identification Number |
candle-items | symbol (display name) | HMKB | Human-readable ticker used by the editor |
build-candles.ts script is the bridge between these namespaces. It queries trade-results using the ISIN and writes to candle-items using the display symbol. Both arguments must be supplied on the command line:
Idempotency Guarantees
Both collections are designed for safe re-ingestion at any stage of the pipeline:trade-results: SHA1 hash deduplication
Every trade document carries a
hash field (SHA1 over trade content + scraping context). The { hash: 1 } unique index means re-importing the same UZSE export file never creates duplicates — already-seen rows are silently skipped.candle-items: Composite unique index
The
{ symbol: 1, interval: 1, timestamp: 1 } unique index means re-running build-candles.ts for any symbol and date range already in the database will skip all existing candles rather than failing or creating duplicates.Example MongoDB Queries
The following queries can be run directly inmongosh or MongoDB Compass against the backtest database.
Bulk Import via mongoimport
If you have a pre-existing JSON dump (e.g. from a colleague or a previousmongoexport), you can seed both collections directly without running the full scraping pipeline:
Related Pages
Candle Schema
Full field-level reference for the
candle-items collection.Trade Schema
Full field-level reference for the
trade-results collection.Timeframes
All 11 OHLCV timeframes and the gap-fill aggregation algorithm.
MongoDB Infrastructure
Connection configuration, Atlas setup, and recommended index management.
Build Candles
Step-by-step guide to running
build-candles.ts.Exchange Module
How
getCandles() in editor.module.ts bridges MongoDB and backtest-kit.