Exemplo n.º 1
0
        private void AddTakeProfitExecute(object param)
        {
            int ind = TakeProfit.Count + 1;
            var tpQuantityPercent = TakeProfit.Sum(x => x.QuantityPercent);
            var tp = new TakeProfitViewModel(this, 1.00 - tpQuantityPercent, ind > 1 ? TakeProfit[ind - 2] : null)
            {
                Price = Math.Round(Buy.Price * (1.0m + 0.05m * ind), SymbolInformation.PriceDecimals), Caption = $"Тейк {ind}"
            };

            TakeProfit.Add(tp);
        }
    public override int GetHashCode()
    {
        int hash = 1;

        if (lots_ != null)
        {
            hash ^= Lots.GetHashCode();
        }
        if (takeProfit_ != null)
        {
            hash ^= TakeProfit.GetHashCode();
        }
        if (trailingStop_ != null)
        {
            hash ^= TrailingStop.GetHashCode();
        }
        if (mACDOpenLevel_ != null)
        {
            hash ^= MACDOpenLevel.GetHashCode();
        }
        if (mATTrendPeriod_ != null)
        {
            hash ^= MATTrendPeriod.GetHashCode();
        }
        if (maximumRisk_ != null)
        {
            hash ^= MaximumRisk.GetHashCode();
        }
        if (decreaseFactor_ != null)
        {
            hash ^= DecreaseFactor.GetHashCode();
        }
        if (movingPeriod_ != null)
        {
            hash ^= MovingPeriod.GetHashCode();
        }
        if (movingShift_ != null)
        {
            hash ^= MovingShift.GetHashCode();
        }
        if (_unknownFields != null)
        {
            hash ^= _unknownFields.GetHashCode();
        }
        return(hash);
    }
 public void MergeFrom(AlgorithmParameters other)
 {
     if (other == null)
     {
         return;
     }
     if (other.lots_ != null)
     {
         if (lots_ == null)
         {
             Lots = new global::Lots();
         }
         Lots.MergeFrom(other.Lots);
     }
     if (other.takeProfit_ != null)
     {
         if (takeProfit_ == null)
         {
             TakeProfit = new global::TakeProfit();
         }
         TakeProfit.MergeFrom(other.TakeProfit);
     }
     if (other.trailingStop_ != null)
     {
         if (trailingStop_ == null)
         {
             TrailingStop = new global::TrailingStop();
         }
         TrailingStop.MergeFrom(other.TrailingStop);
     }
     if (other.mACDOpenLevel_ != null)
     {
         if (mACDOpenLevel_ == null)
         {
             MACDOpenLevel = new global::MACDOpenLevel();
         }
         MACDOpenLevel.MergeFrom(other.MACDOpenLevel);
     }
     if (other.mATTrendPeriod_ != null)
     {
         if (mATTrendPeriod_ == null)
         {
             MATTrendPeriod = new global::MATrendPeriod();
         }
         MATTrendPeriod.MergeFrom(other.MATTrendPeriod);
     }
     if (other.maximumRisk_ != null)
     {
         if (maximumRisk_ == null)
         {
             MaximumRisk = new global::MaximumRisk();
         }
         MaximumRisk.MergeFrom(other.MaximumRisk);
     }
     if (other.decreaseFactor_ != null)
     {
         if (decreaseFactor_ == null)
         {
             DecreaseFactor = new global::DecreaseFactor();
         }
         DecreaseFactor.MergeFrom(other.DecreaseFactor);
     }
     if (other.movingPeriod_ != null)
     {
         if (movingPeriod_ == null)
         {
             MovingPeriod = new global::MovingPeriod();
         }
         MovingPeriod.MergeFrom(other.MovingPeriod);
     }
     if (other.movingShift_ != null)
     {
         if (movingShift_ == null)
         {
             MovingShift = new global::MovingShift();
         }
         MovingShift.MergeFrom(other.MovingShift);
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
Exemplo n.º 4
0
        private async Task <bool> SubmitImpl(string param)
        {
            Buy.Model.Symbol = SymbolInformation.Symbol;
            Buy.Model.Side   = TradeSide.Buy;
            Buy.Model.Kind   = OrderKind.Buy;
            Buy.Model.Type   = IsMarketBuy ? OrderType.MARKET : OrderType.LIMIT;

            StopLoss.Model.Symbol = SymbolInformation.Symbol;
            StopLoss.Model.Side   = TradeSide.Sell;
            StopLoss.Model.Kind   = OrderKind.StopLoss;
            StopLoss.Model.Type   = IsLimitStop ? OrderType.STOP_LIMIT : OrderType.MARKET;
            StopLoss.Quantity     = Buy.Quantity;

            Debug.Assert(Buy.Model.Quantity >= SymbolInformation.MinQuantity);
            Debug.Assert((Buy.Model.Price * Buy.Model.Quantity) >= SymbolInformation.MinNotional);
            Debug.Assert((StopLoss.Model.Price * StopLoss.Model.Quantity) >= SymbolInformation.MinNotional);

            foreach (var tp in TakeProfit)
            {
                tp.Model.Symbol = SymbolInformation.Symbol;
                tp.Model.Side   = TradeSide.Sell;
                tp.Model.Kind   = OrderKind.TakeProfit;
                tp.Model.Type   = OrderType.MARKET;
                if (tp.QuantityPercent > 0.01)
                {
                    tp.Quantity = SymbolInformation.ClampQuantity(Buy.Quantity * (decimal)tp.QuantityPercent);
                    Debug.Assert(tp.Quantity >= SymbolInformation.MinQuantity);
                    Debug.Assert(tp.Total >= SymbolInformation.MinNotional);
                }
                else
                {
                    tp.Quantity = 0m;
                }
            }

            var tpQuantityTotal   = TakeProfit.Sum(tp => tp.Quantity);
            var tpQuantityPercent = TakeProfit.Sum(tp => tp.QuantityPercent);

            if (tpQuantityPercent > 0.98)
            {
                tpQuantityPercent = 1.00;
            }
            var tpValidQuantity = SymbolInformation.ClampQuantity(Buy.Quantity * (decimal)tpQuantityPercent);

            var tpQuantityLeft = tpValidQuantity - tpQuantityTotal;

            while (tpQuantityLeft >= SymbolInformation.StepSize)
            {
                foreach (var tp in TakeProfit.Where(x => x.QuantityPercent >= 0.01))
                {
                    if (tpQuantityLeft >= SymbolInformation.StepSize)
                    {
                        tp.Quantity    += SymbolInformation.StepSize;
                        tpQuantityLeft -= SymbolInformation.StepSize;
                    }
                }
                tpQuantityLeft = Buy.Quantity - TakeProfit.Sum(tp => tp.Quantity);
            }

            Debug.Assert(Buy.Quantity >= TakeProfit.Sum(tp => tp.Quantity));

            if (tpQuantityLeft > 0m)
            {
                //System.Windows.MessageBox.Show($"Остаток: {tpQuantityLeft} {SymbolInformation.BaseAsset}");
                var ok = await Confirm.Handle($"Остаток: {tpQuantityLeft} {SymbolInformation.BaseAsset}");

                if (!ok)
                {
                    return(false);
                }
            }

            Model.Jobs.Add(Buy.Model);
            foreach (var tp in TakeProfitCollection)
            {
                // NOTE: if SL is TRAILING by STEPS,
                // then create new object with corresponding price
                // for every TP.
                Model.Jobs.Add(StopLoss.Model);
                Model.Jobs.Add(tp.Model);
            }

            Model.Created = DateTime.Now;
            Model.Updated = DateTime.Now;
            Model.Events.Add(Model.Created, "Task created.");

            SerializeModel(Model);

            return(true);
        }