Esempio n. 1
0
        /// <summary>
        /// Private - SU dung ASPWebservices
        /// </summary>
        /// <param name="updateTime"></param>
        /// <param name="exchangeDetailRow"></param>
        /// <returns></returns>
        private databases.importDS.importPriceDataTable GetPriceFromWeb(DateTime updateTime, databases.baseDS.exchangeDetailRow exchangeDetailRow)
        {
            try
            {
                databases.importDS.importPriceDataTable importPriceTbl = new databases.importDS.importPriceDataTable();

                if (ssiPage==null)
                    ssiPage = new SSIPage("http://banggia2.ssi.com.vn/", "http://banggia2.ssi.com.vn/Hnx.aspx");
                    //ssiPage = new SSIPage("file:///C:/Temp/selenium/HOSE%20-%20CTCP%20ch%E1%BB%A9ng%20kho%C3%A1n%20S%C3%A0i%20G%C3%B2n%20-%20B%E1%BA%A3ng%20gi%C3%A1%20tr%E1%BB%B1c%20tuy%E1%BA%BFn.html", "file:///C:/Temp/selenium/HNX%20-%20CTCP%20ch%E1%BB%A9ng%20kho%C3%A1n%20S%C3%A0i%20G%C3%B2n%20-%20B%E1%BA%A3ng%20gi%C3%A1%20tr%E1%BB%B1c%20tuy%E1%BA%BFn.html");

                ssiPage.getHOSEData();
                ssiPage.getHNXData();
                //SaveDatatoImportPriceDataTable(updateTime,importPriceTbl);
                databases.importDS.importPriceRow importRow = null;
                databases.importDS.importPriceRow oldImportRow;

                foreach (var stock in ssiPage.dictStocks)
                {
                    importRow = importPriceTbl.NewimportPriceRow();
                    databases.AppLibs.InitData(importRow);
                    importRow.onDate = updateTime;
                    importRow.stockCode = stock.Key;
                    //Doi de fix error #136 - Lỗi cập nhật HNX
                    //importRow.isTotalVolume = true;
                    importRow.isTotalVolume = false;

                    importRow.closePrice=(decimal)stock.Value.price;

                    //Doi de fix error #136 - Lỗi cập nhật HNX
                    //importRow.volume = (decimal)stock.Value.totalVolume;
                    importRow.volume = (decimal)stock.Value.actualVolume;

                    //Doi de fix error #136 - Lỗi cập nhật HNX
                    if (importRow.closePrice > 0)
                    {
                        //Only add new when there are some changes
                        oldImportRow = lastImportData.Find(importRow);
                        if (!lastImportData.IsSameData(importRow, oldImportRow))
                        {
                            importPriceTbl.AddimportPriceRow(importRow);
                            lastImportData.Update(importRow);
                        }
                        else importRow.CancelEdit();
                    }
                    else importRow.CancelEdit();
                }

                return importPriceTbl;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return null;
        }
Esempio n. 2
0
 public void Update(databases.importDS.importPriceRow row)
 {
     databases.importDS.importPriceRow oldRow = Find(row);
     if (oldRow == null)
     {
         oldRow = dataTbl.NewimportPriceRow();
         databases.AppLibs.InitData(oldRow);
         dataTbl.AddimportPriceRow(oldRow);
     }
     oldRow.onDate        = row.onDate;
     oldRow.stockCode     = row.stockCode;
     oldRow.closePrice    = row.closePrice;
     oldRow.volume        = row.volume;
     oldRow.isTotalVolume = row.isTotalVolume;
 }
Esempio n. 3
0
        public static void GenPriceData(string stockCode)
        {
            DateTime dt = DateTime.Now;
            decimal  lastHighPrice = 0, lastLowPrice = 0, lastClosePrice = 0, lastOpenPrice = 0, lastVolume = 0;

            databases.baseDS.priceDataSumRow dayPriceRow = myDailyPrice.GetData(stockCode, dt);
            if (dayPriceRow == null)
            {
                databases.baseDS.priceDataRow priceRow = databases.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();

            databases.importDS.importPriceRow importRow = importPriceTbl.NewimportPriceRow();
            databases.AppLibs.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.volume    = lastVolume + common.system.Random(0, 100);
            importRow.onDate    = dt;
            importRow.stockCode = stockCode;
            importPriceTbl.AddimportPriceRow(importRow);

            Imports.Libs.AddImportPrice(importPriceTbl, priceDataTbl);
            databases.DbAccess.UpdateData(priceDataTbl);
            // In VN culture : start of week is Monday (not Sunday)
            databases.AppLibs.AggregatePriceData(priceDataTbl, vnCulture, null);

            myDailyPrice.UpdateData(importRow);
        }
Esempio n. 4
0
 protected virtual void AddImportRow(DateTime updateTime, ForexData data, bool isTotalVolume, databases.importDS.importPriceDataTable tbl)
 {
     databases.importDS.importPriceRow oldImportRow;
     databases.importDS.importPriceRow importRow = tbl.NewimportPriceRow();
     databases.AppLibs.InitData(importRow);
     importRow.isTotalVolume = isTotalVolume;
     importRow.onDate        = updateTime;
     importRow.stockCode     = data.code;
     importRow.volume        = 0;
     importRow.closePrice    = data.last;
     //Only add new when there are some changes
     oldImportRow = lastImportData.Find(importRow);
     if (!lastImportData.IsSameData(importRow, oldImportRow))
     {
         tbl.AddimportPriceRow(importRow);
         lastImportData.Update(importRow);
     }
     else
     {
         importRow.CancelEdit();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Private - SU dung ASPWebservices
        /// </summary>
        /// <param name="updateTime"></param>
        /// <param name="exchangeDetailRow"></param>
        /// <returns></returns>
        private databases.importDS.importPriceDataTable GetPriceFromWeb(DateTime updateTime, databases.baseDS.exchangeDetailRow exchangeDetailRow)
        {
            int idx = 0;
            clientSSI.AjaxWebServiceSoapClient client = null;
            try
            {
                client = new clientSSI.AjaxWebServiceSoapClient();
                //client = new clientSSI.AjaxWebServiceSoapClient(exchangeDetailRow.address);
                //HoSTC_ServiceSoapClient
                client.Endpoint.Address = new System.ServiceModel.EndpointAddress(exchangeDetailRow.address);
                System.ServiceModel.BasicHttpBinding binding = (client.Endpoint.Binding as System.ServiceModel.BasicHttpBinding);

                binding.OpenTimeout = TimeSpan.FromSeconds(Consts.constWebServiceTimeOutInSecs);
                binding.CloseTimeout = binding.OpenTimeout;
                binding.SendTimeout = binding.OpenTimeout;

                binding.MaxReceivedMessageSize = Consts.constWebServiceMaxReceivedMessageSize;
                binding.MaxBufferSize = Consts.constWebServiceMaxReceivedMessageSize;

                binding.ReaderQuotas.MaxStringContentLength = Consts.constWebServiceMaxStringContentLength;
                binding.ReaderQuotas.MaxBytesPerRead = Consts.constWebServiceMaxBytesPerRead;

                String s = String.Empty;
                switch (exchangeDetailRow.code.ToUpper().Trim())
                {
                    case "HOSE_SSI":
                        //s = client.GetDataHoSTC2();
                        s = client.GetHoseStockQuote(0);
                        break;
                    case "HASTC_SSI":
                        //s = client.GetDataHaSTC2();
                        break;
                    default: return null;
                }
                //Parsing
                List<string> tradeList = new List<string>(s.Split('#'));
                databases.importDS.importPriceDataTable importPriceTbl = new databases.importDS.importPriceDataTable();
                CultureInfo dataCulture = application.AppLibs.GetCulture(exchangeDetailRow.culture);
                for (idx = 0; idx < tradeList.Count; idx++)
                {
                    List<string> tradeData = new List<string>(tradeList[idx].Split('|'));
                    if (tradeData[8].Trim() == "" || tradeData[9].Trim() == "")
                    {
                        continue;
                    }
                    databases.importDS.importPriceRow importRow = importPriceTbl.NewimportPriceRow();
                    databases.AppLibs.InitData(importRow);
                    importRow.stockCode = tradeData[0].ToString();
                    importRow.onDate = updateTime;
                    importRow.closePrice = decimal.Parse(tradeData[8], dataCulture);
                    importRow.volume = decimal.Parse(tradeData[9], dataCulture);
                    importRow.isTotalVolume = false;//day ko phai total volume. Cai nay la volume tung thoi diem
                    importPriceTbl.AddimportPriceRow(importRow);
                }
                return importPriceTbl;
            }
            catch (Exception er)
            {
                common.SysLog.WriteLog("Error : " + er.Message);
                return null;
            }
            finally
            {
                if (client != null && client.State == System.ServiceModel.CommunicationState.Opened)
                    client.Close();
            }
        }
Esempio n. 6
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>
        public databases.importDS.importPriceDataTable GetPriceFromWeb(DateTime updateTime, metaStock priceMeta, databases.baseDS.exchangeDetailRow exchangeDetailRow)
        {
            bool bHaveData = false; //Kiem tra xem bang co du lieu hay ko
            //Data in
            CultureInfo CultureInfoUS = common.language.GetCulture("en-US");

            databases.importDS.importPriceDataTable importPriceTbl = new databases.importDS.importPriceDataTable();
            this.mappingList = CreateMapping(priceMeta, importPriceTbl);

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

            // 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;

            databases.importDS.importPriceRow importRow = null;
            databases.importDS.importPriceRow oldImportRow;
            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();
                    databases.AppLibs.InitData(importRow);
                    importRow.onDate        = updateTime;
                    importRow.stockCode     = stockCode;
                    importRow.isTotalVolume = true;
                    columnCount++;
                    continue;
                }
                //Last column
                if (columnCount == priceMeta.endAtColId)
                {
                    if (importRow.closePrice > 0)
                    {
                        //Only add new when there are some changes
                        oldImportRow = lastImportData.Find(importRow);
                        if (!lastImportData.IsSameData(importRow, oldImportRow))
                        {
                            importPriceTbl.AddimportPriceRow(importRow);
                            lastImportData.Update(importRow);
                        }
                        else
                        {
                            importRow.CancelEdit();
                        }
                    }
                    else
                    {
                        importRow.CancelEdit();
                    }
                    columnCount = 0;
                    continue;
                }
                object obj = this.mappingList.GetValue(columnCount.ToString());
                if (obj != null)
                {
                    val = 0; common.system.StrToDecimal(item.Text, CultureInfoUS, out val);

                    //15/07: Kiem tra gia tri co bang 0 hay ko. Neu co thi se co loi doc du lieu
                    if (val != 0)
                    {
                        bHaveData = true;
                    }
                    importRow[(string)obj] = val;
                }
                columnCount++;
            }

            //Neu ko co du lieu
            if (!bHaveData)
            {
                throw new Exception();
            }

            return(importPriceTbl);
        }
Esempio n. 7
0
        /// <summary>
        /// Private - SU dung ASPWebservices
        /// </summary>
        /// <param name="updateTime"></param>
        /// <param name="exchangeDetailRow"></param>
        /// <returns></returns>
        private databases.importDS.importPriceDataTable GetPriceFromWeb(DateTime updateTime, databases.baseDS.exchangeDetailRow exchangeDetailRow)
        {
            int idx = 0;

            clientSSI.AjaxWebServiceSoapClient client = null;
            try
            {
                client = new clientSSI.AjaxWebServiceSoapClient();
                //client = new clientSSI.AjaxWebServiceSoapClient(exchangeDetailRow.address);
                //HoSTC_ServiceSoapClient
                client.Endpoint.Address = new System.ServiceModel.EndpointAddress(exchangeDetailRow.address);
                System.ServiceModel.BasicHttpBinding binding = (client.Endpoint.Binding as System.ServiceModel.BasicHttpBinding);

                binding.OpenTimeout  = TimeSpan.FromSeconds(Consts.constWebServiceTimeOutInSecs);
                binding.CloseTimeout = binding.OpenTimeout;
                binding.SendTimeout  = binding.OpenTimeout;

                binding.MaxReceivedMessageSize = Consts.constWebServiceMaxReceivedMessageSize;
                binding.MaxBufferSize          = Consts.constWebServiceMaxReceivedMessageSize;

                binding.ReaderQuotas.MaxStringContentLength = Consts.constWebServiceMaxStringContentLength;
                binding.ReaderQuotas.MaxBytesPerRead        = Consts.constWebServiceMaxBytesPerRead;

                String s = String.Empty;
                switch (exchangeDetailRow.code.ToUpper().Trim())
                {
                case "HOSE_SSI":
                    //s = client.GetDataHoSTC2();
                    s = client.GetHoseStockQuote(0);
                    break;

                case "HASTC_SSI":
                    //s = client.GetDataHaSTC2();
                    break;

                default: return(null);
                }
                //Parsing
                List <string> tradeList = new List <string>(s.Split('#'));
                databases.importDS.importPriceDataTable importPriceTbl = new databases.importDS.importPriceDataTable();
                CultureInfo dataCulture = application.AppLibs.GetCulture(exchangeDetailRow.culture);
                for (idx = 0; idx < tradeList.Count; idx++)
                {
                    List <string> tradeData = new List <string>(tradeList[idx].Split('|'));
                    if (tradeData[8].Trim() == "" || tradeData[9].Trim() == "")
                    {
                        continue;
                    }
                    databases.importDS.importPriceRow importRow = importPriceTbl.NewimportPriceRow();
                    databases.AppLibs.InitData(importRow);
                    importRow.stockCode     = tradeData[0].ToString();
                    importRow.onDate        = updateTime;
                    importRow.closePrice    = decimal.Parse(tradeData[8], dataCulture);
                    importRow.volume        = decimal.Parse(tradeData[9], dataCulture);
                    importRow.isTotalVolume = false;//day ko phai total volume. Cai nay la volume tung thoi diem
                    importPriceTbl.AddimportPriceRow(importRow);
                }
                return(importPriceTbl);
            }
            catch (Exception er)
            {
                common.SysLog.WriteLog("Error : " + er.Message);
                return(null);
            }
            finally
            {
                if (client != null && client.State == System.ServiceModel.CommunicationState.Opened)
                {
                    client.Close();
                }
            }
        }
Esempio n. 8
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>
        public databases.importDS.importPriceDataTable GetPriceFromWeb(DateTime updateTime, metaStock priceMeta,databases.baseDS.exchangeDetailRow exchangeDetailRow)
        {
            bool bHaveData = false; //Kiem tra xem bang co du lieu hay ko
            //Data in
            CultureInfo CultureInfoUS = common.language.GetCulture("en-US");
            databases.importDS.importPriceDataTable importPriceTbl = new databases.importDS.importPriceDataTable();
            this.mappingList = CreateMapping(priceMeta, importPriceTbl);

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

            // 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;
            databases.importDS.importPriceRow importRow = null;
            databases.importDS.importPriceRow oldImportRow;
            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();
                    databases.AppLibs.InitData(importRow);
                    importRow.onDate = updateTime;
                    importRow.stockCode = stockCode;
                    importRow.isTotalVolume = true;
                    columnCount++;
                    continue;
                }
                //Last column
                if (columnCount == priceMeta.endAtColId)
                {
                    if (importRow.closePrice > 0)
                    {
                        //Only add new when there are some changes 
                        oldImportRow = lastImportData.Find(importRow);
                        if (!lastImportData.IsSameData(importRow, oldImportRow))
                        {
                            importPriceTbl.AddimportPriceRow(importRow);
                            lastImportData.Update(importRow);
                        }
                        else importRow.CancelEdit();
                    }
                    else importRow.CancelEdit();
                    columnCount = 0;
                    continue;
                }
                object obj = this.mappingList.GetValue(columnCount.ToString());
                if (obj != null)
                {
                    val = 0; common.system.StrToDecimal(item.Text, CultureInfoUS, out val);

                    //15/07: Kiem tra gia tri co bang 0 hay ko. Neu co thi se co loi doc du lieu
                    if (val != 0)
                        bHaveData = true;                    
                    importRow[(string)obj] = val;
                }
                columnCount++;
            }

            //Neu ko co du lieu
            if (!bHaveData) 
                throw new Exception();
            
            return importPriceTbl;
            
        }