private void DoRefreshPrice(databases.tmpDS.stockCodeDataTable dataTbl) { databases.baseDS.lastPriceDataDataTable openPriceTbl = DataAccess.Libs.myLastDailyOpenPrice; databases.baseDS.lastPriceDataDataTable closePriceTbl = DataAccess.Libs.myLastDailyClosePrice; //databases.baseDS.lastPriceDataDataTable volumeTbl = DataAccess.Libs.myLastDailyVolume; if (openPriceTbl == null || closePriceTbl == null) { return; } dataTbl.priceColumn.ReadOnly = false; dataTbl.priceVariantColumn.ReadOnly = false; databases.tmpDS.stockCodeRow stockCodeRow; databases.baseDS.lastPriceDataRow openPriceRow, closePriceRow; //databases.baseDS.lastPriceDataRow volumeRow; for (int idx = 0; idx < stockGV.RowCount; idx++) { //Lay stock code stockCodeRow = dataTbl.FindBycode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString()); if (stockCodeRow == null) { continue; } //Lay gia dong cua closePriceRow = closePriceTbl.FindBystockCode(stockCodeRow.code); if (closePriceRow == null) { continue; } if (stockCodeRow.price == closePriceRow.value) { continue; } //Lay chenh lech Open/Close stockCodeRow.price = closePriceRow.value; openPriceRow = openPriceTbl.FindBystockCode(stockCodeRow.code); if (openPriceRow != null && openPriceRow.value != 0) { stockCodeRow.priceVariant = (closePriceRow.value - openPriceRow.value) / openPriceRow.value; } else { stockCodeRow.priceVariant = 0; } //Lay volume //volumeRow = volumeTbl.FindBystockCode(stockCodeRow.code); //if (volumeRow == null) continue; //if (stockCodeRow.volume == volumeRow.value) continue; //stockCodeRow.volume = volumeRow.value; } SetColor(); }
public void Diagnose(string exchangeCode, commonTypes.AppTypes.PriceDataType dataType, double allowVariantPerc, ref databases.tmpDS.priceDiagnoseDataTable priceDiagnoseTbl) { databases.tmpDS.stockCodeDataTable codeTbl = new databases.tmpDS.stockCodeDataTable(); databases.DbAccess.LoadStockCode_ByStockExchange(codeTbl, exchangeCode, AppTypes.CommonStatus.Enable); for (int idx = 0; idx < codeTbl.Count; idx++) { //Diagnose(dataType,allowVariantPerc, ref databases.tmpDS.priceDiagnoseDataTable priceDiagnoseTbl) } }
public void Diagnose(string exchangeCode,commonTypes.AppTypes.PriceDataType dataType, double allowVariantPerc, ref databases.tmpDS.priceDiagnoseDataTable priceDiagnoseTbl) { databases.tmpDS.stockCodeDataTable codeTbl = new databases.tmpDS.stockCodeDataTable(); databases.DbAccess.LoadStockCode_ByStockExchange(codeTbl, exchangeCode, AppTypes.CommonStatus.Enable); for (int idx = 0; idx < codeTbl.Count; idx++) { //Diagnose(dataType,allowVariantPerc, ref databases.tmpDS.priceDiagnoseDataTable priceDiagnoseTbl) } }
public static databases.tmpDS.stockCodeRow FindAndCache(databases.tmpDS.stockCodeDataTable tbl, string code) { databases.tmpDS.stockCodeRow row = tbl.FindBycode(code); if (row != null) { return(row); } databases.tmpDSTableAdapters.stockCodeTA dataTA = new databases.tmpDSTableAdapters.stockCodeTA(); dataTA.ClearBeforeFill = false; dataTA.FillByCode(tbl, code); row = tbl.FindBycode(code); if (row != null) { return(row); } return(null); }
private void DoRefreshPrice(databases.tmpDS.stockCodeDataTable dataTbl) { databases.baseDS.lastPriceDataDataTable openPriceTbl = DataAccess.Libs.myLastDailyOpenPrice; databases.baseDS.lastPriceDataDataTable closePriceTbl = DataAccess.Libs.myLastDailyClosePrice; if (openPriceTbl == null || closePriceTbl == null) { return; } dataTbl.priceColumn.ReadOnly = false; dataTbl.priceVariantColumn.ReadOnly = false; databases.tmpDS.stockCodeRow stockCodeRow; databases.baseDS.lastPriceDataRow openPriceRow, closePriceRow; for (int idx = 0; idx < stockGV.RowCount; idx++) { stockCodeRow = dataTbl.FindBycode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString()); if (stockCodeRow == null) { continue; } closePriceRow = closePriceTbl.FindBystockCode(stockCodeRow.code); if (closePriceRow == null) { continue; } if (stockCodeRow.price == closePriceRow.value) { continue; } stockCodeRow.price = closePriceRow.value; openPriceRow = openPriceTbl.FindBystockCode(stockCodeRow.code); if (openPriceRow != null) { stockCodeRow.priceVariant = closePriceRow.value - openPriceRow.value; } else { stockCodeRow.priceVariant = 0; } } SetColor(); }
//public static int CreateTradeAlert() //{ // CreateTradeAlert(null, null, null); //} public static int CreateTradeAlert(onProcessStart onStartFunc, onProcessItem onProcessItemFunc, onProcessEnd onEndFunc) { DateTime frDate = common.Consts.constNullDate; DateTime toDate = DateTime.Now; //Run all strategy analysis for all stocks. databases.tmpDS.stockCodeDataTable stockCodeTbl = new databases.tmpDS.stockCodeDataTable(); databases.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable); application.AnalysisData data = new application.AnalysisData(); data.DataTimeRange = AppTypes.TimeRanges.None; data.DataMaxCount = Settings.sysGlobal.AlertDataCount; TradeAlertItem[] tradeAlertList = new TradeAlertItem[0]; StringCollection strategyList = new StringCollection(); for (int idx = 0; idx < StrategyData.MetaList.Values.Length; idx++) { application.Strategy.StrategyMeta meta = (application.Strategy.StrategyMeta)StrategyData.MetaList.Values[idx]; if (meta.Type != AppTypes.StrategyTypes.Strategy) { continue; } strategyList.Add(((application.Strategy.StrategyMeta)StrategyData.MetaList.Values[idx]).Code); } if (onStartFunc != null) { onStartFunc(stockCodeTbl.Count); } DateTime alertDate; DateTime alertFrDate = toDate.Date; DateTime alertToDate = toDate; for (int stockCodeIdx = 0; stockCodeIdx < stockCodeTbl.Count; stockCodeIdx++) { if (onProcessItemFunc != null) { if (!onProcessItemFunc(stockCodeTbl[stockCodeIdx].code)) { break; } } //foreach (AppTypes.TimeScale timeScale in AppTypes.myTimeScales) //??? AppTypes.TimeScale timeScale = AppTypes.TimeScaleFromType(AppTypes.TimeScaleTypes.Day); { data.DataStockCode = stockCodeTbl[stockCodeIdx].code; data.DataTimeScale = timeScale; data.LoadData(); for (int strategyIdx = 0; strategyIdx < strategyList.Count; strategyIdx++) { StrategyData.ClearCache(); TradePoints advices = application.Strategy.StrategyLibs.AnalysisStrategy(data, strategyList[strategyIdx].Trim()); if ((advices == null) || (advices.Count == 0)) { continue; } //Only check the last advices for alert TradePointInfo tradeInfo = (TradePointInfo)advices[advices.Count - 1]; alertDate = DateTime.FromOADate(data.DateTime[tradeInfo.DataIdx]); //Ignore alerts that out of date range. if (alertDate < alertFrDate || alertDate > alertToDate) { continue; } Array.Resize(ref tradeAlertList, tradeAlertList.Length + 1); tradeAlertList[tradeAlertList.Length - 1] = new TradeAlertItem(stockCodeTbl[stockCodeIdx].code.Trim(), strategyList[strategyIdx].Trim(), timeScale, alertDate, data.Close[tradeInfo.DataIdx], data.Volume[tradeInfo.DataIdx], tradeInfo); } } } //Create alerts in the day int noAlertCreated = CreateTradeAlert(tradeAlertList); //Save last lun date //SaveLastRunTime(toDate); if (onEndFunc != null) { onEndFunc(); } stockCodeTbl.Dispose(); return(noAlertCreated); }
private void DoFilter(bool notUseCache) { string cacheKey; common.myKeyValueExt item = (common.myKeyValueExt)common.Threading.GetValue(codeGroupCb, "SelectedItem"); cbStockSelection.Options watchListType = (cbStockSelection.Options) byte.Parse(item.Attribute1); StringCollection stocCodeList = new StringCollection(); myStockTbl.Columns[myStockTbl.selectedColumn.ColumnName].ReadOnly = false; switch (watchListType) { case cbStockSelection.Options.All: stockSource.Filter = ""; break; case cbStockSelection.Options.StockExchange: stockSource.Filter = this.myStockTbl.stockExchangeColumn.ColumnName + "='" + item.Value + "'"; break; case cbStockSelection.Options.SysWatchList: case cbStockSelection.Options.WatchList: cacheKey = watchListType.ToString();; StringCollection watchList = new StringCollection(); //All stock codes of specified type ?? if (item.Value != "") { cacheKey += "-" + item.Value; watchList.Add(item.Value); } else { for (int idx = 0; idx < codeGroupCb.Items.Count; idx++) { common.myKeyValueExt tmpItem = (common.myKeyValueExt)codeGroupCb.Items[idx]; if (watchListType != (cbStockSelection.Options) byte.Parse(tmpItem.Attribute1) || (tmpItem.Value == "")) { continue; } watchList.Add(tmpItem.Value); } } cacheKey = DataAccess.Libs.MakeCacheKey(this, cacheKey); if (notUseCache) { DataAccess.Libs.ClearCache(cacheKey); } StringCollection selectStockList = null; object obj = DataAccess.Libs.GetCache(cacheKey); if (obj != null) { selectStockList = (obj as StringCollection); } else { selectStockList = common.system.List2Collection(DataAccess.Libs.GetStockList_ByWatchList(watchList)); DataAccess.Libs.AddCache(cacheKey, selectStockList); } for (int idx = 0; idx < this.myStockTbl.Count; idx++) { this.myStockTbl[idx].selected = (selectStockList.Contains(this.myStockTbl[idx].code)?1:0); } stockSource.Filter = this.myStockTbl.selectedColumn + "=1"; break; case cbStockSelection.Options.UserPorfolio: cacheKey = watchListType.ToString();; StringCollection porfolioList = new StringCollection(); //All stock codes of the specified type ?? if (item.Value != "") { cacheKey += "-" + item.Value; porfolioList.Add(item.Value); } else { for (int idx = 0; idx < codeGroupCb.Items.Count; idx++) { common.myKeyValueExt tmpItem = (common.myKeyValueExt)codeGroupCb.Items[idx]; if (watchListType != (cbStockSelection.Options) byte.Parse(tmpItem.Attribute1) || (tmpItem.Value == "")) { continue; } porfolioList.Add(tmpItem.Value); } } cacheKey = DataAccess.Libs.MakeCacheKey(this, cacheKey); if (notUseCache) { DataAccess.Libs.ClearCache(cacheKey); } databases.tmpDS.stockCodeDataTable codeTbl = null; obj = DataAccess.Libs.GetCache(cacheKey); if (obj != null) { codeTbl = (obj as databases.tmpDS.stockCodeDataTable); } else { codeTbl = DataAccess.Libs.GetStock_InPortfolio(porfolioList); DataAccess.Libs.AddCache(cacheKey, codeTbl); } for (int idx = 0; idx < this.myStockTbl.Count; idx++) { this.myStockTbl[idx].selected = (codeTbl.FindBycode(this.myStockTbl[idx].code) != null ? 1 : 0); } stockSource.Filter = this.myStockTbl.selectedColumn + "=1"; break; } }
private static databases.tmpDS.stockCodeDataTable StockFromCodeList(string[] codes) { try { databases.tmpDS.stockCodeDataTable retTbl = new databases.tmpDS.stockCodeDataTable(); databases.tmpDS.stockCodeRow stockRow; databases.tmpDS.stockCodeDataTable stockCodeTbl = myStockCodeTbl; for (int idx = 0; idx < codes.Length; idx++) { stockRow = stockCodeTbl.FindBycode(codes[idx]); if (stockRow != null) retTbl.ImportRow(stockRow); } return retTbl; } catch (Exception er) { if (OnError != null) OnError(er); } return null; }
public override void LoadData() { this.myDataTbl = DataAccess.Libs.myStockCodeTbl; }
//public static int CreateTradeAlert() //{ // CreateTradeAlert(null, null, null); //} public static int CreateTradeAlert(onProcessStart onStartFunc, onProcessItem onProcessItemFunc, onProcessEnd onEndFunc) { DateTime frDate = common.Consts.constNullDate; DateTime toDate = DateTime.Now; //Run all strategy analysis for all stocks. databases.tmpDS.stockCodeDataTable stockCodeTbl = new databases.tmpDS.stockCodeDataTable(); databases.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable); application.AnalysisData data = new application.AnalysisData(); data.DataTimeRange = AppTypes.TimeRanges.None; data.DataMaxCount = Settings.sysGlobal.AlertDataCount; TradeAlertItem[] tradeAlertList = new TradeAlertItem[0]; StringCollection strategyList = new StringCollection(); for (int idx = 0; idx < application.Strategy.StrategyData.MetaList.Values.Length; idx++) { application.Strategy.StrategyMeta meta = (application.Strategy.StrategyMeta)application.Strategy.StrategyData.MetaList.Values[idx]; if (meta.Type != AppTypes.StrategyTypes.Strategy) continue; strategyList.Add(((application.Strategy.StrategyMeta)application.Strategy.StrategyData.MetaList.Values[idx]).Code); } if (onStartFunc != null) onStartFunc(stockCodeTbl.Count); DateTime alertDate; DateTime alertFrDate = toDate.Date; DateTime alertToDate = toDate; for (int stockCodeIdx = 0; stockCodeIdx < stockCodeTbl.Count; stockCodeIdx++) { if (onProcessItemFunc != null) if (!onProcessItemFunc(stockCodeTbl[stockCodeIdx].code)) break; //foreach (AppTypes.TimeScale timeScale in AppTypes.myTimeScales) //??? AppTypes.TimeScale timeScale = AppTypes.TimeScaleFromType(AppTypes.TimeScaleTypes.Day); { data.DataStockCode = stockCodeTbl[stockCodeIdx].code; data.DataTimeScale = timeScale; data.LoadData(); for (int strategyIdx = 0; strategyIdx < strategyList.Count; strategyIdx++) { application.Strategy.StrategyData.ClearCache(); application.Strategy.StrategyData.TradePoints advices = application.Strategy.StrategyLibs.AnalysisStrategy(data, strategyList[strategyIdx].Trim()); if ( (advices == null) || (advices.Count==0)) continue; //Only check the last advices for alert TradePointInfo tradeInfo = (TradePointInfo)advices[advices.Count-1]; alertDate = DateTime.FromOADate(data.DateTime[tradeInfo.DataIdx]); //Ignore alerts that out of date range. if (alertDate < alertFrDate || alertDate > alertToDate) continue; Array.Resize(ref tradeAlertList, tradeAlertList.Length + 1); tradeAlertList[tradeAlertList.Length - 1] = new TradeAlertItem(stockCodeTbl[stockCodeIdx].code.Trim(), strategyList[strategyIdx].Trim(), timeScale, alertDate, data.Close[tradeInfo.DataIdx], data.Volume[tradeInfo.DataIdx],tradeInfo); } } } //Create alerts in the day int noAlertCreated = CreateTradeAlert(tradeAlertList); //Save last lun date //SaveLastRunTime(toDate); if (onEndFunc != null) onEndFunc(); stockCodeTbl.Dispose(); return noAlertCreated; }
public databases.tmpDS.stockCodeDataTable GetStock_InPortfolio(string[] portfolios) { try { databases.tmpDS.stockCodeDataTable retTbl = new databases.tmpDS.stockCodeDataTable(); databases.DbAccess.LoadStockCode_ByPortfolios(retTbl, common.system.List2Collection(portfolios)); return retTbl; } catch (Exception ex) { WriteSysLogLocal("WS039", ex); } return null; }
public databases.tmpDS.stockCodeDataTable GetStock_ByBizSector(string[] bizSectors) { try { databases.tmpDS.stockCodeDataTable retTbl = new databases.tmpDS.stockCodeDataTable(); databases.DbAccess.LoadStockCode_ByBizSectors(retTbl, common.system.List2Collection(bizSectors)); return retTbl; } catch (Exception ex) { WriteSysLogLocal("WS040", ex); } return null; }
public string[] GetStockList_ByWatchList(string[] watchList) { try { databases.tmpDS.stockCodeDataTable stockCodeTbl = new databases.tmpDS.stockCodeDataTable(); databases.DbAccess.LoadStockCode_ByWatchList(stockCodeTbl, common.system.List2Collection(watchList)); return MakeStockCodeList(stockCodeTbl); } catch (Exception ex) { WriteSysLogLocal("WS037", ex); } return null; }
public databases.tmpDS.stockCodeDataTable GetStockByStatus(AppTypes.CommonStatus status) { try { databases.tmpDS.stockCodeDataTable tbl = new databases.tmpDS.stockCodeDataTable(); databases.DbAccess.LoadData(tbl, status); return tbl; } catch (Exception ex) { WriteSysLogLocal("WS017", ex); } return null; }
public databases.tmpDS.priceDiagnoseDataTable DiagnosePrice_CloseAndNextOpen(DateTime frDate, DateTime toDate, string timeScaleCode, string exchangeCode,string code, double variancePerc, double variance,byte precision) { try { databases.baseDS.priceDataDataTable priceDataTbl = new databases.baseDS.priceDataDataTable(); databases.tmpDS.priceDiagnoseDataTable priceDiagnoseTbl = new databases.tmpDS.priceDiagnoseDataTable(); if (code != null && code.Trim() != "") { priceDataTbl.Clear(); databases.DbAccess.LoadData(priceDataTbl, timeScaleCode, frDate, toDate, code.Trim()); application.AppLibs.DiagnosePrice_CloseAndNextOpen(priceDataTbl, variancePerc, variance,precision, priceDiagnoseTbl); } else { databases.tmpDS.stockCodeDataTable codeTbl = new databases.tmpDS.stockCodeDataTable(); databases.DbAccess.LoadStockCode_ByStockExchange(codeTbl, exchangeCode, AppTypes.CommonStatus.Enable); for (int idx = 0; idx < codeTbl.Count; idx++) { priceDataTbl.Clear(); databases.DbAccess.LoadData(priceDataTbl, timeScaleCode, frDate, toDate, codeTbl[idx].code); application.AppLibs.DiagnosePrice_CloseAndNextOpen(priceDataTbl, variancePerc, variance,precision, priceDiagnoseTbl); } codeTbl.Dispose(); } priceDataTbl.Dispose(); return priceDiagnoseTbl; } catch (Exception ex) { WriteSysLogLocal("WS088", ex); } return null; }