OnixS C++ ICE Binary Order Entry Handler 1.2.3
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 38 of file GettingStarted.cpp.

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