From aba9f136da6f8fec9fa5ed55d7e48bc6787e1d0f Mon Sep 17 00:00:00 2001 From: Jhonathan Abreu Date: Wed, 8 Jan 2025 11:31:42 -0400 Subject: [PATCH] Fix: use universe data for market data in FuturesContract --- Common/Data/Market/FuturesContract.cs | 45 ++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/Common/Data/Market/FuturesContract.cs b/Common/Data/Market/FuturesContract.cs index 81957d95124e..8bf0e11bfbaa 100644 --- a/Common/Data/Market/FuturesContract.cs +++ b/Common/Data/Market/FuturesContract.cs @@ -22,6 +22,7 @@ namespace QuantConnect.Data.Market /// public class FuturesContract : BaseContract { + private FutureUniverse _universeData; private TradeBar _tradeBar; private QuoteBar _quoteBar; private Tick _tradeTick; @@ -31,7 +32,18 @@ public class FuturesContract : BaseContract /// /// Gets the open interest /// - public override decimal OpenInterest => _openInterest?.Value ?? decimal.Zero; + public override decimal OpenInterest + { + get + { + // Contract universe data is prioritized + if (_universeData != null) + { + return _universeData.OpenInterest; + } + return _openInterest?.Value ?? decimal.Zero; + } + } /// /// Gets the last price this contract traded at @@ -40,6 +52,11 @@ public override decimal LastPrice { get { + if (_universeData != null) + { + return _universeData.Close; + } + if (_tradeBar == null && _tradeTick == null) { return decimal.Zero; @@ -55,7 +72,17 @@ public override decimal LastPrice /// /// Gets the last volume this contract traded at /// - public override long Volume => (long)(_tradeBar?.Volume ?? 0); + public override long Volume + { + get + { + if (_universeData != null) + { + return (long)_universeData.Volume; + } + return (long)(_tradeBar?.Volume ?? 0); + } + } /// /// Get the current bid price @@ -64,6 +91,10 @@ public override decimal BidPrice { get { + if (_universeData != null) + { + return _universeData.Close; + } if (_quoteBar == null && _quoteTick == null) { return decimal.Zero; @@ -102,6 +133,10 @@ public override decimal AskPrice { get { + if (_universeData != null) + { + return _universeData.Close; + } if (_quoteBar == null && _quoteTick == null) { return decimal.Zero; @@ -149,11 +184,7 @@ public FuturesContract(Symbol symbol) public FuturesContract(FutureUniverse contractData) : base(contractData.Symbol) { - LastPrice = contractData.Close; - AskPrice = contractData.Close; - BidPrice = contractData.Close; - Volume = (long)contractData.Volume; - OpenInterest = contractData.OpenInterest; + _universeData = contractData; } ///