Advanced Features

W Swap Trade Volume API

This document describes the W Swap Trade Volume API endpoint that returns the last 24 hours of traded volume (in USD) for a specific trading pair.

This document describes the W Swap Trade Volume API endpoint that returns the last 24 hours of traded volume (in USD) for a specific trading pair.

Endpoint

  • Method: GET
  • URL: https://oracle.w-chain.com/api/w-swap/volume/:id

Purpose

  • Returns the 24-hour aggregated USD volume for the specified trading pair.
  • Also returns the pair name for convenience.

Request

  • Path parameter id (number): The trade_pairs.id of the pair.

Example

GET https://oracle.w-chain.com/api/w-swap/volume/2

Success Response

  • Status: 200 OK
  • Body:
{
  "vol24h": 12345.67,
  "pair": "USDT/WCO"
}

Field Details

  • vol24h (number): Total swap volume in USD over the past 24 hours.
  • pair (string): The human-readable pair name from trade_pairs.name.

Error Responses

  • 400 Bad Request: Missing id path parameter.
{
  "statusCode": 400,
  "statusMessage": "Missing id parameter"
}
  • 404 Not Found: Pair not found (no matching trade_pairs.id).
{
  "statusCode": 404,
  "statusMessage": "Pair not found"
}

How Volume Is Calculated

  • Source table: trade_pair_swap_events.
  • Aggregation: Sum of usd_value for rows where:
    • pair_id equals the requested id.
    • timestamp is within the last 24 hours (gt now - 24h and lte now).
  • USD valuation:
    • Stablecoins (USDT, USDC, and bridged variants) use a 1:1 USD mapping.
    • WCO is valued using its CoinGecko USD price.
    • Other tokens may currently resolve to 0 USD unless specifically supported.
  • Caching: Results are cached for ~60 seconds to reduce load.

trade_pairs Reference

The following pairs (from trade_pairs) are relevant for W Swap operations and USD valuation logic. The usd_value_from column indicates which token is used to determine USD value during swaps: 0 means token0, 1 means token1.

idnameplatformpair_addresstoken0_addresstoken1_addresstoken0_decimalstoken1_decimalsfeeusd_value_fromwave_pid
1WAVE/WCO00x35264f0e8cd7a32341f47dbfbf2d85b81fd0ef0a0x42abfb13b4e3d25407ffa9705146b7cb812404a00xedb8008031141024d50ca2839a607b2f82c1c045181830010
2USDT/WCO00xd4e9176d5189dbb24f40e5c6c45bb1682dcb33240x40cb2cccf80ed2192b53fb09720405f6fe3497430xedb8008031141024d50ca2839a607b2f82c1c04561830001
3USDC/WCO00x00d91ce419c068e36928fd8e9379b11d0011f0520x643ec74ed2b79098a37dc45dcc7f1abfe2ade6d80xedb8008031141024d50ca2839a607b2f82c1c04561830002
4SOL/WCO00x9556d7afa868cb8b25657d34f3e0d46929f9d7100xd4f93cacd6d607789c8ecf1dddeba8b0c4d915a80xedb8008031141024d50ca2839a607b2f82c1c045181830014
5DOGE/WCO00x8b5f11ea77641b208fb53b4b91b2825db64b8c320x6cdfda79787caa4ad1a95456095bedc95abd2d750xedb8008031141024d50ca2839a607b2f82c1c04581830015
6XRP/WCO00x24f07de79398f24c9d4dd60a281a29843e43b7fd0x4560d5eb0c32a05fa59acd2e8d639f84a15a24140xedb8008031141024d50ca2839a607b2f82c1c045181830016

Note on wave_pid

The wave_pid sequence skips 3 because in Wave Farm, pool ID 3 is a WCO Single Stake pool (not an LP pool). Therefore, LP-related pairs continue with 4, 5, 6, etc.

Usage Examples

cURL

curl -s "http://<host>/api/w-swap/volume/2"

JavaScript (fetch)

// Fetch 24h volume for pair id 2 (USDT/WCO)
const resp = await fetch('/api/w-swap/volume/2');
if (!resp.ok) throw new Error('Request failed');
const data = await resp.json();
// data.vol24h is a number in USD; data.pair is the pair name

Implementation Notes

  • Internals use a 60-second cache to avoid excessive DB queries.
  • If there are no swap events in the last 24h for the given pair, vol24h returns 0.
  • Authentication is not required for this public endpoint.
  • GET /api/w-swap/lp-value/:id — returns latest pair price and LP price (in USD).