LiveThreaded::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
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 27 28 29 30 31 32
#include <chrono>
#include <databento/exceptions.hpp>
#include <databento/live.hpp>
#include <exception>
#include <vector>
using namespace databento;
std::vector<std::string> symbols = {"CL.c.0"};
auto schema = Schema::Trades;
auto stype_in = SType::Continuous;
auto client = LiveThreaded::Builder()
.SetKey("$YOUR_API_KEY")
.SetDataset("GLBX.MDP3")
.BuildThreaded();
client.Subscribe(symbols, schema, stype_in);
auto record_callback = [](const databento::Record&) {
return KeepGoing::Continue;
};
auto exc_callback = [&client, &symbols, schema,
stype_in](const std::exception& exc) {
if (dynamic_cast<const TcpError*>(&exc)) {
// Resubscribe, replaying the last 30 seconds
auto sys_time = std::chrono::system_clock::now();
client.Subscribe(symbols, schema, stype_in,
sys_time - std::chrono::seconds{30});
return LiveThreaded::ExceptionAction::Restart;
}
return LiveThreaded::ExceptionAction::Stop;
};
// Ignore metadata
client.Start({}, record_callback, exc_callback);