public void TestKlineWs()
 {
     using (var client = new BinanceWebSocketClient())
     {
         client.ConnectKlineEndpoint("ethbtc", KlineInterval.Minute1, GenericMessageHandler);
         Thread.Sleep(60000);
     }
 }
Beispiel #2
0
        static void WebSocketExamples()
        {
            //Listen For Depth Messages
            using (var client = new BinanceWebSocketClient())
            {
                client.ConnectDepthEndpoint("ethbtc", depthMsg
                                            => Console.WriteLine($"{depthMsg.EventTime} {depthMsg.Symbol} {depthMsg.AskDepthDelta.Sum(b=>b.Quantity)}"));
                Thread.Sleep(60000);
            }

            //Listen For KLine Messages
            using (var client = new BinanceWebSocketClient())
            {
                client.ConnectKlineEndpoint("ethbtc", KlineInterval.Minute1, klineMsg
                                            => Console.WriteLine($"{klineMsg.Symbol} {klineMsg.KLineData.NumberOfTrades}"));
                Thread.Sleep(60000);
            }

            //Listen For Trades Messages
            using (var client = new BinanceWebSocketClient())
            {
                client.ConnectTradesEndpoint("ethbtc", tradesMsg
                                             => Console.WriteLine($"{tradesMsg.Symbol} {tradesMsg.Price} {tradesMsg.Quantity}"));
                Thread.Sleep(60000);
            }

            //Listen User Data Endpoint
            //Return ListenKey if you need to explicitly call CloseUserDataStream, KeepAliveUserDataStream from the rest client
            //Automatically makes keepalive request every 30 seconds
            var restClient = new BinanceClient(ConfigurationManager.AppSettings["BinanceApiKey"], ConfigurationManager.AppSettings["BinanceApiSecret"]);

            using (var client = new BinanceWebSocketClient())
            {
                var listenKey = client.ConnectUserDataEndpoint(restClient,
                                                               accountMessage => Console.WriteLine("UserData Received! " + accountMessage.EventTime),
                                                               orderMessage => Console.WriteLine("Order Message Received! " + orderMessage.EventTime),
                                                               tradeMessage => Console.WriteLine("Trade Message Received! " + tradeMessage.EventTime)
                                                               ).Result;
                Thread.Sleep(300000);
            }
        }