From 56fa4795022ecf0777399b51cdd50e35cefa63a8 Mon Sep 17 00:00:00 2001 From: devin-y Date: Fri, 29 Nov 2019 11:15:49 +0800 Subject: [PATCH] update SubscribeMarketDepthMBP --- CHANGE_LOG.md | 11 ++ README.md | 2 + config.h | 2 +- examples/SubscribeMarketDepthMBP/main.cpp | 129 +++++++++------------- 4 files changed, 65 insertions(+), 79 deletions(-) diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index d94a648..d0965fc 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -16,6 +16,8 @@ The SDK supports both synchronous RESTful API invoking, and subscribe the market ## Table of Contents +- [Huobi Global API C++ SDK version 1.0.8](#Huobi-Global-API-c++-SDK-version-1.0.8) + - [Huobi Global API C++ SDK version 1.0.7](#Huobi-Global-API-c++-SDK-version-1.0.7) - [Huobi Global API C++ SDK version 1.0.6](#Huobi-Global-API-c++-SDK-version-1.0.6) @@ -30,6 +32,15 @@ The SDK supports both synchronous RESTful API invoking, and subscribe the market - [Huobi Global API C++ SDK version 1.0.1](#Huobi-Global-API-c++-SDK-version-1.0.1) +## Huobi Global API Cpp SDK version 1.0.8 + +[***version 1.0.8***](https://github.com/HuobiRDCenter/huobi_Cpp/releases) +***2019-11-29*** + +- update example demo, fix 1.0.7 bug + ``` + SubscribeMarketDepthMBP + ``` ## Huobi Global API Cpp SDK version 1.0.7 diff --git a/README.md b/README.md index 3c8efe6..fcc03f1 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ The SDK supports both synchronous RESTful API invoking, and subscribe the market ## Huobi C++ SDK Download +- [Huobi Global API C++ SDK version 1.0.8](https://github.com/HuobiRDCenter/huobi_Cpp/releases/tag/1.0.8) + - [Huobi Global API C++ SDK version 1.0.7](https://github.com/HuobiRDCenter/huobi_Cpp/releases/tag/1.0.7) - [Huobi Global API C++ SDK version 1.0.6](https://github.com/HuobiRDCenter/huobi_Cpp/releases/tag/1.0.6) diff --git a/config.h b/config.h index a65fb7a..ad59ade 100644 --- a/config.h +++ b/config.h @@ -1 +1 @@ -#define CURRENT_VERSION 1.0.7 +#define CURRENT_VERSION 1.0.8 diff --git a/examples/SubscribeMarketDepthMBP/main.cpp b/examples/SubscribeMarketDepthMBP/main.cpp index 825a71f..af77fa7 100644 --- a/examples/SubscribeMarketDepthMBP/main.cpp +++ b/examples/SubscribeMarketDepthMBP/main.cpp @@ -19,7 +19,6 @@ using namespace Huobi; using namespace std; -MarketDepthMBPEvent fullData; list changes; void subMarketDepthMBPEvent() { @@ -29,114 +28,88 @@ void subMarketDepthMBPEvent() { changes.push_back(event); }); client->startService(); - } -void fun() { +MarketDepthMBPEvent fullData; - while (!changes.size()) { +void reqData() { + WsRequestClient* client = createWsRequestClient(); + client->requestMarketDepthMBPEvent("btcusdt", MBPLevel::LEVEL150, [](MarketDepthMBPEvent event) { + fullData = event; + }); +} - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } +int main(int argc, char** argv) { - list::iterator ite = changes.begin(); - list::iterator eraseIte = changes.begin(); - int i = 0; - while (1) { + // Simple demo for using incremental push to get full data. You should transform the demo yourself. - if ((*ite).prevSeqNum == fullData.seqNum) { - while (eraseIte != ite) { - eraseIte = changes.erase(eraseIte); - } - break; - } - ite++; - i++; - if (i == 20 || ite == changes.end()) { - i = 0; - ite = changes.begin(); - } + std::thread t1(subMarketDepthMBPEvent); + t1.detach(); + + reqData(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + list::iterator ite = changes.begin(); - } - vector nums; while (1) { - while (!changes.size()) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } + if (fullData.seqNum > (*ite).prevSeqNum) { + while (ite == --changes.end()) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + ite++; + changes.pop_front(); + } else if (fullData.seqNum == (*ite).prevSeqNum) { - for (std::map::iterator it = (*ite).asks.begin(); it != (*ite).asks.end(); ++it) { + fullData.seqNum = (*ite).seqNum; + fullData.prevSeqNum = (*ite).prevSeqNum; - if (it->second == Decimal("0.0") || it->second == Decimal("0E-18")) - fullData.asks.erase(it->first); - else - fullData.asks[it->first] = it->second; - } + for (std::map::iterator it = (*ite).asks.begin(); it != (*ite).asks.end(); ++it) { - for (std::map::iterator it = (*ite).bids.begin(); it != (*ite).bids.end(); ++it) { + if (it->second == Decimal("0.0") || it->second == Decimal("0E-18")) + fullData.asks.erase(it->first); + else + fullData.asks[it->first] = it->second; + } - if (it->second == Decimal("0.0") || it->second == Decimal("0E-18")) - fullData.bids.erase(it->first); - else - fullData.bids[it->first] = it->second; + for (std::map::iterator it = (*ite).bids.begin(); it != (*ite).bids.end(); ++it) { - } + if (it->second == Decimal("0.0") || it->second == Decimal("0E-18")) + fullData.bids.erase(it->first); + else + fullData.bids[it->first] = it->second; + } + while (ite == --changes.end()) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + ite++; + changes.pop_front(); - // the full data - - fullData.seqNum = (*ite).seqNum; - fullData.prevSeqNum = (*ite).prevSeqNum; + // the full data + + cout << "prevSeqNum: " << fullData.prevSeqNum << endl; + cout << "seqNum: " << fullData.seqNum << endl; - cout << "prevSeqNum: " << fullData.prevSeqNum << endl; - cout << "seqNum: " << fullData.seqNum << endl; + for (map::iterator it = fullData.asks.begin(); it != fullData.asks.end(); ++it) + cout << "ask: " << it->first << " => " << it->second << '\n'; - for (map::iterator it = fullData.asks.begin(); it != fullData.asks.end(); ++it) - cout << "ask: " << it->first << " => " << it->second << '\n'; - for (map::iterator it = fullData.bids.begin(); it != fullData.bids.end(); ++it) - cout << "bid: " << it->first << " => " << it->second << '\n'; + for (map::iterator it = fullData.bids.begin(); it != fullData.bids.end(); ++it) + cout << "bid: " << it->first << " => " << it->second << '\n'; - ite++; - while (ite == changes.end()) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } else { + reqData(); } - } } -int main(int argc, char** argv) { - // Simple demo for using incremental push to get full data. You should transform the demo yourself. - - - std::thread t1(subMarketDepthMBPEvent); - t1.detach(); - WsRequestClient* client = createWsRequestClient(); - client->requestMarketDepthMBPEvent("btcusdt", MBPLevel::LEVEL150, [](MarketDepthMBPEvent event) { - - fullData = event; - for (map::iterator it = fullData.asks.begin(); it != fullData.asks.end(); ++it) - cout << "ask: " << it->first << " => " << it->second << '\n'; - for (map::iterator it = fullData.bids.begin(); it != fullData.bids.end(); ++it) - cout << "bid: " << it->first << " => " << it->second << '\n'; - - }); - - - std::thread t(fun); - t.detach(); - - while (1); - - -}