Exchange API 📝
Introduktion
Exchange API är p3p:s centrala swap-yta. Använd det för att upptäcka vad som kan handlas, få den bästa citeringen från varje aggregerad likviditetskälla, låsa den citeringen i en on-chain swap och spåra den till slutförande.
Alla endpoints nedan kräver en utvecklar-api-key-header. Registrera dig som partner på p3p.xyz för att få en.
api-key: YOUR_P3P_API_KEYEndpoints
1. Hämta kedjor
GET /chains api-key krävs
Returnerar varje kedja som för närvarande är aktiverad på p3p.
curl https://api.p3p.xyz/chains \
-H "api-key: YOUR_P3P_API_KEY"const chains = await fetch("https://api.p3p.xyz/chains", {
headers: { "api-key": "YOUR_P3P_API_KEY" },
}).then((r) => r.json());{
"status": 200,
"message": "ok",
"data": [
{
"id": 0,
"key": "btc",
"name": "Bitcoin",
"display": "BTC Chain",
"color": "#F7931A",
"logo": "",
"icon": "token:btc",
"explorer": {
"address": "https://mempool.space/address/%s",
"tx": "https://mempool.space/tx/%s"
},
"website": "https://bitcoin.org",
"vm": "BVM",
"validation": [
"^(1[1-9A-HJ-NP-Za-km-z]{25,34}|3[1-9A-HJ-NP-Za-km-z]{25,34}|bc1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{8,87})$"
],
"defaults": ["btc"],
"tags": ["bitcoin", "btc", "xbt", "satoshi"],
"enabled": true
},
{
"id": 1,
"key": "eth",
"name": "Ethereum",
"display": "ETH Chain",
"color": "#627EEA",
"logo": "",
"icon": "token:eth",
"explorer": {
"address": "https://etherscan.io/address/%s",
"tx": "https://etherscan.io/tx/%s"
},
"website": "https://ethereum.org",
"vm": "EVM",
"validation": [
"^(0x)[0-9A-Fa-f]{40}$"
],
"defaults": ["eth", "usdt", "usdc", "dai"],
"tags": ["ethereum", "eth", "eht", "vitalik"],
"enabled": true
}
]
}2. Hämta tokens
GET /tokens api-key krävs
Returnerar aktiverade tokens grupperade per kedja.
curl https://api.p3p.xyz/tokens \
-H "api-key: YOUR_P3P_API_KEY"{
"eth": [
{ "key": "eth", "name": "Ether", "symbol": "ETH", "decimals": 18, "rate": "3421.8", "address": "", "native": true, "enabled": true },
{ "key": "usdt", "name": "Tether", "symbol": "USDT", "decimals": 6, "rate": "1.0", "address": "0xdac17f958d2ee523a2206206994597c13d831ec7", "native": false, "enabled": true }
],
"ton": [
{ "key": "ton", "name": "Toncoin", "symbol": "TON", "decimals": 9, "rate": "5.23", "address": "", "native": true, "enabled": true },
{ "key": "usdt", "name": "USDT (TON)", "symbol": "USDT", "decimals": 6, "rate": "1.0", "address": "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs", "native": false, "enabled": true }
]
}3. Hämta kurser
GET /rates api-key krävs
Returnerar live marknadsreferenskurser för varje stödd tillgång, hämtade från on-chain orakel.
curl https://api.p3p.xyz/rates \
-H "api-key: YOUR_P3P_API_KEY"{
"btc": 98234.56,
"eth": 3421.8,
"ton": 5.23,
"usdt": 1.0,
"usdc": 1.0,
"sol": 142.35
}4. Citera exchange-kurs
POST /exchange/rate api-key krävs
Aggregerar kurser från varje aktiv likviditetskälla och returnerar den bästa (eller alla).
Body
| Fält | Typ | Krävs | Beskrivning |
|---|---|---|---|
chain_from | string | ja | Källkedjenyckel |
token_from | string | ja | Källtokennyckel |
amount_from | string | ja | Mängd i visningsenheter |
chain_to | string | ja | Målkedjenyckel |
token_to | string | ja | Måltokennyckel |
opts.best | boolean | nej | Sortera efter bästa kurs (standard) |
opts.fastest | boolean | nej | Sortera efter snabbaste kurs istället för bästa |
opts.partner_id | string | nej | Ditt partner-ID eller registrerade plånbok (tjäna intäkter) |
curl -X POST https://api.p3p.xyz/exchange/rate \
-H "Content-Type: application/json" \
-H "api-key: YOUR_P3P_API_KEY" \
-d '{
"chain_from": "eth",
"token_from": "eth",
"amount_from": "0.1",
"chain_to": "ton",
"token_to": "ton",
"opts": { "best": true }
}'const rate = await fetch("https://api.p3p.xyz/exchange/rate", {
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": "YOUR_P3P_API_KEY",
},
body: JSON.stringify({
chain_from: "eth",
token_from: "eth",
amount_from: "0.1",
chain_to: "ton",
token_to: "ton",
opts: { best: true },
}),
}).then((r) => r.json());{
"type": "crypto",
"path_from": "eth.eth",
"path_to": "ton.ton",
"amount_from": "0.1",
"amount_to": "342.18",
"direction": "exact_input",
"amount_from_unit": 0.1,
"amount_to_unit": 342.18,
"rate": "3421.8",
"impact": "0.01",
"duration": 90,
"boosted": false
}5. Skapa exchange
POST /exchange/create api-key krävs
Lås en kurs, skapa en exchange och få en insättningsadress.
Body
| Fält | Typ | Krävs | Beskrivning |
|---|---|---|---|
chain_from | string | ja | Källkedjenyckel |
token_from | string | ja | Källtokennyckel |
amount_from | string | ja | Mängd i visningsenheter |
chain_to | string | ja | Målkedjenyckel |
token_to | string | ja | Måltokennyckel |
wallet_to | string | ja | Mottagaradress på målkedjan |
wallet_refund | string | nej | Återbetalningsadress om swappen inte kan slutföras |
wallet_from | string | nej | Användarens källadress (vissa kedjor behöver den) |
opts.best | boolean | nej | Sortera efter bästa kurs (standard) |
opts.fastest | boolean | nej | Sortera efter snabbaste kurs istället för bästa |
opts.partner_id | string | nej | Ditt partner-ID eller registrerade plånbok (tjäna intäkter) |
curl -X POST https://api.p3p.xyz/exchange/create \
-H "Content-Type: application/json" \
-H "api-key: YOUR_P3P_API_KEY" \
-d '{
"chain_from": "eth", "token_from": "eth", "amount_from": "0.1",
"chain_to": "ton", "token_to": "ton",
"wallet_to": "UQAbc...XYZ",
"wallet_refund": "0xRefund...address",
"opts": { "partner_id": "P3_YOURPARTNERID" }
}'const exchange = await fetch("https://api.p3p.xyz/exchange/create", {
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": "YOUR_P3P_API_KEY",
},
body: JSON.stringify({
chain_from: "eth",
token_from: "eth",
amount_from: "0.1",
chain_to: "ton",
token_to: "ton",
wallet_to: "UQAbc...XYZ",
wallet_refund: "0xRefund...address",
opts: { partner_id: "P3_YOURPARTNERID" },
}),
}).then((r) => r.json());{
"created_at": "2026-05-24T10:30:00Z",
"id": "ex_8f4c2a...",
"type": "crypto",
"chain_from": "eth",
"token_from": "eth",
"amount_from": "0.1",
"chain_to": "ton",
"token_to": "ton",
"amount_to": "342.18",
"amount_to_unit": 342.18,
"wallet_refund": "0xRefund...address",
"wallet_from": "",
"wallet_to": "UQAbc...XYZ",
"deposit_address": "0xDepositAddressGeneratedForYou",
"rate": "3421.8",
"impact": "0.01",
"duration": 90
}För partnerexchanges (när api-key-header används): Svaret returnerar hash istället för id:
{
"created_at": "2026-05-24T10:30:00Z",
"hash": "A7K2M9X5B3C1D8F4",
"type": "crypto",
"chain_from": "eth",
"token_from": "eth",
"amount_from": "0.1",
"chain_to": "ton",
"token_to": "ton",
"amount_to": "342.18",
"amount_to_unit": 342.18,
"wallet_to": "UQAbc...XYZ",
"deposit_address": "0xDepositAddressGeneratedForYou",
"rate": "3421.8",
"impact": "0.01",
"duration": 90
}Skicka amount_from av token_from från din plånbok till deposit_address för att starta swappen. Spåra framsteg med Kontrollera exchange-status nedan.
Partnerexchanges är privata
Partnerexchanges (identifierade av hash) är endast tillgängliga genom att överföra hashen som ID med ditt api-key-header. De kan inte frågas efter med normalt transaktions-ID.
Insättningsfönster
Insättningen måste matcha amount_from exakt och anlända inom ~6 minuter. Efter timeout kan du försöka igen med ?bump=true på status-endpointen.
6. Kontrollera exchange-status
GET /check/:txId api-key krävs
Hämta det aktuella tillståndet för en enskild exchange eller faktura.
| Query | Typ | Beskrivning |
|---|---|---|
bump | boolean | Om true, försöker igen en stannad/utlöst exchange |
curl https://api.p3p.xyz/check/ex_8f4c2a... \
-H "api-key: YOUR_P3P_API_KEY"{
"id": "ex_8f4c2a...",
"created_at": "2026-05-24T10:30:00Z",
"status": "exchanging",
"type": "internal",
"invoice": false,
"chain_from": "eth",
"token_from": "eth",
"amount_from": "0.1",
"chain_to": "ton",
"token_to": "ton",
"amount_to": "342.18",
"amount_to_unit": 342.18,
"wallet_to": "UQAbc...XYZ",
"deposit_address": "0xDepositAddressGeneratedForYou",
"checkpoint": 3,
"checkpoints": 5
}Statusvärden
| Status | Betydelse |
|---|---|
new | Väntar på användarens insättning |
deposited | Insättning upptäckt, förbereder swapen |
processing | Swap skickad till likviditetskällan, väntar på bekräftelse |
exchanging | Swap bekräftad, medlen byts |
complete | Klar — mottagaren har fått medlen |
timeout | Insättningsfönstret har löpt ut; anropa med ?bump=true för att återställa och försöka igen |
error | Exchange stötte på ett fel; anropa med ?bump=true för att försöka igen |
expired | Exchange har löpt ut och kan inte längre göras om |
Bump-omförsök
Om en trade får timeout (ingen insättning upptäckt inom insättningsfönstret), anropa endpointen igen med ?bump=true för att återställa fönstret:
curl "https://api.p3p.xyz/check/ex_8f4c2a...?bump=true" \
-H "api-key: YOUR_P3P_API_KEY"Partnerexchanges (skapade med api-key-header) kan frågas genom att skicka hash som ID. Om ett api-key-header finns försöker systemet automatiskt matcha det som hash först:
# Använder partner api-key — slår upp via hash
curl https://api.p3p.xyz/check/A7K2M9X5B3C1D8F4 \
-H "api-key: YOUR_PARTNER_API_KEY"{
"hash": "A7K2M9X5B3C1D8F4",
"created_at": "2026-05-24T10:30:00Z",
"status": "complete",
"type": "internal",
"invoice": false,
"chain_from": "eth",
"token_from": "eth",
"amount_from": "0.1",
"chain_to": "ton",
"token_to": "ton",
"amount_to": "342.18",
"amount_to_unit": 342.18,
"wallet_to": "UQAbc...XYZ",
"deposit_address": "0xDepositAddressGeneratedForYou",
"checkpoint": 5,
"checkpoints": 5
}Hash-format
Som standard är hashar 40 alfanumeriska tecken (a-z, A-Z, 0-9). Partners kan anpassa formatet via Partner Dashboard.
7. Kontrollera flera exchanges
POST /check api-key krävs
Kontrollera flera trades i ett anrop.
Kropp
| Fält | Typ | Krävs | Beskrivning |
|---|---|---|---|
hashes | string[] | ja | Array av exchange-ID:n |
curl -X POST https://api.p3p.xyz/check \
-H "Content-Type: application/json" \
-H "api-key: YOUR_P3P_API_KEY" \
-d '{ "hashes": ["ex_8f4c2a...", "ex_aa11bb..."] }'Returnerar en array av minifierade exchange-statusobjekt:
[
{
"hash": "ex_8f4c2a...",
"status": "complete",
"type": "crypto",
"invoice": false,
"chain_from": "eth",
"token_from": "eth",
"amount_from": "0.1",
"chain_to": "ton",
"token_to": "ton",
"amount_to": "342.18",
"checkpoint": 4,
"checkpoints": 4
},
{
"hash": "A7K2M9X5B3C1D8F4",
"status": "exchanging",
"type": "crypto",
"invoice": false,
"chain_from": "ton",
"token_from": "usdt",
"amount_from": "100",
"chain_to": "eth",
"token_to": "usdc",
"amount_to": "99.5",
"checkpoint": 2,
"checkpoints": 4
}
]