예제 #1
0
        public async Task <double> CalcSumFromPercent(double PercentValue, bool DirectionBuy)
        {
            double          Amount   = 0;
            CurrencyBalance cbalance = null;

            if (DirectionBuy == true)
            {
                cbalance = await Stock.GetBalance(Param.Market.MarketCurrency, Print);
            }
            else
            {
                cbalance = await Stock.GetBalance(Param.Market.BaseCurrency, Print);
            }

            if (cbalance != null)
            {
                double available = (double)cbalance.Available;
                Amount = Math.Round((available * PercentValue) / 100d, 8); //уменьшить учитывая ограничение
            }
            else
            {
                Print("balance is null at buy (percent)!");
            }
            return(Amount);
        }
예제 #2
0
        //возвращает суму в BaseCurrency
        public async Task <double> GetAmount(bool DirectionBuy, ExTool.StepRepresent BalanceRest)
        {
            double amount    = 0; //в BaseCurrency
            double available = 0;
            string Currency  = "";

            if (DirectionBuy)
            {
                if (BalanceRest.IsPercentSize)
                {
                    Currency = Param.Market.MarketCurrency;
                    CurrencyBalance cbalance = await Stock.GetBalance(Currency, Print);

                    Ticker ticker = await Stock.GetMarketPrice(Param.Market, Print);

                    if (cbalance != null && ticker != null)
                    {
                        available = (double)cbalance.Available;
                        available = Math.Round((available * BalanceRest[0]) / 100d, 8); //уменьшить учитывая ограничение
                        amount    = Math.Round(available / (double)ticker.Ask, 8);
                    }
                    else
                    {
                        Print("balance or ticker is null at buy!");
                    }
                }
                else
                {
                    Ticker ticker = await Stock.GetMarketPrice(Param.Market, Print);

                    if (ticker != null)
                    {
                        amount = Math.Round(BalanceRest[0] / (double)ticker.Ask, 8);
                    }
                    else
                    {
                        Print("ticker is null at buy!");
                    }
                }
            }
            else
            {
                if (Param.SellOnlyBought)
                {
                    amount = (double)State.PurchasedAmount;
                }
                else
                {
                    if (BalanceRest.IsPercentSize)
                    {
                        Currency = Param.Market.BaseCurrency;
                        CurrencyBalance cbalance = await Stock.GetBalance(Currency, Print);

                        if (cbalance != null)
                        {
                            available = (double)cbalance.Available;
                            amount    = Math.Round((available * BalanceRest[0]) / 100d, 8);
                        }
                        else
                        {
                            Print("balance is null at sell!");
                        }
                    }
                    else
                    {
                        amount = BalanceRest[0];
                    }
                }
            }
            if (amount < 0.00000001)
            {
                throw new Exception(string.Format("Доступно: {0}, cума на ордер: {1}. Недостаточно {2} для заявки!",
                                                  available, amount, Currency));
            }
            return(amount);
        }