-
Notifications
You must be signed in to change notification settings - Fork 195
02QueryingIndexerOracle
Ivan Angelkoski edited this page Jun 12, 2023
·
4 revisions
Example code snippets to query the indexer for oracle module related data.
- 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);
Powering the future of decentralized finance.