public void test_IsPositionOnSignalOnClose_Negative()
        {
            ISignalContext context = new SignalContext();

            context.CurrentMarketPosition = 0;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_1Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_10Contract_5Complete(), "Buy Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell10Contract_5Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_10Contract_5Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell10Contract_5Complete(), "Sell Order");
            Assert.AreEqual(false, context.isPositionOnSignalOnClose());
        }
        public void test_IsSignalBidirection_Negative()
        {
            ISignalContext context = new SignalContext();

            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_1Complete(), "Buy Order");
            Assert.AreEqual(false, context.isSignalBidirection());
        }
        public void test_CompletePendingSignal()
        {
            ISignalContext context = new SignalContext();

            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_1Complete(), "Buy Order");
            context.completePendingSignal();
            Assert.AreEqual(2, context.CurrentMarketPosition);

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_1Complete(), "Sell Order");
            context.completePendingSignal();
            Assert.AreEqual(0, context.CurrentMarketPosition);

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_10Contract_10Complete(), "Buy Order");
            context.completePendingSignal();
            Assert.AreEqual(11, context.CurrentMarketPosition);

            context = new SignalContext();
            context.CurrentMarketPosition = -1;
            context.setPendingSignal1(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell10Contract_10Complete(), "Sell Order");
            context.completePendingSignal();
            Assert.AreEqual(-11, context.CurrentMarketPosition);

            context = new SignalContext();
            context.CurrentMarketPosition = 1;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.completePendingSignal();
            Assert.AreEqual(1, context.CurrentMarketPosition);
        }
        public void test_IsSignalBidirection_Positive()
        {
            ISignalContext context = new SignalContext();

            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(true, context.isSignalBidirection());
        }
        public void test_IsPositionSignalBothEmpty_Negative()
        {
            ISignalContext context = new SignalContext();

            context.CurrentMarketPosition = 1;
            Assert.AreEqual(false, context.isPositionSignalBothEmpty());

            context = new SignalContext();
            context.CurrentMarketPosition = 0;
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            Assert.AreEqual(false, context.isPositionSignalBothEmpty());
        }
Пример #6
0
 private void setupOrderAndContext(AppOrder appOrder, String buySell, double triggerPrice, String remark, int indexExecution)
 {
     appOrderManager.addAppOrUpdateOrder(appOrder);
     appOrderManager.addOpenAppOrder(stgIndex, appOrder);
     if (indexExecution == 1)
     {
         execution.setPendingSignal1(buySell, triggerPrice, appOrder, remark);
     }
     else
     {
         execution.setPendingSignal2(buySell, triggerPrice, appOrder, remark);
     }
 }
        public void test_GetIndexClosedAppOrder()
        {
            ISignalContext context = new SignalContext();

            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_1Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(1, context.getIndexClosedAppOrder());

            context = new SignalContext();
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_1Complete(), "Sell Order");
            Assert.AreEqual(2, context.getIndexClosedAppOrder());
        }
        public void test_GetCompleteSignalSide_Positive()
        {
            ISignalContext context = new SignalContext();

            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_1Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(AppConstant.BUY_SIGNAL, context.getCompleteSignalSide());

            context = new SignalContext();
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_1Complete(), "Sell Order");
            Assert.AreEqual(AppConstant.SELL_SIGNAL, context.getCompleteSignalSide());

            context = new SignalContext();
            context.setPendingSignal1(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.BUY_SIGNAL, 20000, createOrder_10Contract_10Complete(), "Sell Order");
            Assert.AreEqual(AppConstant.BUY_SIGNAL, context.getCompleteSignalSide());
        }
        public void test_GetFilled_Price()
        {
            ISignalContext context = new SignalContext();

            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_1Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            Assert.AreEqual(20010, context.getFilledPrice());

            context = new SignalContext();
            context.setPendingSignal1(AppConstant.BUY_SIGNAL, 20000, createOrder_Buy1Contract_0Complete(), "Buy Order");
            context.setPendingSignal2(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_1Complete(), "Sell Order");
            Assert.AreEqual(22010, context.getFilledPrice());

            context = new SignalContext();
            double filledPrice = (20010.0d * 1 + 20009 * 4 + 20008 * 5) / 10;

            context.setPendingSignal1(AppConstant.SELL_SIGNAL, 22000, createOrder_Sell1Contract_0Complete(), "Sell Order");
            context.setPendingSignal2(AppConstant.BUY_SIGNAL, 20000, createOrder_10Contract_10Complete(), "Buy Order");
            Assert.AreEqual(filledPrice, context.getFilledPrice());
        }