/// <summary>
        /// 监控方法
        /// </summary>
        /// <param name="model"></param>
        private void AllMonitor(StockConfigModel model)
        {
            if (model != null && model.Monitoring)
            {
                if (model.LimitBuyTime)
                {
                    if (DateTime.Parse(DateTime.Now.ToLongTimeString()) >= DateTime.Parse(model.BuyBeginTime.ToLongTimeString()) && DateTime.Parse(DateTime.Now.ToLongTimeString()) < DateTime.Parse(model.BuyEndTime.ToLongTimeString()))
                    {
                        Monitoring(model, TradeTypeEnum.Buy);
                    }
                }
                else
                {
                    Monitoring(model, TradeTypeEnum.Buy);
                }

                if (model.LimitSaleTime)
                {
                    if (DateTime.Parse(DateTime.Now.ToLongTimeString()) >= DateTime.Parse(model.SaleBeginTime.ToLongTimeString()) && DateTime.Parse(DateTime.Now.ToLongTimeString()) < DateTime.Parse(model.SaleEndTime.ToLongTimeString()))
                    {
                        Monitoring(model, TradeTypeEnum.Sale);
                    }
                }
                else
                {
                    Monitoring(model, TradeTypeEnum.Sale);
                }
            }
        }
        private void DownLoad()
        {
            try
            {
                LoadConfig();
                string filepath = "";
                if (Utils.DownloadFile(Utils.FileNameAoto))
                {
                    filepath = Utils.FileNameAoto;

                    string json = File.ReadAllText(filepath);

                    StockConfigModel configModel = Newtonsoft.Json.JsonConvert.DeserializeObject(json, typeof(StockConfigModel)) as StockConfigModel;

                    BindData(configModel);

                    SetMessage("下载成功," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    MessageBox.Show("下载文件出现错误", "注意", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("下载文件出现错误,{0}", ex.Message);
                MessageBox.Show("下载文件出现错误", "注意", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// 从数据容器获取实体model
        /// </summary>
        /// <returns></returns>
        private StockConfigModel GetModelFromDataContainer()
        {
            StockConfigModel model = new StockConfigModel();

            model.AvailableBalance = Convert.ToInt32(txtBalance.Text);
            model.LimitBuyTime     = chkLimitBuyTime.Checked;
            model.LimitSaleTime    = chkLimitSaleTime.Checked;
            model.BuyBeginTime     = dtBuyBeginTime.Value;
            model.BuyEndTime       = dtBuyEndTime.Value;
            model.SaleBeginTime    = dtSaleBeginTime.Value;
            model.SaleEndTime      = dtSaleEndTime.Value;
            model.Monitoring       = lblMonitor.Text == "正在监控..." ? true : false;
            List <StockList> list = new List <StockList>();

            for (int i = 0; i < dataGrid.Rows.Count; i++)
            {
                DataGridViewCellCollection cells = dataGrid.Rows[i].Cells;
                if (cells[txtStockCode].Value != null && cells[txtStockName].Value != null)
                {
                    if (cells[txtStockCode].Value.ToString() != "" && cells[txtStockName].Value.ToString() != "")
                    {
                        list.Add(new StockList {
                            StockCode = cells[txtStockCode].Value.ToString(), StockName = cells[txtStockName].Value.ToString(), BuyPrice = Convert.ToDecimal(cells[txtBuyPrice].Value), BuyAmount = Convert.ToInt32(cells[txtBuyAmount].Value), Monitor = cells[txtMonitor].Value.ToString()
                        });
                    }
                }
            }
            model.StockList = list;
            return(model);
        }
Exemple #4
0
        public MdiForm(string code, string name, string buyamount, string buyprice, string buyvariabletrend, string buyvariableamount, string saleamount, string saleprice, string salevariabletrend, string salevariableamount, StockConfigModel configModel, DataGridView DataGrid, int rowindex)
        {
            InitializeComponent();

            List <DictionaryEntry> buyVarTrendList = new List <DictionaryEntry>();

            buyVarTrendList.Add(new DictionaryEntry(BuyVariableTrendEnum.ReachOrUp.GetEnumDescription(), (int)BuyVariableTrendEnum.ReachOrUp));
            buyVarTrendList.Add(new DictionaryEntry(BuyVariableTrendEnum.ReachOrDown.GetEnumDescription(), (int)BuyVariableTrendEnum.ReachOrDown));
            buyVarTrendList.Add(new DictionaryEntry(BuyVariableTrendEnum.DownThenRebound.GetEnumDescription(), (int)BuyVariableTrendEnum.DownThenRebound));
            buyVarTrendList.Add(new DictionaryEntry(BuyVariableTrendEnum.DownThenUp.GetEnumDescription(), (int)BuyVariableTrendEnum.DownThenUp));
            cbxBuyVarTrend.DataSource    = buyVarTrendList;
            cbxBuyVarTrend.ValueMember   = "Value";
            cbxBuyVarTrend.DisplayMember = "Key";

            List <DictionaryEntry> SaleVarTrendList = new List <DictionaryEntry>();

            SaleVarTrendList.Add(new DictionaryEntry(SaleVariableTrendEnum.ReachOrUp.GetEnumDescription(), (int)SaleVariableTrendEnum.ReachOrUp));
            SaleVarTrendList.Add(new DictionaryEntry(SaleVariableTrendEnum.ReachOrDown.GetEnumDescription(), (int)SaleVariableTrendEnum.ReachOrDown));
            SaleVarTrendList.Add(new DictionaryEntry(SaleVariableTrendEnum.UpThenFallBack.GetEnumDescription(), (int)SaleVariableTrendEnum.UpThenFallBack));
            SaleVarTrendList.Add(new DictionaryEntry(SaleVariableTrendEnum.UpThenDown.GetEnumDescription(), (int)SaleVariableTrendEnum.UpThenDown));
            cbxSaleVarTrend.DataSource    = SaleVarTrendList;
            cbxSaleVarTrend.ValueMember   = "Value";
            cbxSaleVarTrend.DisplayMember = "Key";
            if (code == "")
            {
                this.Text = "添加证券";
                cbxBuyVarTrend.SelectedValue  = (int)BuyVariableTrendEnum.ReachOrDown;
                cbxSaleVarTrend.SelectedValue = (int)SaleVariableTrendEnum.ReachOrUp;
                txtBuyVarAmount.Text          = "0";
                txtSaleVarAmount.Text         = "0";
                txtCode.ReadOnly = false;
            }
            else
            {
                this.Text = "修改信息";
                cbxBuyVarTrend.SelectedValue  = int.Parse(buyvariabletrend);
                cbxSaleVarTrend.SelectedValue = int.Parse(salevariabletrend);
                txtCode.Text                     = code;
                txtName.Text                     = name;
                txtBuyAmount.Text                = buyamount;
                txtBuyPrice.Text                 = buyprice;
                txtBuyVarAmount.Text             = buyvariableamount;
                txtSaleAmount.Text               = saleamount;
                txtSalePrice.Text                = saleprice;
                txtSaleVarAmount.Text            = salevariableamount;
                txtBalance.Text                  = (decimal.Parse(buyprice) * int.Parse(buyamount)).ToString();
                cbxBuyChooseAmount.DataSource    = CalculateBuyStore();
                cbxBuyChooseAmount.ValueMember   = "Value";
                cbxBuyChooseAmount.DisplayMember = "Key";
                txtCode.ReadOnly                 = true;
            }
            mainConfigModel = configModel;
            mainDataGrid    = DataGrid;
            RowIndexSelect  = rowindex;
        }
 private void dataGrid_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Delete)
     {
         StockConfigModel model = GetModelFromDataContainer();
         if (dataGrid.CurrentRow.Index != dataGrid.Rows.Count - 1)
         {
             model.StockList.RemoveAt(dataGrid.CurrentRow.Index);
             BindData(model);
         }
     }
 }
 /// <summary>
 /// 根据策略得到购买价格
 /// </summary>
 /// <param name="config"></param>
 /// <param name="stock"></param>
 /// <returns></returns>
 private decimal GetBuyPriceByTactics(StockConfigModel config, StockList stock)
 {
     if (config.UseGapLowerTactics)
     {
         StockModel model = GetInfo.Get(stock.StockCode);
         if (model.YesterdayEndPrice / model.TodayBeginPrice >= 1.01M)
         {
             return(Math.Round(stock.BuyPrice * (1 - (model.TodayBeginPrice / model.YesterdayEndPrice)), 2));
         }
     }
     return(stock.BuyPrice);
 }
        private void btnStop_Click(object sender, EventArgs e)
        {
            Boolean flag = (btnStop.Text == "停止监控");

            btnStop.Text = flag ? "开始监控" : "停止监控";

            lblMonitor.Text = flag ? "正在监控..." : "监控已停止...";
            StockConfigModel model = GetModelFromDataContainer();

            model.StockList.ForEach(x => x.Monitor = flag ? "已停止" : "监控中");
            BindData(model);
        }
        public Main()
        {
            InitializeComponent();
            LoadConfig();
            mac = new Mac(AK, SK);
            //Control.CheckForIllegalCrossThreadCalls = false;
            model = Download(Utils.FileNameAoto);
            BindData(model);

            #region 交易线程
            thread = new Thread(CrossThreadFlush);
            thread.IsBackground = true;
            thread.Start();
            #endregion
        }
 /// <summary>
 /// 关闭电脑
 /// </summary>
 /// <param name="model"></param>
 private void CloseComputer(StockConfigModel model)
 {
     if (model != null && model.CloseComputerTime.Date == DateTime.Today && DateTime.Now >= model.CloseComputerTime)
     {
         lblMessage.Text = "正在关闭...";
         #region 发送邮件通知
         SendMail(lblMessage.Text, "");
         #endregion
         #region 开关关闭
         model.CloseComputerTime = DateTime.MinValue;
         UploadFile(model);
         #endregion
         Thread.Sleep(2000);
         DoExitWin(EWX_SHUTDOWN);
     }
 }
Exemple #10
0
 private void Monitoring(StockConfigModel model, TradeTypeEnum type)
 {
     foreach (StockList stock in model.StockList)
     {
         if (stock.Monitor == "监控中")
         {
             if (type == TradeTypeEnum.Buy)
             {
                 reachBuyCondition(model, stock);
             }
             else
             {
                 reachSaleCondition(model, stock);
             }
         }
     }
 }
Exemple #11
0
        private Boolean SaveAsDefaultFile(string filename, StockConfigModel model)
        {
            //if (GetTrueCondition())
            //{
            try
            {
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(model);

                File.WriteAllText(filename, json);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
            //}
        }
Exemple #12
0
        private void BindData(StockConfigModel configModel)
        {
            int Cnt = 0;

            foreach (StockList ll in configModel.StockList)
            {
                StockModel infoModel = GetInfo.Get(ll.StockCode);
                if (infoModel != null)
                {
                    ll.CurrentPrice = infoModel.CurrentPrice;
                }
                else
                {
                    ll.CurrentPrice = 0;
                }

                ll.BuyStrategy  = string.Format("{0}{1}元", ((BuyVariableTrendEnum)ll.BuyVariableTrend).GetEnumDescription(), ll.BuyVariableAmount);
                ll.SaleStrategy = string.Format("{0}{1}元", ((SaleVariableTrendEnum)ll.SaleVariableTrend).GetEnumDescription(), ll.SaleVariableAmount);

                if (ll.Monitor == "监控中")
                {
                    Cnt++;
                }
            }

            configModel.StockList.Add(new StockList {
                StockCode = "", StockName = "", BuyPrice = 0, BuyAmount = 0, CurrentPrice = 0, SalePrice = 0, SaleAmount = 0, Monitor = ""
            });
            dataGrid.DataSource      = configModel.StockList;
            txtBalance.Text          = configModel.AvailableBalance.ToString();
            chkLimitBuyTime.Checked  = configModel.LimitBuyTime;
            chkLimitSaleTime.Checked = configModel.LimitSaleTime;
            dtBuyBeginTime.Value     = configModel.BuyBeginTime;
            dtBuyEndTime.Value       = configModel.BuyEndTime;
            dtSaleBeginTime.Value    = configModel.SaleBeginTime;
            dtSaleEndTime.Value      = configModel.SaleEndTime;
            btnStop.Visible          = true;
            lblMonitor.Visible       = true;
            cbxSoft.SelectedIndex    = configModel.TradeSoftWare;
            btnStop.Text             = Cnt > 0 ? "停止监控" : "开始监控";
            lblMonitor.Text          = Cnt > 0 ? "正在监控..." : "监控已停止...";
            btnCloseComputer.Text    = configModel.CloseComputerTime == DateTime.MinValue ? "关闭电脑" : "取消关闭";
            chkGapLower.Checked      = configModel.UseGapLowerTactics;
        }
Exemple #13
0
        private StockConfigModel GetModelFromDataContainer()
        {
            StockConfigModel model = new StockConfigModel();

            model.AvailableBalance = Convert.ToInt32(txtBalance.Text);
            model.LimitBuyTime     = chkLimitBuyTime.Checked;
            model.LimitSaleTime    = chkLimitSaleTime.Checked;
            model.BuyBeginTime     = dtBuyBeginTime.Value;
            model.BuyEndTime       = dtBuyEndTime.Value;
            model.SaleBeginTime    = dtSaleBeginTime.Value;
            model.SaleEndTime      = dtSaleEndTime.Value;
            model.TradeSoftWare    = cbxSoft.SelectedIndex;
            //关机设置
            model.CloseComputerTime = (btnCloseComputer.Text == "取消关闭") ? DateTime.Now : DateTime.MinValue;
            int Cnt = 0;



            List <StockList> list = new List <StockList>();

            for (int i = 0; i < dataGrid.Rows.Count; i++)
            {
                DataGridViewCellCollection cells = dataGrid.Rows[i].Cells;
                if (cells[txtStockCode].Value != null && cells[txtStockName].Value != null)
                {
                    if (cells[txtStockCode].Value.ToString() != "" && cells[txtStockName].Value.ToString() != "")
                    {
                        list.Add(new StockList {
                            StockCode = cells[txtStockCode].Value.ToString(), StockName = cells[txtStockName].Value.ToString(), BuyPrice = Convert.ToDecimal(cells[txtBuyPrice].Value), BuyAmount = Convert.ToInt32(cells[txtBuyAmount].Value), Monitor = cells[txtMonitor].Value.ToString(), BuyVariableTrend = Convert.ToInt32(cells[txtBuyVariableTrend].Value), BuyVariableAmount = Convert.ToDecimal(cells[txtBuyVariableAmount].Value), SalePrice = Convert.ToDecimal(cells[txtSalePrice].Value), SaleAmount = Convert.ToInt32(cells[txtSaleAmount].Value), SaleVariableTrend = Convert.ToInt32(cells[txtSaleVariableTrend].Value), SaleVariableAmount = Convert.ToDecimal(cells[txtSaleVariableAmount].Value)
                        });
                        if (cells[txtMonitor].Value.ToString() == "监控中")
                        {
                            Cnt++;
                        }
                    }
                }
            }

            model.Monitoring         = Cnt > 0 ? true : false;
            model.StockList          = list;
            model.UseGapLowerTactics = chkGapLower.Checked;
            return(model);
        }
Exemple #14
0
        private void UploadFile(StockConfigModel model)
        {
            try
            {
                SaveFileFlag = SaveAsDefaultFile(Utils.FileNameAoto, model);
                // 本地文件
                string localFile = Utils.FileNameAoto;
                // 上传策略
                PutPolicy putPolicy = new PutPolicy();
                // 设置要上传的目标空间
                putPolicy.Scope = Utils.bucket;
                // 上传策略的过期时间(单位:秒)
                putPolicy.SetExpires(3600);
                // 文件上传完毕后,在多少天后自动被删除
                //putPolicy.DeleteAfterDays = 1;
                // 请注意这里的Zone设置(如果不设置,就默认为华东机房)
                var zoneId = Qiniu.Common.AutoZone.Query(AK, Utils.bucket);
                Qiniu.Common.Config.ConfigZone(zoneId);
                //Mac mac = new Mac(AK, SK); // Use AK & SK here
                // 生成上传凭证
                string        uploadToken   = Auth.createUploadToken(putPolicy, mac);
                UploadOptions uploadOptions = null;

                // 上传完毕事件处理
                UpCompletionHandler uploadCompleted = new UpCompletionHandler(OnUploadCompleted);
                // 方式1:使用UploadManager
                //默认设置 Qiniu.Common.Config.PUT_THRESHOLD = 512*1024;
                //可以适当修改,UploadManager会根据这个阈值自动选择是否使用分片(Resumable)上传
                UploadManager um = new UploadManager();

                DelFileFlag = DelFile(Utils.FileNameAoto);

                um.uploadFile(localFile, Utils.FileNameAoto, uploadToken, uploadOptions, uploadCompleted);
                // 方式2:使用FormManager
                //FormUploader fm = new FormUploader();
                //fm.uploadFile(localFile, saveKey, token, uploadOptions, uploadCompleted);
            }
            catch (Exception ex)
            {
                string text = "上传文件出现错误" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                log.ErrorFormat(text, ex.Message);
            }
        }
Exemple #15
0
        private void BindData(StockConfigModel configModel)
        {
            if (configModel != null)
            {
                int Cnt = 0;
                foreach (StockList ll in configModel.StockList)
                {
                    StockModel smodel = GetInfo.Get(ll.StockCode);
                    ll.CurrentPrice = smodel.CurrentPrice;

                    ll.BuyStrategy  = string.Format("{0}{1}元", ((BuyVariableTrendEnum)ll.BuyVariableTrend).GetEnumDescription(), ll.BuyVariableAmount);
                    ll.SaleStrategy = string.Format("{0}{1}元", ((SaleVariableTrendEnum)ll.SaleVariableTrend).GetEnumDescription(), ll.SaleVariableAmount);
                    if (ll.CurrentPrice >= smodel.YesterdayEndPrice)
                    {
                        ll.IncreaseAmt = string.Format("{0}", Math.Round((ll.CurrentPrice / smodel.YesterdayEndPrice - 1) * 100, 2));
                    }
                    else
                    {
                        ll.IncreaseAmt = string.Format("-{0}", Math.Round((1 - ll.CurrentPrice / smodel.YesterdayEndPrice) * 100, 2));
                    }
                    if (ll.Monitor == "监控中")
                    {
                        Cnt++;
                    }
                }

                dataGrid.DataSource = configModel.StockList;
                dataGrid.Refresh();
                txtBalance.Text          = configModel.AvailableBalance.ToString();
                chkLimitBuyTime.Checked  = configModel.LimitBuyTime;
                chkLimitSaleTime.Checked = configModel.LimitSaleTime;
                dtBuyBeginTime.Value     = configModel.BuyBeginTime;
                dtBuyEndTime.Value       = configModel.BuyEndTime;
                dtSaleBeginTime.Value    = configModel.SaleBeginTime;
                dtSaleEndTime.Value      = configModel.SaleEndTime;
                lblMonitor.Visible       = true;
                lblMonitor.Text          = Cnt > 0 ? "正在监控..." : "监控已停止...";
                cbxSoft.SelectedIndex    = configModel.TradeSoftWare;
                chkGapLower.Checked      = configModel.UseGapLowerTactics;
            }
        }
Exemple #16
0
 private void ThreadFunction()
 {
     if (this.dataGrid.InvokeRequired)//等待异步
     {
         FlushClient fc = new FlushClient(ThreadFunction);
         this.Invoke(fc); //通过代理调用刷新方法
     }
     else
     {
         try
         {
             model = CanDownload(Utils.FileNameAoto, mac);
             CloseComputer(model);
             BindData(model);
             AllMonitor(model);
         }
         catch (Exception ex)
         {
             log.ErrorFormat("监控出错,{0}", ex.Message);
         }
     }
 }
Exemple #17
0
        /// <summary>
        /// 达到卖出条件
        /// </summary>
        /// <param name="model">全量数据model</param>
        /// <param name="stock">监控中的证券model</param>
        private void reachSaleCondition(StockConfigModel model, StockList stock)
        {
            //decimal currentPrice = GetInfo.Get(stock.StockCode).CurrentPrice;//实时再获取一次
            decimal currentPrice = stock.CurrentPrice;//和绑定Grid的数据保持一致

            if (CurrentCanTrade(model, stock, TradeTypeEnum.Sale) && currentPrice != 0 && stock.SaleAmount != 0)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                Boolean flagTrade = false;
                if (cbxSoft.SelectedIndex == 0)
                {
                    flagTrade = ZhaoShangZhiYuanTrade(stock, TradeTypeEnum.Sale);
                }
                else
                {
                    flagTrade = JQKA(stock, TradeTypeEnum.Sale);
                }
                sw.Stop();

                if (flagTrade)
                {
                    int saleamount = stock.SaleAmount;

                    Task.Factory.StartNew(() =>
                    {
                        SendTradeSuccessMail(saleamount, stock, sw, TradeTypeEnum.Sale);
                    });

                    voice.Speak(string.Format(config.SaleSuccessVoice, stock.StockName, stock.CurrentPrice), SSF);

                    model.AvailableBalance = Convert.ToInt32(Math.Floor(model.AvailableBalance + (stock.CurrentPrice * stock.SaleAmount)));//计算剩余金额
                    stock.SaleAmount       = 0;
                    stock.Monitor          = "已停止";

                    UploadFile(model);
                }
            }
        }
Exemple #18
0
        private StockConfigModel Download(string FileNameAoto)
        {
            string filepath = "";

            if (Utils.DownloadFile(FileNameAoto))
            {
                filepath = FileNameAoto;

                string json = File.ReadAllText(filepath);

                StockConfigModel configModel = Newtonsoft.Json.JsonConvert.DeserializeObject(json, typeof(StockConfigModel)) as StockConfigModel;

                SetMessage("下载文件转换成功," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                log.DebugFormat(lblMessage.Text);

                return(configModel);
            }
            else
            {
                SetMessage("下载文件出现错误," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                log.ErrorFormat(lblMessage.Text);
                return(null);
            }
        }
Exemple #19
0
        private void dataGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                var cell = dataGrid.Rows[e.RowIndex].Cells[0].Value;

                if (cell == null)
                {
                    return;
                }
                string code = cell.ToString();
                if (code.Length == 6)
                {
                    StockModel model = GetInfo.Get(code);
                    if (model != null)
                    {
                        bool flag = false;
                        for (int j = 0; j < dataGrid.Rows.Count; j++)
                        {
                            if (j != e.RowIndex)
                            {
                                if (dataGrid.Rows[j].Cells[txtStockCode].Value != null)
                                {
                                    if (dataGrid.Rows[j].Cells[txtStockCode].Value.ToString() == dataGrid.Rows[e.RowIndex].Cells[txtStockCode].Value.ToString())
                                    {
                                        flag = true; break;
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            MessageBox.Show("证券信息重复!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            ClearRow(e.RowIndex);
                        }
                        else
                        {
                            dataGrid.Rows[e.RowIndex].Cells[txtStockName].Value = model.Name;
                            dataGrid.Rows[e.RowIndex].Cells[txtBuyPrice].Value  = model.CurrentPrice;
                            SetFull_Stock();
                            dataGrid.Rows[e.RowIndex].Cells[txtMonitor].Value           = "已停止";//默认值
                            dataGrid.Rows[e.RowIndex].Cells[txtBuyVariableTrend].Value  = (int)BuyVariableTrendEnum.ReachOrDown;
                            dataGrid.Rows[e.RowIndex].Cells[txtBuyVariableAmount].Value = 0.00M;
                            dataGrid.Rows[e.RowIndex].Cells[txtBuyStrategy].Value       = string.Format("{0}{1}元", BuyVariableTrendEnum.ReachOrDown.GetEnumDescription(), 0);

                            dataGrid.Rows[e.RowIndex].Cells[txtSalePrice].Value          = Math.Round(model.CurrentPrice * 1.04M, 2);
                            dataGrid.Rows[e.RowIndex].Cells[txtSaleAmount].Value         = 0;//默认值
                            dataGrid.Rows[e.RowIndex].Cells[txtSaleVariableTrend].Value  = (int)SaleVariableTrendEnum.ReachOrUp;
                            dataGrid.Rows[e.RowIndex].Cells[txtSaleVariableAmount].Value = 0.00M;
                            dataGrid.Rows[e.RowIndex].Cells[txtSaleStrategy].Value       = string.Format("{0}{1}元", SaleVariableTrendEnum.ReachOrUp.GetEnumDescription(), 0);
                        }
                    }
                    else
                    {
                        MessageBox.Show("获取信息失败!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        ClearRow(e.RowIndex);
                    }
                }
                else
                {
                    ClearRow(e.RowIndex);
                    StockConfigModel model = GetModelFromDataContainer();
                    BindData(model);
                }
            }
            if (e.RowIndex == dataGrid.Rows.Count - 1)
            {
                DataGridViewCellCollection cells = dataGrid.Rows[e.RowIndex].Cells;
                if (cells[txtStockCode].Value != null && cells[txtStockCode].Value.ToString() != "" && cells[txtStockName].Value.ToString() != "")
                {
                    StockConfigModel model = GetModelFromDataContainer();
                    BindData(model);
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// 是否能下单
        /// </summary>
        /// <param name="model"></param>
        /// <param name="stock"></param>
        /// <returns></returns>
        private bool CurrentCanTrade(StockConfigModel model, StockList stock, TradeTypeEnum type)
        {
            if (type == TradeTypeEnum.Buy)
            {
                if (stock.BuyVariableTrend != 0)
                {
                    if (stock.BuyVariableTrend == (int)BuyVariableTrendEnum.ReachOrDown)
                    {
                        return(stock.CurrentPrice <= GetBuyPriceByTactics(model, stock));
                    }
                    else if (stock.BuyVariableTrend == (int)BuyVariableTrendEnum.DownThenRebound)
                    {
                        if (stock.BuyPrice - stock.CurrentPrice >= stock.BuyVariableAmount)
                        {
                            stock.BuyMarkPrice = stock.CurrentPrice;
                        }

                        if (stock.CurrentPrice - stock.BuyMarkPrice >= stock.BuyVariableAmount)
                        {
                            return(true);
                        }
                    }
                    else if (stock.BuyVariableTrend == (int)BuyVariableTrendEnum.DownThenUp)
                    {
                        if (stock.BuyMarkPrice == 0)
                        {
                            if (stock.BuyPrice - stock.CurrentPrice >= stock.BuyVariableAmount)
                            {
                                stock.BuyMarkPrice = stock.CurrentPrice;
                            }
                        }
                        else
                        {
                            if (stock.BuyMarkPrice - stock.CurrentPrice >= stock.BuyVariableAmount)
                            {
                                stock.BuyMarkPrice = stock.CurrentPrice;
                            }
                        }

                        if (stock.CurrentPrice - stock.BuyMarkPrice >= stock.BuyVariableAmount)
                        {
                            return(true);
                        }
                    }
                    else if (stock.BuyVariableTrend == (int)BuyVariableTrendEnum.ReachOrUp)
                    {
                        return(stock.CurrentPrice >= stock.BuyPrice);
                    }
                }
            }
            else
            {
                if (stock.SaleVariableTrend != 0)
                {
                    if (stock.SaleVariableTrend == (int)SaleVariableTrendEnum.ReachOrDown)
                    {
                        return(stock.CurrentPrice <= stock.SalePrice);
                    }
                    else if (stock.SaleVariableTrend == (int)SaleVariableTrendEnum.UpThenFallBack)
                    {
                        if (stock.CurrentPrice - stock.SalePrice >= stock.SaleVariableAmount)
                        {
                            stock.SaleMarkPrice = stock.CurrentPrice;
                        }

                        if (stock.SaleMarkPrice - stock.CurrentPrice >= stock.SaleVariableAmount)
                        {
                            return(true);
                        }
                    }
                    else if (stock.SaleVariableTrend == (int)SaleVariableTrendEnum.UpThenDown)
                    {
                        if (stock.SaleMarkPrice == 0)
                        {
                            if (stock.CurrentPrice - stock.SalePrice >= stock.SaleVariableAmount)
                            {
                                stock.SaleMarkPrice = stock.CurrentPrice;
                            }
                        }
                        else
                        {
                            if (stock.CurrentPrice - stock.SaleMarkPrice >= stock.SaleVariableAmount)
                            {
                                stock.SaleMarkPrice = stock.CurrentPrice;
                            }
                        }

                        if (stock.SaleMarkPrice - stock.CurrentPrice >= stock.SaleVariableAmount)
                        {
                            return(true);
                        }
                    }
                    else if (stock.SaleVariableTrend == (int)SaleVariableTrendEnum.ReachOrUp)
                    {
                        return(stock.CurrentPrice >= stock.SalePrice);
                    }
                }
            }
            return(false);
        }