TT CORE SDK

Extracting Market Data Values

Extracting Market Data Values

After the subscription starts, TT Core SDK invokes the event handler method you registered with the subscription for every price update passing an instance of a PriceSnap struct. The PriceSnap struct contains members for each element of market data, such as:

    
double open_price = NAN;                  
double close_price = NAN;         
double high_price = NAN;          
double low_price = NAN;           
double last_trade_price = NAN;    
double last_trade_quantity = NAN; 
double volume = NAN;              
double cum_last_trade_quantity = NAN; 
double settlement_price = NAN;    
double open_interest = NAN;       

It also contains an array of the DepthLevel struct for bid depth and an array of the DepthLevel struct for ask depth.



struct DepthSnap
{
  // a single level of the total depth

  struct DepthLevel
  {
    double price;            //!< Price
    int32_t order_count;     //!< Number of orders that make up the total quantity
    double quantity;         //!< Total quantity at this level
    double implied_quantity; //!< Implied quantity contributing to the total quantity
  } levels[MAX_DEPTH_LEVEL];

  size_t count; //!< Number of available price depth levels
};


                      
DepthSnap asks; DepthSnap bids; Note: All prices are delivered in Points. The following code snippet demonstrates how to process a price subscription update.


std::string to_string(const ttsdk::PriceSnap& snap)
{
  std::ostringstream ss;

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

  ss << "market_state=" << (int)snap.market_state
     << " asks.count=" << snap.asks.count
     << " bids.count=" << snap.bids.count
     << '\n'
     << "open=" << snap.open_price
     << " close=" << snap.close_price
     << " high=" << snap.high_price
     << " low=" << snap.low_price
     << " settle=" << snap.settlement_price
     << '\n'
     << "ltp=" << snap.last_trade_price
     << " ltq=" << snap.last_trade_quantity
     << " volume=" << snap.volume
     << '\n';

  if (snap.asks.count > 0 || snap.bids.count > 0)
  {
      ss << "  #order   imp Q       Q  |     price     |       Q   imp Q  #order\n";
  }

  for (int i = snap.asks.count - 1; i >= 0; --i)
  {
    const auto& level = snap.asks.levels[i];
    ss << "                          |"
       << std::setw(15) << std::setprecision(6) << level.price
       << "|"
       << std::setw(8) << level.quantity
       << std::setw(8) << level.implied_quantity
       << std::setw(8) << level.order_count << '\n';
  }

  for (int i = 0; i < snap.bids.count; ++i)
  {
    const auto& level = snap.bids.levels[i];
    ss << std::setw(8) << level.order_count
       << std::setw(8) << level.implied_quantity
       << std::setw(8) << level.quantity
       << "  |"
       << std::setw(15) << std::setprecision(6) << level.price << "|\n";
  }

  return ss.str();
}