> For the complete documentation index, see [llms.txt](https://docs.tardis.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tardis.dev/historical-data-details/okex-swap.md).

# OKX Swap

OKX Swap historical market data details - instruments, data coverage and data collection specifics

OKX historical data for **all its perpetual swap instruments** is available since **2019-03-30**.

{% embed url="<https://api.tardis.dev/v1/exchanges/okex-swap>" %}
See OKX Swap 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 a Data API key**. See [downloadable CSV files documentation](/downloadable-csv-files/overview.md).

{% hint style="info" %}
Liquidations datasets are available since 2020-12-18.
{% endhint %}

| data type             | symbol       | date       |                                                                                                                |
| --------------------- | ------------ | ---------- | -------------------------------------------------------------------------------------------------------------- |
| incremental\_book\_L2 | BTC-USD-SWAP | 2020-01-01 | [Download sample](https://datasets.tardis.dev/v1/okex-swap/incremental_book_L2/2020/01/01/BTC-USD-SWAP.csv.gz) |
| trades                | BTC-USD-SWAP | 2020-01-01 | [Download sample](https://datasets.tardis.dev/v1/okex-swap/trades/2020/01/01/BTC-USD-SWAP.csv.gz)              |
| derivative\_ticker    | BTC-USD-SWAP | 2020-01-01 | [Download sample](https://datasets.tardis.dev/v1/okex-swap/derivative_ticker/2020/01/01/BTC-USD-SWAP.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-swap",
        from_date="2024-01-01",
        to_date="2024-01-02",
        filters=[Channel(name="books", symbols=["BTC-USD-SWAP"])],
        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-swap',
  from: '2024-01-01',
  to: '2024-01-02',
  filters: [{ channel: 'books', symbols: ['BTC-USD-SWAP'] }],
  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-swap?from=2024-01-01&filters=[{"channel":"books","symbols":["BTC-USD-SWAP"]}]&offset=0'
```

{% embed url="<https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01&filters=[{%22channel%22:%22books%22,%22symbols%22:[%22BTC-USD-SWAP%22]}]&offset=0>" %}
Example API response for OKX Swap 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-swap","filters":[{"channel":"books","symbols":["BTC-USD-SWAP"]}],"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 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-swap?from=2024-01-01\&filters=\[{%22channel%22:%22trades%22,%22symbols%22:\[%22BTC-USDT-SWAP%22]}]) Public swap trade executions stream
* [trades-all](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22trades-all%22,%22symbols%22:\[%22BTC-USDT-SWAP%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-swap?from=2024-01-01\&filters=\[{%22channel%22:%22books-l2-tbt%22,%22symbols%22:\[%22BTC-USDT-SWAP%22]}]) — available until **2026-05-21** Tick-by-tick L2 swap order book updates (10ms)
* [books](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2023-06-01\&filters=\[{%22channel%22:%22books%22,%22symbols%22:\[%22BTC-USDT-SWAP%22]}]) — available from **2023-02-24** to **2024-07-19**, and from **2026-05-21** onward Incremental swap order book depth updates (100ms)
* [bbo-tbt](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22bbo-tbt%22,%22symbols%22:\[%22BTC-USDT-SWAP%22]}]) — available since **2022-05-05** Tick-by-tick best bid and offer updates (10ms)
* [tickers](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22tickers%22,%22symbols%22:\[%22BTC-USDT-SWAP%22]}]) 24h swap ticker updates (100ms)
* [liquidations](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2022-06-01\&filters=\[{%22channel%22:%22liquidations%22}]) — available until **2023-03-30** Liquidation events with at most one update per second per contract
* [liquidation-orders](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-03-01\&filters=\[{%22channel%22:%22liquidation-orders%22}]) — available since **2023-03-30** Liquidation orders with at most one update per second per contract
* [open-interest](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22open-interest%22,%22symbols%22:\[%22BTC-USDT-SWAP%22]}]) Open interest updates (3s)
* [mark-price](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22mark-price%22,%22symbols%22:\[%22BTC-USDT-SWAP%22]}]) Mark price updates with keepalive up to 10s when unchanged (200ms)
* [funding-rate](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22funding-rate%22,%22symbols%22:\[%22BTC-USDT-SWAP%22]}]) Funding rate updates with upcoming funding time (30s to 90s cadence)
* [index-tickers](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22index-tickers%22}]) Index ticker updates with keepalive up to 1m when unchanged (100ms)
* [price-limit](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22price-limit%22,%22symbols%22:\[%22BTC-USDT-SWAP%22]}]) Price limit updates (200ms)
* [status](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22status%22}]) Exchange status and maintenance notifications
* [instruments](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22instruments%22}]) Instrument state updates (listing, suspension, parameter changes)
* [long-short-account-ratio](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22long-short-account-ratio%22}]) Long/short account ratio snapshots from REST statistics endpoint (1m). From **2023-06-09 15:30 UTC** to **2026-08-04 11:16 UTC**, updates occurred at varying intervals longer than the documented 1m.
* [taker-volume](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22taker-volume%22}]) Taker buy/sell volume snapshots from REST statistics endpoint (1m). From **2023-06-09 15:30 UTC** to **2026-08-04 11:16 UTC**, updates occurred at varying intervals longer than the documented 1m.
* [public-block-trades](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22public-block-trades%22}]) — available since **2023-01-01** Public block trades stream (15m)
* [public-struc-block-trades](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-01-01\&filters=\[{%22channel%22:%22public-struc-block-trades%22}]) — available since **2023-01-01** Public structured block trades stream (15m)
* [taker-volume-contract](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-09-01\&filters=\[{%22channel%22:%22taker-volume-contract%22}]) — available since **2024-08-08** Contract-level taker buy/sell volume snapshots from REST statistics endpoint (1m)
* [long-short-account-ratio-contract-top-trader](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-09-01\&filters=\[{%22channel%22:%22long-short-account-ratio-contract-top-trader%22}]) — available since **2024-08-08** Contract-level top-trader long/short account ratio snapshots (1m)
* [long-short-position-ratio-contract-top-trader](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-09-01\&filters=\[{%22channel%22:%22long-short-position-ratio-contract-top-trader%22}]) — available since **2024-08-08** Contract-level top-trader long/short position ratio snapshots (1m)
* [long-short-account-ratio-contract](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2024-09-01\&filters=\[{%22channel%22:%22long-short-account-ratio-contract%22}]) — available since **2024-08-08** Contract-level long/short account ratio snapshots from REST statistics endpoint (1m)

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

* [swap/trade](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2020-01-01\&filters=\[{%22channel%22:%22swap/trade%22,%22symbols%22:\[%22BTC-USD-SWAP%22]}]) — until **2021-12-23** Public swap trade executions stream
* [swap/depth](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2019-08-01\&filters=\[{%22channel%22:%22swap/depth%22,%22symbols%22:\[%22BTC-USD-SWAP%22]}]) — until **2020-02-13** Incremental swap order book updates (legacy depth channel, 100ms)
* [swap/depth\_l2\_tbt](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2020-06-01\&filters=\[{%22channel%22:%22swap/depth_l2_tbt%22,%22symbols%22:\[%22BTC-USD-SWAP%22]}]) — available since **2020-02-07**, until **2021-12-23** Tick-by-tick L2 swap order book updates with sequencing
* [swap/ticker](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2020-01-01\&filters=\[{%22channel%22:%22swap/ticker%22,%22symbols%22:\[%22BTC-USD-SWAP%22]}]) — until **2021-12-23** 24h swap ticker updates
* [swap/liquidation](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2021-01-01\&filters=\[{%22channel%22:%22swap/liquidation%22}]) — available since **2020-12-18**, until **2021-12-23** Swap liquidation events
* [swap/funding\_rate](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2020-01-01\&filters=\[{%22channel%22:%22swap/funding_rate%22,%22symbols%22:\[%22BTC-USD-SWAP%22]}]) — until **2021-12-23** Funding rate updates
* [swap/mark\_price](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2020-01-01\&filters=\[{%22channel%22:%22swap/mark_price%22,%22symbols%22:\[%22BTC-USD-SWAP%22]}]) — until **2021-12-23** Mark price with keepalive up to 10s when unchanged
* [index/ticker](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2020-01-01\&filters=\[{%22channel%22:%22index/ticker%22}]) — available since **2019-09-20**, until **2021-12-23** Index ticker for swap contracts with keepalive up to 1m when unchanged
* [system/status](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2020-08-01\&filters=\[{%22channel%22:%22system/status%22}]) — available since **2020-07-01**, until **2021-12-23** Exchange status and maintenance notifications
* [information/sentiment](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2021-01-01\&filters=\[{%22channel%22:%22information/sentiment%22}]) — available since **2020-10-28**, until **2021-12-23** Market sentiment ratio metrics (75s, REST polling)
* [information/long\_short\_ratio](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2021-01-01\&filters=\[{%22channel%22:%22information/long_short_ratio%22}]) — available since **2020-10-28**, until **2021-12-23** Long/short account ratio metrics (75s, REST polling)
* [information/margin](https://api.tardis.dev/v1/data-feeds/okex-swap?from=2021-01-01\&filters=\[{%22channel%22:%22information/margin%22}]) — available since **2020-10-28**, until **2021-12-23** Margin ratio metrics (75s, REST polling)

### Market data collection details

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

Real-time market data is captured via **multiple WebSocket connections** to `wss://ws.okx.com/ws/v5/public`. Earlier endpoints:

* `wss://awscolows1.okx.com:8443/ws/v5/public` (2023-11-24 – 2026-05-21)
* `wss://ws.okx.com:8443/ws/v5/public` (2022-05-04 – 2023-11-24)
* `wss://wsaws.okex.com:8443/ws/v5/public` (2021-12-23 – 2022-05-04)
* `wss://real.okex.com:8443/ws/v3` (until 2021-12-23)

{% hint style="info" %}
OKX servers are located in AWS ap-northeast-1 region (Tokyo, Japan) since **2026-08-04**. Before that they were located in Alibaba Cloud cn-hongkong region (Hong Kong, China).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
