API des Échanges 📝
Introduction
L'API des Échanges est la surface de swap principale de p3p. Utilise-la pour découvrir ce qui est échangeable, obtenir la meilleure cote à travers chaque source de liquidité agrégée, verrouiller cette cote dans un swap on-chain, et la suivre jusqu'à son achèvement.
Tous les endpoints ci-dessous nécessitent un en-tête api-key de développeur. Inscris-toi comme partenaire sur p3p.xyz pour en obtenir un.
api-key: YOUR_P3P_API_KEYEndpoints
1. Obtenir les Chaînes
GET /chains api-key requise
Retourne chaque chaîne actuellement activée sur 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. Obtenir les Tokens
GET /tokens api-key requise
Retourne les tokens activés regroupés par chaîne.
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. Obtenir les Taux
GET /rates api-key requise
Retourne les taux de marché de référence en direct pour chaque actif supporté, provenant d'oracles on-chain.
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. Coter le Taux d'Exchange
POST /exchange/rate api-key requise
Agrège les taux de chaque source de liquidité active et retourne le meilleur (ou tous).
Corps
| Champ | Type | Requis | Description |
|---|---|---|---|
chain_from | string | oui | Clé de chaîne source |
token_from | string | oui | Clé de token source |
amount_from | string | oui | Montant en unités d'affichage |
chain_to | string | oui | Clé de chaîne de destination |
token_to | string | oui | Clé de token de destination |
opts.best | boolean | non | Trier par meilleur taux (par défaut) |
opts.fastest | boolean | non | Trier par taux le plus rapide au lieu du meilleur |
opts.partner_id | string | non | Ton ID partenaire ou portefeuille enregistré (gagne des revenus) |
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. Créer un Exchange
POST /exchange/create api-key requise
Verrouille un taux, crée un exchange et reçois une adresse de dépôt.
Corps
| Champ | Type | Requis | Description |
|---|---|---|---|
chain_from | string | oui | Clé de chaîne source |
token_from | string | oui | Clé de token source |
amount_from | string | oui | Montant en unités d'affichage |
chain_to | string | oui | Clé de chaîne de destination |
token_to | string | oui | Clé de token de destination |
wallet_to | string | oui | Adresse du destinataire sur la chaîne de destination |
wallet_refund | string | non | Adresse de remboursement si le swap ne peut pas se terminer |
wallet_from | string | non | Adresse source de l'utilisateur (certaines chaînes en ont besoin) |
opts.best | boolean | non | Trier par meilleur taux (par défaut) |
opts.fastest | boolean | non | Trier par taux le plus rapide au lieu du meilleur |
opts.partner_id | string | non | Ton ID partenaire ou portefeuille enregistré (gagne des revenus) |
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
}Pour les exchanges partenaires (lors de l'utilisation du header api-key) : La réponse retourne hash au lieu de 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
}Envoie amount_from de token_from depuis ton portefeuille vers deposit_address pour démarrer le swap. Suis la progression avec Vérifier le Statut de l'Exchange ci-dessous.
Les exchanges partenaires sont privés
Les exchanges partenaires (identifiés par hash) ne sont accessibles qu'en passant le hash comme ID avec ton header api-key. Ils ne peuvent pas être interrogés par un ID de transaction normal.
Fenêtre de dépôt
Le dépôt doit correspondre exactement à amount_from et arriver dans ~6 minutes. Après le délai d'expiration, tu peux réessayer avec ?bump=true sur l'endpoint de statut.
6. Vérifier le Statut de l'Exchange
GET /check/:txId api-key requise
Obtiens l'état actuel d'un seul exchange ou facture.
| Query | Type | Description |
|---|---|---|
bump | boolean | Si true, réessaie un exchange bloqué/expiré |
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
}Valeurs de statut
| Statut | Signification |
|---|---|
new | En attente du dépôt de l'utilisateur |
deposited | Dépôt détecté, préparation du swap |
processing | Swap soumis à la source de liquidité, en attente de confirmation |
exchanging | Swap confirmé, les fonds sont en cours d'échange |
complete | Terminé — le destinataire a reçu les fonds |
timeout | Fenêtre de dépôt expirée ; appeler avec ?bump=true pour réinitialiser et réessayer |
error | L'exchange a rencontré une erreur ; appeler avec ?bump=true pour réessayer |
expired | L'exchange a expiré et ne peut plus être réessayé |
Réessai bump
Si un trade expire (pas de dépôt détecté dans la fenêtre de dépôt), appelle à nouveau l'endpoint avec ?bump=true pour réinitialiser la fenêtre :
curl "https://api.p3p.xyz/check/ex_8f4c2a...?bump=true" \
-H "api-key: YOUR_P3P_API_KEY"Exchanges partenaires (créés avec le header api-key) peuvent être interrogés en passant le hash comme ID. Si un header api-key est présent, le système essaie automatiquement de le faire correspondre en tant que hash en premier :
# Utilisation du api-key partenaire — recherche par 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
}Format du hash
Par défaut, les hashs font 40 caractères alphanumeriques (a-z, A-Z, 0-9). Les partenaires peuvent personnaliser le format via le Tableau de bord Partenaire.
7. Vérifier Plusieurs Exchanges
POST /check api-key requise
Vérifie plusieurs trades en un seul appel.
Corps
| Champ | Type | Requis | Description |
|---|---|---|---|
hashes | string[] | oui | Tableau d'IDs d'exchange |
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..."] }'Retourne un tableau d'objets de statut d'exchange minifiés :
[
{
"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
}
]