Beispiel #1
0
        public void testPositionPublish()
        {
            var counter = positionPublishCounter();

            // get a position in "simulation"
            processBar(1, 3.5, 0, 2);
            hasOrders(buy("enter long", stop(3.5), 100, fillOrKill()));
            fill(0, 3.0);
            // now we are live
            processTick(3.5);
            AreEqual(100, counter.getOne <int>("beginValue"));
            AreEqual(100, counter.getOne <int>("liveValue"));
            AreEqual(O.hostname(), counter.getOne <string>("hostname"));
            var beginTime = counter.getOne <string>("beginTimestamp");
            var liveTime  = counter.getOne <string>("liveTimestamp");

            counter.clear();
            // this way we should get a new timestamp
            util.Dates.freezeNow(util.Dates.secondsAhead(1, util.Dates.now()));
            processTick(3.5);
            counter.requireNoMessages();
            hasOrders(
                sell("exit long", market(), 100, fillOrKill()),
                sell("exit long 2", market(), 100, fillOrKill())
                );
            fill(0, 2.0);
            O.sleep(100);
            AreNotEqual(liveTime, counter.getOne <string>("liveTimestamp"));
            AreEqual(beginTime, counter.getOne <string>("beginTimestamp"));
            AreEqual(100, counter.getOne <int>("beginValue"));
            AreEqual(0, counter.getOne <int>("liveValue"));
        }
Beispiel #2
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));
        }
Beispiel #3
0
        public void testOnCloseLogicIsCompletelySkippedWhenTurnedOffBySystem()
        {
            symbolSystem.useOnCloseLogic = false;
            var bar = new Bar(1, 1, 1, 1);

            processBar(bar);
            processTick(2);
            O.sleep(100);
            IsFalse(symbolSystem.onCloseTriggered);
            O.sleep(1100);
            IsFalse(symbolSystem.onCloseTriggered);
        }
Beispiel #4
0
 void acquireTestLock()
 {
     while (O.trueDat())
     {
         var otherLock = db.TestLocksTable.TEST_LOCK.tryAcquireLockOnce("test", GetType().FullName);
         if (otherLock.Equals(db.TestLocksTable.NONE))
         {
             return;
         }
         LogC.info("waiting for test lock " + otherLock);
         O.sleep(350);
     }
 }
Beispiel #5
0
        public void testAccumulatingSomeRunTime()
        {
            const string A = "a";
            const string B = "b";

            O.zeroTo(10, i => {
                Stopwatch.start(A);
                Objects.sleep(10);
                Stopwatch.stop(A);
            });
            Stopwatch.start(B);
            O.zeroTo(100, i => O.sleep(10));
            Stopwatch.stop(B);
            IsTrue(Stopwatch.millis(A) > 100, "elapsed outside allowed range: " + Stopwatch.millis(A) + " " + Stopwatch.seconds(A));
            IsTrue(Stopwatch.seconds(A) < 0.3, "elapsed outside allowed range: " + Stopwatch.millis(A) + " " + Stopwatch.seconds(A));
            IsTrue(Stopwatch.millis(B) > 1000 && Stopwatch.seconds(B) < 4, "elapsed outside allowed range: " + Stopwatch.seconds(B));
            IsTrue(Stopwatch.millisPer(A) >= 10 && Stopwatch.millisPer(A) < 30);
            Matches("a - total", Stopwatch.report(A));
        }