Ejemplo n.º 1
0
        //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);
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        //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;
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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();
            }
        }
Ejemplo n.º 6
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();
            }
        }