예제 #1
0
        private static async Task RestAPI()
        {
            var api = new BinanceApi();

            if (await api.PingAsync())
            {
                Console.WriteLine("Successful!");
            }
            else
            {
                Console.WriteLine("Fail!");
            }


            var apiKey    = Environment.GetEnvironmentVariable("API_KEY");
            var apiSecret = Environment.GetEnvironmentVariable("API_SECRET");

            using var user = new BinanceApiUser(apiKey, apiSecret);


            await Symbol.UpdateCacheAsync(api);


            Console.WriteLine(Symbol.Cache.GetAll().Count());
            Console.WriteLine(Symbol.Cache.Get("BTCUSD"));
            Console.WriteLine(Symbol.Cache.Get("BTCEUR"));
            Console.WriteLine($"{Symbol.Cache.Get("BTCUSDT")}  {Symbol.Cache.Get("BTCUSDT")?.IsMarginTradingAllowed}");


            try
            {
                //var clientOrder = new MarketOrder(user)
                //{
                //    Symbol = Symbol.XLM_USDT,
                //    Side = OrderSide.Sell,
                //    Quantity = 100m
                //};
                //var conf = await api.PlaceMarginMarketAsync(clientOrder, true);
                //Console.WriteLine(JsonConvert.SerializeObject(conf));


                var xlmMaxBorrow = api.GetMaxBorrowAsync(user, "XLM");
                var usdMaxBorrow = api.GetMaxBorrowAsync(user, "USDT");
                var btcMaxBorrow = api.GetMaxBorrowAsync(user, "BTC");
                await Task.WhenAll(new[] { xlmMaxBorrow, usdMaxBorrow, btcMaxBorrow });

                Console.WriteLine($"Xlm: {xlmMaxBorrow.Result}");
                Console.WriteLine($"usd: {usdMaxBorrow.Result}");
                Console.WriteLine($"usd: {btcMaxBorrow.Result}");


                var pairs = await api.GetMarginPairsAsync(user);

                Console.WriteLine(JsonConvert.SerializeObject(pairs, Formatting.Indented));
            }
            catch (BinanceRequestRateLimitExceededException ex)
            {
                Console.WriteLine(
                    $"TEST Order HTTP Failed: Status: {ex.StatusCode}, Code: {ex.ErrorCode}, Message: {ex.ErrorMessage}");
            }
            catch (BinanceHttpException ex)
            {
                Console.WriteLine(
                    $"TEST Order HTTP Failed: Status: {ex.StatusCode}, Code: {ex.ErrorCode}, Message: {ex.ErrorMessage}");
            }
            catch (BinanceApiException e)
            {
                Console.WriteLine($"TEST Order Failed: \"{e.Message}\"");
            }

            catch (Exception e)
            {
                Console.WriteLine($"TEST Order Exception: \"{e.Message}\"");
            }
        }