示例#1
0
        public void WebSocket_Opened(object sender, EventArgs e)
        {
            if (productTypes.Count == 0)
            {
                throw new ArgumentException($"You must specify at least one {nameof(productTypes)}");
            }

            Subscribe();

            webSocketFeed.Invoke(OnWebSocketOpenAndSubscribed, sender, new WebfeedEventArgs <EventArgs>(e));
        }
示例#2
0
        public 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:
                var subscription = JsonConfig.DeserializeObject <Subscription>(json);
                webSocketFeed.Invoke(OnSubscriptionReceived, sender, new WebfeedEventArgs <Subscription>(subscription));
                break;

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

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

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

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

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

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

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

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

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#3
0
        public void WebSocket_Opened(object sender, EventArgs e)
        {
            if (productTypes.Count == 0)
            {
                throw new ArgumentException($"You must specify at least one {nameof(productTypes)}");
            }

            var channels = GetChannels();

            var timeStamp          = clock.GetTime().ToTimeStamp();
            var withAuthentication = authenticator != null;

            var json = SubscribeMessage(withAuthentication, channels, timeStamp);

            webSocketFeed.Send(json);

            webSocketFeed.Invoke(OnWebSocketOpenAndSubscribed, sender, new WebfeedEventArgs <EventArgs>(e));
        }
示例#4
0
        public void WebSocket_Opened(object sender, EventArgs e)
        {
            if (productTypes.Count == 0)
            {
                throw new ArgumentException("You must specify at least one product type");
            }

            var channels = GetChannels();

            var timeStamp = clock.GetTime().ToTimeStamp();
            var json      = JsonConfig.SerializeObject(new TickerChannel
            {
                Type       = ActionType.Subscribe,
                ProductIds = productTypes,
                Channels   = channels,
                Timestamp  = timeStamp.ToString("F0", CultureInfo.InvariantCulture),
                Key        = authenticator.ApiKey,
                Passphrase = authenticator.Passphrase,
                Signature  = authenticator.ComputeSignature(HttpMethod.Get, authenticator.UnsignedSignature, timeStamp,
                                                            "/users/self/verify")
            });

            webSocketFeed.Send(json);

            webSocketFeed.Invoke(OnWebSocketOpenAndSubscribed, sender, new WebfeedEventArgs <EventArgs>(e));
        }