예제 #1
0
        public void testOrderDuration()
        {
            var fillKill = symbol().buy("fill or kill", stop(10), 100, fillOrKill());

            processBar(1, 1, 1, 1);
            symbolSystem.placeOrder(fillKill);
            hasOrders(fillKill);
            processTick(1);
            noOrders();
            fillKill = symbol().buy("fill or kill", stop(10), 100, fillOrKill());
            symbolSystem.placeOrder(fillKill);
            processBar(1, 1, 1, 1);
            noOrders();
            var bar = symbol().buy("one bar", stop(10), 100, oneBar());

            symbolSystem.placeOrder(bar);
            hasOrders(bar);
            processTick(1);
            hasOrders(bar);
            processTick(1);
            hasOrders(bar);
            O.freezeNow("2001/02/03 04:05:06");
            processBar(1, 1, 1, 1, O.now());
            noOrders();
            var dayOrder = symbol().buy("day", stop(10), 100, oneDay());

            symbolSystem.placeOrder(dayOrder);
            hasOrders(dayOrder);
            processBar(1, 1, 1, 1, O.now().AddHours(1));
            hasOrders(dayOrder);
            processBar(1, 1, 1, 1, O.now().AddDays(1));
            noOrders();
        }
예제 #2
0
 public void testRunsLimitedOnCloseDoesNotRunPassedClose()
 {
     // set the time after the close
     O.freezeNow(date("2008/10/08 16:15:00"));
     tick(-17, -0.5, 21, 0.021, 2);
     IsNull(symbolSystem.onCloseTimer);
 }
예제 #3
0
        public void testTimers()
        {
            var timers = new Timers <double>();

            O.freezeNow("2008/11/11 11:11:11");
            timers.add(0.0, millisAhead(100), () => call(0));
            O.wait(() => didCall(0));
            IsFalse(timers.has(0.0));
            timers.add(0.0, millisAhead(100), () => call(0));
            timers.add(1.0, millisAhead(100), () => call(1));
            O.wait(() => didCall(0));
            O.wait(() => didCall(1));
            timers.add(0.0, millisAhead(1000), () => call(0));
            Bombs(() => timers.add(0.0, millisAhead(100), () => call(1)), "value exists");
            timers.replace(0.0, millisAhead(100), () => call(1));
            O.wait(() => didCall(1));
            IsFalse(timers.remove(0.0));
            timers.replace(0.0, millisAhead(200), () => call(1));
            IsTrue(timers.remove(0.0));
            O.sleep(300);
            IsFalse(didCall(1));
            timers.add(0.0, millisAhead(800), () => call(0)); // adding removeOne tracking to Timers::clear method added
            timers.add(1.0, millisAhead(800), () => call(1)); // enough overhead to require loosening this deadline by 400 millis.
            timers.clear();
            O.sleep(300);
            IsFalse(didCall(0));
            IsFalse(didCall(1));
            timers.add(1.0, Objects.now().AddMilliseconds(100), d => call((int)d));
            O.wait(() => didCall(1));
            IsFalse(didCall(0));
        }
예제 #4
0
 public void testRunsLimitedOnCloseInLiveMode()
 {
     // set the time to early in the day, so that we haven't passed the close
     O.freezeNow(date("2008/10/08 11:00:00"));
     enterLong();
     IsTrue(symbolSystem.runOnClose());
     tick(-17, -0.5, 21, 0.021, 2);
     IsTrue(symbolSystem.runOnClose());
     IsNotNull(symbolSystem.onCloseTimer);
 }
예제 #5
0
        public void testNestedTimers()
        {
            var timers = new Timers <string>();

            O.freezeNow("2008/11/11 11:11:11");
            timers.add("first", millisAhead(100), name => {
                call(1);
                timers.replace("first", millisAhead(100), nameLater => {
                    didCall(1);
                    call(1);
                    timers.replace("first", millisAhead(100), s => call(0));
                });
            });
            Objects.wait(() => didCall(0));
            Objects.wait(() => didCall(1));
        }
예제 #6
0
        public void testOnCloseLive()
        {
            O.freezeNow("2009/01/01 09:00:00");
            var bar = new Bar(1, 1, 1, 1);

            processBar(bar);
            var closeTime = date("2009/01/01 12:34:56");

            symbolSystem.processCloseAt = closeTime;
            O.timerManager().isInterceptingTimersForTest = true;
            O.timerManager().intercept("2009/01/01 12:34:56", "subsystem close");
            O.timerManager().intercept("2009/01/11 09:00:00", "multisystem close");
            O.timerManager().intercept("2009/01/01 09:00:00", "system heartbeat");
            processTick(3, closeTime);
            processTick(2, closeTime);
            IsFalse(symbolSystem.onCloseTriggered);
            O.timerManager().runTimers(closeTime);
            IsTrue(symbolSystem.onCloseTriggered);
            AreEqual(2.0, symbolSystem.lastCloseProcessed);
        }