public async Task PullRequest_ResponseMessageReceived() { // Arrange using var client = HuobiWebsocketClientsFactory.CreateMarketClient(HuobiConstants.ApiWebsocketUrl); var request = new MarketCandlestickPullRequest("req1", "btcusdt", MarketCandlestickPeriodType.SixtyMinutes); MarketCandlestickPullResponse?response = null; var receivedEvent = new ManualResetEvent(false); client.Streams.CandlestickPullStream.Subscribe( message => { response = message; receivedEvent.Set(); }); await client.Start(); // Act client.Send(request); // Assert receivedEvent.WaitOne(TimeSpan.FromSeconds(30)); Assert.NotNull(response); }
private static (ITradeSource, IWebsocketClient) GetHuobi(string pair) { var config = new HuobiMarketWebsocketClientConfig { Url = HuobiConstants.ApiWebsocketUrl, CommunicatorName = "Huobi" }; var loggerFactory = new LoggerFactory().AddSerilog(Log.Logger); var client = HuobiWebsocketClientsFactory.CreateMarketClient(config, loggerFactory); var source = new HuobiTradeSource(client); client.Communicator.ReconnectionHappened.Subscribe( x => { var subscribeRequest = new MarketTradeDetailSubscribeRequest("id1", pair); client.Send(subscribeRequest); }); return(source, client.Communicator); }
public async Task ConnectionEstablished_PingMessageReceived() { // Arrange using var client = HuobiWebsocketClientsFactory.CreateMarketClient(HuobiConstants.ApiWebsocketUrl); PingRequest?receivedPingMessage = null; var receivedEvent = new ManualResetEvent(false); client.Streams.PingMessageStream.Subscribe( message => { receivedPingMessage = message; receivedEvent.Set(); }); // Act await client.Start(); // Assert receivedEvent.WaitOne(TimeSpan.FromSeconds(30)); Assert.NotNull(receivedPingMessage); }