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;
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;
}
};