1515#include < quickfix/fix44/MarketDataRequest.h>
1616#include < quickfix/fix44/MarketDataSnapshotFullRefresh.h>
1717#include < quickfix/fix44/MarketDataIncrementalRefresh.h>
18+ #include " spdlog/spdlog.h"
1819
1920namespace Binance {
2021
@@ -45,24 +46,26 @@ std::string replaceSoh(const std::string& input) {
4546}
4647
4748void FixApp::onCreate (const FIX ::SessionID& sessionId) {
48- std::cout << std::format (" Session created, id [{}]" , sessionId.toString ()) << std::endl ;
49+ spdlog::info ( std::format (" Session created, id [{}]" , sessionId.toString ())) ;
4950};
5051void FixApp::onLogon (const FIX ::SessionID& sessionId) {
51- std::cout << std::format (" Session logon, id [{}]" , sessionId.toString ()) << std::endl;
52+ spdlog::info (std::format (" Session logon, id [{}]" , sessionId.toString ()));
53+
5254 subscribeToDepth (sessionId);
5355};
5456void FixApp::onLogout (const FIX ::SessionID& sessionId) {
55- std::cout << std::format (" Session logout, id [{}]" , sessionId.toString ()) << std::endl;
57+ spdlog::info (std::format (" Session logout, id [{}]" , sessionId.toString ()));
58+
5659};
5760void FixApp::toAdmin (FIX ::Message& msg, const FIX ::SessionID& sessionId) {
5861 const FIX ::Header& header = msg.getHeader ();
5962 FIX ::MsgType msgType;
6063 header.getField (msgType);
61- std::cout << std::format (" toAdmin, session Id [{}], type [{}], message [{}]" ,
62- sessionId.toString (), msgType.getString (), replaceSoh (msg.toString ())) << std::endl ;
64+ spdlog::info ( std::format (" toAdmin, session Id [{}], type [{}], message [{}]" ,
65+ sessionId.toString (), msgType.getString (), replaceSoh (msg.toString ()))) ;
6366
6467 if (msgType == FIX ::MsgType_Logon) {
65- std::cout << std::format (" authenticating" ) << std::endl ;
68+ spdlog::info ( std::format (" authenticating" )) ;
6669
6770 // collect required fields
6871 const std::string sender = header.getField (FIX ::FIELD ::SenderCompID);
@@ -92,20 +95,20 @@ void FixApp::toApp(FIX::Message& msg, const FIX::SessionID& sessionId) noexcept(
9295 const FIX ::Header& header = msg.getHeader ();
9396 FIX ::MsgType msgType;
9497 header.getField (msgType);
95- // std::cout << std::format("toApp, session Id [{}], type [{}], message [{}]",
96- // sessionId.toString(), msgType.getString(), replaceSoh(msg.toString())) << std::endl ;
98+ spdlog::debug ( std::format (" toApp, session Id [{}], type [{}], message [{}]" ,
99+ sessionId.toString (), msgType.getString (), replaceSoh (msg.toString ()))) ;
97100};
98101void FixApp::fromAdmin (const FIX ::Message& msg, const FIX ::SessionID& sessionId) noexcept (false ) {
99102 const FIX ::Header& header = msg.getHeader ();
100103 FIX ::MsgType msgType;
101104 header.getField (msgType);
102- // std::cout << std::format("fromAdmin, session Id [{}], type [{}], message [{}]",
103- // sessionId.toString(), msgType.getString(), replaceSoh(msg.toString())) << std::endl ;
105+ spdlog::debug ( std::format (" fromAdmin, session Id [{}], type [{}], message [{}]" ,
106+ sessionId.toString (), msgType.getString (), replaceSoh (msg.toString ()))) ;
104107};
105108void FixApp::fromApp (const FIX ::Message& msg, const FIX ::SessionID& sessionId) noexcept (false ) {
106109 FIX::MessageCracker::crack (msg, sessionId);
107- // std::cout << std::format("fromApp, session Id [{}], message [{}]",
108- // sessionId.toString(), replaceSoh(msg.toString())) << std::endl ;
110+ spdlog::trace ( std::format (" fromApp, session Id [{}], message [{}]" ,
111+ sessionId.toString (), replaceSoh (msg.toString ()))) ;
109112}
110113
111114void FixApp::onMessage (const FIX44 ::MarketDataSnapshotFullRefresh& m, const FIX ::SessionID& sessionID) {
@@ -120,17 +123,16 @@ void FixApp::onMessage(const FIX44::MarketDataIncrementalRefresh& m, const FIX::
120123
121124// PUBLIC
122125
123- FixApp::FixApp (std::string apiKey, std::string privatePemPath) {
124- apiKey_ = std::move (apiKey);
125- privatePemPath_ = std::move (privatePemPath);
126-
126+ FixApp::FixApp (const std::string& apiKey, const std::string& privatePemPath, const std::vector<std::string>& instruments) :
127+ // TODO: should I use references here?
128+ apiKey_ (apiKey), privatePemPath_ (privatePemPath), symbols_(instruments)
129+ {
127130 if (sodium_init () < 0 )
128131 throw std::runtime_error (" libsodium failed to initialize" );
129132}
130133
131134void FixApp::subscribeToDepth (const FIX ::SessionID& sessionId) {
132- std::cout << std::format (" Subscribe to depth" ) << std::endl;
133-
135+ spdlog::debug (std::format (" Subscribe to depth" ));
134136 FIX44 ::MarketDataRequest marketDataRequest;
135137
136138 // Generate a unique request ID for this session's request
@@ -142,7 +144,8 @@ void FixApp::subscribeToDepth(const FIX::SessionID& sessionId) {
142144 FIX ::SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES));
143145
144146 // Set market depth
145- marketDataRequest.set (FIX::MarketDepth (15 )); // 1 = Top of book
147+ constexpr int BINANCE_MAX_DEPTH = 5000 ;
148+ marketDataRequest.set (FIX::MarketDepth (BINANCE_MAX_DEPTH ));
146149
147150 // Create NoMDEntryTypes group for requesting BID and OFFER
148151 FIX44 ::MarketDataRequest::NoMDEntryTypes entryTypeGroup;
@@ -153,10 +156,12 @@ void FixApp::subscribeToDepth(const FIX::SessionID& sessionId) {
153156 entryTypeGroup.set (FIX::MDEntryType (FIX ::MDEntryType_OFFER));
154157 marketDataRequest.addGroup (entryTypeGroup);
155158
156- // Add symbol
157- FIX44 ::MarketDataRequest::NoRelatedSym symbolGroup;
158- symbolGroup.set (FIX::Symbol (" BTCUSDT" ));
159- marketDataRequest.addGroup (symbolGroup);
159+ // Add symbols
160+ for (const auto & instrument : symbols_) {
161+ FIX44 ::MarketDataRequest::NoRelatedSym symbolGroup;
162+ symbolGroup.set (FIX::Symbol (instrument));
163+ marketDataRequest.addGroup (symbolGroup);
164+ }
160165
161166 // Send the request to the corresponding market data session
162167 FIX::Session::sendToTarget (marketDataRequest, sessionId);
0 commit comments