Пример #1
0
 public override void LoadData(Dictionary <string, string> dict)
 {
     base.LoadData(dict);
     EnterDistance = ExTool.StepRepresent.LoadFromString(dict["EnterDistance"]);
     CloseDistance = ExTool.StepRepresent.LoadFromString(dict["CloseDistance"]);
     IsLong        = Convert.ToBoolean(dict["IsLong"]);
     IsShort       = Convert.ToBoolean(dict["IsShort"]);
     StopDistance  = ExTool.StepRepresent.LoadFromString(dict["StopDistance"]);
 }
Пример #2
0
        //увеличивает цену для перехода на следующий шаг с теущего ForStep, ForStep from 1
        private double IncreasePrice(double BeginPrice, ExTool.StepRepresent stepRepresent, int ForStep)
        {
            double result   = BeginPrice;
            int    count    = stepRepresent.Values.Count;
            double CurValue = ForStep > count ? stepRepresent.Values[count - 1] : stepRepresent.Values[ForStep - 1];

            if (stepRepresent.IsPercentSize)
            {
                result += Math.Round((BeginPrice * CurValue) / 100d, 8);
            }
            else
            {
                result += CurValue;
            }
            return(result);
        }
        /// <summary>
        /// Считать параметры стратегии с формы
        /// </summary>
        /// <returns></returns>
        private StrategyParam ReadStrategyParam(bool ForSave)
        {
            try
            {
                if (strategyName.Text == "" || strategyMarket.Text == "" || strategyBuyValue.Text == "" ||
                    strategySellValue.Text == "")
                {
                    System.Media.SystemSounds.Beep.Play();
                    Print("Заполнены не все поля!", false);
                    return(null);
                }

                if (!SManager.CheckNameValid(strategyName.Text, ForSave))
                {
                    System.Media.SystemSounds.Beep.Play();
                    Print("Такое название уже существует!", false);
                    return(null);
                }

                Market sMarket = null;
                try
                {
                    sMarket = Market.LoadFromString(strategyMarket.Text);
                }
                catch (Exception ex)
                {
                    System.Media.SystemSounds.Beep.Play();
                    Print("Не удалось считать торговую пару! " + ex.Message);
                    return(null);
                }

                //ограничения покупки
                double ValueRestBuy = 0;
                if (!String.IsNullOrEmpty(strategyBuyValue.Text))
                {
                    ValueRestBuy = Convert.ToDouble(strategyBuyValue.Text.Replace(',', '.'), CultureInfo.InvariantCulture);
                }
                var balRestBuy = new ExTool.StepRepresent(1)
                {
                    Values = new List <double>()
                    {
                        ValueRestBuy
                    },
                    IsPercentSize = strategyBuyIsPerc.Checked ? true : false
                };

                //ограничения продажи
                double ValueRestSell = 0;
                if (!String.IsNullOrEmpty(strategySellValue.Text))
                {
                    ValueRestSell = Convert.ToDouble(strategySellValue.Text.Replace(',', '.'), CultureInfo.InvariantCulture);
                }

                var balRestSell = new ExTool.StepRepresent(1)
                {
                    Values = new List <double>()
                    {
                        ValueRestSell
                    },
                    IsPercentSize = strategySellIsPerc.Checked ? true : false,
                };

                var Param = new StrategyParam
                {
                    StrategyName    = strategyName.Text,
                    StrategyType    = AllStrategies[strategyType.SelectedItem.ToString()],
                    Market          = sMarket,
                    BalanceRestBuy  = balRestBuy,
                    BalanceRestSell = balRestSell,
                    Interval        = (Candle_Interval)strategyInterval.SelectedIndex,
                    SellOnlyBought  = strategySellBought.Checked,
                    WriteToFile     = checkBox2.Checked,
                    Stock           = ExTool.StockByName(comboBox1.SelectedItem.ToString())
                };
                return(Param);
            }
            catch (Exception ex)
            {
                System.Media.SystemSounds.Beep.Play();
                Print("Ошибка считывания параметров: " + ex.Message);
                return(null);
            }
        }
Пример #4
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);
        }