# APIs

### Requirement

The PiperX APIs provide a way to query PiperX standard (v2) and concentrated pools (v3) status. The below examples demonstrated how to query them. Note that PiperX API implemented [CORS Policy](https://aws.amazon.com/what-is/cross-origin-resource-sharing/#:~:text=Cross%2Dorigin%20resource%20sharing%20\(CORS\)%20is%20an%20extension%20of,that%20are%20public%20or%20authorized.). Therefore, if you want to use PiperX APIs from your deployed site (<https://example.xyz>), you need to contact PiperX team first to add your site.

### DEX Stats

Get TVL and Volume of PiperX

Example query

```bash
curl https://piperxdb.piperxprotocol.workers.dev/api/piperxapi/tvl
```

Example output

```json
{
  "dex": {
    "id": "piperx",
    "name": "PiperX",
    "totalVolumeUSD": "49432841143971", // decimal 6 for USD
    "totalVolumeNative": "15038256415533119426220899", // decimal 18 for native token
    "tvlUSD": "6979210444605",
    "tvlNative": "1034401251952740102208458"
  }
}
```

###

### Recent Transactions

Recent swap transactions on a list of pools

Example query&#x20;

```bash
curl -X POST \
-H "Content-Type: application/json"
-d '{"pairAddresses": ["0x4a170A20Dd1ff838C99d49Ac18b517a339206E83"]}'
https://piperxdb.piperxprotocol.workers.dev/api/piperxapi/recentSwaps
```

Example output

```json
{
  "tokenSwaps": [
    {
      "timestamp": "1740996085000000",
      "token0Amount": "29425453054133087415",
      "token1Amount": "200000000",
      "zeroForOne": false,
      "amountUSD": "200000000", // decimal 6 for USD
      "account": {
        "id": "0xd49eeafa6bdbcc551f462c5a582959a9b7a2efdb"
      }
    },
    {
      "timestamp": "1740996059000000",
      "token0Amount": "10005484788346883",
      "token1Amount": "67988",
      "zeroForOne": false,
      "amountUSD": "67988",
      "account": {
        "id": "0x7e093ba1474b79481f9b87d66c99a819f25e82e2"
      }
    }]
}
```

### Get All Tokens&#x20;

Fetch all tokens and their price on PiperX V2 and V3 pool, including those tokens without transactions (price = 0)

Example query&#x20;

```bash
curl https://piperxdb.piperxprotocol.workers.dev/api/piperxapi/getAllTokens
```

Example output

```json
{
  "tokens": [
    {
      "id": "0x0149d87e919967148b18b09f3ef6fd87ad55ad6f",
      "name": "Test",
      "symbol": "TESTT",
      "decimals": 18,
      "latestPriceUSD": "0", // token without any transactions
      "latestPriceNative": "0"
    },
    {
      "id": "0x1514000000000000000000000000000000000000",
      "name": "Wrapped IP",
      "symbol": "WIP",
      "decimals": 18,
      "latestPriceUSD": "6757786", // to convert to real price, use latestPriceUSD /1e(24-decimals), i.e., 1 IP = 6.7577 USD
      "latestPriceNative": "1000000000000000000" // to convert to real price, use latestPriceNative /1e(36-decimals), i.e., 1 IP = 1 IP
    }
}
```

###

### Token Historical Prices

Fetch a list of tokens' historical price

Example query&#x20;

```bash
curl -X POST \
-H "Content-Type: application/json" 
-d '{"addresses": ["0x1514000000000000000000000000000000000000"]}' 
https://piperxdb.piperxprotocol.workers.dev/api/piperxapi/getAllTokenPrices
```

Example output

```json
{
  "tokens": {
    "0x1514000000000000000000000000000000000000": {
      "symbol": "WIP",
      "now": "4.450893",
      "1h": "4.466922",
      "2h": "4.466922",
      "3h": "4.4358",
      "4h": "4.462126",
      "5h": "4.546206",
      "6h": "4.608218",
      "7h": "4.601109",
      "8h": "4.783078",
      "9h": "4.622222",
      "10h": "4.315662",
      "11h": "4.325639",
      "12h": "4.380279",
      "13h": "4.229204",
      "14h": "4.170735",
      "15h": "4.171767",
      "16h": "4.232448",
      "17h": "4.249791",
      "18h": "4.262093",
      "19h": "4.286277",
      "20h": "4.256168",
      "21h": "4.217988",
      "22h": "4.285186",
      "23h": "4.31172",
      "24h": "4.305063",
      "1d": "4.170735",
      "2d": "4.352007",
      "3d": "4.619924",
      "4d": "3.493126",
      "5d": "3.099228",
      "6d": "3.043802",
      "7d": "3.190185"
    }
  },
  "timestamp": 1752495887019
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.piperx.xyz/developer/apis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
