Skip to main content
A Node API token is required. Without one, requests return 401 Unauthorized.

Purpose

  • Fetch market data (prices, depth, trades, candlesticks) and account views (orders, positions, Trading Accounts).
  • Works over REST and Aptos views. No signing or private keys required.

When to use

  • Use for dashboards, analytics, and read-heavy server/frontend use cases.
  • Do not use for submitting transactions; use the Write SDK instead.

Initialization

import { DecibelReadDex, TESTNET_CONFIG } from "@decibeltrade/sdk";

const read = new DecibelReadDex(TESTNET_CONFIG, {
  // Required: SDK will send Authorization: Bearer <YOUR_NODE_API_KEY> on fullnode requests
  nodeApiKey: process.env.APTOS_NODE_API_KEY!,
  onWsError: (e) => console.warn("WS error", e), // optional
});

Main readers

  • Markets: read.markets.getAll(), getByName()
  • Prices: read.marketPrices.getAll(), getByName(), subscribeByName()
  • Depth: read.marketDepth.getByName()
  • Trades: read.marketTrades.getByName()
  • Candlesticks: read.candlesticks.getByName(), subscribeByName()
  • Accounts and orders:
    • read.accountOverview.getByAddr()
    • read.userOpenOrders.getBySubaccount() / read.userOrderHistory.getBySubaccount()
    • read.userPositions.getBySubaccount()
    • read.userTradeHistory.getBySubaccount()
    • read.userSubaccounts.getByOwner()
  • Portfolio and leaderboard:
    • read.portfolioChart.getByAddr()
    • read.leaderboard.getTopUsers()
  • Vaults and delegations:
    • read.vaults.getUserOwned() / getAll()
    • read.delegations.getForSubaccount()

Examples

Markets

const markets = await read.markets.getAll();
const btc = await read.markets.getByName("BTC-USD");

Prices and candlesticks

const price = await read.marketPrices.getByName("BTC-USD");

// Subscribe (unsubscribe by calling the returned function)
const unsubscribe = read.marketPrices.subscribeByName("BTC-USD", (msg) => {
  console.log("Price update", msg);
});

// Candlesticks
import { CandlestickInterval } from "@decibeltrade/sdk";
const candles = await read.candlesticks.getByName(
  "BTC-USD",
  CandlestickInterval.OneMinute,
  Date.now() - 60 * 60 * 1000,
  Date.now()
);

Account views

const addr = "0x...owner";
const overview = await read.accountOverview.getByAddr(addr);
const subs = await read.userSubaccounts.getByOwner(addr);

User positions

const subAddr = "0x....subaccount";

const stopPositions = read.userPositions.subscribeByAddr(subAddr, (data) => {
  data.positions.forEach((position) => {
    console.log("Position delta", position.market_name, position.open_size);
  });
});

// Stop streaming for this subaccount
stopPositions();

Notes

  • For raw REST/WS endpoints, see the API Reference tabs.