# HTX Spot

HTX Spot historical data for **high caps currency pairs** is available since **2019-11-19,** data for all currency pairs is available since **2022-06-09**.

{% embed url="<https://api.tardis.dev/v1/exchanges/huobi>" %}
See HTX Spot historical data coverage: available symbols, channels, date ranges and incidents
{% endembed %}

### Downloadable **CSV** files

Historical CSV datasets for the first day of each month are **available to download without API key**. See [downloadable CSV files documentation](https://docs.tardis.dev/downloadable-csv-files/overview).

| data type             | symbol  | date       |                                                                                                       |
| --------------------- | ------- | ---------- | ----------------------------------------------------------------------------------------------------- |
| incremental\_book\_L2 | BTCUSDT | 2019-12-01 | [Download sample](https://datasets.tardis.dev/v1/huobi/incremental_book_L2/2019/12/01/BTCUSDT.csv.gz) |
| trades                | BTCUSDT | 2019-12-01 | [Download sample](https://datasets.tardis.dev/v1/huobi/trades/2019/12/01/BTCUSDT.csv.gz)              |
| quotes                | BTCUSDT | 2019-12-01 | [Download sample](https://datasets.tardis.dev/v1/huobi/quotes/2019/12/01/BTCUSDT.csv.gz)              |

### API Access and data format

Historical data format is the same as provided by real-time HTX Spot WebSocket API with addition of local timestamps. If you'd like to work with **normalized data format** instead (same format for each exchange) see [downloadable CSV files](https://docs.tardis.dev/downloadable-csv-files/overview) or official [client libs](https://docs.tardis.dev/api/quickstart) that perform data normalization client-side.

{% tabs %}
{% tab title="Python" %}

```python
# pip install tardis-dev
import asyncio
from tardis_dev import Channel, replay

async def main():
    async for local_timestamp, message in replay(
        exchange="huobi",
        from_date="2024-01-01",
        to_date="2024-01-02",
        filters=[Channel(name="mbp", symbols=["btcusdt"])],
        api_key="YOUR_API_KEY",
    ):
        # messages as provided by HTX Spot real-time stream
        print(message)

asyncio.run(main())
```

See [Python client docs](https://docs.tardis.dev/python-client/quickstart).
{% endtab %}

{% tab title="Node.js" %}

```javascript
// npm install tardis-dev
import { replay } from 'tardis-dev';

const messages = replay({
  exchange: 'huobi',
  from: '2024-01-01',
  to: '2024-01-02',
  filters: [{ channel: 'mbp', symbols: ['btcusdt'] }],
  apiKey: 'YOUR_API_KEY'
});

// messages as provided by HTX Spot real-time stream
for await (const { localTimestamp, message } of messages) {
  console.log(localTimestamp, message);
}
```

See [Node.js client docs](https://docs.tardis.dev/node-client/quickstart).
{% endtab %}

{% tab title="cURL & HTTP API" %}

```bash
curl --compressed -g 'https://api.tardis.dev/v1/data-feeds/huobi?from=2024-01-01&filters=[{"channel":"mbp","symbols":["btcusdt"]}]&offset=0'
```

{% embed url="<https://api.tardis.dev/v1/data-feeds/huobi?from=2024-01-01&filters=[{%22channel%22:%22mbp%22,%22symbols%22:[%22btcusdt%22]}]&offset=0>" %}
Example API response for HTX Spot historical market data request
{% endembed %}

See [HTTP API docs](https://docs.tardis.dev/api/http-api-reference).
{% endtab %}

{% tab title="cURL & tardis-machine" %}

```bash
curl -g 'localhost:8000/replay?options={"exchange":"huobi","filters":[{"channel":"mbp","symbols":["btcusdt"]}],"from":"2024-01-01","to":"2024-01-02"}'
```

[Tardis-machine](https://docs.tardis.dev/tardis-machine/quickstart) is a locally runnable server that exposes API allowing efficiently requesting historical market data for whole time periods in contrast to [HTTP API](https://docs.tardis.dev/api/http-api-reference) that provides data only in minute by minute slices.

See [tardis-machine](https://docs.tardis.dev/tardis-machine/quickstart) docs.
{% endtab %}
{% endtabs %}

### Captured real-time channels

{% embed url="<https://www.htx.com/en-us/opend/newApiPages/?id=662>" %}
See HTX Spot WebSocket API docs providing documentation for each captured channel's format
{% endembed %}

{% hint style="info" %}
Click any channel below to see [HTTP API](https://docs.tardis.dev/api/http-api-reference#data-feeds-exchange) response with historical data recorded for it.
{% endhint %}

* [trade](https://api.tardis.dev/v1/data-feeds/huobi?from=2024-01-01\&filters=\[{%22channel%22:%22trade%22,%22symbols%22:\[%22btcusdt%22]}]) Trade executions stream
* [depth](https://api.tardis.dev/v1/data-feeds/huobi?from=2020-12-01\&filters=\[{%22channel%22:%22depth%22,%22symbols%22:\[%22btcusdt%22]}]) — available **until 2020-12-10** Legacy full depth snapshots stream replaced by mbp. Collected with `step0` aggregation level. Publishes full order book snapshots which are stored as initial snapshot plus incremental updates (calculated by diffing subsequent snapshots, marked with `"update": true` flag).
* [mbp](https://api.tardis.dev/v1/data-feeds/huobi?from=2024-01-01\&filters=\[{%22channel%22:%22mbp%22,%22symbols%22:\[%22btcusdt%22]}]) — available since **2020-07-03** Market by price incremental updates stream. Subscribed as mbp.150 (150-level) until 2021-08-26, after that as mbp.400 (400-level). MBP feed is based on snapshots at 100ms interval via /feed endpoint. Initial order book snapshot is fetched via "req" request on the same WebSocket connection. During data collection integrity of incremental updates is validated using sequence numbers (seqNum and prevSeqNum) — on sequence gap a new snapshot is requested automatically.
* [mbp.20](https://api.tardis.dev/v1/data-feeds/huobi?from=2024-01-01\&filters=\[{%22channel%22:%22mbp.20%22,%22symbols%22:\[%22btcusdt%22]}]) — available since **2022-05-27** Market by price 20-level incremental updates stream. Tick by tick feed via /feed endpoint. Only collected for select high-cap symbols. Initial order book snapshot is fetched via "req" request.
* [bbo](https://api.tardis.dev/v1/data-feeds/huobi?from=2024-01-01\&filters=\[{%22channel%22:%22bbo%22,%22symbols%22:\[%22btcusdt%22]}]) Best bid and ask quote updates stream
* [detail](https://api.tardis.dev/v1/data-feeds/huobi?from=2024-01-01\&filters=\[{%22channel%22:%22detail%22,%22symbols%22:\[%22btcusdt%22]}]) 24h market statistics stream
* [etp](https://api.tardis.dev/v1/data-feeds/huobi?from=2022-11-01\&filters=\[{%22channel%22:%22etp%22}]) — available since **2020-08-17**, available **until 2022-11-22** Leveraged token NAV and premium updates stream

### Market data collection details

[Market data collection infrastructure](https://docs.tardis.dev/faq/general#what-is-your-infrastructure-setup) for HTX Spot is located in GCP asia-northeast1 region (Tokyo, Japan). Before **2020-06-19** it was located in GCP europe-west2 region (London, UK).

Real-time market data is captured via **multiple WebSocket connections** to `wss://api-aws.huobi.pro/ws`.

{% hint style="info" %}
HTX servers are located in AWS ap-northeast-1 region (Tokyo, Japan).
{% endhint %}
