TT CORE SDK  0.1
TT CORE SDK documentation
Retrieving Market Data

Subscribing for Market Data

The TT Core SDK offers two types of market data subscriptions:

  • Inside market (bid, ask, etc.) and market depth
  • Time & Sales

To create a market data subscription, you call the CreatePriceSubscription() function. The signature for this function is as follows.

// \param [in] instr Contract for which updates are being requested
// \param [in] filter Bitmask of fields that trigger event notifications
// \param [in] listener Listener on which to invoke callbacks
// \returns \ref PriceSubscription controller
// \throws std::invalid_argument Invalid parameters
// \throws std::domain_error Failed to create the subscription
PriceSubscription CreatePriceSubscription (
const std::shared_ptr<Instrument>& instr,
const Filter& filter,
const std::shared_ptr<PriceEventListener>& listener
);

where:

  • The instr variable is a reference to an instance of the Instrument class. It must be valid reference to an instrument that was returned from the DownloadInstrument() function.
  • The filter variable is a reference to an instance of the Filter class. This class allows users to define the list of market data fields for which notifications should be sent. The list of market data fields that can be included in the filter are located in the prices.hpp header file.
  • The listener variable is a reference to an instance of a class that must be derived from the PriceEventListener class described below.

The following code snippet demonstrates how to subscribe for market data for a given instrument.

// Download instrument
std::shared_ptr<Instrument> instr = DownloadInstrument("ESU7", market::CME);
if (!instr)
{
std::cerr << "Failed to download instrument\n";
return EXIT_FAILURE;
}
// Create a filter for the market data fields of interest
Filter filter = PRICE_FILTER_ASK0 | // best ask
PRICE_FILTER_BID0 | // best bid
PRICE_FILTER_LAST_TRADE_PRICE | // ltp
PRICE_FILTER_LAST_TRADE_QTY | // ltq
PRICE_FILTER_VOLUME | // volume
PRICE_FILTER_TIME_SALES; // time and sales updates
// Create a custom listener that will handle the price updates
auto listener = std::make_shared<MyPriceListener>();
// Subscribe for market data
PriceSubscription price_sub;
try
{
price_sub = CreatePriceSubscription(instr, filter, listener);
}
catch (const std::invalid_argument& ex)
{
std::cerr << "Invalid argument provided to create the price subscription"
<< " what=" << ex.what() << '\n';
return EXIT_FAILURE;
}
catch (const std::domain_error& ex)
{
std::cerr << "Failed to create the price subscription"
<< " what=" << ex.what() << '\n';
return EXIT_FAILURE;
}

Creating the Price Subscription Event Handlers

After the price subscription starts, the TT Core SDK retrieves a snapshot of the market data for the instrument and invokes the price update event handler method you registered with the subscription. It then subsequently invokes the event handler whenever there is an update to the market data. To create a listener you must inherit from the PriceEventListener class.

class MyPriceListener : public PriceEventListener
{
public:
// Callback delivering price updates
void OnPriceUpdate (const PriceSnap& snap) override
{
...
}
// Callback delivering time & sales updates
void OnTimeSalesUpdate (const TimeSale& ts) override
{
...
}
// Callback fired when an error occurs fulfilling a price subscription request
void OnError (const std::string& error) override
{
}
...
};

To receive Time & Sales updates, you must add the PRICE_FILTER_TIME_SALES flag to the filter you supply to the CreatePriceSubscription() method.

PriceSnap Structure

The definition of the PriceSnap struct can be found in the prices.hpp header file, and includes:

Public Attribute Description
asks

Ask side depth.

Returns a depth_snap struct, which is defined in the prices.hpp file.

bids

Bid side depth.

Returns a depth_snap struct, which is defined in the prices.hpp file.

close_price Price at the session close.
conflation_no Price conflation count.
exchange_time_ns Time that the exchange received the order that resulted in this market data update (in nanoseconds). Populated only when provided by the exchange.
exchange_transaction_time_ns Time that the exchange received the order that resulted in this market data update (in nanoseconds). Populated only when provided by the exchange.
high_price High price.
last_trade_price Last traded price.
last_trade_quantity Last traded quantity.
low_price Low price.
market_state

Market state.

Returns a market_state enum, which is defined in the enums.hpp file.

mdrc_recv_time Time that the price update was received from the TT Price Server.
open_price Price at the session open.
settlement_price Settlement Price
volume Total contract volume.

Note that all prices are returned in decimal (Points) format and will return NAN when a price is unavailable.

TimeSale Structure

The definition of the TimeSale struct can be found in the prices.hpp header file, and includes:

Public Attribute Description
epoch_transact_time_micro Transaction time since epoch (in microseconds)
exchange_transact_time_ns Time that the exchange received the order that resulted in this market data update (in nanoseconds).
is_implied Whether the trade is implied.
is_leg Whether the trade is a leg trade.
is_otc Trade is exchange supported OTC trade.
last_trade_price Last Traded Price.
last_trade_quantity Last traded quantity.
qualifier

Trade Qualifier.

Returns a trade_qualifier struct, which is defined in the enums.hpp file.

status

Trade Status.

Returns a trade_status struct, which is defined in the enums.hpp file.

type

Trade type.

Returns a trade_type struct, which is defined in the enums.hpp file.

Note that all prices are returned in decimal (Points) format and will return NAN when a price is unavailable.

Managing the Price Subscription

The PriceSubscription object returned from CreatePriceSubscription() provides the interface to manage the price subscription, including methods to pause, resume, and cancel. The Filter for the subscription can also be queried and updated.

PriceSubscription Class

Member Functions Description
AddFilter()

Appends to existing filter

void tt_core_sdk::PriceSubscription::AddFilter(const Filter & additional_filter);

The Filter bitset is defined in the prices.hpp file.

Cancel()

Cancels the price subscription.

GetFilter()

Manages the filters for this price subscription.

The Filter bitset is defined in the prices.hpp file.

Id()

Unique PriceSubscription ID.

IsValid()

Check if the subscription is valid.

Pause()

Stop delivering subscription updates to the listener.

Resume()

Resume delivering subscription updates to the listener.

SetFilter()

Overwrites filter.

The Filter bitset is defined in the prices.hpp file.