예제 #1
0
        public async Task SerializeSubscribeMessageLevel2Channel()
        {
            var message = SubscribeMessage.Create(new Level2Channel
            {
                Products = new List <string> {
                    "XTZ-EUR"
                }
            });

            var json = JsonSerializer.Serialize <FeedRequestMessage>(message, SerializerOptions);

            var expected = await File.ReadAllTextAsync("TestData/subscribe_level2.json");

            json.ShouldBe(expected);
        }
예제 #2
0
        private async Task SubscribeAsync(IEnumerable <FeedChannel> channels, CancellationToken cancellationToken)
        {
            if (_apiOptions.WebsocketFeedUri == null)
            {
                throw new InvalidOperationException();
            }

            await _webSocket.ConnectAsync(_apiOptions.WebsocketFeedUri, cancellationToken);

            _log.LogInformation($"connected to {_apiOptions.WebsocketFeedUri}");

            // To begin receiving feed messages, you must first send a subscribe message to the server indicating which channels and products
            // to receive. This message is mandatory - you will be disconnected if no subscribe has been received within 5 seconds.
            var message = SubscribeMessage.Create(channels);
            var bytes   = JsonSerializer.SerializeToUtf8Bytes <FeedRequestMessage>(message, _serializerOptions);
            await _webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, cancellationToken);
        }