A Tick-level Update offers an efficient approach for accessing order book information of an exchange. 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.
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:
# This is a code example. Configure your parameters in the parameter configuration section #from__future__import print_functionimport loggingimport osimport grpcfrom google.protobuf.json_format import MessageToJsonfrom google.protobuf import duration_pb2from kaikosdk import sdk_pb2_grpcfrom kaikosdk.core import instrument_criteria_pb2, assets_pb2from kaikosdk.stream.aggregates_ohlcv_v1 import request_pb2 as pb_ohlcvfrom kaikosdk.stream.aggregates_vwap_v1 import request_pb2 as pb_vwapfrom kaikosdk.stream.market_update_v1 import request_pb2 as pb_market_updatefrom kaikosdk.stream.market_update_v1 import commodity_pb2 as pb_commodityfrom kaikosdk.stream.trades_v1 import request_pb2 as pb_tradesfrom kaikosdk.stream.index_v1 import request_pb2 as pb_indexfrom kaikosdk.stream.index_multi_assets_v1 import request_pb2 as pb_index_multi_assetsfrom kaikosdk.stream.index_forex_rate_v1 import request_pb2 as pb_index_forex_ratefrom kaikosdk.stream.aggregated_quote_v2 import request_pb2 as pb_aggregated_quotefrom kaikosdk.stream.aggregates_spot_exchange_rate_v2 import request_pb2 as pb_spot_exchange_ratefrom kaikosdk.stream.aggregates_direct_exchange_rate_v2 import request_pb2 as pb_direct_exchange_ratedefmarket_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())defrun(): 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_functionimport loggingimport grpcimport osfrom google.protobuf.json_format import MessageToJsonfrom google.protobuf.timestamp_pb2 import Timestampimport grpcfrom google.protobuf.json_format import MessageToJsonfrom google.protobuf.timestamp_pb2 import Timestampfrom kaikosdk import sdk_pb2_grpcfrom kaikosdk.core import instrument_criteria_pb2, assets_pb2from kaikosdk.stream.aggregates_ohlcv_v1 import request_pb2 as pb_ohlcvfrom kaikosdk.stream.aggregates_vwap_v1 import request_pb2 as pb_vwapfrom kaikosdk.stream.market_update_v1 import request_pb2 as pb_market_updatefrom kaikosdk.stream.market_update_v1 import commodity_pb2 as pb_commodityfrom kaikosdk.stream.trades_v1 import request_pb2 as pb_tradesfrom kaikosdk.stream.index_v1 import request_pb2 as pb_indexfrom kaikosdk.stream.index_multi_assets_v1 import request_pb2 as pb_index_multi_assetsfrom kaikosdk.stream.index_forex_rate_v1 import request_pb2 as pb_index_forex_ratefrom kaikosdk.stream.aggregated_quote_v2 import request_pb2 as pb_aggregated_quotefrom kaikosdk.stream.aggregates_spot_exchange_rate_v2 import request_pb2 as pb_spot_exchange_ratefrom kaikosdk.stream.aggregates_direct_exchange_rate_v2 import request_pb2 as pb_direct_exchange_ratedefmarket_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 ="algo-btc"),# end of parameter configuration # 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())defrun(): 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.