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 1 Tick-Level

Best bids and asks (top of book)

What is this endpoint for?

Top-of-Book is also known as best bids and asks. It offers the best bid and best asks on an order book, provided in real-time.

Endpoints

gateway-v0-grpc.kaiko.ovh
gateway-v0-http.kaiko.ovh
https://gateway-v0-http.kaiko.ovh/api/stream/market_update_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

amount

  • When BEST-BID: The quantity of the base asset that the buyer is willing to purchase

  • When BEST-ASK: The quantity of the base asset the seller has available for sale

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.

price

When BEST-BID: 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 price: 1.96e-06

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

When BEST-ASK: 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 price: 1.97e-06

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

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

BEST_BID - The current best bid BEST_ASK - The current best ask

additionalProperties

N/A. Always null

id

N/A. Always null

Request examples

 # 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 = "btc-usd"
                ),
                  # end of parameter configuration # 
                commodities=[pb_commodity.SMUC_TOP_OF_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()

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 and dates in each section #

from __future__ import print_function
import logging
import grpc
import os

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

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:
         # start of date configuration #
        start = Timestamp()
        start.FromJsonString('2024-09-25T05:00:00Z')
        end = Timestamp()
        end.FromJsonString('2024-09-26T06:00:00Z')
        # end of date configuration #

        stub = sdk_pb2_grpc.StreamMarketUpdateServiceV1Stub(channel)
        responses = stub.Subscribe(pb_market_update.StreamMarketUpdateRequestV1(
            instrument_criteria = instrument_criteria_pb2.InstrumentCriteria(
                     # start of parameter configuration #
                    exchange = "cbse",
                    instrument_class = "spot",
                    code = "btc-usd"
                ),
                  # end of parameter configuration # 
                commodities=[pb_commodity.SMUC_TOP_OF_BOOK],
            interval={
                'start_time': start,
                'end_time' : end
            }
        ))
        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)

    res = market_update_request(channel)
    print("Response: %s" % res)
    channel.close()

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

cURL requests are intended for testing purposes only.

curl -X POST "https://gateway-v0-http.kaiko.ovh/api/stream/market_update_v1" -H "accept: application/json" -H "X-Api-Key: $KAIKO_API_KEY" -H "Content-Type: application/json" -d "{ \"instrumentCriteria\": {  \"exchange\": \"cbse\",  \"instrumentClass\": \"spot",  \"code\": \"btx-usd\" }, \"commodities\": [\"SMUC_TOP_OF_BOOK\"]}"

Response Example

{
  "commodity": "SMUC_TOP_OF_BOOK",
  "amount": 6.835e-05,
  "class": "spot",
  "code": "btc-usd",
  "exchange": "cbse",
  "sequenceId": "cqr9icumv1b0afe4cg50",
  "price": 60763.73,
  "tsExchange": {
    "value": "2024-08-09T22:33:23.902971Z"
  },
  "tsCollection": {
    "value": "2024-08-09T22:33:23.916224545Z"
  },
  "tsEvent": "2024-08-09T22:33:23.978211823Z",
  "updateType": "BEST_BID",
  "id": "",
  "additionalProperties": {}
}
PreviousAll tradesNextLevel 2 Tick-Level

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