Skip to content

02QueryingIndexerOracle

Ivan Angelkoski edited this page Jun 12, 2023 · 4 revisions

⚠️ The Docs have been moved to https://docs.ts.injective.network/querying/querying-api/querying-indexer-oracle ⚠️

Example code snippets to query the indexer for oracle module related data.

Using gRPC

  • Get a list of oracles
import { IndexerGrpcOracleApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcOracleApi = new IndexerGrpcOracleApi(endpoints.indexer);

const oracleList = await indexerGrpcOracleApi.fetchOracleList();

console.log(oracleList);
  • Get price from oracle
import { IndexerGrpcOracleApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcOracleApi = new IndexerGrpcOracleApi(endpoints.indexer);

const baseSymbol = "INJ";
const quoteSymbol = "USDT";
const oracleType = "bandibc"; // primary oracle we use

const oraclePrice = await indexerGrpcOracleApi.fetchOraclePriceNoThrow({
  baseSymbol,
  quoteSymbol,
  oracleType,
});

console.log(oraclePrice);

⚠️ DOCUMENTATION ⚠️

Clone this wiki locally