Ejemplo n.º 1
0
        /// <summary>
        /// 获取K线静态数值
        /// </summary>
        /// <param name="div">K线层</param>
        private void SetCandleStaticValue(SandBoxCandleDiv div)
        {
            SecurityData data       = div.Data;
            SpinA        spinOpen   = GetSpin("txtOpen");
            SpinA        spinClose  = GetSpin("txtClose");
            SpinA        spinHigh   = GetSpin("txtHigh");
            SpinA        spinLow    = GetSpin("txtLow");
            SpinA        spinVolume = GetSpin("txtVolume");
            SpinA        spinAmount = GetSpin("txtAmount");
            LabelA       lblDate    = GetLabel("lblDate");

            data.m_open   = (float)spinOpen.Value;
            data.m_close  = (float)spinClose.Value;
            data.m_high   = (float)spinHigh.Value;
            data.m_low    = (float)spinLow.Value;
            data.m_volume = spinVolume.Value;
            data.m_amount = spinAmount.Value;
            String strDate = lblDate.Text;

            if (strDate != null && strDate.Length > 0)
            {
                data.m_date = CStrA.ConvertDateToNum(Convert.ToDateTime(strDate));
            }
            div.Data = data;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取历史数据
        /// </summary>
        /// <param name="dataInfo"></param>
        /// <param name="datas"></param>
        /// <param name="body"></param>
        /// <param name="bodyLength"></param>
        /// <returns></returns>
        public static int GetHistoryDatas(ref HistoryDataInfo dataInfo, List <SecurityData> datas, byte[] body, int bodyLength)
        {
            Binary binary = new Binary();

            binary.Write(body, bodyLength);
            dataInfo.m_securityCode = binary.ReadString();
            dataInfo.m_type         = binary.ReadChar();
            dataInfo.m_size         = binary.ReadInt();
            dataInfo.m_cycle        = binary.ReadInt();
            dataInfo.m_subscription = binary.ReadInt();
            dataInfo.m_startDate    = binary.ReadDouble();
            dataInfo.m_endDate      = binary.ReadDouble();
            dataInfo.m_pushData     = binary.ReadBool();
            int size = dataInfo.m_size;

            for (int i = 0; i < size; i++)
            {
                SecurityData item = new SecurityData();
                item.m_date   = binary.ReadDouble();
                item.m_close  = binary.ReadFloat();
                item.m_high   = binary.ReadFloat();
                item.m_low    = binary.ReadFloat();
                item.m_open   = binary.ReadFloat();
                item.m_volume = binary.ReadDouble();
                item.m_amount = binary.ReadDouble();
                if (dataInfo.m_cycle == 0)
                {
                    item.m_avgPrice = binary.ReadFloat();
                }
                datas.Add(item);
            }
            binary.Close();
            return(1);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 执行秒表方法
 /// </summary>
 /// <param name="timerID">秒表ID</param>
 public void OnTimer(int timerID)
 {
     if (m_timerID == timerID)
     {
         INativeBase             native     = Native;
         ChartA                  chart      = m_chart.Chart;
         CTable                  dataSource = chart.DataSource;
         int                     divsSize   = m_divs.Count;
         bool                    painting   = false;
         int                     cx         = native.ClientX(m_window);
         int                     cy         = native.ClientY(m_window);
         List <SandBoxCandleDiv> removeDivs = new List <SandBoxCandleDiv>();
         for (int i = 0; i < divsSize; i++)
         {
             SandBoxCandleDiv div = m_divs[i];
             //判断是否需要重绘
             if (div.Moving)
             {
                 painting = true;
             }
             //执行秒表
             if (m_divs[i].OnTimer())
             {
                 SecurityData data     = div.Data;
                 int          rowIndex = dataSource.GetRowIndex(data.m_date);
                 int[]        fields   = new int[7];
                 fields[0] = KeyFields.CLOSE_INDEX;
                 fields[1] = KeyFields.HIGH_INDEX;
                 fields[2] = KeyFields.LOW_INDEX;
                 fields[3] = KeyFields.OPEN_INDEX;
                 fields[4] = KeyFields.VOL_INDEX;
                 fields[5] = KeyFields.AMOUNT_INDEX;
                 fields[6] = KeyFields.AVGPRICE_INDEX;
                 //插入数据
                 SecurityDataHelper.InsertLatestData(m_chart.Chart, dataSource, m_chart.Indicators, fields, data);
                 removeDivs.Add(div);
             }
         }
         //移除控件
         int removeDivsSize = removeDivs.Count;
         if (removeDivsSize > 0)
         {
             for (int i = 0; i < removeDivsSize; i++)
             {
                 SandBoxCandleDiv div = removeDivs[i];
                 m_native.RemoveControl(div);
                 m_divs.Remove(div);
                 div.Dispose();
             }
             removeDivs.Clear();
             m_chart.Chart.Update();
         }
         //重绘
         if (painting)
         {
             m_native.Invalidate();
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 复制数据
 /// </summary>
 /// <param name="data">数据</param>
 public void Copy(SecurityData data)
 {
     m_close  = data.m_close;
     m_date   = data.m_date;
     m_high   = data.m_high;
     m_low    = data.m_low;
     m_open   = data.m_open;
     m_volume = data.m_volume;
     m_amount = data.m_amount;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="chart">证券控件</param>
        /// <param name="dataSource">数据源</param>
        /// <param name="fields">字段</param>
        /// <param name="securityData">证券数据</param>
        /// <returns>索引</returns>
        public static int InsertData(ChartA chart, CTable dataSource, int[] fields, SecurityData securityData)
        {
            double close = securityData.m_close, high = securityData.m_high, low = securityData.m_low, open = securityData.m_open, avgPrice = securityData.m_avgPrice, volume = securityData.m_volume, amount = securityData.m_amount;

            if (volume > 0 || close > 0)
            {
                if (high == 0)
                {
                    high = close;
                }
                if (low == 0)
                {
                    low = close;
                }
                if (open == 0)
                {
                    open = close;
                }
                if (avgPrice == 0)
                {
                    avgPrice = double.NaN;
                }
            }
            else
            {
                close    = double.NaN;
                high     = double.NaN;
                low      = double.NaN;
                open     = double.NaN;
                volume   = double.NaN;
                amount   = double.NaN;
                avgPrice = double.NaN;
            }
            double date = securityData.m_date;

            dataSource.Set(date, fields[4], volume);
            int index = dataSource.GetRowIndex(date);

            dataSource.Set2(index, fields[0], close);
            dataSource.Set2(index, fields[1], high);
            dataSource.Set2(index, fields[2], low);
            dataSource.Set2(index, fields[3], open);
            dataSource.Set2(index, fields[5], amount);
            dataSource.Set2(index, fields[6], avgPrice);
            return(index);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 数值输入变化方法
        /// </summary>
        /// <param name="spinA">数值控件</param>
        public void OnSpinTextChanged(SpinA spin)
        {
            int divsSize = m_divs.Count;

            for (int i = 0; i < divsSize; i++)
            {
                SandBoxCandleDiv div = m_divs[i];
                if (!div.Moving)
                {
                    SecurityData data  = div.Data;
                    String       name  = spin.Name;
                    double       value = spin.Value;
                    if (name == "txtOpen")
                    {
                        data.m_open = (float)value;
                    }
                    else if (name == "txtClose")
                    {
                        data.m_close = (float)value;
                    }
                    else if (name == "txtHigh")
                    {
                        data.m_high = (float)value;
                    }
                    else if (name == "txtLow")
                    {
                        data.m_low = (float)value;
                    }
                    else if (name == "txtVolume")
                    {
                        data.m_volume = value;
                    }
                    else if (name == "txtAmount")
                    {
                        data.m_amount = value;
                    }
                    div.Data = data;
                    m_native.Invalidate();
                    break;
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 绑定历史数据
        /// </summary>
        /// <param name="chart">股票控件</param>
        /// <param name="dataSource">数据源</param>
        /// <param name="indicators">指标</param>
        /// <param name="fields">字段</param>
        /// <param name="historyDatas">历史数据</param>
        public static void BindHistoryDatas(ChartA chart, CTable dataSource, List <CIndicator> indicators, int[] fields, List <SecurityData> historyDatas)
        {
            dataSource.Clear();
            int size = historyDatas.Count;

            dataSource.SetRowsCapacity(size + 10);
            dataSource.SetRowsGrowStep(100);
            int columnsCount = dataSource.ColumnsCount;

            for (int i = 0; i < size; i++)
            {
                SecurityData securityData = historyDatas[i];
                if (dataSource == chart.DataSource)
                {
                    InsertData(chart, dataSource, fields, securityData);
                }
                else
                {
                    double[] ary = new double[columnsCount];
                    ary[0] = securityData.m_close;
                    ary[1] = securityData.m_high;
                    ary[2] = securityData.m_low;
                    ary[3] = securityData.m_open;
                    ary[4] = securityData.m_volume;
                    for (int j = 5; j < columnsCount; j++)
                    {
                        ary[j] = double.NaN;
                    }
                    dataSource.AddRow(securityData.m_date, ary, columnsCount);
                }
            }
            int indicatorsSize = indicators.Count;

            for (int i = 0; i < indicatorsSize; i++)
            {
                indicators[i].OnCalculate(0);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 插入最新数据
 /// </summary>
 /// <param name="chart">股票控件</param>
 /// <param name="dataSource">数据源</param>
 /// <param name="indicators">指标</param>
 /// <param name="fields">字段</param>
 /// <param name="historyDatas">最近的历史数据</param>
 /// <param name="latestData">实时数据</param>
 /// <returns>索引</returns>
 public static int InsertLatestData(ChartA chart, CTable dataSource, List <CIndicator> indicators, int[] fields, SecurityData latestData)
 {
     if (latestData.m_close > 0 && latestData.m_volume > 0)
     {
         int indicatorsSize = indicators.Count;
         int index          = InsertData(chart, dataSource, fields, latestData);
         for (int i = 0; i < indicatorsSize; i++)
         {
             indicators[i].OnCalculate(index);
         }
         return(index);
     }
     else
     {
         return(-1);
     }
 }