protected override Task CheckStrategies() { // TODO: Check registered strategies. StrategyController strategyController = new StrategyController(); Dictionary <string, double> prevPrice = new Dictionary <string, double>(); var reutberg = new Reutberg.ReutbergService(); foreach (var strategy in strategyController.getStrategies()) { string ticker = strategy.Value.Ticker; double newQuote = (double)reutberg.GetQuote(ticker); if (!prevPrice.ContainsKey(ticker)) { prevPrice[ticker] = newQuote; } else if ((newQuote / prevPrice[ticker]) == ((100.0 + (double)strategy.Value.PriceMovement) / 100.0)) { if (strategy.Value.Instruction == BuySell.Buy) { reutberg.Buy(ticker, strategy.Value.Quantity); strategyController.UnregisterStrategy(strategy.Key); } else if (strategy.Value.Instruction == BuySell.Sell) { reutberg.Sell(ticker, strategy.Value.Quantity); strategyController.UnregisterStrategy(strategy.Key); } } } return(Task.CompletedTask); }
public void UnregisterStrategyTest2() { StrategyDetailsDto strategyDetails = new StrategyDetailsDto(); strategyDetails.Instruction = TradingPlaces.Resources.BuySell.Sell; strategyDetails.PriceMovement = 2; strategyDetails.Quantity = 10; strategyDetails.Ticker = "MSBT"; StrategyController strategyController = new StrategyController(); var mockDependency = new Mock <StrategyController>(); CreatedResult result = new CreatedResult("12345678", strategyDetails); mockDependency.Setup(x => x.RegisterStrategy(strategyDetails)).Returns(result); string id = "12345678"; var result2 = strategyController.UnregisterStrategy(id); var okResult = result2 as OkObjectResult; Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); }