Clients
Indexer Client

Indexer Client

Getting Started

Installation

pnpm install @dydxprotocol/v4-client-js

Initializing the Client

import { IndexerClient, Network } from "@dydxprotocol/v4-client-js";
 
/**
// For the deployment by DYDX token holders, use below:
 
import { IndexerConfig, ValidatorConfig } from "@dydxprotocol/v4-client-js";
 
const NETWORK: Network = new Network(
  'mainnet',
  new IndexerConfig(
    'https://indexer.dydx.trade',
    'wss://indexer.dydx.trade',
  ),
  new ValidatorConfig(
    'https://dydx-ops-rpc.kingnodes.com', // or other node URL
    'dydx-mainnet-1',
    {
      CHAINTOKEN_DENOM: 'adydx',
      CHAINTOKEN_DECIMALS: 18,
      USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
      USDC_GAS_DENOM: 'uusdc',
      USDC_DECIMALS: 6,
    },
  ),
);
*/
const NETWORK = Network.testnet();
 
const client = new IndexerClient(NETWORK.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