How-to get current price for a token
You can get the current price using either a policy ID or a pool ID.
Using Policy ID (SNEK Token):
import requests
SNEK_POLICY = "279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f534e454b"
# Get current price using policy ID
response = requests.get(
"https://api.charli3.io/api/v1/tokens/current",
headers={"Authorization": "Bearer YOUR_API_TOKEN"},
params={"policy": SNEK_POLICY}
)
current_price = response.json()
print(f"SNEK current price: {current_price}")
Using Pool ID (SNEK Token):
import requests
SNEK_POOL = "f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c2ffadbb87144e875749122e0bbb9f535eeaa7f5660c6c4a91bcc4121e477f08d"
# Get current price using pool ID
response = requests.get(
"https://api.charli3.io/api/v1/tokens/current",
headers={"Authorization": "Bearer YOUR_API_TOKEN"},
params={"pool": SNEK_POOL}
)
current_price = response.json()
print(f"SNEK current price: {current_price}")
How-to get token logo
E.g. using DJED Stablecoin:
import requests
import base64
DJED_POLICY = "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344"
# Get token logo
response = requests.get(
f"https://api.charli3.io/api/v1/tokens/logo/{DJED_POLICY}",
headers={"Authorization": "Bearer YOUR_API_TOKEN"}
)
logo_data = response.json()
if logo_data:
# Decode base64 and save as PNG
logo_bytes = base64.b64decode(logo_data)
with open("djed_logo.png", "wb") as f:
f.write(logo_bytes)
print("Logo saved as djed_logo.png")
else:
print("No logo available for this token")
How-to batch check prices using policy IDs
import requests
tokens = {
"SNEK": "279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f534e454b",
"DJED": "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344",
"AGIX": "f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc53541474958"
}
prices = {}
for name, policy in tokens.items():
response = requests.get(
"https://api.charli3.io/api/v1/tokens/current",
headers={"Authorization": "Bearer YOUR_API_TOKEN"},
params={"policy": policy}
)
if response.status_code == 200:
prices[name] = response.json()
else:
prices[name] = None
print("Current token prices:")
for token, price in prices.items():
if price:
print(f"{token}: {price}")
else:
print(f"{token}: Price unavailable")
How-to batch check prices using pool IDs
import requests
# Mix of tokens with available pool IDs
pools = {
"SNEK": "f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c2ffadbb87144e875749122e0bbb9f535eeaa7f5660c6c4a91bcc4121e477f08d",
"DJED": "f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4ca939812d08cfb6066e17d2914a7272c6b8c0197acdf68157d02c73649cc3efc0",
"C3": "f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c36ba6613fc391c292c6fc96c50f17b4e7e26d72212d3d07f6e1cd4d4dbe93bbc"
}
prices = {}
for name, pool in pools.items():
response = requests.get(
"https://api.charli3.io/api/v1/tokens/current",
headers={"Authorization": "Bearer YOUR_API_TOKEN"},
params={"pool": pool}
)
if response.status_code == 200:
prices[name] = response.json()
else:
prices[name] = None
print("Current token prices (via pool ID):")
for token, price in prices.items():
if price:
print(f"{token}: {price}")
else:
print(f"{token}: Price unavailable")
How-to handle mixed requests
import requests
# Function to get price by policy or pool
def get_token_price(policy_id=None, pool_id=None, token_name="Token"):
if policy_id and pool_id:
raise ValueError("Provide either policy_id or pool_id, not both")
if not policy_id and not pool_id:
raise ValueError("Must provide either policy_id or pool_id")
params = {}
if policy_id:
params['policy'] = policy_id
if pool_id:
params['pool'] = pool_id
response = requests.get(
"https://api.charli3.io/api/v1/tokens/current",
params=params,
headers={"Authorization": "Bearer YOUR_API_TOKEN"}
)
if response.status_code == 200:
price = response.json()
print(f"{token_name} current price: {price}")
return price
else:
print(f"Failed to get price for {token_name}: {response.status_code}")
return None
# Examples
get_token_price(policy_id="279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f534e454b", token_name="SNEK")
get_token_price(pool_id="f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c2ffadbb87144e875749122e0bbb9f535eeaa7f5660c6c4a91bcc4121e477f08d", token_name="SNEK")