Exemplo n.º 1
0
        public Task <BestPriceToBuyViewModel> GetBestPriceToBuyAsync(BitcointoyouOrderBook orderBook, decimal min_value = 2000)
        {
            return(Task.Factory.StartNew(() =>
            {
                double transaction_fee_percent = (0.60 / 100);
                var best_price_to_buy_vm = new BestPriceToBuyViewModel();
                var prices_to_buy = orderBook.Asks;
                decimal best_price_to_buy = 0;
                double amount_to_buy = 0;

                for (int i = 0; i < (prices_to_buy.Length / 2) - 1; i++)
                {
                    var value = (prices_to_buy[i, 0] * prices_to_buy[i, 1]);

                    if (value > min_value)
                    {
                        best_price_to_buy = prices_to_buy[i, 0];
                        amount_to_buy = (double)prices_to_buy[i, 1];
                        break;
                    }
                }

                best_price_to_buy_vm.Exchange = "Bitcointoyou";
                if (best_price_to_buy > 0)
                {
                    best_price_to_buy_vm.Amount = (double)(min_value / best_price_to_buy);
                    best_price_to_buy_vm.Price = best_price_to_buy;
                    best_price_to_buy_vm.Valeu = (decimal)best_price_to_buy_vm.Amount * best_price_to_buy;
                    var fee = best_price_to_buy_vm.Valeu * (decimal)transaction_fee_percent;
                    best_price_to_buy_vm.Fee = fee;
                }

                return best_price_to_buy_vm;
            }));
        }
Exemplo n.º 2
0
        public Task <BestPriceToBuyViewModel> GetBestPriceToBuyAsync(TemBTCOrderBook orderBook, decimal min_value = 2000)
        {
            return(Task.Factory.StartNew(() =>
            {
                double transaction_fee_percent = (0.50 / 100);
                var best_price_to_buy_vm = new BestPriceToBuyViewModel();
                if (orderBook.Asks != null)
                {
                    var prices_to_buy = orderBook.Asks;
                    var best_price_to_buy = prices_to_buy.FirstOrDefault(p => ((decimal)p.Quantity * p.Price) > min_value);

                    best_price_to_buy_vm.Exchange = "TemBTC";
                    if (best_price_to_buy != null)
                    {
                        best_price_to_buy_vm.Amount = (double)(min_value / best_price_to_buy.Price);
                        best_price_to_buy_vm.Valeu = (decimal)best_price_to_buy_vm.Amount * best_price_to_buy.Price;
                        best_price_to_buy_vm.Price = best_price_to_buy.Price;
                        var fee = best_price_to_buy_vm.Valeu * (decimal)transaction_fee_percent;
                        best_price_to_buy_vm.Fee = fee;
                    }
                }


                return best_price_to_buy_vm;
            }));
        }