/// <summary> /// Do trading work initiated from scheduler task /// </summary> private void DoTradingWork() { if (AllConfigurations.AllConfigurationsObject.Application.AllowAutoTrading == false) { return; } if (UNLManager.PositionsDataBuilder.PositionDataDic.Values.Count == 0) { return; } foreach (var expiry in ExpiryDateEnumerable) { try { if (UNLManager.PositionsDataBuilder.PositionDataDic.Values.Any( pd => pd.Position < 0 && pd.OptionData.Expiry == expiry && (pd.OptionData.DeltaAbsValue >= MaxDeltaOffset || pd.OptionData.DeltaAbsValue <= MinDeltaOffset)) == false) { continue; } OnPositionNeedToOptimized(); //return; var optimizer = new PositionsOptimizer(Symbol, expiry); _optimizersDic[optimizer.GetHashCode()] = optimizer; optimizer.MissionAccomplished += OptimizerOnMissionAccomplished; optimizer.OptimizePositions(); } catch (Exception ex) { Logger.Error(ex.Message, ex); } } }
public void PerformPartialOptimization(DateTime expiryDate, int mateCoupleCount) { var optimizer = new PositionsOptimizer(Symbol, expiryDate); if (!optimizer.PerformPartialOptimization(mateCoupleCount)) { throw new Exception("There is no positions for optimization!"); } }
private void OptimizerOnMissionAccomplished(PositionsOptimizer positionsOptimizer) { var key = positionsOptimizer.GetHashCode(); if (_optimizersDic.ContainsKey(key)) { _optimizersDic.Remove(key); } //Remove registration: positionsOptimizer.MissionAccomplished -= OptimizerOnMissionAccomplished; }
public void OptimizePositions(DateTime expiryDate) { var optimizer = new PositionsOptimizer(Symbol, expiryDate); optimizer.OptimizePositions(); }