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_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);
        }