OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
TradingClient.h
Go to the documentation of this file.
1/*
2* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3*
4* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5* and international copyright treaties.
6*
7* Access to and use of the software is governed by the terms of the applicable OnixS Software
8* Services Agreement (the Agreement) and Customer end user license agreements granting
9* a non-assignable, non-transferable and non-exclusive license to use the software
10* for it's own data processing purposes under the terms defined in the Agreement.
11*
12* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13* of this source code or associated reference material to any other location for further reproduction
14* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15*
16* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17* the terms of the Agreement is a violation of copyright law.
18*/
19#pragma once
20
22
23#include "Settings.h"
24#include "CUI.h"
25#include "Order.h"
26#include "Book.h"
27#include "Utils.h"
28
29namespace Samples {
30
34
44
46{
47public:
49 explicit TradingClient(const Settings& settings);
50
52
54 void connectBus();
55
58
60 void requestInstruments();
61
63 void listInstruments();
64
66 void lookupInstruments();
67
69 void connectBgw();
70
72 void traderLogon();
73
75 void traderLogout();
76
78 void sendOrder();
79
81 void cancelOrder();
82
84 void replaceOrder();
85
87 void sendOrderCross();
88
90 void sendMassCancel();
91
93 void showOrders();
94
96 void showActiveOrders();
97
99 void sendQuote();
100
103
105 void sendMassQuote();
106
108 void createStrategy();
109
111 void createFlex();
112
113private:
114 using SessionPtr = std::unique_ptr<Session>;
115 using OrderBook = Book;
116 using OrderId = OrderBook::BookEntryId;
117
119 const Settings& settings_;
120 const SessionSettings sessionSettings_;
121
123 OrderBook orderBook_;
124
125 BgwCredentials bgwCredentials_;
126
128 std::vector<std::shared_ptr<std::vector<uint8_t>>> instruments_;
129
131 std::vector<std::pair<Int32, Int32>> quoteSetId_;
132 Int32 getQuoteSetId(Int32 underlyingSymbol);
133
134 SessionPtr busSession_;
135 SessionPtr bgwSession_;
136
137 NewOrderRequestMsg newOrderRequest_;
138 SecurityDefinitionRequestMsg securityDefinitionRequest_;
139 CancelRequestMsg cancelRequest_;
140 CancelReplaceRequestMsg replaceRequest_;
141 NewOrderCrossRequestMsg newOrderCrossRequest_;
142 OrderMassCancelRequestMsg orderMassCancelRequest_;
143 QuoteRequestMsg quoteRequest_;
144 QuoteCancelRequestMsg quoteCancelRequest_;
145 MassQuoteRequestMsg massQuoteRequest_;
146
147 static void checkConnected(const SessionPtr& sn, const char* kind);
148
149 template<class Message>
150 static void send(const SessionPtr& sn, Message&& msg);
151
152 OptionalRef<Order> findByOrderId(OrderId id);
153
154 template <typename MsgType>
155 static void setCommonMessageFields(Order& order, MsgType&& msg);
156
157 OrderPtr newOrder(const Order* base = nullptr);
158 CrossOrderPtr newOrderCross();
159
160 #define ONIXS_ICE_TRADING_CLIENT_MSG_CALLBACK(Msg) \
161 void on##Msg(const Msg msg, Session* sn) override {CUI::Screen::traceMsg(sn->id(), msg, CUI::Screen::Direction::In);}
162
164 void onError(SessionErrorReason::Enum reason, const std::string & description, Session * sn, Messaging::SbeMessage) override;
165 void onWarning(SessionWarningReason::Enum reason, const std::string & description, Session * sn, Messaging::SbeMessage) override;
166 void onStateChange(SessionStateId::Enum newState, SessionStateId::Enum prevState, Session * sn) override;
167 void onMessageSending(char*, size_t, Session*) override;
168 void onIPReport(const Messaging::IPReport msg, Session* sn) override;
169 void onSecurityDefinitionReport(const Messaging::SecurityDefinitionReport msg, Session* sn) override;
170 void onSecurityDefinitionReport_Strategy(const Messaging::SecurityDefinitionReport_Strategy msg, Session* sn) override;
171
172 void onExecutionReport_New(const Messaging::ExecutionReport_New msg, Session* sn) override;
173 void onExecutionReport_Reject(const Messaging::ExecutionReport_Reject msg, Session* sn) override;
174 void onExecutionReport_Cancel(const Messaging::ExecutionReport_Cancel msg, Session* sn) override;
175 void onExecutionReport_Modify(const Messaging::ExecutionReport_Modify msg, Session* sn) override;
176 void onExecutionReport_Trade(const Messaging::ExecutionReport_Trade msg, Session* sn) override;
177 void onExecutionReport_Snapshot(const Messaging::ExecutionReport_Snapshot msg, Session* sn) override;
178 void onNewOrderCrossReport(const Messaging::NewOrderCrossReport msg, Session* sn) override;
182 ONIXS_ICE_TRADING_CLIENT_MSG_CALLBACK(SecurityDefinitionReport_Product);
183 ONIXS_ICE_TRADING_CLIENT_MSG_CALLBACK(TraderLogonReport);
184 ONIXS_ICE_TRADING_CLIENT_MSG_CALLBACK(TraderLogoutReport);
186 ONIXS_ICE_TRADING_CLIENT_MSG_CALLBACK(OrderMassCancelReport);
191 ONIXS_ICE_TRADING_CLIENT_MSG_CALLBACK(SecurityDefinitionReject);
192};
193
194template<class Message>
195void TradingClient::send(const SessionPtr& sn, Message&& msg)
196{
197 sn->send(std::forward<Message>(msg));
198}
199
200template <typename MsgType>
201void TradingClient::setCommonMessageFields(Order& order, MsgType&& msg)
202{
203 order.transactTime_ = getTransactTime(msg);
204 setLeavesQty(order, msg);
205}
206
207}
#define ONIXS_ICE_TRADING_CLIENT_MSG_CALLBACK(Msg)
BGW session connection credentials.
Contains the SimpleOpenFramingHeader, the SBE message, and the data buffer.
Order book.
Definition Book.h:35
Order::OrderId BookEntryId
Definition Book.h:37
void createStrategy()
Creates a strategy.
void traderLogout()
Logs the trader out from the BGW session.
TradingClient(const Settings &settings)
Initializes the client with the given settings.
void listInstruments()
Prints the list of instruments currently known to the client.
void requestBgwCredentials()
Requests BGW credentials (IpRequest) over the active BUS session.
void connectBus()
Commands.
void connectBgw()
Establishes a BGW session using previously obtained credentials.
void createFlex()
Creates a flexible instrument (flex).
void sendOrderCross()
Sends a cross order.
void sendMassCancel()
Submits a mass cancel request.
void replaceOrder()
Issues a replace for an existing live order.
void lookupInstruments()
Prints the list of instruments currently known to the client by the provided Symbol value.
void sendQuoteCancelRequest()
Cancels a previously submitted quote.
void cancelOrder()
Sends a cancel request for a specific order.
void sendOrder()
Sends a new order via BGW.
void sendMassQuote()
Sends a multiple quote request.
void showActiveOrders()
Displays active orders sent by this client session and their last-known statuses.
void showOrders()
Displays orders sent by this client session and their last-known statuses.
void sendQuote()
Sends a quote message.
void traderLogon()
Logs a trader into the connected BGW session.
void requestInstruments()
Submits a SecurityDefinitionRequest to fetch/refresh known instruments.
MessageHolder< CancelReplaceRequest > CancelReplaceRequestMsg
constexpr size_t MassQuoteRequestMaxEntriesCount
MessageHolder< OrderMassCancelRequest > OrderMassCancelRequestMsg
MessageHolder< SecurityDefinitionRequest > SecurityDefinitionRequestMsg
constexpr size_t NewOrderCrossRequestMaxEntriesCount
std::shared_ptr< CrossOrder > CrossOrderPtr
Definition Order.h:104
MessageHolder< NewOrderRequest > NewOrderRequestMsg
constexpr size_t QuoteCancelRequestMaxEntriesCount
MessageHolder< QuoteRequest > QuoteRequestMsg
std::optional< std::shared_ptr< T > > OptionalRef
Manages an optional contained reference.
Definition Utils.h:224
MessageHolder< MassQuoteRequest, getMaxMessageSize< MassQuoteRequest >(MassQuoteRequestMaxEntriesCount)> MassQuoteRequestMsg
MessageHolder< QuoteCancelRequest, getMaxMessageSize< QuoteCancelRequest >(QuoteCancelRequestMaxEntriesCount)> QuoteCancelRequestMsg
std::shared_ptr< Order > OrderPtr
Definition Order.h:75
Timestamp getTransactTime(MsgType &&msg, typename std::enable_if< hasTransactTime< MsgType >::value, void * >::type=nullptr)
Definition Utils.h:92
MessageHolder< NewOrderCrossRequest, getMaxMessageSize< NewOrderCrossRequest >(NewOrderCrossRequestMaxEntriesCount)> NewOrderCrossRequestMsg
void setLeavesQty(Order &order, MsgType &&msg, typename std::enable_if< hasLeavesQty< MsgType >::value, void * >::type=nullptr)
Definition Utils.h:128
MessageHolder< CancelRequest > CancelRequestMsg