To build this type of application, you must:
The following code snippet demonstrates an example of this process.
#pragma once
#include <string.h>
#include <map>
#include <memory>
#include <tt_cplus_sdk.h>
//
// external algo request event handler class
//
class SDKAlgoManager : public ttsdk::ISDKAlgoManager
{
public:
SDKAlgoManager() : ttsdk::ISDKAlgoManager() {};
virtual ~SDKAlgoManager() {};
virtual uint64_t GetInstanceId() override
{
return 1;
}
virtual const char* GetMarkets() override
{
return markets_.c_str();
}
virtual void OnRecoverAlgo(ttsdk::SDKAlgoPtr algoOrder,
ttsdk::SDKAlgoRequestPtr req)
{ // … }
virtual void OnRecoveryEnd()
{ // … }
virtual void OnRecoveryFailed()
{ // … }
virtual void OnStartRequest(ttsdk::SDKAlgoPtr algoOrder,
ttsdk::SDKAlgoRequestPtr req)
{ // … }
virtual void OnUpdateRequest(ttsdk::SDKAlgoPtr algoOrder,
ttsdk::SDKAlgoRequestPtr req)
{ // … }
virtual void OnStopRequest(ttsdk::SDKAlgoPtr algoOrder,
ttsdk::SDKAlgoRequestPtr req)
{ // … }
virtual void OnPauseRequest(ttsdk::SDKAlgoPtr algoOrder,
ttsdk::SDKAlgoRequestPtr req)
{ // … }
virtual void OnResumeRequest(ttsdk::SDKAlgoPtr algoOrder,
ttsdk::SDKAlgoRequestPtr req)
{ // … }
virtual void OnAlgoCompleted(ttsdk::SDKAlgoPtr algoOrder)
{ // … }
virtual void OnScheduledEvent(ttsdk::SDKAlgoPtr algoOrder,
unsigned int eventId,
void* eventUserData)
{ // … }
protected:
std::string markets_ = "7,32";
};
//
// SDK event handler class
// See here for further details
//
class SDKEventHandler : public ttsdk::IEventHandler
{
// …
}
//
// Order Book event handler class
// See here for further details
//
class MyOrderBookHandler : public ttsdk::IOrderBookEventHandler
{
// ...
}
//
// Main
//
int main(int argc, char* argv[])
{
//Set the environment the app needs to run in here
ttsdk::Environment env = ttsdk::Environment::ProdLive;
// Add your app secret Key here. It looks like: 00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000
std::string app_key = “Your App Key”;
ttsdk::TTSDKOptions options;
options.environment = env;
options.app_key_secret = app_key.c_str();
SDKEventHandler myObserver;
MyOrderBookHandler myOrderBookObserver;
SDKAlgoManager algoManager;
if (!ttsdk::Initialize(options, &myObserver, &myOrderBookObserver, &algoManager))
{
std::cout << "Unable to initialize SDK!" << std::endl;
return -1;
}
std::unique_lock lock(mutex);
if (sdkReadyCondition.wait_for(lock, std::chrono::seconds(300)) ==
std::cv_status::timeout)
{
std::cout << "Timeout waiting for SDK to initialize!" << std::endl;
return -1;
}
std::cout << std::endl;
std::cout << "<<<<< TT CORE SDK is initialized. >>>>>" << std::endl;
std::cout << std::endl << "Press q to exit....." << std::endl;
std::string command;
while (std::cin >> command)
{
if (command == "q")
{
std::cout << "Quitting...\n";
break;
}
}
std::cout << "Exiting..." << std::endl;
ttsdk::Shutdown();
}