Guides
Building with the API
TypeScript and Python examples for integrating Philidor into your applications.
TypeScript: Fetch and Filter Vaults
interface Vault {
id: string;
name: string;
total_score: number;
risk_tier: string;
apr_net: string;
tvl_usd: string;
chain_name: string;
protocol_name: string;
}
async function getPrimeVaults(asset: string): Promise<Vault[]> {
const res = await fetch(
`https://api.philidor.io/v1/vaults?riskTier=prime&asset=${asset}&sortBy=apr_net&sortOrder=desc`
);
const { data } = await res.json();
return data;
}
const vaults = await getPrimeVaults('USDC');
for (const v of vaults) {
console.log(
`${v.name}: score=${v.total_score}, APR=${(parseFloat(v.apr_net) * 100).toFixed(2)}%`
);
}Python: Daily Risk Monitor
import requests
import json
from datetime import datetime
API = "https://api.philidor.io/v1"
def check_portfolio(address: str):
res = requests.get(f"{API}/address/{address}/positions")
data = res.json()["data"]
print(f"Portfolio: {address}")
print(f"Total value: ${float(data['summary']['total_value_usd']):,.0f}")
print(f"Weighted risk: {data['summary']['weighted_risk_score']:.1f}")
print()
for pos in data["positions"]:
score = pos["total_score"]
tier = pos["risk_tier"]
flag = " ⚠" if score < 5 else ""
print(f" {pos['vault_name']}: {score:.1f} ({tier}){flag}")
check_portfolio("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")Error Handling
async function fetchVault(network: string, address: string) {
const res = await fetch(`https://api.philidor.io/v1/vault/${network}/${address}`);
if (res.status === 404) {
throw new Error(`Vault not found: ${network}/${address}`);
}
if (res.status === 429) {
const retryAfter = res.headers.get('Retry-After');
throw new Error(`Rate limited. Retry after ${retryAfter}s`);
}
if (!res.ok) {
const body = await res.json();
throw new Error(body.error?.message || `HTTP ${res.status}`);
}
const { data } = await res.json();
return data;
}Rate Limit Considerations
- Public endpoints: 100 requests/minute
- Use pagination (
page+limit) instead of fetching all vaults at once - Cache responses where possible — vault data updates every 30 minutes
- The API returns
X-RateLimit-Remainingheaders
Pagination
async function getAllVaults(): Promise<Vault[]> {
const all: Vault[] = [];
let page = 1;
while (true) {
const res = await fetch(`https://api.philidor.io/v1/vaults?page=${page}&limit=50`);
const { data, pagination } = await res.json();
all.push(...data);
if (page >= pagination.totalPages) break;
page++;
}
return all;
}