Exemple #1
0
        private void HandleTickerMessage(TickerEventResponse channel, dynamic data)
        {
            if (data[1].GetType() != typeof(JArray))
            {
                return;
            }

            var raw = (data[1] as JArray).ToObject <object[]>();

            var pair = Exchange.DecodeSymbol(channel.Symbol);

            var symbol = SymbolFactory.Get(pair[0], pair[1]);

            var additionalData = new NameValueCollection();

            additionalData.Add("SymbolCode", symbol.Code.ToString());

            var result = Exchange.ChangeType <dynamic, MarketTick>(SymbolFactory, raw, null, additionalData);

            OnTickerReceived?.Invoke(this, new TickerReceivedEventArgs {
                Data = result
            });
        }
Exemple #2
0
        private void WebSocket_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            if (StopWebSocket)
            {
                WebSocketFeed.Close();
                return;
            }

            var json     = e.Message;
            var response = JsonConfig.DeserializeObject <BaseMessage>(json);

            switch (response.Type)
            {
            case ResponseType.Subscriptions:
                break;

            case ResponseType.Ticker:
                var ticker = JsonConfig.DeserializeObject <Ticker>(json);
                OnTickerReceived?.Invoke(sender, new WebfeedEventArgs <Ticker>(ticker));
                break;

            case ResponseType.Snapshot:
                var snapshot = JsonConfig.DeserializeObject <Snapshot>(json);
                OnSnapShotReceived?.Invoke(sender, new WebfeedEventArgs <Snapshot>(snapshot));
                break;

            case ResponseType.L2Update:
                var level2 = JsonConfig.DeserializeObject <Level2>(json);
                OnLevel2UpdateReceived?.Invoke(sender, new WebfeedEventArgs <Level2>(level2));
                break;

            case ResponseType.Heartbeat:
                var heartbeat = JsonConfig.DeserializeObject <Heartbeat>(json);
                OnHeartbeatReceived?.Invoke(sender, new WebfeedEventArgs <Heartbeat>(heartbeat));
                break;

            case ResponseType.Received:
                var received = JsonConfig.DeserializeObject <Received>(json);
                OnReceivedReceived?.Invoke(sender, new WebfeedEventArgs <Received>(received));
                break;

            case ResponseType.Open:
                var open = JsonConfig.DeserializeObject <Open>(json);
                OnOpenReceived?.Invoke(sender, new WebfeedEventArgs <Open>(open));
                break;

            case ResponseType.Done:
                var done = JsonConfig.DeserializeObject <Done>(json);
                OnDoneReceived?.Invoke(sender, new WebfeedEventArgs <Done>(done));
                break;

            case ResponseType.Match:
                var match = JsonConfig.DeserializeObject <Match>(json);
                OnMatchReceived?.Invoke(sender, new WebfeedEventArgs <Match>(match));
                break;

            case ResponseType.LastMatch:
                var lastMatch = JsonConfig.DeserializeObject <LastMatch>(json);
                OnLastMatchReceived?.Invoke(sender, new WebfeedEventArgs <LastMatch>(lastMatch));
                break;

            case ResponseType.Error:
                var error = JsonConfig.DeserializeObject <Error>(json);
                OnErrorReceived?.Invoke(sender, new WebfeedEventArgs <Error>(error));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }