Created
November 23, 2020 15:06
-
-
Save madmongo1/4f62a90409d6a124a63b33f3c2417d36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
net::awaitable< void > | |
monitor_subscription(async::st::stop_token stop, | |
util::printable_base const & ident, | |
entity::entity_service owner, | |
entity::universal_key const & key, | |
async::st::ready_latch_impl & ready_latch, | |
trade::snapshot_condition & condition, | |
std::function< void(json::value const &) > update) | |
try | |
{ | |
spdlog::trace("{}::{} entry", ident, __func__); | |
// premable | |
auto conn = trade::deribit_connection(owner); | |
auto to_channel = [&key] { | |
auto s = to_deribit(key); | |
return json::string(s.begin(), s.end()); | |
}; | |
auto subs = co_await conn.public_subscribe(to_channel()); | |
auto stopconn = stop.connect([&] { subs.disconnect(); }); | |
while (!stop.stopped()) | |
{ | |
auto upsnap = co_await subs.consume(); | |
spdlog::debug( | |
"{}::{} received data {}", ident, __func__, print(upsnap)); | |
try | |
{ | |
condition.reset_good(); | |
update(upsnap); | |
} | |
catch (...) | |
{ | |
spdlog::error("{}::{} error {}", ident, __func__, explain()); | |
condition.reset_error(trade::error_info(to_string(to_string(ident)), | |
to_string(explain()))); | |
} | |
ready_latch.notify_ready(); | |
} | |
spdlog::trace("{}::{} exit", ident, __func__); | |
} | |
catch (...) | |
{ | |
spdlog::error("{}::{} fatal error {}", ident, __func__, explain()); | |
condition.reset_error( | |
trade::error_info(to_string(to_string(ident)), to_string(explain()))); | |
ready_latch.notify_ready(); | |
throw; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment