Skip to main content

Documentation 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.

download-trades.ts is the first step in the UZSE data pipeline. It launches a headless Chromium browser via Playwright, navigates to https://uzse.uz/trade_results with the parameters you supply, auto-detects how many result pages exist, and saves each page as an HTML file in the local tmp/ directory for the next import step to consume.

Usage

npx tsx scripts/download-trades.ts <symbol> <begin> <end> [mktId]

Arguments

symbol
string
required
ISIN code of the security to query, e.g. UZ7011340005.
begin
string
required
Start date of the query window in DD.MM.YYYY format, e.g. 01.01.2024.
end
string
required
End date of the query window in DD.MM.YYYY format, e.g. 31.01.2024.
mktId
string
Market sector to filter by. Defaults to STK when omitted.
ValueDescription
STKEquity / stocks market
BONBond market

Example

npx tsx scripts/download-trades.ts UZ7011340005 01.01.2024 31.01.2024

URL Pattern

For each page N, the script builds and fetches:
https://uzse.uz/trade_results?begin={begin}&end={end}&mkt_id={mktId}&page={N}&search_key={symbol}
Page detection is done by parsing the .last.next CSS selector in the first page’s HTML to read the highest available page number.

Behavior

1

Clear stale HTML

Before any network requests are made, all existing .html files are deleted from tmp/ to prevent stale data from a previous run mixing with new results.
2

Fetch page 1 and detect total pages

The script fetches page 1 and inspects the pagination markup. The regex /class="last next">\s*<a[^>]+[?&](?:amp;)?page=(\d+)/ extracts the last page number. If no pagination element is found, the total is assumed to be 1.
3

Download remaining pages

Pages 2 through N are fetched sequentially. Each page is written to tmp/trades_page_N.html.
4

Close browser

Playwright shuts down the headless Chromium instance and reports the output directory path.

Retry Logic

Network timeouts on uzse.uz are common. The script retries automatically before giving up.
ParameterValue
TIMEOUT30 s
RETRIES10
RETRY_DELAY30 s
If a page load exceeds 30 seconds, the script waits 30 seconds and then retries. After 10 failed attempts on the same page an error is thrown and the process exits with code 1.

Output

Saved files follow the naming convention tmp/trades_page_N.html where N is the 1-based page index. A summary line is printed after the last page:
Total pages: 3
Downloaded page 2/3
Downloaded page 3/3
Done. HTML saved to /path/to/tmp
The tmp/ directory is created automatically if it does not already exist. Ensure the process has write permissions to the project root.

Next Step

Once the HTML pages are saved to tmp/, proceed to Import Trades to parse them and insert the records into MongoDB.

Build docs developers (and LLMs) love