示例#1
0
        /// <summary>
        /// 获取THS龙虎榜数据
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public List <object> GetLHB(string stockCode, string source = "THS")
        {
            var resList = new List <object>();

            if ("THS" == source.ToUpper() && !string.IsNullOrWhiteSpace(stockCode)) //
            {
                var lhbHtml = DataSourceTHS.CreateInstance().GetGGLHB(stockCode);
                if (string.IsNullOrWhiteSpace(lhbHtml))
                {
                    lhbHtml = WebDataSource.GetDataFromHttpAgent(string.Format("http://aifuwu.wang/API.ashx?c=WangJun.Stock.DataSourceTHS&m=GetGGLHB&p={0}", stockCode));
                }

                var lhbDict = NodeService.Get(CONST.NodeServiceUrl, "同花顺", "GetDataFromHtml", new { ContentType = "THS个股龙虎榜", Page = lhbHtml });
                resList.Add((lhbDict as Dictionary <string, object>)["PageData"]);
                ThreadManager.Pause(seconds: 2);
                var lhbmxUrlList = DataSourceTHS.CreateInstance().GetUrlGGLHBMX(lhbHtml);
                foreach (var lhbMXUrl in lhbmxUrlList)
                {
                    var lhbMXHtml = DataSourceTHS.CreateInstance().GetGGLHBMX(stockCode, lhbMXUrl);
                    if (string.IsNullOrWhiteSpace(lhbMXHtml))
                    {
                        //lhbHtml = WebDataSource.GetDataFromHttpAgent(string.Format("http://aifuwu.wang/API.ashx?c=WangJun.Stock.DataSourceTHS&m=GetGGLHBMX&p={0}", stockCode));
                    }
                    var lhbMXDict = NodeService.Get(CONST.NodeServiceUrl, "同花顺", "GetDataFromHtml", new { ContentType = "THS个股龙虎榜明细", Page = lhbMXHtml });
                    resList.Add((lhbMXDict as Dictionary <string, object>)["PageData"]);
                    ThreadManager.Pause(seconds: 1);
                }
            }

            return(resList);
        }
示例#2
0
        /// <summary>
        /// 获取SINA公司简介数据
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public object GetGSJJ(string stockCode, string source = "SINA")
        {
            var res = new object();

            if ("SINA" == source.ToUpper() && !string.IsNullOrWhiteSpace(stockCode)) //
            {
                var html = DataSourceSINA.GetInstance().GetGSJJ(stockCode);
                if (string.IsNullOrWhiteSpace(html))
                {
                    html = WebDataSource.GetDataFromHttpAgent(string.Format("http://aifuwu.wang/API.ashx?c=WangJun.Stock.DataSourceSINA&m=GetGSJJ&p={0}", stockCode));
                }

                var resDict = NodeService.Get(CONST.NodeServiceUrl, "新浪", "GetDataFromHtml", new { ContentType = "SINA公司简介", Page = html });
                return(resDict);
            }

            return(res);
        }
示例#3
0
        /// <summary>
        /// 获取THS资金流向
        /// </summary>
        /// <param name="stockCode"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public object GetZJLX(string stockCode, string source = "THS")
        {
            var res = new object();

            if ("THS" == source.ToUpper() && !string.IsNullOrWhiteSpace(stockCode)) //
            {
                var html = DataSourceTHS.CreateInstance().GetJZLX(stockCode);
                if (string.IsNullOrWhiteSpace(html))
                {
                    html = WebDataSource.GetDataFromHttpAgent(string.Format("http://aifuwu.wang/API.ashx?c=WangJun.Stock.DataSourceTHS&m=GetZJLX&p={0}", stockCode));
                }

                var resDict = NodeService.Get(CONST.NodeServiceUrl, "同花顺", "GetDataFromHtml", new { ContentType = "THS资金流向", Page = html });
                return(resDict);
            }

            return(res);
        }
        /// <summary>
        /// 下载大单数据
        /// </summary>
        public void GetDaDanData()
        {
            ///获取页码码数
            ///下载每一页数据
            ///查找最近一个交易日的数据是否存在,若存在则不下载
            ///

            var mongo     = DataStorage.GetInstance(DBType.MongoDB);
            var webSource = DataSourceSINA.GetInstance();
            var pageCount = 0;// webSource.GetDaDanPageCount();

            if (0 == pageCount)
            {
                pageCount = int.Parse(WebDataSource.GetDataFromHttpAgent(string.Format("http://aifuwu.wang/API.ashx?c=WangJun.Stock.DataSourceSINA&m=GetDaDanPageCount")));
            }
            var dbName         = CONST.DB.DBName_StockService;
            var collectionName = CONST.DB.CollectionName_DaDan;
            ///数据检查
            var lastTradingDate = Convertor.CalTradingDate(DateTime.Now, "00:00:00");

            ///删除根据日期创建的临时表格
            ///将数据写入表格
            ///将这个数据转移到大表中
            #region 存储临时数据
            var tempCollectionName = collectionName + string.Format("{0:yyyyMMdd}", DateTime.Now);
            mongo.Remove(dbName, tempCollectionName, "{}");
            #endregion

            var methodName = "GetDaDanData";
            var status     = TaskStatusManager.Get(methodName);
            var startIndex = (status.ContainsKey("PageIndex")) ? int.Parse(status["PageIndex"].ToString()) : 0;
            var totalCount = 0;
            for (int i = startIndex; i < pageCount; i++)
            {
                var html = "";// webSource.GetDaDan(i);

                if (string.IsNullOrWhiteSpace(html))
                {
                    html = WebDataSource.GetDataFromHttpAgent(string.Format("http://aifuwu.wang/API.ashx?c=WangJun.Stock.DataSourceSINA&m=GetDaDan&p={0}", i));
                }

                var res = NodeService.Get(CONST.NodeServiceUrl, "新浪", "GetDataFromHtml", new { ContentType = "SINA大单", Page = html });

                if (res is Dictionary <string, object> )
                {
                    var item = new
                    {
                        PageData    = (res as Dictionary <string, object>)["PageData"],
                        ContentType = "SINA大单",
                        CreateTime  = DateTime.Now,
                        TradingDate = Convertor.CalTradingDate(DateTime.Now, "00:00:00"),
                        PageIndex   = i,
                        PageCount   = pageCount,
                    };
                    LOGGER.Log(string.Format("SINA大单保存 {0} {1}", i, pageCount));

                    var arrayList = item.PageData as ArrayList;
                    ///数据二维化,计算可以计算的,剩下的再想办法计算
                    for (int k = 0; k < arrayList.Count; k++)
                    {
                        totalCount++;
                        var arrItem  = arrayList[k] as Dictionary <string, object>;
                        var svItem2D = new
                        {
                            StockCode   = arrItem["StockCode"],
                            StockName   = arrItem["StockName"],
                            TickTime    = arrItem["交易时间"],
                            Price       = arrItem["成交价"],
                            Turnover    = arrItem["成交量"],
                            PrevPrice   = arrItem["之前价格"],
                            Kind        = arrItem["成交类型"],
                            TradingTime = Convertor.CalTradingDate(item.TradingDate, arrItem["交易时间"].ToString()),
                            TradingDate = item.TradingDate,
                            CreateTime  = item.CreateTime,
                            PageIndex   = i,
                            PageCount   = pageCount,
                            RowIndex    = k
                        };
                        mongo.Save3(dbName, tempCollectionName, svItem2D);
                        TaskStatusManager.Set(methodName, new { ID = methodName, PageIndex = i, PageCount = pageCount, Status = "已下载", CreateTime = DateTime.Now });

                        LOGGER.Log(string.Format("SINA大单2D保存 {0} {1} {2}", i, k, pageCount));
                    }
                }
                ThreadManager.Pause(seconds: 2);
            }
            TaskStatusManager.Set(methodName, new { ID = methodName, Status = "队列处理完毕", CreateTime = DateTime.Now });
            var countInDB = mongo.Count(CONST.DB.DBName_StockService, tempCollectionName, "{}");
            if (totalCount == countInDB)
            {
                LOGGER.Log(string.Format("准备转移数据"));
                ///数据检查是否完毕,完备后插入
                //DataStorage.MoveCollection(mongo, CONST.DB.DBName_StockService, tempCollectionName, "{}", mongo, CONST.DB.DBName_StockService, CONST.DB.CollectionName_DaDan, false);
            }
            else
            {
                LOGGER.Log(string.Format("数据对不上 {0} {1}", totalCount, countInDB));
            }
        }