TT CORE SDK

Receiving Only Specific Solicited Order / Fill Events

Receiving Only Specific Solicited Order / Fill Events

To receive specific solicited order / fill events, you need to:

  • Create a class that is derived from ttsdk::IOrderEventHandler and provide implementations for the following methods.

    • virtual void OnExecutionReport(OrderPtr order, ExecutionReportPtr execRpt) = 0;

      • Callback fired when delivering execution report messages
    • virtual void OnReject(OrderPtr order, RejectResponsePtr rejResp) = 0;
      • Callback fired when delivering order reject messages
    • virtual void OnSendFailed(OrderPtr order, const OrderProfile& profile, const SendCode code) = 0;
      • Callback fired when a request delivery surpasses the timeout threshold
    • virtual void OnUnsubscribed(const char* orderId) = 0;
      • Callback fired when the unsubscribe request is complete and it is safe to destroy the handler object
  • Call the Subscribe() method of the OrderPtr instance passing an instance of the class that defines your ttsdk::IOrderEventHandler event handler.

A sample implementation of class derived from ttsdk::IOrderEventHandler is demonstrated in the following code snippet.


  
class OrderObserver : public ttsdk::IOrderEventHandler
{
  public:
      OrderObserver() {}

      virtual void OnExecutionReport(ttsdk::OrderPtr order, 
              ttsdk::ExecutionReportPtr execRpt) override
      {
              switch(execRpt->GetExecType())
              {
                    case ttsdk::ExecType::New :
                      std::cout << "Order successfully entered in market. RequestId=" 
                            << execRpt->GetRequestId() 
                            << " OrderStatus=" 
                            << ttsdk::ToString(execRpt->GetOrderStatus()) << std::endl;
                      break;
                    case ttsdk::ExecType::Canceled :
                      std::cout << "Order successfully cancelled. RequestId=" 
                            << execRpt->GetRequestId() 
                            << " OrderStatus=" 
                            << ttsdk::ToString(execRpt->GetOrderStatus()) 
                            << " [external=" << execRpt->IsExternalAction() 
                            << "]" << std::endl;
                      break;
                    case ttsdk::ExecType::Replaced :
                      std::cout << "Order replaced. RequestId=" 
                            << execRpt->GetRequestId() 
                            << " TTOrderId=" << order->GetOrderId() 
                            << " OrderStatus=" 
                            << ttsdk::ToString(execRpt->GetOrderStatus()) 
                            << " [external=" << execRpt->IsExternalAction() 
                            << "]" << std::endl;
                      break;
                    case ttsdk::ExecType::Trade :
                      std::cout << "Order filled. RequestId=" 
                            << execRpt->GetRequestId() 
                            << " TTOrderId=" << order->GetOrderId() 
                            << " OrderStatus=" 
                            << ttsdk::ToString(execRpt->GetOrderStatus()) << std::endl;
                      break;
                    case ttsdk::ExecType::Rejected :
                      std::cout << "Order filled. RequestId=" << execRpt->GetRequestId() 
                            << " TTOrderId=" << order->GetOrderId() 
                            << " OrderStatus=" 
                            << ttsdk::ToString(execRpt->GetOrderStatus()) << std::endl;
                      break;
                    default:
                      std::cout << "Unhandled event. RequestId=" 
                            << execRpt->GetRequestId() << " TTOrderId=" 
                            << order->GetOrderId() << " OrderStatus=" 
                            << ttsdk::ToString(execRpt->GetOrderStatus()) 
                            << " ExecutionType=" 
                            << ttsdk::ToString(execRpt->GetExecType()) << std::endl;
              }
      }

      virtual void OnReject(ttsdk::OrderPtr order, ttsdk::RejectResponsePtr rejResp) override
      {
              std::cout << "OnReject event. RequestId=" << rejResp->GetRequestId() 
                    << " TTOrderId=" << order->GetOrderId() << " RejectReason=" 
                    << ttsdk::ToString(rejResp->GetRejectReason()) 
                    << " Text=" << rejResp->GetText() << std::endl;
              order_.reset();
      }

      virtual void OnSendFailed(ttsdk::OrderPtr order, const ttsdk::OrderProfile& profile, 
              const ttsdk::IOrderEventHandler::SendCode code) override
      {
            std::cout << "Order send failed. RequestId=" << profile.request_id
                  << " TTOrderId=" << order->GetOrderId() << " SendCode=" 
                  << (int)code << std::endl;
      }

      virtual void OnUnsubscribed(const char* orderId) override
      {
            std::cout << "Order observer for orderId=" << orderId 
                  << " has been successfully unsubscribed." << std::endl;
      }  
};