{"id":7020,"date":"2025-08-28T22:11:58","date_gmt":"2025-08-29T03:11:58","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=7020"},"modified":"2026-06-29T16:55:27","modified_gmt":"2026-06-29T21:55:27","slug":"receiving-solicited-and-unsolicited-order-fill-events","status":"publish","type":"doc","link":"https:\/\/library-staging.tradingtechnologies.com\/apis\/tt-core-sdk\/working-with-orders-and-fills\/receiving-solicited-and-unsolicited-order-fill-events\/","title":{"rendered":"Receiving Solicited and Unsolicited Order \/ Fill Events"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To receive solicited and unsolicited order \/ fill events, you need to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a class that is derived from ttsdk::IOrderBookEventHandler and defines your Order Book event handler.\n<ul class=\"wp-block-list\">\n<li>You must provide implementations for the following methods:\n<ul class=\"wp-block-list\">\n<li>virtual void OnExecutionReport(OrderPtr order, ExecutionReportPtr execRpt) = 0;\n<ul class=\"wp-block-list\">\n<li>Callback fired when delivering execution report messages<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>virtual void OnReject(OrderPtr order, RejectResponsePtr rejResp) = 0;\n<ul class=\"wp-block-list\">\n<li>Callback fired when delivering order reject messages<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>virtual void OnSendFailed(OrderPtr order, const OrderProfile&amp; profile, const SendCode code) = 0;\n<ul class=\"wp-block-list\">\n<li>Callback fired when a request delivery surpasses the timeout threshold<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>virtual void OnUnsubscribed(const char* orderId) = 0;\n<ul class=\"wp-block-list\">\n<li>Callback fired when the unsubscribe request is complete and it is safe to destroy the handler object<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>You can also optionally provide implementations for the following methods:\n<ul class=\"wp-block-list\">\n<li>virtual void OnPositionUpdate(const Position&amp; updatedPosition) {};\n<ul class=\"wp-block-list\">\n<li>Callback delivering position updates<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>virtual void OnAccountDownloadEnd(const uint64_t accountId) {};\n<ul class=\"wp-block-list\">\n<li>Callback indicating that the given account has been synchronized with the real time streams, and orders and positions have been downloaded.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>virtual void OnAccountDownloadFailed(const uint64_t accountId, const char* message) {};\n<ul class=\"wp-block-list\">\n<li>Callback indicating that the given account\u2019s orders and positions downloads have failed and the account is not usable.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>virtual void OnOrderBookDownloadEnd() {};\n<ul class=\"wp-block-list\">\n<li>Callback indicating that all orders and positions for all accounts are downloaded and synchronized with the real time stream.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Initialize the TT Core SDK passing your TTSDKOptions instance variable, your SDK event handler instance variable, and your Order Book event handler instance variable.\n<ul class=\"wp-block-list\">\n<li>Note that both the SDK and Order Book event handlers must have a lifespan that is valid for the life of the SDK (until shutdown is completed).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">An&nbsp;<strong>OnAccountDownloadEnd<\/strong>&nbsp;event is fired when an account is ready to be used for trading. And an&nbsp;<strong>OnOrderBookDownloadEnd<\/strong>&nbsp;event is fired when all accounts are ready.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following code snippet demonstrates an example of this process.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n#include &lt;iomanip>\n#include &lt;atomic>\n#include &lt;sstream>\n#include &lt;string.h>\n#include &lt;tt_cplus_sdk.h>\n#include &lt;condition_variable>\n\nstd::mutex mutex;\nstd::condition_variable sdkReadyCondition;\n\n\/\/\n\/\/  SDK event handler class\n\/\/\n\nclass SDKEventHandler : public ttsdk::IEventHandler\n{\n  public:\n      SDKEventHandler() : IEventHandler() {}\n      virtual ~SDKEventHandler() {}\n\n      \/\/ received on an SDK managed thread that can be used for processing.\n      \/\/ beware that time consuming tasks can delay the delivery of another status event.\n\n      virtual void OnStatus(const ttsdk::IEventHandler::Status status) override\n      {\n          std::cout &lt;&lt; \"SDKEventHandler::OnStatus (\" &lt;&lt; (uint32_t)status &lt;&lt; \")\" &lt;&lt; std::endl;\n      }\n};\n\n\/\/\n\/\/  Order Book event handler class\n\/\/\n\nclass MyOrderBookHandler : public ttsdk::IOrderBookEventHandler\n{\n  public:\n    MyOrderBookHandler() : IOrderBookEventHandler() {};\n    virtual ~MyOrderBookHandler() {};\n\n    virtual void OnExecutionReport(ttsdk::OrderPtr order, \n              ttsdk::ExecutionReportPtr execRpt) override\n    {\n      \/\/ ...\n    }\n    virtual void OnReject(ttsdk::OrderPtr order, ttsdk::RejectResponsePtr rejResp) override\n    {\n      \/\/ ...\n    }\n    virtual void OnSendFailed(ttsdk::OrderPtr order, const ttsdk::OrderProfile&amp; profile, \nconst SendCode code) override\n    {\n      \/\/ ...\n    }\n    virtual void OnUnsubscribed(const char* orderId) override\n    {\n      \/\/ ...\n    }\n\n    \/\/ account and book sync events are sent on the position thread so they are sequenced\n    \/\/ properly with the position update events\n\n    virtual void OnOrderBookDownloadEnd() override\n    {\n      std::cout &lt;&lt; \"---All assigned accounts are ready to use.\" &lt;&lt; std::endl;\n      std::lock_guard&lt;std::mutex> lock(mutex);\n      sdkReadyCondition.notify_one();\n    }\n    \n    \/\/ the SDK synchronizes the order book and positions by account.  as such, \n    \/\/ any given account can be able to trade without needing to wait \n    \/\/ for all accounts to be ready\n\n    virtual void OnAccountDownloadEnd(const uint64_t accountId) override\n    {\n      std::cout &lt;&lt; \"---Account accountId:\" &lt;&lt; accountId \n              &lt;&lt; \" is synchronized and ready to use.\" &lt;&lt; std::endl;\n    }\n    virtual void OnAccountDownloadFailed(const uint64_t accountId, const char* msg) override\n    {\n      std::cout &lt;&lt; \"---Account accountId:\" &lt;&lt; accountId &lt;&lt;\" download failed details: \" \n              &lt;&lt; msg &lt;&lt; std::endl;\n    }\n\n    \/\/ all position events are received on the SDK position processing thread. \n    \/\/ holding up processing for a given position event will impact all \n    \/\/ subsequent position updates\n\n    virtual void OnPositionUpdate(const ttsdk::Position&amp; updatedPosition) override\n    {\n      std::cout &lt;&lt; \"---OnPositionUpdate for AccountId:\" &lt;&lt; updatedPosition.account_id \n              &lt;&lt; \" Instrument:\" &lt;&lt; updatedPosition.instrument->GetAlias() &lt;&lt; std::endl;\n      std::cout &lt;&lt; \" SOD:\" &lt;&lt; updatedPosition.sod_quantity &lt;&lt; \"@\" \n              &lt;&lt; updatedPosition.sod_price \n              &lt;&lt; \" Buys:\" &lt;&lt;  updatedPosition.buy_quantity &lt;&lt; \"@\" \n              &lt;&lt; updatedPosition.buy_average_price \n              &lt;&lt; \" Sells:\" &lt;&lt; updatedPosition.sell_quantity &lt;&lt; \"@\" \n              &lt;&lt; updatedPosition.sell_average_price\n              &lt;&lt; \" Net:\" &lt;&lt; updatedPosition.net_position \n              &lt;&lt; \" P\/L:\" &lt;&lt; updatedPosition.native_currency_pnl \n              &lt;&lt; \" AvgPrc:\" &lt;&lt; updatedPosition.open_average_price \n              &lt;&lt; std::endl;\n    }\n};\n\n\/\/\n\/\/  Main\n\/\/\n\nint main(int argc, char* argv&#91;])\n{\n  \/\/Set the environment the app needs to run in here\n  ttsdk::Environment env = ttsdk::Environment::ProdLive;\n\n  \/\/ Add your app secret Key here. It looks like:\n00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000\n  std::string app_key = \u201cYour App Key\u201d;\n\n  ttsdk::TTSDKOptions options;\n  options.environment = env;\n  options.app_key_secret = app_key.c_str();\n\n  SDKEventHandler myObserver;\n  MyOrderBookHandler myOrderBookObserver;\n    \n  if (!ttsdk::Initialize(options, &amp;myObserver, &amp;myOrderBookObserver))\n  {\n    std::cout &lt;&lt; \"Unable to initialize SDK!\" &lt;&lt; std::endl;\n    return -1;\n  }  \n\n  std::unique_lock&lt;std::mutex> lock(mutex);\n  if (sdkReadyCondition.wait_for(lock, std::chrono::seconds(300)) == std::cv_status::timeout)\n  {\n    std::cout &lt;&lt; \"Timeout waiting for SDK to initialize!\" &lt;&lt; std::endl;\n    return -1;\n  }\n\n  std::cout &lt;&lt; std::endl;\n  std::cout &lt;&lt; \"&lt;&lt;&lt;&lt;&lt; TT CORE SDK is initialized. >>>>>\" &lt;&lt; std::endl;\n\n  std::cout &lt;&lt; std::endl &lt;&lt; \"Press q to exit.....\" &lt;&lt; std::endl;\n  std::string command;\n  while (std::cin >> command)\n  {\n    if (command == \"q\")\n    {\n      std::cout &lt;&lt; \"Quitting...\\n\";\n      break;\n    }\n  }\n  std::cout &lt;&lt; \"Exiting...\" &lt;&lt; std::endl;\n  ttsdk::Shutdown();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p class=\"wp-block-paragraph\">To receive solicited and unsolicited order \/ fill events, you need to:<\/p>\n<p class=\"wp-block-paragraph\">An&nbsp;<strong>OnAccountDownloadEnd<\/strong>&nbsp;event is fired when an account is ready to be used for trading. And an&nbsp;<strong>OnOrderBookDownloadEnd<\/strong>&nbsp;event is fired when all accounts are ready.<\/p>\n<p class=\"wp-block-paragraph\">The following code snippet demonstrates an example of this process.<\/p>\n","protected":false},"author":2,"template":"wp-custom-template-single-doc-tt-core-sdk","meta":{"_acf_changed":false,"footnotes":""},"docs-category":[448],"class_list":["post-7020","doc","type-doc","status-publish","hentry","docs-category-working-with-orders-and-fills"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/7020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc"}],"about":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/types\/doc"}],"author":[{"embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":5,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/7020\/revisions"}],"predecessor-version":[{"id":59704,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/7020\/revisions\/59704"}],"wp:attachment":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=7020"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=7020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}