| 117 | } |
| 118 | |
| 119 | cobalt::promise<void> handle_update( |
| 120 | std::list<std::string> & unconfirmed, |
| 121 | subscription_map & subs, |
| 122 | const json::object & ms, |
| 123 | websocket_type & ws) |
| 124 | { |
| 125 | |
| 126 | const auto & sym = json::value_to<std::string>(ms.at("symbol")); |
| 127 | |
| 128 | if (!unconfirmed.empty() && sym == unconfirmed.front()) |
| 129 | unconfirmed.pop_front(); |
| 130 | |
| 131 | bool has_expired = false; |
| 132 | auto r = boost::make_iterator_range(subs.equal_range(sym)); |
| 133 | for (const auto & [k, chn] : r) |
| 134 | if (auto ptr = chn.lock()) |
| 135 | co_await ptr->write(ms); |
| 136 | else |
| 137 | has_expired = true; |
| 138 | |
| 139 | if (has_expired) |
| 140 | erase_if(subs, [](const auto & p) {return p.second.expired();}); |
| 141 | |
| 142 | if (r.empty() && ms.at("event") != "unsubscribed") // |
| 143 | { |
| 144 | auto msg = json::serialize( |
| 145 | json::object{ |
| 146 | {"action", "unsubscribe"}, |
| 147 | {"channel", "ticker"}, |
| 148 | {"symbol", sym}}); |
| 149 | |
| 150 | co_await ws.async_write(asio::buffer(msg)); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | cobalt::promise<void> handle_new_subscription( |
| 155 | std::list<std::string> & unconfirmed, |
no test coverage detected