Kaiko Best Execution

What is this endpoint for?

Get a market-representative execution benchmark that’s ideal for reporting and demonstrating execution efficiency to clients. The exchanges used in this calculation are vetted, meaning only those that are part of the Kaiko Exchange Ranking are included. The best bids are aggregated over 10-second intervals and delivered every second. This means you receive the best bids and asks from the previous 10 seconds, updated every second.

Note that Kaiko Exchange Ranking is updated every quarter, so the exchanges used in the calculation may change.

Endpoints

gateway-v0-grpc.kaiko.ovh

Request parameters

Parameter
Description
Examples
Mandatory?

instrument_class

The class of the instrument(s) . Explore instruments, codes and exchanges in the Instrument Explorer or Reference Data.

spot

code

The Kaiko code for the instrument(s). The class of the instrument(s) . Explore instruments, codes and exchanges in the Instrument Explorer or Reference Data.

btc-usd

includeUnvettedPrice

This parameter is set to false by default and not included in the code example. Setting this field to true includes best bids and asks from exchanges that are not included in the Kaiko Exchange Ranking. This parameter is helpful when an instrument you need is not covered by any exchange on the Kaiko Exchange ranking. It also serves as a backup for instruments covered by only one exchange, ensuring you still receive a price in case that exchange drops off the ranking when it's updated. If you set this parameter true, the calculation will include all exchanges covered by Kaiko and this price will appear in a separate unvetted section of the response.

"includeUnvettedPrice": true

Configuring multiple instruments

To configure multiple instruments in the same stream, provide the code as a comma separated list eg btc-usd,eth-usd.

Response fields

Field
Description

aggregate

The time period over which the best bid or ask was calculated. This is always 10s.

instrumentClass

The class of the instrument.

code

The instrument code.

eventType

BEST_BID - The best bid from the period BEST_ASK - The best ask from the period

tsEvent

The timestamp the data became available in the Kaiko system.

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: btc-usd

  • base asset = btc

  • quote asset = usd price: 60555.00271626198

For each unit of btc, the buyer is willing to pay 60555.00271626198 USD.

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: btc-usd

  • base asset = btc

  • quote asset = usd price: 60556.00224312413

For each unit of btc, the buyer is willing to accept 60556.00224312413 USD.

volume

  • 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

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
from google.protobuf.timestamp_pb2 import Timestamp
import grpc
from google.protobuf.json_format import MessageToJson
from kaikosdk import sdk_pb2_grpc
from kaikosdk.stream.aggregated_quote_v2 import request_pb2 as pb_aggregated_quote

def aggregated_quote_request(channel: grpc.Channel):
    try:
        with channel:
            stub = sdk_pb2_grpc.StreamAggregatedQuoteServiceV2Stub(channel)
            # Globbing patterns are also supported on all fields. See http://sdk.kaiko.com/#instrument-selection for all supported patterns
            responses = stub.Subscribe(pb_aggregated_quote.StreamAggregatedQuoteRequestV2(
                instrument_class = "spot",
                code = "btc-usd"
            ))
            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)
    aggregated_quote_request(channel)

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

Response Example

 "aggregate": "10s",
  "instrumentClass": "spot",
  "code": "btc-usd",
  "eventType": "BEST_ASK",
  "tsEvent": "2024-08-09T23:15:18.087882038Z",
  "vetted": {
    "price": "60556.00224312413",
    "volume": "0.2699806"

Last updated

Was this helpful?