36using namespace ONIXS_ICEBOE_NAMESPACE::Threading;
40 template <
typename MessageType>
43 std::clog << msg << std::endl;
49 std::clog <<
"Unknown message type";
60 std::clog <<
"\nOutbound message:\n";
66 std::clog <<
"\nReceived:\n" << msg << std::endl;
71 std::clog <<
"\nReceived:\n" << msg << std::endl;
76 std::clog <<
"\nReceived:\n" << msg << std::endl;
81 std::clog <<
"\nReceived:\n" << msg << std::endl;
86 std::clog <<
"\nReceived:\n" << msg << std::endl;
91 std::clog <<
"\nReceived:\n" << msg << std::endl;
96 std::clog <<
"\nReceived:\n" << msg << std::endl;
101 std::clog <<
"\nReceived:\n" << msg << std::endl;
106 std::clog <<
"\nReceived:\n" << msg << std::endl;
111 std::clog <<
"\nReceived:\n" << msg << std::endl;
116 std::clog <<
"\nReceived:\n" << msg << std::endl;
120 const auto text = msg.
text();
132 std::clog <<
"\nReceived:\n" << msg << std::endl;
137 std::clog <<
"\nReceived:\n" << msg << std::endl;
142 std::clog <<
"\nReceived:\n" << msg << std::endl;
147 std::clog <<
"\nReceived:\n" << msg << std::endl;
152 std::clog <<
"\nReceived:\n" << msg << std::endl;
157 std::clog <<
"\nReceived:\n" << msg << std::endl;
162 std::clog <<
"\nReceived:\n" << msg << std::endl;
167 std::clog <<
"\nReceived:\n" << msg << std::endl;
172 std::clog <<
"\nReceived:\n" << msg << std::endl;
177 std::clog <<
"\nReceived:\n" << msg << std::endl;
182 std::clog <<
"\nReceived:\n" << msg << std::endl;
188 <<
"\nSession's state is changed, prevState="
198 std::cerr <<
"\nSession-level error: " << description;
202 std::cerr <<
",\nCaused by the message: ";
206 std::cerr << std::endl;
212 std::cerr <<
"\nSession-level warning: " << description;
216 std::cerr <<
",\nCaused by the message: ";
220 std::cerr << std::endl;
226template <
typename T,
typename Stack>
227std::future<T>
wait(Stack& stack, std::promise<T>& promise, std::chrono::seconds timeout = std::chrono::seconds{30})
229 auto future = promise.get_future();
231 const auto deadline = std::chrono::steady_clock::now() + timeout;
232 std::uint32_t spins = 0;
236 stack.dispatchEvents();
238 if (future.wait_for(std::chrono::nanoseconds{0}) == std::future_status::ready)
241 if ((++spins & 0xFFu) == 0)
243 if (std::chrono::steady_clock::now() >= deadline)
245 promise.set_exception(std::make_exception_ptr(std::runtime_error(
"Operation timed out.")));
253std::future<T>
wait(std::promise<T>& promise, std::chrono::seconds timeout = std::chrono::seconds{30})
255 auto future = promise.get_future();
257 if(future.wait_for(timeout) != std::future_status::ready)
258 promise.set_exception(std::make_exception_ptr(std::runtime_error(
"Operation timed out.")));
274 busSession.
connect(host, port);
278 const auto bgwCredentials = bgwCredentialsFuture.get();
283 return bgwCredentials;
#define ONIXS_ICEBOE_NAMESPACE
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE
BGW session connection credentials.
Session & connect(const std::string &host, Port port)
Establishes the connection.
Threading::SharedFuture< BgwCredentials > getBgwCredentialsAsync(const std::string &userId, bool forceRequest=0) final
Asynchronously provides the BGW session connection credentials for the given user id.
bool valid() const noexcept
const std::string & userId() const noexcept
ThreadingModel::Enum threadingModel() const noexcept
Session & disconnect(const std::string &reason={})
Terminates the connection.
void onMassQuoteReport(const Messaging::MassQuoteReport msg, Session *) override
Called when a MassQuoteReport message is received.
void onStateChange(SessionStateId::Enum newState, SessionStateId::Enum prevState, Session *) override
Called when the session changes its state.
void onSecurityDefinitionReject(const Messaging::SecurityDefinitionReject msg, Session *) override
Called when a SecurityDefinitionReject message is received.
void onWarning(SessionWarningReason::Enum, const std::string &description, Session *, Messaging::SbeMessage msg) override
Called when a warning condition is detected by the session.
void onNews(const Messaging::News msg, Session *) override
Called when a News message is received.
std::promise< void > traderLoggedOn
void onTraderLogoutReport(const Messaging::TraderLogoutReport msg, Session *) override
Called when a TraderLogoutReport message is received.
~Listener() override=default
void onHeartBeat(const Messaging::HeartBeat msg, Session *) override
Called when a HeartBeat message is received.
void onSecurityDefinitionReport(const Messaging::SecurityDefinitionReport msg, Session *) override
Called when a SecurityDefinitionReport message is received.
void onNewOrderCrossReport(const Messaging::NewOrderCrossReport msg, Session *) override
Called when a NewOrderCrossReport message is received.
void onExecutionReport_Modify(const Messaging::ExecutionReport_Modify msg, Session *) override
Called when an ExecutionReport_Modify message is received.
void onLogonReport(const Messaging::LogonReport msg, Session *) override
Called when a LogonReport message is received.
void onError(const Messaging::Error msg, Session *) override
Called when an Error message is received from the counterparty.
void onIPReport(const Messaging::IPReport msg, Session *) override
Called when an IPReport message is received.
void onExecutionReport_Cancel(const Messaging::ExecutionReport_Cancel msg, Session *) override
Called when an ExecutionReport_Cancel message is received.
void onExecutionReport_Reject(const Messaging::ExecutionReport_Reject msg, Session *) override
Called when an ExecutionReport_Reject message is received.
void onExecutionReport_Trade(const Messaging::ExecutionReport_Trade msg, Session *) override
Called when an ExecutionReport_Trade message is received.
void onOrderMassCancelReport(const Messaging::OrderMassCancelReport msg, Session *) override
Called when an OrderMassCancelReport message is received.
void onExecutionReport_New(const Messaging::ExecutionReport_New msg, Session *) override
Called when an ExecutionReport_New message is received.
void onQuoteReport(const Messaging::QuoteReport msg, Session *) override
Called when a QuoteReport message is received.
void onSecurityDefinitionReport_Strategy(const Messaging::SecurityDefinitionReport_Strategy msg, Session *) override
Called when a SecurityDefinitionReport_Strategy message is received.
void onSecurityDefinitionReport_Product(const Messaging::SecurityDefinitionReport_Product msg, Session *) override
Called when a SecurityDefinitionReport_Product message is received.
void onMessageSending(char *bytes, size_t size, Session *) override
Called right before an SBE message is sent to the wire.
void onError(SessionErrorReason::Enum, const std::string &description, Session *, Messaging::SbeMessage msg) override
Called when an error condition is detected by the session.
void onExecutionReport_Snapshot(const Messaging::ExecutionReport_Snapshot msg, Session *) override
Called when an ExecutionReport_Snapshot message is received.
void onLogoutReport(const Messaging::LogoutReport msg, Session *) override
Called when a LogoutReport message is received.
void onTraderLogonReport(const Messaging::TraderLogonReport msg, Session *) override
Called when a TraderLogonReport message is received.
constexpr std::enable_if<!details::HasMemberTraits< Value >::value, size_t >::type size() noexcept
bool processTypified(SbeMessage binary, Processor &&processor)
Casts a given binary message according to template/type information and processes the cast messages b...
std::string format(Int32 index, StrRef input)
UInt16 MessageSize
Message length type.
BgwCredentials receiveBgwCredentials(SessionSettings settings, std::string host, Port port)
std::future< T > wait(Stack &stack, std::promise< T > &promise, std::chrono::seconds timeout=std::chrono::seconds{30})
Error processing client request.
New Order, cancel-replace, or cancel reject.
Heartbeat message. Sent in the absence of application messages.
Response to IPRequest for Binary Gateways.
Logon Report for Gateway ID.
Logout Report for Gateway ID.
Message identifiers and length of message root.
Report for Order Mass Cancel Request.
Response to Quote Request (RFQ).
Security Definition Reject.
Security Definition for products.
Security Definition for a strategy.
Security Definition for futures, options, and FLEX creations. Each report will contain a single marke...
Trader Logon Report for Trader ID.
auto exchangeCode() const noexcept
int32NULL.
auto text() const noexcept
Provides access to text field.
static const std::string & toString(Enum state) noexcept
@ Dedicated
Each session has a sender thread and a receiving thread.
void operator()(const MessageType msg) const
static void printMsg(const Messaging::SbeMessage msg)