TT CORE SDK

Extracting Time and Sales Values

Extracting Time and Sales Values

After the subscription starts, TT Core SDK invokes the event handler method you registered with the subscription for every Time & Sales update passing an instance of a TimeSales struct. The TimeSales struct contains an array of Trade struct instances where each contains the data corresponding to a trade that occurred in the market, including:

        
double last_trade_price = NAN; 
double last_trade_quantity = NAN;  
ttsdk::TradeType trade_side;
uint64_t epoch_transact_time_nano;
uint64_t exchange_transact_time_ns;

In other words, you will receive data for one or more trades when this callback is fired. The following code snippet demonstrates how to process a price subscription update.



std::string to_string(const ttsdk::TimeSales& ts)
{
  std::ostringstream ss;

  if (ts.event_type == ttsdk::PriceEventType::DIRECT)
      ss << "TimeSales:     [direct event]\n";
  else if (ts.event_type == ttsdk::PriceEventType::CALCULATED_IMPLIEDS)
      ss << "TimeSales:     [calulcated implieds event]\n";
  else if (ts.event_type == ttsdk::PriceEventType::SIMULATED)
      ss << "TimeSales:     [simulated event]\n";
  else
      ss << "TimeSales:     [unknown event]\n";

  for (size_t i=0; i< ts.count;++i) 
  {
      ss <<  "side=" << (int)ts.trades[i].trade_side << '\n'
          << "ltp=" << ts.trades[i].last_trade_price << '\n'
          << "ltq=" << ts.trades[i].last_trade_quantity << '\n'
          << "trade_indicator=" << (int)ts.trades[i].indicator << '\n'
          << "trade_qualifier=" << (int)ts.trades[i].qualifier << '\n'
          << "otc_type=" << (int)ts.trades[i].otc_type << '\n';
  }
  
  return ss.str();
}