Esempio n. 1
0
        private static data.importDS.importPriceDataTable GetPrice(DateTime updateTime, string url, string marketCode)
        {
            data.importDS.importPriceDataTable importPriceTbl = new data.importDS.importPriceDataTable();
            ForexData[] frData   = ImportForex(url);
            ForexData   goldData = frData[3]; //Gold at price 4

            if (lastForexData != null)
            {
                if (lastForexData.last == goldData.last &&
                    lastForexData.high == goldData.high &&
                    lastForexData.low == goldData.low)
                {
                    return(importPriceTbl);
                }
            }
            else
            {
                lastForexData = new ForexData();
            }
            lastForexData.last = goldData.last;
            lastForexData.high = goldData.high;
            lastForexData.low  = goldData.low;

            data.importDS.importPriceRow importRow;
            importRow = importPriceTbl.NewimportPriceRow();
            application.DbAccess.InitData(importRow);
            importRow.onDate        = updateTime;
            importRow.stockExchange = marketCode;
            importRow.stockCode     = goldData.code;
            importRow.closePrice    = goldData.last;
            importRow.highPrice     = goldData.high;
            importRow.lowPrice      = goldData.low;

            if (goldOpenPriceDate != updateTime.Date || goldOpenPrice == decimal.MinValue)
            {
                data.baseDS.priceDataRow row = application.DbAccess.GetLastPriceData(importRow.stockCode);
                if (row != null)
                {
                    goldOpenPrice = row.closePrice;
                }
                else
                {
                    goldOpenPrice = importRow.closePrice;
                }
                goldOpenPriceDate = updateTime.Date;
            }
            importRow.openPrice = goldOpenPrice;
            importPriceTbl.AddimportPriceRow(importRow);
            return(importPriceTbl);
        }
Esempio n. 2
0
        public static void GenPriceData(string stockCode)
        {
            DateTime dt = DateTime.Now;
            decimal  lastHighPrice = 0, lastLowPrice = 0, lastClosePrice = 0, lastOpenPrice = 0, lastVolume = 0;

            data.baseDS.priceDataSumRow dayPriceRow = myDailyPrice.GetData(stockCode, dt);
            if (dayPriceRow == null)
            {
                data.baseDS.priceDataRow priceRow = application.DbAccess.GetLastPriceData(stockCode);
                lastHighPrice  = priceRow.highPrice;
                lastLowPrice   = priceRow.lowPrice;
                lastClosePrice = priceRow.closePrice;
                lastOpenPrice  = priceRow.openPrice;
                lastVolume     = 0;
            }
            else
            {
                lastHighPrice  = dayPriceRow.highPrice;
                lastLowPrice   = dayPriceRow.lowPrice;
                lastClosePrice = dayPriceRow.closePrice;
                lastOpenPrice  = dayPriceRow.openPrice;
                lastVolume     = dayPriceRow.volume;
            }
            priceDataTbl.Clear();
            importPriceTbl.Clear();

            data.importDS.importPriceRow importRow = importPriceTbl.NewimportPriceRow();
            application.DbAccess.InitData(importRow);

            decimal highPrice  = lastHighPrice + lastHighPrice * (decimal)common.system.Random(-4, 5) / 100;
            decimal lowPrice   = lastLowPrice + lastLowPrice * (decimal)common.system.Random(-4, 5) / 100;
            decimal closePrice = lastClosePrice + lastClosePrice * (decimal)common.system.Random(-5, 5) / 100;

            importRow.openPrice = lastOpenPrice;
            importRow.highPrice = Math.Max(lastHighPrice, highPrice);
            if (lowPrice < importRow.highPrice)
            {
                importRow.lowPrice = lowPrice;
            }
            else
            {
                importRow.lowPrice = importRow.highPrice;
            }

            if (closePrice >= importRow.lowPrice && closePrice <= importRow.highPrice)
            {
                importRow.closePrice = closePrice;
            }
            else
            {
                importRow.closePrice = (importRow.lowPrice + importRow.highPrice) / 2;
            }
            importRow.volume    = lastVolume + common.system.Random(0, 100);
            importRow.onDate    = dt;
            importRow.stockCode = stockCode;
            importPriceTbl.AddimportPriceRow(importRow);

            imports.libs.AddImportPrice(importPriceTbl, priceDataTbl);
            application.DbAccess.UpdateData(priceDataTbl);
            // In VN culture : start of week is Monday (not Sunday)
            imports.libs.AggregatePriceData(priceDataTbl, vnCulture, null);

            myDailyPrice.UpdateData(importRow);
        }
Esempio n. 3
0
        /// <summary>
        /// Import data from URL to tables : importPrice
        /// The function also detect and add new companies to the database
        /// </summary>
        /// <param name="url">URL to get data</param>
        /// <param name="priceMeta">meta describe the webpage structure</param>
        /// <param name="stockExchangeCode">stock exchange code of imported data </param>
        /// <param name="importPriceTbl"> where to store imported data </param>
        private static data.importDS.importPriceDataTable GetPriceFromURL(DateTime updateTime, string url, importPriceMeta priceMeta, string marketCode)
        {
            data.importDS.importPriceDataTable importPriceTbl = new data.importDS.importPriceDataTable();
            common.extSortedList mappingList = CreateMapping(priceMeta, importPriceTbl);

            data.baseDS.priceDataRow priceDataRow;

            // Get the URL specified
            var webGet   = new HtmlWeb();
            var document = webGet.Load(url);

            // Get <a> tags that have a href attribute and non-whitespace inner text
            var linksOnPage = from item in document.DocumentNode.Descendants()
                              where item.Name == "td" && item.Attributes["id"] == null
                              select new
            {
                Text = item.InnerText
            };

            bool    fError = false;
            int     igmoreRowCount = 0, columnCount = 0;
            decimal val = 0;

            data.importDS.importPriceRow importRow = null;
            string stockCode;

            foreach (var item in linksOnPage)
            {
                //Check whether to ignore some items at the first
                if (++igmoreRowCount <= priceMeta.noRowIgnore)
                {
                    continue;
                }
                if (fError)
                {
                    break;
                }

                if (columnCount == priceMeta.startAtColId)
                {
                    stockCode = item.Text.Trim();
                    importRow = importPriceTbl.NewimportPriceRow();
                    application.DbAccess.InitData(importRow);
                    importRow.onDate        = updateTime;
                    importRow.stockCode     = stockCode;
                    importRow.stockExchange = marketCode;
                    importRow.isTotalVolume = true;
                    columnCount++;
                    continue;
                }
                //Last column
                if (columnCount == priceMeta.endAtColId)
                {
                    if (importRow.closePrice > 0)
                    {
                        if (importRow.openPrice == 0)
                        {
                            priceDataRow = application.DbAccess.GetLastPriceData(importRow.stockCode);
                            if (priceDataRow == null)
                            {
                                importRow.openPrice = importRow.lowPrice;
                            }
                            else
                            {
                                importRow.openPrice = priceDataRow.closePrice;
                            }
                        }
                        importPriceTbl.AddimportPriceRow(importRow);
                    }
                    else
                    {
                        importRow.CancelEdit();
                    }
                    columnCount = 0;
                    continue;
                }
                object obj = mappingList.GetValue(columnCount.ToString());
                if (obj != null)
                {
                    val = 0; common.system.StrToDecimal(item.Text, libs.CultureInfoUS, out val);
                    importRow[(string)obj] = val;
                }
                columnCount++;
            }
            return(importPriceTbl);
        }
Esempio n. 4
0
        /// <summary>
        /// Import data from URL to tables : importPrice 
        /// The function also detect and add new companies to the database
        /// </summary>
        /// <param name="url">URL to get data</param>
        /// <param name="priceMeta">meta describe the webpage structure</param>
        /// <param name="stockExchangeCode">stock exchange code of imported data </param>
        /// <param name="importPriceTbl"> where to store imported data </param>
        private static data.importDS.importPriceDataTable GetPriceFromURL(DateTime updateTime, string url, importPriceMeta priceMeta, string marketCode)
        {
            data.importDS.importPriceDataTable importPriceTbl = new data.importDS.importPriceDataTable();
            common.extSortedList mappingList = CreateMapping(priceMeta, importPriceTbl);

            data.baseDS.priceDataRow priceDataRow;

            // Get the URL specified
            var webGet = new HtmlWeb();
            var document = webGet.Load(url);

            // Get <a> tags that have a href attribute and non-whitespace inner text
            var linksOnPage = from item in document.DocumentNode.Descendants()
                              where item.Name == "td" && item.Attributes["id"] == null
                              select new
                              {
                                  Text = item.InnerText
                              };

            bool fError = false;
            int igmoreRowCount = 0, columnCount = 0;
            decimal val = 0;
            data.importDS.importPriceRow importRow = null;
            string stockCode;
            foreach (var item in linksOnPage)
            {
                //Check whether to ignore some items at the first
                if (++igmoreRowCount <= priceMeta.noRowIgnore) continue;
                if (fError) break;

                if (columnCount == priceMeta.startAtColId)
                {
                    stockCode = item.Text.Trim();
                    importRow = importPriceTbl.NewimportPriceRow();
                    application.DbAccess.InitData(importRow);
                    importRow.onDate = updateTime;
                    importRow.stockCode = stockCode;
                    importRow.stockExchange = marketCode;
                    importRow.isTotalVolume = true;
                    columnCount++;
                    continue;
                }
                //Last column
                if (columnCount == priceMeta.endAtColId)
                {
                    if (importRow.closePrice > 0)
                    {
                        if (importRow.openPrice == 0)
                        {
                            priceDataRow = application.DbAccess.GetLastPriceData(importRow.stockCode);
                            if (priceDataRow == null) importRow.openPrice = importRow.lowPrice;
                            else importRow.openPrice = priceDataRow.closePrice;
                        }
                        importPriceTbl.AddimportPriceRow(importRow);
                    }
                    else importRow.CancelEdit();
                    columnCount = 0;
                    continue;
                }
                object obj = mappingList.GetValue(columnCount.ToString());
                if (obj != null)
                {
                    val = 0; common.system.StrToDecimal(item.Text, libs.CultureInfoUS, out val);
                    importRow[(string)obj] = val;
                }
                columnCount++;
            }
            return importPriceTbl;
        }
Esempio n. 5
0
        private static data.importDS.importPriceDataTable GetPrice(DateTime updateTime, string url, string marketCode)
        {
            data.importDS.importPriceDataTable importPriceTbl = new data.importDS.importPriceDataTable();
            ForexData[] frData = ImportForex(url);
            ForexData goldData = frData[3]; //Gold at price 4
            if (lastForexData != null)
            {
                if (lastForexData.last == goldData.last && 
                    lastForexData.high == goldData.high &&
                    lastForexData.low  == goldData.low) return importPriceTbl;
            }
            else lastForexData = new ForexData();
            lastForexData.last = goldData.last;
            lastForexData.high = goldData.high;
            lastForexData.low = goldData.low;
            
            data.importDS.importPriceRow importRow;
            importRow = importPriceTbl.NewimportPriceRow();
            application.DbAccess.InitData(importRow);
            importRow.onDate = updateTime;
            importRow.stockExchange = marketCode;
            importRow.stockCode = goldData.code;
            importRow.closePrice = goldData.last;
            importRow.highPrice = goldData.high;
            importRow.lowPrice = goldData.low;

            if (goldOpenPriceDate != updateTime.Date || goldOpenPrice == decimal.MinValue)
            {
                data.baseDS.priceDataRow row  = application.DbAccess.GetLastPriceData(importRow.stockCode);
                if (row != null) goldOpenPrice = row.closePrice;
                else  goldOpenPrice = importRow.closePrice;
                goldOpenPriceDate = updateTime.Date;
            }
            importRow.openPrice = goldOpenPrice;
            importPriceTbl.AddimportPriceRow(importRow);
            return importPriceTbl;
        }