public void CreateFromString_TestOnlyBids() { var rawBookupdateMessage = TestSocketMessages.BookUpdateMessageOnlyBids; var bookUpdateMessage = BookUpdateMessage.CreateFromString(rawBookupdateMessage); Assert.NotNull(bookUpdateMessage); Assert.Equal(1234, bookUpdateMessage.ChannelId); Assert.Null(bookUpdateMessage.Asks); Assert.NotNull(bookUpdateMessage.Bids); Assert.Single(bookUpdateMessage.Bids); }
public void CreateFromString_TestOnlyBids() { var rawBookupdateMessage = @"[1234,{""b"": [[""5541.30000"",""0.00000000"",""1534614335.345903""]]}]"; var bookUpdateMessage = BookUpdateMessage.CreateFromString(rawBookupdateMessage); Assert.NotNull(bookUpdateMessage); Assert.Equal(1234, bookUpdateMessage.ChannelId); Assert.Null(bookUpdateMessage.Asks); Assert.NotNull(bookUpdateMessage.Bids); Assert.Single(bookUpdateMessage.Bids); }
public void CreateFromString_TestOnlyAsks() { var rawBookupdateMessage = @"[1234,{""a"": [[""5541.30000"",""2.50700000"",""1534614248.456738""],[""5542.50000"",""0.40100000"",""1534614248.456738""]]}]"; var bookUpdateMessage = BookUpdateMessage.CreateFromString(rawBookupdateMessage); Assert.NotNull(bookUpdateMessage); Assert.Equal(1234, bookUpdateMessage.ChannelId); Assert.NotNull(bookUpdateMessage.Asks); Assert.Equal(2, bookUpdateMessage.Asks.Length); Assert.Null(bookUpdateMessage.Bids); }
public void CreateFromString_TestComplete() { var rawBookupdateMessage = TestSocketMessages.BookUpdateCompleteMessage; var bookUpdateMessage = BookUpdateMessage.CreateFromString(rawBookupdateMessage); Assert.NotNull(bookUpdateMessage); Assert.Equal(1234, bookUpdateMessage.ChannelId); Assert.NotNull(bookUpdateMessage.Asks); Assert.Equal(2, bookUpdateMessage.Asks.Length); Assert.NotNull(bookUpdateMessage.Bids); Assert.Single(bookUpdateMessage.Bids); }
public void CreateFromString_TestAsksRepublished() { var rawBookupdateMessage = TestSocketMessages.BookUpdateAsksRepublished; var bookUpdateMessage = BookUpdateMessage.CreateFromString(rawBookupdateMessage); Assert.NotNull(bookUpdateMessage); Assert.Equal(1234, bookUpdateMessage.ChannelId); Assert.NotNull(bookUpdateMessage.Asks); Assert.Equal(2, bookUpdateMessage.Asks.Length); Assert.Null(bookUpdateMessage.Bids); #endregion }
private void HandleData(KrakenMessageEventArgs eventArgs, SubscriptionStatus subscription) { var dataType = subscription.Subscription.Name; if (dataType == SubscribeOptionNames.Ticker) { var tickerMessage = TickerMessage.CreateFromString(eventArgs.RawContent, subscription); TickerReceived.InvokeAll(this, new TickerEventArgs(subscription.ChannelId.Value, subscription.Pair, tickerMessage)); } if (dataType == SubscribeOptionNames.OHLC) { var ohlcMessage = OhlcMessage.CreateFromString(eventArgs.RawContent); OhlcReceived.InvokeAll(this, new OhlcEventArgs(subscription.ChannelId.Value, subscription.Pair, ohlcMessage)); } if (dataType == SubscribeOptionNames.Trade) { var tradeMessage = TradeMessage.CreateFromString(eventArgs.RawContent); TradeReceived.InvokeAll(this, new TradeEventArgs(subscription.ChannelId.Value, subscription.Pair, tradeMessage)); } if (dataType == SubscribeOptionNames.Spread) { var spreadMessage = SpreadMessage.CreateFromString(eventArgs.RawContent); SpreadReceived.InvokeAll(this, new SpreadEventArgs(subscription.ChannelId.Value, subscription.Pair, spreadMessage)); } if (dataType == SubscribeOptionNames.Book) { if (eventArgs.RawContent.Contains(@"""as"":") && eventArgs.RawContent.Contains(@"""bs"":")) { var bookSnapshotMessage = BookSnapshotMessage.CreateFromString(eventArgs.RawContent); BookSnapshotReceived.InvokeAll(this, new KrakenDataEventArgs <BookSnapshotMessage>(eventArgs.ChannelId.Value, subscription.Pair, bookSnapshotMessage)); } if (eventArgs.RawContent.Contains(@"""a"":") || eventArgs.RawContent.Contains(@"""b"":")) { var bookUpdateMessage = BookUpdateMessage.CreateFromString(eventArgs.RawContent); BookUpdateReceived.InvokeAll(this, new KrakenDataEventArgs <BookUpdateMessage>(eventArgs.ChannelId.Value, subscription.Pair, bookUpdateMessage)); } } }
private void HandleIncomingMessage(object sender, KrakenMessageEventArgs eventArgs) { logger.LogDebug("Handling incoming '{event}' message", eventArgs.Event); switch (eventArgs.Event) { case Heartbeat.EventName: var heartbeat = serializer.Deserialize <Heartbeat>(eventArgs.RawContent); logger.LogTrace("Heartbeat received: {heartbeat}", heartbeat); HeartbeatReceived.InvokeAll(this, heartbeat); break; case SystemStatus.EventName: var systemStatus = serializer.Deserialize <SystemStatus>(eventArgs.RawContent); logger.LogTrace("System status changed: {systemStatus}", systemStatus); SystemStatus = systemStatus; SystemStatusChanged.InvokeAll(this, systemStatus); break; case SubscriptionStatus.EventName: var subscriptionStatus = serializer.Deserialize <SubscriptionStatus>(eventArgs.RawContent); logger.LogTrace("Subscription status changed: {subscriptionStatus}", subscriptionStatus); SynchronizeSubscriptions(subscriptionStatus); SubscriptionStatusChanged.InvokeAll(this, subscriptionStatus); break; case "data": var subscription = Subscriptions.ContainsKey(eventArgs.ChannelId.Value) ? Subscriptions[eventArgs.ChannelId.Value] : null; if (subscription == null) { logger.LogWarning("Didn't find a subscription for channelId {channelId}", eventArgs.ChannelId); break; } var dataType = subscription.Subscription.Name; if (dataType == SubscribeOptionNames.Ticker) { var tickerMessage = TickerMessage.CreateFromString(eventArgs.RawContent, subscription); TickerReceived.InvokeAll(this, new TickerEventArgs(subscription.ChannelId.Value, subscription.Pair, tickerMessage)); } if (dataType == SubscribeOptionNames.OHLC) { var ohlcMessage = OhlcMessage.CreateFromString(eventArgs.RawContent); OhlcReceived.InvokeAll(this, new OhlcEventArgs(subscription.ChannelId.Value, subscription.Pair, ohlcMessage)); } if (dataType == SubscribeOptionNames.Trade) { var tradeMessage = TradeMessage.CreateFromString(eventArgs.RawContent); TradeReceived.InvokeAll(this, new TradeEventArgs(subscription.ChannelId.Value, subscription.Pair, tradeMessage)); } if (dataType == SubscribeOptionNames.Spread) { var spreadMessage = SpreadMessage.CreateFromString(eventArgs.RawContent); SpreadReceived.InvokeAll(this, new SpreadEventArgs(subscription.ChannelId.Value, subscription.Pair, spreadMessage)); } if (dataType == SubscribeOptionNames.Book) { if (eventArgs.RawContent.Contains(@"""as"":") && eventArgs.RawContent.Contains(@"""bs"":")) { var bookSnapshotMessage = BookSnapshotMessage.CreateFromString(eventArgs.RawContent); BookSnapshotReceived.InvokeAll(this, new KrakenDataEventArgs <BookSnapshotMessage>(eventArgs.ChannelId.Value, subscription.Pair, bookSnapshotMessage)); } if (eventArgs.RawContent.Contains(@"""a"":") || eventArgs.RawContent.Contains(@"""b"":")) { var bookUpdateMessage = BookUpdateMessage.CreateFromString(eventArgs.RawContent); BookUpdateReceived.InvokeAll(this, new KrakenDataEventArgs <BookUpdateMessage>(eventArgs.ChannelId.Value, subscription.Pair, bookUpdateMessage)); } } break; default: logger.LogWarning("Could not handle incoming message: {message}", eventArgs.RawContent); break; } }