public static void InitData(databases.importDS.importPriceRow row) { row.onDate = common.Consts.constNullDate; row.stockCode = ""; row.closePrice = 0; row.volume = 0; row.isTotalVolume = false; }
public databases.importDS.importPriceRow Find(databases.importDS.importPriceRow row) { DataRowView[] foundRows = dataTbl.DefaultView.FindRows(new object[] { row.stockCode }); if (foundRows.Length <= 0) { return(null); } return((databases.importDS.importPriceRow)foundRows[0].Row); }
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; }
public bool IsSameData(databases.importDS.importPriceRow row1, databases.importDS.importPriceRow row2) { if (row1 == null && row2 == null) { return(false); } if (row1 == null && row2 != null) { return(false); } if (row1 != null && row2 == null) { return(false); } return((row1.closePrice == row2.closePrice) && (row1.volume == row2.volume)); }
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); }
public void UpdateData(databases.importDS.importPriceRow row) { if (lastTime != row.onDate.Date) { Reset(); lastTime = row.onDate.Date; } databases.baseDS.priceDataSumRow priceRow = GetData(row); if (priceRow == null) { priceRow = priceSumTbl.NewpriceDataSumRow(); databases.AppLibs.InitData(priceRow); priceRow.type = timeType; priceRow.stockCode = row.stockCode; priceRow.onDate = row.onDate.Date; priceSumTbl.AddpriceDataSumRow(priceRow); } //Now only volume need to be processed priceRow.volume = row.volume; priceRow.closePrice = row.closePrice; }
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(); } }
/// <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); }
/// <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(); } } }
public databases.baseDS.priceDataSumRow GetData(databases.importDS.importPriceRow row) { return(FindAndCache(priceSumTbl, row.stockCode, timeType, row.onDate.Date)); }