# OKX Spot

OKX historical data for **spot high caps currency pairs** is available since **2019-03-30**, data for all spot currency pairs is available since **2021-03-11**.

{% embed url="<https://api.tardis.dev/v1/exchanges/okex>" %}
See OKX 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](/downloadable-csv-files/overview.md).

| data type             | symbol   | date       |                                                                                                       |
| --------------------- | -------- | ---------- | ----------------------------------------------------------------------------------------------------- |
| incremental\_book\_L2 | BTC-USDT | 2020-01-01 | [Download sample](https://datasets.tardis.dev/v1/okex/incremental_book_L2/2020/01/01/BTC-USDT.csv.gz) |
| trades                | BTC-USDT | 2020-01-01 | [Download sample](https://datasets.tardis.dev/v1/okex/trades/2020/01/01/BTC-USDT.csv.gz)              |
| quotes                | BTC-USDT | 2020-01-01 | [Download sample](https://datasets.tardis.dev/v1/okex/quotes/2020/01/01/BTC-USDT.csv.gz)              |

### API Access and data format

Historical data format is the same as provided by real-time OKX WebSocket **v5** API with addition of local timestamps (before 2021-12-23 it was **v3** API version). If you'd like to work with **normalized data format** instead (same format for each exchange) see [downloadable CSV files](/downloadable-csv-files/overview.md) or official [client libs](/api/quickstart.md) that can 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="okex",
        from_date="2024-01-01",
        to_date="2024-01-02",
        filters=[Channel(name="books", symbols=["BTC-USDT"])],
        api_key="YOUR_API_KEY",
    ):
        # messages as provided by OKX real-time stream
        print(message)

asyncio.run(main())
```

See [Python client docs](/python-client/quickstart.md).
{% endtab %}

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

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

const messages = replay({
  exchange: 'okex',
  from: '2024-01-01',
  to: '2024-01-02',
  filters: [{ channel: 'books', symbols: ['BTC-USDT'] }],
  apiKey: 'YOUR_API_KEY'
});

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

See [Node.js client docs](/node-client/quickstart.md).
{% endtab %}

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

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

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

See [HTTP API docs](/api/http-api-reference.md).
{% endtab %}

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

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

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

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

### Captured real-time channels

{% embed url="<https://www.okx.com/docs-v5/en/>" %}
See OKX Spot WebSocket API docs providing documentation for each captured channel's format
{% endembed %}

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

**Current channels (API v5, since 2021-12-23):**

* [trades](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22trades%22}]) Public spot trade executions stream
* [trades-all](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22trades-all%22}]) — available since **2023-10-19** All trades stream including non-aggregated trade messages
* [books-l2-tbt](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22books-l2-tbt%22}]) — available until **2026-05-21** Tick-by-tick L2 spot order book updates
* [books](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22books%22}]) — available from **2023-02-24** to **2024-07-19**, and from **2026-05-21** onward Incremental spot order book depth updates
* [bbo-tbt](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22bbo-tbt%22}]) — available since **2022-05-05** Tick-by-tick best bid and offer updates
* [tickers](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22tickers%22}]) 24h spot ticker updates
* [interest-rate-loan-quota](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22interest-rate-loan-quota%22}]) — generated channel Public interest rate and loan quota snapshots from REST endpoint
* [vip-interest-rate-loan-quota](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22vip-interest-rate-loan-quota%22}]) — generated channel VIP interest rate and loan quota snapshots from REST endpoint
* [status](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22status%22}]) Exchange status and maintenance notifications
* [instruments](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22instruments%22}]) Instrument state updates (listing, suspension, parameter changes)
* [taker-volume](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22taker-volume%22}]) — generated channel Taker buy/sell volume snapshots from REST statistics endpoint
* [liquidations](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22liquidations%22}]) — generated channel Margin liquidation events from REST liquidation orders endpoint
* [public-block-trades](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22public-block-trades%22}]) — available since **2023-01-01** Public block trades stream
* [public-struc-block-trades](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22public-struc-block-trades%22}]) — available since **2023-01-01** Public structured block trades stream
* [loan-ratio](https://api.tardis.dev/v1/data-feeds/okex?from=2024-01-01\&filters=\[{%22channel%22:%22loan-ratio%22}]) — generated channel Margin loan ratio snapshots from REST statistics endpoint

**Legacy channels (API v3, until 2021-12-23):**

* [spot/trade](https://api.tardis.dev/v1/data-feeds/okex?from=2021-01-01\&filters=\[{%22channel%22:%22spot/trade%22}]) Public spot trade executions stream
* [spot/depth](https://api.tardis.dev/v1/data-feeds/okex?from=2020-01-01\&filters=\[{%22channel%22:%22spot/depth%22}]) — available until **2020-04-11** Incremental spot order book updates (legacy depth channel)
* [spot/depth\_l2\_tbt](https://api.tardis.dev/v1/data-feeds/okex?from=2021-01-01\&filters=\[{%22channel%22:%22spot/depth_l2_tbt%22}]) — available since **2020-04-09** Tick-by-tick L2 spot order book updates with sequencing
* [spot/ticker](https://api.tardis.dev/v1/data-feeds/okex?from=2021-01-01\&filters=\[{%22channel%22:%22spot/ticker%22}]) 24h spot ticker updates
* [system/status](https://api.tardis.dev/v1/data-feeds/okex?from=2021-01-01\&filters=\[{%22channel%22:%22system/status%22}]) — available since **2020-07-01** Exchange status and maintenance notifications
* [margin/interest\_rate](https://api.tardis.dev/v1/data-feeds/okex?from=2021-06-01\&filters=\[{%22channel%22:%22margin/interest_rate%22}]) — available since **2021-02-24** Margin interest rate updates

### Market data collection details

[Market data collection infrastructure](/faq/general.md#what-is-your-infrastructure-setup) for OKX Spot is located in GCP asia-northeast1 region (Tokyo, Japan) since **2026-05-21**. Before that, from **2022-05-04**, it was located in AWS HK region (Hong Kong, China, VPC colo setup), before that, since **2020-05-15** it was located in GCP asia-northeast1 region (Tokyo, Japan) and initially it was located in GCP europe-west2 region (London, UK).

Real-time market data is captured via **multiple WebSocket connections** to `wss://ws.okx.com:8443/ws/v5/public`. Before **2026-05-21**, data was captured from the OKX colocation endpoint at `wss://awscolows1.okx.com:8443/ws/v5/public`.

{% hint style="info" %}
OKX servers are located in Alibaba Cloud cn-hongkong region (Hong Kong, China).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tardis.dev/historical-data-details/okex.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
