{"id":7008,"date":"2025-08-28T22:11:56","date_gmt":"2025-08-29T03:11:56","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=7008"},"modified":"2025-09-04T17:17:22","modified_gmt":"2025-09-04T22:17:22","slug":"initializing-an-application-with-order-book-download","status":"publish","type":"doc","link":"https:\/\/library-staging.tradingtechnologies.com\/apis\/tt-core-sdk\/creating-application-framework\/initializing-an-application-with-order-book-download\/","title":{"rendered":"Initializing an Application with Order Book Download"},"content":{"rendered":"\n<p>\n  To create a basic TT Core SDK application that downloads the\n  Order Book on start up, you need to:\n<\/p>\n\n<ul>\n  <li>\n    Create a class that is derived from\n    <strong>ttsdk::IEventHandler<\/strong> and defines your SDK\n    event handler. You must provide implementations for:\n    <ul>\n      <li>virtual void OnStatus(const Status status) = 0;<\/li>\n    <\/ul>\n  <\/li>\n  <li>\n    Create a class that is derived from\n    <strong>ttsdk::IOrderBookEventHandler<\/strong> and defines\n    your Order Book event handler.<br>\n    Create an instance of the\n    <strong>TTSDKOptions<\/strong> class. Define the TT\n    environment to which your application will connect and\n    specify your application key for this environment.\n  <\/li>\n  <li>\n    Initialize the TT Core SDK passing your\n    <strong>TTSDKOptions<\/strong> instance variable, your SDK\n    event handler instance variable, and your Order Book event\n    handler instance variable.\n    <ul>\n      <li>\n        Once an application initializes the TT Core SDK shared\n        library, all other applications will use the same\n        instance, so any subsequent calls will be a no-op.\n      <\/li>\n      <li>\n        Note that both the SDK and Order Book event handlers\n        must have a lifespan that is valid for the life of the\n        SDK (until shutdown is completed).\n      <\/li>\n    <\/ul>\n  <\/li>\n<\/ul>\n\n<p>\n  After the initialization is started, TT Core SDK downloads:\n<\/p>\n\n<ul>\n  <li>the accounts belonging to the user<\/li>\n  <li>the orders associated with each account<\/li>\n  <li>the positions associated with each account<\/li>\n<\/ul>\n\n<p>\n  TT Core SDK synchronizes the Order Book and positions by\n  account. As such, any given account can be used to trade\n  without needing to wait for all accounts to be ready. An\n  OnAccountDownloadEnd event is fired when an account is ready\n  to be used for trading. An\n  <strong>OnOrderBookDownloadEnd<\/strong> event is fired when\n  all accounts are ready.\n<\/p>\n\n<p>\n  The following code snippet demonstrates an example of this\n  process.\n<\/p>\n\n<div class=\"language-plaintext highlighter-rouge\">\n  <div class=\"highlight\">\n    <pre class=\"highlight\"><code>\n\n#include &lt;iostream&gt;\n#include &lt;iomanip&gt;\n#include &lt;atomic&gt;\n#include &lt;sstream&gt;\n#include &lt;string.h&gt;\n#include &lt;tt_cplus_sdk.h&gt;\n#include &lt;condition_variable&gt;\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  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 GetAlias()  lock(mutex);\n  if (sdkReadyCondition.wait_for(lock, std::chrono::seconds(300)) == std::cv_status::timeout)\n  {\n    std::cout &gt;&gt;&gt;&gt;\" &gt; command)\n  {\n    if (command == \"q\")\n    {\n      std::cout <\/code><\/pre>\n                  <\/div>\n                <\/div>\n","protected":false},"excerpt":{"rendered":"<p>To create a basic TT Core SDK application that downloads the Order Book on start up, you need to: Create a cla [&hellip;]<\/p>\n","protected":false},"author":2,"template":"wp-custom-template-single-doc-tt-core-sdk","meta":{"_acf_changed":false,"footnotes":""},"docs-category":[445],"class_list":["post-7008","doc","type-doc","status-publish","hentry","docs-category-creating-application-framework"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/7008","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":0,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/7008\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=7008"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=7008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}