Skip to content

Commit

Permalink
Merge pull request #17 from HuobiRDCenter/feature_1_0_8
Browse files Browse the repository at this point in the history
update SubscribeMarketDepthMBP
  • Loading branch information
devin-y authored Nov 29, 2019
2 parents 1fa17b5 + 56fa479 commit 49822bd
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 79 deletions.
11 changes: 11 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define CURRENT_VERSION 1.0.7
#define CURRENT_VERSION 1.0.8
129 changes: 51 additions & 78 deletions examples/SubscribeMarketDepthMBP/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ using namespace Huobi;
using namespace std;


MarketDepthMBPEvent fullData;
list<MarketDepthMBPEvent> changes;

void subMarketDepthMBPEvent() {
Expand All @@ -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<MarketDepthMBPEvent>::iterator ite = changes.begin();
list<MarketDepthMBPEvent>::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<MarketDepthMBPEvent>::iterator ite = changes.begin();

}

vector<long> 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<Decimal, Decimal>::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<Decimal, Decimal>::iterator it = (*ite).asks.begin(); it != (*ite).asks.end(); ++it) {

for (std::map<Decimal, Decimal>::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<Decimal, Decimal>::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<Decimal, Decimal>::iterator it = fullData.asks.begin(); it != fullData.asks.end(); ++it)
cout << "ask: " << it->first << " => " << it->second << '\n';

for (map<Decimal, Decimal>::iterator it = fullData.asks.begin(); it != fullData.asks.end(); ++it)
cout << "ask: " << it->first << " => " << it->second << '\n';
for (map<Decimal, Decimal>::iterator it = fullData.bids.begin(); it != fullData.bids.end(); ++it)
cout << "bid: " << it->first << " => " << it->second << '\n';
for (map<Decimal, Decimal>::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<Decimal, Decimal>::iterator it = fullData.asks.begin(); it != fullData.asks.end(); ++it)
cout << "ask: " << it->first << " => " << it->second << '\n';
for (map<Decimal, Decimal>::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);


}



0 comments on commit 49822bd

Please sign in to comment.