LiveBlocking::Reconnect

Closes the current connection, and attempts to reconnect and authenticate with the gateway. Allows reestablishing the connection with the Live gateway without creating a new instance of the client.

API method
1
void Reconnect();
Example usage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <databento/exceptions.hpp>
#include <databento/live.hpp>
#include <exception>
#include <iostream>

using namespace databento;

auto client = LiveBlocking::Builder()
                  .SetKey("$YOUR_API_KEY")
                  .SetDataset("GLBX.MDP3")
                  .BuildBlocking();
client.Subscribe({"CL.c.0"}, Schema::Trades, SType::Continuous);
auto metadata = client.Start();
for (int32_t i = 0; i < 10; ++i) {
  try {
    [[maybe_unused]] auto record = client.NextRecord();
  } catch (const databento::TcpError& error) {
    std::cerr << "Caught TCP error: " << error.what()
              << "\nAttempting reconnect\n";
    client.Reconnect();
  } catch (const std::exception& exc) {
    std::cerr << "Caught unknown exception: " << exc.what()
              << "\nShutting down\n";
    client.Stop();
  }
}