Example #1
0
        public async Task CancelPnLController_Should_StopPnLEvent()
        {
            int waitDelayInMs = 5000;

            TwsObjectFactory   twsObjectFactory = new TwsObjectFactory("localhost", TestConstants.Port, 1);
            ITwsControllerBase twsController    = twsObjectFactory.TwsControllerBase;

            await twsController.EnsureConnectedAsync();

            PnLEventArgs pnlEventArgs            = null;
            DateTime     pnlEventTriggerDateTime = DateTime.MaxValue;

            twsObjectFactory.TwsCallbackHandler.PnLEvent +=
                (sender, args) => { pnlEventArgs = args; pnlEventTriggerDateTime = DateTime.Now; };

            var pnlResult = await twsObjectFactory.TwsControllerBase.RequestPnL("DU1052488", "");

            pnlEventArgs.Should().NotBeNull();
            pnlResult.Should().NotBeNull();
            pnlEventArgs.RequestId.Should().IsSameOrEqualTo(pnlResult.RequestId);

            twsObjectFactory.TwsControllerBase.CancelPnL(pnlResult.RequestId);

            await Task.Delay(waitDelayInMs);

            pnlEventTriggerDateTime.Ticks.Should().BeLessThan(DateTime.Now.AddMilliseconds(-waitDelayInMs).Ticks);
        }
Example #2
0
        public async Task PnLController_Should_ReturnPnL()
        {
            TwsObjectFactory   twsObjectFactory = new TwsObjectFactory("localhost", TestConstants.Port, 1);
            ITwsControllerBase twsController    = twsObjectFactory.TwsControllerBase;

            await twsController.EnsureConnectedAsync();

            PnLEventArgs pnlEventArgs = null;

            twsObjectFactory.TwsCallbackHandler.PnLEvent +=
                (sender, args) => { pnlEventArgs = args; };

            var pnlResult = await twsObjectFactory.TwsControllerBase.RequestPnL("DU1052488", "");

            pnlEventArgs.Should().NotBeNull();
            pnlResult.Should().NotBeNull();
            pnlEventArgs.RequestId.Should().IsSameOrEqualTo(pnlResult.RequestId);
        }