Exemplo n.º 1
0
        /// <summary>
        /// 添加指标行
        /// </summary>
        private void AddIndicatorRows()
        {
            List <SecurityFilterInfo> infos = new List <SecurityFilterInfo>();

            m_task.GetSecurityInfos(infos);
            m_gridFilterResult.BeginUpdate();
            int infosSize = infos.Count;

            for (int i = 0; i < infosSize; i++)
            {
                SecurityFilterInfo      info = infos[i];
                SecurityFilterResultRow row  = new SecurityFilterResultRow();
                row.Height = 30;
                row.Info   = info;
                m_gridFilterResult.AddRow(row);
                SecurityFilterResultDoubleCell noCell = new SecurityFilterResultDoubleCell();
                row.AddCell(0, noCell);
                SecurityFilterResultStringCell nameCell = new SecurityFilterResultStringCell();
                nameCell.Text = info.Security.m_name;
                row.AddCell(1, nameCell);
                SecurityFilterResultDoubleCell closeCell = new SecurityFilterResultDoubleCell();
                row.AddCell(2, closeCell);
                SecurityFilterResultDoubleCell diffCell = new SecurityFilterResultDoubleCell();
                row.AddCell(3, diffCell);
                SecurityFilterResultDoubleCell volumeCell = new SecurityFilterResultDoubleCell();
                row.AddCell(4, volumeCell);
                SecurityFilterResultDoubleCell highCell = new SecurityFilterResultDoubleCell();
                row.AddCell(5, highCell);
                SecurityFilterResultDoubleCell lowCell = new SecurityFilterResultDoubleCell();
                row.AddCell(6, lowCell);
                SecurityFilterResultDoubleCell buyCell = new SecurityFilterResultDoubleCell();
                row.AddCell(7, buyCell);
                SecurityFilterResultDoubleCell sellCell = new SecurityFilterResultDoubleCell();
                row.AddCell(8, sellCell);
                SecurityFilterResultDoubleCell diffRange = new SecurityFilterResultDoubleCell();
                row.AddCell(9, diffRange);
                SecurityFilterResultDoubleCell openCell = new SecurityFilterResultDoubleCell();
                row.AddCell(10, openCell);
                SecurityFilterResultStringCell codeCell = new SecurityFilterResultStringCell();
                codeCell.Style.Font = new FONT("Arial", 14, false, false, false);
                codeCell.Text       = info.Security.m_code;
                row.AddCell(11, codeCell);
                SecurityFilterResultDoubleCell lastCloseCell = new SecurityFilterResultDoubleCell();
                row.AddCell(12, lastCloseCell);
                SecurityFilterResultDoubleCell amountCell = new SecurityFilterResultDoubleCell();
                row.AddCell(13, amountCell);
                CIndicator indicator = m_task.Indicator;
                int        index     = 14;
                foreach (String name in indicator.MainVariables.Keys)
                {
                    SecurityFilterResultDoubleCell indicatorCell = new SecurityFilterResultDoubleCell();
                    indicatorCell.FieldName = name;
                    row.AddCell(index, indicatorCell);
                    index++;
                }
            }
            m_gridFilterResult.EndUpdate();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 重绘方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="rect">矩形</param>
        /// <param name="clipRect">裁剪矩形</param>
        /// <param name="isAlternate">是否交替行</param>
        public override void OnPaint(CPaint paint, RECT rect, RECT clipRect, bool isAlternate)
        {
            int clipW = clipRect.right - clipRect.left;
            int clipH = clipRect.bottom - clipRect.top;

            if (clipW > 0 && clipH > 0)
            {
                GridA      grid   = Grid;
                GridRow    row    = Row;
                GridColumn column = Column;
                if (grid != null && row != null && column != null)
                {
                    //判断选中
                    String         text             = Text;
                    bool           selected         = false;
                    List <GridRow> selectedRows     = grid.SelectedRows;
                    int            selectedRowsSize = selectedRows.Count;
                    for (int i = 0; i < selectedRowsSize; i++)
                    {
                        if (selectedRows[i] == row)
                        {
                            selected = true;
                            break;
                        }
                    }
                    //获取颜色
                    FONT          font      = null;
                    long          foreColor = COLOR.EMPTY;
                    GridCellStyle style     = Style;
                    if (style != null)
                    {
                        if (style.Font != null)
                        {
                            font = style.Font;
                        }
                        foreColor = style.ForeColor;
                    }
                    SecurityFilterInfo info = (row as SecurityFilterResultRow).Info;
                    if (info.GetValue("FILTER") != 1)
                    {
                        foreColor = CDraw.PCOLORS_FORECOLOR8;
                    }
                    SIZE  tSize  = paint.TextSize(text, font);
                    POINT tPoint = new POINT(rect.left + 1, rect.top + clipH / 2 - tSize.cy / 2);
                    if (column.Name == "colCode")
                    {
                        tPoint.x = rect.right - tSize.cx;
                    }
                    RECT tRect = new RECT(tPoint.x, tPoint.y, tPoint.x + tSize.cx, tPoint.y + tSize.cy);
                    paint.DrawText(text, foreColor, font, tRect);
                    if (selected)
                    {
                        paint.DrawLine(CDraw.PCOLORS_LINECOLOR, 2, 0, rect.left, rect.bottom - 1, rect.right, rect.bottom - 1);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 运行指标
        /// </summary>
        public void Run()
        {
            if (m_chart == null)
            {
                m_chart        = new ChartA();
                m_chart.Native = m_native;
                m_dataSource   = SecurityDataHelper.CreateDataSource(m_chart);
            }
            if (m_indicator != null)
            {
                m_indicator.Dispose();
            }
            String indicator = m_template.m_indicator;

            if (m_template.m_filter != null && m_template.m_filter.Length > 0)
            {
                indicator += "FILTER:=" + m_template.m_filter;
            }
            else
            {
                indicator += "FILTER:=1";
            }
            m_indicator = SecurityDataHelper.CreateIndicator(m_chart, m_dataSource, indicator, m_template.m_parameters);
            m_indicator.OnCalculate(0);
            m_infos.Clear();
            List <Security> securities = new List <Security>();

            DataCenter.SecurityService.GetSecuritiesByCodes(m_template.m_codes, securities);
            int securitiesSize = securities.Count;

            for (int i = 0; i < securitiesSize; i++)
            {
                Security           security = securities[i];
                SecurityFilterInfo info     = new SecurityFilterInfo();
                info.DataSource          = m_dataSource;
                info.Security            = security;
                m_infos[security.m_code] = info;
            }
            LatestDataInfo dataInfo = new LatestDataInfo();

            dataInfo.m_codes      = m_template.m_codes;
            dataInfo.m_formatType = 1;
            m_quoteService.PushLatestDatas(m_qtRequestID, dataInfo);
            m_securityFilterService.StartFilter(m_sfRequestID, m_template);
            m_runningState = 0;
            m_matchCount   = 0;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 表格单元格点击方法
        /// </summary>
        /// <param name="sender">调用者</param>
        /// <param name="cell">单元格</param>
        /// <param name="mp">坐标</param>
        /// <param name="button">按钮</param>
        /// <param name="clicks">点击次数</param>
        /// <param name="delta">滚轮值</param>
        public void OnGridCellDoubleClick(GridCell cell)
        {
            SecurityFilterInfo info = (cell.Row as SecurityFilterResultRow).Info;

            if (info != null && m_chart != null)
            {
                m_chart.Chart.DataSource.Clear();
                SecurityFilterTemplate template = m_task.Template;
                m_chart.DeleteIndicators(true);
                List <CDiv> divs     = m_chart.Chart.GetDivs();
                int         divsSize = divs.Count;
                m_chart.AddMainIndicator(template.m_name, template.m_name, template.m_indicator, template.m_parameters, divs[divsSize - 1], true);
                m_chart.Cycle        = m_task.Template.m_cycle;
                m_chart.Subscription = m_task.Template.m_subscription;
                m_chart.SearchSecurity(info.Security);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// 条件选股回调方法
 /// </summary>
 /// <param name="message">消息</param>
 public void OnSecurityFilterDataCallBack(CMessage message)
 {
     if (message.m_bodyLength > 0)
     {
         int currentBatch = 0, totalBatch = 1;
         if (m_runningState != -1)
         {
             Dictionary <String, double[]> datas = new Dictionary <String, double[]>();
             SecurityFilterService.GetFilterResults(datas, ref currentBatch, ref totalBatch, message.m_body, message.m_bodyLength);
             if (datas.Count > 0)
             {
                 foreach (String code in datas.Keys)
                 {
                     double[] result = datas[code];
                     if (m_infos.ContainsKey(code))
                     {
                         SecurityFilterInfo info = m_infos[code];
                         if (result != null)
                         {
                             int pos = 0;
                             foreach (String name in m_indicator.MainVariables.Keys)
                             {
                                 double value = result[pos];
                                 info.SetValue(name, value);
                                 if (name == "FILTER" && value == 1)
                                 {
                                     m_matchCount++;
                                 }
                                 pos++;
                             }
                         }
                         m_runningState++;
                         info.Completed = true;
                     }
                 }
             }
             datas.Clear();
         }
         if (currentBatch == totalBatch)
         {
             m_runningState = -1;
         }
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// 重绘方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="rect">矩形</param>
        /// <param name="clipRect">裁剪矩形</param>
        /// <param name="isAlternate">是否交替行</param>
        public override void OnPaint(CPaint paint, RECT rect, RECT clipRect, bool isAlternate)
        {
            int clipW = clipRect.right - clipRect.left;
            int clipH = clipRect.bottom - clipRect.top;

            if (clipW > 0 && clipH > 0)
            {
                GridA      grid   = Grid;
                GridRow    row    = Row;
                GridColumn column = Column;
                if (grid != null && row != null && column != null)
                {
                    //判断选中
                    String         text             = "-";
                    bool           selected         = false;
                    List <GridRow> selectedRows     = grid.SelectedRows;
                    int            selectedRowsSize = selectedRows.Count;
                    for (int i = 0; i < selectedRowsSize; i++)
                    {
                        if (selectedRows[i] == row)
                        {
                            selected = true;
                            break;
                        }
                    }
                    //获取颜色
                    FONT          font      = null;
                    long          foreColor = COLOR.EMPTY;
                    GridCellStyle style     = Style;
                    if (style != null)
                    {
                        foreColor = style.ForeColor;
                        if (style.Font != null)
                        {
                            font = style.Font;
                        }
                    }
                    SecurityFilterInfo info  = (row as SecurityFilterResultRow).Info;
                    double             value = GetDouble();
                    if (!double.IsNaN(value))
                    {
                        if (m_fieldName != null && m_fieldName.Length > 0)
                        {
                            if (m_fieldName == "FILTER")
                            {
                                if (value == 1)
                                {
                                    foreColor = CDraw.PCOLORS_FORECOLOR9;
                                    text      = "是";
                                }
                                else
                                {
                                    foreColor = CDraw.PCOLORS_FORECOLOR7;
                                    text      = "否";
                                }
                            }
                            else
                            {
                                foreColor = CDraw.GetPriceColor(value, 0);
                                text      = value.ToString("0.0000");
                            }
                        }
                        else
                        {
                            SecurityLatestData data       = info.LatestData;
                            String             columnName = column.Name;
                            int dataSize = data != null ? data.m_securityCode.Length : 0;
                            if (columnName == "colNo")
                            {
                                foreColor = CDraw.PCOLORS_FORECOLOR7;
                                text      = ((int)value + 1).ToString();
                            }
                            else if (columnName == "colAmount" || columnName == "colVolume")
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.PCOLORS_FORECOLOR9;
                                    text      = ((long)value).ToString();
                                }
                            }
                            else if (columnName == "colDiff")
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.GetPriceColor(value, 0);
                                    text      = value.ToString("0.00");
                                }
                            }
                            else if (columnName == "colDiffRange")
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.GetPriceColor(data.m_close, data.m_lastClose);
                                    text      = value.ToString("0.00") + "%";
                                }
                            }
                            else if (columnName == "colLastClose")
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.PCOLORS_FORECOLOR9;
                                    text      = value.ToString("0.00");
                                }
                            }
                            else
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.GetPriceColor(value, data.m_lastClose);
                                    text      = value.ToString("0.00");
                                }
                            }
                        }
                    }
                    if (info.GetValue("FILTER") != 1)
                    {
                        foreColor = CDraw.PCOLORS_FORECOLOR8;
                    }
                    SIZE  tSize  = paint.TextSize(text, font);
                    POINT tPoint = new POINT(rect.right - tSize.cx, rect.top + clipH / 2 - tSize.cy / 2);
                    RECT  tRect  = new RECT(tPoint.x, tPoint.y, tPoint.x + tSize.cx, tPoint.y + tSize.cy);
                    paint.DrawText(text, foreColor, font, tRect);
                    if (selected)
                    {
                        paint.DrawLine(CDraw.PCOLORS_LINECOLOR, 2, 0, rect.left, rect.bottom - 1, rect.right, rect.bottom - 1);
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取浮点型数值
        /// </summary>
        /// <returns>浮点型数值</returns>
        public override double GetDouble()
        {
            GridRow            row  = Row;
            SecurityFilterInfo info = (row as SecurityFilterResultRow).Info;

            if (m_fieldName != null && m_fieldName.Length > 0)
            {
                return(info.GetValue(m_fieldName));
            }
            else
            {
                SecurityLatestData data = info.LatestData;
                int        dataSize     = data != null ? data.m_securityCode.Length : 0;
                GridColumn column       = Column;
                String     columnName   = column.Name;
                if (columnName == "colNo")
                {
                    return(row.Index);
                }
                else if (columnName == "colAmount")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_amount);
                    }
                }
                else if (columnName == "colClose")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_close);
                    }
                }
                else if (columnName == "colDiff")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_close - data.m_lastClose);
                    }
                }
                else if (columnName == "colHigh")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_high);
                    }
                }
                else if (columnName == "colLow")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_low);
                    }
                }
                else if (columnName == "colBuy")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_buyPrice1);
                    }
                }
                else if (columnName == "colSell")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_sellPrice1);
                    }
                }
                else if (columnName == "colDiffRange")
                {
                    if (dataSize > 0)
                    {
                        if (data.m_lastClose != 0)
                        {
                            return(100 * (data.m_close - data.m_lastClose) / data.m_lastClose);
                        }
                    }
                }
                else if (columnName == "colOpen")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_open);
                    }
                }
                else if (columnName == "colLastClose")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_lastClose);
                    }
                }
                else if (columnName == "colVolume")
                {
                    if (dataSize > 0)
                    {
                        return(data.m_volume);
                    }
                }
            }
            return(0);
        }