Exemplo n.º 1
0
        /// <summary>
        /// Listen to the User Data endpoint.
        /// </summary>
        /// <param name="accountInfoHandler">Handler to be used when a account message is received.</param>
        /// <param name="tradesHandler">Handler to be used when a trade message is received.</param>
        /// <param name="ordersHandler">Handler to be used when a order message is received.</param>
        /// <returns></returns>
        public string ListenUserDataEndpoint(ApiClientAbstract.MessageHandler <AccountUpdatedMessage> accountInfoHandler, ApiClientAbstract.MessageHandler <OrderOrTradeUpdatedMessage> tradesHandler, ApiClientAbstract.MessageHandler <OrderOrTradeUpdatedMessage> ordersHandler)
        {
            var listenKey = StartUserStream().Result.ListenKey;

            _apiClient.ConnectToUserDataWebSocket(listenKey, accountInfoHandler, tradesHandler, ordersHandler);

            return(listenKey);
        }
        /// <see cref="ICobinhoodClient.UnsubscribeFromEndpoint(string, ApiClientAbstract.MessageHandler{UnsubscribeResponse})"/>
        public void UnsubscribeFromEndpoint(string channelId, ApiClientAbstract.MessageHandler <UnsubscribeResponse> messageHandler)
        {
            var requestData = new WebSocketRequest()
            {
                Action    = "unsubscribe",
                ChannelId = channelId
            };

            _apiClient.SuscribeToWebSocket(messageHandler, requestData);
        }
        /// <see cref="ICobinhoodClient.ListenOrderEndpoint(ApiClientAbstract.MessageHandler{OrderResponse})"/>
        public void ListenOrderEndpoint(ApiClientAbstract.MessageHandler <OrderResponse> messageHandler)
        {
            var requestData = new WebSocketRequest()
            {
                Action = "subscribe",
                Type   = "order"
            };

            _apiClient.SuscribeToWebSocket(messageHandler, requestData);
        }
        /// <summary>
        /// Kim
        /// </summary>
        /// <param name="messageHandler"></param>
        public void PingEndpoint(ApiClientAbstract.MessageHandler <OrderResponse> messageHandler)
        {
            var requestData = new WebSocketRequest()
            {
                Action = "ping",
                ID     = "sample_id"
            };

            _apiClient.SuscribeToWebSocket(messageHandler, requestData);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Listen to the Trades endpoint.
        /// </summary>
        /// <param name="symbol">Ticker symbol.</param>
        /// <param name="tradeHandler">Handler to be used when a message is received.</param>
        public void ListenTradeEndpoint(string symbol, ApiClientAbstract.MessageHandler <AggregateTradeMessage> tradeHandler)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("symbol cannot be empty. ", "symbol");
            }

            var param = symbol + "@aggTrade";

            _apiClient.ConnectToWebSocket(param, tradeHandler);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Listen to the Kline endpoint.
        /// </summary>
        /// <param name="symbol">Ticker symbol.</param>
        /// <param name="interval">Time interval to retreive.</param>
        /// <param name="klineHandler">Handler to be used when a message is received.</param>
        public void ListenKlineEndpoint(string symbol, TimeInterval interval, ApiClientAbstract.MessageHandler <KlineMessage> klineHandler)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("symbol cannot be empty. ", "symbol");
            }

            var param = symbol + $"@kline_{interval.GetDescription()}";

            _apiClient.ConnectToWebSocket(param, klineHandler);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Listen to the Depth endpoint.
        /// </summary>
        /// <param name="symbol">Ticker symbol.</param>
        /// <param name="depthHandler">Handler to be used when a message is received.</param>
        public void ListenDepthEndpoint(string symbol, ApiClientAbstract.MessageHandler <DepthMessage> depthHandler)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("symbol cannot be empty. ", "symbol");
            }

            var param = symbol + "@depth";

            _apiClient.ConnectToWebSocket(param, depthHandler, true);
        }
        /// <summary>
        /// Listen to the Trades endpoint.
        /// </summary>
        /// <param name="symbol">Ticker symbol.</param>
        /// <param name="tradeHandler">Handler to be used when a message is received.</param>
        public WebSocket ListenTradeEndpoint(string symbol, ApiClientAbstract.MessageHandler <AggregateTradeMessage> tradeHandler, Action <CloseEventArgs> onClose = null)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("symbol cannot be empty. ", "symbol");
            }

            var param = symbol + "@aggTrade";

            return(_apiClient.ConnectToWebSocket(param, tradeHandler, onClose));
        }
        /// <summary>
        /// Listen to the Depth endpoint.
        /// </summary>
        /// <param name="symbol">Ticker symbol.</param>
        /// <param name="depthHandler">Handler to be used when a message is received.</param>
        public WebSocket ListenDepthEndpoint(string symbol, ApiClientAbstract.MessageHandler <DepthMessage> depthHandler, Action <CloseEventArgs> onClose = null)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("symbol cannot be empty. ", "symbol");
            }

            var param = symbol + "@depth";

            return(_apiClient.ConnectToWebSocket(param, depthHandler, onClose, true));
        }
Exemplo n.º 10
0
        public void  ListenPartialDepthEndpoint(string symbol, ApiClientAbstract.MessageHandler <PartialDepthMessage> partialDepthHandler)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("symbol cannot be empty. ", "symbol");
            }

            var param = "stream?streams=" + symbol + "@depth" + "20";

            _apiClient.ConnectToWebSocket(param, partialDepthHandler, 2);
        }
Exemplo n.º 11
0
        public void ListenPartialDepthEndPoint(string symbol, int levels, ApiClientAbstract.MessageHandler <DepthPartialMessage> depthHandler)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("symbol cannot be empty. ", "symbol");
            }
            if (levels != 5 && levels != 10 && levels != 20)
            {
                throw new ArgumentException("Valid values for level are 5,10 or 20");
            }
            var param = symbol.ToLower() + "@depth" + levels;

            _apiClient.ConnectToWebSocket(param, depthHandler, true);
        }
        /// <see cref="ICobinhoodClient.ListenTickerEndpoint(string, string, ApiClientAbstract.MessageHandler{TickerResponse})"/>
        public void ListenTickerEndpoint(string quoteSymbol, string baseSymbol, ApiClientAbstract.MessageHandler <TickerResponse> messageHandler)
        {
            if (string.IsNullOrWhiteSpace(quoteSymbol))
            {
                throw new ArgumentException("QuoteSymbol cannot be empty. ", "quoteSymbol");
            }
            if (string.IsNullOrWhiteSpace(baseSymbol))
            {
                throw new ArgumentException("BaseSymbol cannot be empty. ", "baseSymbol");
            }

            var tradingPair = (quoteSymbol + "-" + baseSymbol).ToUpper();

            var requestData = new WebSocketRequest()
            {
                Action        = "subscribe",
                Type          = "ticker",
                TradingPairId = tradingPair
            };

            _apiClient.SuscribeToWebSocket(messageHandler, requestData);
        }
        /// <summary>
        /// Listen to the Depth endpoint.
        /// </summary>
        /// <param name="symbol">Ticker symbol.</param>
        /// <param name="depthHandler">Handler to be used when a message is received.</param>
        public string ListenDepthEndpoint(string symbol, Action <string> openHandler, ApiClientAbstract.MessageHandler <DepthMessage> depthHandler)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("symbol cannot be empty. ", "symbol");
            }

            string param = symbol + "@depth5";

            return(_apiClient.ConnectToWebSocket(param, depthHandler, openHandler, true));
        }