/// <summary>
        /// 触发自动止盈止损
        /// </summary>
        public static void StartAutoStopLoss(QuotationEntity futures)
        {
            if (ContractVariety.ContracPostionID.Count == 0)
            {
                return;
            }
            if (ContractVariety.ContracPostionID.ContainsKey(futures.cd))
            {
                //如果自动止盈止损包含此合约号
                //循环查询持仓明细,进行比较
                foreach (string value in ContractVariety.ContracPostionID[futures.cd])
                {
                    PotionDetailModelViewModel item = PositionAllViewModel.Instance().DetPMList.FirstOrDefault(x => x.PsitionId == value);
                    if (item != null)
                    {
                        AutoStopLossModel aslm = CommParameterSetting.AutoStopLossModel.FirstOrDefault(x => x.Direction == item.Direction && x.Agreement == item.ContractId);
                        if (aslm == null)
                        {
                            break;
                        }
                        string[] VarietiesKey = futures.cd.Split(' ');
                        if (VarietiesKey.Length != 3)
                        {
                            return;
                        }
                        string       varietie = VarietiesKey[1];
                        VarietyModel vm       = null;
                        if (ContractVariety.Varieties.ContainsKey(varietie))
                        {
                            vm = ContractVariety.Varieties[varietie];
                        }
                        if (vm == null)
                        {
                            break;
                        }

                        if (aslm.StopLossPotion > 0)
                        {
                            //止损价》最新价触发止损
                            if (item.Direction == "B")
                            {
                                if (ContractVariety.PostionPrice[item.PsitionId].LossPrice >= futures.lp)
                                {
                                    //平仓
                                    if (!PostinIds.Contains(item.PsitionId))
                                    {
                                        OpenCloseing(item, 0);
                                        PostinIds.Add(item.PsitionId);
                                        int count = SQLiteHelper.ExecuteNonQuery(SQLiteHelper.DBPath, CommandType.Text, "delete from AutoStopLoss where ContractID='" + item.ContractId + "' and PostionID='" + item.PsitionId + "';");

                                        LogHelper.Debug("买:持仓的止损价" + ContractVariety.PostionPrice[item.PsitionId].LossPrice + ": 行情最新价" + futures.lp);
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                if (ContractVariety.PostionPrice[item.PsitionId].LossPrice <= futures.lp)
                                {
                                    //平仓
                                    if (!PostinIds.Contains(item.PsitionId))
                                    {
                                        OpenCloseing(item, 0);
                                        PostinIds.Add(item.PsitionId);
                                        int count = SQLiteHelper.ExecuteNonQuery(SQLiteHelper.DBPath, CommandType.Text, "delete from AutoStopLoss where ContractID='" + item.ContractId + "' and PostionID='" + item.PsitionId + "';");

                                        LogHelper.Debug("卖:持仓的止损价" + ContractVariety.PostionPrice[item.PsitionId].LossPrice + ": 行情最新价" + futures.lp);
                                        continue;
                                    }
                                }
                            }
                        }
                        if (aslm.StopProfitPotion > 0)
                        {
                            //止盈价《最新价触发止盈
                            if (item.Direction == "B")
                            {
                                if ((item.OpenPrice + aslm.StopProfitPotion * vm.tick_size) <= futures.lp)
                                {
                                    //平仓
                                    if (!PostinIds.Contains(item.PsitionId))
                                    {
                                        OpenCloseing(item, 0);
                                        PostinIds.Add(item.PsitionId);
                                        int count = SQLiteHelper.ExecuteNonQuery(SQLiteHelper.DBPath, CommandType.Text, "delete from AutoStopLoss where ContractID='" + item.ContractId + "' and PostionID='" + item.PsitionId + "';");

                                        LogHelper.Debug("买:持仓的止盈价" + ContractVariety.PostionPrice[item.PsitionId].LossPrice + ": 行情最新价" + futures.lp);
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                if ((item.OpenPrice - aslm.StopProfitPotion * vm.tick_size) >= futures.lp)
                                {
                                    //平仓
                                    if (!PostinIds.Contains(item.PsitionId))
                                    {
                                        OpenCloseing(item, 0);
                                        PostinIds.Add(item.PsitionId);
                                        int count = SQLiteHelper.ExecuteNonQuery(SQLiteHelper.DBPath, CommandType.Text, "delete from AutoStopLoss where ContractID='" + item.ContractId + "' and PostionID='" + item.PsitionId + "';");

                                        LogHelper.Debug("卖:持仓的止盈价" + ContractVariety.PostionPrice[item.PsitionId].LossPrice + ": 行情最新价" + futures.lp);
                                        continue;
                                    }
                                }
                            }
                        }
                        if (aslm.FloatingProfitAndLoss > 0 && aslm.StopLossPotion > 0)
                        {
                            if (item.Direction == "B")
                            {
                                double cha = futures.lp - ContractVariety.PostionPrice[item.PsitionId].NewPrice;
                                if (cha > aslm.FloatingProfitAndLoss * vm.tick_size)
                                {
                                    int bs = (int)(cha / aslm.FloatingProfitAndLoss * vm.tick_size);
                                    ContractVariety.PostionPrice[item.PsitionId].NewPrice  = ContractVariety.PostionPrice[item.PsitionId].NewPrice + (bs * (aslm.FloatingProfitAndLoss * vm.tick_size));
                                    ContractVariety.PostionPrice[item.PsitionId].LossPrice = ContractVariety.PostionPrice[item.PsitionId].LossPrice + (bs * (aslm.FloatingProfitAndLoss * vm.tick_size));
                                    // 修改数据库中数据
                                    int count = SQLiteHelper.ExecuteNonQuery(SQLiteHelper.DBPath, CommandType.Text, "UPDATE AutoStopLoss set LossPrice=" + ContractVariety.PostionPrice[item.PsitionId].LossPrice + ",newprice=" + ContractVariety.PostionPrice[item.PsitionId].NewPrice + " WHERE UserID='" + UserInfoHelper.UserId + "' and PostionID='" + item.PsitionId + "' and ContractID='" + item.ContractId + "';");
                                    LogHelper.Debug("买:更新止损价:" + ContractVariety.PostionPrice[item.PsitionId].LossPrice + ":止损价基数" + ContractVariety.PostionPrice[item.PsitionId].NewPrice);
                                }
                            }
                            else
                            {
                                double cha = ContractVariety.PostionPrice[item.PsitionId].NewPrice - futures.lp;//买就是反过来减
                                if (cha > aslm.FloatingProfitAndLoss * vm.tick_size)
                                {
                                    int bs = (int)(cha / aslm.FloatingProfitAndLoss * vm.tick_size);
                                    ContractVariety.PostionPrice[item.PsitionId].NewPrice  = ContractVariety.PostionPrice[item.PsitionId].NewPrice - (bs * (aslm.FloatingProfitAndLoss * vm.tick_size));
                                    ContractVariety.PostionPrice[item.PsitionId].LossPrice = ContractVariety.PostionPrice[item.PsitionId].LossPrice - (bs * (aslm.FloatingProfitAndLoss * vm.tick_size));
                                    // 修改数据库中数据
                                    int count = SQLiteHelper.ExecuteNonQuery(SQLiteHelper.DBPath, CommandType.Text, "UPDATE AutoStopLoss set LossPrice=" + ContractVariety.PostionPrice[item.PsitionId].LossPrice + ",newprice=" + ContractVariety.PostionPrice[item.PsitionId].NewPrice + " WHERE UserID='" + UserInfoHelper.UserId + "' and PostionID='" + item.PsitionId + "' and ContractID='" + item.ContractId + "';");
                                    LogHelper.Debug("卖:更新止损价:" + ContractVariety.PostionPrice[item.PsitionId].LossPrice + ":止损价基数" + ContractVariety.PostionPrice[item.PsitionId].NewPrice);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void EnterExecuteChanged()
        {
            try
            {
                if (OrderVersion.DefaultLot > OrderVersion.MaxLot && OrderVersion.MaxLot > 0)
                {
                    MessageBox.Show("下单默认数量不能大于最大数量!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                CommParameterSetting.StopLossModel.BuyNum             = StopLossModelViewModel.BuyNum;
                CommParameterSetting.StopLossModel.CkBuy              = StopLossModelViewModel.CkBuy;
                CommParameterSetting.StopLossModel.CkSell             = StopLossModelViewModel.CkSell;
                CommParameterSetting.StopLossModel.SellNum            = StopLossModelViewModel.SellNum;
                CommParameterSetting.StopLossModel.StopLossDelegation = StopLossModelViewModel.StopLossDelegation;
                CommParameterSetting.StopLossModel.StopLossPrice      = StopLossModelViewModel.StopLossPrice;
                IniHelper.ProfileWriteValue("CheckFullStop", "BuyNum", CommParameterSetting.StopLossModel.BuyNum.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("CheckFullStop", "CkBuy", CommParameterSetting.StopLossModel.CkBuy.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("CheckFullStop", "CkSell", CommParameterSetting.StopLossModel.CkSell.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("CheckFullStop", "SellNum", CommParameterSetting.StopLossModel.SellNum.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("CheckFullStop", "StopLossDelegation", CommParameterSetting.StopLossModel.StopLossDelegation.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("CheckFullStop", "StopLossPrice", CommParameterSetting.StopLossModel.StopLossPrice.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("CheckFullStop", "StopProfitDelegation", CommParameterSetting.StopLossModel.StopProfitDelegation.ToString(), IniHelper.parameterSetting);


                //加载自动止盈止损 自动盈亏是用;分割行,分割列;

                if (Aslmvm != null)
                {
                    string para = "";
                    lock (CommParameterSetting.AutoStopLossModel)
                    {
                        CommParameterSetting.AutoStopLossModel.Clear();
                    }
                    List <string> AgreementList = new List <string>();
                    foreach (AutoStopLossModelViewModel item in Aslmvm)
                    {
                        if (string.IsNullOrEmpty(item.Agreement) || string.IsNullOrEmpty(item.VarietySelectedItem) || string.IsNullOrEmpty(item.Direction))
                        {
                            continue;
                        }
                        AutoStopLossModel asmvm = new AutoStopLossModel();
                        asmvm.Variety               = item.VarietySelectedItem;
                        asmvm.Agreement             = item.Agreement;
                        asmvm.Direction             = item.Direction == "买" ? "B" : "S";
                        asmvm.FloatingProfitAndLoss = item.FloatingProfitAndLoss;
                        asmvm.StopLossPotion        = item.StopLossPotion;
                        asmvm.StopProfitPotion      = item.StopProfitPotion;
                        CommParameterSetting.AutoStopLossModel.Add(asmvm);
                        if (!AgreementList.Contains(asmvm.Agreement))
                        {
                            AgreementList.Add(asmvm.Agreement);
                        }
                        para += item.VarietySelectedItem + "," + item.Agreement + "," + asmvm.Direction + "," + item.FloatingProfitAndLoss + "," + item.StopLossPotion + "," + item.StopProfitPotion + ";";

                        //将新增的添加到现有的集合中
                        if (!ContractVariety.ContracPostionID.ContainsKey(asmvm.Agreement))
                        {
                            ContractVariety.ContracPostionID.Add(asmvm.Agreement, new List <string>());
                        }
                    }

                    List <string> tempKeys   = ContractVariety.ContracPostionID.Keys.ToList();
                    string        Agreements = "";
                    foreach (string item in tempKeys)
                    {
                        if (!AgreementList.Contains(item))
                        {
                            lock (ContractVariety.ContracPostionID)
                            {
                                ContractVariety.ContracPostionID.Remove(item);
                            }
                            Agreements += item + ",";
                        }
                    }
                    if (!string.IsNullOrEmpty(Agreements))
                    {
                        int count = SQLiteHelper.ExecuteNonQuery(SQLiteHelper.DBPath, CommandType.Text, "delete from AutoStopLoss where ContractID in ('" + Agreements.TrimEnd(',') + "')");
                    }
                    IniHelper.ProfileWriteValue("AutoCheckFullStop", "AutoStopLoss", para.TrimEnd(';'), IniHelper.parameterSetting);
                }
                //}
                //下单版设置
                CommParameterSetting.OrderVersion.BeforeOrderEnter = OrderVersion.BeforeOrderEnter;
                CommParameterSetting.OrderVersion.DefaultLot       = OrderVersion.DefaultLot;
                CommParameterSetting.OrderVersion.MaxLot           = OrderVersion.MaxLot;

                IniHelper.ProfileWriteValue("OrderVersion", "BeforeOrderEnter", CommParameterSetting.OrderVersion.BeforeOrderEnter.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("OrderVersion", "DefaultLot", CommParameterSetting.OrderVersion.DefaultLot.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("OrderVersion", "MaxLot", CommParameterSetting.OrderVersion.MaxLot.ToString(), IniHelper.parameterSetting);
                if (OrderVersion.DefaultLot > 0)
                {
                    TransactionViewModel.Instance().FTNum = OrderVersion.DefaultLot;
                }
                if (OrderVersion.MaxLot > 0)
                {
                    TransactionViewModel.Instance().MaxLot = OrderVersion.MaxLot;
                }

                //快捷键设置
                CommParameterSetting.ShortcutKey.LockMenu    = ShortcutKey.LockMenu;
                CommParameterSetting.ShortcutKey.BuyOpen     = ShortcutKey.BuyOpen;
                CommParameterSetting.ShortcutKey.Clearance   = ShortcutKey.Clearance;
                CommParameterSetting.ShortcutKey.ClosingBuy  = ShortcutKey.ClosingBuy;
                CommParameterSetting.ShortcutKey.ClosingSell = ShortcutKey.ClosingSell;
                CommParameterSetting.ShortcutKey.Revoke      = ShortcutKey.Revoke;
                CommParameterSetting.ShortcutKey.SellOpen    = ShortcutKey.SellOpen;
                IniHelper.ProfileWriteValue("ShortcutKey", "LockMenu", CommParameterSetting.ShortcutKey.LockMenu.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "BuyOpen", CommParameterSetting.ShortcutKey.BuyOpen.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "Clearance", CommParameterSetting.ShortcutKey.Clearance.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "ClosingBuy", CommParameterSetting.ShortcutKey.ClosingBuy.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "ClosingSell", CommParameterSetting.ShortcutKey.ClosingSell.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "Revoke", CommParameterSetting.ShortcutKey.Revoke.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "SellOpen", CommParameterSetting.ShortcutKey.SellOpen.ToString(), IniHelper.parameterSetting);

                IniHelper.ProfileWriteValue("ShortcutKey", "IntBuyOpen", CommParameterSetting.ShortcutKey.IntBuyOpen.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "IntClearance", CommParameterSetting.ShortcutKey.IntClearance.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "IntClosingBuy", CommParameterSetting.ShortcutKey.IntClosingBuy.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "IntClosingSell", CommParameterSetting.ShortcutKey.IntClosingSell.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "IntRevoke", CommParameterSetting.ShortcutKey.IntRevoke.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("ShortcutKey", "IntSellOpen", CommParameterSetting.ShortcutKey.IntSellOpen.ToString(), IniHelper.parameterSetting);

                //消息提示
                CommParameterSetting.MessageAlert.OrderAlert  = MessageAlert.OrderAlert;
                CommParameterSetting.MessageAlert.RevokeAlert = MessageAlert.RevokeAlert;
                CommParameterSetting.MessageAlert.TradeAlert  = MessageAlert.TradeAlert;
                IniHelper.ProfileWriteValue("MessageAlert", "OrderAlert", CommParameterSetting.MessageAlert.OrderAlert.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("MessageAlert", "RevokeAlert", CommParameterSetting.MessageAlert.RevokeAlert.ToString(), IniHelper.parameterSetting);
                IniHelper.ProfileWriteValue("MessageAlert", "TradeAlert", CommParameterSetting.MessageAlert.TradeAlert.ToString(), IniHelper.parameterSetting);
                this.Close();
            }
            catch (Exception ex)
            {
                LogHelper.Info(ex.Message);
            }
        }
        public void ExecutePositionInfoData(object para)
        {
            try
            {
                PotionModel                rtm       = para as PotionModel;
                PositionAllViewModel       pavm      = PositionAllViewModel.Instance();
                PositionViewModel          pvm       = PositionViewModel.Instance();
                PotionDetailModelViewModel pdmvmtemp = pavm.DetPMList.FirstOrDefault(x => x.PsitionId == rtm.position_id);

                if (rtm.position_volume == 0)
                {
                    if (pdmvmtemp != null)
                    {
                        pavm.DetPMList.Remove(pdmvmtemp);
                        LogHelper.Info("4007  移除 " + rtm.contract_code + ":" + rtm.direction);
                        pavm.PMList.Clear();
                        pvm.PMList.Clear();
                    }

                    int count = SQLiteHelper.ExecuteNonQuery(SQLiteHelper.DBPath, CommandType.Text, "delete from AutoStopLoss where ContractID='" + rtm.contract_id + "' and PostionID='" + rtm.position_id + "';");
                }
                else
                {
                    if (pdmvmtemp != null)
                    {
                        pdmvmtemp.PositionVolume = rtm.position_volume;
                        pdmvmtemp.AbleVolume     = rtm.position_volume;
                        pdmvmtemp.UseMargin      = rtm.use_margin;
                        pdmvmtemp.SysUseMargin   = rtm.sys_margin;
                    }
                    else
                    {
                        PotionDetailModel pdm = new PotionDetailModel();
                        pdm.able_volume       = rtm.position_volume;
                        pdm.contract_code     = rtm.contract_code;
                        pdm.contract_id       = rtm.contract_id;
                        pdm.direction         = rtm.direction;
                        pdm.open_date         = rtm.position_date;
                        pdm.open_price        = rtm.position_price;
                        pdm.open_time         = rtm.position_time;
                        pdm.position_volume   = rtm.position_volume;
                        pdm.position_id       = rtm.position_id;
                        pdm.shadow_orderID    = rtm.shadow_orderID;
                        pdm.shadow_positionid = rtm.shadow_positionid;
                        pdm.shadow_tradeid    = rtm.shadow_tradeid;

                        pdm.trade_id   = "";
                        pdm.user_id    = rtm.user_id;
                        pdm.use_margin = rtm.use_margin;
                        pdm.sys_margin = rtm.sys_margin;
                        VarietyModel vm     = null;
                        string[]     values = pdm.contract_id.Split(' ');
                        if (values.Length == 3)
                        {
                            string varietie = values[1];
                            if (ContractVariety.Varieties.ContainsKey(varietie))
                            {
                                vm = ContractVariety.Varieties[varietie];
                            }
                            if (vm != null)
                            {
                                pdm.precision = vm.precision;
                            }
                        }

                        pdmvmtemp = new PotionDetailModelViewModel(pdm);
                        pavm.DetPMList.Add(pdmvmtemp);
                    }
                }
                if (ContractVariety.ContracPostionID.ContainsKey(rtm.contract_id))
                {
                    AutoStopLossModel aslm = CommParameterSetting.AutoStopLossModel.FirstOrDefault(x => x.Direction == rtm.direction && x.Agreement == rtm.contract_id);
                    if (aslm != null)
                    {
                        if (!ContractVariety.PostionPrice.ContainsKey(rtm.position_id))
                        {
                            ContractVariety.PostionPrice.Add(rtm.position_id, new AutoLossPrice());
                        }
                        string[] VarietiesKey = rtm.contract_id.Split(' ');
                        if (VarietiesKey.Length == 3)
                        {
                            string       varietie = VarietiesKey[1];
                            VarietyModel vm       = null;
                            if (ContractVariety.Varieties.ContainsKey(varietie))
                            {
                                vm = ContractVariety.Varieties[varietie];
                            }
                            if (vm != null)
                            {
                                if (rtm.direction == "B")
                                {
                                    ContractVariety.PostionPrice[rtm.position_id].LossPrice = rtm.position_price - aslm.StopLossPotion * vm.tick_size;
                                }
                                else
                                {
                                    ContractVariety.PostionPrice[rtm.position_id].LossPrice = rtm.position_price + aslm.StopLossPotion * vm.tick_size;
                                }
                                ContractVariety.PostionPrice[rtm.position_id].NewPrice = rtm.position_price;
                                if (!ContractVariety.ContracPostionID.ContainsKey(rtm.contract_id))
                                {
                                    ContractVariety.ContracPostionID.Add(rtm.contract_id, new List <string>());
                                }
                                ContractVariety.ContracPostionID[rtm.contract_id].Add(rtm.position_id);
                                int count = SQLiteHelper.ExecuteNonQuery(SQLiteHelper.DBPath, CommandType.Text, "insert INTO AutoStopLoss VALUES('" + rtm.position_id + "','" + rtm.contract_id + "','" + UserInfoHelper.UserId + "'," + ContractVariety.PostionPrice[rtm.position_id].LossPrice + "," + ContractVariety.PostionPrice[rtm.position_id].NewPrice + ");");
                            }
                        }
                    }
                }
                PotionDetailModelViewModel[] temp = pavm.DetPMList.ToArray();
                //合约名加方向作为K
                Dictionary <string, PotionDetailModelViewModel> dicod = new Dictionary <string, PotionDetailModelViewModel>();

                foreach (PotionDetailModelViewModel item in temp)
                {
                    PotionDetailModelViewModel pm1 = item.Clone(item);
                    if (!dicod.Keys.Contains(pm1.ContractCode + pm1.Direction))
                    {
                        pm1.AllPrice = pm1.OpenPrice * pm1.PositionVolume;
                        dicod.Add(pm1.ContractCode + pm1.Direction, pm1);
                        //MainViewModel.GetInstance().SubscribedStocks.Add(pm1.ContractCode);
                    }
                    else
                    {
                        dicod[item.ContractCode + item.Direction].AbleVolume         = dicod[item.ContractCode + item.Direction].AbleVolume + item.AbleVolume;
                        dicod[item.ContractCode + item.Direction].PositionProfitLoss = dicod[item.ContractCode + item.Direction].PositionProfitLoss + item.PositionProfitLoss;
                        dicod[item.ContractCode + item.Direction].PositionVolume     = dicod[item.ContractCode + item.Direction].PositionVolume + item.PositionVolume;
                        dicod[item.ContractCode + item.Direction].UseMargin          = dicod[item.ContractCode + item.Direction].UseMargin + item.UseMargin;
                        dicod[item.ContractCode + item.Direction].SysUseMargin       = dicod[item.ContractCode + item.Direction].SysUseMargin + item.SysUseMargin;
                        dicod[item.ContractCode + item.Direction].AllPrice          += item.PositionVolume * item.OpenPrice;
                        dicod[item.ContractCode + item.Direction].OpenPrice          = dicod[item.ContractCode + item.Direction].AllPrice / dicod[item.ContractCode + item.Direction].PositionVolume;
                    }
                }
                if (dicod.Keys.Count > 0)
                {
                    pavm.PMList.Clear();
                    pvm.PMList.Clear();
                    foreach (PotionDetailModelViewModel item in dicod.Values)
                    {
                        pavm.PMList.Add(item);
                        pvm.PMList.Add(item);
                    }
                    pvm.SelectedItem = pvm.PMList.FirstOrDefault(x => x.ContractCode == rtm.contract_code && x.Direction == rtm.direction);
                }
                if (!MainViewModel.GetInstance().SubscribedStocks.Contains(rtm.contract_code))
                {
                    MainViewModel.GetInstance().SubscribedStocks.Add(rtm.contract_code);
                    ScoketManager.GetInstance().SendSubscribeInfo(7, rtm.contract_code);
                }

                foreach (string key in CommHelper.CFSmvmList.Keys)
                {
                    PotionDetailModelViewModel temp1 = PositionViewModel.Instance().PMList.FirstOrDefault(x => (x.ContractId + x.Direction) == key);
                    if (temp1 == null)
                    {
                        continue;
                    }
                    double maxprice  = 99999999999;
                    double minprice  = 0;
                    double maxprice1 = 0;
                    double minprice1 = 99999999999;
                    int    maxnum    = 0;
                    int    minnum    = 0;
                    foreach (CheckFullStopModelViewModel item in CommHelper.CFSmvmList[key])
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        if (item.StoplossPrice > 0 || item.StopprofitPrice > 0)
                        {
                            if (item.Direction == "B")
                            {
                                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;
                                    }
                                }
                                if (maxprice < 99999999999 && maxnum > 0)
                                {
                                    temp1.ProfitVolume = maxprice + "/" + maxnum;
                                }
                                if (minprice > 0 && minnum > 0)
                                {
                                    temp1.LossVolume = minprice + "/" + minnum;
                                }
                            }
                            else
                            {
                                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;
                                    }
                                }
                                if (maxprice1 > 0 && maxnum > 0)
                                {
                                    temp1.ProfitVolume = maxprice1 + "/" + maxnum;
                                }
                                if (minprice < 99999999999 && minnum > 0)
                                {
                                    temp1.LossVolume = minprice1 + "/" + minnum;
                                }
                            }
                        }
                    }
                }
                TransactionViewModel.Instance().AgreementChangedExecuteChanged();
                if (pavm.PMList.FirstOrDefault(x => x.ContractCode == rtm.contract_code && x.Direction == rtm.direction) == null)
                {
                    if (CommHelper.CFSmvmList.ContainsKey(rtm.contract_code + rtm.direction))
                    {
                        CommHelper.CFSmvmList[rtm.contract_code + rtm.direction].Clear();
                        LogHelper.Info("4007中移除止盈止损" + rtm.contract_id + rtm.direction + "清除数据");
                    }
                }

                //PositionViewModel.Instance().JSAbleVolume();
                TransactionViewModel.Instance().FigureUpNum(TransactionViewModel.Instance()._futures);
            }
            catch (Exception ex)
            {
                LogHelper.Info(ex.ToString());
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 加载参数设置
        /// </summary>
        private void LoadParameter()
        {
            //加载止盈止损
            // CommParameterSetting.StopLossModel.ADelegateSecond = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "ADelegateSecond", IniHelper.parameterSetting)) ? 0 : int.Parse(IniHelper.ProfileReadValue("CheckFullStop", "ADelegateSecond", IniHelper.parameterSetting));
            CommParameterSetting.StopLossModel.BuyNum = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "BuyNum", IniHelper.parameterSetting)) ? 0 : int.Parse(IniHelper.ProfileReadValue("CheckFullStop", "BuyNum", IniHelper.parameterSetting));
            //   CommParameterSetting.StopLossModel.CkADelegate = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "CkADelegate", IniHelper.parameterSetting)) ? false : bool.Parse(IniHelper.ProfileReadValue("CheckFullStop", "CkADelegate", IniHelper.parameterSetting));
            CommParameterSetting.StopLossModel.CkBuy = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "CkBuy", IniHelper.parameterSetting)) ? false : bool.Parse(IniHelper.ProfileReadValue("CheckFullStop", "CkBuy", IniHelper.parameterSetting));
            //  CommParameterSetting.StopLossModel.CkReADelegate = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "CkReADelegate", IniHelper.parameterSetting)) ? false : bool.Parse(IniHelper.ProfileReadValue("CheckFullStop", "CkReADelegate", IniHelper.parameterSetting));
            CommParameterSetting.StopLossModel.CkSell = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "CkSell", IniHelper.parameterSetting)) ? false : bool.Parse(IniHelper.ProfileReadValue("CheckFullStop", "CkSell", IniHelper.parameterSetting));
            //   CommParameterSetting.StopLossModel.DateValidity = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "DateValidity", IniHelper.parameterSetting)) ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : IniHelper.ProfileReadValue("CheckFullStop", "DateValidity", IniHelper.parameterSetting);
            // CommParameterSetting.StopLossModel.ReADelegateAllSecond = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "ReADelegateAllSecond", IniHelper.parameterSetting)) ? 0 : int.Parse(IniHelper.ProfileReadValue("CheckFullStop", "ReADelegateAllSecond", IniHelper.parameterSetting));
            CommParameterSetting.StopLossModel.SellNum = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "SellNum", IniHelper.parameterSetting)) ? 0 : int.Parse(IniHelper.ProfileReadValue("CheckFullStop", "SellNum", IniHelper.parameterSetting));
            // CommParameterSetting.StopLossModel.StopLoss = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "StopLoss", IniHelper.parameterSetting)) ? 0 : int.Parse(IniHelper.ProfileReadValue("CheckFullStop", "StopLoss", IniHelper.parameterSetting));
            CommParameterSetting.StopLossModel.StopLossDelegation = IniHelper.ProfileReadValue("CheckFullStop", "StopLossDelegation", IniHelper.parameterSetting);
            if (string.IsNullOrEmpty(CommParameterSetting.StopLossModel.StopLossDelegation))
            {
                CommParameterSetting.StopLossModel.StopLossDelegation = "市价";
            }
            CommParameterSetting.StopLossModel.StopLossPrice = IniHelper.ProfileReadValue("CheckFullStop", "StopLossPrice", IniHelper.parameterSetting);
            if (string.IsNullOrEmpty(CommParameterSetting.StopLossModel.StopLossPrice))
            {
                CommParameterSetting.StopLossModel.StopLossPrice = "最新价";
            }
            //  CommParameterSetting.StopLossModel.StopProfit = string.IsNullOrEmpty(IniHelper.ProfileReadValue("CheckFullStop", "StopProfit", IniHelper.parameterSetting)) ? 0 : int.Parse(IniHelper.ProfileReadValue("CheckFullStop", "StopProfit", IniHelper.parameterSetting));
            CommParameterSetting.StopLossModel.StopProfitDelegation = IniHelper.ProfileReadValue("CheckFullStop", "StopProfitDelegation", IniHelper.parameterSetting);
            //  CommParameterSetting.StopLossModel.StopProfitPrice = IniHelper.ProfileReadValue("CheckFullStop", "StopProfitPrice", IniHelper.parameterSetting);
            //加载自动止盈止损 自动盈亏是用;分割行,分割列;
            string AutoStopLossModel = IniHelper.ProfileReadValue("AutoCheckFullStop", "AutoStopLoss", IniHelper.parameterSetting);

            // public static List<AutoStopLossModel> AutoStopLossModel = new List<AutoStopLossModel>();
            if (!string.IsNullOrEmpty(AutoStopLossModel))
            {
                string[] ModelCount = AutoStopLossModel.Split(';');

                for (int i = 0; i < ModelCount.Length; i++)
                {
                    string[]          paras = ModelCount[i].Split(',');
                    AutoStopLossModel aspl  = new AutoStopLossModel();
                    aspl.Variety               = paras[0];
                    aspl.Agreement             = paras[1];
                    aspl.Direction             = paras[2];
                    aspl.FloatingProfitAndLoss = string.IsNullOrEmpty(paras[3]) ? 0 : int.Parse(paras[3]);
                    aspl.StopLossPotion        = string.IsNullOrEmpty(paras[4]) ? 0 : int.Parse(paras[4]);
                    aspl.StopProfitPotion      = string.IsNullOrEmpty(paras[5]) ? 0 : int.Parse(paras[5]);
                    CommParameterSetting.AutoStopLossModel.Add(aspl);
                    if (!ContractVariety.ContracPostionID.ContainsKey(aspl.Agreement))
                    {
                        ContractVariety.ContracPostionID.Add(aspl.Agreement, new List <string>());
                    }
                }
            }

            //下单版设置

            CommParameterSetting.OrderVersion.BeforeOrderEnter = string.IsNullOrEmpty(IniHelper.ProfileReadValue("OrderVersion", "BeforeOrderEnter", IniHelper.parameterSetting)) ? true : bool.Parse(IniHelper.ProfileReadValue("OrderVersion", "BeforeOrderEnter", IniHelper.parameterSetting));
            CommParameterSetting.OrderVersion.DefaultLot       = string.IsNullOrEmpty(IniHelper.ProfileReadValue("OrderVersion", "DefaultLot", IniHelper.parameterSetting)) ? 0 : int.Parse(IniHelper.ProfileReadValue("OrderVersion", "DefaultLot", IniHelper.parameterSetting));
            CommParameterSetting.OrderVersion.MaxLot           = string.IsNullOrEmpty(IniHelper.ProfileReadValue("OrderVersion", "MaxLot", IniHelper.parameterSetting)) ? 0 : int.Parse(IniHelper.ProfileReadValue("OrderVersion", "MaxLot", IniHelper.parameterSetting));
            //快捷键设置
            CommParameterSetting.ShortcutKey.BuyOpen     = IniHelper.ProfileReadValue("ShortcutKey", "BuyOpen", IniHelper.parameterSetting);
            CommParameterSetting.ShortcutKey.Clearance   = IniHelper.ProfileReadValue("ShortcutKey", "Clearance", IniHelper.parameterSetting);
            CommParameterSetting.ShortcutKey.ClosingBuy  = IniHelper.ProfileReadValue("ShortcutKey", "ClosingBuy", IniHelper.parameterSetting);
            CommParameterSetting.ShortcutKey.ClosingSell = IniHelper.ProfileReadValue("ShortcutKey", "ClosingSell", IniHelper.parameterSetting);
            CommParameterSetting.ShortcutKey.LockMenu    = string.IsNullOrEmpty(IniHelper.ProfileReadValue("ShortcutKey", "LockMenu", IniHelper.parameterSetting)) ? false : bool.Parse(IniHelper.ProfileReadValue("ShortcutKey", "LockMenu", IniHelper.parameterSetting));;
            CommParameterSetting.ShortcutKey.Revoke      = IniHelper.ProfileReadValue("ShortcutKey", "Revoke", IniHelper.parameterSetting);
            CommParameterSetting.ShortcutKey.SellOpen    = IniHelper.ProfileReadValue("ShortcutKey", "SellOpen", IniHelper.parameterSetting);

            CommParameterSetting.ShortcutKey.IntBuyOpen     = Convert.ToInt32(IniHelper.ProfileReadValue("ShortcutKey", "IntBuyOpen", IniHelper.parameterSetting));
            CommParameterSetting.ShortcutKey.IntClearance   = Convert.ToInt32(IniHelper.ProfileReadValue("ShortcutKey", "IntClearance", IniHelper.parameterSetting));
            CommParameterSetting.ShortcutKey.IntClosingBuy  = Convert.ToInt32(IniHelper.ProfileReadValue("ShortcutKey", "IntClosingBuy", IniHelper.parameterSetting));
            CommParameterSetting.ShortcutKey.IntClosingSell = Convert.ToInt32(IniHelper.ProfileReadValue("ShortcutKey", "IntClosingSell", IniHelper.parameterSetting));
            CommParameterSetting.ShortcutKey.IntRevoke      = Convert.ToInt32(IniHelper.ProfileReadValue("ShortcutKey", "IntRevoke", IniHelper.parameterSetting));
            CommParameterSetting.ShortcutKey.IntSellOpen    = Convert.ToInt32(IniHelper.ProfileReadValue("ShortcutKey", "IntSellOpen", IniHelper.parameterSetting));

            //消息提示
            CommParameterSetting.MessageAlert.OrderAlert  = IniHelper.ProfileReadValue("MessageAlert", "OrderAlert", IniHelper.parameterSetting);
            CommParameterSetting.MessageAlert.RevokeAlert = IniHelper.ProfileReadValue("MessageAlert", "RevokeAlert", IniHelper.parameterSetting);
            CommParameterSetting.MessageAlert.TradeAlert  = IniHelper.ProfileReadValue("MessageAlert", "TradeAlert", IniHelper.parameterSetting);

            ContractVariety.effectivityLenth = string.IsNullOrEmpty(IniHelper.ProfileReadValue("effectivity", "effectivityLenth", IniHelper.parameterSetting)) ? 100.00 : double.Parse(IniHelper.ProfileReadValue("effectivity", "effectivityLenth", IniHelper.parameterSetting));
        }