Beispiel #1
0
        public void Stop()
        {
            if (webSocketFeed.State != WebSocketState.Open)
            {
                throw new GDAXSharpWebSocketException(
                          $"Websocket needs to be in the opened state. The current state is {webSocketFeed.State}")
                      {
                          WebSocketFeed = webSocketFeed,
                          StatusCode    = webSocketFeed.State,
                          ErrorEvent    = null
                      };
            }

            stopWebSocket = true;

            var json = JsonConfig.SerializeObject(new TickerChannel
            {
                Type = ActionType.Unsubscribe
            });

            webSocketFeed.Send(json);
            webSocketFeed.Close();

            Log.Information("WebSocket stopped");
        }
Beispiel #2
0
        public void Stop()
        {
            if (webSocketFeed == null)
            {
                Log.Warning("Websocket did not attempt to stop as the feed has not been started yet");
                return;
            }

            if (webSocketFeed.State != WebSocketState.Open)
            {
                throw new CoinbaseProWebSocketException(
                          $"Websocket needs to be in the opened state. The current state is {webSocketFeed.State}")
                      {
                          WebSocketFeed = webSocketFeed,
                          StatusCode    = webSocketFeed.State,
                          ErrorEvent    = null
                      };
            }

            stopWebSocket = true;

            var json = JsonConfig.SerializeObject(new TickerChannel
            {
                Type = ActionType.Unsubscribe
            });

            webSocketFeed.Send(json);
            webSocketFeed.Close();

            Log.Information("WebSocket stopped");
        }
Beispiel #3
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();
            }
        }