State price

What is this endpoint for?

This endpoint should be used when there isn’t enough liquidity to produce a direct or synthetic price. Especially useful for DeFi-only assets, state price derives a price by analyzing the real-time state of liquidity pools for the selected asset, inspecting the pools’ reserves, balances, and recent flow to infer a-price consistent with current market conditions. The data includes the calculated state price and the trading volume from the associated block within each pool, expressed in USD. Pool eligibility depends on the pairing: non-LST tokens must be paired with USDT, USDC, or wETH, while LST tokens must be paired with wETH.

Endpoint

gateway-v0-grpc.kaiko.ovh

Parameters

Parameter
Description
Examples
Mandatory?

asset

The asset name you would like to get data for. To retrieve data for all eligible assets at once, simply enter * in the asset parameter field.

ageur,wsteth

Fields

Field
Description

datetime

Timestamp at which the data has been processed. One data point per second will be published.

base

Base asset requested.

aggregatedPriceUsd

State price aggregated over multiple pools, denominated in USD.

aggregatedPriceEth

State price aggregated over multiple pools, denominated in ETH. This field will return empty for LST tokens.

tsEvent

Date of the publication.

lstQuote

LST quote token if relevant, otherwise will return empty.

Request examples

Make sure to read our Python quick-start guide before starting.

# 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_state_price_v1 import request_pb2 as pb_aggregated_state_price

def aggregated_state_price_v1_request(channel: grpc.Channel):
    try:
        with channel:
            stub = sdk_pb2_grpc.StreamAggregatedStatePriceServiceV1Stub(channel)

            responses = stub.Subscribe(pb_aggregated_state_price.StreamAggregatedStatePriceRequestV1(
            	# Globbing patterns are also supported: ["*"] will subscribe to all assets
                assets = ["ageur", "wsteth"]
            ))
            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)
    aggregated_state_price_v1_request(channel)

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

Response Example

{
	"result": {
		"datetime": "2024-10-23T09:45:13.000964543Z",
		"base": "wsteth",
		"aggregatedPriceUsd": "3036.2060425401045987863569203955",
		"aggregatedPriceEth": "1.1822171670279031",
		"tsEvent": "2024-10-23T09:45:13.447941047Z",
		"lstQuote": "weth"
	}
}

Last updated

Was this helpful?