/// <summary> /// Initializes a new instance of the <see cref="MediaEngine" /> class. /// </summary> /// <param name="parent">The associated parent object.</param> /// <param name="connector">The parent implementing connector methods.</param> /// <exception cref="InvalidOperationException">Thrown when the static Initialize method has not been called.</exception> public MediaEngine(object parent, IMediaConnector connector) { // Associate the parent as the media connector that implements the callbacks Parent = parent; Connector = connector; Commands = new CommandManager(this); State = new MediaEngineState(this); Timing = new TimingController(this); // Don't start up timers or any other stuff if we are in design-time if (Platform.IsInDesignTime) { return; } // Check initialization has taken place lock (InitLock) { if (IsInitialized == false) { throw new InvalidOperationException( $"{nameof(MediaEngine)} not initialized. Call the static method {nameof(Initialize)}"); } } }
protected override void OnStarted() { List <Security> securitiesToReg = new List <Security>(); securitiesToReg.AddRange(_optionsPositions.Keys); securitiesToReg.Add(Security); DoStrategyPreparation(securitiesToReg.ToArray(), new Security[] { Security }, new Portfolio[] { Portfolio }); if (DeltaStep < 0) { throw new ArgumentException("DeltaStep cannot be below zero: " + DeltaStep); } md = GetMarketDepth(Security); TimingController.SetTimingMethod(HedgingProcess); Security.WhenMarketDepthChanged(Connector) .Do(() => { TimingController.TimingMethodHappened(); HedgingProcess(); }) .Apply(this); base.OnStarted(); }
protected override void OnStarted() { DoStrategyPreparation(new Security[] { Security }, new Security[] { Security }, new Portfolio[] { Portfolio }); if (_spread <= 0) { throw new ArgumentException("Spread cannot be below zero: " + _spread); } if (_lot <= 0) { throw new ArgumentException("Lot cannot be below zero: " + _lot); } if (Security.PriceStep == null) { throw new ArgumentException("Cannot read security price set, probably data still loading... :" + Security.PriceStep); } if (LimitedFuturesValueAbs < 0) { throw new ArgumentException("limitation of futures positions is established by value >=0 : " + LimitedFuturesValueAbs); } if (_sideForEnterToPosition == Sides.Sell) { LimitedFuturesValueAbs = LimitedFuturesValueAbs != 0 ? LimitedFuturesValueAbs * -1 : decimal.MinValue; } else { LimitedFuturesValueAbs = LimitedFuturesValueAbs != 0 ? LimitedFuturesValueAbs : decimal.MaxValue; } md = GetMarketDepth(Security); TimingController.SetTimingMethod(SpreadingProcess); Security.WhenMarketDepthChanged(Connector) .Do(() => { TimingController.TimingMethodHappened(); SpreadingProcess(); }) .Apply(this); this.WhenStopping() .Do(() => { ChildStrategies.Clear(); }) .Once() .Apply(this); base.OnStarted(); }
private void Start() { timingController = FindObjectOfType <TimingController>(); // We spawn the pattern instance right away but deactivate it. The pattern is responsible for setting it active // again at its scheduled "spawn" time. Transform spawner = GameController.EnemyManager.transform; patternInstance = Instantiate(Config.Pattern, Vector2.zero, Quaternion.identity, spawner); patternInstance.gameObject.SetActive(false); SetStartMeasure(GameController.TimingController.NumberOfMeasuresToSkipOnStart); configuredActions = ScheduleActions(); queuedActions = new List <SchedulableAction>(configuredActions); }
protected PrimaryStrategy() { TimingController = new TimingController(700, 2000); Timeout = 5000; _isSetDone = false; _isCorrectChild = false; _isPrimaryStoppingStarted = false; _closedChildCounter = 0; CancelOrdersWhenStopping = false; CommentOrders = true; DisposeOnStop = true; MaxErrorCount = 10; OrdersKeepTime = TimeSpan.Zero; Name += GlobalCounter++; }
public void Awake() { Instance = this; }
void Start() { timingController = FindObjectOfType <TimingController>(); }
protected override void OnStarted() { DoStrategyPreparation(new Security[] { }, new Security[] { Security }, new Portfolio[] { Portfolio }); if (Volume <= 0) { throw new ArgumentException("Volume cannot be below zero: " + Volume); } MarketDepth = GetMarketDepth(Security); TimingController.SetTimingMethod(QuotingProcess); if (IsTradingTime()) { QuotingProcess(); } else { OrderSynchronizer.CancelCurrentOrder(); } Security.WhenMarketDepthChanged(Connector) .Do(() => { TimingController.TimingMethodHappened(); if (IsPrimaryStoppingStarted()) { OrderSynchronizer.CancelCurrentOrder(); return; } if (!_isQuoting) { _isQuoting = true; if (IsTradingTime()) { QuotingProcess(); } else { OrderSynchronizer.CancelCurrentOrder(); } _isQuoting = false; } }) .Until(IsStrategyStopping) .Apply(this); this.WhenPositionChanged() .Do(() => { if (Math.Abs(Position) >= Volume) { PrimaryStopping(); } }) .Until(IsStrategyStopping) .Apply(this); base.OnStarted(); }
protected override void OnStarted() { if (SecurityWithSignalToClose == null) { DoStrategyPreparation(new Security[] { }, new Security[] { Security }, new Portfolio[] { Portfolio }); } else { DoStrategyPreparation(new Security[] { }, new Security[] { Security, SecurityWithSignalToClose }, new Portfolio[] { Portfolio }); } if (Volume <= 0 || _priceToClose <= 0) { throw new ArgumentException( $"Volume: {Volume} or price to close: {_priceToClose} cannot be below zero"); } ; this.WhenPositionChanged() .Do(() => { if (Math.Abs(Position) >= Volume) { PrimaryStopping(); } }) .Apply(this); //не проверяем время, т.к. правило выполняется Once() TimingController.SetTimingUnnecessary(); if (SecurityWithSignalToClose == null) { var md = GetMarketDepth(Security); Security.WhenMarketDepthChanged(Connector) .Do(() => { var mqs = new MarketQuoterStrategy(_strategyOrderSide, Volume, _priceToClose); mqs.WhenStopped() .Do(this.Stop) .Once() .Apply(this); MarkStrategyLikeChild(mqs); ChildStrategies.Add(mqs); }) .Once() .Apply(this); } else { PrimaryStrategy mqs = null; var md = GetMarketDepth(SecurityWithSignalToClose); var mqsStartRule = SecurityWithSignalToClose .WhenMarketDepthChanged(Connector) .Do(() => { if (!IsTradingTime()) { return; } //котировки специально развернуты неверно - как только была сделка на графике (ударили в аск или налили в бид) - закрываемся if (_securityDesirableDirection == PriceDirection.Up && md.BestAsk.Price >= _priceToClose || _securityDesirableDirection == PriceDirection.Down && md.BestBid.Price <= _priceToClose) { // пока делаем по любой цене, как только сработает условие mqs = new MarketQuoterStrategy(_strategyOrderSide, Volume, Security.GetMarketPrice(_strategyOrderSide)); mqs.WhenStopped() .Do(this.Stop) .Once() .Apply(this); MarkStrategyLikeChild(mqs); ChildStrategies.Add(mqs); } }) .Until(() => mqs != null) .Apply(this); this.WhenStopping() .Do(() => { /*NOP*/ }) .Apply(this) .Exclusive(mqsStartRule); } base.OnStarted(); }