public JobSchedule(JobQueue jobs, DateTime startTime, int maxTimes, TimeSpan interval, AutoResetEvent autoEvent) { this.jobs = jobs; this.startTime = startTime; this.maxTimes = maxTimes; this.interval = interval; this.autoEvent = autoEvent; this.jobEventHandler = new ReminderEventHandler(this.doJobs); if (this.startTime > Clock.Now) { Clock.AddReminder(this.jobEventHandler, startTime, null); } else { Console.WriteLine("作业开始时间必须大于当前时间!"); if (this.autoEvent != null) { this.autoEvent.Set(); //在不能开启作业的情况下,释放一次信号量 } } }
public static void RemoveReminder(ReminderEventHandler handler) { Clock.reminders.RemoveAt(Clock.reminders.IndexOfValue(handler)); }
public static void AddReminder(ReminderEventHandler handler, DateTime datetime, object data) { Clock.reminders.Add(datetime, handler); }
public static void RemoveReminder(ReminderEventHandler handler, DateTime datetime) { Clock.reminders.Remove(datetime); }
private void o38yaR1giJ(object obj0, TransactionEventArgs obj1) { lock (this) { if (!this.followChanges) return; this.tempPortfolio.Add(obj1.Transaction); this.tempPortfolio.Monitored = true; switch (obj1.Transaction.Side) { case Side.Buy: this.currentAccount -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocation += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocationLong += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.isAllocationLong = true; break; case Side.Sell: this.currentAccount += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocation -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocationLong -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.isAllocationLong = true; break; case Side.BuyMinus: this.currentAccount -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocation += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocationShort += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.isAllocationShort = true; break; case Side.SellShort: this.currentAccount += FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocation -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.allocationShort -= FreeQuant.Instruments.Currency.Convert(obj1.Transaction.Value, obj1.Transaction.Currency, this.portfolio.Account.Currency); this.isAllocationShort = true; break; } if (this.isRoundTripsOnly) { if (!this.tempPortfolio.Positions.Contains(obj1.Transaction.Instrument)) { this.roundTripList.CloseOpenRoundTrip(obj1.Transaction.Instrument, obj1.Transaction.Price, obj1.Transaction.DateTime); if (obj1.Transaction.Side == Side.Buy) this.shortRoundTripList.CloseOpenRoundTrip(obj1.Transaction.Instrument, obj1.Transaction.Price, obj1.Transaction.DateTime); else this.longRoundTripList.CloseOpenRoundTrip(obj1.Transaction.Instrument, obj1.Transaction.Price, obj1.Transaction.DateTime); } else if (this.tempPortfolio.Positions[obj1.Transaction.Instrument].Transactions.Count == 1) { PositionSide local_0 = PositionSide.Short; if (obj1.Transaction.Side == Side.Buy) local_0 = PositionSide.Long; RoundTrip local_1 = new RoundTrip(this.tempPortfolio.Positions[obj1.Transaction.Instrument], obj1.Transaction.Instrument, local_0, obj1.Transaction.Amount, obj1.Transaction.Price, obj1.Transaction.Price, obj1.Transaction.DateTime, obj1.Transaction.DateTime, RoundTripStatus.Opened); this.roundTripList.AddOpenRoundTrip(local_1); if (obj1.Transaction.Side == Side.Buy) this.longRoundTripList.AddOpenRoundTrip(local_1); else this.shortRoundTripList.AddOpenRoundTrip(local_1); } else { this.isRoundTripsOnly = false; this.EmitRoundTripsFinished(); } } if (this.isRoundTripsOnly) this.roundTripList.UpdateOpenRoundTrips(); this.currentAccount -= obj1.Transaction.Cost; this.cost += obj1.Transaction.Cost; if (this.isRoundTripsOnly) { this.EmitRoundTripsUpdated(); this.EmitRoundTripStatisticChanged(); } if (!this.waitingForStart) return; this.waitingForStart = false; this.awaitTime = this.GetIntervalEnd(obj1.Transaction.DateTime, this.timeInterval); this.awaitHandler = new ReminderEventHandler(this.JKNyi7SDXu); Clock.AddReminder(this.awaitHandler, this.awaitTime, (object)null); } }
private void JKNyi7SDXu(ReminderEventArgs obj0) { lock (this) { try { DateTime local_0 = obj0.SignalTime; for (DateTime local_1 = Clock.Now; local_0 <= local_1; local_0 = this.AddInterval(local_0, this.timeInterval)) { this.Cndy1I50JO(local_0); this.isNewData = false; } this.awaitTime = local_0; this.awaitHandler = new ReminderEventHandler(this.JKNyi7SDXu); Clock.AddReminder(this.awaitHandler, this.awaitTime, (object)null); } catch (Exception exception_0) { throw exception_0; } } }