Skip to content

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.

http
api-key: YOUR_P3P_API_KEY

Endpoints


1. Obtenir les Chaînes

GET /chains api-key requise

Retourne chaque chaîne actuellement activée sur p3p.

bash
curl https://api.p3p.xyz/chains \
  -H "api-key: YOUR_P3P_API_KEY"
ts
const chains = await fetch("https://api.p3p.xyz/chains", {
  headers: { "api-key": "YOUR_P3P_API_KEY" },
}).then((r) => r.json());
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.

bash
curl https://api.p3p.xyz/tokens \
  -H "api-key: YOUR_P3P_API_KEY"
json
{
  "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.

bash
curl https://api.p3p.xyz/rates \
  -H "api-key: YOUR_P3P_API_KEY"
json
{
  "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

ChampTypeRequisDescription
chain_fromstringouiClé de chaîne source
token_fromstringouiClé de token source
amount_fromstringouiMontant en unités d'affichage
chain_tostringouiClé de chaîne de destination
token_tostringouiClé de token de destination
opts.bestbooleannonTrier par meilleur taux (par défaut)
opts.fastestbooleannonTrier par taux le plus rapide au lieu du meilleur
opts.partner_idstringnonTon ID partenaire ou portefeuille enregistré (gagne des revenus)
bash
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 }
  }'
ts
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());
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

ChampTypeRequisDescription
chain_fromstringouiClé de chaîne source
token_fromstringouiClé de token source
amount_fromstringouiMontant en unités d'affichage
chain_tostringouiClé de chaîne de destination
token_tostringouiClé de token de destination
wallet_tostringouiAdresse du destinataire sur la chaîne de destination
wallet_refundstringnonAdresse de remboursement si le swap ne peut pas se terminer
wallet_fromstringnonAdresse source de l'utilisateur (certaines chaînes en ont besoin)
opts.bestbooleannonTrier par meilleur taux (par défaut)
opts.fastestbooleannonTrier par taux le plus rapide au lieu du meilleur
opts.partner_idstringnonTon ID partenaire ou portefeuille enregistré (gagne des revenus)
bash
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" }
  }'
ts
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());
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 :

json
{
  "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.

QueryTypeDescription
bumpbooleanSi true, réessaie un exchange bloqué/expiré
bash
curl https://api.p3p.xyz/check/ex_8f4c2a... \
  -H "api-key: YOUR_P3P_API_KEY"
json
{
  "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

StatutSignification
newEn attente du dépôt de l'utilisateur
depositedDépôt détecté, préparation du swap
processingSwap soumis à la source de liquidité, en attente de confirmation
exchangingSwap confirmé, les fonds sont en cours d'échange
completeTerminé — le destinataire a reçu les fonds
timeoutFenêtre de dépôt expirée ; appeler avec ?bump=true pour réinitialiser et réessayer
errorL'exchange a rencontré une erreur ; appeler avec ?bump=true pour réessayer
expiredL'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 :

bash
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 :

bash
# Utilisation du api-key partenaire — recherche par hash
curl https://api.p3p.xyz/check/A7K2M9X5B3C1D8F4 \
  -H "api-key: YOUR_PARTNER_API_KEY"
json
{
  "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

ChampTypeRequisDescription
hashesstring[]ouiTableau d'IDs d'exchange
bash
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 :

json
[
  {
    "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
  }
]