Ejemplo n.º 1
0
        public static async Task <List <HistoryPrice> > Data(List <string> lstSymbols)
        {
            List <HistoryPrice> list = new List <HistoryPrice>();


            foreach (var symbol in lstSymbols)
            {
                string csvData = null;
                string uri     = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol={0}&interval=1min&apikey=RJQACXXR1DL2WYJT&datatype=csv";

                uri = string.Format(uri, symbol);

                using (var wc = new WebClient())
                {
                    wc.Headers.Add(HttpRequestHeader.Cookie, Token.Cookie);
                    csvData = await wc.DownloadStringTaskAsync(uri).ConfigureAwait(false);
                }


                var rows = csvData.Split(Convert.ToChar(10));

                //row(0) was ignored because is column names
                //data is read from oldest to latest
                for (var i = 1; i <= rows.Length - 1; i++)
                {
                    var row = rows[i];
                    if (string.IsNullOrEmpty(row))
                    {
                        continue;
                    }

                    var cols = row.Split(',');
                    if (cols[1] == "null")
                    {
                        continue;
                    }

                    var itm = new HistoryPrice
                    {
                        Date   = DateTime.Parse(cols[0]),
                        Open   = Convert.ToDouble(cols[1]),
                        High   = Convert.ToDouble(cols[2]),
                        Low    = Convert.ToDouble(cols[3]),
                        Close  = Convert.ToDouble(cols[4]),
                        Volume = Convert.ToDouble(cols[5]),
                        Symbol = symbol
                    };

                    //fixed issue in some currencies quote (e.g: SGDAUD=X)


                    list.Add(itm);
                }
            }



            return(list);
        }
Ejemplo n.º 2
0
        public static HistoryPrice ToHistory(this PoloniexHistoryDataType historyDataType, Pair pair)
        {
            var history = new HistoryPrice(PoloniexTools.UnixTimeStampToDateTime(historyDataType.TimeStamp),
                                           historyDataType.Open, historyDataType.Close,
                                           historyDataType.High, historyDataType.Low, historyDataType.Volume, historyDataType.QuoteVolume);

            return(history);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 记录指定楼盘的历史价格
        /// </summary>
        /// <param name="loupanID">楼盘ID</param>
        /// <param name="loupanDetialNode">“楼盘详情”页面</param>
        private void RecordHistoryPrice(string loupanID, HtmlNode loupanDetialNode)
        {
            if (loupanDetialNode == null)
                return;
            HtmlNodeCollection historyPriceList = loupanDetialNode
                .OwnerDocument
                .GetElementbyId("priceListOpen")
                .SelectNodes("./table[1]/tr");
            historyPriceList.RemoveAt(0);

            foreach (var node in historyPriceList)
            {
                string date = node.SelectSingleNode("./td[1]").InnerText;
                if (date.StartsWith("0000"))
                    return;
                int MaxPrice = GetPrice(node.SelectSingleNode("./td[2]").InnerText);
                int AvgPrice = GetPrice(node.SelectSingleNode("./td[3]").InnerText);
                int MinPrice = GetPrice(node.SelectSingleNode("./td[4]").InnerText);
                string Description = node.SelectSingleNode("./td[5]").InnerText.Replace("&nbsp;", String.Empty);

                HistoryPrice loupanPrice = new HistoryPrice()
                {
                    LoupanID = loupanID,
                    RecordDate = DateTime.ParseExact(date, "yyyy-MM-dd", DateTimeFormatInfo.CurrentInfo),
                    MaxPrice = MaxPrice,
                    AveragePrice = AvgPrice,
                    MinPrice = MinPrice,
                    Description = Description
                };
                db.HistoryPrice.InsertOnSubmit(loupanPrice);
                Console.WriteLine($"{loupanID},{date},{AvgPrice},{MinPrice},{MaxPrice}");
            }
        }