public PbTickView Int2Double(PbTick tick) { if (tick == null) { return(null); } var field = new PbTickView(); // 利用此机会设置TickSize if (Codec == null) { Codec = new PbTickCodec(); } field.Config = Int2Double(tick.Config); Codec.Config = tick.Config; field.Turnover = Codec.GetTurnover(tick); field.AveragePrice = Codec.GetAveragePrice(tick); field.LastPrice = Codec.TickToPrice(tick.LastPrice); field.Depth1_3 = Int2Double(tick.Depth1_3); field.Volume = tick.Volume; field.OpenInterest = tick.OpenInterest; field.TradingDay = tick.TradingDay; field.ActionDay = tick.ActionDay; field.Time_HHmm = tick.Time_HHmm; field.Time_____ssf__ = tick.Time_____ssf__; field.Time________ff = tick.Time________ff; field.Bar = Int2Double(tick.Bar); field.Static = Int2Double(tick.Static); field.Split = Int2Double(tick.Split); return(field); }
public void TestGetSetPrice() { var codec = new PbTickCodec(); codec.Config.SetTickSize(0.2); PbTick tick = new PbTick(); Assert.AreEqual(0, codec.GetBidPrice(tick, 1)); Assert.AreEqual(0, codec.GetBidPrice(tick, 4)); Assert.AreEqual(0, codec.GetBidPrice(tick, 10)); codec.SetBidPrice(tick, 1, 1.0); codec.SetBidPrice(tick, 4, 2.4); codec.SetBidPrice(tick, 10, 5.8); Assert.AreEqual(1, codec.GetBidPrice(tick, 1)); Assert.AreEqual(2.4, codec.GetBidPrice(tick, 4)); Assert.AreEqual(5.8, codec.GetBidPrice(tick, 10)); Assert.AreEqual(0, codec.GetAskPrice(tick, 1)); Assert.AreEqual(0, codec.GetAskPrice(tick, 4)); Assert.AreEqual(0, codec.GetAskPrice(tick, 10)); codec.SetAskPrice(tick, 1, -1.0); codec.SetAskPrice(tick, 4, 2.4); codec.SetAskPrice(tick, 10, -5.8); Assert.AreEqual(-1.0, codec.GetAskPrice(tick, 1)); Assert.AreEqual(2.4, codec.GetAskPrice(tick, 4)); Assert.AreEqual(-5.8, codec.GetAskPrice(tick, 10)); codec.SetAskCount(tick, 1, 4); codec.SetAskCount(tick, 4, 5); codec.SetAskCount(tick, 10, -9); Assert.AreEqual<double>(4, codec.GetAskCount(tick, 1)); Assert.AreEqual<double>(5, codec.GetAskCount(tick, 4)); Assert.AreEqual<double>(-9, codec.GetAskCount(tick, 10)); codec.SetSettlementPrice(tick, 1234.56); Assert.AreEqual(1234.56, codec.GetSettlementPrice(tick), "SettlementPrice"); codec.SetTurnover(tick, 4567.8); Assert.AreEqual(4567.8, codec.GetTurnover(tick), "Turnover"); }
public void TestTickMultiplier() { PbTickCodec codec = new PbTickCodec(); codec.Config.SetTickSize(0.2); codec.TickSize = codec.Config.GetTickSize(); codec.Config.ContractMultiplier = 50000; codec.Config.Time_ssf_Diff = 5; PbTick tick1 = new PbTick(); codec.SetAveragePrice(tick1, 123.45); codec.SetSettlementPrice(tick1, 123.45); codec.SetTurnover(tick1, 1234567890123456); codec.SetOpenInterest(tick1, 9123456789012345678); codec.SetVolume(tick1, 1234567890); Assert.AreEqual(123.45, codec.GetAveragePrice(tick1)); Assert.AreEqual(123.45, codec.GetSettlementPrice(tick1)); Assert.AreEqual(1234567890120000, codec.GetTurnover(tick1)); Assert.AreEqual(9123456789012345678, codec.GetOpenInterest(tick1)); Assert.AreEqual(1234567890, codec.GetVolume(tick1)); codec.Config.ContractMultiplier = 5; codec.SetTurnover(tick1, 1234567890123456); Assert.AreEqual(1234567890123456, codec.GetTurnover(tick1)); codec.Config.ContractMultiplier = 0.1; codec.SetTurnover(tick1, 12345678901234.56); Assert.AreEqual(12345678901234.56, codec.GetTurnover(tick1)); }