Skip to content

Commit

Permalink
reverted example delete
Browse files Browse the repository at this point in the history
  • Loading branch information
flashnuke committed Dec 28, 2020
1 parent b9079c6 commit e4951c6
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions examples/custom_ws_stream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "../include/Binance_Client.h"
#include <thread>
#include <iostream>

struct SomeFunctor
{
Json::CharReaderBuilder charbuilder;
Json::CharReader* charreader;
std::string parse_errors;
std::string msg_buffer;
Json::Value stream_msg;

SomeFunctor()
: msg_buffer{ "" }, parse_errors{ }, charreader{ charbuilder.newCharReader() }
{}


SomeFunctor operator()(const std::string& response)
{
this->stream_msg.clear();
this->parse_errors.clear();

this->charreader->parse(response.c_str(),
response.c_str() + response.size(),
&this->stream_msg,
&parse_errors);

std::cout << this->stream_msg;

return *this;
}
};


int main()
{
try
{
SpotClient my_client{ };
SomeFunctor ws_stream_read{};

std::string cust_stream = "btcusdt@aggTrade/ethusdt@aggTrade";
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);

t1.join();
}
catch (ClientException& e)
{
std::cout << e.what();
}

return 0;
}

0 comments on commit e4951c6

Please sign in to comment.