Synthetic price
What is this endpoint for?
This endpoint calculates a synthetic price when there is no liquidity (historic trades) between two assets (fiat or digital). Let's say, for example, there was no liquidity between NEXO and GBP, but you need a price. To calculate this, the liquidity engine will use a series of intermediary assets where there is liquidity (lots of trading history) to calculate the price for NEXO > GBP. To demonstrate how this calculation works, the engine might take the price for NEXO > BTC (where there is plenty of liquidity) and then the price of BTC > GBP (where there is also lots of liquidity) and combine the two to determine a robust synthetic price for NEXO > GBP. The engine will always use the path of highest liquidity, meaning several intermediary assets might be used. Read the full methodology here.
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.
HTTP Request
https://<eu|us>.market-api.kaiko.io/v2/data/trades.v2/spot_exchange_rate/{base_asset}/{quote_asset}Path parameters
Query parameters
start_time
No
Start time in ISO 8601 (exclusive). Automatically included in continuation tokens.
end_time
No
Ending time in ISO 8601 (exclusive). Automatically included in continuation tokens.
interval
No
The interval parameter is suffixed with s, m, h or d to specify seconds, minutes, hours or days, respectively.
Any arbitrary value between one second and one day can be used, as long as it sums up to a maximum of 1 day. The suffixes are s (second), m (minute), h (hour) and d (day).
Default 1d.
page_size
No
See Pagination
Page size limits differ by the interval selected:
Less than or equal to
1mDefault:10, Max:1001mto1hDefault:4, Max:10More than
1hDefault:1, Max:4
Automatically included in continuation tokens.
sort
No
Return the data in ascending (asc) or descending (desc) order. Default is desc.
Automatically included in continuation tokens.
include_exchanges
No
List of exchanges' code to include in the calculation.
Exchange codes
Default is all exchanges.
Automatically included in continuation tokens.
exclude_exchanges
No
List of exchanges' code to exclude in the calculation.
Automatically included in continuation tokens.
extrapolate_missing_values
No
When true, if there are any null (missing) prices for the calculation, they will be filled in using the last available price from the window requested. This is useful for assets that don't have a lot of trades or for data that is collected very frequently.
However, if the parameter is set to true and no prices were available in that window, a null value will still be returned.
sources
No
When true, the response includes the intermediary pair price details used to calculate the price.
Default: false
Fields
timestamp
Timestamp at which the interval begins.
price
Aggregated Robust Weighted Median using liquidity path engine.
null when no trades reported, except if extrapolate_missing_values is true.
Liquidity path is calculated every 4 hours seeking for the most liquid pairs to convert from base asset to quote asset.
extrapolate_missing_values
true if the value has been extrapolated from the last computed value available, false if not.
Request examples
curl --compressed -H 'Accept: application/json' -H 'X-Api-Key: <client-api-key>' \
'https://us.market-api.kaiko.io/v2/data/trades.v2/spot_exchange_rate/dash/usd?interval=1m&extrapolate_missing_values=true&start_time=2023-05-03T00:01:00.000Z&end_time=2023-05-04T00:00:00.000Z'##### 1. Import dependencies #####
import requests
import pandas as pd
##### 2. Choose the value of the query's parameters #####
# ---- Required parameters ---- #
base_asset = "btc"
quote_asset = "usd"
# ---- Optional parameters ---- #
interval = "1h"
sort = "desc"
page_size = 4
start_time= "2023-01-01T00:00:00Z"
end_time= "2023-01-01T23:59:59Z"
include_exchanges = None
exclude_exchanges = None
extrapolate_missing_values = None
sources = None
# ---- API key configuration ---- #
api_key = "YOUR_API_KEY"
##### 3. Get the data #####
# ---- Function to run an API call ---- #
# Get the data in a dataframe --------- #
def get_kaiko_data(api_key: str, base_asset: str, quote_asset: str, start_time: str, end_time: str, interval: str, sort: str, page_size: int, include_exchanges: list = None, exclude_exchanges: list = None, extrapolate_missing_values: bool = None, sources: bool = None):
headers = {'Accept': 'application/json', 'X-Api-Key': api_key}
url = f'https://us.market-api.kaiko.io/v2/data/trades.v2/spot_exchange_rate/{base_asset}/{quote_asset}'
params = {
"start_time": start_time,
"end_time": end_time,
"sort": sort,
"page_size": page_size,
"interval": interval,
"include_exchanges": include_exchanges,
"exclude_exchanges": exclude_exchanges,
"extrapolate_missing_values": extrapolate_missing_values,
"sources": sources
}
try:
res = requests.get(url, headers=headers, params=params)
res.raise_for_status()
data = res.json()
if 'data' not in data:
print("No data returned.")
return pd.DataFrame()
df = pd.DataFrame(data['data'])
# Handle pagination with continuation token
while 'next_url' in data:
next_url = data['next_url']
if next_url is None:
break
res = requests.get(next_url, headers=headers)
res.raise_for_status()
data = res.json()
if 'data' in data:
df = pd.concat([df, pd.DataFrame(data['data'])], ignore_index=True)
return df
except requests.exceptions.RequestException as e:
print(f"API request error: {e}")
return pd.DataFrame()
# ---- Get the data ---- #
df = get_kaiko_data(api_key=api_key, base_asset=base_asset, quote_asset=quote_asset, interval=interval, start_time=start_time, end_time=end_time, sort=sort, page_size=page_size, include_exchanges=include_exchanges, exclude_exchanges=exclude_exchanges, extrapolate_missing_values=extrapolate_missing_values, sources=sources)
print (df)Response example
{
"query": {
"start_time": "2023-05-03T00:01:00Z",
"end_time": "2023-05-04T00:00:00Z",
"page_size": 10,
"base_asset": "dash",
"quote_asset": "usd",
"interval": "1m",
"sort": "desc",
"sources": false,
"include_exchanges": [],
"exclude_exchanges": [],
"data_version": "v1",
"commodity": "trades",
"request_time": "2024-07-11T08:10:21.828Z",
"instruments": [
"bbsp:spot:btc-usdt",
"bfnx:spot:btc-usdt",
"bgon:spot:btc-usdt",
"binc:spot:btc-usdt",
"bnus:spot:btc-usdt",
"bull:spot:btc-usdt",
"cbse:spot:btc-usdt",
"cnex:spot:btc-usdt",
"gmni:spot:btc-usdt",
"kcon:spot:btc-usdt",
"krkn:spot:btc-usdt",
"okex:spot:btc-usdt",
"stmp:spot:btc-usdt",
"bfnx:spot:dash-btc",
"binc:spot:dash-btc",
"cbse:spot:dash-btc",
"cnex:spot:dash-btc",
"yobt:spot:dash-btc",
"bfnx:spot:usdt-usd",
"bnus:spot:usdt-usd",
"cbse:spot:usdt-usd",
"gmni:spot:usdt-usd",
"krkn:spot:usdt-usd",
"stmp:spot:usdt-usd"
],
"start_timestamp": 1683157800000,
"end_timestamp": 1683158400000,
"extrapolate_missing_values": true
},
"time": "2024-07-11T08:10:21.891Z",
"timestamp": 1720685421891,
"data": [
{
"timestamp": 1683158340000,
"price": "49.263380298334226",
"extrapolated": false
},
{
"timestamp": 1683158280000,
"price": "49.24160302106242",
"extrapolated": false
},
/*...*/
],
"result": "success",
"continuation_token": "AV2cWacBUPR8PvJTwoHZtPBUSEuqNYcv2iNgL96oZpT6MqqGc6ajQo7XM66wySCwViwNjs9C8Gu1xS2rRwGMrCT6rCRxFDCFnnKusyGFo34HkuY7Em7KqgpSzNADLhciV7w5UPeJrvm6cDgTnsaKVUgLMpj2ZioT",
"next_url": "https://us.market-api.kaiko.io/v2/data/trades.v2/spot_exchange_rate/dash/usd?continuation_token=AV2cWacBUPR8PvJTwoHZtPBUSEuqNYcv2iNgL96oZpT6MqqGc6ajQo7XM66wySCwViwNjs9C8Gu1xS2rRwGMrCT6rCRxFDCFnnKusyGFo34HkuY7Em7KqgpSzNADLhciV7w5UPeJrvm6cDgTnsaKVUgLMpj2ZioT",
"access": {
"access_range": {
"start_timestamp": 1262995200000,
"end_timestamp": 2186006399000
},
"data_range": {
"start_timestamp": null,
"end_timestamp": null
}
}
}Last updated
Was this helpful?
