Note Market data subscriptions are throttled at 750 per second and applications are limited to making no more than 15,000 market data subscriptions.
To create a price subscription and start receiving updates, you:
The following code snippet demonstrates an example of this process.
class PriceObserver : public ttsdk::IPriceEventHandler
{
public:
PriceObserver() {}
virtual void OnPriceUpdate(const uint64_t subId,
const ttsdk::InstrumentPtr& instrument, const ttsdk::PriceSnap& snap)
{
std::cout << “Price snapshot received.” << std::endl;
}
virtual void OnError(const uint64_t subId, const ttsdk::InstrumentPtr& instrument,
const ttsdk::SubscriptionError code, const char* error)
{
std::cout << "Error [" << error << "] occurred for instrument:"
<< instrument->GetAlias() << " subId=" << subId
<< " code=" << (int)code << std::endl;
}
virtual void OnDisconnect(const uint64_t subId,
const ttsdk::InstrumentPtr& instrument, const ttsdk::PriceEventType type)
{
std::cout << "Prices disconnected for subscription for instrument:"
<< instrument->GetAlias() << " subid=" << subId << std::endl;
}
virtual void OnUnsubscribed(const uint64_t subId)
{
std::cout << "Price observer for subId=" << subId
<< " has been successfully unsubscribed. " << std::endl;
}
};
void foo()
{
// …
PriceObserver prcObserver;
ttsdk::Instrument::ResponseCode respCode;
ttsdk::MarketId market = ttsdk::MarketId::CME;
std::string product = “GE”;
ttsdk::ProductType productType = ttsdk::ProductType::Future;
std::string alias = "GE Sep28";
ttsdk::InstrumentPtr instrument = ttsdk::GetInstrument(market, product.c_str(),
productType, alias.c_str(), respCode);
if (!instrument)
{
std::cout << "Unable to find instrument with alias = “ << alias << std::endl;
}
else
{
uint64_t subId = 0;
subId = ttsdk::SubscribePrices(instrument, 10, true, true, false, &prcObserver);
std::cout << "Subscription id=" << subId << std::endl;
}
// ...
}