示例#1
0
 private void Init()
 {
     _transport.MessageReceived     += ReceiveMessage;
     _transport.DataConnected       += () => DataConnected?.Invoke();
     _transport.DataReconnected     += () => DataReconnected?.Invoke();
     _transport.DataDisconnected    += () => DataDisconnected?.Invoke();
     _transport.ControlConnected    += () => ControlConnected?.Invoke();
     _transport.ControlReconnected  += () => ControlReconnected?.Invoke();
     _transport.ControlDisconnected += () => ControlDisconnected?.Invoke();
 }
        private async void OpenDataEvents()
        {
            string prefix = SecureConnection ? "wss" : "ws";
            var    uri    = new Uri($"{prefix}://{HostName}/events/marketdata/");

            DataSocket = new WebsocketClient(uri, GetWSFactory());
            DataSocket.ReconnectTimeout      = null;
            DataSocket.IsReconnectionEnabled = true;
            DataSocket.ReconnectionHappened.Subscribe(info => {
                logger.Warn($"Reconnection happened, reason: {info.Type}, stream: data");
                System.Diagnostics.Debug.WriteLine($"Reconnection happened, type: {info.Type}, stream: data");
                DataReconnected?.Invoke();
            });
            DataSocket.DisconnectionHappened.Subscribe(info => {
                logger.Warn($"Disconnection happened, reason: {info.Type}, stream: data");
                DataDisconnected?.Invoke();
            });
            DataSocket.MessageReceived.Subscribe(msg =>
                                                 MessageReceived?.Invoke(msg.Binary));
            await DataSocket.Start();

            DataConnected?.Invoke();
        }