OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
GettingStarted.cpp File Reference

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 37 of file GettingStarted.cpp.

38{
39 // `--help` to show options.
40 const AppConfiguration<
45 > cfg{"GettingStarted", argc, argv};
46
47 try
48 {
50
51 auto settings = fillSettings(cfg);
52
53 const auto emulator = createEmulator(settings, cfg);
54
55 // A `SessionListener` instance.
56 Listener listener;
57
58 // Credentials for Binary Order Gateway service.
59 BgwCredentials bgwCredentials;
60
61 // Request Binary Order Gateway credentials from Binary Utility Service (BUS) Gateway.
62 {
63 auto busSettings = settings;
64
65 // Create an instance of a `BUS` session
66 const auto busSession = std::make_unique<BusSession>(settings, &listener, cfg.storage());;
67
68 // Connect.
69 busSession->connect(cfg.host(), cfg.port());
70
71 //request a bgw credentials
72 auto bgwCredentialsFuture = busSession->getBgwCredentialsAsync(cfg.userId());
73
74 // Save Binary Order Gateway service credentials.
75 bgwCredentials = bgwCredentialsFuture.get();
76
77 // Disconnect.
78 busSession->disconnect();
79 }
80
81 // Log in and put an order to Binary Order Gateway service.
82 {
83 // Create an instance of a `BGW` session.
84 const auto bgwSession = std::make_unique<BgwSession>(settings, &listener, cfg.storage());;
85
86 // Connect.
87 bgwSession->connect(bgwCredentials);
88
89 // Create `TraderLogonRequest` message.
90 auto traderLogonRequest = Helper::createTraderLogonRequest(cfg.traderId(), cfg.traderPwd());
91
92 // Send `TraderLogonRequest` message.
93 bgwSession->send(traderLogonRequest);
94
95 // Wait until `TraderLogonReport` is received.
96 Samples::wait(listener.traderLoggedOn).get();
97
98 // Create an order.
99 auto order = Helper::createOrder(cfg.traderId());
100
101 // Put an order.
102 bgwSession->send(order);
103
104 // Wait for user action.
105 SignalHelper::waitUntilKey("disconnect the BGW session and terminate the application");
106
107 // Create `TraderLogoutRequest` message.
108 auto traderLogoutRequest = Helper::createTraderLogoutRequest(cfg.traderId());
109
110 // Log out trader.
111 bgwSession->send(traderLogoutRequest);
112
113 // Disconnect.
114 bgwSession->disconnect();
115 }
116 }
117 catch(const std::exception & ex)
118 {
119 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
120 return 1;
121 }
122
123 return 0;
124}
BGW session connection credentials.
static MessageHolder< NewOrderRequest > createOrder(const std::string &traderId)
Definition Helpers.h:104
static MessageHolder< TraderLogoutRequest > createTraderLogoutRequest(const std::string &traderId)
Definition Helpers.h:95
static MessageHolder< TraderLogonRequest > createTraderLogonRequest(const std::string &traderId, const std::string &traderPwd)
Definition Helpers.h:77
std::promise< void > traderLoggedOn
Definition Listener.h:223
std::pair< std::unique_ptr< GatewayEmulatorThread< BusSessionGatewayListener > >, std::unique_ptr< GatewayEmulatorThread< GatewayListener > > > createEmulator(const SessionSettings &settings, const ConnectivityConfiguration &cfg, bool tcpDirect=false)
Definition Emulator.h:157
SessionSettings fillSettings(const LogonConfiguration &logonCfg, const ConnectivityConfiguration &connCfg, const SettingsConfiguration &settingsCfg)
Definition Settings.h:32
std::future< T > wait(Stack &stack, std::promise< T > &promise, std::chrono::seconds timeout=std::chrono::seconds{30})
Definition Listener.h:227
static void waitUntilKey(const std::string &message)
Definition Signal.h:57
static void manageSignals() noexcept
Definition Signal.h:46