public void reqHistDataIfValid(DateTime current, String whatToShow, Contract contract)
        {
            DateTime rtbDataStartTime = appMDManager.getRtbDataStartTime();
            //DateTime histDataEndTime = rtbDataStartTime.AddMinutes(-1);
            DateTime histReqProcessTime = rtbDataStartTime.AddSeconds(30);

            //appMDManager.setHistDataEndTime(histDataEndTime);
            if (current >= histReqProcessTime && isReqHistDataSent == false && needMergeFlag)
            {
                //string whatToShow = parentUI.GetWTS();
                string strEndTime = String.Format("{0:yyyyMMdd HH:mm:ss}", rtbDataStartTime) + " HKT";
                string duration   = "1 D";
                string barSize    = "1 min";
                int    outsideRTH = 1; //use regular trading hour

                IIBTradeAppBridge parentUI = appMDManager.getParentUI();
                TickerInfo        info     = appMDManager.tickerInfo;

                //*** 2015-12-09 big change***
                //parentUI.addHistDataRequest(contract, strEndTime, duration, barSize, info.whatToShow, 1);
                parentUI.addHistDataRequest(contract, strEndTime, duration, barSize, whatToShow, 1);
                isReqHistDataSent = true;
                isReqHistDataSent = true;
            }
        }
        public AppStrategyManager(IIBTradeAppBridge appForm)
        {
            appMDManager          = new AppMDManager(appForm);
            appEventManager       = new AppEventManager(this);
            appOrderManager       = new AppOrderManager(this);
            appMaintenanceManager = new AppMainteanceManager(this);
            appMaintenanceManager.startManager();
            ParentUI = appForm;
            //OrderRepositry = new ConcurrentDictionary<string, OrderRecord>();
            activeStgNamesMap = new ConcurrentDictionary <String, String>();
            storeStg          = new Dictionary <string, IStrategy>();
            storeStg.Add(AppConstant.STG1_SHORT_NAME, new StrategyRandom1(AppConstant.STG1_SHORT_NAME, 0));
            storeStg.Add(AppConstant.STG2_SHORT_NAME, new StrategyRBreakerReverse1(AppConstant.STG2_SHORT_NAME, 1));
            storeStg.Add(AppConstant.STG3_SHORT_NAME, new StrategyRBreakerTrend1(AppConstant.STG3_SHORT_NAME, 2));
            storeStg.Add(AppConstant.STG4_SHORT_NAME, new StrategyRandom4(AppConstant.STG4_SHORT_NAME, 3));

            /*
             * storeStg.Add(AppConstant.STG5_SHORT_NAME, new StrategyStastic1(AppConstant.STG5_SHORT_NAME, 4));
             * storeStg.Add(AppConstant.STG6_SHORT_NAME, new StrategyRBreaker1(AppConstant.STG6_SHORT_NAME, 5));
             * storeStg.Add(AppConstant.STG7_SHORT_NAME, new StrategyRBreakerTrend2(AppConstant.STG7_SHORT_NAME, 6));
             */
            StoreCancelToken = new ConcurrentDictionary <string, CancellationTokenSource>();
            TimeDiffServer   = long.MaxValue;
            appEventManager.startGenerateTimeEvents();
        }
예제 #3
0
        public void test_handleResetRTBRequest()
        {
            IRealTimeBarsManagerBridge rtsBarManager = new RealTimeBarsManagerMock();
            var        uiMock   = new Mock <IIBTradeAppBridge>();
            Contract   contract = getContract();
            TickerInfo ticker   = getTickerInfo();

            uiMock.Setup(foo => foo.getRealTimeBarsManager()).Returns(rtsBarManager);
            uiMock.Setup(foo => foo.GetMDContract()).Returns(contract);
            uiMock.Setup(foo => foo.getTickerInfo()).Returns(ticker);
            IIBTradeAppBridge uiMockObj = uiMock.Object;

            var mock = new Mock <IAppStrategyManager>();

            mock.Setup(foo => foo.ParentUI).Returns(uiMockObj);
            IAppStrategyManager mockObj = mock.Object;

            DateTime time1 = new DateTime(2015, 12, 10, 10, 0, 0, DateTimeKind.Local);
            DateTime time2 = new DateTime(2015, 12, 10, 12, 57, 1, DateTimeKind.Local);
            DateTime time3 = new DateTime(2015, 12, 10, 12, 58, 1, DateTimeKind.Local);

            IAppMainteanceManager maintenanceManager = getInitMaintenaceManger(mockObj);
            AppTimeEvent          timeEvent1         = getItemEvent(time1);
            AppTimeEvent          timeEvent2         = getItemEvent(time2);
            AppTimeEvent          timeEvent3         = getItemEvent(time3);

            //[reset negative, time is before moring time and lunch time]
            maintenanceManager.handleResetRTBRequest(timeEvent1);
            Assert.IsFalse(maintenanceManager.morningTimeRTBReset);
            Assert.IsFalse(maintenanceManager.lunchTimeRTBReset);

            //[reset lunch positive, time is at lunch time]
            maintenanceManager.handleResetRTBRequest(timeEvent2);
            Assert.IsFalse(maintenanceManager.morningTimeRTBReset);
            Assert.IsTrue(maintenanceManager.lunchTimeRTBReset);

            //[reset lunch negative, time is just after lunch time]
            maintenanceManager = getInitMaintenaceManger(mockObj);
            maintenanceManager.handleResetRTBRequest(timeEvent3);
            Assert.IsFalse(maintenanceManager.morningTimeRTBReset);
            Assert.IsFalse(maintenanceManager.lunchTimeRTBReset);


            DateTime time4 = new DateTime(2015, 12, 10, 07, 0, 0, DateTimeKind.Local);
            DateTime time5 = new DateTime(2015, 12, 10, 09, 12, 1, DateTimeKind.Local);
            DateTime time6 = new DateTime(2015, 12, 10, 09, 13, 1, DateTimeKind.Local);

            AppTimeEvent timeEvent4 = getItemEvent(time4);
            AppTimeEvent timeEvent5 = getItemEvent(time5);
            AppTimeEvent timeEvent6 = getItemEvent(time6);

            //[reset morning negative, time is before morning time]
            maintenanceManager = getInitMaintenaceManger(mockObj);
            maintenanceManager.handleResetRTBRequest(timeEvent4);
            Assert.IsFalse(maintenanceManager.morningTimeRTBReset);
            Assert.IsFalse(maintenanceManager.lunchTimeRTBReset);

            //[reset morning positive, time is at morning time]
            maintenanceManager = getInitMaintenaceManger(mockObj);
            maintenanceManager.handleResetRTBRequest(timeEvent5);
            Assert.IsTrue(maintenanceManager.morningTimeRTBReset);
            Assert.IsFalse(maintenanceManager.lunchTimeRTBReset);

            //[reset morning negative, time is after morning time]
            maintenanceManager = getInitMaintenaceManger(mockObj);
            maintenanceManager.handleResetRTBRequest(timeEvent6);
            Assert.IsFalse(maintenanceManager.morningTimeRTBReset);
            Assert.IsFalse(maintenanceManager.lunchTimeRTBReset);

            //[reset morning & lunch, one cycle]
            DateTime time7 = new DateTime(2015, 12, 11, 0, 0, 1, DateTimeKind.Local);
            DateTime time8 = new DateTime(2015, 12, 11, 09, 12, 1, DateTimeKind.Local);
            DateTime time9 = new DateTime(2015, 12, 11, 12, 57, 1, DateTimeKind.Local);

            AppTimeEvent timeEvent7 = getItemEvent(time7);
            AppTimeEvent timeEvent8 = getItemEvent(time8);
            AppTimeEvent timeEvent9 = getItemEvent(time9);

            maintenanceManager = getInitMaintenaceManger(mockObj);

            //[time is 07:00]
            maintenanceManager.handleResetRTBRequest(timeEvent4);
            Assert.IsFalse(maintenanceManager.morningTimeRTBReset);
            Assert.IsFalse(maintenanceManager.lunchTimeRTBReset);

            //[time is 09:12]
            maintenanceManager.handleResetRTBRequest(timeEvent5);
            Assert.IsTrue(maintenanceManager.morningTimeRTBReset);
            Assert.IsFalse(maintenanceManager.lunchTimeRTBReset);

            //[time is 12:57]
            maintenanceManager.handleResetRTBRequest(timeEvent2);
            Assert.IsTrue(maintenanceManager.morningTimeRTBReset);
            Assert.IsTrue(maintenanceManager.lunchTimeRTBReset);

            //[time is 0:0 T+1]
            maintenanceManager.resetDailyAllFlag(time7);
            Assert.IsFalse(maintenanceManager.morningTimeRTBReset);
            Assert.IsFalse(maintenanceManager.lunchTimeRTBReset);

            //[time is  09:12 T+1]
            maintenanceManager.handleResetRTBRequest(timeEvent8);
            Assert.IsTrue(maintenanceManager.morningTimeRTBReset);
            Assert.IsFalse(maintenanceManager.lunchTimeRTBReset);

            //[time is  12:57 T+1]
            maintenanceManager.handleResetRTBRequest(timeEvent9);
            Assert.IsTrue(maintenanceManager.morningTimeRTBReset);
            Assert.IsTrue(maintenanceManager.lunchTimeRTBReset);
        }
예제 #4
0
 public AppMDManager(IIBTradeAppBridge ui)
 {
     this.parentUI   = ui;
     RTBSynchronizer = new AppRTBSynchronizer(this);
 }