02StreamingIndexerOracle - InjectiveLabs/injective-ts GitHub Wiki

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

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);