Ejemplo n.º 1
0
        private IAppRTBSynchronizer getSynchronizer_for_updatePreMergeRTBarSeries()
        {
            Series <DateTime, MarketDataElement> preMergeRTBarSeries   = null;
            Series <DateTime, MarketDataElement> preMergeHistBarSeries = null;
            Series <DateTime, MarketDataElement> TimeBarSeries         = null;

            DateTime RTBTime1 = new DateTime(2015, 10, 21, 9, 20, 0, DateTimeKind.Local);
            DateTime RTBTime2 = new DateTime(2015, 10, 21, 9, 21, 0, DateTimeKind.Local);
            DateTime RTBTime3 = new DateTime(2015, 10, 21, 9, 22, 0, DateTimeKind.Local);

            preMergeRTBarSeries = addMarketDataElementWithTimeOnlyToSeries(RTBTime1, preMergeRTBarSeries);
            preMergeRTBarSeries = addMarketDataElementWithTimeOnlyToSeries(RTBTime2, preMergeRTBarSeries);
            preMergeRTBarSeries = addMarketDataElementWithTimeOnlyToSeries(RTBTime3, preMergeRTBarSeries);

            AppMDManager appMDManager = new AppMDManager(null);

            appMDManager.setTimeBarSeries(TimeBarSeries);
            appMDManager.setRtbDataStartTime(RTBTime1);

            IAppRTBSynchronizer synchronizer = appMDManager.getAppRTBSynchronizer();

            synchronizer.preMergeHistBarSeries = preMergeHistBarSeries;
            synchronizer.preMergeRTBarSeries   = preMergeRTBarSeries;
            synchronizer.setNeedMergeFlag(true);
            synchronizer.setIsDataMerged(false);
            return(synchronizer);
        }
Ejemplo n.º 2
0
        public void test_isDataReady_negative2()
        {
            //[Test: non-syn action and data not ready case, synchronizer.getIsDataMerged is false, synchronizer.getNeedMergeFlag is false, Timeseries is null.]
            IAppRTBSynchronizer synchronizer = getAppRTBSynchronizer_for_isDataReady_negative2();
            AppMDManager        appMDManager = new AppMDManager(null);

            appMDManager.injectAppRTBSynchronizer(synchronizer);
            Assert.IsFalse(appMDManager.isDataReady());
        }
Ejemplo n.º 3
0
        public void test_isDataReady_positive1()
        {
            //[Test: need syn action and data ready case, synchronizer.getIsDataMerged is true, synchronizer.getNeedMergeFlag is true.]
            IAppRTBSynchronizer synchronizer = getAppRTBSynchronizer_for_isDataReady_positive1();
            AppMDManager        appMDManager = new AppMDManager(null);

            appMDManager.injectAppRTBSynchronizer(synchronizer);
            Assert.IsTrue(appMDManager.isDataReady());
        }
Ejemplo n.º 4
0
        private IAppRTBSynchronizer getSyn_checkIsRTBarMergeNeed()
        {
            var mock = new Mock <IAppRTBSynchronizer>();

            mock.Setup(foo => foo.isRTBarMergeNeed("true")).Returns(true);
            mock.Setup(foo => foo.isRTBarMergeNeed("false")).Returns(false);
            IAppRTBSynchronizer fooObj = mock.Object;

            return(fooObj);
        }
Ejemplo n.º 5
0
        private IAppRTBSynchronizer getAppRTBSynchronizer_for_isDataReady_negative2()
        {
            var mock = new Mock <IAppRTBSynchronizer>();

            mock.Setup(foo => foo.getIsDataMerged()).Returns(false);
            mock.Setup(foo => foo.getNeedMergeFlag()).Returns(false);
            IAppRTBSynchronizer fooObj = mock.Object;

            return(fooObj);
        }
Ejemplo n.º 6
0
        public void test_mergeRTBHistDataIfValid_negative4()
        {
            //[Test : merge unsuccess, RTB data serie is null]
            IAppRTBSynchronizer synchronizer = getSynchronizer_for_mergeRTBHistDataIfValid_negative4();

            synchronizer.mergeRTBHistDataIfValid();
            IAppMDManager appMDManager = synchronizer.getAppMDManager();
            Series <DateTime, MarketDataElement> TimeBarSeries = appMDManager.getTimeBarSeries();

            Assert.IsNull(TimeBarSeries);
            Assert.AreEqual(false, synchronizer.getIsDataMerged());
        }
Ejemplo n.º 7
0
        public void test_mergeRTBHistDataIfValid_negative2()
        {
            //[Test : merge unsuccess, hist data is not fully loaded yet, missing the last hist data]
            IAppRTBSynchronizer synchronizer = getSynchronizer_for_mergeRTBHistDataIfValid_negative2();

            synchronizer.mergeRTBHistDataIfValid();
            IAppMDManager appMDManager = synchronizer.getAppMDManager();
            Series <DateTime, MarketDataElement> TimeBarSeries = appMDManager.getTimeBarSeries();

            Assert.IsNull(TimeBarSeries);
            Assert.AreEqual(false, synchronizer.getIsDataMerged());
        }
        public HistoricalDataManager(IBClient ibClient, Chart chart, DataGridView gridView, IBTradeApp appForm)
            : base(ibClient, chart)
        {
            /*
             * Chart historicalChart = (Chart)uiControl;
             * historicalChart.Series[0]["PriceUpColor"] = "Green";
             * historicalChart.Series[0]["PriceDownColor"] = "Red";
             */
            this.gridView = gridView;
            this.appForm  = appForm;
            AppStrategyManager stgManager = appForm.appStrategyManager;

            this.appMDManager    = stgManager.getAppMDManager();
            this.RTBSynchronizer = appMDManager.getAppRTBSynchronizer();
        }
Ejemplo n.º 9
0
        public void test_isDataReady_positive2()
        {
            DateTime time1 = new DateTime(2015, 10, 21, 10, 0, 5, DateTimeKind.Local);
            //[Test: non-syn action and data ready case, synchronizer.getIsDataMerged is false, synchronizer.getNeedMergeFlag is false, Timeseries is not null.]
            Series <DateTime, MarketDataElement> TimeSeries = null;

            TimeSeries = addMarketDataElementWithTimeOnlyToSeries(time1, TimeSeries);

            IAppRTBSynchronizer synchronizer = getAppRTBSynchronizer_for_isDataReady_positive2();
            AppMDManager        appMDManager = new AppMDManager(null);

            appMDManager.injectAppRTBSynchronizer(synchronizer);
            appMDManager.setTimeBarSeries(TimeSeries);
            Assert.IsTrue(appMDManager.isDataReady());
        }
Ejemplo n.º 10
0
        public void test_mergeRTBHistDataIfValid_positive2()
        {
            //[Test : merge success, histDataSeries and RTBDataSeries is not continuous]
            IAppRTBSynchronizer synchronizer = getSynchronizer_for_mergeRTBHistDataIfValid_positive2();

            synchronizer.mergeRTBHistDataIfValid();
            IAppMDManager appMDManager = synchronizer.getAppMDManager();
            Series <DateTime, MarketDataElement> TimeBarSeries = appMDManager.getTimeBarSeries();

            Assert.AreEqual(10, TimeBarSeries.KeyCount);
            Assert.AreEqual(true, TimeBarSeries.TryGet(new DateTime(2015, 10, 21, 9, 15, 0, DateTimeKind.Local)).HasValue);
            Assert.AreEqual(true, TimeBarSeries.TryGet(new DateTime(2015, 10, 21, 9, 23, 0, DateTimeKind.Local)).HasValue);
            Assert.AreEqual(true, TimeBarSeries.TryGet(new DateTime(2015, 10, 21, 9, 24, 0, DateTimeKind.Local)).HasValue);
            Assert.AreEqual(true, TimeBarSeries.TryGet(new DateTime(2015, 10, 21, 9, 26, 0, DateTimeKind.Local)).HasValue);
            Assert.AreEqual(true, synchronizer.getIsDataMerged());
        }
Ejemplo n.º 11
0
        public void test_checkIsRTBarMergeNeed_negative2()
        {
            //[Test: non-initial and negative case, initFlag is true and isRTBarMergeNeed is false => initFlag is true, getIsRTBarMergeNeed is false]
            IAppRTBSynchronizer synchronizer = getSyn_checkIsRTBarMergeNeed();
            AppMDManager        appMDManager = new AppMDManager(null);

            appMDManager.injectRTBInitFlag(true);
            TickerInfo info = new TickerInfo();

            info.startTime = "false";
            appMDManager.injectAppRTBSynchronizer(synchronizer);
            appMDManager.tickerInfo = info;
            appMDManager.checkIsRTBarMergeNeed();
            Assert.IsTrue(appMDManager.getRTBInitFlag());
            Assert.IsFalse(appMDManager.getIsRTBarMergeNeed());
        }
Ejemplo n.º 12
0
        private IAppRTBSynchronizer getSynchronizer_for_mergeRTBHistDataIfValid_positive3()
        {
            Series <DateTime, MarketDataElement> preMergeRTBarSeries   = null;
            Series <DateTime, MarketDataElement> preMergeHistBarSeries = null;
            Series <DateTime, MarketDataElement> TimeBarSeries         = null;

            DateTime histTime1 = new DateTime(2015, 10, 21, 9, 15, 0, DateTimeKind.Local);
            DateTime histTime2 = new DateTime(2015, 10, 21, 9, 16, 0, DateTimeKind.Local);
            DateTime histTime3 = new DateTime(2015, 10, 21, 9, 17, 0, DateTimeKind.Local);
            DateTime histTime4 = new DateTime(2015, 10, 21, 9, 18, 0, DateTimeKind.Local);
            DateTime histTime5 = new DateTime(2015, 10, 21, 9, 21, 0, DateTimeKind.Local);
            DateTime histTime6 = new DateTime(2015, 10, 21, 9, 22, 0, DateTimeKind.Local);
            DateTime histTime7 = new DateTime(2015, 10, 21, 9, 23, 0, DateTimeKind.Local);
            DateTime histTime8 = new DateTime(2015, 10, 21, 9, 24, 0, DateTimeKind.Local);

            DateTime RTBTime1 = new DateTime(2015, 10, 21, 9, 24, 0, DateTimeKind.Local);
            DateTime RTBTime2 = new DateTime(2015, 10, 21, 9, 25, 0, DateTimeKind.Local);
            DateTime RTBTime3 = new DateTime(2015, 10, 21, 9, 26, 0, DateTimeKind.Local);


            preMergeHistBarSeries = addMarketDataElementWithTimeOnlyToSeries(histTime1, preMergeHistBarSeries);
            preMergeHistBarSeries = addMarketDataElementWithTimeOnlyToSeries(histTime2, preMergeHistBarSeries);
            preMergeHistBarSeries = addMarketDataElementWithTimeOnlyToSeries(histTime3, preMergeHistBarSeries);
            preMergeHistBarSeries = addMarketDataElementWithTimeOnlyToSeries(histTime4, preMergeHistBarSeries);
            preMergeHistBarSeries = addMarketDataElementWithTimeOnlyToSeries(histTime5, preMergeHistBarSeries);
            preMergeHistBarSeries = addMarketDataElementWithTimeOnlyToSeries(histTime6, preMergeHistBarSeries);
            preMergeHistBarSeries = addMarketDataElementWithTimeOnlyToSeries(histTime7, preMergeHistBarSeries);
            preMergeHistBarSeries = addMarketDataElementWithTimeOnlyToSeries(histTime8, preMergeHistBarSeries);

            preMergeRTBarSeries = addMarketDataElementWithTimeOnlyToSeries(RTBTime1, preMergeRTBarSeries);
            preMergeRTBarSeries = addMarketDataElementWithTimeOnlyToSeries(RTBTime2, preMergeRTBarSeries);
            preMergeRTBarSeries = addMarketDataElementWithTimeOnlyToSeries(RTBTime3, preMergeRTBarSeries);

            AppMDManager appMDManager = new AppMDManager(null);

            appMDManager.setTimeBarSeries(TimeBarSeries);
            appMDManager.setRtbDataStartTime(RTBTime1);
            appMDManager.setHistDataEndTime(histTime7);
            IAppRTBSynchronizer synchronizer = appMDManager.getAppRTBSynchronizer();

            synchronizer.preMergeHistBarSeries = preMergeHistBarSeries;
            synchronizer.preMergeRTBarSeries   = preMergeRTBarSeries;
            synchronizer.setNeedMergeFlag(true);
            synchronizer.setIsDataMerged(false);
            return(synchronizer);
        }
Ejemplo n.º 13
0
        public void test_updatePreMergeRTBarSeries()
        {
            DateTime validTime   = new DateTime(2015, 10, 21, 9, 23, 0, DateTimeKind.Local);
            DateTime invalidTime = new DateTime(2015, 10, 21, 9, 22, 0, DateTimeKind.Local);

            //[Test : merge sucess]
            RTDataBar RTBar = new RTDataBar();

            RTBar.high   = 20200;
            RTBar.open   = 20100;
            RTBar.low    = 20000;
            RTBar.close  = 20150;
            RTBar.volume = 99999;
            RTBar.time   = validTime;
            IAppRTBSynchronizer synchronizer = getSynchronizer_for_updatePreMergeRTBarSeries();

            synchronizer.setIsDataMerged(false);
            synchronizer.updatePreMergeRTBarSeries(RTBar);
            Assert.AreEqual(4, synchronizer.preMergeRTBarSeries.KeyCount);

            //[Test : merge unsucess, the time of real time bar is already in the sereise]
            RTBar        = new RTDataBar();
            RTBar.high   = 20200;
            RTBar.open   = 20100;
            RTBar.low    = 20000;
            RTBar.close  = 20150;
            RTBar.volume = 99999;
            RTBar.time   = invalidTime;
            synchronizer = getSynchronizer_for_updatePreMergeRTBarSeries();
            synchronizer.setIsDataMerged(false);
            synchronizer.updatePreMergeRTBarSeries(RTBar);
            Assert.AreEqual(3, synchronizer.preMergeRTBarSeries.KeyCount);

            //[Test : merge unsucess, the isDataMerged flag is already set to ture]
            RTBar        = new RTDataBar();
            RTBar.high   = 20200;
            RTBar.open   = 20100;
            RTBar.low    = 20000;
            RTBar.close  = 20150;
            RTBar.volume = 99999;
            RTBar.time   = validTime;
            synchronizer = getSynchronizer_for_updatePreMergeRTBarSeries();
            synchronizer.setIsDataMerged(true);
            synchronizer.updatePreMergeRTBarSeries(RTBar);
            Assert.AreEqual(3, synchronizer.preMergeRTBarSeries.KeyCount);
        }
Ejemplo n.º 14
0
        public void test_mergeRTBHistDataIfValid_negative1()
        {
            //[Test : merge unsuccess, needMerge Flag is set to false]
            IAppRTBSynchronizer synchronizer = getSynchronizer_for_mergeRTBHistDataIfValid_negative1();

            synchronizer.setNeedMergeFlag(false);
            synchronizer.setIsDataMerged(false);
            synchronizer.mergeRTBHistDataIfValid();
            IAppMDManager appMDManager = synchronizer.getAppMDManager();
            Series <DateTime, MarketDataElement> TimeBarSeries = appMDManager.getTimeBarSeries();

            Assert.IsNull(TimeBarSeries);
            Assert.AreEqual(false, synchronizer.getIsDataMerged());

            //[Test : merge unsuccess, data merged Flag is set to true]
            synchronizer = getSynchronizer_for_mergeRTBHistDataIfValid_negative1();
            synchronizer.setNeedMergeFlag(true);
            synchronizer.setIsDataMerged(true);
            synchronizer.mergeRTBHistDataIfValid();
            appMDManager  = synchronizer.getAppMDManager();
            TimeBarSeries = appMDManager.getTimeBarSeries();
            Assert.IsNull(TimeBarSeries);
        }
Ejemplo n.º 15
0
 public AppMDManager(IIBTradeAppBridge ui)
 {
     this.parentUI   = ui;
     RTBSynchronizer = new AppRTBSynchronizer(this);
 }