public void WhenPriceGoesDownAndIsNotSustainedForLongerThan7SecondsThenDoesntTriggerStopLoss() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 0.89M }; stopLossManager.Consume(priceUpdated); var priceUpdated2 = new PriceUpdated { Price = 0.91M }; stopLossManager.Consume(priceUpdated2); var sendToMeInX = new SendToMeInX <PriceUpdated>(7.0M, priceUpdated); stopLossManager.Consume(sendToMeInX); var stopLossTriggered = bus.GetLastMessage <StopLossTriggered>(); Assert.Null(stopLossTriggered); }
static void Main() { BusConfiguration busConfiguration = new BusConfiguration(); busConfiguration.EndpointName("Samples.Gateway.Headquarters"); busConfiguration.EnableInstallers(); busConfiguration.EnableFeature <Gateway>(); busConfiguration.UsePersistence <InMemoryPersistence>(); using (IBus bus = Bus.Create(busConfiguration).Start()) { Console.WriteLine("Press 'Enter' to send a message to RemoteSite which will reply. To exit, Ctrl + C"); while (Console.ReadLine() != null) { string[] siteKeys = { "RemoteSite" }; PriceUpdated priceUpdated = new PriceUpdated { ProductId = 2, NewPrice = 100.0, ValidFrom = DateTime.Today, }; bus.SendToSites(siteKeys, priceUpdated); Console.WriteLine("Message sent, check the output in RemoteSite"); } } }
public void WhenPriceUpdatedAfterThresholdThenTargetUpdatedWithNewPriceWithoutObsoletePricesAffectingIt() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 1.0M }; stopLossManager.Consume(priceUpdated); var priceUpdated2 = new PriceUpdated { Price = 1.2M }; stopLossManager.Consume(priceUpdated2); bus.Clear(); stopLossManager.Consume(new SendToMeInX <PriceUpdated>(10.0M, priceUpdated)); stopLossManager.Consume(new SendToMeInX <PriceUpdated>(10.0M, priceUpdated2)); var targetUpdated = bus.GetLastMessage <TargetUpdated>(); Assert.NotNull(targetUpdated); Assert.Equal(targetUpdated.TargetPrice, 1.1M); }
public void AfterSellingDoesntSellAgain() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 0.89M }; stopLossManager.Consume(priceUpdated); var priceUpdated2 = new PriceUpdated { Price = 0.5M }; stopLossManager.Consume(priceUpdated); stopLossManager.Consume(new SendToMeInX <PriceUpdated>(7.0M, priceUpdated)); bus.Clear(); stopLossManager.Consume(new SendToMeInX <PriceUpdated>(7.0M, priceUpdated2)); var stopLossTriggered = bus.GetLastMessage <StopLossTriggered>(); Assert.Null(stopLossTriggered); }
public void WhenPriceNotSustainedForLongerThan10SecondsThenTargetNotUpdated() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 0.8M }; stopLossManager.Consume(priceUpdated); bus.Clear(); priceUpdated = new PriceUpdated { Price = 1.5M }; var sendToMeInX = new SendToMeInX <PriceUpdated>(10.0M, priceUpdated); stopLossManager.Consume(sendToMeInX); var targetUpdated = bus.GetLastMessage <TargetUpdated>(); Assert.Null(targetUpdated); }
public void WhenPriceUpdatedWithinTenSecondsThenRaisesTwoSendInX() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 1.5M }; stopLossManager.Consume(priceUpdated); var events = bus.GetMessages().OfType <SendToMeInX <PriceUpdated> >().ToArray(); Assert.Equal(events.Length, 2); var sendToMeInX1 = events.First(); var sendToMeInX2 = events.Last(); Assert.NotNull(sendToMeInX1); Assert.Equal(sendToMeInX1.Message, priceUpdated); Assert.Equal(sendToMeInX1.X, 10.0M); Assert.NotNull(sendToMeInX2); Assert.Equal(sendToMeInX2.Message, priceUpdated); Assert.Equal(sendToMeInX2.X, 7.0M); }
public void WhenPriceGoesUpAndThenDownThenTakesTheMinimumSustainedIncrease() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 1.5M }; stopLossManager.Consume(priceUpdated); priceUpdated = new PriceUpdated { Price = 1.2M }; stopLossManager.Consume(priceUpdated); bus.Clear(); priceUpdated = new PriceUpdated { Price = 1.5M }; var sendToMeInX = new SendToMeInX <PriceUpdated>(10.0M, priceUpdated); stopLossManager.Consume(sendToMeInX); var targetUpdated = bus.GetLastMessage <TargetUpdated>(); Assert.NotNull(targetUpdated); Assert.Equal(targetUpdated.TargetPrice, 1.1M); }
private void PriceAction(long timeStamp, double closingPrice) { double closingPricePoint = closingPrice / _pricePoint; if (_lastClosingPrice == 0) { _lastClosingPrice = closingPrice; _lastClosingPricePoint = closingPricePoint; } else { double pricePointDelta = closingPricePoint - _lastClosingPricePoint; if (Math.Abs(pricePointDelta) + 1 >= _brickValue) { UpdatePool(timeStamp, _lastClosingPrice, closingPrice); _lastClosingPrice = closingPrice; _lastClosingPricePoint = closingPricePoint; } } BarUpdated?.Invoke(Current); PriceUpdated?.Invoke(Current.Timestamp, RenkoPriceOption.Low, Current.Close); }
public void Write(long timeStamp, double open, double high, double low, double close, double volume = 0) { var priceBar = (PriceBar)NextPoolItem; priceBar.Write(timeStamp, open, high, low, close, volume); MoveNext(); BarUpdated?.Invoke(Current); PriceUpdated?.Invoke(Current.Timestamp, PriceBarOption.Close, Current.Close); }
static async Task AsyncMain() { Console.Title = "Samples.Gateway.Headquarters"; var endpointConfiguration = new EndpointConfiguration("Samples.Gateway.Headquarters"); endpointConfiguration.EnableInstallers(); endpointConfiguration.EnableFeature <Gateway>(); endpointConfiguration.UsePersistence <InMemoryPersistence>(); endpointConfiguration.SendFailedMessagesTo("error"); var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); try { Console.WriteLine("Press 'Enter' to send a message to RemoteSite which will reply."); Console.WriteLine("Press any other key to exit"); while (true) { var key = Console.ReadKey(); Console.WriteLine(); if (key.Key != ConsoleKey.Enter) { return; } string[] siteKeys = { "RemoteSite" }; var priceUpdated = new PriceUpdated { ProductId = 2, NewPrice = 100.0, ValidFrom = DateTime.Today, }; await endpointInstance.SendToSites(siteKeys, priceUpdated) .ConfigureAwait(false); Console.WriteLine("Message sent, check the output in RemoteSite"); } } finally { await endpointInstance.Stop() .ConfigureAwait(false); } }
private void OnCompleted() { TraderState.Budget.Profit = TraderState.Trades.Sum(t => t.Profit); foreach (var trade in TraderState.Trades) { Log($"{TraderState.Trades.IndexOf(trade)}\t{trade.Status}\t{trade.Profit}"); } Log($"Profit: {TraderState.Budget.Profit}"); Log($"Available: {TraderState.Budget.Available}"); Log($"Invested: {TraderState.Budget.Invested}"); Log($"Earned: {TraderState.Budget.Earned}"); PriceUpdated.OnCompleted(); _taskCompletionSource.SetResult(TraderState.Budget); }
public void WhenPriceSustainedForLongerThan10SecondsThenTargetUpdated() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 1.5M }; stopLossManager.Consume(priceUpdated); var sendToMeInX = new SendToMeInX<PriceUpdated>(10.0M, priceUpdated); stopLossManager.Consume(sendToMeInX); var targetUpdated = bus.GetLastMessage<TargetUpdated>(); Assert.That(targetUpdated, Is.Not.Null); Assert.That(targetUpdated.TargetPrice, Is.EqualTo(1.4M)); }
public async Task Handle(UpdatePrice message, IMessageHandlerContext context) { Console.WriteLine("Price update request received from the webclient, going to push it to RemoteSite"); string[] siteKeys = { "RemoteSite", }; PriceUpdated priceUpdated = new PriceUpdated { ProductId = message.ProductId, NewPrice = message.NewPrice, ValidFrom = message.ValidFrom, }; await context.SendToSites(siteKeys, priceUpdated); }
void _tick_Elapsed(object sender, ElapsedEventArgs e) { _tick.Stop(); foreach (var securityID in _prices.Keys.ToList()) { decimal change = (decimal)1 + _stockMovement.Next(-30, 30) * (decimal).0001; _prices[securityID] = _prices[securityID] * change; if (null != PriceUpdated) { PriceUpdated.Invoke(securityID, _prices[securityID]); } } _tick.Start(); }
static async Task AsyncMain() { Console.Title = "Samples.Gateway.Headquarters"; var endpointConfiguration = new EndpointConfiguration("Samples.Gateway.Headquarters"); endpointConfiguration.EnableInstallers(); endpointConfiguration.EnableFeature<Gateway>(); endpointConfiguration.UsePersistence<InMemoryPersistence>(); endpointConfiguration.SendFailedMessagesTo("error"); var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); try { Console.WriteLine("Press 'Enter' to send a message to RemoteSite which will reply."); Console.WriteLine("Press any other key to exit"); while (true) { var key = Console.ReadKey(); Console.WriteLine(); if (key.Key != ConsoleKey.Enter) { return; } string[] siteKeys = { "RemoteSite" }; var priceUpdated = new PriceUpdated { ProductId = 2, NewPrice = 100.0, ValidFrom = DateTime.Today, }; await endpointInstance.SendToSites(siteKeys, priceUpdated) .ConfigureAwait(false); Console.WriteLine("Message sent, check the output in RemoteSite"); } } finally { await endpointInstance.Stop() .ConfigureAwait(false); } }
static async Task Main() { Console.Title = "Samples.Gateway.Headquarters"; var endpointConfiguration = new EndpointConfiguration("Samples.Gateway.Headquarters"); endpointConfiguration.EnableInstallers(); endpointConfiguration.UsePersistence <InMemoryPersistence>(); endpointConfiguration.UseTransport <LearningTransport>(); #region HeadquartersGatewayConfig var gatewayConfig = endpointConfiguration.Gateway(); gatewayConfig.AddReceiveChannel("http://localhost:25899/Headquarters/"); gatewayConfig.AddSite("RemoteSite", "http://localhost:25899/RemoteSite/"); #endregion var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); Console.WriteLine("Press 'Enter' to send a message to RemoteSite which will reply."); Console.WriteLine("Press any other key to exit"); while (true) { var key = Console.ReadKey(); Console.WriteLine(); if (key.Key != ConsoleKey.Enter) { break; } string[] siteKeys = { "RemoteSite" }; var priceUpdated = new PriceUpdated { ProductId = 2, NewPrice = 100.0, ValidFrom = DateTime.Today, }; await endpointInstance.SendToSites(siteKeys, priceUpdated) .ConfigureAwait(false); Console.WriteLine("Message sent, check the output in RemoteSite"); } await endpointInstance.Stop() .ConfigureAwait(false); }
public void Handle(UpdatePrice message) { log.Info("Price update received from the webclient, going to push to RemoteSite"); string[] siteKeys = { "RemoteSite" }; var priceUpdated = new PriceUpdated { ProductId = message.ProductId, NewPrice = message.NewPrice, ValidFrom = message.ValidFrom, }; bus.SendToSites(siteKeys, priceUpdated); }
public void Handle(PriceUpdated message) { _possibleStopLossPrices.Add(message.Price); _currentPrices.Add(message.Price); _publisher.Publish(new SendMessageIn { MessageToSend = new PriceExpiredFromStopLossWindow { Price = message.Price } }); _publisher.Publish(new SendMessageIn { MessageToSend = new PriceExpiredFromStopLossHitWindow { Price = message.Price } }); }
public void Handle(PriceUpdated message) { _price10SecondWindow.Add(message.Price); _price13SecondWindow.Add(message.Price); _publisher.Publish(new SendToMeIn { DelayInSeconds = 10, Inner = new RemoveFrom10SecondWindow() { Price = message.Price } }); _publisher.Publish(new SendToMeIn { DelayInSeconds = 13, Inner = new RemoveFrom13SecondWindow { Price = message.Price } }); }
public void Handle(UpdatePrice message) { Console.WriteLine("Price update request received from the webclient, going to push it to RemoteSite"); string[] siteKeys = { "RemoteSite", }; PriceUpdated priceUpdated = new PriceUpdated { ProductId = message.ProductId, NewPrice = message.NewPrice, ValidFrom = message.ValidFrom, }; bus.SendToSites(siteKeys, priceUpdated); }
public Task Handle(UpdatePrice message, IMessageHandlerContext context) { log.Info("Price update request received from the webclient, going to push it to RemoteSite"); string[] siteKeys = { "RemoteSite" }; var priceUpdated = new PriceUpdated { ProductId = message.ProductId, NewPrice = message.NewPrice, ValidFrom = message.ValidFrom, }; return(context.SendToSites(siteKeys, priceUpdated)); }
public void Write(long timeStamp, double open, double high, double low, double close) { var ohlcBar = (OHLCBar)NextPoolItem; ohlcBar.Write(timeStamp, open, high, low, close); MoveNext(); if (_persistenceWriter != null) { _persistenceWriter.Append(ohlcBar.ToByteArray()); } BarUpdated?.Invoke(Current); PriceUpdated?.Invoke(Current.Timestamp, OHLCPriceOption.Close, Current.Close); }
static void Main() { Console.Title = "Samples.Gateway.Headquarters"; Configure configure = Configure.With(); configure.Log4Net(); configure.DefineEndpointName("Samples.Gateway.Headquarters"); configure.DefaultBuilder(); configure.RunGatewayWithInMemoryPersistence(); configure.UseInMemoryGatewayDeduplication(); configure.InMemorySagaPersister(); configure.UseInMemoryTimeoutPersister(); configure.InMemorySubscriptionStorage(); configure.UseTransport <Msmq>(); using (IStartableBus startableBus = configure.UnicastBus().CreateBus()) { IBus bus = startableBus .Start(() => configure.ForInstallationOn <Windows>().Install()); Console.WriteLine("Press 'Enter' to send a message to RemoteSite which will reply."); Console.WriteLine("Press any other key to exit"); while (true) { ConsoleKeyInfo key = Console.ReadKey(); Console.WriteLine(); if (key.Key != ConsoleKey.Enter) { return; } string[] siteKeys = { "RemoteSite" }; PriceUpdated priceUpdated = new PriceUpdated { ProductId = 2, NewPrice = 100.0, ValidFrom = DateTime.Today, }; bus.SendToSites(siteKeys, priceUpdated); Console.WriteLine("Message sent, check the output in RemoteSite"); } } }
static void Main() { Console.Title = "Samples.Gateway.Headquarters"; Configure configure = Configure.With(); configure.Log4Net(); configure.DefineEndpointName("Samples.Gateway.Headquarters"); configure.DefaultBuilder(); configure.RunGatewayWithInMemoryPersistence(); configure.UseInMemoryGatewayDeduplication(); configure.InMemorySagaPersister(); configure.UseInMemoryTimeoutPersister(); configure.InMemorySubscriptionStorage(); configure.UseTransport<Msmq>(); using (IStartableBus startableBus = configure.UnicastBus().CreateBus()) { IBus bus = startableBus .Start(() => configure.ForInstallationOn<Windows>().Install()); Console.WriteLine("Press 'Enter' to send a message to RemoteSite which will reply."); Console.WriteLine("Press any other key to exit"); while (true) { ConsoleKeyInfo key = Console.ReadKey(); Console.WriteLine(); if (key.Key != ConsoleKey.Enter) { return; } string[] siteKeys = { "RemoteSite" }; PriceUpdated priceUpdated = new PriceUpdated { ProductId = 2, NewPrice = 100.0, ValidFrom = DateTime.Today, }; bus.SendToSites(siteKeys, priceUpdated); Console.WriteLine("Message sent, check the output in RemoteSite"); } } }
public void WhenPriceSustainedForLongerThan10SecondsThenTargetUpdated() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 1.5M }; stopLossManager.Consume(priceUpdated); var sendToMeInX = new SendToMeInX <PriceUpdated>(10.0M, priceUpdated); stopLossManager.Consume(sendToMeInX); var targetUpdated = bus.GetLastMessage <TargetUpdated>(); Assert.That(targetUpdated, Is.Not.Null); Assert.That(targetUpdated.TargetPrice, Is.EqualTo(1.4M)); }
private void OnCompleted() { TraderState.Budget.Profit = TraderState.Trades.Sum(t => t.Profit); foreach (var trade in TraderState.Trades.OrderByDescending(t => t.Profit)) { Log($"{TraderState.Trades.IndexOf(trade)}" + $"\t{trade.Status}" + $"\t{trade.Profit}" + $"\t{trade.BuyReason}" + $"\t{trade.BuyOrder.PricePerUnit}" + $"\t{trade.SellReason}" + $"\t{trade.SellOrder.PricePerUnit}"); } Log($"Profit: {TraderState.Budget.Profit}"); Log($"Available: {TraderState.Budget.Available}"); Log($"Invested: {TraderState.Budget.Invested}"); Log($"Earned: {TraderState.Budget.Earned}"); PriceUpdated.OnCompleted(); _taskCompletionSource.SetResult(TraderState.Budget); }
static void Main() { Console.Title = "Samples.Gateway.Headquarters"; var busConfiguration = new BusConfiguration(); busConfiguration.EndpointName("Samples.Gateway.Headquarters"); busConfiguration.EnableInstallers(); busConfiguration.EnableFeature <Gateway>(); busConfiguration.UsePersistence <InMemoryPersistence>(); using (var bus = Bus.Create(busConfiguration).Start()) { Console.WriteLine("Press 'Enter' to send a message to RemoteSite which will reply."); Console.WriteLine("Press any other key to exit"); while (true) { var key = Console.ReadKey(); Console.WriteLine(); if (key.Key != ConsoleKey.Enter) { return; } string[] siteKeys = { "RemoteSite" }; var priceUpdated = new PriceUpdated { ProductId = 2, NewPrice = 100.0, ValidFrom = DateTime.Today, }; bus.SendToSites(siteKeys, priceUpdated); Console.WriteLine("Message sent, check the output in RemoteSite"); } } }
public void GivenPriceUpdated_ThenRemoveIn10SecondsIsPublished() { var publisher = new FakeMessagePublisher(); var sut = new StopLossProcessManager(publisher); sut.Handle(new PositionAcquired { Price = 100 }); publisher.Clear(); var priceUpdated = new PriceUpdated { Price = 95 }; sut.Handle(priceUpdated); var message = publisher.FindSendMeInMessage <PriceExpiredFromStopLossWindow>(); Assert.That(message != null); //Assert.That(message.DelayInSeconds == 10); }
public void GivenPriceUpdated_ThenRemoveIn10SecondsIsPublished() { var publisher = new FakePublisher(); var sut = new StopLossProcessManager(publisher); sut.Handle(new PositionAcquired { Price = 100 }); publisher.PublishedMessages.Clear(); var priceUpdated = new PriceUpdated { Price = 95 }; sut.Handle(priceUpdated); var message = (SendToMeIn)publisher.PublishedMessages.First(); Assert.IsInstanceOf <RemoveFrom10SecondWindow>(message.Inner); Assert.That(message.DelayInSeconds == 10); }
public async Task <Unit> UpdatePrice(Ticker ticker) { if (IsInTestMode) { (_cryptoApi as FakeBittrexApi)?.UpdateBuyOrders(Ticker); } Ticker = ticker; if (ticker.Timestamp == default) { ticker.Timestamp = DateTime.UtcNow; } await UpdateTrades(); if (IsInTestMode) { (_cryptoApi as FakeBittrexApi)?.UpdateSellOrders(Ticker); } PriceUpdated.OnNext(ticker); return(Unit.Default); }
public void WhenPriceUpdatedWithinTenSecondsThenRaisesTwoSendInX() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated {Price = 1.5M}; stopLossManager.Consume(priceUpdated); var events = bus.GetMessages().OfType<SendToMeInX<PriceUpdated>>().ToArray(); Assert.That(events, Has.Length.EqualTo(2)); var sendToMeInX1 = events.First(); var sendToMeInX2 = events.Last(); Assert.That(sendToMeInX1, Is.Not.Null); Assert.That(sendToMeInX1.Message, Is.EqualTo(priceUpdated)); Assert.That(sendToMeInX1.X, Is.EqualTo(10.0M)); Assert.That(sendToMeInX2, Is.Not.Null); Assert.That(sendToMeInX2.Message, Is.EqualTo(priceUpdated)); Assert.That(sendToMeInX2.X, Is.EqualTo(7.0M)); }
static void Main() { Console.Title = "Samples.Gateway.Headquarters"; BusConfiguration busConfiguration = new BusConfiguration(); busConfiguration.EndpointName("Samples.Gateway.Headquarters"); busConfiguration.EnableInstallers(); busConfiguration.EnableFeature<Gateway>(); busConfiguration.UsePersistence<InMemoryPersistence>(); using (IBus bus = Bus.Create(busConfiguration).Start()) { Console.WriteLine("Press 'Enter' to send a message to RemoteSite which will reply."); Console.WriteLine("Press any other key to exit"); while (true) { ConsoleKeyInfo key = Console.ReadKey(); Console.WriteLine(); if (key.Key != ConsoleKey.Enter) { return; } string[] siteKeys = { "RemoteSite" }; PriceUpdated priceUpdated = new PriceUpdated { ProductId = 2, NewPrice = 100.0, ValidFrom = DateTime.Today, }; bus.SendToSites(siteKeys, priceUpdated); Console.WriteLine("Message sent, check the output in RemoteSite"); } } }
public void GivenPriceUodated_WhenRemovingIn10Seconds_ThenStopLossPriceUpdated() { var publisher = new FakePublisher(); var sut = new StopLossProcessManager(publisher); sut.Handle(new PositionAcquired { Price = 100 }); var priceUpdated = new PriceUpdated { Price = 101 }; sut.Handle(priceUpdated); publisher.PublishedMessages.Clear(); sut.Handle(new RemoveFrom10SecondWindow { Price = 100 }); StopLossPriceUpdated actual = publisher.FindMessage <StopLossPriceUpdated>(); Assert.AreEqual(91, actual.Price); }
public void Write(long timeStamp, double open, double high, double low, double close) { var CandlestickBar = (CandlestickBar)NextPoolItem; if (open > close) { CandlestickBar.Write(timeStamp, open, high, low, close, open - close, high - open, close - low, false); } else { CandlestickBar.Write(timeStamp, open, high, low, close, close - open, high - close, open - low, true); } MoveNext(); if (_persistenceWriter != null) { _persistenceWriter.Append(CandlestickBar.ToByteArray()); } BarUpdated?.Invoke(Current); PriceUpdated?.Invoke(Current.Timestamp, CandlestickPriceOption.Close, Current.Close); }
private void NotifyUpdate() { BarUpdated?.Invoke(Current); PriceUpdated?.Invoke(Current.Timestamp, HeikenAshiPriceOption.Close, Current.Close); }
public void WhenPriceGoesUpAndThenDownThenTakesTheMinimumSustainedIncrease() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 1.5M }; stopLossManager.Consume(priceUpdated); priceUpdated = new PriceUpdated { Price = 1.2M }; stopLossManager.Consume(priceUpdated); bus.Clear(); priceUpdated = new PriceUpdated { Price = 1.5M }; var sendToMeInX = new SendToMeInX<PriceUpdated>(10.0M, priceUpdated); stopLossManager.Consume(sendToMeInX); var targetUpdated = bus.GetLastMessage<TargetUpdated>(); Assert.That(targetUpdated, Is.Not.Null); Assert.That(targetUpdated.TargetPrice, Is.EqualTo(1.1M)); }
public void WhenPriceGoesDownAndIsNotSustainedForLongerThan7SecondsThenDoesntTriggerStopLoss() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 0.89M }; stopLossManager.Consume(priceUpdated); var priceUpdated2 = new PriceUpdated { Price = 0.91M }; stopLossManager.Consume(priceUpdated2); var sendToMeInX = new SendToMeInX<PriceUpdated>(7.0M, priceUpdated); stopLossManager.Consume(sendToMeInX); var stopLossTriggered = bus.GetLastMessage<StopLossTriggered>(); Assert.That(stopLossTriggered, Is.Null); }
public void WhenPriceUpdatedAfterThresholdThenTargetUpdatedWithNewPriceWithoutObsoletePricesAffectingIt() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 1.0M }; stopLossManager.Consume(priceUpdated); var priceUpdated2 = new PriceUpdated { Price = 1.2M }; stopLossManager.Consume(priceUpdated2); bus.Clear(); stopLossManager.Consume(new SendToMeInX<PriceUpdated>(10.0M, priceUpdated)); stopLossManager.Consume(new SendToMeInX<PriceUpdated>(10.0M, priceUpdated2)); var targetUpdated = bus.GetLastMessage<TargetUpdated>(); Assert.That(targetUpdated, Is.Not.Null); Assert.That(targetUpdated.TargetPrice, Is.EqualTo(1.1M)); }
public void AfterSellingDoesntSellAgain() { var positionAcquired = new PositionAcquired(1.0M); stopLossManager.Consume(positionAcquired); var priceUpdated = new PriceUpdated { Price = 0.89M }; stopLossManager.Consume(priceUpdated); var priceUpdated2 = new PriceUpdated { Price = 0.5M }; stopLossManager.Consume(priceUpdated); stopLossManager.Consume(new SendToMeInX<PriceUpdated>(7.0M, priceUpdated)); bus.Clear(); stopLossManager.Consume(new SendToMeInX<PriceUpdated>(7.0M, priceUpdated2)); var stopLossTriggered = bus.GetLastMessage<StopLossTriggered>(); Assert.That(stopLossTriggered, Is.Null); }