To create a Time and Sales subscription and start receiving updates, you:
-
Create a class that is derived from
ttsdk::ITimeSalesEventHandler and defines your event
handler. You must provide implementations for:
- virtual void OnTimeSalesUpdate(const uint64_t subId, const InstrumentPtr& instrument, const TimeSales& ts) = 0;
- Callback fired when trades occur in the market
- virtual void OnError(const uint64_t subId, const InstrumentPtr& instrument, const SubscriptionError code, const char* error) = 0;
- Callback fired when an error occurs fulfilling a price subscription request
- virtual void OnDisconnect(const uint64_t subId, const InstrumentPtr& instrument, const PriceEventType type) = 0;
- Callback fired when an disconnection event happens
- virtual void OnUnsubscribed(const uint64_t subId) = 0;
- Callback fired when the unsubscribe request is complete and it is safe to destroy the handler object
-
Call the SubscribeTimeAndSales() function passing your event
handler instance variable.
- The SubscribeTimeAndSales() function allows you to specify whether to wish to optionally receive TT’s simulation price stream.
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 GetAlias() GetAlias()