MFClient  1.3.0
 All Classes Functions Variables Enumerations
MFStpBookingSession.h
1 /*
2  * Copyright (C) 2017 MarketFactory, Inc. All rights reserved.
3  * Use in source and binary forms, with or without modification, is permitted
4  * provided that the following conditions are met:
5  * 1. You may only use this software for internal evaluation and testing
6  * purposes and may not use the software for engaging
7  * in live trades, unless and until you have entered into a separate agreement
8  * with MarketFactory governing the use of
9  * MarketFactory software in a production environment.
10  * 2. You may not distribute the software (in either source or binary forms) to
11  * third parties.
12  * 3. All copies of source code must retain the above copyright notice, this
13  * list of conditions and the following disclaimer.
14  * THIS SOFTWARE IS PROVIDED BY MARKETFACTORY AND ITS LICENSORS "AS IS" AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
16  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18  * NO EVENT SHALL MARKETFACTORY OR ITS LICENSORS BE LIABLE FOR ANY DIRECT,
19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23  * LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef _MF_STPBOOKINGSESSION_H_
29 #define _MF_STPBOOKINGSESSION_H_
30 
31 #define USERNAME_LENGTH 32
32 #define PASSWORD_LENGTH 32
33 #define CLORDID_LENGTH 32
34 #define STRATEGY_PARAMETERS_LENGTH 32
35 #define CONFIRMID_LENGTH 32
36 #define EXECID_LENGTH 32
37 
38 #include <MFProto.h>
39 #include <TimeUtil.h>
40 #include <MFProtoInputBuffer.h>
41 #include <MFProtoOutputBuffer.h>
42 #include <MFProtoMsgWrapper.h>
43 #include <SessionState.h>
44 
45 #include <mfstp_booking/DecimalQtyNULL.hpp>
46 #include <mfstp_booking/Logon.hpp>
47 #include <mfstp_booking/Logout.hpp>
48 #include <mfstp_booking/LogoutResponse.hpp>
49 #include <mfstp_booking/Heartbeat.hpp>
50 #include <mfstp_booking/PriceNULL.hpp>
51 #include <mfstp_booking/SecurityDefinition.hpp>
52 #include <mfstp_booking/SecurityDefinitionRequest.hpp>
53 #include <mfstp_booking/Side.hpp>
54 #include <mfstp_booking/SubscriptionRequestType.hpp>
55 #include <mfstp_booking/TradeCaptureReportSpotForward.hpp>
56 #include <mfstp_booking/TradeCaptureReportSwap.hpp>
57 #include <mfstp_booking/Confirmation.hpp>
58 
59 #include <boost/asio.hpp>
60 #include <boost/thread/mutex.hpp>
61 #include <boost/noncopyable.hpp>
62 
64 
69 class MFStpBookingSession : private boost::noncopyable {
70  friend class MFClient;
71 
72  public:
77  void logon();
78 
85  void logout();
86 
93  void logoutResponse();
94 
99 
104 
109 
114 
119 
123  void confirmation(uint32_t msgSeqNum, const char * confirmID, const char * execID);
124 
128  uint64_t getSendingTime() const { return _inputBuffer.getSendingTime(); }
129 
130  //----------------------------------------------------------------------------------------------------
131  // StpBooking
132 
133  private:
134  void sendLogonMessage();
135  void sendLogoutMessage();
136  void relogonIfNecessary();
137 
142  bool disconnect(bool reconnect = true);
143 
148  void connect();
149 
150  //-- Socket methods
151  template <typename T>
152  void write(MFProtoMsgWrapper<T>& msgWrapper) {
153  write(msgWrapper.buf());
154  }
155 
156  void write(MFProtoOutputBuffer& outputBuffer);
157 
158  void handle_connect(const boost::system::error_code& ec);
159  void handle_read(const boost::system::error_code& ec,
160  size_t bytes_transferred);
161 
162  void onTimer(TimeUtil::Timestamp now);
163  void checkForDeadConnection(TimeUtil::Timestamp now);
164  void sendHeartbeatIfNecessary(TimeUtil::Timestamp now);
165  void closeConnectionIfWaitedTooLongForServerLogoutResponse(
166  TimeUtil::Timestamp now);
167 
168  MFStpBookingSession(MFStpBookingHandler& handler, boost::asio::io_service& ios,
169  const std::string& username, const std::string& password,
170  const std::string& hostname, uint16_t port,
171  bool reconnectOnDisconenect, uint16_t heartBtInt);
172 
173  void onStart();
174  void onStop();
175 
176  void write_internal(MFProtoOutputBuffer& outputBuffer);
177 
178  MFStpBookingHandler& _handler;
179  const uint16_t _heartBtInt;
180  boost::asio::ip::tcp::socket _socket;
181  MFProtoInputBuffer _inputBuffer;
182  mutable boost::mutex _outputBufferLock;
183  uint32_t _outputBufferPacketSeqNum;
184 
185  const std::string _username;
186  const std::string _password;
187  const std::string _hostname;
188  const uint16_t _port;
189  const bool _relogonOnDisconnect;
190  SessionState _state;
191  long _lastMessageSentTimestamp;
192  long _lastMessageRecvTimestamp;
193 };
194 
195 #endif
Applications implement this interface in order to process events from a MFStpBookingSession ...
Definition: MFStpBookingHandler.h:51
MFProtoMsgWrapper< mfstp_booking::TradeCaptureReportSwap > & tradeCaptureReportSwap(int numPartyIDs)
Trade Capture Report Swap
Definition: MFStpBookingSession.cpp:172
void tradeCaptureReportSwapSend()
Trade Capture Report Swap Send
Definition: MFStpBookingSession.cpp:179
void logon()
Sends a logon message with the supplied username and password. Should only be called in the event loo...
Definition: MFStpBookingSession.cpp:111
void logout()
Initiates logout. This should be called so a clean and dirty (one where the socket closes w/o a logou...
Definition: MFStpBookingSession.cpp:130
Central class for managing sessions with MarketFactory. Create sessions using this class...
Definition: MFClient.h:83
uint64_t getSendingTime() const
Retrieve the sending time of the current frame.
Definition: MFStpBookingSession.h:128
void logoutResponse()
The response to a logout from the server. This should be called if a logout is received so that the c...
Definition: MFStpBookingSession.cpp:145
A session with MarketFactory for trading with all the venues for which a user has access...
Definition: MFStpBookingSession.h:69
void tradeCaptureReportSpotForwardSend()
Trade Capture Report Spot Forward Send
Definition: MFStpBookingSession.cpp:164
void confirmation(uint32_t msgSeqNum, const char *confirmID, const char *execID)
Trade booking confirmation message.
Definition: MFStpBookingSession.cpp:187
MFProtoMsgWrapper< mfstp_booking::TradeCaptureReportSpotForward > & tradeCaptureReportSpotForward(int numPartyIDs)
Trade Capture Reort Spot Forward
Definition: MFStpBookingSession.cpp:158
Definition: SessionState.h:37
void securityDefinitionRequest()
A request to receive the definitions of each market.
Definition: MFStpBookingSession.cpp:150
MFProtoOutputBuffer & buf()
Return a reference to the buffer where the object payload is stored.
Definition: MFProtoMsgWrapper.h:34