# Unified Crypto Orderbook Scraper (`d2a8k3u/unified-orderbook-scraper`) Actor

Instant Level 2 order books from 10 top exchanges (Binance, Coinbase, Kraken, KuCoin, Bybit, OKX, Gate.io, HTX, Bitget, MEXC). Pick any symbols, custom exchange list, or get a synthetic aggregated book. Built for arbitrage bots, market-making & real-time analysis.

- **URL**: https://apify.com/d2a8k3u/unified-orderbook-scraper.md
- **Developed by:** [David Kulhánek](https://apify.com/d2a8k3u) (community)
- **Categories:** Developer tools, Automation, Other
- **Features:** Limited permissions
- **Stats:** 34 total users, 3 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Unified Orderbook Scraper

### Overview

Unified Orderbook Scraper is an Apify Actor that fetches Level 2 (orderbook) data from multiple cryptocurrency exchanges and can optionally create a “synthetic” (aggregated) orderbook across all successfully fetched exchanges. Supported exchanges: Binance, Coinbase, Kraken, KuCoin, Bybit, OKX, Gate.io, HTX, Bitget, MEXC.

### Features

- Parallel fetching of L2 orderbooks from multiple exchanges
- Choose symbols and exchanges via the Actor input
- Optional synthetic (aggregated) orderbook
- Retries and timeouts for network communication
- In-memory caching of exchange trading pairs for faster validation during a single run

### How it works (briefly)

1. For each input symbol, the Actor validates it on all selected exchanges: the symbol is first mapped to the exchange’s expected format and verified to be supported.

2. For exchanges where the symbol is supported, the L2 orderbook is fetched.

3. If synthetic output is enabled, an aggregated L2 book is created across all successfully fetched exchanges (volumes for identical price levels are summed; bids are sorted descending, asks ascending).

### Input (Input Schema)

The actual schema is defined in `.actor/input_schema.json`. Example input:

```json
{
  "symbols": ["BTCUSDT", "ETHUSDT"],
  "exchanges": ["binance", "coinbase", "kraken", "kucoin", "bybit", "okx", "gate", "htx", "bitget", "mexc"],
  "synthetic": true
}
```

Parameters:

- symbols (array of strings): List of symbols to fetch. Default: \["BTCUSDT", "ETHUSDT"].
- exchanges (array of strings): Exchanges to fetch from. Supported values: binance, coinbase, kraken, kucoin, bybit, okx, gate, htx, bitget, mexc. Default: all supported exchanges.
- synthetic (boolean): Enable/disable creation of the synthetic book. Default: true.

Note: Some schema versions may include a `depth` parameter. In the current implementation, this parameter is not used (depth is not applied when requesting orderbooks).

### Output (Dataset)

Each dataset item corresponds to one input symbol and contains:

- symbol: the original input symbol (e.g., "BTCUSDT").
- mappedSymbols: an object with exchanges and the concrete symbol used on that exchange (or null if not supported).
- orderbook: an object keyed by exchange; value is an L2 orderbook in the format `{ bids: [[price, size], ...], asks: [[price, size], ...] }`, or `null` if it could not be fetched.
- synthetic: optional synthetic aggregated book in the format `{ bids: [[price, size], ...], asks: [[price, size], ...] }`. Present only if enabled and at least one valid orderbook exists.
- fetchedAt: ISO timestamp when the record was created.

Example dataset item (shortened, valid JSON):

```json
{
  "symbol": "BTCUSDT",
  "mappedSymbols": {
    "binance": "BTCUSDT",
    "coinbase": "BTC-USDT",
    "kraken": null
  },
  "orderbook": {
    "binance": {
      "bids": [["65000.00", "0.5"], ["64990.00", "0.3"]],
      "asks": [["65010.00", "0.4"], ["65020.00", "0.2"]]
    },
    "coinbase": {
      "bids": [["65001.00", "0.2"]],
      "asks": [["65011.00", "0.1"]]
    },
    "kraken": null
  },
  "synthetic": {
    "bids": [[65001, 0.7], [64990, 0.3]],
    "asks": [[65010, 0.5], [65020, 0.2]]
  },
  "fetchedAt": "2025-01-01T12:00:00.000Z"
}
```

### Running on Apify

- On the Actor page, open the Input tab and fill in `symbols`, `exchanges`, and `synthetic` as needed.
- The output is available in the run’s Dataset (items in the format described above).

# Actor input Schema

## `symbols` (type: `array`):

Empty = default \['BTCUSDT', 'ETHUSDT']

## `exchanges` (type: `array`):

Select which exchanges to fetch orderbooks from.

## `synthetic` (type: `boolean`):

If enabled, output will include aggregated market-wide synthetic L2 book.

## `depth` (type: `integer`):

How many price levels to fetch from each exchange (when supported). Recommended values: 5, 20, 50, 100

## Actor input object example

```json
{
  "exchanges": [
    "binance",
    "coinbase",
    "kraken",
    "kucoin",
    "bybit",
    "okx",
    "gate",
    "htx",
    "bitget",
    "mexc"
  ],
  "synthetic": true,
  "depth": 50
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

## `datasetUrl` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("d2a8k3u/unified-orderbook-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("d2a8k3u/unified-orderbook-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call d2a8k3u/unified-orderbook-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,d2a8k3u/unified-orderbook-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/fgcu5sEx5NKJLMHwC/builds/ZcqwB77wZmWmrfLkd/openapi.json
