public void Threshold_Is_Not_Exceeded_And_Start_Time_Expired() { // arrange var interval = TimeSpan.FromSeconds(1); var threshold = 100; var markup = 0.002m; var negativePnL = -10; var pnLStopLossEngine = new PnLStopLossEngine { Id = Guid.NewGuid().ToString(), Mode = PnLStopLossEngineMode.Idle, Interval = interval, Threshold = threshold, Markup = markup }; // act pnLStopLossEngine.AddNegativePnL(negativePnL); pnLStopLossEngine.Refresh(); Thread.Sleep(900); pnLStopLossEngine.AddNegativePnL(negativePnL); pnLStopLossEngine.Refresh(); // assert Assert.IsFalse(string.IsNullOrWhiteSpace(pnLStopLossEngine.Id)); Assert.AreEqual(pnLStopLossEngine.Interval, interval); Assert.AreEqual(pnLStopLossEngine.Threshold, threshold); Assert.AreEqual(pnLStopLossEngine.Markup, markup); Assert.AreEqual(pnLStopLossEngine.Mode, PnLStopLossEngineMode.Idle); Assert.AreEqual(pnLStopLossEngine.TotalNegativePnL, negativePnL * 2); Assert.IsNotNull(pnLStopLossEngine.StartTime); Assert.IsNotNull(pnLStopLossEngine.LastTime); // act again Thread.Sleep(100); pnLStopLossEngine.Refresh(); // assert again Assert.IsFalse(string.IsNullOrWhiteSpace(pnLStopLossEngine.Id)); Assert.AreEqual(pnLStopLossEngine.Interval, interval); Assert.AreEqual(pnLStopLossEngine.Threshold, threshold); Assert.AreEqual(pnLStopLossEngine.Markup, markup); Assert.AreEqual(pnLStopLossEngine.Mode, PnLStopLossEngineMode.Idle); Assert.AreEqual(pnLStopLossEngine.TotalNegativePnL, 0); Assert.IsNull(pnLStopLossEngine.StartTime); Assert.IsNull(pnLStopLossEngine.LastTime); }
public void Initialized_And_Refreshed_Without_Negative_PnL() { // arrange var interval = TimeSpan.FromSeconds(1); var threshold = 100; var markup = 0.002m; var pnLStopLossEngine = new PnLStopLossEngine { Id = Guid.NewGuid().ToString(), Mode = PnLStopLossEngineMode.Idle, Interval = interval, Threshold = threshold, Markup = markup }; // act pnLStopLossEngine.Refresh(); // assert Assert.IsFalse(string.IsNullOrWhiteSpace(pnLStopLossEngine.Id)); Assert.AreEqual(pnLStopLossEngine.Interval, interval); Assert.AreEqual(pnLStopLossEngine.Threshold, threshold); Assert.AreEqual(pnLStopLossEngine.Markup, markup); Assert.AreEqual(pnLStopLossEngine.Mode, PnLStopLossEngineMode.Idle); Assert.AreEqual(pnLStopLossEngine.TotalNegativePnL, 0); Assert.IsNull(pnLStopLossEngine.StartTime); Assert.IsNull(pnLStopLossEngine.LastTime); }
private async Task Refresh(PnLStopLossEngine pnLStopLossEngine) { var isUpdated = pnLStopLossEngine.Refresh(); if (isUpdated) { await UpdateAsync(pnLStopLossEngine); } }