コード例 #1
0
        internal async Task ConnectAsync(CancellationToken cancellation)
        {
            var uri = _Client.GetFullUri($"v1/cryptos/{_Client.CryptoCode}/connect", null);

            uri = ToWebsocketUri(uri);
            WebSocket socket = null;

            try
            {
                socket = await ConnectAsyncCore(uri, cancellation);
            }
            catch (WebSocketException)            // For some reason the ErrorCode is not properly set, so we can check for error 401
            {
                if (!_Client._Auth.RefreshCache())
                {
                    throw;
                }
                socket = await ConnectAsyncCore(uri, cancellation);
            }
            JsonSerializerSettings settings = new JsonSerializerSettings();

            new Serializer(_Client.Network.NBitcoinNetwork).ConfigureSerializer(settings);
            _MessageListener = new WebsocketMessageListener(socket, settings);
        }