Robust Pair Prices

What is this endpoint for?

Robust aggregation pricing methodology across all or specified exchanges. Tackle complex tax reporting and audit valuation challenges, accurately value your portfolios, and power internal analytics with stable and outlier-resistant pair prices that aggregate data from over 100 exchanges. The computation works as follows:

  1. Listen to trades from all selected exchanges where the instrument is actively traded.

  2. Compute RWM price. The computation is based on two principles:

    • A robust aggregation of prices (derived from a weighted median methodology: full details available here)

    • An incremental increase of the estimation window seeking for sufficient dataset to compute a robust price (e.g. number of trades under a certain threshold)

At the end of the computation, in case there are still no trades, a null value will be returned. In this instance, we'd reccomend using Cross Prices.

Endpoints

gateway-v0-grpc.kaiko.ovh

Parameters

ParameterDescriptionExamples

window

The window on which you would like your Cross Price to be calculated. Available windows: 1s, 5s, 15s, 30s, 1m, 5m

15s

update_frequency

How regularly you would like to receive your pricing updates. Available frequencies: 1s, 5s, 10s, 30s, and 1m

1s

assets

A nested object to configure following properties for your stream:

  • base - the base asset you'd like your price to be based on

  • quote - the asset you'd like the price to be quoted in

Explore codes in the Instrument Explorer or by using the Reference API endpoint.

btc eur

extrapolate_missing_values

This parameter is set to false by default. Setting it to true means that if there is no trade price available from the calculation window you configured, the last available price (from outside the window) will be used.

false

Exchanges that send their trades late may not be captured in the given sliding window.

Fields

FieldDescription

assets

The base and quote assets as configured above.

price

The calculated Cross Price.

timestamp

The time the Cross Price was calculated.

window

A nested object containing the following fields:

  • startTime - The start of the calculation window for this Cross Price

  • endTime - The end of the calculation window for this Cross Price

  • Duration - The window as configured above

noTrade

If false a price was able to be calculated within the window provided. If true the extrapolate_missing_values parameter was needed to calculate a price.

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 aggregates_direct_exchange_rate_request(channel: grpc.Channel):
    try:
        with channel:
            stub = sdk_pb2_grpc.StreamAggregatesSpotDirectExchangeRateV2ServiceV1Stub(channel)

            window = duration_pb2.Duration()
            window.FromSeconds(10)

            update_frequency = duration_pb2.Duration()
            update_frequency.FromSeconds(2)

            responses = stub.Subscribe(pb_direct_exchange_rate.StreamAggregatesDirectExchangeRateV2RequestV1(
                assets = assets_pb2.Assets(
                    base = "btc",
                    quote = "usd"
                ),
                window = window,
                update_frequency = update_frequency
            ))
            for response in responses:
                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)

    aggregates_direct_exchange_rate_request(channel)

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

Response Example

 "assets": {
    "base": "btc",
    "quote": "usd"
  },
  "price": 59394.87,
  "timestamp": "2024-08-12T11:14:58.022023572Z",
  "window": {
    "startTime": "2024-08-12T11:14:48Z",
    "endTime": "2024-08-12T11:14:58Z",
    "duration": "10s"
  },
  "noTrade": false
}

Last updated