Esempio n. 1
0
        public void GetKLineValue(bool debug = true)
        {
            KLineCache tempCache = new KLineCache();

            List <string> keys = m_List.Keys.ToList();

            //获取K线数据
            //获取近200条K线
            try
            {
                ASpotData spotData = m_List[keys[curIndex]];

                spotData.kLineDataDic.Clear();

                //Debugger.Log("获取K线数据:" + spotData.SpotName);

                string result = GetKLineData(spotData.coin, 60, 400);
                if (string.IsNullOrEmpty(result))
                {
                    throw new Exception("no Data");
                }
                JContainer con = JArray.Parse(result);
                spotData.hourData.RefreshAData(con);

                spotData.sixHourData.RefreshData(spotData.hourData.GetMergeKLine(6));

                result = GetKLineData(spotData.coin, 4 * 60, 400);
                if (string.IsNullOrEmpty(result))
                {
                    throw new Exception("no Data");
                }
                con = JArray.Parse(result);

                tempCache.RefreshAData(con);
                spotData.dayData.RefreshData(tempCache.GetMergeKLine(2));

                //4h的其实是day
                //spotData.dayData.RefreshAData(con);

                spotData.kLineDataDic[60]   = spotData.hourData;
                spotData.kLineDataDic[360]  = spotData.sixHourData;
                spotData.kLineDataDic[1440] = spotData.dayData;

                //计算推荐值
                spotData.RefreshCommandValue(debug);
            }
            catch (Exception ex)
            {
                if (!ex.ToString().Contains("timed out"))
                {
                    curIndex++;
                    Debugger.Error(ex.ToString());
                    TimeEventHandler.Ins.RemoveEvent(getKLineData);
                    TimeEventHandler.Ins.AddEvent(
                        new TimeEventModel(300, 1, () => { TimeEventHandler.Ins.AddEvent(getKLineData); })
                        );
                }
                return;
            }
            curIndex++;
            if (curIndex >= keys.Count)
            {
                TimeEventHandler.Ins.RemoveEvent(getKLineData);
                curIndex = 0;
                SortData();
                TelegramBot.Ins.SendMsg(GetResult(false));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 刷新所有股票数据(开始执行一次算了。。。)
        /// </summary>
        public void InitData()
        {
            m_List.Clear();
            typeDataList.Clear();


            string filePath = AppDomain.CurrentDomain.BaseDirectory + "/" + "A.xls";

            try
            {
                string    url         = "http://www.szse.cn/api/report/ShowReport?SHOWTYPE=xlsx&CATALOGID=1110&TABKEY=tab1&random=0.809744887977796";
                WebClient myWebClient = new WebClient();
                myWebClient.DownloadFile(url, filePath);
            }
            catch
            {
                Debugger.Error("download error");
            }



            //判断文件在不在,读取所有数据并分类
            if (File.Exists(filePath))
            {
                using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
                {
                    // Auto-detect format, supports:
                    //  - Binary Excel files (2.0-2003 format; *.xls)
                    //  - OpenXml Excel files (2007 format; *.xlsx, *.xlsb)
                    using (var reader = ExcelReaderFactory.CreateReader(stream))
                    {
                        // Choose one of either 1 or 2:

                        // 1. Use the reader methods
                        do
                        {
                            reader.Read();
                            while (reader.Read())
                            {
                                // reader.GetDouble(0);

                                string name = reader.GetString(5);
                                string id   = reader.GetString(4);
                                string type = reader.GetString(17);

                                if (id.StartsWith("3"))
                                {
                                    continue;
                                }

                                ASpotData data = new ASpotData(id, name, type);

                                m_List.Add(id, data);

                                if (!typeDataList.ContainsKey(type))
                                {
                                    typeDataList.Add(type, new List <ASpotData>());
                                }

                                typeDataList[type].Add(data);

                                //Console.WriteLine(id+"  "+name+"  "+type);
                            }
                        } while (reader.NextResult());
                    }
                }
            }
        }