Пример #1
0
        public MainViewModel(IConnectableObservable <Trade> source)
        {
            var prices = from trade in source
                         select trade.Price;

            this.lastPrice = prices
                             .Sample(TimeSpan.FromSeconds(0.2))
                             .ToProperty(this, t => t.LastPrice);

            this.trend = prices
                         .DistinctUntilChanged()
                         .Buffer(2, 1)
                         .Sample(TimeSpan.FromSeconds(0.2))
                         .ObserveOnDispatcher()
                         .Select(b => b[0] < b[1] ? GreenBrush : RedBrush)
                         .ToProperty(this, t => t.Trend);

            var tardis = new HistoricalScheduler(DateTimeOffset.UtcNow.AddMinutes(-61));

            source.Subscribe(t => tardis.AdvanceTo(t.Timestamp));

            this.Candles = prices
                           .Window(TimeSpan.FromMinutes(5), tardis)
                           .Select(w => new Candle(
                                       lo: w.Scan(double.MaxValue, (min, current) => Math.Min(min, current)),
                                       hi: w.Scan(double.MinValue, (max, current) => Math.Max(max, current)),
                                       open: w.Take(1),
                                       close: w,
                                       time: new DateTime(tardis.Clock.Ticks)))
                           .CreateCollection();

            this.Chart = new PlotModel {
                PlotAreaBackground = OxyColors.Black, PlotAreaBorderThickness = new OxyThickness(1)
            };
            this.Chart.Axes.Add(new DateTimeAxis {
                StringFormat = "hh:mm", AxislineStyle = LineStyle.Solid, AxislineColor = OxyColors.White, AxislineThickness = 1, TextColor = OxyColors.White, TicklineColor = OxyColors.White
            });
            this.Chart.Axes.Add(new LinearAxis {
                AxislineStyle = LineStyle.Solid, AxislineColor = OxyColors.White, AxislineThickness = 1, TextColor = OxyColors.White, TicklineColor = OxyColors.White, MajorGridlineColor = OxyColors.Gray, MajorGridlineStyle = LineStyle.Dash
            });
            this.Chart.Series.Add(new CandleStickSeries
            {
                ItemsSource    = this.Candles,
                DataFieldX     = "Time",
                DataFieldHigh  = "Hi",
                DataFieldLow   = "Lo",
                DataFieldOpen  = "Open",
                DataFieldClose = "Close",

                CandleWidth = 12, StrokeThickness = 2, IncreasingFill = OxyColors.DarkGreen, DecreasingFill = OxyColors.Red, Color = OxyColors.White
            });

            this.Candles.ChangeTrackingEnabled = true;
            this.Candles.ItemChanged
            .Sample(TimeSpan.FromSeconds(0.2))
            .Subscribe(p => this.Chart.InvalidatePlot(updateData: true));

            source.Connect();
        }
        public void No_Nested_AdvanceTo()
        {
            var s = new HistoricalScheduler();

            s.Schedule(() => s.AdvanceTo(DateTimeOffset.Now.AddDays(1)));

            ReactiveAssert.Throws <InvalidOperationException>(() => s.Start());
        }
        public void AdvanceTo_ArgumentChecking()
        {
            var now = DateTimeOffset.Now;

            var s = new HistoricalScheduler(now);

            ReactiveAssert.Throws <ArgumentOutOfRangeException>(() => s.AdvanceTo(now.Subtract(TimeSpan.FromSeconds(1))));
        }
 public void Clock()
 {
     var scheduler = new HistoricalScheduler ();
     Assert.AreEqual (DateTimeOffset.MinValue, scheduler.Clock, "#1"); // default
     scheduler.AdvanceBy (TimeSpan.FromDays (1));
     Assert.AreEqual (DateTimeOffset.MinValue.AddDays (1), scheduler.Clock, "#2");
     scheduler.AdvanceTo (new DateTimeOffset (2012, 1, 1, 0, 0, 0, TimeSpan.Zero));
     Assert.AreEqual (2012, scheduler.Clock.Year, "#3");
 }
Пример #5
0
        public void Clock()
        {
            var scheduler = new HistoricalScheduler();

            Assert.AreEqual(DateTimeOffset.MinValue, scheduler.Clock, "#1");              // default
            scheduler.AdvanceBy(TimeSpan.FromDays(1));
            Assert.AreEqual(DateTimeOffset.MinValue.AddDays(1), scheduler.Clock, "#2");
            scheduler.AdvanceTo(new DateTimeOffset(2012, 1, 1, 0, 0, 0, TimeSpan.Zero));
            Assert.AreEqual(2012, scheduler.Clock.Year, "#3");
        }
        public void SetUp()
        {
            _tradeRepo = Substitute.For<ITradeRepository>();
            _analyticsService = Substitute.For<IAnalyticsService>();
            _executionService = Substitute.For<IExecutionService>();
            _lastValueCache = Substitute.For<IPriceLastValueCache>();

            _scheduler = new HistoricalScheduler();
            _scheduler.AdvanceTo(DateTimeOffset.Now);

            _schedulerService = Substitute.For<ISchedulerService>();
            _schedulerService.ThreadPool.Returns(_scheduler);
        }
Пример #7
0
        public void SetUp()
        {
            _tradeRepo        = Substitute.For <ITradeRepository>();
            _analyticsService = Substitute.For <IAnalyticsService>();
            _executionService = Substitute.For <IExecutionService>();
            _lastValueCache   = Substitute.For <IPriceLastValueCache>();

            _scheduler = new HistoricalScheduler();
            _scheduler.AdvanceTo(DateTimeOffset.Now);

            _schedulerService = Substitute.For <ISchedulerService>();
            _schedulerService.ThreadPool.Returns(_scheduler);
        }
        public void Sleep2()
        {
            var s = new HistoricalScheduler();

            var n = 0;

            s.Schedule(s.Now.AddMinutes(1), rec =>
            {
                s.Sleep(TimeSpan.FromMinutes(3));
                n++;

                rec(s.Now.AddMinutes(1));
            });

            s.AdvanceTo(s.Now + TimeSpan.FromMinutes(5));

            Assert.Equal(2, n);
        }
        public void AdvanceTo()
        {
            var s = new HistoricalScheduler();

            var list = new List <Timestamped <int> >();

            s.Schedule(Time(0), () => list.Add(new Timestamped <int>(0, s.Now)));
            s.Schedule(Time(1), () => list.Add(new Timestamped <int>(1, s.Now)));
            s.Schedule(Time(2), () => list.Add(new Timestamped <int>(2, s.Now)));
            s.Schedule(Time(10), () => list.Add(new Timestamped <int>(10, s.Now)));
            s.Schedule(Time(11), () => list.Add(new Timestamped <int>(11, s.Now)));

            s.AdvanceTo(Time(8));

            Assert.Equal(Time(8), s.Now);
            Assert.Equal(Time(8), s.Clock);

            list.AssertEqual(
                new Timestamped <int>(0, Time(0)),
                new Timestamped <int>(1, Time(1)),
                new Timestamped <int>(2, Time(2))
                );

            s.AdvanceTo(Time(8));

            Assert.Equal(Time(8), s.Now);
            Assert.Equal(Time(8), s.Clock);

            list.AssertEqual(
                new Timestamped <int>(0, Time(0)),
                new Timestamped <int>(1, Time(1)),
                new Timestamped <int>(2, Time(2))
                );

            s.Schedule(Time(7), () => list.Add(new Timestamped <int>(7, s.Now)));
            s.Schedule(Time(8), () => list.Add(new Timestamped <int>(8, s.Now)));

            ReactiveAssert.Throws <ArgumentOutOfRangeException>(() => s.AdvanceTo(Time(4)));

            Assert.Equal(Time(8), s.Now);
            Assert.Equal(Time(8), s.Clock);

            list.AssertEqual(
                new Timestamped <int>(0, Time(0)),
                new Timestamped <int>(1, Time(1)),
                new Timestamped <int>(2, Time(2))
                );

            s.AdvanceTo(Time(10));

            Assert.Equal(Time(10), s.Now);
            Assert.Equal(Time(10), s.Clock);

            list.AssertEqual(
                new Timestamped <int>(0, Time(0)),
                new Timestamped <int>(1, Time(1)),
                new Timestamped <int>(2, Time(2)),
                new Timestamped <int>(7, Time(8)),
                new Timestamped <int>(8, Time(8)),
                new Timestamped <int>(10, Time(10))
                );

            s.AdvanceTo(Time(100));

            Assert.Equal(Time(100), s.Now);
            Assert.Equal(Time(100), s.Clock);

            list.AssertEqual(
                new Timestamped <int>(0, Time(0)),
                new Timestamped <int>(1, Time(1)),
                new Timestamped <int>(2, Time(2)),
                new Timestamped <int>(7, Time(8)),
                new Timestamped <int>(8, Time(8)),
                new Timestamped <int>(10, Time(10)),
                new Timestamped <int>(11, Time(11))
                );
        }
Пример #10
0
 public void AdvanceTo(DateTimeOffset time)
 {
     Scheduler.AdvanceTo(time);
     movements.OnNext(Scheduler.Now);
 }
Пример #11
0
 public void SetUp()
 {
     this.scheduler = new HistoricalScheduler();
     scheduler.AdvanceTo(GameStartDateTimeOffset);
     this.game = new Okazuki.TenSecGame.Models.TenSecGame(scheduler);
 }