public static void OnStatisticsMessage(AlgoInstrumentStatisticsDto[] statistics) { Console.WriteLine("OnStatisticsMessage"); if (statistics == null) { return; } bool isSavePricer = _isChange; // Select trade statistic for our algorithm var tradeStatistic = statistics.FirstOrDefault(a => a.AlgoId == _algoId); if (tradeStatistic != null) { //Console.WriteLine("Current position size: {0}", tradeStatistic.CurrentPositionSize); if (tradeStatistic.CurrentPositionSize < 0) { if (Math.Abs(tradeStatistic.CurrentPositionSize) > _instrument.RiskLimitsConfig.MaxShortExposure * _topMarginThreshold && !_isChange) { _instrument.PricerConfig.SellMargins = ChangeMargins(_originalSellMargins, 1.5); _isChange = true; } if (Math.Abs(tradeStatistic.CurrentPositionSize) < _instrument.RiskLimitsConfig.MaxShortExposure * _bottomMarginThreshold && _isChange) { _instrument.PricerConfig.SellMargins = ChangeMargins(_originalSellMargins, 1.0); _isChange = false; } } if (tradeStatistic.CurrentPositionSize > 0) { if (Math.Abs(tradeStatistic.CurrentPositionSize) > _instrument.RiskLimitsConfig.MaxLongExposure * _topMarginThreshold && !_isChange) { _instrument.PricerConfig.BuyMargins = ChangeMargins(_originalBuyMargins, 1.5); _isChange = true; } if (Math.Abs(tradeStatistic.CurrentPositionSize) < _instrument.RiskLimitsConfig.MaxLongExposure * _bottomMarginThreshold && _isChange) { _instrument.PricerConfig.BuyMargins = ChangeMargins(_originalBuyMargins, 1.0); _isChange = false; } } // check condition, and change margins if needed } // Save pricer if (isSavePricer != _isChange) { mmRestService.SavePricer(_instrument.PricerConfig); } }
public void AddChangeStopFullInstrumentConfig() { Initialize(); _testEvent.Algorithms[0].InstrumentConfigInfo = _mmRest.CreateInstrument(_testEvent.Algorithms[0].InstrumentConfigInfo); _testEvent.Algorithms[0].SetAlgoId(_testEvent.Algorithms[0].InstrumentConfigInfo.AlgoId); _testEvent.Algorithms[0].PricerConfigInfo = _mmRest.SavePricer(_testEvent.Algorithms[0].PricerConfigInfo); _testEvent.Algorithms[0].HedgerConfigInfo = _mmRest.SaveHedger(_testEvent.Algorithms[0].HedgerConfigInfo); _testEvent.Algorithms[0].RiskLimitConfigInfo = _mmRest.SaveRiskLimitsConfig(_testEvent.Algorithms[0].RiskLimitConfigInfo); Thread.Sleep(1000); // Check full config bool testResult = _testEvent.Algorithms[0].Equals(_mmRest.GetInstrument(_testEvent.Algorithms[0].AlgoId)); _mmRest.StartInstrument(_testEvent.Algorithms[0].AlgoId); _testEvent.Algorithms[0].InstrumentConfigInfo.Running = true; _mmRest.StartPricer(_testEvent.Algorithms[0].AlgoId); _testEvent.Algorithms[0].PricerConfigInfo.Running = true; _mmRest.StartHedger(_testEvent.Algorithms[0].AlgoId); _testEvent.Algorithms[0].HedgerConfigInfo.Running = true; Thread.Sleep(1000); // Check start testResult = _testEvent.Algorithms[0].Equals(_mmRest.GetInstrument(_testEvent.Algorithms[0].AlgoId)) && testResult; // Change pricer PricerConfigDto newPricerConfig = AlgorithmInfo.CreateConfig <PricerConfigDto>("pricer3.json", _testEvent.Algorithms[0].AlgoId); _testEvent.Algorithms[0].PricerConfigInfo = _mmRest.SavePricer(newPricerConfig); // Change hedger HedgerConfigDto newHedgerConfig = AlgorithmInfo.CreateConfig <HedgerConfigDto>("hedger2.json", _testEvent.Algorithms[0].AlgoId); _testEvent.Algorithms[0].HedgerConfigInfo = _mmRest.SaveHedger(newHedgerConfig); // Change riskLimits RiskLimitsConfigDto newRiskLimitsConfig = AlgorithmInfo.CreateConfig <RiskLimitsConfigDto>("riskLimit3.json", _testEvent.Algorithms[0].AlgoId); _testEvent.Algorithms[0].RiskLimitConfigInfo = _mmRest.SaveRiskLimitsConfig(newRiskLimitsConfig); Thread.Sleep(1000); // Check after change testResult = _testEvent.Algorithms[0].Equals(_mmRest.GetInstrument(_testEvent.Algorithms[0].AlgoId)) && testResult; _mmRest.StopHedger(_testEvent.Algorithms[0].AlgoId); _testEvent.Algorithms[0].InstrumentConfigInfo.Running = false; _mmRest.StopPricer(_testEvent.Algorithms[0].AlgoId); _testEvent.Algorithms[0].PricerConfigInfo.Running = false; _mmRest.StopInstrument(_testEvent.Algorithms[0].AlgoId); _testEvent.Algorithms[0].HedgerConfigInfo.Running = false; Thread.Sleep(1000); // Check stop testResult = _testEvent.Algorithms[0].Equals(_mmRest.GetInstrument(_testEvent.Algorithms[0].AlgoId)) && testResult; _mmRest.DeleteAlgorithm(_testEvent.Algorithms[0].AlgoId); Thread.Sleep(1000); // Check delete and test result Assert.AreEqual(true, _mmRest.GetInstrument(_testEvent.Algorithms[0].AlgoId) == null, "Deleted algorithm doesn't equal to null"); Assert.AreEqual(true, testResult, TestFail); }