Пример #1
0
 internal void PositionClosed(TradeResult tradeResult)
 {
     if (tradeResult.IsSuccessful)
     {
         Grids.Where(x => x.Status == TradeStatus.Active && x.RobotPosition.Id == tradeResult.Position.Id).All(x => {
             x.Reset();
             return(true);
         });
         if (Grids.All(x => x.Status == TradeStatus.Inactive))
         {
             Reset();
         }
     }
 }
Пример #2
0
 internal void PendingOrderCancelled(TradeResult tradeResult)
 {
     if (tradeResult.IsSuccessful)
     {
         Grids.Where(x => x.Status == TradeStatus.Pending && x.RobotPendingOrder.Id == tradeResult.PendingOrder.Id).All(x => {
             x.Reset();
             return(true);
         });
         if (Grids.All(x => x.Status == TradeStatus.Inactive))
         {
             Reset();
         }
     }
 }
Пример #3
0
 internal void CloseCycle()
 {
     //close all positions
     Grids.Where(x => x.Status == TradeStatus.Active).OrderBy(x => x.RobotPosition.NetProfit).All(x =>
     {
         robot.ClosePositionAsync(x.RobotPosition, PositionClosed);
         return(true);
     });
     //close all pending orders
     Grids.Where(x => x.Status == TradeStatus.Pending).All(x =>
     {
         robot.CancelPendingOrderAsync(x.RobotPendingOrder, PendingOrderCancelled);
         return(true);
     });
 }
Пример #4
0
        internal void AnalyzeConditionalClosure()
        {
            TotalNetProfit = Grids.Where(x => x.Status == TradeStatus.Active).Select(x => x.RobotPosition.NetProfit).Sum();
            ClosureMode closureMode = c.ClosureParameters.ClosureMode;

            if (closureMode == ClosureMode.Fixed)
            {
                var ClosureCondition1 = TotalNetProfit >= robot.ClosureFixedTP.FallbackIfZero(c.ClosureParameters.Fixed.TakeProfit);
                var ClosureCondition2 = (new[] {
                    Grids.Where(x => x.Status == TradeStatus.Active && x.Side == GridSide.UpperGround).Count(),
                    Grids.Where(x => x.Status == TradeStatus.Active && x.Side == GridSide.UnderGround).Count()
                }).All(x => x == GridSize) && c.GridParameters.OrderType == OrderType.STOP;
                var IsPassingMaxDuration = c.ClosureParameters.FallbackClosureMode == FallbackClosureMode.MaxDuration && robot.Time.ToLocalTime() > ActiveSince.ToLocalTime().Add(c.ClosureParameters.MaxDurationSpan);

                if (ClosureCondition1 || ClosureCondition2 || IsPassingMaxDuration)
                {
                    CloseCycle();
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Добавить в дерево
        /// </summary>
        public void Build(ObservableCollection <WebPageBaseViewModel> properties)
        {
            var       description = GetGroupNames();
            RootPanel root        = (RootPanel)properties.First();

            //Устанавливаем базовою таблицу
            root.TableName = BaseTable;
            var grids = Grids.Where(i => i.IsGrid);

            description.ForEach((i, c) =>
            {
                var grid = grids.FirstOrDefault(j => j.Description == i);
                if (grid != null)
                {
                    GridViewModel model = new GridViewModel(root);
                    model.FieldInDb     = "grid" + c;
                    model.RuDescription = i;
                    model.TableName     = grid.TableName;
                    root.Children.Add(model);
                }
                else
                {
                    PanelViewModel model = new PanelViewModel(root)
                    {
                        FieldInDb = "panel" + c, RuDescription = i
                    };
                    root.Children.Add(model);
                }
            });
            Table table = _tables.ElementAt(CurrentTable);
            //Загрузка полей
            var fields =
                table.Elements <TableRow>()
                .Skip(1)
                .Select(i => new DocProperty(i.Elements <TableCell>().ElementAt(DescriptionField.Key).InnerText, i.Elements <TableCell>().ElementAt(TypeField.Key).InnerText, i.Elements <TableCell>().ElementAt(GroupName.Key).InnerText));
            int count = 0;

            foreach (DocProperty field in fields)
            {
                ModalViewModel model;
                if (string.IsNullOrEmpty(field.Parent))
                {
                    model = new ModalViewModel(root);
                    root.Children.Add(model);
                }
                else
                {
                    //Поиск панели
                    var tmp = root.Children.FirstOrDefault(i => i.RuDescription == field.Parent && i.Type == "panel" || i.Type == "grid");
                    if (tmp == null)
                    {
                        model = new ModalViewModel(root);
                        root.Children.Add(model);
                    }
                    else
                    {
                        model = new ModalViewModel(tmp);
                        tmp.Children.Add(model);
                        //model.TableName = (tmp as GridViewModel)?.TableName;
                    }
                }
                model.FieldInDb     = "field" + count.ToString();
                model.RuDescription = field.Description;
                model.Type          = field.GetRightType();
                //model.TableName = model.TableName??BaseTable;
                count++;
            }
        }