private static async Task<ICryptoOrderBook> StartCoinbase(string pair, bool optimized, bool l2Optimized) { var url = CoinbaseValues.ApiWebsocketUrl; var communicator = new CoinbaseWebsocketCommunicator(url) { Name = "Coinbase" }; var client = new CoinbaseWebsocketClient(communicator); var source = new CoinbaseOrderBookSource(client); var orderBook = l2Optimized ? new CryptoOrderBookL2(pair, source) : (ICryptoOrderBook)new CryptoOrderBook(pair, source); if (optimized) { ConfigureOptimized(source, orderBook); } _ = communicator.Start(); // Send subscription request to order book data client.Send(new SubscribeRequest( new[] { pair }, ChannelSubscriptionType.Level2 )); return orderBook; }
public async Task Heartbeat() { var url = CoinbaseValues.ApiWebsocketUrl; using (var communicator = new CoinbaseWebsocketCommunicator(url)) { HeartbeatResponse received = null; var receivedEvent = new ManualResetEvent(false); using (var client = new CoinbaseWebsocketClient(communicator)) { client.Streams.HeartbeatStream.Subscribe(pong => { received = pong; receivedEvent.Set(); }); await communicator.Start(); client.Send(new SubscribeRequest(new [] { "BTC-EUR" }, ChannelSubscriptionType.Heartbeat)); receivedEvent.WaitOne(TimeSpan.FromSeconds(30)); Assert.NotNull(received); } } }
public async Task ConnectToSource_ShouldHandleOrderBookCorrectly() { var url = CoinbaseValues.ApiWebsocketUrl; using (var communicator = new CoinbaseWebsocketCommunicator(url)) { using (var client = new CoinbaseWebsocketClient(communicator)) { var pair = "BTC-USD"; var source = new CoinbaseOrderBookSource(client); var orderBook = new CryptoOrderBook(pair, source); await communicator.Start(); client.Send(new SubscribeRequest( new [] { pair }, ChannelSubscriptionType.Level2 )); await Task.Delay(TimeSpan.FromSeconds(5)); Assert.True(orderBook.BidPrice > 0); Assert.True(orderBook.AskPrice > 0); Assert.NotEmpty(orderBook.BidLevels); Assert.NotEmpty(orderBook.AskLevels); } } }
private static async Task SendSubscriptionRequestsAuthenticated(CoinbaseWebsocketClient client) { //create an authenticator with your apiKey, apiSecret and passphrase var authenticator = new CoinbaseAuthentication(API_KEY, API_SECRET, API_PASSPHRASE); var subscription = new SubscribeRequest( new[] { "BTC-EUR", "BTC-USD" }, new[] { ChannelSubscriptionType.Heartbeat, ChannelSubscriptionType.Ticker, ChannelSubscriptionType.Matches, ChannelSubscriptionType.Heartbeat, ChannelSubscriptionType.User, ChannelSubscriptionType.Level2, //ChannelSubscriptionType.Status }, authenticator); client.Send(subscription); }
private static async Task SendSubscriptionRequests(CoinbaseWebsocketClient client) { var subscription = new SubscribeRequest { ProductIds = new[] { "BTC-EUR", "BTC-USD" }, Channels = new[] { //ChannelSubscriptionType.Heartbeat, ChannelSubscriptionType.Ticker, ChannelSubscriptionType.Matches, //ChannelSubscriptionType.Level2 } }; client.Send(subscription); }
private static void SendSubscriptionRequests(CoinbaseWebsocketClient client) { var subscription = new SubscribeRequest( new[] { "BTC-EUR", "BTC-USD" }, new[] { ChannelSubscriptionType.Heartbeat, // ChannelSubscriptionType.Ticker, // ChannelSubscriptionType.Matches, // ChannelSubscriptionType.User, ChannelSubscriptionType.Level2, // ChannelSubscriptionType.Status }); client.Send(subscription); }
private static (ITradeSource, IWebsocketClient) GetCoinbase(string pair) { var url = CoinbaseValues.ApiWebsocketUrl; var communicator = new CoinbaseWebsocketCommunicator(url) { Name = "Coinbase" }; var client = new CoinbaseWebsocketClient(communicator); var source = new CoinbaseTradeSource(client); communicator.ReconnectionHappened.Subscribe(x => { client.Send(new SubscribeRequest( new[] { pair }, ChannelSubscriptionType.Matches )); }); return(source, communicator); }