Developers
Clients
Indexer Client

Indexer Client

Getting Started

Installation

pnpm install @dydxprotocol/v4-client-js

Initializing the Client

import { IndexerClient } from "@dydxprotocol/v4-client-js";
 
const client = new IndexerClient(Network.testnet().indexerConfig);

Indexer Status

Get Block Height and Block Time parsed by Indexer

const response = await client.utility.getHeight();
const height = response.height;
const heightTime = response.time;

Get Server Time

const response = await client.utility.getTime();
const timeIso = response.iso;
const timeEpoch = response.epoch;

Markets

List Perpetual Markets

const response = await client.markets.getPerpetualMarkets();

Params and Response: See Indexer API

List Sparklines

const response = await client.markets.getPerpetualMarketSparklines();

Params and Response: See Indexer API

Get Perpetual Market

// ticker is the market ticket, such as "BTC-USD"
const response = await client.markets.getPerpetualMarket(ticker);

Params and Response: See Indexer API

Get Orderbook

// ticker is the market ticket, such as "BTC-USD"
const response = await client.markets.getPerpetualMarketOrderbook(ticker);
const asks = response.asks;
const bids = response.bids;

Params and Response: See Indexer API

Get Trades

// ticker is the market ticket, such as "BTC-USD"
const response = await client.markets.getPerpetualMarketTrades(ticker);
const trades = response.trades;

Params and Response: See Indexer API

Get Historical Funding

// ticker is the market ticket, such as "BTC-USD"
const response = await client.markets.getPerpetualMarketHistoricalFunding(ticker);
const historicalFunding = response.historicalFunding;

Params and Response: See Indexer API

Get Candles

// ticker is the market ticket, such as "BTC-USD", resolution is the resolution of the candles, such as "1MIN"
const response = await client.markets.getPerpetualMarketCandles(ticket, resolution);
const candles = response.candles;

Params and Response: See Indexer API

Subaccount

Get Address Subaccounts

// address is the wallet address on dYdX chain
const response = await client.account.getSubaccounts(address);
const subaccounts = response.subaccounts;

Params and Response: See Indexer API

Get Subaccount

// address is the wallet address on dYdX chain, subaccountNumber is the subaccount number
const response = await client.account.getSubaccount(address, subaccountNumber);
const subaccounts = response.subaccount;

Params and Response: See Indexer API

Get Asset Positions

// address is the wallet address on dYdX chain, subaccountNumber is the subaccount number
const response = await client.account.getSubaccountAssetPositions(address, subaccountNumber);
const positions = response.positions;

Params and Response: See Indexer API

Get Perpetual Positions

// address is the wallet address on dYdX chain, subaccountNumber is the subaccount number
const response = await client.account.getSubaccountPerpetualPositions(address, subaccountNumber);
const positions = response.positions;

Params and Response: See Indexer API

Get Orders

// address is the wallet address on dYdX chain, subaccountNumber is the subaccount number
const response = await client.account.getSubaccountOrders(address, subaccountNumber);
const orders = response;

Params and Response: See Indexer API

Get Order

// orderId is the ID of the order
const response = await client.account.getOrder(orderId);
const order = response;

Params and Response: See Indexer API

Get Fills

// address is the wallet address on dYdX chain, subaccountNumber is the subaccount number
const response = await client.account.getSubaccountFills(address, subaccountNumber);
const fills = response.fills;

Params and Response: See Indexer API

Get Transfers

// address is the wallet address on dYdX chain, subaccountNumber is the subaccount number
const response = await client.account.getSubaccountTransfers(address, subaccountNumber);
const transfers = response.transfers;

Params and Response: See Indexer API

Get Historical PNL

// address is the wallet address on dYdX chain, subaccountNumber is the subaccount number
const response = await client.account.getSubaccountHistoricalPNLs(address, subaccountNumber);
const historicalPnl = response.historicalPnl;

Params and Response: See Indexer API