MFClient  1.3.0
 All Classes Functions Variables Enumerations
MFTradeDateRollOverSession.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_TRADEDATEROLLOVERSESSION_H_
29 #define _MF_TRADEDATEROLLOVERSESSION_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 <mftradedaterollover/LogonResponse.hpp>
46 #include <mftradedaterollover/Logout.hpp>
47 #include <mftradedaterollover/LogoutResponse.hpp>
48 #include <mftradedaterollover/Heartbeat.hpp>
49 #include <mftradedaterollover/TradeDateRequest.hpp>
50 #include <mftradedaterollover/TradeDateReport.hpp>
51 #include <mftradedaterollover/TradeDateType.hpp>
52 #include <mftradedaterollover/GroupSizeEncoding.hpp>
53 #include <mftradedaterollover/MessageHeader.hpp>
54 
55 #include <boost/asio.hpp>
56 #include <boost/thread/mutex.hpp>
57 #include <boost/noncopyable.hpp>
58 
60 
65 class MFTradeDateRollOverSession : private boost::noncopyable {
66  friend class MFClient;
67 
68  public:
73  void logon();
74 
81  void logout();
82 
89  void logoutResponse();
90 
96  void tradeDateRequest();
97 
101  mftradedaterollover::TradeDateRequest& createTradeDateRequest();
102 
106  uint64_t getSendingTime() const { return _inputBuffer.getSendingTime(); }
107 
108  private:
109  void sendLogonMessage();
110  void sendLogoutMessage();
111  void relogonIfNecessary();
112 
117  bool disconnect(bool reconnect = true);
118 
123  void connect();
124 
125  //-- Socket methods
126  template <typename T>
127  void write(MFProtoMsgWrapper<T>& msgWrapper) {
128  write(msgWrapper.buf());
129  }
130 
131  void write(MFProtoOutputBuffer& outputBuffer);
132 
133  void handle_connect(const boost::system::error_code& ec);
134  void handle_read(const boost::system::error_code& ec,
135  size_t bytes_transferred);
136 
137  void onTimer(TimeUtil::Timestamp now);
138  void checkForDeadConnection(TimeUtil::Timestamp now);
139  void sendHeartbeatIfNecessary(TimeUtil::Timestamp now);
140  void closeConnectionIfWaitedTooLongForServerLogoutResponse(
141  TimeUtil::Timestamp now);
142 
143  MFTradeDateRollOverSession(MFTradeDateRollOverHandler& handler, boost::asio::io_service& ios,
144  const std::string& username, const std::string& password,
145  const std::string& hostname, uint16_t port,
146  bool reconnectOnDisconenect, uint16_t heartBtInt);
147  void onStart();
148  void onStop();
149 
150  void write_internal(MFProtoOutputBuffer& outputBuffer);
151 
152  MFTradeDateRollOverHandler& _handler;
153  const uint16_t _heartBtInt;
154  boost::asio::ip::tcp::socket _socket;
155  MFProtoInputBuffer _inputBuffer;
156  mutable boost::mutex _outputBufferLock;
157  uint32_t _outputBufferPacketSeqNum;
158 
159  const std::string _username;
160  const std::string _password;
161  const std::string _hostname;
162  const uint16_t _port;
163  const bool _relogonOnDisconnect;
164  SessionState _state;
165  long _lastMessageSentTimestamp;
166  long _lastMessageRecvTimestamp;
167 };
168 
169 #endif
A wrapper to encapsulate an SBE class instance and the buffer where the message payload is actually s...
Definition: MFProtoMsgWrapper.h:17
Applications implement this interface in order to process events from a MFTradeRollOverDateSession ...
Definition: MFTradeDateRollOverHandler.h:48
void logoutResponse()
The response to a logout from the server. This should be called if a logout is received so that the c...
Definition: MFTradeDateRollOverSession.cpp:142
void tradeDateRequest()
The trade date roll over request message sent to the server. This should be called to initiate a subs...
Definition: MFTradeDateRollOverSession.cpp:148
Central class for managing sessions with MarketFactory. Create sessions using this class...
Definition: MFClient.h:83
void logout()
Initiates logout. This should be called so a clean and dirty (one where the socket closes w/o a logou...
Definition: MFTradeDateRollOverSession.cpp:127
uint64_t getSendingTime() const
Retrieve the sending time of the current frame.
Definition: MFTradeDateRollOverSession.h:106
mftradedaterollover::TradeDateRequest & createTradeDateRequest()
Creates a Trade Date Roll Over Request message
Definition: MFTradeDateRollOverSession.cpp:153
void logon()
Sends a logon message with the supplied username and password. Should only be called in the event loo...
Definition: MFTradeDateRollOverSession.cpp:108
Definition: SessionState.h:37
MFProtoOutputBuffer & buf()
Return a reference to the buffer where the object payload is stored.
Definition: MFProtoMsgWrapper.h:34
A session with MarketFactory for trading with all the venues for which a user has access...
Definition: MFTradeDateRollOverSession.h:65