public void CalculateSpreadOnQuotesUpdate(string symbol) { if (!arbitrageSettings.HasSymbol(symbol)) { return; } double buySpreadPrice = new BuySpreadFactory(this.arbitrageSettings.LeftLeg, this.arbitrageSettings.RightLeg, this.orderBook).Make(); double sellSpreadPrice = new SellSpreadFactory(this.arbitrageSettings.LeftLeg, this.arbitrageSettings.RightLeg, this.orderBook).Make(); if (buySpreadPrice == 0 || sellSpreadPrice == 0) { return; } SpreadValue lastSpread = GetLastSpreadValue(); if (lastSpread != null && lastSpread.BuyBeforePrice == buySpreadPrice && lastSpread.SellAfterPrice == sellSpreadPrice) { return; } SpreadValue spreadValue = new SpreadValue(arbitrageSettings.Id, BrokerDateTime.Make(DateTime.Now), sellSpreadPrice, buySpreadPrice); this.logger.Log(String.Format("{0:dd/MM/yyyy H:mm:ss.fff}, {1}, выполнено вычисление нового значения {2}.", DateTime.Now, this.GetType().Name, spreadValue.ToString())); this.tradingData.Get <ObservableCollection <SpreadValue> >().Add(spreadValue); }
public void SpreadValue_constructor_test() { int id = 1; DateTime dt = new DateTime(2199, 12, 1); double sellAfterPrice = 1.3385; double buyBeforePrice = 1.3385; SpreadValue sv = new SpreadValue(id, dt, sellAfterPrice, buyBeforePrice); Assert.AreEqual(id, sv.Id); Assert.AreEqual(dt, sv.DateTime); Assert.AreEqual(sellAfterPrice, sv.SellAfterPrice); Assert.AreEqual(buyBeforePrice, sv.BuyBeforePrice); }
public void SpreadValue_ToString_test() { CultureInfo ci = CultureInfo.InvariantCulture; DateTime date = DateTime.Now; SpreadValue sp = new SpreadValue(1, date, 1.255, 1.188); string expected = String.Format("SpreadValue: {0},{1:dd/MM/yyyy H:mm:ss.fff},{2},{3}", sp.Id, sp.DateTime, sp.SellAfterPrice.ToString("0.0000", ci), sp.BuyBeforePrice.ToString("0.0000", ci)); Assert.AreEqual(expected, sp.ToString()); }
public void CalculateSpreadOnOrderBookChange_calculate_spread_test() { Assert.IsFalse(this.tradingData.Get <IEnumerable <SpreadValue> >().Any(s => s.Id == this.arbitrageSettings.Id)); this.orderBook.Update(0, this.leftStrategy.Symbol, 5, 10, 6, 10); Assert.IsFalse(this.tradingData.Get <IEnumerable <SpreadValue> >().Any(s => s.Id == this.arbitrageSettings.Id)); this.orderBook.Update(0, this.rightStrategy.Symbol, 4, 10, 5, 10); Assert.IsTrue(this.tradingData.Get <IEnumerable <SpreadValue> >().Any(s => s.Id == this.arbitrageSettings.Id)); SpreadValue spreadValue = this.tradingData.Get <IEnumerable <SpreadValue> >().Last(); Assert.AreEqual(this.arbitrageSettings.Id, spreadValue.Id); Assert.AreEqual(1.5, spreadValue.BuyBeforePrice); Assert.AreEqual(1, spreadValue.SellAfterPrice); }
public string ToConsole() { var spread = SpreadType == SpreadType.Percentage ? SpreadPercentage.ToString("p2") : SpreadValue.ToString("f2"); var message = $"{FromExchangeName}-{ToExchangeName} \t {RunningStatus} \t Volume! Maximum:{MaximumVolume:f2} Minimum:{MinimumVolume} Per:{PerVolume:f2} \t Available:{AvailabeVolume:f2} \t Spread:{spread} "; return(message); }