Bids and asks

What is this endpoint for?

All bids and asks on an exchange's order books. Use Kaiko Stream for real-time tick-level updates, or Rest API for snapshots at 30-second intervals. When you connect, you first receive a snapshot of the current order book, 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

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.

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.

updateType

SNAPSHOT - A new Snapshot of the order book UPDATED_BID - A new bid since the snapshot

UPDATED_ASK - A new ask 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

Request examples

Make sure to read our Python quick-start guide before starting.

# This is a code example. Configure your parameters in the parameter configuration section #

from __future__ import print_function
import logging
import os

import grpc
from google.protobuf.json_format import MessageToJson
from google.protobuf import duration_pb2

from kaikosdk import sdk_pb2_grpc
from kaikosdk.core import instrument_criteria_pb2, assets_pb2
from kaikosdk.stream.aggregates_ohlcv_v1 import request_pb2 as pb_ohlcv
from kaikosdk.stream.aggregates_vwap_v1 import request_pb2 as pb_vwap
from kaikosdk.stream.market_update_v1 import request_pb2 as pb_market_update
from kaikosdk.stream.market_update_v1 import commodity_pb2 as pb_commodity
from kaikosdk.stream.trades_v1 import request_pb2 as pb_trades
from kaikosdk.stream.index_v1 import request_pb2 as pb_index
from kaikosdk.stream.index_multi_assets_v1 import request_pb2 as pb_index_multi_assets
from kaikosdk.stream.index_forex_rate_v1 import request_pb2 as pb_index_forex_rate
from kaikosdk.stream.aggregated_quote_v2 import request_pb2 as pb_aggregated_quote
from kaikosdk.stream.aggregates_spot_exchange_rate_v2 import request_pb2 as pb_spot_exchange_rate
from kaikosdk.stream.aggregates_direct_exchange_rate_v2 import request_pb2 as pb_direct_exchange_rate

def market_update_request(channel: grpc.Channel):
    try:
        with channel:
            stub = sdk_pb2_grpc.StreamMarketUpdateServiceV1Stub(channel)
            responses = stub.Subscribe(pb_market_update.StreamMarketUpdateRequestV1(
                  # start of parameter configuration # 
                instrument_criteria = instrument_criteria_pb2.InstrumentCriteria(
                    exchange = "cbse",
                    instrument_class = "spot",
                    code = "algo-btc"
                ),
                  # end of parameter configuration # 
                commodities=[pb_commodity.SMUC_FULL_ORDER_BOOK]
            ))
            for response in responses:
                print("Received message %s" % (MessageToJson(response, including_default_value_fields = True)))
                # print("Received message %s" % list(map(lambda o: o.string_value, response.data.values)))
    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)

    market_update_request(channel)

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

Response Example

  Received message {"commodity": "SMUC_FULL_ORDER_BOOK",
  "class": "spot",
  "code": "bch-eur",
  "exchange": "cbse",
  "sequenceId": "cqr4creaghi85rh762vg",
  "tsExchange": {
    "value": "2024-08-09T16:40:11.514371Z"
  },
  "tsCollection": {
    "value": "2024-08-09T16:40:13.920904647Z"
  },
  "tsEvent": "2024-08-09T16:40:13.988430052Z",
  "updateType": "SNAPSHOT",
  "snapshot": {
     "asks": [
      {
        "amount": 42656.0,
        "price": 1.97e-06
      },
     "bids": [
      {
        "amount": 80569.0,
        "price": 1.96e-06
      },
      {
        "amount": 30569.0,
        "price": 1.95e-06
      }, ]
Received message {
"commodity": "SMUC_FULL_ORDER_BOOK",
  "class": "spot",
  "code": "bch-eur",
  "exchange": "cbse",
  "sequenceId": "cqr4crmaghi85rh7688g",
  "price": 317.67,
  "tsExchange": {
    "value": "2024-08-09T16:40:14.020Z"
  },
  "tsCollection": {
    "value": "2024-08-09T16:40:14.020618238Z"
  },
  "tsEvent": "2024-08-09T16:40:14.227194837Z",
  "updateType": "UPDATED_BID",
  "amount": 0.0,
  "id": "",
  "additionalProperties": {}
}Received message {
  "commodity": "SMUC_FULL_ORDER_BOOK",
  "class": "spot",
  "code": "bch-eur",
  "exchange": "cbse",
  "sequenceId": "cqr4crmaghi85rh7682g",
  "price": 318.07,
  "tsExchange": {
    "value": "2024-08-09T16:40:14.020Z"
  },
  "tsCollection": {
    "value": "2024-08-09T16:40:14.020432858Z"
  },
  "tsEvent": "2024-08-09T16:40:14.227070681Z",
  "updateType": "UPDATED_ASK",
  "amount": 0.0,
  "id": "",
  "additionalProperties": {}
}


Last updated