public EndPlateMonitorJob(string name, RealPlateMonitor plateMonitor, Job[] needJobs) : base(name, needJobs) { this.plateMonitor = plateMonitor; }
public EndPlateMonitorJob(string name, RealPlateMonitor plateMonitor) : this(name, plateMonitor, null) { }
protected override void MarketInit() { DateTime curDate = Clock.Now.Date; //策略当前运行时间 Console.WriteLine("日期:" + curDate.ToString("yyyy-MM-dd")); this.MarketOpen = true; if (curDate > lastTradeDate) { //连接数据提供者 DateTime endDate = curDate.AddYears(1); //下面返回的交易日历是curDate到endDate前一天为止的交易日历 this.tradeDates = this.getTradeDates("SHSE", curDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd")); lastTradeDate = endDate.AddDays(-1); } if ((this.tradeDates.Count > 0) && (!this.tradeDates.Contains(curDate))) { Console.WriteLine("今天不是交易日"); this.MarketOpen = false; //return; } //在实盘模式下需要等待头一天的作业完成,才能市场初始化,进行今天的交易,故而这里设置等待一个信号量 if (this.StrategyMode == StrategyMode.Live) { this.autoEvent.WaitOne(); } /*添加市场并初始化*/ //Marketor marketor=new UpLimitStockMarketor(this); //marketor.OnInit(); if (this.StrategyMode == StrategyMode.Live) { this.closeAllJobSchedules(); //在实盘模式下,进行重连接市场数据提供者和交易提供者 JobSchedule jbs1 = new JobSchedule(this.buildReconnectJobs(), curDate.Add(new TimeSpan(9, 0, 0)), 5, new TimeSpan(0, 1, 0)); //Clock.Now.AddSeconds(5),5,new TimeSpan(0,1,0)); this.jobSchedules.Add(jbs1); if (this.plateMonitor is RealPlateMonitor) { RealPlateMonitor plateMonitor = (RealPlateMonitor)this.plateMonitor; //添加启动板块监控作业 DateTime beginTime = curDate.Add(new TimeSpan(9, 15, 0)); DateTime tempTime = Clock.Now.AddSeconds(5); if (tempTime > beginTime) { beginTime = tempTime; } JobSchedule jbs2 = new JobSchedule(new BeginPlateMonitorJob("开始板块监控", plateMonitor), beginTime, 5, new TimeSpan(0, 1, 0)); this.jobSchedules.Add(jbs2); //添加结束板块监控作业 JobSchedule jbs3 = new JobSchedule(new EndPlateMonitorJob("结束板块监控", plateMonitor), curDate.Add(new TimeSpan(15, 10, 0)), 5, new TimeSpan(0, 1, 0)); this.jobSchedules.Add(jbs3); //添加选择股票入场作业 JobSchedule jbs4 = new JobSchedule(new EntryJob("买入证券作业", plateMonitor, this, this.tradeManager), curDate.Add(new TimeSpan(11, 0, 0)), 10, new TimeSpan(0, 20, 0)); this.jobSchedules.Add(jbs4); } //在实盘模式下,调度每天要进行额外的作业,作业完成后发出一个信号量,通知可以进行下一天的交易 JobSchedule jbs5 = new JobSchedule(this.buildDayJobs(), curDate.Add(new TimeSpan(22, 40, 0)) , 5, new TimeSpan(0, 20, 0), this.autoEvent); this.jobSchedules.Add(jbs5); } }
static void Main(string[] args) { // TO DO: Add your code here bool liveMode = true; PlateMonitorForm monitorForm = null; HotPlateTradeStrategy myStrategy = null; if (liveMode) { monitorForm = new PlateMonitorForm(); GMRealTimeProvider provider = (GMRealTimeProvider)ProviderManager.MarketDataProviders["GMRealTimeProvider"]; RealPlateMonitor plateMonitor = new RealPlateMonitor(provider, @"D:\eastmoney\swc8", monitorForm); myStrategy = new HotPlateTradeStrategy(plateMonitor); myStrategy.StrategyMode = StrategyMode.Live; myStrategy.MarketDataProvider = provider; myStrategy.ExecutionProvider = ProviderManager.ExecutionSimulator; myStrategy.ResetPortfolio = false; //myStrategy.SaveOrders=true;//是否保存委托订单 myStrategy.Portfolio.Persistent = true; //是否保存投资组合 } else { myStrategy = new HotPlateTradeStrategy(null); myStrategy.ResetPortfolio = false; //每次运行是否重置投资组合 myStrategy.CheckBuyPower = true; myStrategy.SimulationEntryDate = new DateTime(2017, 1, 1); myStrategy.SimulationExitDate = new DateTime(2017, 1, 31); } myStrategy.SimulationCash = 100000; Thread aThread = new Thread(new ThreadStart(myStrategy.Start)); if (aThread.ThreadState == ThreadState.Unstarted) { aThread.Start(); } if (monitorForm != null) { Application.Run(monitorForm); } else { MessageBox.Show("Press OK to stop ATS", "SmartQuant Automation", MessageBoxButtons.OK, MessageBoxIcon.Information); } myStrategy.Stop(); aThread.Abort(); aThread.Join(); /*GraphShowForm showForm=new GraphShowForm(); * DateTime curDate=Clock.Now.Date; * string symbol="SZSE.300503"; * Instrument inst=InstrumentManager.Instruments[symbol]; * ISeriesObject[] dailyBars=Util.GetNDailiesBeforeDate(inst,curDate,60); * if (dailyBars.Length>0){ * Util.AdjustDailys(dailyBars);//向前复权 * double[] inputs=new double[60]; * double[] outputs=new double[60]; * double basePrice=((GMDaily)dailyBars[0]).Amount/((GMDaily)dailyBars[0]).Volume; * for(int i=0;i<dailyBars.Length;i++){ * inputs[i]=i; * outputs[i]=((GMDaily)dailyBars[i]).Amount/((GMDaily)dailyBars[i]).Volume; * outputs[i]=(outputs[i]/basePrice-1)*100; * } * PatternRecognition pr=new PatternRecognition(showForm); * RecognitionState ret=pr.Recognition(inputs,outputs); * Console.WriteLine("slope={0},shape={1},speed={2}",ret.Slope,ret.Shape,ret.Speed); * Application.Run(showForm); * }else { * Console.WriteLine("no data."); * }*/ Console.WriteLine("Strategy Stopped!"); }
public EntryJob(string name, RealPlateMonitor plateMonitor, Strategy strategy) : this(name, plateMonitor, strategy, null, null) { }
public EntryJob(string name, RealPlateMonitor plateMonitor, Strategy strategy, TradeManager tradeManager) : this(name, plateMonitor, strategy, tradeManager, null) { }
public EntryJob(string name, RealPlateMonitor plateMonitor, Strategy strategy, TradeManager tradeManager, Job[] needJobs) : base(name, needJobs) { this.plateMonitor = plateMonitor; this.strategy = strategy; this.tradeManager = tradeManager; }