Skip to content

Commit e4951c6

Browse files
committed
reverted example delete
1 parent b9079c6 commit e4951c6

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

examples/custom_ws_stream.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "../include/Binance_Client.h"
2+
#include <thread>
3+
#include <iostream>
4+
5+
struct SomeFunctor
6+
{
7+
Json::CharReaderBuilder charbuilder;
8+
Json::CharReader* charreader;
9+
std::string parse_errors;
10+
std::string msg_buffer;
11+
Json::Value stream_msg;
12+
13+
SomeFunctor()
14+
: msg_buffer{ "" }, parse_errors{ }, charreader{ charbuilder.newCharReader() }
15+
{}
16+
17+
18+
SomeFunctor operator()(const std::string& response)
19+
{
20+
this->stream_msg.clear();
21+
this->parse_errors.clear();
22+
23+
this->charreader->parse(response.c_str(),
24+
response.c_str() + response.size(),
25+
&this->stream_msg,
26+
&parse_errors);
27+
28+
std::cout << this->stream_msg;
29+
30+
return *this;
31+
}
32+
};
33+
34+
35+
int main()
36+
{
37+
try
38+
{
39+
SpotClient my_client{ };
40+
SomeFunctor ws_stream_read{};
41+
42+
std::string cust_stream = "btcusdt@aggTrade/ethusdt@aggTrade";
43+
std::thread t1(&SpotClient::custom_stream<SomeFunctor>, std::ref(my_client), cust_stream, std::ref(ws_stream_read.msg_buffer), std::ref(ws_stream_read), 0);
44+
45+
t1.join();
46+
}
47+
catch (ClientException& e)
48+
{
49+
std::cout << e.what();
50+
}
51+
52+
return 0;
53+
}

0 commit comments

Comments
 (0)