public void Handle(TenSecondsPassed tenSecondsPassed) { var wasRemoved = LastTenSecondsPrices.Remove(tenSecondsPassed.Price); if (!wasRemoved) { throw new InvalidOperationException(); } var minPrice = new[] { tenSecondsPassed.Price }.Concat(LastTenSecondsPrices).Min(); if (StopLossRatio * minPrice > CurrentStopLossPrice) { UpdateStopLossPrice(StopLossRatio * CurrentPricePerItem); } }
public void Handle(PriceUpdated priceUpdated) { CurrentPricePerItem = priceUpdated.NewPricePerItem; var price = priceUpdated.NewPricePerItem; LastTenSecondsPrices.Add(price); LastThirteenSecondsPrices.Add(price); _bus.Fire(new SendBackIn(TimeSpan.FromSeconds(10), new TenSecondsPassed { Price = price })); _bus.Fire(new SendBackIn(TimeSpan.FromSeconds(13), new ThirteenSecondsPassed { Price = price })); }