Пример #1
0
        private void UpdateChart(WindData wd)
        {
            SetChartTitle();

            if (wd.GetDataLength() < 1 || wd.GetTimeLength() < 1)
            {
                return;
            }

            if (!(wd.data is double[]))
            {
                return;
            }
            double[] closeData = (double[])wd.data;
            if (closeData.Length != wd.GetTimeLength())
            {
                return;
            }

            AddChartSerie();
            Series ser     = this.myChart.Series[0];
            double dClose  = 0.0;
            string strDate = string.Empty;

            for (int i = 0; i < closeData.Length; i++)
            {
                dClose = closeData[i];
                ser.Points.AddXY(wd.timeList[i].ToString("yy/MM"), dClose);
            }
        }
Пример #2
0
        public void Execute()
        {
            //从万得提取数据
            WindAPI w = new WindAPI();

            w.start();
            WindData wd = w.wsi("510050.SH", "open,high,low,close,volume"
                                , "2016-07-01 09:00:00", "2016-07-22 15:00:00", "Fill=Previous");

            w.stop();
            //初始化各类变量
            DateTime[] DataDate = wd.timeList;
            String.Format("yyyy/MM/dd hh:mm:ss", DataDate);
            //日期、开盘价、最高价、最低价、收盘价、成交量
            int FieldLength = wd.GetFieldLength();
            int DataLength  = wd.GetDataLength();
            int DateLength  = DataLength / FieldLength;
            int sign        = 0;//下标计数

            double[] RawData = (double[])wd.data;
            double[,] MarketData = new double[DateLength, 5];

            /*
             * double[] OP = new double[DateLength];
             * double[] HP = new double[DateLength];
             * double[] LP = new double[DateLength];
             * double[] CP = new double[DateLength];
             */
            for (int i = 0; i < RawData.Length; i = i + FieldLength)
            {
                for (int j = 0; j < FieldLength; j++)
                {
                    MarketData[sign, j] = RawData[i + j];
                }
                sign++;
            }
            //    System.Console.WriteLine("{0},{1},{2},{3}", sign, MarketData.GetLength(0), MarketData.GetLength(1), DateLength);

            /*
             * for (int now = 0; now <= sign; now++)
             * {
             *  if (now != 0 && now % 60 == 0)//60min做一次停顿
             *      Console.ReadKey();
             *  System.Console.WriteLine("Time:{0} -- O:{1} H:{2} L:{3} C:{4} Volum:{5}\n"
             *      , DataDate[now], MarketData[now,0], MarketData[now,1]
             *      , MarketData[now,2], MarketData[now,3], MarketData[now,4]);
             * }
             * Console.ReadKey();
             */
            GenSignal myGS = new GenSignal();

            myGS.getSignal(MarketData);
        }
        public static DataTable ToDataTable(this WindData wData)
        {
            var dt = new DataTable();

            if (wData != null && wData.GetDataLength() > 0)
            {
                dt.Columns.AddRange(wData.GetDataColumns());
                dt.BeginLoadData();
                wData.GetRowData().ForEach(c => dt.LoadDataRow(c, false));
                dt.EndLoadData();
            }

            return(dt);
        }
        public static List <object[]> GetRowData(this WindData wData, DataColumn[] columnTypes)
        {
            var     rows     = new List <object[]>();
            dynamic source   = ConvertToArray(wData.data);
            var     rowCount = wData.GetDataLength() / wData.GetFieldLength();

            for (int i = 0; i < rowCount; i++)
            {
                var row = new object[wData.GetFieldLength()];
                for (int j = 0; j < wData.GetFieldLength(); ++j)
                {
                    if (source[j + i * wData.GetFieldLength()] == null)
                    {
                        if (columnTypes[j].DataType == typeof(String))
                        {
                            row[j] = "";
                        }
                        else if (columnTypes[j].DataType == typeof(double))
                        {
                            row[j] = 0;
                        }
                        else if (columnTypes[j].DataType == typeof(DateTime))
                        {
                            row[j] = new DateTime();
                        }
                    }
                    else
                    {
                        if (source[j + i * wData.GetFieldLength()].GetType() == typeof(System.DBNull))
                        {
                            if (columnTypes[j].DataType == typeof(String))
                            {
                                row[j] = "数据缺失";
                            }
                            else
                            {
                                row[j] = -1;
                            }
                        }
                        else
                        {
                            row[j] = source[j + i * wData.GetFieldLength()];
                        }
                    }
                }
                rows.Add(row);
            }
            return(rows);
        }
        public static DataTable ToDataTable(this WindData wData)
        {
            var     dt     = new DataTable();
            dynamic source = ConvertToArray(wData.data);

            if (wData != null && wData.GetDataLength() > 0)
            {
                var columnTypes = wData.GetDataColumns();
                dt.Columns.AddRange(columnTypes);
                dt.BeginLoadData();
                wData.GetRowData(columnTypes).ForEach(c => dt.LoadDataRow(c, false));
                dt.EndLoadData();
            }

            return(dt);
        }
        public static List <object[]> GetRowData(this WindData wData)
        {
            var     rows     = new List <object[]>();
            dynamic source   = ConvertToArray(wData.data);
            var     rowCount = wData.GetDataLength() / wData.GetFieldLength();

            for (int i = 0; i < rowCount; i++)
            {
                var row = new object[wData.GetFieldLength()];
                for (int j = 0; j < wData.GetFieldLength(); ++j)
                {
                    row[j] = source[j + i * wData.GetFieldLength()];
                }
                rows.Add(row);
            }
            return(rows);
        }
Пример #7
0
        static string WindDataToSerialize(WindData wd, string windFuncName)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = Int32.MaxValue;
            serializer.RegisterConverters(new JavaScriptConverter[] { new ExpandoJSONConverter() });

            //请求出错,获取错误信息
            if (wd.errorCode != 0)
            {
                return(serializer.Serialize(wd.GetErrorMsg()));
            }

            // OutputWindData(wd, "wsd");
            // OutputWindData(wd, "edb");
            // Console.WriteLine(serializer.Serialize(wd.data));

            object[,] odata = (object[, ])wd.getDataByFunc(windFuncName, false);
            int nTimeLength  = wd.timeList.Length;
            int nCodeLength  = wd.codeList.Length;
            int nFieldLength = wd.fieldList.Length;
            int nDataLength  = wd.GetDataLength();

            // Console.WriteLine(string.Format("nTimeLength={0} nCodeLength={1} nFieldLength={2}", nTimeLength, nCodeLength, nFieldLength));

            // for (int i = 0; i < odata.GetLength(0);i++ )
            // {
            //     for (int j = 0; j < odata.GetLength(1); j++)
            //     {
            //          Console.WriteLine("维度 {0} {1} 的值为 {2}", i, j, odata[i, j]);
            //     }
            // }
            // Console.WriteLine(nDataLength);

            dynamic[] rows       = new ExpandoObject[nDataLength];
            int       indexTime  = 0;
            int       indexCode  = 0;
            int       indexField = 0;

            for (int i = 0; i < nDataLength; i++)
            {
                indexTime  = (int)Math.Ceiling((float)(i + 1) / (float)(nCodeLength * nFieldLength)) - 1;
                indexCode  = (i) % nCodeLength;
                indexField = (i) % nFieldLength;
                // MAC_IND_API Urban;
                // Urban.END_DATE = wd.timeList[i].ToString("yyyy-MM-dd");
                // Urban.DATA_FREQ_PAR = 5;
                // Urban.MAC_IDX_PAR = 1001;
                // Urban.PRC_UNIT = "万人";
                // Urban.IDX_VAL = Convert.ToSingle(odata[i, 0].ToString());
                // Console.WriteLine(Urban.ToString());

                dynamic o = new ExpandoObject();
                o.time  = wd.timeList[indexTime].ToString("yyyy-MM-dd");
                o.code  = wd.codeList[indexCode];
                o.field = wd.fieldList[indexField];
                o.value = odata[indexTime, indexCode *nFieldLength + indexField];
                // o.value = Double.IsNaN((double)odata[indexTime, indexCode]) ? 0 : odata[indexTime, indexCode];
                rows[i] = o;
                // Console.WriteLine(string.Format("{0} {1} {2} {3}", o.time, o.code, o.field, o.value));
            }
            String serialization = serializer.Serialize(rows);

            return(serialization);
        }