BetaTrader
A HFT Eco-System
Loading...
Searching...
No Matches
fix_client::FixClientSession Class Reference

High-performance asynchronous FIX client using ASIO. More...

#include <FixClientSession.h>

Inheritance diagram for fix_client::FixClientSession:
Inheritance graph
Collaboration diagram for fix_client::FixClientSession:
Collaboration graph

Public Types

using MessageCallback = std::function< void(const ParsedFixMessage &)>
 Callback type for when a fully parsed message falls out of the protocol engine.
 
using StateChangeCallback = std::function< void(FixClientState)>
 Callback type for state transitions (e.g. Disconnected -> Active).
 

Public Member Functions

 FixClientSession (asio::io_context &ioContext, const std::string &senderCompId, const std::string &targetCompId, const std::string &seqStoreDir="seq_store")
 Constructs a new FIX Client Session.
 
 ~FixClientSession ()
 
void connect (const std::string &host, short port)
 Connects to the remote FIX server asynchronously.
 
void disconnect ()
 Closes the socket and stops reading.
 
const std::string & getSenderCompId () const
 
FixClientState getState () const
 
void sendAuthRequest (const std::string &username, const std::string &password)
 Helper to send an authenticated UserRequest (35=BE)
 
void sendLogon (int heartbeatInterval=30, bool forceReset=false)
 Sends a Logon (35=A) request. Must be called after connect() is successful.
 
void sendLogout (const std::string &reason="")
 Sends a Logout (35=5) request.
 
void sendMarketDataRequest (const std::string &symbol, char subscriptionRequestType='1')
 
void sendMessage (const std::string &msgType, const std::string &bodyStr)
 Queues a raw FIX message body to be properly headed, trailed, sequenced, and sent.
 
void sendNewOrder (const std::string &symbol, char side, double price, int qty, char type='2', char tif='0')
 
void setHeartbeatInterval (int seconds)
 
void setMessageCallback (MessageCallback cb)
 
void setStateChangeCallback (StateChangeCallback cb)
 

Private Member Functions

void changeState (FixClientState newState)
 
void doRead ()
 
void doWrite (std::shared_ptr< std::string > message)
 
void handleHeartbeat (const std::string &msgStr)
 
void handleLogonResponse (const std::string &msgStr, uint32_t inSeq)
 
void handleLogoutResponse (const std::string &msgStr)
 
void handleProtocolMessage (const std::string &msgStr)
 
void handleResendRequest (const std::string &msgStr)
 
void handleSequenceReset (const std::string &msgStr)
 
void handleTestRequest (const std::string &msgStr)
 
void startHeartbeatTimer ()
 
void startTestRequestTimer ()
 

Private Attributes

int mHeartbeatInterval = 30
 
asio::steady_timer mHeartbeatTimer
 
asio::io_context & mIoContext
 
MessageCallback mMessageCb
 
std::string mReadBuffer
 
std::vector< char > mReadChunk
 
asio::ip::tcp::resolver mResolver
 
std::string mSenderCompId
 
SeqNumStore mSeqStore
 
asio::ip::tcp::socket mSocket
 
std::atomic< FixClientStatemState {FixClientState::Disconnected}
 
StateChangeCallback mStateChangeCb
 
std::string mTargetCompId
 
asio::steady_timer mTestReqTimer
 

Static Private Attributes

static constexpr size_t ChunkSize = 8192
 

Friends

class FixClientSessionTests
 

Detailed Description

High-performance asynchronous FIX client using ASIO.

Member Typedef Documentation

◆ MessageCallback

Callback type for when a fully parsed message falls out of the protocol engine.

◆ StateChangeCallback

Callback type for state transitions (e.g. Disconnected -> Active).

Constructor & Destructor Documentation

◆ FixClientSession()

fix_client::FixClientSession::FixClientSession ( asio::io_context &  ioContext,
const std::string &  senderCompId,
const std::string &  targetCompId,
const std::string &  seqStoreDir = "seq_store" 
)

Constructs a new FIX Client Session.

Parameters
ioContextThe ASIO event loop to run on.
senderCompIdThis client's identification string (e.g. "MahaSahayak").
targetCompIdThe exchange's identification string (e.g. "BETA_EXCHANGE").

◆ ~FixClientSession()

fix_client::FixClientSession::~FixClientSession ( )
Here is the call graph for this function:

Member Function Documentation

◆ changeState()

void fix_client::FixClientSession::changeState ( FixClientState  newState)
private
Here is the caller graph for this function:

◆ connect()

void fix_client::FixClientSession::connect ( const std::string &  host,
short  port 
)

Connects to the remote FIX server asynchronously.

Here is the call graph for this function:

◆ disconnect()

void fix_client::FixClientSession::disconnect ( )

Closes the socket and stops reading.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doRead()

void fix_client::FixClientSession::doRead ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ doWrite()

void fix_client::FixClientSession::doWrite ( std::shared_ptr< std::string >  message)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSenderCompId()

const std::string & fix_client::FixClientSession::getSenderCompId ( ) const
inline

◆ getState()

FixClientState fix_client::FixClientSession::getState ( ) const
inline

◆ handleHeartbeat()

void fix_client::FixClientSession::handleHeartbeat ( const std::string &  msgStr)
private
Here is the caller graph for this function:

◆ handleLogonResponse()

void fix_client::FixClientSession::handleLogonResponse ( const std::string &  msgStr,
uint32_t  inSeq 
)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleLogoutResponse()

void fix_client::FixClientSession::handleLogoutResponse ( const std::string &  msgStr)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleProtocolMessage()

void fix_client::FixClientSession::handleProtocolMessage ( const std::string &  msgStr)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleResendRequest()

void fix_client::FixClientSession::handleResendRequest ( const std::string &  msgStr)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleSequenceReset()

void fix_client::FixClientSession::handleSequenceReset ( const std::string &  msgStr)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleTestRequest()

void fix_client::FixClientSession::handleTestRequest ( const std::string &  msgStr)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendAuthRequest()

void fix_client::FixClientSession::sendAuthRequest ( const std::string &  username,
const std::string &  password 
)

Helper to send an authenticated UserRequest (35=BE)

◆ sendLogon()

void fix_client::FixClientSession::sendLogon ( int  heartbeatInterval = 30,
bool  forceReset = false 
)

Sends a Logon (35=A) request. Must be called after connect() is successful.

Parameters
heartbeatIntervalRequired heartbeat interval (default 30s).
forceResetIf true, sends ResetSeqNumFlag=Y and drops seq store to 1.
Here is the call graph for this function:

◆ sendLogout()

void fix_client::FixClientSession::sendLogout ( const std::string &  reason = "")

Sends a Logout (35=5) request.

Here is the call graph for this function:

◆ sendMarketDataRequest()

void fix_client::FixClientSession::sendMarketDataRequest ( const std::string &  symbol,
char  subscriptionRequestType = '1' 
)
Here is the call graph for this function:

◆ sendMessage()

void fix_client::FixClientSession::sendMessage ( const std::string &  msgType,
const std::string &  bodyStr 
)

Queues a raw FIX message body to be properly headed, trailed, sequenced, and sent.

Parameters
msgTypeThe Tag 35 value (e.g. "D" for new order).
bodyStrThe raw tag=value body string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendNewOrder()

void fix_client::FixClientSession::sendNewOrder ( const std::string &  symbol,
char  side,
double  price,
int  qty,
char  type = '2',
char  tif = '0' 
)
Here is the call graph for this function:

◆ setHeartbeatInterval()

void fix_client::FixClientSession::setHeartbeatInterval ( int  seconds)
inline

◆ setMessageCallback()

void fix_client::FixClientSession::setMessageCallback ( MessageCallback  cb)
inline

◆ setStateChangeCallback()

void fix_client::FixClientSession::setStateChangeCallback ( StateChangeCallback  cb)
inline

◆ startHeartbeatTimer()

void fix_client::FixClientSession::startHeartbeatTimer ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ startTestRequestTimer()

void fix_client::FixClientSession::startTestRequestTimer ( )
private

Friends And Related Symbol Documentation

◆ FixClientSessionTests

friend class FixClientSessionTests
friend

Member Data Documentation

◆ ChunkSize

constexpr size_t fix_client::FixClientSession::ChunkSize = 8192
staticconstexprprivate

◆ mHeartbeatInterval

int fix_client::FixClientSession::mHeartbeatInterval = 30
private

◆ mHeartbeatTimer

asio::steady_timer fix_client::FixClientSession::mHeartbeatTimer
private

◆ mIoContext

asio::io_context& fix_client::FixClientSession::mIoContext
private

◆ mMessageCb

MessageCallback fix_client::FixClientSession::mMessageCb
private

◆ mReadBuffer

std::string fix_client::FixClientSession::mReadBuffer
private

◆ mReadChunk

std::vector<char> fix_client::FixClientSession::mReadChunk
private

◆ mResolver

asio::ip::tcp::resolver fix_client::FixClientSession::mResolver
private

◆ mSenderCompId

std::string fix_client::FixClientSession::mSenderCompId
private

◆ mSeqStore

SeqNumStore fix_client::FixClientSession::mSeqStore
private

◆ mSocket

asio::ip::tcp::socket fix_client::FixClientSession::mSocket
private

◆ mState

std::atomic<FixClientState> fix_client::FixClientSession::mState {FixClientState::Disconnected}
private

◆ mStateChangeCb

StateChangeCallback fix_client::FixClientSession::mStateChangeCb
private

◆ mTargetCompId

std::string fix_client::FixClientSession::mTargetCompId
private

◆ mTestReqTimer

asio::steady_timer fix_client::FixClientSession::mTestReqTimer
private

The documentation for this class was generated from the following files: