Skip to content

02StreamingIndexerOracle

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

Attention! The Docs have been moved to https://docs.ts.injective.network/

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

Using gRPC Stream

  • stream oracle prices
import { IndexerGrpcOracleStream } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcOracleStream = new IndexerGrpcOracleStream(endpoints.indexer);

const streamFn = indexerGrpcOracleStream.streamOraclePrices.bind(
  indexerGrpcOracleStream
);

const callback = (oraclePrices) => {
  console.log(oraclePrices);
};

const streamFnArgs = {
  callback,
};

streamFn(streamFnArgs);
  • stream oracle prices by market
import { IndexerGrpcOracleStream } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcOracleStream = new IndexerGrpcOracleStream(endpoints.indexer);

const marketIds = ["0x..."]; /* optional param */

const streamFn = indexerGrpcOracleStream.streamOraclePricesByMarkets.bind(
  indexerGrpcOracleStream
);

const callback = (oraclePrices) => {
  console.log(oraclePrices);
};

const streamFnArgs = {
  marketIds,
  callback,
};

streamFn(streamFnArgs);

⚠️ DOCUMENTATION ⚠️

Clone this wiki locally