import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import {
IndexerGrpcOracleApi,
IndexerGrpcDerivativesApi,
} from "@injectivelabs/sdk-ts/client/indexer";
const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcDerivativesApi = new IndexerGrpcDerivativesApi(endpoints.indexer);
const indexerGrpcOracleApi = new IndexerGrpcOracleApi(endpoints.indexer);
// Fetch the list of derivative markets
const markets = await indexerGrpcDerivativesApi.fetchMarkets();
// Find the specific market by ticker
const market = markets.find((market) => market.ticker === "INJ/USDT PERP");
if (!market) {
throw new Error("Market not found");
}
// These values are a part of the market object
// fetched from the indexer i.e `oracleBase` and `oracleQuote`
const baseSymbol = market.oracleBase;
const quoteSymbol = market.oracleQuote;
const oracleType = market.oracleType;
const oraclePrice = await indexerGrpcOracleApi.fetchOraclePriceNoThrow({
baseSymbol,
quoteSymbol,
oracleType,
});
console.log(oraclePrice);