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
Request parameters
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.
Explore instruments, codes and exchanges in the Instrument Explorer or Reference Data.
cbse
spot
algo-btc
Response fields
amount
When
BEST-BID
: The quantity of the base asset that the buyer is willing to purchaseWhen
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 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.core import instrument_criteria_pb2
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
def market_update_request(channel: grpc.Channel):
try:
with channel:
stub = sdk_pb2_grpc.StreamMarketUpdateServiceV1Stub(channel)
# Globbing patterns are also supported on all fields. See http://sdk.kaiko.com/#instrument-selection for all supported patterns
responses = stub.Subscribe(pb_market_update.StreamMarketUpdateRequestV1(
instrument_criteria = instrument_criteria_pb2.InstrumentCriteria(
exchange = "cbse",
instrument_class = "spot",
code = "*"
),
commodities=[pb_commodity.SMUC_TOP_OF_BOOK]
))
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)
market_update_request(channel)
if __name__ == '__main__':
logging.basicConfig()
run()
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": {}
}
Last updated
Was this helpful?