> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baibaibot.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Realtime Market Data

> Subscribe to realtime market data from various exchanges.

<img noZoom src="https://mintcdn.com/baibai/Q0FEDFNQDcX1j3TO/images/separator.jpg?fit=max&auto=format&n=Q0FEDFNQDcX1j3TO&q=85&s=5350c337aa3613424b48079d872b63e6" width="721" height="5" data-path="images/separator.jpg" />

## Using OHLCV realtime market data

<Note>
  You can register multiple OHLCV data sources accross different timeframes and exchanges.
</Note>

<Tip>
  Using multiple OHLCV data sources can help you build more complex signals. As an example in the crypto market, usually when BTC goes up/down, the altcoins follow that trend. By using multiple OHLCV data sources, you can build a signal that takes into account the BTC price movement and the altcoin price movement.
</Tip>

Here is an example that demonstrates how to use the SDK to register to multiple OHLCV data sources:

#### Register the OHLCV data sources in the init function of your signal:

```php theme={null}
// register a 5 minute OHLCV data source for the default exchange and asset pair the signal runs on (e.g. AAPL on IBKR) with a 5 entry history
$this->addOHLCVData("min5", OHLCVDataPeriod::Min5, 5);
// register a 1 minute OHLCV data source for the ETH/USDT pair on Binance with a 10 entry history
$this->addOHLCVDataSeries("eth_min1", OHLCVDataFetcherBinance::Id, CryptoAsset::USDT(), CryptoAsset::ETH(), OHLCVDataPeriod::Min1, 10);
```

#### Use the OHLCV data in the getSignalInfo function of your signal:

```php theme={null}
function getSignalInfo(TradeContext $tradeContext):?TradeSignalInfo
{
	foreach ($tradeContext->dataSeries as $key => $dataSeries)
	{
		if (!$dataSeries)
		{
			// we have no data for this data series
			continue;
		}

		// do something with the data series
		$ohlcvEntry = $dataSeries->data[0];

		// do something with the OHLCV entry
		// $ohlcvEntry->openTime;
		// $ohlcvEntry->closeTime;
		// $ohlcvEntry->low;
		// $ohlcvEntry->high;
		// $ohlcvEntry->open;
		// $ohlcvEntry->close;
		// $ohlcvEntry->volume;
		// $ohlcvEntry->previousEntry()->close;
	}

	...
}
```

#### Full example class

```php theme={null}
class MultiOHLCVDataExample extends UserTradeSignalBase
{
	protected function init(?ParamValues $params = null)
	{
		// NOTE: we could use the $params variable to pass the entry lengths for the OHLCV data sources and other parameters that are hard-coded in this example
		// register a 5 minute OHLCV data source for the default exchange and asset pair the signal runs on (e.g. AAPL on IBKR) with a 5 entry history
		$this->addOHLCVData("min5", OHLCVDataPeriod::Min5, 5);
		// register a 1 minute OHLCV data source for the ETH/USDT pair on Binance with a 10 entry history
		$this->addOHLCVDataSeries("eth_min1", OHLCVDataFetcherBinance::Id, CryptoAsset::USDT(), CryptoAsset::ETH(), OHLCVDataPeriod::Min1, 10);
	}

	function getSignalInfo(TradeContext $tradeContext):?TradeSignalInfo
	{
		foreach ($tradeContext->dataSeries as $key => $dataSeries)
		{
			if (!$dataSeries)
			{
				// we have no data for this data series
				continue;
			}

			// do something with the data series
			$ohlcvEntry = $dataSeries->data[0];

			// do something with the OHLCV entry
			// $ohlcvEntry->openTime;
			// $ohlcvEntry->closeTime;
			// $ohlcvEntry->low;
			// $ohlcvEntry->high;
			// $ohlcvEntry->open;
			// $ohlcvEntry->close;
			// $ohlcvEntry->volume;
			// $ohlcvEntry->previousEntry()->close;
		}

		return null;
	}
}
```
