private async Task <bool> SubscribeToPrivateOrderUpdatesAsync(int timeoutMs, CancellationToken cancellationToken) { var tcsSubscribed = new TaskCompletionSource <string>(); _api.Subscribed += (sender, message) => { tcsSubscribed.SetResult(message); return(tcsSubscribed.Task); }; // Subscribe var skipTask = _api.SubscribeToPrivateUpdatesAsync(new[] { _btcUsd }, cancellationToken); await WhenAllTaskAreDone(timeoutMs, tcsSubscribed.Task); // Wait max n milliseconds for subscription return(tcsSubscribed.Task.IsCompletedSuccessfully); }
protected override async void StartImpl() { _webSocketCtSource = new CancellationTokenSource(); try { _orderBooksHarvester.Start(); OnConnected(); await _websocketApi.SubscribeToPrivateUpdatesAsync(Instruments.Select(i => i.Name).ToList(), _webSocketCtSource.Token); } catch (Exception ex) { await LogAsync(ex); } }