Beispiel #1
0
        public static void LoadStockCode_ByCodeList(data.tmpDS.stockCodeDataTable tbl, StringCollection stockCode)
        {
            string cond   = common.system.MakeConditionStr(stockCode, "" + tbl.codeColumn.ColumnName + "=N'", "'", "OR");
            string sqlCmd = "SELECT * FROM stockCode WHERE " + cond;

            LoadFromSQL(tbl, sqlCmd);
        }
Beispiel #2
0
        public static void LoadStockCode_ByWatchList(data.tmpDS.stockCodeDataTable stockCodeTbl, StringCollection codes)
        {
            StringCollection retList = new StringCollection();
            StringCollection list;

            data.tmpDS.stockCodeDataTable  tmpTbl       = new data.tmpDS.stockCodeDataTable();
            data.baseDS.portfolioDataTable portfolioTbl = new data.baseDS.portfolioDataTable();
            data.baseDS.portfolioRow       portfolioRow;
            for (int idx1 = 0; idx1 < codes.Count; idx1++)
            {
                portfolioRow = SysLibs.FindAndCache(portfolioTbl, codes[idx1]);
                if (portfolioRow == null)
                {
                    continue;
                }
                list = common.MultiValueString.String2List(portfolioRow.interestedStock);
                if (list.Count <= 0)
                {
                    continue;
                }
                tmpTbl.Clear();
                LoadStockCode_ByCodeList(tmpTbl, list);
                for (int idx2 = 0; idx2 < tmpTbl.Count; idx2++)
                {
                    if (stockCodeTbl.FindBycode(tmpTbl[idx2].code) == null)
                    {
                        stockCodeTbl.ImportRow(tmpTbl[idx2]);
                    }
                }
            }
            portfolioTbl.Dispose();
        }
        protected override void LoadData(data.tmpDS.stockCodeDataTable toTbl, string[] portfolioCodes)
        {
            DateTime startTime = DateTime.Now;

            LoadStockList(toTbl, portfolioCodes);
            UpdateRealTime(toTbl, portfolioCodes);
            this.ShowMessage(common.dateTimeLibs.TimeSpan2String(DateTime.Now.Subtract(startTime)));
        }
Beispiel #4
0
 private static string[] MakeStockCodeList(data.tmpDS.stockCodeDataTable stockCodeTbl)
 {
     string[] retList = new string[stockCodeTbl.Count];
     for (int idx = 0; idx < stockCodeTbl.Count; idx++)
     {
         retList[idx] = stockCodeTbl[idx].code;
     }
     return(retList);
 }
Beispiel #5
0
        public static void LoadStockCode_ByBizSectors(data.tmpDS.stockCodeDataTable tbl, StringCollection bizSectors)
        {
            data.baseDS.stockCodeDataTable comTbl = new data.baseDS.stockCodeDataTable();
            string cond = common.system.MakeConditionStr(bizSectors,
                                                         comTbl.bizSectorsColumn.ColumnName + " LIKE N'" +
                                                         common.Consts.SQL_CMD_ALL_MARKER + common.settings.sysListSeparatorPrefix,
                                                         common.settings.sysListSeparatorPostfix + common.Consts.SQL_CMD_ALL_MARKER + "'",
                                                         "OR");
            string sqlCmd = "SELECT code, stockExchange, tickerCode, name,nameEn,0 AS price,0 AS priceVariant FROM stockCode WHERE " + cond;

            LoadFromSQL(tbl, sqlCmd);
        }
Beispiel #6
0
        private static data.tmpDS.stockCodeDataTable StockFromCodeList(string[] codes)
        {
            data.tmpDS.stockCodeDataTable retTbl = new data.tmpDS.stockCodeDataTable();

            data.tmpDS.stockCodeRow       stockRow;
            data.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);
        }
Beispiel #7
0
 public static data.tmpDS.stockCodeRow FindAndCache(data.tmpDS.stockCodeDataTable tbl, string code)
 {
     data.tmpDS.stockCodeRow row = tbl.FindBycode(code);
     if (row != null)
     {
         return(row);
     }
     data.tmpDSTableAdapters.stockCodeTA dataTA = new data.tmpDSTableAdapters.stockCodeTA();
     dataTA.ClearBeforeFill = false;
     dataTA.FillByCode(tbl, code);
     row = tbl.FindBycode(code);
     if (row != null)
     {
         return(row);
     }
     return(null);
 }
Beispiel #8
0
        public static void LoadStockCode_ByPortfolios(data.tmpDS.stockCodeDataTable tbl, StringCollection portfolios)
        {
            data.baseDS.investorStockDataTable tmpTbl = new data.baseDS.investorStockDataTable();
            string cond = common.system.MakeConditionStr(portfolios, "b." + tmpTbl.portfolioColumn.ColumnName + "=N'", "'", "OR");

            if (cond.Trim() == "")
            {
                return;
            }

            tmpTbl.Dispose();

            string sqlCmd = "SELECT DISTINCT a.*" +
                            " FROM stockCode a" +
                            " INNER JOIN investorStock b ON a.code = b.stockCode" +
                            " WHERE " + cond;

            LoadFromSQL(tbl, sqlCmd);
        }
        private void DoRefreshPrice(data.tmpDS.stockCodeDataTable dataTbl)
        {
            //Open price is the same all day.
            if (openPriceTbl == null || openPriceDate != DateTime.Today)
            {
                openPriceTbl  = DataAccess.Libs.GetLastPrice(commonClass.PriceDataType.Open);
                openPriceDate = DateTime.Today;
            }

            data.baseDS.lastPriceDataDataTable priceTbl = DataAccess.Libs.GetLastPrice(commonClass.PriceDataType.Close);
            if (priceTbl == null)
            {
                return;
            }

            data.tmpDS.stockCodeRow      stockCodeRow;
            data.baseDS.lastPriceDataRow openPriceRow, closePriceRow;
            dataTbl.priceColumn.ReadOnly        = false;
            dataTbl.priceVariantColumn.ReadOnly = false;
            for (int idx = 0; idx < stockGV.RowCount; idx++)
            {
                stockCodeRow = dataTbl.FindBycode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString());
                if (stockCodeRow == null)
                {
                    continue;
                }
                closePriceRow = priceTbl.FindBystockCode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString());
                if (stockCodeRow.price != closePriceRow.value)
                {
                    stockCodeRow.price = closePriceRow.value;
                    openPriceRow       = openPriceTbl.FindBystockCode(stockGV.Rows[idx].Cells[codeColumn.Name].Value.ToString());
                    if (openPriceRow != null)
                    {
                        stockCodeRow.priceVariant = closePriceRow.value - openPriceRow.value;
                    }
                    else
                    {
                        stockCodeRow.priceVariant = 0;
                    }
                }
            }
        }
Beispiel #10
0
        public static void LoadData(data.tmpDS.stockCodeDataTable stockCodeTbl, data.baseDS.portfolioRow row)
        {
            StringCollection list;

            list = common.MultiValueString.String2List(row.interestedSector);
            if (list.Count > 0)
            {
                LoadStockCode_ByBizSectors(stockCodeTbl, list);
            }

            list = common.MultiValueString.String2List(row.interestedStock);
            if (list.Count > 0)
            {
                data.tmpDS.stockCodeDataTable tmpTbl = new data.tmpDS.stockCodeDataTable();
                LoadStockCode_ByCodeList(tmpTbl, list);
                for (int idx = 0; idx < tmpTbl.Count; idx++)
                {
                    SysLibs.FindAndCache(stockCodeTbl, tmpTbl[idx].code);
                }
            }
        }
        protected void LoadStockList(data.tmpDS.stockCodeDataTable toTbl, string[] watchCodes)
        {
            //Load stocks in portfolio
            data.tmpDS.stockCodeDataTable myStockCodeTbl = null;
            switch (this.watchType)
            {
            case AppTypes.PortfolioTypes.Portfolio:
                myStockCodeTbl = DataAccess.Libs.GetStock_InPortfolio(common.system.List2Collection(watchCodes));
                break;

            case AppTypes.PortfolioTypes.WatchList:
                myStockCodeTbl = DataAccess.Libs.GetStock_ByWatchList(common.system.List2Collection(watchCodes));
                break;

            default:
                common.system.ThrowException("Invalid WatchType");
                break;
            }

            DataView myStockView = new DataView(myStockCodeTbl);

            data.baseDS.stockCodeRow stockRow;
            myStockView.Sort = myStockCodeTbl.codeColumn.ColumnName + "," + myStockCodeTbl.stockExchangeColumn.ColumnName;
            data.tmpDS.stockCodeRow reportRow;
            for (int idx1 = 0; idx1 < myStockView.Count; idx1++)
            {
                stockRow = (data.baseDS.stockCodeRow)myStockView[idx1].Row;
                //Ignore duplicate stocks
                reportRow = toTbl.FindBycode(stockRow.code);
                if (reportRow != null)
                {
                    continue;
                }
                reportRow = toTbl.NewstockCodeRow();
                commonClass.AppLibs.InitData(reportRow);
                reportRow.code          = stockRow.code;
                reportRow.stockExchange = stockRow.stockExchange;
                toTbl.AddstockCodeRow(reportRow);
            }
        }
        protected void UpdateRealTime(data.tmpDS.stockCodeDataTable reportTbl, string[] portfolioCodes)
        {
            //DateTime onTime = DataAccess.Libs.GetServerDateTime();
            //data.baseDS.priceDataRow priceRow;
            //data.tmpDS.portfolioListRow reportRow;
            //decimal qty = 0, boughtAmt = 0;
            //byte allTimeScaleMask = 0;
            //foreach (AppTypes.TimeScale item in Enum.GetValues(typeof(AppTypes.TimeScale))) allTimeScaleMask += (byte)item;


            //progressBar.Visible = true;
            //progressBar.Maximum = reportTbl.Count; progressBar.Value = 0;
            //for (int idx1 = 0; idx1 < reportTbl.Count; idx1++)
            //{
            //    reportRow = reportTbl[idx1];
            //    reportRow.qty = 0; reportRow.boughtAmt = 0;
            //    for (int idx2 = 0; idx2 < portfolioCodes.Length; idx2++)
            //    {
            //        dataLibs.GetOwnStock(reportRow.stockCode, portfolioCodes[idx2], 0, onTime, out qty, out boughtAmt);
            //        reportRow.qty += qty; reportRow.boughtAmt += boughtAmt;
            //    }
            //    reportRow.boughtPrice = (reportRow.qty == 0 ? 0 : reportRow.boughtAmt / reportRow.qty) / application.Settings.sysStockPriceWeight;

            //    priceRow = application.dataLibs.GetLastPrice(onTime.Date, onTime, AppTypes.TimeScale.Daily, reportRow.stockCode);
            //    reportRow.price = (priceRow == null ? 0 : priceRow.closePrice);
            //    reportRow.priceVariant = (priceRow == null ? 0 : reportRow.price - priceRow.openPrice);
            //    reportRow.volume = (priceRow == null ? 0 : priceRow.volume);
            //    reportRow.amt = reportRow.qty * reportRow.price * application.Settings.sysStockPriceWeight;
            //    reportRow.profitVariantAmt = reportRow.amt - reportRow.boughtAmt;
            //    reportRow.profitVariantPerc = (reportRow.boughtAmt == 0 ? 0 : reportRow.profitVariantAmt / reportRow.boughtAmt) * 100;

            //    //Alert summary info
            //    reportRow.notes = AlertSummaryInfo(onTime, reportRow.stockCode, allTimeScaleMask, (byte)AppTypes.CommonStatus.New);
            //    progressBar.Value++;
            //}
            //progressBar.Visible = false;
        }
Beispiel #13
0
 public string[] GetStockList_ByWatchList(string[] watchList)
 {
     data.tmpDS.stockCodeDataTable stockCodeTbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadStockCode_ByWatchList(stockCodeTbl,common.system.List2Collection(watchList));
     return MakeStockCodeList(stockCodeTbl);
 }
Beispiel #14
0
 public data.tmpDS.stockCodeDataTable GetStockByStatus(AppTypes.CommonStatus status)
 {
     data.tmpDS.stockCodeDataTable tbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadData(tbl, status);
     return(tbl);
 }
Beispiel #15
0
 public static void LoadData(data.tmpDS.stockCodeDataTable tbl, AppTypes.CommonStatus status)
 {
     shortStockCodeTA.ClearBeforeFill = false;
     shortStockCodeTA.FillByStatusMask(tbl, ((byte)status).ToString());
 }
Beispiel #16
0
        private static data.tmpDS.stockCodeDataTable StockFromCodeList(string[] codes)
        {
            data.tmpDS.stockCodeDataTable retTbl = new data.tmpDS.stockCodeDataTable();

            data.tmpDS.stockCodeRow stockRow;
            data.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;
        }
        public static void CreateTradeAlert(onProcessStart onStartFunc, onProcessItem onProcessItemFunc, onProcessEnd onEndFunc)
        {
            CultureInfo cultureInfo = new CultureInfo(Settings.sysCultureCode);
            DateTime frDate = common.Consts.constNullDate;
            DateTime toDate = DateTime.Now;
            
            //Run all strategy analysis for all stocks.
            data.tmpDS.stockCodeDataTable stockCodeTbl = new data.tmpDS.stockCodeDataTable();
            global::data.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable);

            application.Data data = new application.Data();

            TradeAlert[] tradeAlertList = new TradeAlert[0];
            StringCollection strategyList = new StringCollection();
            for (int idx = 0; idx < Strategy.Data.MetaList.Values.Length; idx++)
            {
                Strategy.Meta meta = (Strategy.Meta)Strategy.Data.MetaList.Values[idx];
                if (meta.Type != AppTypes.StrategyTypes.Strategy) continue;
                strategyList.Add(((Strategy.Meta)Strategy.Data.MetaList.Values[idx]).Code);
            }

            if (onStartFunc != null) onStartFunc(stockCodeTbl.Count);

            for (int stockCodeIdx = 0; stockCodeIdx < stockCodeTbl.Count; stockCodeIdx++)
            {
                if (onProcessItemFunc != null)
                    if (!onProcessItemFunc(stockCodeTbl[stockCodeIdx].code)) break;

                foreach (AppTypes.TimeScale timeScale in AppTypes.myTimeScales)
                {
                    //Move date ahead to ensure that there are sufficient data need in analysis process
                    switch (timeScale.Type)
                    {
                        case AppTypes.TimeScaleTypes.RealTime:
                            frDate = toDate.AddHours(-1);
                            break;
                        case AppTypes.TimeScaleTypes.Hour:
                            frDate = toDate.Date;
                            break;
                        case AppTypes.TimeScaleTypes.Day:
                            frDate = toDate.Date;
                            break;
                        case AppTypes.TimeScaleTypes.Week:
                            frDate = common.dateTimeLibs.StartOfWeek(toDate, cultureInfo).AddSeconds(-1);
                            break;
                        case AppTypes.TimeScaleTypes.Month:
                            frDate = common.dateTimeLibs.MakeDate(1, toDate.Month, toDate.Year).AddSeconds(-1);
                            break;
                        case AppTypes.TimeScaleTypes.Year:
                            frDate = common.dateTimeLibs.MakeDate(1, 1, toDate.Year).AddSeconds(-1);
                            break;
                        default:
                            common.system.ThrowException("Invalid parametter in calling to LoadStockPrice()");
                            break;
                    }

                    data.Reload(stockCodeTbl[stockCodeIdx].code,timeScale,frDate, toDate);

                    for (int strategyIdx = 0; strategyIdx < strategyList.Count; strategyIdx++)
                    {
                        Strategy.Data.ClearCache();
                        Strategy.Data.TradePoints advices = Strategy.Libs.Analysis(data, strategyList[strategyIdx].Trim());
                        if (advices == null) continue;
                        for (int idx3 = 0; idx3 < advices.Count; idx3++)
                        {
                            TradePointInfo tradeInfo = (TradePointInfo)advices[idx3];
                            Array.Resize(ref tradeAlertList, tradeAlertList.Length + 1);
                            tradeAlertList[tradeAlertList.Length - 1]=
                                new TradeAlert(stockCodeTbl[stockCodeIdx].code.Trim(), strategyList[strategyIdx].Trim(),
                                               timeScale, DateTime.FromOADate(data.DateTime[tradeInfo.DataIdx]),
                                               data.Close[tradeInfo.DataIdx],
                                               data.Volume[tradeInfo.DataIdx],
                                               tradeInfo);

                        }
                    }
                }
            }
            stockCodeTbl.Dispose();

            //Create alerts in the day
            CreateTradeAlert(tradeAlertList,toDate.Date,toDate);

            //Save last lun date
            SaveLastRunTime(toDate);
            if (onEndFunc != null) onEndFunc();
        }
        public static void CreateTradeAlert(onProcessStart onStartFunc, onProcessItem onProcessItemFunc, onProcessEnd onEndFunc)
        {
            DateTime frDate = common.Consts.constNullDate;
            DateTime toDate = DateTime.Now;
            
            //Run all strategy analysis for all stocks.
            data.tmpDS.stockCodeDataTable stockCodeTbl = new data.tmpDS.stockCodeDataTable();
            application.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable);

            application.AnalysisData data = new application.AnalysisData();

            TradeAlert[] tradeAlertList = new TradeAlert[0];
            StringCollection strategyList = new StringCollection();
            for (int idx = 0; idx < application.Strategy.Data.MetaList.Values.Length; idx++)
            {
                application.Strategy.Meta meta = (application.Strategy.Meta)application.Strategy.Data.MetaList.Values[idx];
                if (meta.Type != AppTypes.StrategyTypes.Strategy) continue;
                strategyList.Add(((application.Strategy.Meta)application.Strategy.Data.MetaList.Values[idx]).Code);
            }

            if (onStartFunc != null) onStartFunc(stockCodeTbl.Count);
            
            //Alert on last month data
            data.DataTimeRange = Settings.sysAlertTimeRange; ;
            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) //??
                {
                    data.DataStockCode = stockCodeTbl[stockCodeIdx].code;
                    data.DataTimeScale = timeScale;
                    data.LoadData();
                    for (int strategyIdx = 0; strategyIdx < strategyList.Count; strategyIdx++)
                    {
                        application.Strategy.Data.ClearCache();
                        application.Strategy.Data.TradePoints advices = application.Strategy.Libs.Analysis(data, strategyList[strategyIdx].Trim());
                        if (advices == null) continue;
                        for (int idx3 = 0; idx3 < advices.Count; idx3++)
                        {
                            TradePointInfo tradeInfo = (TradePointInfo)advices[idx3];
                            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 TradeAlert(stockCodeTbl[stockCodeIdx].code.Trim(), strategyList[strategyIdx].Trim(),
                                                                                     timeScale, alertDate,
                                                                                     data.Close[tradeInfo.DataIdx],
                                                                                     data.Volume[tradeInfo.DataIdx],tradeInfo);
                        }
                    }
                }
            }
            stockCodeTbl.Dispose();

            //Create alerts in the day
            CreateTradeAlert(tradeAlertList);

            //Save last lun date
            SaveLastRunTime(toDate);
            if (onEndFunc != null) onEndFunc();
        }
Beispiel #19
0
 public static void LoadStockCode_ByStockExchange(data.tmpDS.stockCodeDataTable tbl, string stockExchange, AppTypes.CommonStatus status)
 {
     shortStockCodeTA.FillByStockExchange(tbl, stockExchange, ((byte)status).ToString());
 }
Beispiel #20
0
 public override void LoadData()
 {
     this.myDataTbl = DataAccess.Libs.myStockCodeTbl;
 }
Beispiel #21
0
 public static void LoadData(data.tmpDS.stockCodeDataTable tbl, string code)
 {
     shortStockCodeTA.ClearBeforeFill = false;
     shortStockCodeTA.FillByCode(tbl, code);
 }
Beispiel #22
0
        public static void LoadData(data.tmpDS.stockCodeDataTable stockCodeTbl, data.baseDS.portfolioRow row)
        {
            StringCollection list;
            list = common.MultiValueString.String2List(row.interestedSector);
            if (list.Count > 0) LoadStockCode_ByBizSectors(stockCodeTbl, list);

            list = common.MultiValueString.String2List(row.interestedStock);
            if (list.Count > 0)
            {
                data.tmpDS.stockCodeDataTable tmpTbl = new data.tmpDS.stockCodeDataTable();
                LoadStockCode_ByCodeList(tmpTbl, list);
                for (int idx = 0; idx < tmpTbl.Count; idx++)
                {
                    SysLibs.FindAndCache(stockCodeTbl, tmpTbl[idx].code);
                }
            }
        }
 protected virtual void LoadData(data.tmpDS.stockCodeDataTable toTbl, string[] portfolioCodes)
 {
     LoadStockList(toTbl, portfolioCodes);
 }
Beispiel #24
0
 public data.tmpDS.stockCodeDataTable GetStock_InPortfolio(string[] portfolios)
 {
     data.tmpDS.stockCodeDataTable retTbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadStockCode_ByPortfolios(retTbl, common.system.List2Collection(portfolios));
     return(retTbl);
 }
Beispiel #25
0
 public string[] GetStockList_ByWatchList(string[] watchList)
 {
     data.tmpDS.stockCodeDataTable stockCodeTbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadStockCode_ByWatchList(stockCodeTbl, common.system.List2Collection(watchList));
     return(MakeStockCodeList(stockCodeTbl));
 }
Beispiel #26
0
 public data.tmpDS.stockCodeDataTable GetStockByStatus(AppTypes.CommonStatus status)
 {
     data.tmpDS.stockCodeDataTable tbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadData(tbl, status);
     return tbl;
 }
Beispiel #27
0
 public string[] GetStockList_ByBizSector(string[] sectors)
 {
     data.tmpDS.stockCodeDataTable stockCodeTbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadStockCode_ByBizSectors(stockCodeTbl, common.system.List2Collection(sectors));
     return(MakeStockCodeList(stockCodeTbl));
 }
Beispiel #28
0
 public string[] GetStockList_ByBizSector(string[] sectors)
 {
     data.tmpDS.stockCodeDataTable stockCodeTbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadStockCode_ByBizSectors(stockCodeTbl, common.system.List2Collection(sectors));
     return MakeStockCodeList(stockCodeTbl);
 }
Beispiel #29
0
 public data.tmpDS.stockCodeDataTable GetStock_ByBizSector(string[] bizSectors)
 {
     data.tmpDS.stockCodeDataTable retTbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadStockCode_ByBizSectors(retTbl, common.system.List2Collection(bizSectors));
     return(retTbl);
 }
Beispiel #30
0
 public data.tmpDS.stockCodeDataTable GetStock_InPortfolio(string[] portfolios)
 {
     data.tmpDS.stockCodeDataTable retTbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadStockCode_ByPortfolios(retTbl,common.system.List2Collection(portfolios));
     return retTbl;
 }
Beispiel #31
0
 public data.tmpDS.stockCodeDataTable GetStock_ByBizSector(string[] bizSectors)
 {
     data.tmpDS.stockCodeDataTable retTbl = new data.tmpDS.stockCodeDataTable();
     DbAccess.LoadStockCode_ByBizSectors(retTbl, common.system.List2Collection(bizSectors));
     return retTbl;
 }
        public static void CreateTradeAlert(onProcessStart onStartFunc, onProcessItem onProcessItemFunc, onProcessEnd onEndFunc)
        {
            DateTime frDate = common.Consts.constNullDate;
            DateTime toDate = DateTime.Now;

            //Run all strategy analysis for all stocks.
            data.tmpDS.stockCodeDataTable stockCodeTbl = new data.tmpDS.stockCodeDataTable();
            application.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable);

            application.AnalysisData data = new application.AnalysisData();

            TradeAlert[]     tradeAlertList = new TradeAlert[0];
            StringCollection strategyList   = new StringCollection();

            for (int idx = 0; idx < application.Strategy.Data.MetaList.Values.Length; idx++)
            {
                application.Strategy.Meta meta = (application.Strategy.Meta)application.Strategy.Data.MetaList.Values[idx];
                if (meta.Type != AppTypes.StrategyTypes.Strategy)
                {
                    continue;
                }
                strategyList.Add(((application.Strategy.Meta)application.Strategy.Data.MetaList.Values[idx]).Code);
            }

            if (onStartFunc != null)
            {
                onStartFunc(stockCodeTbl.Count);
            }

            //Alert on last month data
            data.DataTimeRange = Settings.sysAlertTimeRange;;
            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) //??
                {
                    data.DataStockCode = stockCodeTbl[stockCodeIdx].code;
                    data.DataTimeScale = timeScale;
                    data.LoadData();
                    for (int strategyIdx = 0; strategyIdx < strategyList.Count; strategyIdx++)
                    {
                        application.Strategy.Data.ClearCache();
                        application.Strategy.Data.TradePoints advices = application.Strategy.Libs.Analysis(data, strategyList[strategyIdx].Trim());
                        if (advices == null)
                        {
                            continue;
                        }
                        for (int idx3 = 0; idx3 < advices.Count; idx3++)
                        {
                            TradePointInfo tradeInfo = (TradePointInfo)advices[idx3];
                            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 TradeAlert(stockCodeTbl[stockCodeIdx].code.Trim(), strategyList[strategyIdx].Trim(),
                                                                                       timeScale, alertDate,
                                                                                       data.Close[tradeInfo.DataIdx],
                                                                                       data.Volume[tradeInfo.DataIdx], tradeInfo);
                        }
                    }
                }
            }
            stockCodeTbl.Dispose();

            //Create alerts in the day
            CreateTradeAlert(tradeAlertList);

            //Save last lun date
            SaveLastRunTime(toDate);
            if (onEndFunc != null)
            {
                onEndFunc();
            }
        }
Beispiel #33
0
        public static void LoadStockCode_ByWatchList(data.tmpDS.stockCodeDataTable stockCodeTbl, StringCollection codes)
        {
            StringCollection retList = new StringCollection();
            StringCollection list;

            data.tmpDS.stockCodeDataTable tmpTbl = new data.tmpDS.stockCodeDataTable();
            data.baseDS.portfolioDataTable portfolioTbl = new data.baseDS.portfolioDataTable();
            data.baseDS.portfolioRow portfolioRow;
            for (int idx1 = 0; idx1 < codes.Count; idx1++)
            {
                portfolioRow = SysLibs.FindAndCache(portfolioTbl, codes[idx1]);
                if (portfolioRow == null) continue;
                list = common.MultiValueString.String2List(portfolioRow.interestedStock);
                if (list.Count <= 0) continue;
                tmpTbl.Clear();
                LoadStockCode_ByCodeList(tmpTbl, list);
                for (int idx2 = 0; idx2 < tmpTbl.Count; idx2++)
                {
                    if (stockCodeTbl.FindBycode(tmpTbl[idx2].code)==null) stockCodeTbl.ImportRow(tmpTbl[idx2]);
                }
            }
            portfolioTbl.Dispose();
        }
Beispiel #34
0
        public static void CreateTradeAlert(onProcessStart onStartFunc, onProcessItem onProcessItemFunc, onProcessEnd onEndFunc)
        {
            CultureInfo cultureInfo = new CultureInfo(Settings.sysCultureCode);
            DateTime    frDate      = common.Consts.constNullDate;
            DateTime    toDate      = DateTime.Now;

            //Run all strategy analysis for all stocks.
            data.tmpDS.stockCodeDataTable stockCodeTbl = new data.tmpDS.stockCodeDataTable();
            global::data.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable);

            application.Data data = new application.Data();

            TradeAlert[]     tradeAlertList = new TradeAlert[0];
            StringCollection strategyList   = new StringCollection();

            for (int idx = 0; idx < Strategy.Data.MetaList.Values.Length; idx++)
            {
                Strategy.Meta meta = (Strategy.Meta)Strategy.Data.MetaList.Values[idx];
                if (meta.Type != AppTypes.StrategyTypes.Strategy)
                {
                    continue;
                }
                strategyList.Add(((Strategy.Meta)Strategy.Data.MetaList.Values[idx]).Code);
            }

            if (onStartFunc != null)
            {
                onStartFunc(stockCodeTbl.Count);
            }

            for (int stockCodeIdx = 0; stockCodeIdx < stockCodeTbl.Count; stockCodeIdx++)
            {
                if (onProcessItemFunc != null)
                {
                    if (!onProcessItemFunc(stockCodeTbl[stockCodeIdx].code))
                    {
                        break;
                    }
                }

                foreach (AppTypes.TimeScale timeScale in AppTypes.myTimeScales)
                {
                    //Move date ahead to ensure that there are sufficient data need in analysis process
                    switch (timeScale.Type)
                    {
                    case AppTypes.TimeScaleTypes.RealTime:
                        frDate = toDate.AddHours(-1);
                        break;

                    case AppTypes.TimeScaleTypes.Hour:
                        frDate = toDate.Date;
                        break;

                    case AppTypes.TimeScaleTypes.Day:
                        frDate = toDate.Date;
                        break;

                    case AppTypes.TimeScaleTypes.Week:
                        frDate = common.dateTimeLibs.StartOfWeek(toDate, cultureInfo).AddSeconds(-1);
                        break;

                    case AppTypes.TimeScaleTypes.Month:
                        frDate = common.dateTimeLibs.MakeDate(1, toDate.Month, toDate.Year).AddSeconds(-1);
                        break;

                    case AppTypes.TimeScaleTypes.Year:
                        frDate = common.dateTimeLibs.MakeDate(1, 1, toDate.Year).AddSeconds(-1);
                        break;

                    default:
                        common.system.ThrowException("Invalid parametter in calling to LoadStockPrice()");
                        break;
                    }

                    data.Reload(stockCodeTbl[stockCodeIdx].code, timeScale, frDate, toDate);

                    for (int strategyIdx = 0; strategyIdx < strategyList.Count; strategyIdx++)
                    {
                        Strategy.Data.ClearCache();
                        Strategy.Data.TradePoints advices = Strategy.Libs.Analysis(data, strategyList[strategyIdx].Trim());
                        if (advices == null)
                        {
                            continue;
                        }
                        for (int idx3 = 0; idx3 < advices.Count; idx3++)
                        {
                            TradePointInfo tradeInfo = (TradePointInfo)advices[idx3];
                            Array.Resize(ref tradeAlertList, tradeAlertList.Length + 1);
                            tradeAlertList[tradeAlertList.Length - 1] =
                                new TradeAlert(stockCodeTbl[stockCodeIdx].code.Trim(), strategyList[strategyIdx].Trim(),
                                               timeScale, DateTime.FromOADate(data.DateTime[tradeInfo.DataIdx]),
                                               data.Close[tradeInfo.DataIdx],
                                               data.Volume[tradeInfo.DataIdx],
                                               tradeInfo);
                        }
                    }
                }
            }
            stockCodeTbl.Dispose();

            //Create alerts in the day
            CreateTradeAlert(tradeAlertList, toDate.Date, toDate);

            //Save last lun date
            SaveLastRunTime(toDate);
            if (onEndFunc != null)
            {
                onEndFunc();
            }
        }