LogoLogo
  • Kaiko Knowledge Hub
  • General
    • 👋Introduction
    • ℹ️General information
      • Response codes
      • API Key
      • Parameter patterns
      • Rate limiting
    • 🏎️Quick-Start Guides
      • Quick-Start: Python
      • Quick-Start: cURL
  • Data Feeds
    • Introduction
    • Level 1 & Level 2 Data
      • Level 1 Aggregations
        • OHLCV
        • VWAP
      • Level 1 Tick-Level
        • All trades
        • Best bids and asks (top of book)
      • Level 2 Tick-Level
        • Bids and asks
    • Reference Data
      • Derivatives pricing
  • Analytics Solutions
    • Kaiko Best Execution
    • Kaiko Fair Market Value
      • Kaiko Fair Market Value (high liquidity pairs)
      • Kaiko Fair Market Value (low liquidity pairs)
    • Kaiko Derivatives Risk Indicators
      • Exchange-provided metrics
  • Legacy endpoints
    • Aggregated Quotes (v1)
    • OHLCV Candles (v1)
    • Trades (v1)
    • VWAP (v1)
    • Bids and asks: Market Update
  • BETA ENDPOINTS
    • Implied Volatility SVI (Closed Beta)
Powered by GitBook
On this page
  • What is this endpoint for?
  • Endpoints
  • Parameters
  • Fields
  • Request examples
  • Response Example

Was this helpful?

Export as PDF
  1. Data Feeds
  2. Level 1 & Level 2 Data
  3. Level 2 Tick-Level

Bids and asks

What is this endpoint for?

All bids and asks on an exchange's order book. Use Kaiko Stream for real-time tick-level updates, or CSV for backdated information. When you connect, you first receive a full snapshot of the current order book with every bid and ask, followed by continuous real-time updates for every change ("delta") that takes place.

When you subscribe, you'll initially receive a full snapshot within a few seconds, followed by all subsequent tick-level updates. If you receive another full snapshot, replace your local snapshot with the new one. This should happen infrequently and only occurs if we detect a consistency issue, such as a lost connection to the exchange or the exchange being down for some time.

If you receive an update with an amount of 0, you should remove the corresponding price level from your local order book. You'll occasionally receive a 0 message for a price level that doesn't exist in your local order book - this can be safely ignored and is due to various exchange limitations.

The order book should not be considered valid until all updates with the same tsExchange have been applied to your local order book, meaning all potential messages from the same update batch have been processed.

Endpoints

gateway-v0-grpc.kaiko.ovh
gateway-v0-http.kaiko.ovh
https://gateway-v0-http.kaiko.ovh/api/stream/orderbookl2_v1
https://gateway-v0-http.kaiko.ovh/api/stream/orderbookl2_replay_v1

Parameters

Parameter
Description
Examples

instrumentCriteria

A nested object to configure following properties for your stream:

  • exchange (String) - The code(s) for the exchange(s)

  • instrument_class (String) - The class(es) of the instrument(s) .

  • code (String) - The Kaiko code for the instrument.

cbse

spot

algo-btc

Configuring a wildcard

A wildcard allows you to request all information we have on a specific instrument, class, or exchange in the same stream. Use a * in place of the relevant exchange, instrument, or class parameter.

For example, the configuration below would deliver trades for BTC/USD across all exchanges where it’s supported:

exchange: * class: spot instrument: btc-usd

Fields

Field
Description

class

Instrument class, empty when not mapped.

code

Instrument code, empty when not mapped.

exchange

Instrument exchange code.

sequenceId

Sequence ID for event. Sortable in lexicographic order.

updateType

SNAPSHOT - A new Snapshot of the order book UPDATED- A new batch of bids & asks since the snapshot

asks

Represents sell orders

amount: the quantity of the base asset available for sale

price: the price per unit of the base that the seller is willing to accept in the quote asset, represented as a scientific notation Example: algo-btc

  • base asset = algo

  • quote asset = btc amount : 42656.0 price: 1.97e-06

  • The asker has 42656.0 Algo available

  • For each unit of Algo, the buyer is willing to accept 1.97e-06 BTC, equal to 0.00000197 when converted to a decimal number

bids

Represents buy orders.

amount: the quantity of the base asset the buyer is willing to purchase

price: the price per unit of the base that the buyer is willing to pay in the quote asset, represented as a scientific notation Example: algo-btc

  • base asset = algo

  • quote asset = btc amount : 80569.0 price: 1.96e-06

  • The buyer will purchase up to 80569.0 Algo

  • For each unit of Algo, the buyer is willing to pay 1.96e-06 BTC, equal to 0.00000196 when converted to a decimal number

tsExchange

The timestamp provided by the exchange for the data.

tsCollection

The timestamp for when Kaiko received the data from the exchange.

tsEvent

The timestamp the data became available in the Kaiko system.

Request examples

# This is a code example. Configure your parameters below #

from __future__ import print_function
from datetime import datetime, timedelta
import logging
import os

import grpc
from google.protobuf.timestamp_pb2 import Timestamp
from google.protobuf.json_format import MessageToJson


from kaikosdk import sdk_pb2_grpc
from kaikosdk.core import instrument_criteria_pb2
from kaikosdk.stream.orderbookl2_v1 import request_pb2 as pb_orderbookl2


def orderbookl2_v1_request(channel: grpc.Channel):
    try:
        with channel:
            stub = sdk_pb2_grpc.StreamOrderbookL2ServiceV1Stub(channel)

            responses = stub.Subscribe(
                pb_orderbookl2.StreamOrderBookL2RequestV1(
                    instrument_criteria=instrument_criteria_pb2.InstrumentCriteria(
                        exchange="cbse", instrument_class="spot", code="*"
                    ),
                )
            )

            for response in responses:
                # for debug purpose only, don't use MessageToJson in the reading loop in production
                print(
                    "Received message %s"
                    % (MessageToJson(response, including_default_value_fields=True))
                )
    except grpc.RpcError as e:
        print(e.details(), e.code())


def run():
    credentials = grpc.ssl_channel_credentials(root_certificates=None)
    call_credentials = grpc.access_token_call_credentials(os.environ["KAIKO_API_KEY"])
    composite_credentials = grpc.composite_channel_credentials(
        credentials, call_credentials
    )
    channel = grpc.secure_channel("gateway-v0-grpc.kaiko.ovh", composite_credentials)
    orderbookl2_v1_request(channel)


if __name__ == "__main__":
    logging.basicConfig()
    run()

This example demonstrates how to request historical data using replay. The maximum amount of data you can request for one replay cannot exceed a total of 24 hours in hours, seconds, and minutes.

Replay data is available on a 72-hour rolling basis and should only be used to retrieve missed data. If full history is required, please use Rest API or CSV deployment methods.

# This is a code example. Configure your parameters below #

from __future__ import print_function
from datetime import datetime, timedelta, timezone
import logging
import os

import grpc
from google.protobuf.timestamp_pb2 import Timestamp
from google.protobuf.json_format import MessageToJson

from kaikosdk import sdk_pb2_grpc
from kaikosdk.core import instrument_criteria_pb2
from kaikosdk.stream.orderbookl2_v1 import request_pb2 as pb_orderbookl2


def orderbookl2replay_v1_request(channel: grpc.Channel):
    try:
        with channel:
            # start of date configuration #
            start = Timestamp()
            start.FromDatetime(datetime.now(timezone.utc) - timedelta(days=2))
            end = Timestamp()
            end.FromDatetime(datetime.now(timezone.utc) - timedelta(days=1))
            # end of date configuration #
            stub = sdk_pb2_grpc.StreamOrderbookL2ReplayServiceV1Stub(channel)

            responses = stub.Subscribe(
                pb_orderbookl2.StreamOrderBookL2ReplayRequestV1(
                    instrument_criteria=instrument_criteria_pb2.InstrumentCriteria(
                        exchange="cbse", instrument_class="spot", code="*"
                    ),
                    interval={"start_time": start, "end_time": end},
                )
            )

            for response in responses:
                # for debug purpose only, don't use MessageToJson in the reading loop in production
                print(
                    "Received message %s"
                    % (MessageToJson(response, including_default_value_fields=True))
                )
    except grpc.RpcError as e:
        print(e.details(), e.code())


def run():
    credentials = grpc.ssl_channel_credentials(root_certificates=None)
    call_credentials = grpc.access_token_call_credentials(os.environ["KAIKO_API_KEY"])
    composite_credentials = grpc.composite_channel_credentials(
        credentials, call_credentials
    )
    channel = grpc.secure_channel("gateway-v0-grpc.kaiko.ovh", composite_credentials)
    orderbookl2replay_v1_request(channel)


if __name__ == "__main__":
    logging.basicConfig()
    run()

cURL requests are intended for testing purposes only.

#Live

curl -X POST "https://gateway-v0-http.kaiko.ovh/api/stream/orderbookl2_v1" -H "accept: application/json" -H "X-Api-Key: $KAIKO_API_KEY" -H "Content-Type: application/json" -d "{ \"instrumentCriteria\": { \"exchange\": \"cbse\", \"instrumentClass\": \"spot\", \"code\": \"algo-btc\"}}"


#Replay/Historical Data

curl -X POST "https://gateway-v0-http.kaiko.ovh/api/stream/orderbookl2_replay_v1" -H "accept: application/json" -H "X-Api-Key: $KAIKO_API_KEY" -H "Content-Type: application/json" -d "{ \"instrumentCriteria\": {  \"exchange\": \"cbse\",  \"instrumentClass\": \"spot\",  \"code\": \"algo-btc\" }, \"interval\": { \"startTime\": \"2025-01-14T12:00:00.000Z\", \"endTime\": \"2025-01-14T18:00:00.000Z\" }}"

Response Example

Received message {"class":"spot",
"code":"bch-eur",
"exchange":"cbse",
"sequenceId":"cu2o2sokocas72q8rkq0",
"updateType":"SNAPSHOT",
"asks":[
  {
    "amount":0.02778327,
    "price":414.07
  },
  {
    "amount":0.4,
    "price":414.08
  }
],
"bids":[
  {
    "amount":0.4,
    "price":413.93
  },
  {
    "amount":0.0277962,
    "price":413.85
  } ],
"tsExchange":{
  "value":"2025-01-13T21:11:15.064Z"
},
"tsCollection":{
  "value":"2025-01-13T21:11:15.064284559Z"
},
"tsEvent":"2025-01-13T21:11:15.260258142Z",
"additionalProperties":{}
}

Received message {"class":"spot",
"code":"bch-eur",
"exchange":"cbse",
"sequenceId":"cu2o2sokocas72q8rla0",
"updateType":"UPDATE",
"asks":[
  {
    "amount":4,
    "price":414.42
  }
  ],
"bids":[],
"tsExchange":{
  "value":"2025-01-13T21:11:15.016291Z"
},
"tsCollection":{
  "value":"2025-01-13T21:11:15.086529551Z"
},
"tsEvent":"2025-01-13T21:11:15.277722255Z",
"additionalProperties":{}
}

Received message {"class":"spot",
"code":"bch-eur",
"exchange":"cbse",
"sequenceId":"cu2o2sokocas72q8t9q0",
"updateType":"UPDATE",
"asks":[],
"bids":[
  {
    "amount":0,
    "price":413.85
  },
  {
    "amount":0.02779016,
    "price":413.94
  }
  ],
"tsExchange":{
  "value":"2025-01-13T21:11:15.235251Z"
  },
"tsCollection":{
  "value":"2025-01-13T21:11:15.248921649Z"
  },
"tsEvent":"2025-01-13T21:11:15.635226002Z",
"additionalProperties":{}
}
PreviousLevel 2 Tick-LevelNextReference Data

Last updated 2 months ago

Was this helpful?

Explore instruments, codes and exchanges in the or .

Make sure to read our before starting.

For more advanced users, you can access our full SDK , where you'll find more coding languages, examples and guidance.

Python quick-start guide
here
Instrument Explorer
Reference Data