public void OneExecuteChanged()
        {
            IsAuto = false;
            IsOne  = true;
            int countNum = 0;//表示已经设置过了价格的数量
            List <CheckFullStopModelViewModel> temps = CFSMVMList.ToList();

            CFSMVMList.Clear();
            foreach (CheckFullStopModelViewModel item in temps)
            {
                if (item.StoplossPrice > 0 || item.StopprofitPrice > 0)
                {
                    countNum += item.OrderVolume;
                    CFSMVMList.Add(item);
                }
            }
            int shengcount = _AllNum - countNum;

            while (shengcount > 0)
            {
                CheckFullStopModel cfsm = new CheckFullStopModel();
                cfsm.contract_code = _PositionModelViewModel.ContractCode;
                cfsm.contract_id   = _PositionModelViewModel.ContractId;
                cfsm.create_date   = DateTime.Now.ToString("yyyy-MM-dd");
                cfsm.create_time   = DateTime.Now.ToString("HH:mm:ss");
                cfsm.user_id       = UserInfoHelper.UserId;
                cfsm.order_volume  = 1;
                cfsm.resource      = (int)OperatorTradeType.OPERATOR_TRADE_PC;
                CheckFullStopModelViewModel cfsvm = new CheckFullStopModelViewModel(cfsm);
                cfsvm.Increment = Increment;
                cfsvm.Precision = length;
                CFSMVMList.Add(cfsvm);
                shengcount--;
            }
        }
Exemplo n.º 2
0
 public void ExecuteUpData(object para)
 {
     try
     {
         CheckFullStopModel cfsm = para as CheckFullStopModel;
         //添加持仓集合
         if (CommHelper.CFSmvmList.ContainsKey(cfsm.contract_id + cfsm.direction))
         {
             CheckFullStopModelViewModel temp = CommHelper.CFSmvmList[cfsm.contract_id + cfsm.direction].FirstOrDefault(x => x.StoplossId == cfsm.stoploss_id);
             if (temp != null)
             {
                 temp.StoplossPrice = cfsm.stoploss_price;
                 LogHelper.Info("止盈止损修改" + cfsm.contract_code + ":" + cfsm.direction + ";" + cfsm.create_time + "止损价:" + cfsm.stoploss_price);
             }
             PositionAllViewModel       pavm  = PositionAllViewModel.Instance();
             PotionDetailModelViewModel pdmvm = pavm.PMList.FirstOrDefault(x => x.ContractId == cfsm.contract_id && x.Direction == cfsm.direction);
             if (pdmvm != null)
             {
                 string[] values = pdmvm.LossVolume.Split('/');
                 pdmvm.LossVolume = cfsm.stoploss_price + "/" + values[1];
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Info(ex.ToString());
     }
 }
        public void DeleteExecuteChanged()
        {
            CFSMVMList.Clear();
            CheckFullStopModel cfsm = new CheckFullStopModel();

            cfsm.contract_code = _PositionModelViewModel.ContractCode;
            cfsm.contract_id   = _PositionModelViewModel.ContractId;
            cfsm.create_date   = DateTime.Now.ToString("yyyy-MM-dd");
            cfsm.create_time   = DateTime.Now.ToString("HH:mm:ss");
            cfsm.user_id       = UserInfoHelper.UserId;
            cfsm.order_volume  = _AllNum;
            cfsm.resource      = (int)OperatorTradeType.OPERATOR_TRADE_PC;
            CheckFullStopModelViewModel cfsvm = new CheckFullStopModelViewModel(cfsm);

            CFSMVMList.Add(cfsvm);
        }
        internal void AddData()
        {
            if (CFSMVMList.Count == 0)
            {
                CheckFullStopModel cfsm = new CheckFullStopModel();
                cfsm.contract_code = _PositionModelViewModel.ContractCode;
                cfsm.contract_id   = _PositionModelViewModel.ContractId;
                cfsm.create_date   = DateTime.Now.ToString("yyyy-MM-dd");
                cfsm.create_time   = DateTime.Now.ToString("HH:mm:ss");
                cfsm.user_id       = UserInfoHelper.UserId;
                cfsm.order_volume  = _PositionModelViewModel.PositionVolume;
                cfsm.resource      = (int)OperatorTradeType.OPERATOR_TRADE_PC;
                CheckFullStopModelViewModel cfsvm = new CheckFullStopModelViewModel(cfsm);
                cfsvm.MaxNum = _AllNum;

                cfsvm.Increment = Increment;
                cfsvm.Precision = length;
                CFSMVMList.Add(cfsvm);
            }
            else
            {
                int num = _AllNum - CFSMVMList.Sum(s => s.OrderVolume);
                if (num > 0)
                {
                    CheckFullStopModel cfsm = new CheckFullStopModel();
                    cfsm.contract_code = _PositionModelViewModel.ContractCode;
                    cfsm.contract_id   = _PositionModelViewModel.ContractId;
                    cfsm.create_date   = DateTime.Now.ToString("yyyy-MM-dd");
                    cfsm.create_time   = DateTime.Now.ToString("HH:mm:ss");
                    cfsm.user_id       = UserInfoHelper.UserId;
                    cfsm.order_volume  = num;
                    cfsm.resource      = (int)OperatorTradeType.OPERATOR_TRADE_PC;
                    CheckFullStopModelViewModel cfsvm = new CheckFullStopModelViewModel(cfsm);
                    cfsvm.MaxNum    = _AllNum;
                    cfsvm.Precision = length;
                    cfsvm.Increment = Increment;

                    CFSMVMList.Add(cfsvm);
                }
            }
        }
Exemplo n.º 5
0
 public void ExecuteDeleteData(object para)
 {
     try
     {
         double          maxprice  = 99999999999;
         double          minprice  = 0;
         double          maxprice1 = 0;
         double          minprice1 = 99999999999;
         int             maxnum    = 0;
         int             minnum    = 0;
         RStopLossStatus sls       = para as RStopLossStatus;
         LogHelper.Info("5204止盈止损" + sls.contract_id + "开始");
         if (CommHelper.CFSmvmList.ContainsKey(sls.contract_id + "B"))
         {
             CheckFullStopModelViewModel item = CommHelper.CFSmvmList[sls.contract_id + "B"].FirstOrDefault(x => x.StoplossId == sls.stoploss_id);
             if (item != null)
             {
                 CommHelper.CFSmvmList[sls.contract_id + "B"].Remove(item);
                 LogHelper.Info("5204止盈止损" + sls.contract_id + "B清除数据");
             }
             foreach (CheckFullStopModelViewModel temp in CommHelper.CFSmvmList[sls.contract_id + "B"])
             {
                 if (temp == null)
                 {
                     continue;
                 }
                 if (temp.StoplossPrice > 0 || temp.StopprofitPrice > 0)
                 {
                     if (item.StopprofitPrice > 0)
                     {
                         if (temp.StopprofitPrice < maxprice)
                         {
                             maxprice = temp.StopprofitPrice;
                             maxnum   = temp.OrderVolume;
                         }
                         else if (temp.StopprofitPrice == maxprice)
                         {
                             maxnum += temp.OrderVolume;
                         }
                     }
                     if (temp.StoplossPrice > 0)
                     {
                         if (temp.StoplossPrice > minprice)
                         {
                             minprice = temp.StoplossPrice;
                             minnum   = temp.OrderVolume;
                         }
                         else if (temp.StoplossPrice == minprice)
                         {
                             minnum += temp.OrderVolume;
                         }
                     }
                 }
             }
             PotionDetailModelViewModel _PositionModelViewModel1 = PositionViewModel.Instance().PMList.FirstOrDefault(x => x.ContractId == sls.contract_id && x.Direction == "B");
             if (_PositionModelViewModel1 != null)
             {
                 if (maxprice < 99999999999 && maxnum > 0)
                 {
                     _PositionModelViewModel1.ProfitVolume = maxprice + "/" + maxnum;
                 }
                 else
                 {
                     _PositionModelViewModel1.ProfitVolume = "";
                 }
                 if (minprice > 0 && minnum > 0)
                 {
                     _PositionModelViewModel1.LossVolume = minprice + "/" + minnum;
                 }
                 else
                 {
                     _PositionModelViewModel1.LossVolume = "";
                 }
             }
         }
         if (CommHelper.CFSmvmList.ContainsKey(sls.contract_id + "S"))
         {
             CheckFullStopModelViewModel item = CommHelper.CFSmvmList[sls.contract_id + "S"].FirstOrDefault(x => x.StoplossId == sls.stoploss_id);
             if (item != null)
             {
                 CommHelper.CFSmvmList[sls.contract_id + "S"].Remove(item);
                 LogHelper.Info("5204止盈止损" + sls.contract_id + "S清除数据");
             }
             foreach (CheckFullStopModelViewModel temp in CommHelper.CFSmvmList[sls.contract_id + "S"])
             {
                 if (temp == null)
                 {
                     continue;
                 }
                 if (temp.StoplossPrice > 0 || temp.StopprofitPrice > 0)
                 {
                     if (item.StopprofitPrice > 0)
                     {
                         if (item.StopprofitPrice > maxprice1)
                         {
                             maxprice1 = item.StopprofitPrice;
                             maxnum    = item.OrderVolume;
                         }
                         else if (item.StopprofitPrice == maxprice1)
                         {
                             maxnum += item.OrderVolume;
                         }
                     }
                     if (item.StoplossPrice > 0)
                     {
                         if (item.StoplossPrice < minprice1)
                         {
                             minprice1 = item.StoplossPrice;
                             minnum    = item.OrderVolume;
                         }
                         else if (item.StoplossPrice == minprice1)
                         {
                             minnum += item.OrderVolume;
                         }
                     }
                 }
             }
             PotionDetailModelViewModel _PositionModelViewModel = PositionViewModel.Instance().PMList.FirstOrDefault(x => x.ContractId == sls.contract_id && x.Direction == "S");
             if (_PositionModelViewModel != null)
             {
                 if (maxprice1 > 0 && maxnum > 0)
                 {
                     _PositionModelViewModel.ProfitVolume = maxprice1 + "/" + maxnum;
                 }
                 else
                 {
                     _PositionModelViewModel.ProfitVolume = "";
                 }
                 if (minprice1 < 99999999999 && minnum > 0)
                 {
                     _PositionModelViewModel.LossVolume = minprice1 + "/" + minnum;
                 }
                 else
                 {
                     _PositionModelViewModel.LossVolume = "";
                 }
             }
         }
         if (CheckFullStopViewModel.IsInstance())
         {
             CheckFullStopViewModel.Instance(null).Close();
         }
     }
     catch (Exception ex)
     {
         LogHelper.Info(ex.ToString());
     }
 }
Exemplo n.º 6
0
        public void Result(List <CheckFullStopModel> cfsms)
        {
            List <CheckFullStopModel> temps = cfsms;
            double maxprice  = 99999999999;
            double minprice  = 0;
            double maxprice1 = 0;
            double minprice1 = 99999999999;
            int    maxnum    = 0;
            int    minnum    = 0;

            if (CommHelper.CFSmvmList.ContainsKey(temps[0].contract_id + temps[0].direction))
            {
                CommHelper.CFSmvmList[temps[0].contract_id + temps[0].direction].Clear();
            }
            else
            {
                CommHelper.CFSmvmList.Add(temps[0].contract_id + temps[0].direction, new List <CheckFullStopModelViewModel>());
            }
            CommHelper.CFSmvmList[temps[0].contract_id + temps[0].direction].Clear();

            foreach (CheckFullStopModel item in temps)
            {
                if (item.stoploss_price > 0 || item.stopprofit_price > 0)
                {
                    if (item.direction == "B")
                    {
                        if (item.stopprofit_price > 0)
                        {
                            if (item.stopprofit_price < maxprice)
                            {
                                maxprice = item.stopprofit_price;
                                maxnum   = item.order_volume;
                            }
                            else if (item.stopprofit_price == maxprice)
                            {
                                maxnum += item.order_volume;
                            }
                        }
                        if (item.stoploss_price > 0)
                        {
                            if (item.stoploss_price > minprice)
                            {
                                minprice = item.stoploss_price;
                                minnum   = item.order_volume;
                            }
                            else if (item.stoploss_price == minprice)
                            {
                                minnum += item.order_volume;
                            }
                        }
                    }
                    else
                    {
                        if (item.stopprofit_price > 0)
                        {
                            if (item.stopprofit_price > maxprice1)
                            {
                                maxprice1 = item.stopprofit_price;
                                maxnum    = item.order_volume;
                            }
                            else if (item.stopprofit_price == maxprice1)
                            {
                                maxnum += item.order_volume;
                            }
                        }
                        if (item.stoploss_price > 0)
                        {
                            if (item.stoploss_price < minprice1)
                            {
                                minprice1 = item.stoploss_price;
                                minnum    = item.order_volume;
                            }
                            else if (item.stoploss_price == minprice1)
                            {
                                minnum += item.order_volume;
                            }
                        }
                    }
                    CheckFullStopModel cfsm = new CheckFullStopModel();
                    cfsm.user_id          = item.user_id;
                    cfsm.contract_id      = item.contract_id;
                    cfsm.direction        = item.direction;
                    cfsm.open_offset      = (int)OffsetType.OFFSET_COVER;
                    cfsm.order_volume     = item.order_volume;
                    cfsm.stoploss_price   = item.stoploss_price;
                    cfsm.stopprofit_price = item.stopprofit_price;
                    cfsm.float_loss       = item.float_loss;
                    cfsm.stoploss_id      = item.stoploss_id;
                    cfsm.float_loss_flag  = (int)FloatLossFlag.FLF_FloatLoss;
                    if (CommParameterSetting.StopLossModel.StopLossPrice == "最新价")
                    {
                        cfsm.trriger_price_type = (int)YunTrrigerStyle.Y_LASTPRICE;
                    }
                    else
                    {
                        if (item.direction == "S")
                        {
                            cfsm.trriger_price_type = (int)YunTrrigerStyle.Y_BUYONEPRICE;
                            cfsm.order_add_price    = CommParameterSetting.StopLossModel.BuyNum;
                        }
                        else
                        {
                            cfsm.order_add_price    = CommParameterSetting.StopLossModel.SellNum;
                            cfsm.trriger_price_type = (int)YunTrrigerStyle.Y_SELLONEPRICE;
                        }
                    }
                    if (CommParameterSetting.StopLossModel.StopProfitDelegation == "市价")
                    {
                        cfsm.price_type = "M";
                    }
                    else
                    {
                        cfsm.price_type = "L";
                    }
                    cfsm.create_date = DateTime.Now.ToString("yyyy-MM-dd");
                    cfsm.create_time = DateTime.Now.ToString("HH:mm:ss");

                    CheckFullStopModelViewModel cfsmvm = new CheckFullStopModelViewModel(cfsm);
                    if (CommHelper.CFSmvmList[item.contract_id + item.direction].FirstOrDefault(x => x.StoplossId == cfsm.stoploss_id) == null)
                    {
                        CommHelper.CFSmvmList[item.contract_id + item.direction].Add(cfsmvm);
                        LogHelper.Info("止盈止损添加 " + cfsm.contract_code + ":" + cfsm.direction + ";" + cfsm.create_time);
                    }
                }
            }
            PotionDetailModelViewModel _PositionModelViewModel = PositionViewModel.Instance().PMList.FirstOrDefault(x => x.ContractId == temps[0].contract_id && x.Direction == temps[0].direction);

            if (_PositionModelViewModel == null)
            {
                return;
            }
            if (_PositionModelViewModel.Direction == "B")
            {
                if (maxprice < 99999999999 && maxnum > 0)
                {
                    _PositionModelViewModel.ProfitVolume = maxprice + "/" + maxnum;
                }
                if (minprice > 0 && minnum > 0)
                {
                    _PositionModelViewModel.LossVolume = minprice + "/" + minnum;
                }
            }
            else
            {
                if (maxprice1 > 0 && maxnum > 0)
                {
                    _PositionModelViewModel.ProfitVolume = maxprice1 + "/" + maxnum;
                }
                if (minprice1 < 99999999999 && minnum > 0)
                {
                    _PositionModelViewModel.LossVolume = minprice1 + "/" + minnum;
                }
            }
        }
        public void NumChangedExecuteChanged()
        {
            int countNum = 0;
            int count    = 0;//表示止损或止盈价已经设置了

            foreach (CheckFullStopModelViewModel item in CFSMVMList)
            {
                if (item.StoplossPrice > 0 || item.StopprofitPrice > 0)
                {
                    count++;
                }
                countNum += item.OrderVolume;
            }
            if (countNum < _AllNum && CFSMVMList.Count - count <= 1)
            {
                CheckFullStopModel cfsm = new CheckFullStopModel();
                cfsm.contract_code = _PositionModelViewModel.ContractCode;
                cfsm.contract_id   = _PositionModelViewModel.ContractId;
                cfsm.create_date   = DateTime.Now.ToString("yyyy-MM-dd");
                cfsm.create_time   = DateTime.Now.ToString("HH:mm:ss");
                cfsm.user_id       = UserInfoHelper.UserId;
                cfsm.order_volume  = _AllNum - countNum;
                cfsm.resource      = (int)OperatorTradeType.OPERATOR_TRADE_PC;
                CheckFullStopModelViewModel cfsvm = new CheckFullStopModelViewModel(cfsm);
                if (SelectedItem.OrderVolume == 0)
                {
                    CFSMVMList.Remove(SelectedItem);
                }
                cfsvm.Increment = Increment;
                cfsvm.Precision = length;
                CFSMVMList.Add(cfsvm);
            }
            else if (countNum < _AllNum && CFSMVMList.Count - count >= 2)
            {
                int tempcount = CFSMVMList.Sum(x => x.OrderVolume);
                foreach (CheckFullStopModelViewModel item in CFSMVMList)
                {
                    if (item.StoplossPrice == 0 && item.StopprofitPrice == 0 && (item.CreateDate + item.CreateTime) != (SelectedItem.CreateDate + SelectedItem.CreateTime))
                    {
                        item.OrderVolume = _AllNum - tempcount + item.OrderVolume;
                        if (item.OrderVolume == 0)
                        {
                            CFSMVMList.Remove(item);
                        }
                        break;
                    }
                }
                if (SelectedItem.OrderVolume == 0)
                {
                    CFSMVMList.Remove(SelectedItem);
                }
            }
            else if (countNum > _AllNum && count <= CFSMVMList.Count - 1)
            {
                List <CheckFullStopModelViewModel> CFSMVMListtemp = CFSMVMList.Where(x => x.StoplossPrice == 0 && x.StopprofitPrice == 0).ToList();
                int num = CFSMVMList.Where(x => x.StoplossPrice > 0 || x.StopprofitPrice > 0).Sum(o => o.OrderVolume);
                if (CFSMVMListtemp.Count > 1)
                {
                    if (CFSMVMListtemp[0] == SelectedItem)
                    {
                        CFSMVMListtemp[1].OrderVolume = _AllNum - SelectedItem.OrderVolume - num;
                        if (CFSMVMListtemp[1].OrderVolume == 0)
                        {
                            CFSMVMListtemp.Remove(CFSMVMListtemp[1]);
                        }
                    }
                    else if (CFSMVMListtemp[1] == SelectedItem)
                    {
                        CFSMVMListtemp[0].OrderVolume = _AllNum - SelectedItem.OrderVolume - num;
                        if (CFSMVMListtemp[0].OrderVolume == 0)
                        {
                            CFSMVMListtemp.Remove(CFSMVMListtemp[0]);
                        }
                    }
                }
                else if (CFSMVMListtemp.Count == 1)
                {
                    if (CFSMVMListtemp[0] == SelectedItem)
                    {
                        CFSMVMListtemp[1].OrderVolume = _AllNum - SelectedItem.OrderVolume - num;
                        if (CFSMVMListtemp[1].OrderVolume == 0)
                        {
                            CFSMVMListtemp.Remove(CFSMVMListtemp[1]);
                        }
                    }
                    else
                    {
                        CFSMVMListtemp[0].OrderVolume = _AllNum - num;
                        if (CFSMVMListtemp[0].OrderVolume == 0)

                        {
                            CFSMVMListtemp.Remove(CFSMVMListtemp[0]);
                        }
                    }
                }
                foreach (CheckFullStopModelViewModel item in CFSMVMList)
                {
                    if (item.OrderVolume == 0)
                    {
                        CFSMVMList.Remove(item);
                        break;
                    }
                }
            }
        }
        public void Result()
        {
            List <CheckFullStopModelViewModel> temps = CFSMVMList.ToList();
            double maxprice = 99999999999;
            double minprice = 0;
            int    maxnum   = 0;
            int    minnum   = 0;

            if (CommHelper.CFSmvmList.ContainsKey(_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction))
            {
                CommHelper.CFSmvmList[_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction].Clear();
            }
            else
            {
                CommHelper.CFSmvmList.Add(_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction, new List <CheckFullStopModelViewModel>());
            }

            CommHelper.CFSmvmList[_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction].Clear();

            foreach (CheckFullStopModelViewModel item in temps)
            {
                if (item.StoplossPrice > 0 || item.StopprofitPrice > 0)
                {
                    if (item.StopprofitPrice > 0)
                    {
                        if (item.StopprofitPrice < maxprice)
                        {
                            maxprice = item.StopprofitPrice;
                            maxnum   = item.OrderVolume;
                        }
                        else if (item.StopprofitPrice == maxprice)
                        {
                            maxnum += item.OrderVolume;
                        }
                    }
                    if (item.StoplossPrice > 0)
                    {
                        if (item.StoplossPrice > minprice)
                        {
                            minprice = item.StoplossPrice;
                            minnum   = item.OrderVolume;
                        }
                        else if (item.StoplossPrice == minprice)
                        {
                            minnum += item.OrderVolume;
                        }
                    }
                    CheckFullStopModel cfsm = new CheckFullStopModel();
                    cfsm.user_id          = item.UserId;
                    cfsm.contract_id      = _PositionModelViewModel.ContractId;
                    cfsm.direction        = _PositionModelViewModel.Direction;
                    cfsm.open_offset      = (int)OffsetType.OFFSET_COVER;
                    cfsm.order_volume     = item.OrderVolume;
                    cfsm.stoploss_price   = item.StoplossPrice;
                    cfsm.stopprofit_price = item.StopprofitPrice;
                    cfsm.float_loss       = item.FloatLoss;
                    cfsm.float_loss_flag  = (int)FloatLossFlag.FLF_FloatLoss;
                    if (CommParameterSetting.StopLossModel.StopLossPrice == "最新价")
                    {
                        cfsm.trriger_price_type = (int)YunTrrigerStyle.Y_LASTPRICE;
                    }
                    else
                    {
                        if (_PositionModelViewModel.Direction == "S")
                        {
                            cfsm.trriger_price_type = (int)YunTrrigerStyle.Y_BUYONEPRICE;
                            cfsm.order_add_price    = CommParameterSetting.StopLossModel.BuyNum;
                        }
                        else
                        {
                            cfsm.order_add_price    = CommParameterSetting.StopLossModel.SellNum;
                            cfsm.trriger_price_type = (int)YunTrrigerStyle.Y_SELLONEPRICE;
                        }
                    }
                    if (CommParameterSetting.StopLossModel.StopProfitDelegation == "市价")
                    {
                        cfsm.price_type = "M";
                    }
                    else
                    {
                        cfsm.price_type = "L";
                    }
                    cfsm.create_date = DateTime.Now.ToString("yyyy-MM-dd");
                    cfsm.create_time = DateTime.Now.ToString("HH:mm:ss");


                    CheckFullStopModelViewModel cfsmvm = new CheckFullStopModelViewModel(cfsm);
                    CommHelper.CFSmvmList[_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction].Add(cfsmvm);
                }
            }
            if (maxprice < 99999999999 && maxnum > 0)
            {
                _PositionModelViewModel.ProfitVolume = maxprice + "/" + maxnum;
            }
            if (minprice > 0 && minnum > 0)
            {
                _PositionModelViewModel.LossVolume = minprice + "/" + minnum;
            }
            this.Close();
        }
        public void EnterExecuteChanged()
        {
            List <CheckFullStopModelViewModel> temps    = CFSMVMList.ToList();
            List <CheckFullStopModel>          cfsmList = new List <CheckFullStopModel>();

            foreach (CheckFullStopModelViewModel item in temps)
            {
                if ((item.StoplossPrice > 0 || item.StopprofitPrice > 0) && item.OrderVolume > 0)
                {
                    CheckFullStopModel cfsm = new CheckFullStopModel();
                    cfsm.user_id          = item.UserId;
                    cfsm.contract_id      = _PositionModelViewModel.ContractId;
                    cfsm.direction        = _PositionModelViewModel.Direction;
                    cfsm.open_offset      = (int)OffsetType.OFFSET_COVER;
                    cfsm.order_volume     = item.OrderVolume;
                    cfsm.stoploss_price   = item.StoplossPrice;
                    cfsm.stopprofit_price = item.StopprofitPrice;
                    cfsm.float_loss       = item.FloatLoss;
                    cfsm.float_loss_flag  = (int)FloatLossFlag.FLF_FloatLoss;
                    if (CommParameterSetting.StopLossModel.StopLossPrice == "最新价")
                    {
                        cfsm.trriger_price_type = (int)YunTrrigerStyle.Y_LASTPRICE;
                        if (_PositionModelViewModel.Direction == "B")
                        {
                            if (cfsm.stoploss_price >= TransactionViewModel.Instance().Futures.Tick.LastPrice&& cfsm.stoploss_price != 0)
                            {
                                MessageBox.Show("设置的止损价不能大于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            if (cfsm.stopprofit_price <= TransactionViewModel.Instance().Futures.Tick.LastPrice&& cfsm.stopprofit_price != 0)
                            {
                                MessageBox.Show("设置的止盈价不能小于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                        }
                        else
                        {
                            if (cfsm.stoploss_price <= TransactionViewModel.Instance().Futures.Tick.LastPrice&& cfsm.stoploss_price != 0)
                            {
                                MessageBox.Show("设置的止损价不能小于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            if (cfsm.stopprofit_price >= TransactionViewModel.Instance().Futures.Tick.LastPrice&& cfsm.stopprofit_price != 0)
                            {
                                MessageBox.Show("设置的止盈价不能大于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                        }
                    }
                    else
                    {
                        if (_PositionModelViewModel.Direction == "S")
                        {
                            cfsm.trriger_price_type = (int)YunTrrigerStyle.Y_SELLONEPRICE;
                        }
                        else
                        {
                            cfsm.trriger_price_type = (int)YunTrrigerStyle.Y_BUYONEPRICE;
                        }

                        if (_PositionModelViewModel.Direction == "B")
                        {
                            if (cfsm.stoploss_price >= TransactionViewModel.Instance().Futures.Tick.BidP1&& cfsm.stoploss_price != 0)
                            {
                                MessageBox.Show("设置的止损价不能大于当前的行情的对手价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            if (cfsm.stopprofit_price <= TransactionViewModel.Instance().Futures.Tick.BidP1&& cfsm.stopprofit_price != 0)
                            {
                                MessageBox.Show("设置的止盈价不能小于当前的行情的对手价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                        }
                        else
                        {
                            if (cfsm.stoploss_price <= TransactionViewModel.Instance().Futures.Tick.AskP1&& cfsm.stoploss_price != 0)
                            {
                                MessageBox.Show("设置的止损价不能小于当前的行情的对手价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            if (cfsm.stopprofit_price >= TransactionViewModel.Instance().Futures.Tick.AskP1&& cfsm.stopprofit_price != 0)
                            {
                                MessageBox.Show("设置的止盈价不能大于当前的行情的对手价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                        }
                    }
                    if (CommParameterSetting.StopLossModel.StopLossDelegation == "市价")
                    {
                        cfsm.price_type = "M";
                    }
                    else if (CommParameterSetting.StopLossModel.StopLossDelegation == "最新价")
                    {
                        cfsm.price_type = "L";
                        if (_PositionModelViewModel.Direction == "S")
                        {
                            cfsm.order_add_price = CommParameterSetting.StopLossModel.BuyNum * Increment;
                        }
                        else
                        {
                            cfsm.order_add_price = CommParameterSetting.StopLossModel.SellNum * Increment;
                        }
                    }
                    else
                    {
                        cfsm.price_type = "R";
                        if (_PositionModelViewModel.Direction == "S")
                        {
                            cfsm.order_add_price = CommParameterSetting.StopLossModel.BuyNum * Increment;
                        }
                        else
                        {
                            cfsm.order_add_price = CommParameterSetting.StopLossModel.SellNum * Increment;
                        }
                    }
                    cfsm.create_date = DateTime.Now.ToString("yyyy-MM-dd");
                    cfsm.create_time = DateTime.Now.ToString("HH:mm:ss");
                    cfsmList.Add(cfsm);

                    CheckFullStopModelViewModel cfsmvm = new CheckFullStopModelViewModel(cfsm);
                    // ContractVariety.CFSmvmList[_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction].Add(cfsmvm);
                }
            }
            if (cfsmList.Count > 0)
            {
                ReqCheckFullStopModel rcfsmv = new ReqCheckFullStopModel();
                rcfsmv.cmdcode = RequestCmdCode.AddStopLoss;
                rcfsmv.content = cfsmList;
                ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rcfsmv));
                if (CommHelper.CFSmvmList.ContainsKey(_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction))
                {
                    CommHelper.CFSmvmList[_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction].Clear();
                }
                else
                {
                    CommHelper.CFSmvmList.Add(_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction, new List <CheckFullStopModelViewModel>());
                }

                CommHelper.CFSmvmList[_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction].Clear();
            }
            else
            {
                if (IsHaveData)
                {
                    ReqDeleteCheckFullStop rdmv = new ReqDeleteCheckFullStop();
                    DeleteCheckFullStop    scfm = new DeleteCheckFullStop();
                    scfm.contract_id = _PositionModelViewModel.ContractId;
                    scfm.direction   = _PositionModelViewModel.Direction;
                    scfm.resource    = (int)OperatorTradeType.OPERATOR_TRADE_MC;
                    scfm.user_id     = UserInfoHelper.UserId;
                    rdmv.cmdcode     = RequestCmdCode.DeleteStopLoss;
                    rdmv.content     = scfm;
                    ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rdmv));
                }
            }
        }
        private CheckFullStopViewModel(PotionDetailModelViewModel pmvm)
        {
            _PositionModelViewModel = pmvm;
            ContractCode            = pmvm.ContractCode;
            _AllNum   = _PositionModelViewModel.PositionVolume;
            Direction = pmvm.Direction == "B" ? " (买入,投机) " : " (卖出,投机) ";


            VarietyModel vm = null;

            string[] values = pmvm.ContractCode.Split(' ');
            if (values.Length != 3)
            {
                return;
            }
            string varietie = values[1];

            if (ContractVariety.Varieties.ContainsKey(varietie))
            {
                vm = ContractVariety.Varieties[varietie];
            }
            if (vm == null)
            {
                return;
            }
            Increment = vm.tick_size;
            length    = vm.precision;
            ////发送命令
            //ReqPotion rp = new ReqPotion();
            //rp.cmdcode = RequestCmdCode.SelectStopLoss;
            //rp.content = new ReqLoginName() { user_id = UserInfoHelper.UserId };
            //ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rp));
            if (CommHelper.CFSmvmList.ContainsKey(_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction))
            {
                foreach (var item in CommHelper.CFSmvmList[_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction])
                {
                    item.Increment = Increment;
                    item.Precision = length;
                    CheckFullStopModel cfsm = new CheckFullStopModel();
                    cfsm.contract_code   = _PositionModelViewModel.ContractCode;
                    cfsm.contract_id     = _PositionModelViewModel.ContractId;
                    cfsm.create_date     = DateTime.Now.ToString("yyyy-MM-dd");
                    cfsm.create_time     = DateTime.Now.ToString("HH:mm:ss");
                    cfsm.user_id         = UserInfoHelper.UserId;
                    cfsm.order_volume    = _PositionModelViewModel.PositionVolume;
                    cfsm.resource        = (int)OperatorTradeType.OPERATOR_TRADE_PC;
                    cfsm.direction       = item.Direction;
                    cfsm.float_loss      = item.FloatLoss;
                    cfsm.float_loss_flag = item.FloatLossFlag;
                    cfsm.open_offset     = item.OpenOffset;
                    cfsm.order_volume    = item.OrderVolume;

                    CheckFullStopModelViewModel cfsvm = new CheckFullStopModelViewModel(cfsm);
                    cfsvm.Increment        = item.Increment;
                    cfsvm.Precision        = item.Precision;
                    cfsvm.Direction        = item.Direction;
                    cfsvm.MaxNum           = item.MaxNum;
                    cfsvm.StopprofitPrice  = item.StopprofitPrice;
                    cfsvm.StoplossId       = item.StoplossId;
                    cfsvm.TrrigerCondition = item.TrrigerCondition;
                    cfsvm.TrrigerPrice     = item.TrrigerPrice;
                    cfsvm.FloatLoss        = item.FloatLoss;

                    cfsvm.StoplossPrice = item.StoplossPrice;
                    cfsvm.CreateDate    = item.CreateDate;
                    cfsvm.OrderVolume   = item.OrderVolume;
                    CFSMVMList.Add(cfsvm);
                }
            }
            if (CFSMVMList.Count > 0)
            {
                IsHaveData = true;
            }
            AddData();
        }