public void CheckSpread() { Initialize(); AlgorithmInfo algo = _testEvent.Algorithms[0]; algo.InstrumentConfigInfo = _mmRest.CreateInstrument(algo.InstrumentConfigInfo); algo.SetAlgoId(algo.InstrumentConfigInfo.AlgoId); algo.PricerConfigInfo = _mmRest.SavePricer(algo.PricerConfigInfo); algo.RiskLimitConfigInfo = _mmRest.SaveRiskLimitsConfig(algo.RiskLimitConfigInfo); _mmRest.StartPricer(algo.AlgoId); _mmRest.StartInstrument(algo.AlgoId); Thread.Sleep(1000); var quotesBookListener = _wsFactory.CreateQuotesSubscription(); var targetBookListener = _wsFactory.CreateTargetMarketDataSubscription(); targetBookListener.Subscribe(algo.AlgoId, algo.OnTargetMessage); algo.QuoteMessageHandler += _testEvent.CompareSpread; Thread.Sleep(1000); quotesBookListener.Subscribe(algo.AlgoId, algo.OnQuoteMessage); WaitTestEvents(3); // Change pricer _testEvent.StartTestTime = DateTime.Now; algo.PricerConfigInfo.Running = true; algo.PricerConfigInfo.MinSpread = "0.0004"; algo.PricerConfigInfo = _mmRest.SavePricer(algo.PricerConfigInfo); Debug.WriteLine("Pricer is changed"); WaitTestEvents(6); quotesBookListener.Unsubscribe(algo.AlgoId, algo.OnQuoteMessage); targetBookListener.Unsubscribe(algo.AlgoId, algo.OnTargetMessage); algo.QuoteMessageHandler -= _testEvent.CompareSpread; Thread.Sleep(500); _wsFactory.Close(); _mmRest.StopPricer(algo.AlgoId); _mmRest.StopInstrument(algo.AlgoId); Thread.Sleep(500); _mmRest.DeleteAlgorithm(algo.AlgoId); Thread.Sleep(500); Assert.AreEqual(true, _mmRest.GetInstrument(algo.AlgoId) == null, "Deleted algorithm doesn't equal to null"); Assert.AreEqual(true, _testEvent.TestResult, TestFail); }
public void LeanHedger() { Initialize(); AlgorithmInfo algo = _testEvent.Algorithms[0]; algo.InstrumentConfigInfo = _mmRest.CreateInstrument(algo.InstrumentConfigInfo); algo.SetAlgoId(algo.InstrumentConfigInfo.AlgoId); algo.PricerConfigInfo = _mmRest.SavePricer(algo.PricerConfigInfo); algo.HedgerConfigInfo = _mmRest.SaveHedger(algo.HedgerConfigInfo); algo.RiskLimitConfigInfo = _mmRest.SaveRiskLimitsConfig(algo.RiskLimitConfigInfo); Thread.Sleep(1000); _mmRest.StartInstrument(algo.AlgoId); _mmRest.StartPricer(algo.AlgoId); Thread.Sleep(1000); var alertsListener = _wsFactory.CreateAlertsSubscription(); algo.AlertsHandler += _testEvent.CheckExecutionsInEvents; alertsListener.Subscribe(algo.OnExecutionAlertMessage); algo.OrderToSend = new OrderCrypto() { Destination = "DLTXMM", Quantity = 10, Side = Side.SELL, Type = OrderType.MARKET, SecurityId = "ETHBTC" }; ConnectToCrypto(); Thread.Sleep(1000); _wsCrypto.OrdersReceiver(algo.CheckOrderStatus); Thread.Sleep(2000); // Sell Order _testEvent.WaitOrderFill(algo, _wsCrypto); algo.OrderToSend.Type = OrderType.LIMIT; algo.OrderToSend.Side = Side.BUY; algo.OrderToSend.Quantity = 1.0; algo.OrderToSend.TimeInForce = TimeInForce.DAY; algo.OrderToSend.Price = 0.033; _mmRest.StopPricer(algo.AlgoId); _mmRest.StartHedger(algo.AlgoId); Thread.Sleep(1000); // Buy Order for hedger _testEvent.WaitOrderFill(algo, _wsCrypto); WaitTestEvents(3); if (_testEvent.TestResult) { _testEvent.CheckFillExecutions(algo); } _wsCrypto.OrdersUnsubscribe(algo.CheckOrderStatus); _wsCrypto.StopResponses(); _wsCrypto.Close(); alertsListener.Unsubscribe(algo.OnExecutionAlertMessage); algo.AlertsHandler -= _testEvent.CheckExecutionsInEvents; Thread.Sleep(500); _wsFactory.Close(); FinishAlgo(true, false, true, algo); Assert.AreEqual(true, _mmRest.GetInstrument(algo.AlgoId) == null, "Deleted algorithm doesn't equal to null"); Assert.AreEqual(true, _testEvent.TestResult, TestFail); }
public void CompareAlertsAgainstTradeQty() { Initialize(); //_testEvent.Algorithms[0] = new AlgorithmInfo(_mmRest.GetInstrument(240)); AlgorithmInfo algo = _testEvent.Algorithms[0]; algo.InstrumentConfigInfo = _mmRest.CreateInstrument(algo.InstrumentConfigInfo); algo.PricerConfigInfo = AlgorithmInfo.CreateConfig <PricerConfigDto>("pricer6.json", algo.AlgoId); algo.SetAlgoId(algo.InstrumentConfigInfo.AlgoId); algo.PricerConfigInfo = _mmRest.SavePricer(algo.PricerConfigInfo); algo.RiskLimitConfigInfo = _mmRest.SaveRiskLimitsConfig(algo.RiskLimitConfigInfo); _mmRest.StartPricer(algo.AlgoId); _mmRest.StartInstrument(algo.AlgoId); Thread.Sleep(1000); algo.OrderToSend = new OrderCrypto() { Destination = "DLTXMM", Quantity = 5, Side = Side.BUY, Type = OrderType.MARKET, SecurityId = "ETHBTC" }; ConnectToCrypto(); var alertsListener = _wsFactory.CreateAlertsSubscription(); var tradeStatisticListener = _wsFactory.CreateTradingStatisticsSubscription(); algo.AlertsHandler += _testEvent.CalculateExecutionsFromAlerts; alertsListener.Subscribe(algo.OnExecutionAlertMessage); algo.TradeStatisticHandler += _testEvent.MonitorChangesPosition; tradeStatisticListener.Subscribe(algo.OnTradeStatisticMessage); WaitTestEvents(2); Thread.Sleep(500); // Buy Order _wsCrypto.SendOrder(algo.OrderToSend, _testEvent.CheckOrderSent); WaitTestEvents(6); algo.OrderToSend.Side = Side.SELL; // Sell Order _wsCrypto.SendOrder(algo.OrderToSend, _testEvent.CheckOrderSent); WaitTestEvents(5); _wsCrypto.StopResponses(); _wsCrypto.Close(); alertsListener.Unsubscribe(algo.OnExecutionAlertMessage); algo.AlertsHandler -= _testEvent.CalculateExecutionsFromAlerts; Thread.Sleep(500); tradeStatisticListener.Unsubscribe(algo.OnTradeStatisticMessage); algo.TradeStatisticHandler -= _testEvent.MonitorChangesPosition; Thread.Sleep(500); _wsFactory.Close(); _mmRest.StopPricer(algo.AlgoId); _mmRest.StopInstrument(algo.AlgoId); Thread.Sleep(500); _mmRest.DeleteAlgorithm(algo.AlgoId); Thread.Sleep(500); Assert.AreEqual(true, _mmRest.GetInstrument(algo.AlgoId) == null, "Deleted algorithm doesn't equal to null"); Assert.AreEqual(true, _testEvent.TestResult, TestFail); }