Ejemplo n.º 1
0
        public void ModifyPwdExecuteChanged()
        {
            if (!string.Equals(OldPassword, UserInfoHelper.Password))
            {
                MessageBox.Show("原密码输入不正确!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (string.IsNullOrEmpty(NewPassword))
            {
                MessageBox.Show("新密码不能为空!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (!string.Equals(NewPassword, ConfirmPassword))
            {
                MessageBox.Show("两次输入的密码不一致!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            IsEdit = true;
            RequestModifyPwd dataModel = new RequestModifyPwd();

            dataModel.cmdcode = RequestCmdCode.RequestModifyPwd;
            dataModel.content = new ModifyPwd()
            {
                user_id      = UserInfoHelper.UserId,
                old_password = OldPassword,
                new_password = NewPassword,
                operator_id  = UserInfoHelper.LoginName,
                resource     = (int)OperatorTradeType.OPERATOR_TRADE_PC
            };
            string msg = JsonConvert.SerializeObject(dataModel);

            ScoketManager.GetInstance().SendTradeWSInfo(msg);
        }
        /// <summary>
        /// 平仓
        /// </summary>
        public static void OpenCloseing(PotionDetailModelViewModel item, int num, bool isClosing = true)
        {
            TransactionModel tm = new TransactionModel();

            tm.direction = item.Direction == "B" ? "S" : "B";

            tm.user_id     = UserInfoHelper.UserId;
            tm.contract_id = item.ContractId;
            if (isClosing)
            {
                tm.open_offset = (int)OffsetType.OFFSET_COVER;
            }
            else
            {
                tm.open_offset = (int)OffsetType.OFFSET_OPEN;
            }
            tm.resource       = (int)OperatorTradeType.OPERATOR_TRADE_PC;
            tm.order_orderref = Guid.NewGuid().ToString();
            tm.order_price    = 0;
            tm.operator_id    = UserInfoHelper.LoginName;
            tm.price_type     = "M";//根据选中的来判断;
            tm.order_volume   = item.PositionVolume - num;
            ReqTransactionModel rtm = new ReqTransactionModel();

            rtm.cmdcode = RequestCmdCode.PlaceOrderCode;
            rtm.content = tm;
            ScoketManager.GetInstance().SendTradeWSInfo(Newtonsoft.Json.JsonConvert.SerializeObject(rtm));
        }
        public void SelectExecuteChanged()
        {
            if (IsShow == Visibility.Collapsed)
            {
                return;
            }
            ReqDescriptModel rdvm = new ReqDescriptModel();
            RDescriptModel   rm   = new RDescriptModel();

            if (JSType == "日结算")
            {
                rm.start_date  = Convert.ToInt32(Convert.ToDateTime(Date).ToString("yyyyMMdd"));
                rm.end_date    = Convert.ToInt32(Convert.ToDateTime(Date).ToString("yyyyMMdd"));
                rm.settle_type = (int)SysSettleType.Sys_SettleDate;
            }
            else
            {
                rm.start_date  = Convert.ToInt32(Convert.ToDateTime(DateMouth).ToString("yyyyMM01"));
                rm.end_date    = Convert.ToInt32(Convert.ToDateTime(DateMouth).AddMonths(1).ToString("yyyyMM01"));
                rm.settle_type = (int)SysSettleType.Sys_SettleMonth;
            }
            rm.user_id   = UserInfoHelper.UserId;
            rdvm.cmdcode = RequestCmdCode.ReqDescript;
            rdvm.content = rm;
            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rdvm));
        }
Ejemplo n.º 4
0
        public void LockingExecuteChanged()
        {
            if (SelectedItem == null)
            {
                MessageBox.Show("请选择快捷锁仓", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            TransactionModel tm = new TransactionModel();

            if (SelectedItem.Direction == "S")
            {
                tm.direction = "B";
            }
            else
            {
                tm.direction = "S";
            }
            tm.contract_id    = SelectedItem.ContractId;
            tm.user_id        = UserInfoHelper.UserId;
            tm.open_offset    = (int)OffsetType.OFFSET_OPEN;
            tm.resource       = (int)OperatorTradeType.OPERATOR_TRADE_PC;
            tm.order_orderref = Guid.NewGuid().ToString();
            tm.order_price    = 0;
            tm.operator_id    = UserInfoHelper.LoginName;
            tm.price_type     = "M";//根据选中的来判断;
            tm.order_volume   = SelectedItem.PositionVolume;
            ReqTransactionModel rtm = new ReqTransactionModel();

            rtm.cmdcode = RequestCmdCode.PlaceOrderCode;
            rtm.content = tm;
            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rtm));
        }
Ejemplo n.º 5
0
        public MainWindow()
        {
            InitializeComponent();
            Application.Current.MainWindow = this;

            MaxHeight      = SystemParameters.MaximizedPrimaryScreenHeight;
            MaxWidth       = SystemParameters.MaximizedPrimaryScreenWidth;
            log.Source     = new BitmapImage(new Uri("\\Resources\\Images\\TitleLog\\TitleImg.png", UriKind.Relative));//strImagePath 就绝对路径
            viewModel      = MainViewModel.GetInstance();
            DataContext    = viewModel;
            _scoketManager = ScoketManager.GetInstance();
            if (viewModel.TradeQuotesViewModel.SetOptionalListAction == null)
            {
                viewModel.TradeQuotesViewModel.SetOptionalListAction = () => { this.SetOptionalList(); };
            }
            //if (viewModel.TradeQuotesViewModel.ReSetOptionalSelectItemAction == null)
            //{
            //    viewModel.TradeQuotesViewModel.ReSetOptionalSelectItemAction = () => { this.ReSetOptionalSelectItem(); };
            //}
            var resizer = new ControlResizer(border, new Thickness(1), 0, null);

            //设置事件
            resizer.Resize += resizer_Resize;
            LoadParameter();
        }
Ejemplo n.º 6
0
 public TradeLoginViewModel(MainViewModel mainVM)
 {
     _mainVM       = mainVM;
     scoketManager = ScoketManager.GetInstance();
     GetTxtSiet();
     GetClientUsers();
     CreateImageSource();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 请求合约品种
        /// </summary>
        private void ReqVariety()
        {
            // Thread.Sleep(2000);
            ReqPotion rpd = new ReqPotion();

            rpd.cmdcode = RequestCmdCode.SelectVariety;
            rpd.content = null;
            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rpd));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 请求收费方式
        /// </summary>
        public void ReqDetType()
        {
            // Thread.Sleep(2000);
            ReqPotion rpd = new ReqPotion();

            rpd.cmdcode = RequestCmdCode.ReqCalcDeposit;
            rpd.content = null;
            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rpd));
        }
        public void DelOptional(string serialnumber)
        {
            scoketManager = ScoketManager.GetInstance();
            if (string.IsNullOrEmpty(serialnumber))
            {
                return;
            }
            string msg = "{\"cmdcode\":2248,\"content\":{\"serial_number\":\"" + serialnumber + "\"}}";

            scoketManager.SendTradeWSInfo(msg);
        }
        public void AddOptional(string contractid)
        {
            scoketManager = ScoketManager.GetInstance();
            if (string.IsNullOrEmpty(UserInfoHelper.UserId))
            {
                return;
            }
            string msg = "{\"cmdcode\":2246,\"content\":{\"user_id\":\"" + UserInfoHelper.UserId + "\",\"contract_id\":\"" + contractid + "\"}}";

            scoketManager.SendTradeWSInfo(msg);
        }
Ejemplo n.º 11
0
        private void LoadData()
        {
            ReqPotion rpd = new ReqPotion();

            rpd.cmdcode = RequestCmdCode.SelectPotionDetialCode;
            rpd.content = new ReqLoginName()
            {
                user_id = UserInfoHelper.UserId
            };
            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rpd));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 请求保证金
        /// </summary>
        public void ReqMargin()
        {
            ReqPotion rp = new ReqPotion();

            rp.cmdcode = RequestCmdCode.ReqMargin;
            rp.content = new ReqLoginName()
            {
                user_id = UserInfoHelper.UserId
            };
            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rp));
        }
        public void LoadData()
        {
            //条件单
            ReqPotion rp = new ReqPotion();

            rp.cmdcode = RequestCmdCode.SelectConditionBill;
            rp.content = new ReqLoginName()
            {
                user_id = UserInfoHelper.UserId
            };

            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rp));
        }
        private void LoadData()
        {
            //成交明细
            ReqPotion rp = new ReqPotion();

            rp.cmdcode = RequestCmdCode.ToDayTradeCode;
            rp.content = new ReqLoginName()
            {
                user_id = UserInfoHelper.UserId
            };

            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rp));
        }
Ejemplo n.º 15
0
        public void OrderCancelExecuteChanged()
        {
            if (SelectedItemTemp == null)
            {
                MessageBox.Show("请选择撤单项", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            ReqCannetOrderModel rcom = new ReqCannetOrderModel();

            rcom.cmdcode = RequestCmdCode.CannelOrderCode;
            rcom.content = new CannetOrderModel()
            {
                user_id = UserInfoHelper.UserId, order_id = SelectedItemTemp.OrderId, resource = (int)OperatorTradeType.OPERATOR_TRADE_PC
            };
            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rcom));
        }
Ejemplo n.º 16
0
 public void OrderCancelAllExecuteChanged()
 {
     if (KCDelegations != null && KCDelegations.Count > 0)
     {
         foreach (DelegationModelViewModel item in KCDelegations)
         {
             ReqCannetOrderModel rcom = new ReqCannetOrderModel();
             rcom.cmdcode = RequestCmdCode.CannelOrderCode;
             rcom.content = new CannetOrderModel()
             {
                 user_id = UserInfoHelper.UserId, order_id = item.OrderId, resource = (int)OperatorTradeType.OPERATOR_TRADE_PC
             };
             ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rcom));
         }
     }
 }
Ejemplo n.º 17
0
        private void SendConditionBill(bool isClear = true)
        {
            ReqPotion rp = new ReqPotion();

            rp.cmdcode = RequestCmdCode.SelectConditionBill;
            rp.content = new ReqLoginName()
            {
                user_id = UserInfoHelper.UserId
            };

            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rp));
            if (isClear)
            {
                UCConditionBillViewModel.Instance().ConditionBillList.Clear();
            }
        }
Ejemplo n.º 18
0
        private void SendOrderCancel(bool isClear = true)
        {
            ReqPotion rpd = new ReqPotion();

            rpd.cmdcode = RequestCmdCode.SelectOrderCancel;
            rpd.content = new ReqLoginName()
            {
                user_id = UserInfoHelper.UserId
            };
            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rpd));
            if (isClear)
            {
                OrderCancelViewModel.Instance().KCDelegations.Clear();
                OrderCancelViewModel.Instance().Delegations.Clear();
            }
        }
Ejemplo n.º 19
0
        private void ToDayTrade(bool isClear = true)
        {
            //成交明细
            ReqPotion rp = new ReqPotion();

            rp.cmdcode = RequestCmdCode.ToDayTradeCode;
            rp.content = new ReqLoginName()
            {
                user_id = UserInfoHelper.UserId
            };

            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rp));
            if (isClear)
            {
                TodayTraderViewModels.Instance().TodayTraderList.Clear();
            }
        }
Ejemplo n.º 20
0
        private void SendPotion(bool isClear = true)
        {
            ReqPotion rpd = new ReqPotion();

            rpd.cmdcode = RequestCmdCode.SelectPotionDetialCode;
            rpd.content = new ReqLoginName()
            {
                user_id = UserInfoHelper.UserId
            };
            ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rpd));
            if (isClear)
            {
                PositionAllViewModel.Instance().DetPMList.Clear();
                PositionAllViewModel.Instance().PMList.Clear();
                PositionViewModel.Instance().PMList.Clear();
            }
        }
        public void LoginExecuteChanged()
        {
            if (string.IsNullOrEmpty(UserName))
            {
                MessageBox.Show("用户名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(Password))
            {
                MessageBox.Show("用户名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (!string.IsNullOrEmpty(UserNameTemp))
            {
                if (UserNameTemp != UserName || Passwordtemp != Password)
                {
                    MessageBox.Show("用户名或密码不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            _scoketManager = ScoketManager.GetInstance();
            string socketUrl = ConfigurationManager.AppSettings["QuotesAddress"];

            if (!_scoketManager.StartQuotesSocket(socketUrl))
            {
                MessageBox.Show("行情服务器无法连接,请检查服务器,重新登录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (IsSave)
            {
                IniHelper.ProfileWriteValue("User", "Username", UserName, IniHelper.configpath);
                string pasword = RSAEncryption.Encrypt(Password);
                IniHelper.ProfileWriteValue("User", "Password", pasword, IniHelper.configpath);
            }
            else
            {
                IniHelper.ProfileWriteValue("User", "Username", "", IniHelper.configpath);
                IniHelper.ProfileWriteValue("User", "Password", "", IniHelper.configpath);
            }
            KeyCodeValue.AddKeys();
            //MainWindow main = new MainWindow();
            //ContractVariety.main = main;
            //main.Show();
            this.Close();
        }
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     _viewModel = DataContext as QuotesTabControlViewModel;
     if (_viewModel != null)
     {
         _viewModel.ContractChanged -= _viewModel_ContractChanged;
         _viewModel.ContractChanged += _viewModel_ContractChanged;
         Init();
         if (_viewModel.SetSelectItemAction == null)
         {
             _viewModel.SetSelectItemAction = s => { SetSelectItem(s); };
         }
         _scoketManager   = ScoketManager.GetInstance();
         myTimer          = new System.Timers.Timer(200);
         myTimer.Elapsed += myTimer_Elapsed;
         myTimer.Start();
     }
 }
        public void OrderCancelExecuteChanged()
        {
            if (SelectedItem == null)
            {
                MessageBox.Show("请选择删除的行!", "提示");
                return;
            }
            if (MessageBox.Show("是否确定删除该条件单?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                DeleteCondtionModel de = new DeleteCondtionModel();
                de.cmdcode = RequestCmdCode.DeleteConditionBill;

                DeleteModel dm = new DeleteModel();
                dm.condition_orderID = SelectedItem.ConditionOrderID;
                dm.resource          = (int)OperatorTradeType.OPERATOR_TRADE_PC;
                dm.user_id           = UserInfoHelper.UserId;
                de.content           = dm;
                ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(de));
            }
        }
Ejemplo n.º 24
0
        public void AddOptionalData(OptionalContractModel item)
        {
            int seq       = TradeInfoHelper.OptionalModelList.Count;
            var datamodel = TradeInfoHelper.ContractModelList.FirstOrDefault(o => string.Equals(o.contractCode, item.contract_id));

            if (datamodel != null)
            {
                var viewModel = new FuturesViewModel(datamodel);
                viewModel.Seq                  = seq;
                viewModel.IsOptionalStock      = true;
                viewModel.OptionalSerialNumber = item.serial_number;
                QuotationEntity quotesmodel = null;
                lock (TradeInfoHelper.SubscribedContractList)
                {
                    quotesmodel = TradeInfoHelper.SubscribedContractList.FirstOrDefault(o => string.Equals(o.cd, item.contract_id));
                }
                if (quotesmodel != null)
                {
                    ScoketManager.GetInstance().UpdateModelInfo(viewModel, quotesmodel);
                }
                OptionalList.Add(viewModel);
                SetOptionalList();
            }
        }
Ejemplo n.º 25
0
 public TradeLoginBLL()
 {
     scoketManager = ScoketManager.GetInstance();
 }
        public void EnterCommandExecuteChanged()
        {
            ReqConditionBillModel rcbm = new ReqConditionBillModel();

            RConditionBillModel cbm = new RConditionBillModel();

            cbm.resource     = (int)OperatorTradeType.OPERATOR_TRADE_PC;
            cbm.contract_id  = ContractCode;
            cbm.order_price  = Price; //提供
            cbm.order_volume = Num;   //提供
            cbm.user_id      = UserInfoHelper.UserId;
            if (IsBuy)
            {
                cbm.direction = "B";
            }
            else if (IsSell)
            {
                cbm.direction = "S";
            }
            else
            {
                MessageBox.Show("请选择买卖方向", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (IsOpen)
            {
                cbm.open_offset = (int)OffsetType.OFFSET_OPEN;
            }
            else if (IsCloseing)
            {
                cbm.open_offset = (int)OffsetType.OFFSET_COVER;
            }
            else
            {
                MessageBox.Show("请选择买卖方向", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (IsFirst)
            {
                cbm.condition_type = (int)YunConditionType.Y_PRICE;
                cbm.trriger_price  = OrderPrice;
                if (PriceItem == null)
                {
                    MessageBox.Show("请选择触发价格类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                cbm.trriger_price_type = PriceItem.Id;
                if (TrrigerConditionItem == null)
                {
                    MessageBox.Show("请选择触条件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                cbm.trriger_condition = TrrigerConditionItem.Id;
                if (cbm.trriger_price_type == 0)
                {
                    if (cbm.trriger_condition == 0)
                    {
                        if (OrderPrice <= TransactionViewModel.Instance().Futures.Tick.LastPrice)
                        {
                            MessageBox.Show("设置的最新价不能小于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    else
                    {
                        if (OrderPrice >= TransactionViewModel.Instance().Futures.Tick.LastPrice)
                        {
                            MessageBox.Show("设置的最新价不能大于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                }
                else if (cbm.trriger_price_type == 1)
                {
                    if (cbm.trriger_condition == 0)
                    {
                        if (OrderPrice <= TransactionViewModel.Instance().Futures.Tick.BidP1)
                        {
                            MessageBox.Show("设置的买一价不能小于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    else
                    {
                        if (OrderPrice >= TransactionViewModel.Instance().Futures.Tick.BidP1)
                        {
                            MessageBox.Show("设置的买一价不能大于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                }
                else if (cbm.trriger_price_type == 2)
                {
                    if (cbm.trriger_condition == 0)
                    {
                        if (OrderPrice <= TransactionViewModel.Instance().Futures.Tick.AskP1)
                        {
                            MessageBox.Show("设置的卖一价不能小于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    else
                    {
                        if (OrderPrice >= TransactionViewModel.Instance().Futures.Tick.AskP1)
                        {
                            MessageBox.Show("设置的卖一价不能大于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                }
            }
            else if (IsSecond)
            {
                cbm.condition_type  = (int)YunConditionType.Y_TIME;
                cbm.trriger_contime = TrrigerTime;
            }
            else if (IsThird)
            {
                cbm.condition_type = (int)YunConditionType.Y_TIMEPRICE;
                cbm.trriger_price  = OrderPrice3;
                if (PriceItem3 == null)
                {
                    MessageBox.Show("请选择触发价格类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                cbm.trriger_price_type = PriceItem3.Id;
                if (TrrigerConditionItem3 == null)
                {
                    MessageBox.Show("请选择触条件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                cbm.trriger_condition = TrrigerConditionItem3.Id;
                cbm.trriger_contime   = TrrigerTime3;
                if (cbm.trriger_price_type == 0)
                {
                    if (cbm.trriger_condition == 0)
                    {
                        if (OrderPrice3 <= TransactionViewModel.Instance().Futures.Tick.LastPrice)
                        {
                            MessageBox.Show("设置的最新价不能小于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    else
                    {
                        if (OrderPrice3 >= TransactionViewModel.Instance().Futures.Tick.LastPrice)
                        {
                            MessageBox.Show("设置的最新价不能大于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                }
                else if (cbm.trriger_price_type == 1)
                {
                    if (cbm.trriger_condition == 0)
                    {
                        if (OrderPrice3 <= TransactionViewModel.Instance().Futures.Tick.BidP1)
                        {
                            MessageBox.Show("设置的买一价不能小于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    else
                    {
                        if (OrderPrice3 >= TransactionViewModel.Instance().Futures.Tick.BidP1)
                        {
                            MessageBox.Show("设置的买一价不能大于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                }
                else if (cbm.trriger_price_type == 2)
                {
                    if (cbm.trriger_condition == 0)
                    {
                        if (OrderPrice3 <= TransactionViewModel.Instance().Futures.Tick.AskP1)
                        {
                            MessageBox.Show("设置的卖一价不能小于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    else
                    {
                        if (OrderPrice3 >= TransactionViewModel.Instance().Futures.Tick.AskP1)
                        {
                            MessageBox.Show("设置的卖一价不能大于当前的行情最新价", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择条件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            cbm.price_type = typePrice;
            rcbm.content   = cbm;
            if (Upatatecondtion == null)
            {
                rcbm.cmdcode = RequestCmdCode.AddConditionBill;
                ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rcbm));
            }
            else
            {
                rcbm.content.condition_orderID = Upatatecondtion.ConditionOrderID;
                rcbm.content.trriger_condate   = Upatatecondtion.TrrigerCondate;
                rcbm.content.price_type        = Upatatecondtion.PriceType;
                rcbm.cmdcode = RequestCmdCode.UpConditionBill;
                ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rcbm));
            }
        }
        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());
            }
        }
Ejemplo n.º 28
0
        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("设置的止损价不能大于当前的行情最新价", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                                return;
                            }
                            if (cfsm.stopprofit_price <= TransactionViewModel.Instance().Futures.Tick.LastPrice&& cfsm.stopprofit_price != 0)
                            {
                                MessageBox.Show("设置的止盈价不能小于当前的行情最新价", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                                return;
                            }
                        }
                        else
                        {
                            if (cfsm.stoploss_price <= TransactionViewModel.Instance().Futures.Tick.LastPrice&& cfsm.stoploss_price != 0)
                            {
                                MessageBox.Show("设置的止损价不能小于当前的行情最新价", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                                return;
                            }
                            if (cfsm.stopprofit_price >= TransactionViewModel.Instance().Futures.Tick.LastPrice&& cfsm.stopprofit_price != 0)
                            {
                                MessageBox.Show("设置的止盈价不能大于当前的行情最新价", "提示", MessageBoxButton.OK, MessageBoxImage.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("设置的止损价不能大于当前的行情的对手价", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                                return;
                            }
                            if (cfsm.stopprofit_price <= TransactionViewModel.Instance().Futures.Tick.BidP1&& cfsm.stopprofit_price != 0)
                            {
                                MessageBox.Show("设置的止盈价不能小于当前的行情的对手价", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                                return;
                            }
                        }
                        else
                        {
                            if (cfsm.stoploss_price <= TransactionViewModel.Instance().Futures.Tick.AskP1&& cfsm.stoploss_price != 0)
                            {
                                MessageBox.Show("设置的止损价不能小于当前的行情的对手价", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                                return;
                            }
                            if (cfsm.stopprofit_price >= TransactionViewModel.Instance().Futures.Tick.AskP1&& cfsm.stopprofit_price != 0)
                            {
                                MessageBox.Show("设置的止盈价不能大于当前的行情的对手价", "提示", MessageBoxButton.OK, MessageBoxImage.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 (ContractVariety.CFSmvmList.ContainsKey(_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction))
                {
                    ContractVariety.CFSmvmList[_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction].Clear();
                }
                else
                {
                    ContractVariety.CFSmvmList.Add(_PositionModelViewModel.ContractId + _PositionModelViewModel.Direction, new List <CheckFullStopModelViewModel>());
                }

                ContractVariety.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));
                }
            }
        }
Ejemplo n.º 29
0
 public ContractBLL()
 {
     scoketManager = ScoketManager.GetInstance();
 }
        public void ExecutePositionDetialData(object para)
        {
            try
            {
                PotionDetailModel    pm   = para as PotionDetailModel;
                PositionAllViewModel pavm = PositionAllViewModel.Instance();
                if (pavm.DetPMList.FirstOrDefault(x => x.PsitionId == pm.position_id) != null)
                {
                    return;
                }
                if (pm.bLast)
                {
                    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)
                    {
                        foreach (PotionDetailModelViewModel item in dicod.Values)
                        {
                            pavm.PMList.Add(item);
                            PositionViewModel.Instance().PMList.Add(item);
                        }
                    }
                    ScoketManager.GetInstance().SendSubscribeInfo(7, MainViewModel.GetInstance().SubscribedStocks);
                    //发送命令
                    ReqPotion rp = new ReqPotion();
                    rp.cmdcode = RequestCmdCode.SelectStopLoss;
                    rp.content = new ReqLoginName()
                    {
                        user_id = UserInfoHelper.UserId
                    };
                    ScoketManager.GetInstance().SendTradeWSInfo(JsonConvert.SerializeObject(rp));
                    //PositionViewModel.Instance().JSAbleVolume();
                    TransactionViewModel.Instance().FigureUpNum(TransactionViewModel.Instance()._futures);
                    return;
                }

                VarietyModel vm     = null;
                string[]     values = pm.contract_id.Split(' ');
                if (values.Length == 3)
                {
                    string varietie = values[1];
                    if (ContractVariety.Varieties.ContainsKey(varietie))
                    {
                        vm = ContractVariety.Varieties[varietie];
                    }
                    if (vm != null)
                    {
                        pm.precision = vm.precision;
                    }
                }

                PotionDetailModelViewModel pvm = new PotionDetailModelViewModel(pm);
                pavm.DetPMList.Add(pvm);
            }
            catch (Exception ex)
            {
                LogHelper.Info(ex.ToString());
            }
        }