Query Markets & Products

In this section, we'll be going over fetching:

  • State and config for all markets & products.

  • Latest market price for one product.

  • Market liquidity for one product (i.e. amount of liquidity at each price tick).

For all available queries, consult the API reference.

All Markets Query

The getAllEngineMarkets function returns the state of all markets from the offchain sequencer.

// Fetches state from offchain sequencer 
const allMarkets = await vertexClient.market.getAllEngineMarkets();

You can use getAllMarkets to query the data in the same way. This fetches the latest on-chain data from Arbitrum / Arbitrum Goerli.

// Fetches state from the chain, this should be the same as `getAllEngineMarkets`
await vertexClient.market.getAllMarkets();

Info

  • getAllEngineMarkets is off-chain and getAllMarkets is on-chain.

  • This means that getAllEngineMarkets has slightly better performance

  • This means that getAllMarkets may reflect delayed data if a state change has not yet been propagated

Latest market price

The getLatestMarketPrice function returns the market price data of a single product given by its product id.

const latestMarketPrice = await vertexClient.market.getLatestMarketPrice({
  productId: 1,
});

Market liquidity

The getMarketLiquidity function returns the available liquidity at each price tick. The number of price levels for each side of the book is given by depth. For example, a depth of 2 will retrieve 2 levels of bids and 2 levels of asks. Price levels are separated by the priceIncrement of the market, given by the getAllEngineMarkets query.

const marketLiquidity = await vertexClient.market.getMarketLiquidity({
  productId: 1,
  depth: 2,
});

Full example

import {getVertexClient, prettyPrintJson} from './common';

async function main() {
  const vertexClient = await getVertexClient();

  const allMarkets = await vertexClient.market.getAllEngineMarkets();
  prettyPrintJson('All Markets', allMarkets);

  const latestMarketPrice = await vertexClient.market.getLatestMarketPrice({
    productId: 1,
  });
  prettyPrintJson('Latest Market Price (Product ID 1)', latestMarketPrice);

  const marketLiquidity = await vertexClient.market.getMarketLiquidity({
    productId: 1,
    // Per side of the book
    depth: 2,
  });
  prettyPrintJson('Market Liquidity (Product ID 1)', marketLiquidity);
}

main();

Last updated