Example #1
0
        protected async override void Handle(PlayInsideBarCommand request)
        {
            if (DateTime.Now.Second >= 58)
            {
                try
                {
                    if (request.InsideBars.Count > 0)
                    {
                        var account = await _accountRepository.GetAccountAsync("11181613");

                        var instruments = await _instrumentRepository.GetInstruments();

                        foreach (var insideBars in request.InsideBars)
                        {
                            var instrument = instruments.FirstOrDefault(x => x.Symbol == insideBars.Symbol);
                            var insideBar  = new InsideBarStrategy(instrument, 1000, account);
                            var chart      = await _chartRepository.GetChartAsync(insideBars.Symbol, "M1", 4000, instrument.Precision);

                            insideBar.Play(chart);
                            await _mediator.DispatchDomainEventsAsync(account);

                            _logger.LogInformation($"Play inside bar {insideBar.Instrument.Symbol}");
                        }
                    }
                    else
                    {
                        _logger.LogInformation("No inside bars");
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Error Inside bar");
                }
            }
        }
Example #2
0
        public static async void Bash()
        {
            var stringArray = string.Empty;
            var symbol      = "DE30";
            var interval    = "M1";

            var instrument = await _instrumentRepository.GetInstrument(symbol);

            var chart = await _chartRepository.GetChartAsync(symbol, interval, 200, instrument.Precision);

            var quotations = chart.Quotations.Skip(chart.Quotations.Count - 120).ToList();;

            foreach (var item in quotations)
            {
                stringArray += $"{item.Close}/{item.Open}/{item.Low}/{item.High}/{item.Volume}/{item.Time} ";
            }

            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "cmd.exe",
                    RedirectStandardInput  = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                }
            };

            process.Start();
            // Pass multiple commands to cmd.exe
            using (var sw = process.StandardInput)
            {
                if (sw.BaseStream.CanWrite)
                {
                    // Vital to activate Anaconda
                    sw.WriteLine(@"C:\Users\pawel\Anaconda3\Scripts\activate.bat");
                    // Activate your environment
                    sw.WriteLine("activate test4");
                    // run your script. You can also pass in arguments
                    sw.WriteLine($@"redictNextMove.py {stringArray}");
                }
            }

            while (!process.StandardOutput.EndOfStream)
            {
                var line = process.StandardOutput.ReadLine();
                Console.WriteLine(line);
                if (line.Contains("BUY"))
                {
                    await _accountRepository.MakeTransactionBuyAsync(30, 8, (double)1, instrument, "M1");
                }
                else if (line.Contains("SELL"))
                {
                    await _accountRepository.MakeTransactionSellAsync(30, 8, (double)1, instrument, "M1");
                }
            }
            Console.ReadKey();
        }
Example #3
0
        public async Task <InsideBarView> GetInsideBar(string symbol)
        {
            var instrument = await _instrumentRepository.GetInstrument(symbol);

            var chart = await _chartRepository.GetChartAsync(symbol, "D1", 10, instrument.Precision);

            chart.SetInsideBar(DateTime.Now.AddDays(-1));
            if (chart.InsideBar != null)
            {
                return(new InsideBarView
                {
                    HighInsideBar = chart.InsideBar.HighInsideBar,
                    LowInsideBar = chart.InsideBar.LowInsideBar,
                    HighMotherInsideBar = chart.InsideBar.HighMotherInsideBar,
                    LowMotherInsideBar = chart.InsideBar.LowMotherInsideBar,
                    Symbol = chart.Symbol,
                    Side = chart.InsideBar.Side
                });
            }
            return(new InsideBarView());
        }
Example #4
0
        public async Task <ChartView> SimulateView(string symbol, string interval)
        {
            var listModel = new List <ChartWithEma>();

            var symbols = await _instrumentRepository.GetInstruments();

            var instrument = symbols.FirstOrDefault(x => x.Symbol == symbol);

            var chartTakeProfit = await _chartRepository.GetChartAsync(instrument.Symbol, interval, 150, instrument.Precision);

            var takeProfit = (decimal)Math.Round((chartTakeProfit.Quotations
                                                  .Sum(x =>
            {
                var low = x.Low * Math.Pow(10, instrument.Precision);
                var high = x.High * Math.Pow(10, instrument.Precision);
                var pipsDiff = Math.Round(Math.Abs(low - high), 1);
                return(pipsDiff / 10);
            }) / chartTakeProfit.Quotations.Count()), 2);
            var chart = await _chartRepository.GetChartAsync(instrument.Symbol, interval, 10000, instrument.Precision);

            var emaValue = 50;
            var emasH    = Indicators.EMA(chart.Quotations.Select(x => x.Close).ToArray(), emaValue);

            for (int i = 0; i < emasH.Count(); i++)
            {
                chart.Quotations[i].AddEma(emasH[i]);
            }

            var quotations = chart.Quotations.ToArray();

            var timeArray  = quotations.Select(x => x.Time.ConvertDateTimeToTicks()).ToArray();
            var openArray  = quotations.Select(x => x.Open).ToArray();
            var highArray  = quotations.Select(x => x.High).ToArray();
            var lowArray   = quotations.Select(x => x.Low).ToArray();
            var closeArray = quotations.Select(x => x.Close).ToArray();

            listModel.AddRange(quotations.Select(
                                   x => new ChartWithEma
            {
                Time  = x.Time.ConvertDateTimeToTicks(),
                Open  = x.Open,
                High  = x.High,
                Low   = x.Low,
                Close = x.Close,
            }));

            var buyTrades  = listModel.Where(x => x.TypeAction == "B").ToList();
            var sellTrades = listModel.Where(x => x.TypeAction == "S").ToList();
            var c          = CombineArrays(timeArray, openArray, highArray, lowArray, closeArray);

            var series = new List <dynamic>()
            {
                CombineArrays(timeArray, openArray, highArray, lowArray, closeArray),
                CombineArrays(timeArray, emasH),
                GetTradeSignals(buyTrades.Select(x => x.Time).ToArray(), "B"),
                GetTradeSignals(sellTrades.Select(x => x.Time).ToArray(), "S")
            };
            var chartView = new ChartView {
                Series = series
            };

            return(chartView);
        }
        protected async override void Handle(PlayGapCommand request)
        {
            if ((DateTime.Now.Hour == 8 && DateTime.Now.Minute > 56) && DateTime.Now.Hour < 9) //EU
            {
                try
                {
                    var account = await _accountRepository.GetAccountAsync("11181613");

                    var instruments = await _instrumentRepository.GetInstruments();

                    var symbolsEu     = request.SymbolsToPlay.BottomGapSymbolEu.Union(request.SymbolsToPlay.TopGapSymbolEu);
                    var instrumentsEu = instruments.Where(x => symbolsEu.Contains(x.Symbol)).ToList();
                    if (instrumentsEu.Any())
                    {
                        var chartsAsync = instrumentsEu.Select(async x => await _chartRepository.GetChartAsync(x.Symbol, "M1", 2250 * 5, x.Precision));
                        var charts      = await Task.WhenAll(chartsAsync);

                        foreach (var chart in charts)
                        {
                            var instrument  = instruments.FirstOrDefault(x => x.Symbol == chart.Symbol);
                            var gapStrategy = new GapStrategy(instrument, 1000, account);
                            gapStrategy.Play(chart);
                        }
                        _logger.LogInformation($"Play eu gap - {instrumentsEu.Aggregate("", (current, next) => current + ", " + next.Symbol)}");
                    }
                    await _mediator.DispatchDomainEventsAsync(account);

                    _logger.LogInformation($"No symbols eu to play gap");
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Error gap");
                }
            }
            if ((DateTime.Now.Hour == 15 && DateTime.Now.Minute > 26) && (DateTime.Now.Hour >= 15 && DateTime.Now.Minute > 30)) // US
            {
                try
                {
                    var account = await _accountRepository.GetAccountAsync("11181613");

                    var instruments = await _instrumentRepository.GetInstruments();

                    var symbolsEu     = request.SymbolsToPlay.BottomGapSymbolUs.Union(request.SymbolsToPlay.TopGapSymbolUs);
                    var instrumentsUs = instruments.Where(x => symbolsEu.Contains(x.Symbol)).ToList();
                    if (instrumentsUs.Any())
                    {
                        var chartsAsync = instrumentsUs.Select(async x => await _chartRepository.GetChartAsync(x.Symbol, "M1", 2250 * 5, x.Precision));
                        var charts      = await Task.WhenAll(chartsAsync);

                        foreach (var chart in charts)
                        {
                            var instrument  = instruments.FirstOrDefault(x => x.Symbol == chart.Symbol);
                            var gapStrategy = new GapStrategy(instrument, 1000, account);
                            gapStrategy.Play(chart);
                        }
                        _logger.LogInformation($"Play us gap - {instrumentsUs.Aggregate("", (current, next) => current + ", " + next.Symbol)}");
                    }
                    await _mediator.DispatchDomainEventsAsync(account);

                    _logger.LogInformation($"No symbols us to play gap");
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Error gap");
                }
            }
        }
Example #6
0
        public async Task <Chart> GetChart(string symbol, string interval, int candles)
        {
            var instrument = await _instrumentRepository.GetInstrument(symbol);

            return(await _chartRepository.GetChartAsync(symbol, interval, candles, instrument.Precision));
        }