示例#1
0
        static async Task Main(string[] args)
        {
            // 1. create connections with exchange
            var credentials = new ApiCredentials(ApiKey, Secret);

            using IBinanceClient binanceRestClient         = new BinanceClient(new BinanceClientOptions { ApiCredentials = credentials });
            using IBinanceSocketClient binanceSocketClient = new BinanceSocketClient(new BinanceSocketClientOptions { ApiCredentials = credentials });


            // 2. test connection
            Logger.Info("Testing connection...");
            var pingResult = await binanceRestClient.PingAsync();

            Logger.Info($"Ping time: {pingResult.Data} ms");


            // 3. get order book
            var marketDepthManager = new MarketDepthManager(binanceRestClient, binanceSocketClient);
            var marketDepth        = new MarketDepth(Symbol);


            marketDepth.MarketDepthChanged += (sender, e) =>
            {
                Clear();

                WriteLine("Price : Volume");

                WriteLine(
                    JsonConvert.SerializeObject(
                        new
                {
                    LastUpdate = e.UpdateTime,
                    Asks       = e.Asks.Reverse().Take(OrderBookDepth).Select(s => $"{s.Price} : {s.Volume}"),
                    Bids       = e.Bids.Take(OrderBookDepth).Select(s => $"{s.Price} : {s.Volume}")
                },
                        Formatting.Indented));

                WriteLine("Press Enter to stop streaming market depth...");

                SetCursorPosition(0, 0);
            };


            // build order book
            await marketDepthManager.BuildAsync(marketDepth, OrderBookDepth);

            // stream order book updates
            marketDepthManager.StreamUpdates(marketDepth, OrderBookUpdateLimit);


            WriteLine("Press Enter to exit...");
            ReadLine();
        }
示例#2
0
        public static async Task Main(string[] args)
        {
            const string token = "ETHBTC";

            IBinanceRestClient binanceRestClient = new BinanceRestClient(new BinanceClientConfiguration
            {
                ApiKey    = "<your_api_key>",
                SecretKey = "<your_secret_key>"
            });


            var marketDepth = new MarketDepth(token);

            await TestConnection(binanceRestClient);

            marketDepth.MarketDepthChanged += (sender, e) =>
            {
                int n = 20;

                System.Console.Clear();

                System.Console.WriteLine("Price : Volume");
                System.Console.WriteLine(
                    JsonConvert.SerializeObject(
                        new
                {
                    LastUpdate = e.UpdateTime,
                    Asks       = e.Asks.Take(n).Reverse().Select(s => $"{s.Price} : {s.Volume}"),
                    Bids       = e.Bids.Take(n).Select(s => $"{s.Price} : {s.Volume}")
                },
                        Formatting.Indented));

                System.Console.WriteLine("Press Enter to stop streaming market depth...");

                System.Console.SetCursorPosition(0, 0);
            };


            var marketDepthManager = new MarketDepthManager(binanceRestClient, new BinanceWebSocketClient(binanceRestClient, Logger));

            // build order book
            await marketDepthManager.BuildAsync(marketDepth);

            // stream order book updates
            marketDepthManager.StreamUpdates(marketDepth);


            System.Console.WriteLine("Press Enter to exit...");
            System.Console.ReadLine();
        }