Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.decibel.trade/llms.txt

Use this file to discover all available pages before exploring further.

Base URLs

Decibel API supports two environments: Mainnet:
https://api.mainnet.aptoslabs.com/decibel
Testnet:
https://api.testnet.aptoslabs.com/decibel
Note about the API URL: The base URLs provide access to all Decibel markets and trading functionality. This includes perpetual futures markets, spot markets, and more.

Package Addresses

Each environment has its own package address: Mainnet Package Address:
0x50ead22afd6ffd9769e3b3d6e0e64a2a350d68e8b102c4e72e33d0b8cfdfdb06
Testnet Package Address:
0xe7da2794b1d8af76532ed95f38bfdf1136abfd8ea3a240189971988a83101b7f
No authentication required: The endpoints in this guide are public and don’t require authentication headers like OAuth or JWT. However, you do still need a Decibel Node API key to access the node; simply pass it as the Authorization header on your requests, in the format:
Authorization: Bearer <NODE_API_KEY>
Base URL Variable: In the code examples below, BASE_URL refers to either: - https://api.mainnet.aptoslabs.com/decibel for Mainnet - https://api.testnet.aptoslabs.com/decibel for Testnet Make sure to set this variable in your code before making requests.

Step 1: Get Available Markets

Let’s start by fetching the list of available markets. We’ll use the Get Markets endpoint to retrieve all active trading markets.
import requests

BASE_URL = "https://api.mainnet.aptoslabs.com/decibel"
NODE_API_KEY = "YOUR_NODE_API_KEY"
headers = {"Authorization": f"Bearer {NODE_API_KEY}"}

# Make a GET request to the markets endpoint

response = requests.get(f"{BASE_URL}/api/v1/markets", headers=headers)

# Check if the request was successful

if response.status_code == 200:
    markets = response.json()
    print(f"Found {len(markets)} markets") # Print first 5 markets
    for market in markets[:5]:
        print(f"- {market.get('market_name', 'N/A')} (leverage: {market.get('max_leverage', 'N/A')}x, addr: {market.get('market_addr', 'N/A')})")
else:
    print(f"Error: {response.status_code}")
    print(response.text)

Step 2: Get Market Prices

After obtaining the list of markets, you can query price information for a specific market—including Oracle price, mark price, mid price, funding rate, and open interest—using its market address.
import requests

BASE_URL = "https://api.mainnet.aptoslabs.com/decibel"
NODE_API_KEY = "YOUR_NODE_API_KEY"
headers = {"Authorization": f"Bearer {NODE_API_KEY}"}

# Replace 'market_address' with an actual market address from Step 1
# Example: "BTC/USD: 0x5e0e16f34adfb4b316f8d532d68acbfa206826feaaa418d3938046bdc2044861"
market_address = "0x5e0e16f34adfb4b316f8d532d68acbfa206826feaaa418d3938046bdc2044861"

# Get market details

response = requests.get(f"{BASE_URL}/api/v1/prices?market={market_address}", headers=headers)

if response.status_code == 200:
    data = response.json()
    if data:
        market = data[0]
        print(f"Market: {market.get('market', 'N/A')}")
        print(f"Oracle Price: {market.get('oracle_px', 'N/A')}")
        print(f"Mark Price: {market.get('mark_px', 'N/A')}")
        print(f"Mid Price: {market.get('mid_px', 'N/A')}")
        print(f"Funding Rate (bps): {market.get('funding_rate_bps', 'N/A')}")
        print(f"Open Interest: {market.get('open_interest', 'N/A')}")
    else:
        print("No data returned")
else:
    print(f"Error: {response.status_code}")
    print(response.text)

Step 3: Get Order Book Data

Now let’s retrieve the order book for a market, which shows the current buy and sell orders with their prices and sizes.
import requests

BASE_URL = "https://api.mainnet.aptoslabs.com/decibel"
NODE_API_KEY = "YOUR_NODE_API_KEY"
headers = {"Authorization": f"Bearer {NODE_API_KEY}"}

ticker_id = "BTC-PERP"

# Get order book
response = requests.get(
    f"{BASE_URL}/api/v1/orderbook",
    params={"ticker_id": ticker_id},
    headers=headers,
)

if response.status_code == 200:
    orderbook = response.json()
    print("Bids (Buy Orders):")
    for bid in orderbook.get("bids", [])[:5]:
        print(f"  Price: {bid[0]}, Size: {bid[1]}")

    print("\nAsks (Sell Orders):")
    for ask in orderbook.get("asks", [])[:5]:
        print(f"  Price: {ask[0]}, Size: {ask[1]}")
else:
    print(f"Error: {response.status_code}")


Step 4: Get Recent Trades

Finally, let’s fetch recent trades for a market to see the latest trading activity.
import requests

BASE_URL = "https://api.mainnet.aptoslabs.com/decibel"
NODE_API_KEY = "YOUR_NODE_API_KEY"
headers = {"Authorization": f"Bearer {NODE_API_KEY}"}

# Replace 'market_address' with an actual market address from Step 1
# Example: "BTC/USD: 0x5e0e16f34adfb4b316f8d532d68acbfa206826feaaa418d3938046bdc2044861"
market_address = "0x5e0e16f34adfb4b316f8d532d68acbfa206826feaaa418d3938046bdc2044861"

# Get recent trades
response = requests.get(
    f"{BASE_URL}/api/v1/trades",
    params={"market": market_address, "limit": 20, "offset": 0},
    headers=headers,
)

if response.status_code == 200:
    data = response.json()
    trades = data.get("items", [])
    total_count = data.get("total_count", 0)
    print(f"Recent Trades (Total: {total_count}):")
    for trade in trades[:10]:
        print(
            f"  Action: {trade.get('action')}, Price: {trade.get('price')}, "
            f"Size: {trade.get('size')}, PnL: {trade.get('realized_pnl_amount')}, "
            f"Fee: {trade.get('fee_amount')}"
        )
else:
    print(f"Error: {response.status_code}")
    print(response.text)


Step 5: Get User Fee Rates

Query a user’s current maker/taker fee rates, fee tier based on 30-day rolling volume, the full VIP fee schedule, and daily volume history. Fee-rate and discount fields are returned as decimal numbers (not strings).
import requests

BASE_URL = "https://api.mainnet.aptoslabs.com/decibel"
NODE_API_KEY = "YOUR_NODE_API_KEY"
headers = {"Authorization": f"Bearer {NODE_API_KEY}"}

account = "0xYOUR_ACCOUNT_ADDRESS"

response = requests.get(f"{BASE_URL}/api/v1/user_fee_rates?account={account}", headers=headers)

if response.status_code == 200:
    data = response.json()
    print(f"Account: {data['account']}")
    print(f"Fee Tier: {data['fee_tier']}")
    print(f"Taker Rate: {data['user_taker_rate']}")
    print(f"Maker Rate: {data['user_maker_rate']}")
    print(f"Active Referral Discount: {data['active_referral_discount']}")
    print(f"30-day daily volume entries: {len(data['daily_user_volume'])}")
    print("\nVIP Fee Schedule:")
    for tier in data['fee_schedule']['tiers']['vip']:
        print(f"  >= ${int(tier['volume_threshold']):,} USD -> taker {tier['taker']}, maker {tier['maker']}")
else:
    print(f"Error: {response.status_code}")
    print(response.text)