private async Task OnStartA() { //if (ZRComputer == null) // ZRComputer = new ZoneRecoveryComputer(); DateTime dt = DateTime.Now; _generalStatsHandler = new GeneralStatsHandler(dt); var pair = _defaultPair.ToUpper(); _posStatsHandler = new PositionStatsHandler(); _tradeStatsComputer = new TradeStatsComputer(); _orderBookStatsComputer = new OrderBookStatsComputer(); _orderStatsHandler = new OrdersStatsHandler(); _errorStatsHandler = new ErrorStatsHandler(); _marginStatsHandler = new MarginStatsHandler(); var url = BitmexValues.ApiWebsocketTestnetUrl; _communicatorA = new BitmexWebsocketCommunicator(url); _clientA = new BitmexWebsocketClient(_communicatorA); // Enable stream listeners Subscribe(_clientA, MTAccount.A); _communicatorA.ReconnectionHappened.Subscribe(async type => { try { ErrorStatsMutex.WaitOne(); if (type != ReconnectionType.Initial) { Log.Warning($"Reconnected A (type: {type})"); _errorStatsHandler.Add2Reconnections(1, ZoneRecoveryAccount.A); } else if (type == ReconnectionType.Error) { _errorStatsHandler.Add2ErrorCnt(1, ZoneRecoveryAccount.A); } } catch (Exception exc) { Log.Error($"_communicatorA.ReconnectionHappened: {exc.Message}"); } finally { ErrorStatsMutex.ReleaseMutex(); } _view.StatusA($"Reconnected (type: {type})", StatusType.Info); _view.ConnStartA = dt.ToString("dd-MM-yy HH:mm:ss"); await SendSubscriptions(_clientA, pair, MTAccount.A); }); _communicatorA.DisconnectionHappened.Subscribe(type => { try { ErrorStatsMutex.WaitOne(); _errorStatsHandler.Add2Disconnections(1, ZoneRecoveryAccount.A); if (type == DisconnectionType.Error) { _errorStatsHandler.Add2ErrorCnt(1, ZoneRecoveryAccount.A); _view.StatusA($"Disconnected by error, next try in {_communicatorA.ErrorReconnectTimeoutMs / 1000} sec", StatusType.Error); return; } } catch (Exception exc) { Log.Error($"_communicatorA.DisconnectionHappened: {exc.Message}"); } finally { ErrorStatsMutex.ReleaseMutex(); } _view.StatusA($"Disconnected (type: {type})", StatusType.Warning); }); await _communicatorA.Start(); StartPingCheckA(_clientA); }