> ## Documentation Index
> Fetch the complete documentation index at: https://injectivelabs-docs-ai-sdk.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Oracle

Example code snippets to stream from the indexer for oracle module related data using StreamManagerV2.

## Using gRPC Stream with StreamManagerV2

### Stream oracle prices

```ts theme={null}
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
import { 
  StreamManagerV2,
  IndexerGrpcOracleStreamV2 
} from '@injectivelabs/sdk-ts/client/indexer'

const endpoints = getNetworkEndpoints(Network.Testnet)
const stream = new IndexerGrpcOracleStreamV2(endpoints.indexer)

const streamManager = new StreamManagerV2({
  id: 'oracle-prices',
  streamFactory: () => stream.streamOraclePrices({
    callback: (response) => {
      streamManager.emit('data', response)
    }
  }),
  onData: (oraclePrices) => {
    console.log(oraclePrices)
  },
  retryConfig: { enabled: true }
})

streamManager.on('connect', () => console.log('Stream connected'))
streamManager.start()
```

### Stream oracle prices by markets

```ts theme={null}
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
import { 
  StreamManagerV2,
  IndexerGrpcOracleStreamV2 
} from '@injectivelabs/sdk-ts/client/indexer'

const endpoints = getNetworkEndpoints(Network.Testnet)
const stream = new IndexerGrpcOracleStreamV2(endpoints.indexer)

const streamManager = new StreamManagerV2({
  id: 'oracle-prices-by-markets',
  streamFactory: () => stream.streamOraclePricesByMarkets({ 
    marketIds: ['0x...'],
    callback: (response) => {
      streamManager.emit('data', response)
    }
  }),
  onData: (oraclePrices) => {
    console.log(oraclePrices)
  },
  retryConfig: { enabled: true }
})

streamManager.on('connect', () => console.log('Stream connected'))
streamManager.start()
```
