예제 #1
0
        private Trader GetTrader(Strategy strategy, ApplicationUser user)
        {
            var stockDataReader = _stockDataReaderManager.GetStockDataReader(user.Id, strategy.Stock);
            var tradingClient   = _tradingClientFactory.GetTradingClient(user);

            switch (strategy)
            {
            case RangeStrategy _:
                return(new RangeTrader(stockDataReader, tradingClient, _serviceProvider, user, strategy, _logger,
                                       _signalRService));

            case PercentStrategy _:
                return(new PercentTrader(stockDataReader, tradingClient, _serviceProvider, user, strategy, _logger,
                                         _signalRService));

            default:
                throw new Exception($"unknown exception: {strategy.GetType()}");
            }
        }
예제 #2
0
        static async Task Main(string[] args)
        {
            try
            {
                var stocks       = new[] { "qqq", "msft", "fb", "aapl" };
                var task         = new List <Task>();
                var alpacaClient = TradingClientFactory.GetTradingClient(TradingClientType.Alpaca);
                foreach (var stock in stocks)
                {
                    var trader = new Trader(StockDataReaderFactory.GetStockDataReader(StockDataReaderType.Yahoo, stock),
                                            alpacaClient, stock);

                    task.Add(Task.Run(() => trader.HandleOrders()));
                }

                await Task.WhenAll(task.ToArray());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            /*var stocks = new[] {"qqq", "msft", "fb", "aapl"};
             * var task = new List<Task>();
             * foreach (var stock in stocks)
             * {
             *  task.Add(Task.Run(() => ScrapperFactory.GetScrapper(ScrapperType.Yahoo, stock).ReadStocksValue()));
             * }
             *
             * await Task.WhenAll(task.ToArray());*/

            /*var watch = System.Diagnostics.Stopwatch.StartNew();
             *
             * Console.WriteLine($"Profit is  {Test()}");
             * watch.Stop();
             * var elapsedMs = watch.ElapsedMilliseconds;
             * Console.WriteLine($"time: { elapsedMs}");*/
        }