X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11concurrency-benchmarks.git;a=blobdiff_plain;f=gdax-orderbook-hpp%2Fgdax-orderbook.hpp;h=c3e59ebc5d9311fd067cb996cefd58978a7c207a;hp=5d8ab8e22370260c422942850d74a07f01bb1acc;hb=refs%2Fheads%2Fmaster;hpb=32d8f54aacadd68443a71559a4f01e4533d2213f diff --git a/gdax-orderbook-hpp/gdax-orderbook.hpp b/gdax-orderbook-hpp/gdax-orderbook.hpp index 5d8ab8e..c3e59eb 100644 --- a/gdax-orderbook-hpp/gdax-orderbook.hpp +++ b/gdax-orderbook-hpp/gdax-orderbook.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -15,6 +16,7 @@ #include #include #include +#define FILENAME "example90.txt" /** * A copy of the GDAX order book for the currency pair product given during @@ -53,7 +55,8 @@ public: if (cds::threading::Manager::isThreadAttached() == false) cds::threading::Manager::attachThread(); } - + //std::ofstream myfile; + std::ifstream myfile; GDAXOrderBook(std::string const& product = "BTC-USD") : m_cdsGarbageCollector(67*2), // per SkipListMap doc, 67 hazard pointers per instance @@ -67,6 +70,8 @@ public: ensureThreadAttached(); m_bookInitialized.get_future().wait(); } + + using Price = unsigned int; // cents using Size = double; @@ -83,7 +88,7 @@ public: bids_map_t bids; offers_map_t offers; - ~GDAXOrderBook() { m_client.stop(); } + ~GDAXOrderBook() { m_client.stop(); myfile.close(); } private: struct websocketppConfig @@ -125,6 +130,8 @@ private: m_client.init_asio(); + + m_client.set_tls_init_handler( [](websocketpp::connection_hdl) { @@ -167,7 +174,16 @@ private: [this, &json] (websocketpp::connection_hdl, websocketppConfig::message_type::ptr msg) { - json.Parse(msg->get_payload().c_str()); + + /*if(!myfile.is_open()) + myfile.open(FILENAME); + if(myfile.is_open()) + { + myfile <get_payload().c_str()<get_payload().c_str()); const char *const type = json["type"].GetString(); if ( strcmp(type, "l2update") == 0 ) { @@ -180,18 +196,41 @@ private: }); websocketpp::lib::error_code errorCode; - auto connection = + + + if(!myfile.is_open()) + myfile.open(FILENAME); + std::string line; + while ( std::getline(myfile,line) ) + { + json.Parse(line.c_str()); + const char *const type = json["type"].GetString(); + if ( strcmp(type, "l2update") == 0 ) + { + processUpdates(json, bids, offers); + } + else if ( strcmp(type, "snapshot") == 0 ) + { + processSnapshot(json, bids, offers, m_bookInitialized); + } + } + + /* auto connection = m_client.get_connection("wss://ws-feed.gdax.com", errorCode); if (errorCode) { std::cerr << "failed websocketclient_t::get_connection(): " << errorCode.message() << std::endl; } - + m_client.connect(connection); - m_client.run(); + m_client.run();*/ + } catch (websocketpp::exception const & e) { std::cerr << "handleUpdates() failed: " << e.what() << std::endl; + + + } }