Как добавить результат тикера в массив в poloniex, используя c ++?

когда я ссылаюсь на ticker я имею

['BTC_BBR','0.00069501','0.00074346','0.00069501','-0.00742634','8.63286802','11983.47150109',0,'0.00107920','0.00045422']

Мне нужно, чтобы каждая ячейка была записана в отдельный массив, например
Arr1.push (BTC_BBR)
Arr2.push (0,00069501)
и так далее

Как подключить библиотеку вы можете узнать по ссылке
автобан

#include <autobahn/autobahn.hpp>
#include <autobahn/wamp_websocketpp_websocket_transport.hpp>
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>
#include <boost/asio.hpp>
#include <boost/version.hpp>
#include <iostream>
#include <memory>
#include <string>
#include <tuple>typedef websocketpp::client<websocketpp::config::asio_tls_client> client;
typedef autobahn::wamp_websocketpp_websocket_transport<websocketpp::config::asio_tls_client> websocket_transport;

void on_topic1(const autobahn::wamp_event& event)
{
std::cerr << "received event: " << event.argument<uint64_t>(0) << std::endl;
}

int main(int argc, char const *argv[])
{

try {

boost::asio::io_service io;

client ws_client;
ws_client.init_asio(&io);
ws_client.set_tls_init_handler([&](websocketpp::connection_hdl) {
return websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv12_client);
});
auto transport = std::make_shared < autobahn::wamp_websocketpp_websocket_transport<websocketpp::config::asio_tls_client> >(
ws_client, "wss://api.poloniex.com:443", true);

auto session = std::make_shared<autobahn::wamp_session>(io, true);

transport->attach(std::static_pointer_cast<autobahn::wamp_transport_handler>(session));

boost::future<void> connect_future;
boost::future<void> start_future;
boost::future<void> join_future;
boost::future<void> subscribe_future;
connect_future = transport->connect().then([&](boost::future<void> connected) {
try {
connected.get();
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
io.stop();
return;
}

std::cerr << "transport connected" << std::endl;

start_future = session->start().then([&](boost::future<void> started) {
try {
started.get();
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
io.stop();
return;
}

std::cerr << "session started" << std::endl;

join_future = session->join("realm1").then([&](boost::future<uint64_t> joined) {
try {
std::cerr << "joined realm: " << joined.get() << std::endl;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
io.stop();
return;
}

subscribe_future = session->subscribe("ticker", &on_topic1).then([&] (boost::future<autobahn::wamp_subscription> subscribed)
{
try {
std::cerr << "subscribed to topic: " << subscribed.get().id() << std::endl;
std::cerr << "---------------------" << argc <<std::endl;
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
io.stop();
return;
}
});
});
});
});

std::cerr << "starting io service" << std::endl;
io.run();
std::cerr << "stopped io service" << std::endl;
}
catch (std::exception& e) {
std::cerr << "exception: " << e.what() << std::endl;
return 1;
}

return 0;
}

-2

Решение

Программисты называют эту задачу «разбор текста». Вы хотите разобрать текст в структуру (см. Комментарий @ Someprogrammerdude).

Допустим, мы хотим поместить данные в простую структуру:

struct TickerEntry {
std::string symbol;
double a, b, c, d, e, f; // I have no clue,
int i;                   // but already my names are
double x, y;             // better than Arr1 and Arr2!
};

Итак, мы хотим сделать функцию как

TickerEntry parse_ticker_entry(std::string const& input);

которые могут иметь дело с цитатами, [, ]и переводит все числа-у (положительная и отрицательная бесконечность, NaN, научная запись и т. д.) в соответствующие типы в нашей структуре.

демонстрация

Вот пример использования моего оружия: Boost Spirit, который является генератором парсера. Использование генератора синтаксических анализаторов позволяет избежать необходимости писать все утомительные проверки самостоятельно.

Жить на Колиру

#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/adapted/struct.hpp>

struct TickerEntry {
std::string symbol;
double a, b, c, d, e, f; // I have no clue,
int i;                   // but already my names are
double x, y;             // better than Arr1 and Arr2!
};

BOOST_FUSION_ADAPT_STRUCT(TickerEntry, symbol, a, b, c, d, e, f, i, x, y)

TickerEntry parse_ticker_entry(std::string const& input) {
TickerEntry result;

{
using namespace boost::spirit::qi;
using It = std::string::const_iterator;

rule<It, double()>      qdouble_ = "'" >> double_ >> "'";
rule<It, std::string()> qstring  = "'" >> *~char_("'") >> "'";

if (phrase_parse(input.begin(), input.end(),
'[' >> qstring >> ','
>> qdouble_ >> ',' >> qdouble_ >> ',' >> qdouble_ >> ',' >> qdouble_ >> ',' >> qdouble_ >> ',' >> qdouble_ >> ','
>> int_ >> ','
>> qdouble_ >> ',' >> qdouble_ >> ']' >> eoi,
space, result))
{
return result;
}
}

throw std::runtime_error("parse failed");
}

int main() {
auto ticker = parse_ticker_entry("['BTC_BBR','0.00069501','0.00074346','0.00069501','-0.00742634','8.63286802','11983.47150109',0,'0.00107920','0.00045422']");

std::cout << ticker.symbol << '\n';
std::cout << ticker.a << '\n';
std::cout << ticker.b << '\n';
std::cout << ticker.c << '\n';
std::cout << ticker.d << '\n';
std::cout << ticker.e << '\n';
std::cout << ticker.i << '\n';
std::cout << ticker.x << '\n';
std::cout << ticker.y << '\n';
}

Печать

http://coliru.stacked-crooked.com/a/7696306b81af2f24

BTC_BBR
0.00069501
0.00074346
0.00069501
-0.00742634
8.63287
0
0.0010792
0.00045422
0

Другие решения

Других решений пока нет …