How-to get historical price data

Once you have the list of available pairs, you can get the historical price data for a specific pair using the /history endpoint.

# Get the first pair from MinswapV2
# Note: The ticker contains the unique identifier for the pair
# The symbol key contains a short, unique display name for the pair.
# For naming convenctions for crypto pairs, see: https://www.tradingview.com/broker-api-docs/data/symbol_info#crypto
symbol = symbols["MinswapV2"]["ticker"][0]
 
# Get the hourly time data
resolution = "60min" # available options are 1min, 15min, 60min, 1d
 
# Get data from the last 3 days
to = int(time.time())
from_ = to - 3 * 24 * 60 * 60
 
response = requests.get(
    "https://api.charli3.io/api/v1/history",
    params={
        "symbol": symbol,
        "resolution": resolution,
        "from": from_,
        "to": to
    }
)
 
# Print the response
print(response.json())

How-to get price for a specific pair

If you own a project with a token, you may want to collect data for your token on each DEX that your token is listed. You can do this by first getting the list of groups, then for each group get the list of available pairs (as shown above). Once you have all pool information, you can find the a pool for specific DEX by searching for the pools that have a base_currency and currency that match the pair you’re interested in. The base_currency and currency contain the policy ID and policy name (concatenated together). The base_currency is the lexicographically sorted first token in the pair, unless ADA is in the pair, in which "" is the base_currency.

As an example, let’s get all pool data for ADA/SNEK.

import requests
 
SNEK_POLICY_ID = "279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f"
SNEK_POLICY_NAME = "534e454b"
SNEK_CURRENCY = f"{SNEK_POLICY_ID}{SNEK_POLICY_NAME}"
 
ADA_CURRENCY = ""
 
groups_data = requests.get("https://api.charli3.io/api/v1/groups").json()
 
groups = [group["id"] for group in groups_data["d"]["groups"]]
 
SNEK_POOLS = {}
 
for group in groups:
    pairs = requests.get(
        "https://api.charli3.io/api/v1/symbol_info",
        params={"group": group}
    ).json()
    for base_currency, currency, ticker in zip(pairs["base_currency"], pairs["currency"], pairs["ticker"]):
        if base_currency == ADA_CURRENCY and currency == SNEK_CURRENCY:
            SNEK_POOLS[ticker] = group
 
print(SNEK_POOLS)

From there, you can get the price data for each individual pool.

for pool in SNEK_POOLS:
    response = requests.get(
        "https://api.charli3.io/api/v1/history",
        params={
            "symbol": pool,
            "resolution": resolution,
            "from": from_,
            "to": to
        }
    )
    print(response.json())