# HTX Coin-M Futures

HTX Coin-M Futures historical data for **all its instruments** is available since **2019-11-19**.

{% embed url="<https://api.tardis.dev/v1/exchanges/huobi-dm>" %}
See HTX Coin-M Futures 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).

{% hint style="info" %}
Derivative ticker datasets are available since 2020-06-24.
{% endhint %}

| data type             | symbol  | date       |                                                                                                         |
| --------------------- | ------- | ---------- | ------------------------------------------------------------------------------------------------------- |
| incremental\_book\_L2 | BTC\_CQ | 2020-02-01 | [Download sample](https://datasets.tardis.dev/v1/huobi-dm/incremental_book_L2/2020/02/01/BTC_CQ.csv.gz) |
| trades                | BTC\_CQ | 2020-02-01 | [Download sample](https://datasets.tardis.dev/v1/huobi-dm/trades/2020/02/01/BTC_CQ.csv.gz)              |
| derivative\_ticker    | BTC\_CQ | 2020-07-01 | [Download sample](https://datasets.tardis.dev/v1/huobi-dm/derivative_ticker/2020/07/01/BTC_CQ.csv.gz)   |

### API Access and data format

Historical data format is the same as provided by real-time HTX Coin-M Futures 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-dm",
        from_date="2024-01-01",
        to_date="2024-01-02",
        filters=[Channel(name="depth", symbols=["BTC_CW"])],
        api_key="YOUR_API_KEY",
    ):
        # messages as provided by HTX Coin-M Futures 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-dm',
  from: '2024-01-01',
  to: '2024-01-02',
  filters: [{ channel: 'depth', symbols: ['BTC_CW'] }],
  apiKey: 'YOUR_API_KEY'
});

// messages as provided by HTX Coin-M Futures 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-dm?from=2024-01-01&filters=[{"channel":"depth","symbols":["BTC_CW"]}]&offset=0'
```

{% embed url="<https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01&filters=[{%22channel%22:%22depth%22,%22symbols%22:[%22BTC_CW%22]}]&offset=0>" %}
Example API response for HTX Coin-M Futures 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-dm","filters":[{"channel":"depth","symbols":["BTC_CW"]}],"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=447>" %}
See HTX Coin-M Futures 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-dm?from=2024-01-01\&filters=\[{%22channel%22:%22trade%22}]) Trade executions stream
* [depth](https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01\&filters=\[{%22channel%22:%22depth%22}]) Order book snapshots and incremental updates stream. Order book integrity is validated using sequence numbers (`version` field) — on missed message the WebSocket connection is restarted. **See also details below regarding depth channel data collection details.**
* [bbo](https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01\&filters=\[{%22channel%22:%22bbo%22}]) — available since **2020-06-23** Best bid and ask quote updates stream
* [liquidation\_orders](https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01\&filters=\[{%22channel%22:%22liquidation_orders%22}]) — available since **2020-06-23** Liquidation events stream
* [contract\_info](https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01\&filters=\[{%22channel%22:%22contract_info%22}]) — available since **2020-06-23** Contract definition and status updates stream
* [basis](https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01\&filters=\[{%22channel%22:%22basis%22}]) — available since **2020-06-23** Basis and index price updates stream
* [open\_interest](https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01\&filters=\[{%22channel%22:%22open_interest%22}]) — generated channel, available since **2020-06-23** Generated open interest snapshots from REST endpoint every 4-6 seconds per instrument. Messages are marked with `"ch":"market.<symbol>.open_interest"` and `"generated":true` fields and `data` field has the same format as REST API response data.
* [detail](https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01\&filters=\[{%22channel%22:%22detail%22}]) 24h contract statistics stream
* [elite\_account\_ratio](https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01\&filters=\[{%22channel%22:%22elite_account_ratio%22}]) — generated channel, available since **2020-10-29** Generated elite account long/short ratio snapshots from REST endpoint using 5min period buckets.
* [elite\_position\_ratio](https://api.tardis.dev/v1/data-feeds/huobi-dm?from=2024-01-01\&filters=\[{%22channel%22:%22elite_position_ratio%22}]) — generated channel, available since **2020-10-29** Generated elite position long/short ratio snapshots from REST endpoint using 5min period buckets.

**Up until 2020-01-31** `depth` channel was collected with `step0` aggregation level (no aggregation) which produces full order book snapshots for each book change which is very inefficient to store. To circumvent this issue we stored only initial book snapshots and then incremental updates instead - incremental updates were calculated by diffing two subsequent book snapshots and provided in the same format as other `depth` messages, except having additional **`update: true`** flag set as in snippet below. Update with amount (second value in array) set to 0 means such level should be deleted, otherwise price level should be updated with new amount value.

```javascript
{
  "ch": "market.ETC_CW.depth.step0",
  "ts": 1572652860024,
  "update": true,
  "tick": {
    "mrid": 24660973159,
    "id": 1572652860,
    "bids": [
      [
        4.869,
        1175
      ]
    ],
    "asks": [],
    "ts": 1572652860013,
    "version": 1572652860,
    "ch": "market.ETC_CW.depth.step0"
  }
}
```

**On 2020-01-31** we've switched to `depth.size_150.high_freq` channel instead when collecting data and which natively provides incremental order book updates without workarounds described above.

Unfortunately it means that when requesting data for **`depth`** channel it may return slightly different format depending for which time period request was made. It's only slightly different and boils down to the way order book update messages are marked vs order book snapshots. In `depth.size_150.high_freq` order book message has `event` field always present with value `update` or `snapshot`, for example:

```javascript
{
  "ch": "market.LTC_CW.depth.size_150.high_freq",
  "tick": {
   ...
    "event": "update",
   ...
  }
}
```

For messages before **2020-01-31** we used the `depth.step0` channel for collecting order book data, which means an order book update message has the `update` flag set to `true`; if it's a snapshot, it doesn't have that flag at all, for example:

```javascript
{
  "ch": "market.ETC_CW.depth.step0",
  "update": true,
  "tick": {
   ...
  }
}
```

All other fields are the same (tick.bids, tick.asks, etc.).

Please feel free to [contact us](https://tardis.dev/#contact) if it's confusing in any way.

We also provide a normalization layer that handles those differences transparently via our [client libs](https://docs.tardis.dev/api/quickstart).

### Market data collection details

[Market data collection infrastructure](https://docs.tardis.dev/faq/general#what-is-your-infrastructure-setup) for HTX Coin-M Futures is located in GCP asia-northeast1 (Tokyo, Japan).

Real-time market data is captured via **multiple WebSocket connections** to `wss://api.hbdm.vn/ws` (proxied via Cloudflare).

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