# Synthetic price

## What is this endpoint for? <a href="#what-is-this-endpoint-for" id="what-is-this-endpoint-for"></a>

This endpoint calculates a synthetic price when there is less liquidity (historic trades) between two assets. The methodology is developed with global tax and accounting standards in mind. Additionally, our robust price aggregation method reduces the impact of outliers in terms of volume and price, meaning you can trust the price returned.

The calculation works as follows:

1. Retrieve the last available optimal liquidity path
2. Listen to trades for all intermediary pairs from all covered exchanges where the instrument is actively traded
3. Compute RWM price for each intermediary pair
4. Compute the product of intermediary pairs based on the liquidity path

The calculation considers all instruments traded across all exchanges covered by Kaiko.

Read the full methodology [here](https://25446524.fs1.hubspotusercontent-eu1.net/hubfs/25446524/Factsheets/Kaiko%20Pricing%20Services%20Methodology.pdf).&#x20;

{% hint style="danger" %}
When using a synthetic price, in order to to meet IFRS-compliance standards, any fiat currency value should be requested in USD and converted using the [Oanda FX Rates add-on](https://docs.kaiko.com/kaiko-rest-api/analytics-solutions/kaiko-fair-market-value/kaiko-fair-market-value-synthetic-prices-for-low-liquidity-pairs/convert-with-oanda-fx-rates).
{% endhint %}

## Endpoints

{% tabs %}
{% tab title="gRPC" %}

```url
gateway-v0-grpc.kaiko.ovh
```

{% endtab %}

{% tab title="http" %}

```url
gateway-v0-http.kaiko.ovh
```

{% endtab %}

{% tab title="API (testing)" %}

```url
https://gateway-v0-http.kaiko.ovh/api/stream/aggregates_spot_exchange_rate_v2
```

{% endtab %}
{% endtabs %}

## Parameters

<table><thead><tr><th width="184">Parameter</th><th width="387">Description</th><th>Examples</th><th data-type="checkbox">Mandatory?</th></tr></thead><tbody><tr><td><code>window</code></td><td>The window on which you would like your Cross Price to be calculated. <br><br>Available windows: <code>1s</code>, <code>5s</code>, <code>15s</code>, <code>30s</code>, <code>60s</code>, <code>300s</code></td><td><code>15s</code></td><td>true</td></tr><tr><td><code>update_frequency</code></td><td>How regularly you would like to receive your pricing updates. <br><br>Available frequencies: <code>1s</code>, <code>5s</code>, <code>10s</code>, <code>30s</code>, and <code>1m</code></td><td><code>1s</code></td><td>true</td></tr><tr><td><code>assets</code></td><td><p>A <strong>nested object</strong> to configure following properties for your stream:</p><ul><li><code>base</code> - the base asset you'd like your price to be based on</li><li><code>quote</code> - the asset you'd like the price to be quoted in</li></ul><p>Explore instruments, codes and exchanges in the <a href="https://instruments.kaiko.com/#/instruments">Instrument Explorer</a> or <a data-mention href="/spaces/ltAbhvgBfrAWlpUnC7ys/pages/ypeWZ4XSK6XHt2hrySeK">/spaces/ltAbhvgBfrAWlpUnC7ys/pages/ypeWZ4XSK6XHt2hrySeK</a>. </p></td><td><code>btc</code><br><br><code>eur</code></td><td>true</td></tr><tr><td><code>extrapolate_missing_values</code></td><td>This parameter is set to <code>false</code> by default. Setting it to <code>true</code> 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.</td><td><code>false</code></td><td>false</td></tr></tbody></table>

{% hint style="warning" %}
Exchanges that send their trades late may not be captured in the given sliding window.
{% endhint %}

## Fields

<table><thead><tr><th width="223">Field</th><th width="537">Description</th></tr></thead><tbody><tr><td><code>assets</code></td><td>The <code>base</code> and quote <code>assets</code> as configured above.</td></tr><tr><td><code>price</code></td><td>The calculated Cross Price.</td></tr><tr><td><code>timestamp</code></td><td>The time the Cross Price was calculated.</td></tr><tr><td><code>window</code></td><td><p>A <strong>nested object</strong> containing the following fields:</p><ul><li><code>startTime</code> - The start of the calculation window for this Cross Price</li><li><code>endTime</code> - The end of the calculation window for this Cross Price</li><li><code>Duration</code> - The window as configured above</li></ul></td></tr><tr><td><code>noTrade</code></td><td>If <code>false</code> a price was able to be calculated within the window provided. If <code>true</code> the <code>extrapolate_missing_values</code> parameter was needed to calculate a price.</td></tr></tbody></table>

## Request examples

{% tabs %}
{% tab title="Python" %}
**Make sure to read our** [**Python quick-start guide**](/stream/general/quick-start-guides/quick-start-python.md) **before starting.**&#x20;

{% code overflow="wrap" %}

```python
 # 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_spot_exchange_rate_request(channel: grpc.Channel):
    try:
        with channel:
            stub = sdk_pb2_grpc.StreamAggregatesSpotExchangeRateV2ServiceV1Stub(channel)
 # confiugure your window and frequency #
            window = duration_pb2.Duration()
            window.FromSeconds(10)

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

            responses = stub.Subscribe(pb_spot_exchange_rate.StreamAggregatesSpotExchangeRateV2RequestV1(
 # confiugure your assets #
                assets = assets_pb2.Assets(
                    base = "eth",
                    quote = "usd"
                ),
                
               # End of parameter configuration#
                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_spot_exchange_rate_request(channel)

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

{% endcode %}
{% endtab %}

{% tab title="cURL" %}
**cURL requests are intended for testing purposes only.**

{% code overflow="wrap" %}

```url
curl -X POST "https://gateway-v0-http.kaiko.ovh/api/stream/aggregates_spot_exchange_rate_v2" -H "accept: application/json" -H "X-Api-Key: $KAIKO_API_KEY" -H "Content-Type: application/json" -d "{ \"assets\": { \"base\": \"eth\", \"quote\": \"usd\" }, \"window\": \"5s\"}"
```

{% endcode %}
{% endtab %}

{% tab title="BigQuery" %}
Information from this endpoint can be accessed through Google BigQuery. \
\
To get started, read our [guide](broken://spaces/zwO3AMVXsp37KK2FngVc/pages/LFIZ1UwRtOxTg308jneZ).
{% endtab %}

{% tab title="Other examples" %}
For more advanced users, you can access our full SDK [here](https://github.com/kaikodata/kaiko-sdk-examples/tree/master), where you'll find more coding languages, examples, and guidance.
{% endtab %}
{% endtabs %}

## Response Example

```json
{
  "assets": {
    "base": "eth",
    "quote": "usd"
  },
  "price": 2629.972960779576,
  "timestamp": "2024-08-12T10:35:06.026554200Z",
  "window": {
    "startTime": "2024-08-12T10:34:56Z",
    "endTime": "2024-08-12T10:35:06Z",
    "duration": "10s"
  },
  "noTrade": false
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kaiko.com/stream/analytics-solutions/kaiko-fair-market-value/established-assets/synthetic-price.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
