To create a Time and Sales subscription and start receiving updates, you:
The following code snippet demonstrates an example of this process.
class TSObserver : public ttsdk::ITimeSalesEventHandler
{
public:
TSObserver() {}
virtual void OnTimeSalesUpdate(const uint64_t subId,
const ttsdk::InstrumentPtr& instrument,
const ttsdk::TimeSales& ts)
{
std::cout << “Time and Sales event 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 << "TimeAndSales disconnected for subscription for instrument:"
<< instrument->GetAlias()
<< " subid=" << subId
<< std::endl;
}
virtual void OnUnsubscribed(const uint64_t subId)
{
std::cout << "TimeAndSales observer for subId="
<< subId
<< " has been successfully unsubscribed."
<< std::endl;
}
};
void foo()
{
// …
TSObserver tsObserver;
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::SubscribeTimeAndSales(instrument, false, &tsObserver);
std::cout << "Subscription id=" << subId
<< std::endl;
}
// …
}