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.
import-trades.ts is the second step in the data pipeline. It reads every trades_page_*.html file that download-trades.ts saved in tmp/, parses the HTML trade tables using regex, and inserts each row as a structured document into the trade-results MongoDB collection. A SHA1 hash derived from each row’s content acts as a unique key so the script is fully idempotent — re-running it never creates duplicates.
How It Works
Reading HTML Pages
The script scanstmp/ for files matching trades_page_*.html and sorts them numerically (page 1 before page 2, and so on). If no matching files exist the script exits with an error, so always run download-trades.ts first.
Parsing Trade Table Rows
Each file’s HTML is walked with a<tr> regex. For every row the script extracts the inner text of each <td>, strips HTML tags, and collapses whitespace. Rows with fewer than 10 cells are skipped (headers, footers, empty rows).
The ten fields extracted per row map directly to ITradeDto:
| Field | Description |
|---|---|
time | Trade timestamp — parsed from Russian locale text (see below) |
symbol | ISIN code of the security, e.g. UZ7011340005 |
issuer | Issuer name, e.g. <Hamkorbank> ATB |
securityType | Security type, e.g. Простые акции (common shares) |
market | Market sector, e.g. STK, BON |
platform | Trading session, e.g. G1, G2 |
tradePrice | Price per security in the trade |
quantity | Number of securities traded |
volume | Total trade value in UZS (tradePrice × quantity) |
hash | SHA1 deduplication key (generated, not parsed from HTML) |
Russian Date Parsing
UZSE renders timestamps in Russian locale. The script contains a full month-name lookup table and parses strings in the format:января through декабря), producing a UTC Date object for each trade.
SHA1 Deduplication
Before inserting a row the script computes a SHA1 hash over the concatenated string:urlKey is derived from the begin, end, and search_key query parameters embedded in the page HTML. This hash is stored as the hash field and is backed by a unique index in MongoDB — any document with an already-seen hash is rejected with error code 11000 (duplicate key) and counted as skipped rather than inserted.
Usage
trades_page_*.html files from tmp/.
Idempotency
Runningimport-trades.ts more than once against the same HTML files is safe. The console output at the end of every run reports both counters:
After all pages have been processed, the script automatically deletes every
.html file from tmp/ and prints Tmp cleaned. — so you will not be able to re-import from the same downloaded files without re-running download-trades.ts.MongoDB Collection
Imported trade documents are stored in thetrade-results collection. Each document has the following structure (from Trade.schema.ts):
time, symbol, and a compound { symbol, time } index for efficient range queries. The hash field carries a unique index.
Next Step
Build OHLCV Candlesticks
Aggregate all imported trades into continuous OHLCV candlestick series across 11 timeframes, with automatic gap-filling for intraday minutes and non-trading days.