# Convert with Oanda FX Rates

## What is this endpoint for?

This add-on endpoint ensures IFRS-compliant currency conversions for over 70 fiat pairs when a synthetic price is used in Kaiko Fair Market Value. While synthetic prices can be generated in any fiat currency, this endpoint guarantees compliance for non-USD currencies. In low-liquidity cases, users request a synthetic price quoted in USD, then convert it into their desired fiat currency using this endpoint.

### HTTP Request

{% code overflow="wrap" %}

```http
https://us.market-api.kaiko.io/v2/data/analytics.{data_version}/oanda_fx_rates
```

{% endcode %}

### Path parameters

<table><thead><tr><th width="229">Parameter</th><th width="108">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>quote</code></td><td>Yes</td><td>The quote fiat currency.<br><br><em>Automatically included in continuation tokens.</em></td></tr><tr><td><code>base</code></td><td>Yes</td><td>The base fiat currency.<br><br><em>Automatically included in continuation tokens.</em></td></tr></tbody></table>

### Query parameters

<table><thead><tr><th width="229">Parameter</th><th width="108">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>continuation_token</code></td><td>No</td><td>See <a data-mention href="/pages/mP3amLsYqKTsrRBoblxX">/pages/mP3amLsYqKTsrRBoblxX</a></td></tr><tr><td><code>end_time</code></td><td>No</td><td>Ending time in ISO 8601 (exclusive).<br><br><em>Automatically included in continuation tokens.</em></td></tr><tr><td><code>interval</code></td><td>No</td><td>The interval parameter is suffixed with <code>m</code>, <code>h</code> or <code>d</code> to specify seconds, minutes, hours or days, respectively.<br><br>Any arbitrary value between one minute and one day can be used, as long as it sums up to a maximum of 1 day. The suffixes are <code>m</code> (minute), <code>h</code> (hour) and <code>d</code> (day).<br><br>Default <code>1h</code>.<br><br><mark style="color:blue;">For each interval, the resulting FX rate is an average of all available FX rates over that period.</mark><br><br><em>Automatically included in continuation tokens.</em></td></tr><tr><td><code>page_size</code></td><td>No</td><td><p>See <a data-mention href="/pages/mP3amLsYqKTsrRBoblxX">/pages/mP3amLsYqKTsrRBoblxX</a><br><br>Minimum: <code>1</code><br>Maximum: <code>1000</code></p><p>Default: <code>100</code></p><p></p><p><em>Automatically included in continuation tokens.</em></p></td></tr><tr><td><code>start_time</code></td><td>No</td><td>Starting time in ISO 8601 (inclusive).<br><br><em>Automatically included in continuation tokens.</em></td></tr><tr><td><code>sort</code></td><td>No</td><td>Return the data in ascending (<code>asc</code>) or descending (<code>desc</code>) order. Default is <code>desc</code>.<br><br><em>Automatically included in continuation tokens.</em></td></tr></tbody></table>

### Fields

| Field       | Description                           |
| ----------- | ------------------------------------- |
| `timestamp` | Timestamp at which the interval ends. |
| `fx_rate`   | Average fx rate over the interval.    |

### Request examples

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```url
curl --compressed -H 'Accept: application/json' -H 'X-Api-Key: <client-api-key>' \
  'https://us.market-api.kaiko.io/v2/data/analytics.v2/oanda_fx_rates?base=eur&page_size=2&sort=desc&interval=1d&quote=jpy'
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code overflow="wrap" %}

```python
##### 1. Import dependencies #####
import requests
import pandas as pd

##### 2. Choose the value of the query's parameters #####
# ---- Required parameters ---- #
quote = "usd"
base = "jpy"

# ---- Optional parameters ---- #
interval = "1h"
sort = "desc"
page_size = 100
start_time= "2025-01-01T00:00:00.000Z"
end_time= "2025-01-31T00:00:00.000Z"

# ---- 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, quote: str, base: str, start_time: str, end_time: str, interval: str, sort: str, page_size: int):
    headers = {'Accept': 'application/json', 'X-Api-Key': api_key}
    
    url = f'https://us.market-api.kaiko.io/v2/data/analytics.v2/oanda_fx_rates'
    params = {
        "start_time": start_time,
        "end_time": end_time,
        "sort": sort,
        "page_size": page_size,
        "interval": interval,
        "quote": quote,
        "base": base
    }

    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, quote=quote, base=base, interval=interval, start_time=start_time, end_time=end_time, sort=sort, page_size=page_size)
print (df)
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Response examples

{% tabs %}
{% tab title="Standard response" %}

```json
{
    "query": {
        "base": "eur",
        "quote": "jpy",
        "interval": "1d",
        "page_size": "2",
        "sort": "desc",
        "start_time": "null",
        "end_time": "2022-08-31T08:38:25.883Z"
    },
    "time": "2022-08-31T08:38:25.905Z",
    "timestamp": 1661935105,
    "data": [
        {
            "timestamp": 1660780800000,
            "fx_rate": "137.38630485436903"
        },
        {
            "timestamp": 1660694400000,
            "fx_rate": "137.15155641205303"
        }
    ],
    "continuation_token": "4tvMKJPYA6ESWsE7s87P2ujFvr6XRNvegzst2eg1EpdyQEPKWpuNic5XPGrhz47RzbbqC598E3XusLo34Hivgw4sYrrvdmYxL7WQVtebjtYVMUPPd97vqo2VjL22A6cTSNojTQsvHh8T6MPRjuJAMfx5LWyVZQWYyzLrSE",
    "next_url": "https://us.market-api.kaiko.io/v2/data/analytics.v2/oanda_fx_rates?continuation_token=4tvMKJPYA6ESWsE7s87P2ujFvr6XRNvegzst2eg1EpdyQEPKWpuNic5XPGrhz47RzbbqC598E3XusLo34Hivgw4sYrrvdmYxL7WQVtebjtYVMUPPd97vqo2VjL22A6cTSNojTQsvHh8T6MPRjuJAMfx5LWyVZQWYyzLrSE"
}
```

{% endtab %}
{% endtabs %}


---

# 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/rest-api/analytics-solutions/kaiko-fair-market-value/established-assets/synthetic-price/convert-with-oanda-fx-rates.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.
