Пример #1
0
        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);
        }
Пример #2
0
        public void CheckQuotesBook()
        {
            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);
            _mmRest.StartPricer(_testEvent.Algorithms[0].AlgoId);

            var quoteBookListener = _wsFactory.CreateQuotesSubscription();

            _testEvent.Algorithms[0].QuoteMessageHandler += _testEvent.CompareQuoteAgainstParams;
            quoteBookListener.Subscribe(_testEvent.Algorithms[0].AlgoId, _testEvent.Algorithms[0].OnQuoteMessage);

            WaitTestEvents(5);

            // Change pricer
            PricerConfigDto newPricerConfig = AlgorithmInfo.CreateConfig <PricerConfigDto>("pricer3.json", _testEvent.Algorithms[0].AlgoId);

            _testEvent.Algorithms[0].PricerConfigInfo = _mmRest.SavePricer(newPricerConfig);
            Debug.WriteLine("Pricer is changed");

            WaitTestEvents(7);

            quoteBookListener.Unsubscribe(_testEvent.Algorithms[0].AlgoId, _testEvent.Algorithms[0].OnQuoteMessage);
            _testEvent.Algorithms[0].QuoteMessageHandler -= _testEvent.CompareQuoteAgainstParams;
            Thread.Sleep(500);
            _wsFactory.Close();

            _mmRest.StopPricer(_testEvent.Algorithms[0].AlgoId);
            Thread.Sleep(500);

            _mmRest.DeleteAlgorithm(_testEvent.Algorithms[0].AlgoId);
            Thread.Sleep(1000);

            Assert.AreEqual(true, _mmRest.GetInstrument(_testEvent.Algorithms[0].AlgoId) == null, "Deleted algorithm doesn't equal to null");
            Assert.AreEqual(true, _testEvent.TestResult, TestFail);
        }
Пример #3
0
        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);
        }
Пример #4
0
        public void CompareSourceAgainstTargetBook()
        {
            Initialize();
            // 1
            _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);
            _mmRest.StartInstrument(_testEvent.Algorithms[0].AlgoId);
            _mmRest.StartPricer(_testEvent.Algorithms[0].AlgoId);

            // 2
            _testEvent.Algorithms[1].InstrumentConfigInfo = _mmRest.CreateInstrument(_testEvent.Algorithms[1].InstrumentConfigInfo);
            _testEvent.Algorithms[1].SetAlgoId(_testEvent.Algorithms[1].InstrumentConfigInfo.AlgoId);
            _testEvent.Algorithms[1].PricerConfigInfo = _mmRest.SavePricer(_testEvent.Algorithms[1].PricerConfigInfo);

            _testEvent.Algorithms[1].HedgerConfigInfo    = _mmRest.SaveHedger(_testEvent.Algorithms[1].HedgerConfigInfo);
            _testEvent.Algorithms[1].RiskLimitConfigInfo = _mmRest.SaveRiskLimitsConfig(_testEvent.Algorithms[1].RiskLimitConfigInfo);
            _mmRest.StartInstrument(_testEvent.Algorithms[1].AlgoId);
            _mmRest.StartPricer(_testEvent.Algorithms[1].AlgoId);

            Thread.Sleep(1000);

            var sourceBookListener = _wsFactory.CreateSourceMarketDataSubscription();
            var targetBookListener = _wsFactory.CreateTargetMarketDataSubscription();

            targetBookListener.Subscribe(_testEvent.Algorithms[0].AlgoId, _testEvent.Algorithms[0].OnTargetMessage);
            _testEvent.StartTestTime = DateTime.Now.AddSeconds(-2);
            _testEvent.Algorithms[1].SourceMessageHandler += _testEvent.CompareSourceAgainstTargetBook;
            sourceBookListener.Subscribe(_testEvent.Algorithms[1].AlgoId, _testEvent.Algorithms[1].OnSourceMessage);

            WaitTestEvents(4);

            _testEvent.StartTestTime = DateTime.Now.AddSeconds(-1);
            // Change pricer
            PricerConfigDto newPricerConfig = AlgorithmInfo.CreateConfig <PricerConfigDto>("pricer3.json", _testEvent.Algorithms[0].AlgoId);

            _testEvent.Algorithms[0].PricerConfigInfo = _mmRest.SavePricer(newPricerConfig);
            // Change riskLimits
            RiskLimitsConfigDto newRiskLimitsConfig = AlgorithmInfo.CreateConfig <RiskLimitsConfigDto>("riskLimit3.json", _testEvent.Algorithms[0].AlgoId);

            _testEvent.Algorithms[0].RiskLimitConfigInfo = _mmRest.SaveRiskLimitsConfig(newRiskLimitsConfig);
            Debug.WriteLine("Pricer and limits are changed");

            WaitTestEvents(7);

            targetBookListener.Unsubscribe(_testEvent.Algorithms[0].AlgoId, _testEvent.Algorithms[0].OnTargetMessage);
            sourceBookListener.Unsubscribe(_testEvent.Algorithms[1].AlgoId, _testEvent.Algorithms[1].OnSourceMessage);
            _testEvent.Algorithms[1].SourceMessageHandler -= _testEvent.CompareSourceAgainstTargetBook;
            Thread.Sleep(500);
            _wsFactory.Close();

            _mmRest.StopPricer(_testEvent.Algorithms[0].AlgoId);
            _mmRest.StopInstrument(_testEvent.Algorithms[0].AlgoId);

            _mmRest.StopPricer(_testEvent.Algorithms[1].AlgoId);
            _mmRest.StopInstrument(_testEvent.Algorithms[1].AlgoId);
            Thread.Sleep(500);

            _mmRest.DeleteAlgorithm(_testEvent.Algorithms[0].AlgoId);
            _mmRest.DeleteAlgorithm(_testEvent.Algorithms[1].AlgoId);
            Thread.Sleep(1000);

            Assert.AreEqual(true, _mmRest.GetInstrument(_testEvent.Algorithms[0].AlgoId) == null, "Deleted algorithm doesn't equal to null");
            Assert.AreEqual(true, _mmRest.GetInstrument(_testEvent.Algorithms[1].AlgoId) == null, "Deleted algorithm doesn't equal to null");
            Assert.AreEqual(true, _testEvent.TestResult, TestFail);
        }