Exemple #1
0
        public async Task <TokenViewModel> Info(string market)
        {
            TokenViewModel viewModel = new TokenViewModel();

            viewModel.BaseType = BaseType(market);
            viewModel.MinValue = MinTradeValue(viewModel.BaseType);
            string asset = market.Replace(viewModel.BaseType, "");

            using (var client = new BinanceClient())
            {
                var balances = await client.GetAccountInfoAsync();

                if (balances.Success)
                {
                    CalculateAmountDecimal amountDecimal = new CalculateAmountDecimal();
                    BinanceBalance         balance       = balances.Data.Balances.Where(b => b.Asset == asset).Single();
                    viewModel.BaseDecimalAmount = viewModel.BaseType == "USDT" || viewModel.BaseType == "TUSD" || viewModel.BaseType == "USDC" || viewModel.BaseType == "PAX" ? 2 : await amountDecimal.OrderBookDecimal(viewModel.BaseType + "USDT");

                    var currentPrice = await client.Get24HPriceAsync(market);

                    if (currentPrice.Success)
                    {
                        viewModel.PriceDecimalAmount = await amountDecimal.PriceDecimal(market);

                        viewModel.AssetDecimalAmount = await amountDecimal.OrderBookDecimal(market);

                        viewModel.Name      = market;
                        viewModel.Amount    = decimal.Round(balance.Free, viewModel.AssetDecimalAmount);
                        viewModel.LastPrice = currentPrice.Data.LastPrice;
                        return(viewModel);
                    }
                }
            }
            return(viewModel);
        }
Exemple #2
0
        public async Task <TokenViewModel> Info(string market, decimal amountPercent)
        {
            TokenViewModel viewModel = new TokenViewModel();

            viewModel.BaseType = BaseType(market);
            viewModel.MinValue = MinTradeValue(viewModel.BaseType);
            using (var client = new BinanceClient())
            {
                var baseBalance = await client.GetAccountInfoAsync();

                if (baseBalance.Success)
                {
                    CalculateAmountDecimal amountDecimal = new CalculateAmountDecimal();
                    viewModel.BaseDecimalAmount = viewModel.BaseType == "USDT" || viewModel.BaseType == "TUSD" || viewModel.BaseType == "USDC" || viewModel.BaseType == "PAX" ? 2 : await amountDecimal.OrderBookDecimal(viewModel.BaseType + "USDT");

                    viewModel.BaseTotal  = decimal.Round(baseBalance.Data.Balances.Where(b => b.Asset == viewModel.BaseType).Select(b => b.Free).Single(), viewModel.BaseDecimalAmount);
                    viewModel.BaseTotal  = decimal.Round(viewModel.BaseTotal - (viewModel.BaseTotal * 0.01m), viewModel.BaseDecimalAmount);
                    viewModel.BaseAmount = decimal.Round(viewModel.BaseTotal * amountPercent, viewModel.BaseDecimalAmount);
                    var currentPrice = await client.Get24HPriceAsync(market);

                    if (currentPrice.Success)
                    {
                        viewModel.PriceDecimalAmount = await amountDecimal.PriceDecimal(market);

                        viewModel.AssetDecimalAmount = await amountDecimal.OrderBookDecimal(market);

                        viewModel.Name      = market;
                        viewModel.LastPrice = currentPrice.Data.LastPrice;
                        viewModel.Amount    = decimal.Round(viewModel.BaseAmount / viewModel.LastPrice, viewModel.AssetDecimalAmount);
                        return(viewModel);
                    }
                }
            }
            return(null);
        }
Exemple #3
0
        public async Task <TokenViewModel> InfoDeterminedBase(string market, decimal baseAmount)
        {
            TokenViewModel viewModel = new TokenViewModel();

            viewModel.BaseType = BaseType(market);
            viewModel.MinValue = MinTradeValue(viewModel.BaseType);
            using (var client = new BinanceClient())
            {
                var baseBalance = await client.GetAccountInfoAsync();

                if (baseBalance.Success)
                {
                    viewModel.BaseTotal  = baseBalance.Data.Balances.Where(b => b.Asset == viewModel.BaseType).Select(b => b.Free).Single();
                    viewModel.BaseAmount = baseAmount;
                    var currentPrice = await client.Get24HPriceAsync(market);

                    if (currentPrice.Success)
                    {
                        CalculateAmountDecimal amountDecimal = new CalculateAmountDecimal();
                        viewModel.Name      = market;
                        viewModel.LastPrice = currentPrice.Data.LastPrice;
                        viewModel.Amount    = decimal.Round(viewModel.BaseAmount / viewModel.LastPrice, await amountDecimal.OrderBookDecimal(market));
                        return(viewModel);
                    }
                }
            }
            return(null);
        }