diff --git a/IEXSharp/Service/Cloud/CoreData/Crypto/CryptoService.cs b/IEXSharp/Service/Cloud/CoreData/Crypto/CryptoService.cs index e89d8045..ffd3a9be 100644 --- a/IEXSharp/Service/Cloud/CoreData/Crypto/CryptoService.cs +++ b/IEXSharp/Service/Cloud/CoreData/Crypto/CryptoService.cs @@ -20,15 +20,18 @@ public CryptoService(ExecutorREST executor, ExecutorSSE executorSSE) public async Task> BookAsync(string symbol) => await executor.SymbolExecuteAsync("crypto/[symbol]/book", symbol); + public SSEClient SubscribeCryptoBook(IEnumerable symbols) => + executorSSE.SymbolsSubscribeSSE("cryptoBook", symbols); + + public SSEClient SubscribeCryptoEvents(IEnumerable symbols) => + executorSSE.SymbolsSubscribeSSE("cryptoEvents", symbols); + public async Task> PriceAsync(string symbol) => await executor.SymbolExecuteAsync("crypto/[symbol]/price", symbol); public async Task> QuoteAsync(string symbol) => await executor.SymbolExecuteAsync("crypto/[symbol]/quote", symbol); - public SSEClient SubscribeCryptoEvents(IEnumerable symbols) => - executorSSE.SymbolsSubscribeSSE("cryptoEvents", symbols); - public SSEClient SubscribeCryptoQuotes(IEnumerable symbols) => executorSSE.SymbolsSubscribeSSE("cryptoQuotes", symbols); } diff --git a/IEXSharp/Service/Cloud/CoreData/Crypto/ICryptoService.cs b/IEXSharp/Service/Cloud/CoreData/Crypto/ICryptoService.cs index e5660b32..ca8db2e3 100644 --- a/IEXSharp/Service/Cloud/CoreData/Crypto/ICryptoService.cs +++ b/IEXSharp/Service/Cloud/CoreData/Crypto/ICryptoService.cs @@ -14,11 +14,18 @@ public interface ICryptoService /// Task> BookAsync(string symbol); + /// + /// + /// + /// + /// + SSEClient SubscribeCryptoBook(IEnumerable symbols); + /// /// /// Only accessible with SSE Streaming. /// - /// + /// /// SSEClient SubscribeCryptoEvents(IEnumerable symbols); @@ -39,7 +46,7 @@ public interface ICryptoService /// /// /// - /// + /// /// SSEClient SubscribeCryptoQuotes(IEnumerable symbols); } diff --git a/IEXSharpTest/Cloud/CoreData/CryptoTest.cs b/IEXSharpTest/Cloud/CoreData/CryptoTest.cs index 6d95736e..89097498 100644 --- a/IEXSharpTest/Cloud/CoreData/CryptoTest.cs +++ b/IEXSharpTest/Cloud/CoreData/CryptoTest.cs @@ -32,13 +32,33 @@ public async Task BookAsyncTest(string symbol) Assert.IsNotNull(response.Data.bids.First().price); } + [Test] + [TestCase(new object[] { "BTCUSD" })] + [TestCase(new object[] { "BTCUSD", "ETHUSD" })] + public async Task SubscribeCryptoBookTest(object[] symbols) + { + using var sseClient = sandBoxClient.Crypto.SubscribeCryptoBook(symbols.Cast()); + sseClient.Error += (s, e) => + { + sseClient.Close(); + Assert.Fail("EventSource Error Occurred. Details: {0}", e.Exception.Message); + }; + sseClient.MessageReceived += (s, m) => + { + sseClient.Close(); + Assert.IsNotNull(m.First().asks); + Assert.IsNotNull(m.First().bids); + Assert.Pass(m.ToString()); + }; + await sseClient.StartAsync(); + } + [Test] [TestCase(new object[] { "btcusdt" })] [TestCase(new object[] { "btcusdt", "ethusdt" })] public async Task CryptoEventSSETest(object[] symbols) { - using var sseClient = sandBoxClient.Crypto.SubscribeCryptoEvents( - symbols.Cast()); + using var sseClient = sandBoxClient.Crypto.SubscribeCryptoEvents(symbols.Cast()); sseClient.Error += (s, e) => { sseClient.Close();