Autobahn распаковать сложного типа на C++

221
24 августа 2017, 21:30

Я подписываюсь на события ticker на wss://api.poloniex.com. Сервер не мой, мне просто нужно собирать информацию из него, но у меня проблема с форматом.

У меня есть это событие и не могу найти правильный тип для такого сложного случая:

RX message: event [543453838537363, 3807360795988603, {}, ["BTC_BCH", "0.18447297", "0.18447297", "0.18410001", "0.06427077", "14359.75209355", "89775.00285182", 0, "0.19500000", "0.14000001"]]

Может кто-нибудь мне помочь?

#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/version.hpp>
#include <iostream>
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include <typeinfo>
#include <sstream>

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 {
        //std::cerr << "Connecting to realm: " << parameters->realm() << std::endl;
        boost::asio::io_service io;
        //bool debug = parameters->debug();
        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);
        // create a WAMP session that talks WAMP-RawSocket over TCP
        auto session = std::make_shared<autobahn::wamp_session>(io, true);
        transport->attach(std::static_pointer_cast<autobahn::wamp_transport_handler>(session));
        // Make sure the continuation futures we use do not run out of scope prematurely.
        // Since we are only using one thread here this can cause the io service to block
        // as a future generated by a continuation will block waiting for its promise to be
        // fulfilled when it goes out of scope. This would prevent the session from receiving
        // responses from the router.
        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;
                        }
                        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;
        //ret_var.successfully_ran = false;
        return 1;
    }

    return 0;
}
READ ALSO
Progress Bar из картинок

Progress Bar из картинок

Есть макет с progressbar´омСтоит он из 1

212
Не выдает &ldquo;alert&rdquo; при отправке формы?

Не выдает “alert” при отправке формы?

В общем не могу понять почему alert не выдает когда форма не заполненна?

302