private static async Task AutoTradeStocks(IAlpacaClient alpacaClient, StockConfig stockConfig, MLConfig mlConfig) { if ((stockConfig.Stock_List?.Count ?? 0) == 0) { throw new ArgumentException("You must pass an least one valid stock symbol", nameof(stockConfig)); } var strategies = new List <Strategy>() { new MeanReversionStrategy(alpacaClient), new MLStrategy(alpacaClient, mlConfig), new MicrotrendStrategy(alpacaClient), //new NewsStrategy(alpacaClient, config.Get<NewsSearchConfig>()), }; var strategy = strategies .SingleOrDefault(x => string.Equals(x.GetType().Name, stockConfig.Stock_Strategy, StringComparison.OrdinalIgnoreCase)); if (strategy == null) { throw new ArgumentException($"Could not find any strategies with the name '{stockConfig.Stock_Strategy}'", nameof(stockConfig)); } if (!await alpacaClient.ConnectStreamApi()) { throw new UnauthorizedAccessException("Failed to connect to streaming API. Authorization failed."); } foreach (var stockSymbol in stockConfig.Stock_List) { var stockData = await alpacaClient.GetStockData(stockSymbol); if ((stockData?.Count ?? 0) == 0) { throw new ArgumentException($"You stock symbol {stockSymbol} is not valid.", nameof(stockConfig)); } strategy.HistoricalData = stockData; alpacaClient.SubscribeMinuteAgg(stockSymbol, async y => await strategy.HandleMinuteAgg(y)); } }
public MLStrategy(IAlpacaClient client, MLConfig config) : base(client) { _config = config; }
public ModelBuilder(MLConfig config) { _config = config; }
public MLStrategy(MLConfig config) { _config = config; }