Skip to content

Commit

Permalink
Fix: use universe data for market data in FuturesContract
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Jan 8, 2025
1 parent c089aeb commit deab0c5
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions Common/Data/Market/FuturesContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace QuantConnect.Data.Market
/// </summary>
public class FuturesContract : BaseContract
{
private FutureUniverse _universeData;
private TradeBar _tradeBar;
private QuoteBar _quoteBar;
private Tick _tradeTick;
Expand All @@ -31,7 +32,18 @@ public class FuturesContract : BaseContract
/// <summary>
/// Gets the open interest
/// </summary>
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;
}
}

/// <summary>
/// Gets the last price this contract traded at
Expand All @@ -40,6 +52,11 @@ public override decimal LastPrice
{
get
{
if (_universeData != null)
{
return _universeData.Close;
}

if (_tradeBar == null && _tradeTick == null)
{
return decimal.Zero;
Expand All @@ -55,7 +72,17 @@ public override decimal LastPrice
/// <summary>
/// Gets the last volume this contract traded at
/// </summary>
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);
}
}

/// <summary>
/// Get the current bid price
Expand All @@ -64,6 +91,10 @@ public override decimal BidPrice
{
get
{
if (_universeData != null)
{
return _universeData.Close;
}
if (_quoteBar == null && _quoteTick == null)
{
return decimal.Zero;
Expand Down Expand Up @@ -102,6 +133,10 @@ public override decimal AskPrice
{
get
{
if (_universeData != null)
{
return _universeData.Close;
}
if (_quoteBar == null && _quoteTick == null)
{
return decimal.Zero;
Expand Down Expand Up @@ -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;
}

/// <summary>
Expand Down

0 comments on commit deab0c5

Please sign in to comment.