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
All Markets Query
The getAllEngineMarkets
function returns the state of all markets from our backend API, which reflects the state of the off-chain matching engine.
Copy // 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.
Copy // Fetches state from the chain, this should be the same as `getAllEngineMarkets`
await vertexClient.market.getAllMarkets();
Latest market price
The getLatestMarketPrice
function returns the market price data of a single product given by its product id.
Copy 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.
Copy const marketLiquidity = await vertexClient.market.getMarketLiquidity({
productId: 1,
depth: 2,
});
Full example
Copy 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();