public Task SubscribeThrows() { var client = new DepthWebSocketClient(new Mock <IWebSocketStream>().Object); using (var cts = new CancellationTokenSource()) return(Assert.ThrowsAsync <ArgumentNullException>("symbol", () => client.StreamAsync(null, cts.Token))); }
public void Throws() { var client = new DepthWebSocketClient(); Assert.Throws <ArgumentNullException>("symbol", () => client.Subscribe((string)null)); Assert.Throws <ArgumentNullException>("symbol", () => client.Subscribe(string.Empty)); }
public void SubscribeTwiceIgnored() { var symbol = Symbol.LTC_USDT; var client = new DepthWebSocketClient(new BinanceWebSocketStream()); client.Subscribe(symbol); client.Subscribe(symbol); }
public async Task SubscribeThrows() { var client = new DepthWebSocketClient(new Mock <IWebSocketClient>().Object); await Assert.ThrowsAsync <ArgumentNullException>("symbol", () => client.SubscribeAsync(null, new CancellationToken())); await Assert.ThrowsAsync <ArgumentException>("token", () => client.SubscribeAsync(Symbol.BTC_USDT, CancellationToken.None)); }
public void Subscribe() { var client = new DepthWebSocketClient(); Assert.Empty(client.ObservedStreams); Assert.Empty(client.Stream.ProvidedStreams); client.Subscribe(Symbol.BTC_USDT); Assert.True(client.ObservedStreams.Count() == 1); Assert.True(client.Stream.ProvidedStreams.Count() == 1); }
public Task SubscribeTwiceThrows() { var symbol = Symbol.BTC_USDT; var client = new DepthWebSocketClient(new BinanceWebSocketStream()); using (var cts = new CancellationTokenSource()) { client.StreamAsync(symbol, cts.Token); return(Assert.ThrowsAsync <InvalidOperationException>(() => client.StreamAsync(symbol, cts.Token))); } }
public async Task Properties() { var symbol = Symbol.BTC_USDT; var client = new DepthWebSocketClient(new BinanceWebSocketStream()); using (var cts = new CancellationTokenSource()) { var task = client.StreamAsync(symbol, cts.Token); Assert.Equal(symbol, client.Symbol); cts.Cancel(); await task; } }
public async Task SubscribeCallback() { var symbol = Symbol.LTC_USDT; var client = new DepthWebSocketClient(new BinanceWebSocketStream()); using (var cts = new CancellationTokenSource()) { var task = client.StreamAsync(symbol, args => { // NOTE: The first event will cancel the client ...could be a while. // ReSharper disable once AccessToDisposedClosure cts.Cancel(); }, cts.Token); await task; } }
private static void ReqAndSubscribeDepth() { var client = new DepthWebSocketClient(); // Add connection open handler client.OnConnectionOpen += Client_OnConnectionOpen; void Client_OnConnectionOpen() { // Subscribe the specific topic client.Subscribe("btcusdt", "step4"); } // Add the response receive handler client.OnResponseReceived += Client_OnResponseReceived; void Client_OnResponseReceived(SubscribeDepthResponse response) { if (response != null) { if (response.tick != null) // Parse subscription data { AppLogger.Info($"WebSocket received data, topic={response.ch}"); if (response.tick.asks != null) { var asks = response.tick.asks; AppLogger.Info($"ask, count={asks.Length}"); for (int i = asks.Length - 1; i >= 0; i--) { AppLogger.Info($"[{asks[i][0]} {asks[i][1]}]"); } } if (response.tick.bids != null) { var bids = response.tick.bids; AppLogger.Info($"bids, count={bids.Length}"); for (int i = 0; i < bids.Length; i++) { AppLogger.Info($"[{bids[i][0]} {bids[i][1]}]"); } } } else if (response.data != null) // Parse request data { AppLogger.Info($"WebSocket returned data, topic={response.ch}"); if (response.data.asks != null) { var asks = response.data.asks; AppLogger.Info($"ask, count={asks.Length}"); for (int i = asks.Length - 1; i >= 0; i--) { AppLogger.Info($"[{asks[i][0]} {asks[i][1]}]"); } } if (response.data.bids != null) { var bids = response.data.bids; AppLogger.Info($"bids, count={bids.Length}"); for (int i = 0; i < bids.Length; i++) { AppLogger.Info($"[{bids[i][0]} {bids[i][1]}]"); } } } } } // Then connect to server and wait for the handler to handle the response client.Connect(); // Request full data client.Req("btcusdt", "step4"); Console.WriteLine("Press ENTER to unsubscribe and stop...\n"); Console.ReadLine(); // Unsubscrive the specific topic client.UnSubscribe("btcusdt", "step4"); // Delete handler client.OnResponseReceived -= Client_OnResponseReceived; }
public void SubscribeThrows() { var client = new DepthWebSocketClient(new Mock <IWebSocketStream>().Object); Assert.Throws <ArgumentNullException>("symbol", () => client.Subscribe(null)); }