The CafeSwap API is a set of endpoints used by market aggregators (e.g. coinmarketcap.com) to surface CafeSwap liquidity and volume information. All information is fetched from the underlying subgraphs.
The API is designed around the CoinMarketCap document and CoinGecko document.
Cafeswap DEX subgraph playground: https://graphapi.cafeswap.finance/subgraphs/name/cafeswap/cafeswap-subgraph-bsc
All CafeSwap pairs consist of two different tokens. BNB is not a native currency in CafeSwap, and is represented only by WBNB in the pairs.
The canonical WBNB address used by the CafeSwap interface is 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c
.
Returns data for the top ~1000 CafeSwap pairs, sorted by reserves. Results are edge cached for 15 minutes.
GET https://dexapi.cafeswap.finance/api/v2/summary
{
"0x..._0x...": { // the asset ids of the BEP20 tokens (i.e. token addresses), joined by an underscore
"last_price": "1.234", // denominated in token0/token1
"base_volume": "123.456", // last 24h volume denominated in token0
"quote_volume": "1234.56", // last 24h volume denominated in token1
"pair_liquidity": "1234.56", // Pair liquidity in USD
trading_pairs:"token0Symbol_token1Symbol"
},
// ...
}
Returns the total liquidity in USD value on CafeSwap. Results are edge cached for 24 hours.
GET https://dexapi.cafeswap.finance/api/v2/totalliquidity
{
data: {
totalLiquidityUSD: '...' // Total liquidity in USD
}
}
Returns the statistics value on CafeSwap. Results are edge cached for 24 hours.
GET https://dexapi.cafeswap.finance/api/v2/stats
{
data: {
totalLiquidityUSD: '8978873.630992191924082507836841046',
totalVolumeUSD: '168455544.4636947032547389604771717',
totalVolumeBNB: '390074.1061147667642290158462536124',
untrackedVolumeUSD: '1192888416.538407463765017781932275',
totalLiquidityBNB: '32025.75027367803725084151221779494',
pairCount: 121,
txCount: '407796',
}
}
Returns the tokens in the top ~1000 pairs on CafeSwap, sorted by reserves. Results are edge cached for 24 hours.
GET https://dexapi.cafeswap.finance/api/v2/assets
{
// ...,
'0x...': {
name: '...', // not necesssarily included for BEP20 tokens
symbol: '...', // not necesssarily included for BEP20 tokens
id: '0x...', // the address of the BEP20 token
maker_fee: '0', // always 0
taker_fee: '0.002', // always 0.002 i.e. .2%
price_bnb:"...",
price_usd:"...",
}
// ...
}
Returns the single token asset
GET https://dexapi.cafeswap.finance/api/v2/assets/:token_address
{
"updated_at": "....",
// ...,
'data': {
name: '...', // not necesssarily included for BEP20 tokens
symbol: '...', // not necesssarily included for BEP20 tokens
id: '0x...', // the address of the BEP20 token
maker_fee: '0', // always 0
taker_fee: '0.002' // always 0.002 i.e. .2%
price_usd:"...",
price_bnb:"...",
}
// ...
}
Returns data for the top ~1000 CafeSwap pairs, sorted by reserves. Results are edge cached for 1 minute.
GET https://dexapi.cafeswap.finance/api/v2/tickers
{
'0x..._0x...': {
// the asset ids of BNB and BEP20 tokens, joined by an underscore
base_name: '...', // token0 name
base_symbol: '...', // token0 symbol
base_id: '0x...', // token0 address
quote_name: '...', // token1 name
quote_symbol: '...', // token1 symbol
quote_id: '0x...', // token1 address
last_price: '1.234', // the mid price as token1/token0
base_volume: '123.456', // denominated in token0
quote_volume: '1234.56' // denominated in token1
}
// ...
}
Returns simulated orderbook data for the given CafeSwap pair. Since CafeSwap has a continuous orderbook, fixed amounts in an interval are chosen for bids and asks, and prices are derived from the CafeSwap formula (accounting for both slippage and fees paid to LPs). Results are edge cached for 15 minutes.
GET https://dexapi.cafeswap.finance/api/v2/orderbook/:pair
pair
: The asset ids of two BEP20 tokens, joined by an underscore, e.g.0x..._0x...
. The first token address is considered the base in the response.
{
timestamp: 1234567, // UNIX timestamp of the response
bids: [
['12', '1.2'], // denominated in base token, quote token/base token
['12', '1.1'] // denominated in base token, quote token/base token
// ...
],
asks: [
['12', '1.3'], // denominated in base token, quote token/base token
['12', '1.4'] // denominated in base token, quote token/base token
// ...
]
}
Returns all swaps in the last 24 hours for the given CafeSwap pair. Results are edge cached for 15 minutes.
The pair address is the address of the two tokens in either order. The first address is considered the base in the response.
Note because CafeSwap supports flash swaps and borrowing of both tokens in a pair, you may wish to exclude these
trade types (types "???"
and "borrow-both"
).
pair
: The asset ids of two BEP20 tokens, joined by an underscore, e.g.0x..._0x...
. The first token address is considered the base in the response.
GET https://dexapi.cafeswap.finance/api/v2/trades/:pair
[
{
trade_id: '...',
price: '1.234', // denominated in quote token/base token
base_volume: '123.456', // denominated in base token
quote_volume: '1234.56', // denominated in quote token
trade_timestamp: 1234567, // UNIX timestamp
type: 'buy' // "buy"/"sell"/"borrow-both"/"???"
}
// ...
]