Пример #1
0
        public BitfinexWebsocketClient(IBitfinexCommunicator communicator)
        {
            BfxValidations.ValidateInput(communicator, nameof(communicator));

            _communicator               = communicator;
            _channelIdToHandler[0]      = Streams.HandleAccountInfo;
            _messageReceivedSubsciption = _communicator.MessageReceived.Subscribe(HandleMessage);
        }
Пример #2
0
 private void OnStop()
 {
     _pingSubscription.Dispose();
     _client.Dispose();
     _communicator.Dispose();
     _client       = null;
     _communicator = null;
     Clear();
 }
Пример #3
0
        /// <inheritdoc />
        public BitfinexWebsocketClient(IBitfinexCommunicator communicator)
        {
            BfxValidations.ValidateInput(communicator, nameof(communicator));

            _communicator = communicator;
            _messageReceivedSubscription = _communicator.MessageReceived.Subscribe(HandleMessage);
            _configurationSubscription   = Streams.ConfigurationSubject.Subscribe(HandleConfiguration);

            _authenticatedHandler = new BitfinexAuthenticatedHandler(Streams, _channelIdToHandler);
            _publicHandler        = new BitfinexPublicHandler(Streams, _channelIdToHandler);
        }
Пример #4
0
        private async Task OnStart()
        {
            var pair = _view.Pair;

            if (string.IsNullOrWhiteSpace(pair))
            {
                pair = _defaultPair;
            }
            pair = pair.ToUpper();

            _tradeStatsComputer     = new TradeStatsComputer();
            _orderBookStatsComputer = new OrderBookStatsComputer();

            var url = BitfinexValues.ApiWebsocketUrl;

            _communicator = new BitfinexWebsocketCommunicator(url);
            _client       = new BitfinexWebsocketClient(_communicator);

            Subscribe(_client);

            _communicator.ReconnectionHappened.Subscribe(info =>
            {
                _view.Status($"Reconnected (type: {info.Type})", StatusType.Info);
                SendSubscriptions(_client, pair);
            });

            _communicator.DisconnectionHappened.Subscribe(info =>
            {
                if (info.Type == DisconnectionType.Error)
                {
                    _view.Status($"Disconnected by error, next try in {_communicator.ErrorReconnectTimeout?.TotalSeconds} sec",
                                 StatusType.Error);
                    return;
                }
                _view.Status($"Disconnected (type: {info.Type})",
                             StatusType.Warning);
            });

            await _communicator.Start();

            StartPingCheck(_client);
        }