Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            var historyProvider = new FinamQuotesHistoryProvider(
                new FinamTicksParser(),
                new FinamCandlesParser(),
                new FinamQuotesHistoryClient(
                    new HistoryConfiguration()));

            var ticksHistory = await historyProvider.GetTicksHistory(
                "GAZP",
                new DateTime(2020, 2, 20, 0, 0, 0),
                new DateTime(2020, 2, 21, 0, 0, 0),
                CancellationToken.None);

            var candlesHistory = await historyProvider.GetCandlesHistory(
                "GAZP",
                TimeInterval.Minutes15,
                new DateTime(2020, 2, 20, 0, 0, 0),
                new DateTime(2020, 2, 21, 0, 0, 0),
                CancellationToken.None);

            var sandBoxRunner = new SandBoxRunner();
            var report        = sandBoxRunner.RunStrategy(
                new List <Candle>(),
                new RandomStrategy(2),
                candlesHistory.Candles.Select(x => new Tick(value: x.CloseValue, x.Volume, x.CloseDateTime)));
        }
Ejemplo n.º 2
0
        public async Task <LiveChartModel> Visualize(DateTime date)
        {
            var ticksToShow = new ChartValues <decimal>();

            seriesCollection = new SeriesCollection
            {
                new LineSeries
                {
                    Values            = ticksToShow,
                    PointGeometrySize = 1,
                    PointForeground   = Brushes.Black,
                    Foreground        = Brushes.Black,
                },
            };

            var historyProvider = new FinamQuotesHistoryProvider(
                new FinamTicksParser(),
                new FinamCandlesParser(),
                new FinamQuotesHistoryClient(
                    new HistoryConfiguration()));

            Log("Load ticks");
            ticks = (await historyProvider.GetTicksHistory(
                         "GAZP",
                         date.Date,
                         date.Date.AddDays(1),
                         CancellationToken.None)).Ticks.ToList();
            Log($"{ticks.Count} ticks loaded");

            textBlock.Dispatcher.InvokeAsync(async() =>
            {
                using var strategy = new RandomStrategy(10);
                strategy.Subscribe(this);
                for (var i = 0; i < ticks.Count; i++)
                {
                    Log($"Tick {i} of {ticks.Count}");
                    var tick = ticks[i];
                    strategy.OnTick(tick);
                    ticksToShow.Add(tick.Value);
                    await Task.Delay(20);
                }

                var report = new Report(strategy);
                Log(report.ToString());
            });

            var ticksDates = ticks.Select(x => x.DateTime.ToString("HH:mm:ss")).ToList();

            return(new LiveChartModel
            {
                SeriesCollection = seriesCollection,
                Labels = ticksDates,
                MinY = ticks.Min(x => x.Value),
                MaxY = ticks.Max(x => x.Value),
            });
        }
 public FinamQuotesHistoryProviderShould()
 {
     ticksParserMock         = new Mock <ITicksParser>();
     candlesParserMock       = new Mock <ICandlesParser>();
     quotesHistoryClientMock = new Mock <IQuotesHistoryClient>();
     quotesHistoryProvider   = new FinamQuotesHistoryProvider(
         ticksParserMock.Object,
         candlesParserMock.Object,
         quotesHistoryClientMock.Object);
 }
Ejemplo n.º 4
0
        public async Task <LiveChartModel> Visualize(DateTime date)
        {
            var historyProvider = new FinamQuotesHistoryProvider(
                new FinamTicksParser(),
                new FinamCandlesParser(),
                new FinamQuotesHistoryClient(
                    new HistoryConfiguration()));

            var candlesHistory = await historyProvider.GetCandlesHistory(
                "GAZP",
                TimeInterval.Minutes10,
                date.Date,
                date.Date.AddDays(1).AddSeconds(-1),
                CancellationToken.None);

            var candles       = candlesHistory.Candles.ToList();
            var sandBoxRunner = new SandBoxRunner();
            var report        = sandBoxRunner.RunStrategy(
                new List <Candle>(),
                new RandomStrategy(3),
                candles.Select(x => new Tick(value: x.CloseValue, x.Volume, x.CloseDateTime)));

            var candlesToShow = new ChartValues <OhlcPoint>();

            candlesToShow.AddRange(candles.Select(x =>
                                                  new OhlcPoint((double)x.OpenValue, (double)x.HighValue, (double)x.LowValue, (double)x.CloseValue)));

            var lots = report.CloseLots.Select(lot =>
            {
                var openPosition  = candles.FindIndex(c => c.CloseDateTime == lot.OpenTime);
                var closePosition = candles.FindIndex(c => c.CloseDateTime == lot.CloseTime);
                var brush         = lot is LongLot ? Brushes.Green : Brushes.Red;
                var pointGeometry = lot is LongLot
                    ? Geometry.Parse("M 0 0 L 4 -4 L 8 0 Z")
                    : Geometry.Parse("M 0 0 L 4 4 L 8 0 Z");
                return(new LineSeries
                {
                    Values = new ChartValues <ObservablePoint>
                    {
                        new ObservablePoint(openPosition, (double)lot.Open),
                        new ObservablePoint(closePosition, (double)lot.Close),
                    },
                    Fill = Brushes.Transparent,
                    Stroke = brush,
                    PointForeground = brush,
                    PointGeometry = pointGeometry,
                    PointGeometrySize = 10,
                });
            });

            var candlesDates     = candlesHistory.Candles.Select(x => x.CloseDateTime.ToString("HH:mm:ss"));
            var seriesCollection = new SeriesCollection
            {
                new OhlcSeries()
                {
                    Values        = candlesToShow,
                    LabelPoint    = x => x.Close.ToString("HH:mm:ss"),
                    IncreaseBrush = Brushes.Black,
                    DecreaseBrush = Brushes.Black,
                },
            };

            seriesCollection.AddRange(lots);
            return(new LiveChartModel
            {
                SeriesCollection = seriesCollection,
                Labels = candlesDates,
                MinY = candlesHistory.Candles.Min(x => x.CloseValue),
                MaxY = candlesHistory.Candles.Max(x => x.CloseValue),
            });
        }