eb1181f5f7
* Adds preliminary universe selection for Future Options
* Fixes scaling issues with Future Options
* Fixes scaling multiplying by 10000x instead of using _scaleFactor
* Fixes scaling for Tick
* Revert changes to Tick since it divides the scaling factor
* Changes stale method name to new method name after rebase
* Fixes selection bugs, adds new methods, and adds unit tests
* Fixes bug where Equity Symbol was created for an underlying
non-equity Symbol, resulting in equity data trying to be loaded
* Adds unit tests covering changes to Tick, QuoteBar, TradeBar and
LeanData
* Adds regression test for AddUniverseOption filter contract selection
for Future Options
* Addresses review - modifies the AddFutureOption signature
* Adds new AddUniverseOptions method overload
* Removes and adds a new unit test
* Misc. modifications to account for new changes
* Fixes bug where futures were loaded using default SID Date
* Refactors and removes unnecessary work
* Fixes regression algorithm, which previously made no trades
* Adds future option data
* Adds the corresponding underlying data, in this case, futures data
to enable usage of future options data
* Replaces data with new data (ES18Z20)
* Improves Future chain filtering and updates regression stats
* Add AddFutureOptionContract API
* Expands regression and unit tests to test in finer detail
* Adds Python regression algorithms for AddFutureOption[Contract] methods
* Adds new unit test for BacktestingOptionChainProvider
* Fixes bug with BacktesingOptionChainProvider where we
attempted to load the Trades option chain first, resulting
in breakage of backwards compatibility and limitation of the
option chain.
* Adds new regression algorithms (Py) to Algorithm.Python project
* Adds FutureOptionMarginBuyingPowerModel
* Modifies code paths used to select margin model
* Adds related unit tests for margin model
* Fixes issue with unit test and MHDB/SPDB lookup for Future Options
* Preliminary regression algorithm testing ITM call/put option buying
* Fixes bug where fee model used did not find non-US market
options fee model. We now use the futures fee model for future
options because IB charges the same commissions per contract
between futures and futures options
* Adds proper regression algorithm for ITM future options expiration
* Pushing broken algorithm for review
* Currently, algorithm does not fill forward, causing
a single future option to not get exercised when it is delisted.
* Adds FutureOptionPutITMExpiryRegressionAlgorithm
* Improves existing regression algorithm for call side
* Fixes bug in existing regression algorithm
* Adds AAPL daily data to advance enumerator for ^^^ fix
* Adds additional future option regression algorithms
* Adds Buy OTM expiration regression algorithms
* Adds Sell ITM/OTM expiration regression algorithms
* Adds missing Python regression algorithms
* Adds remaining Python regression algorithms and fixes issues
* Fixes naming issues and statistics
* Adds short option OTM regression algorithms (Py)
* Add license header and class comments to python algorithms
* Cleans up comments and docstrings
* Create Buy/Sell call intraday regression algo
* Redirects future options symbol properties to futures symbol properties
* Asserts exercise/assignment price and updates stats in regression algos
* Adds new unit test covering changes to SecurityService
* Adds comments and fixes failing test
* Partially fixes future option mis-calculated profit/loss
* Adjusts portfolio model to calculate FOP as a no upfront pay asset class
* Updates regression algorithm statistics
* Begin IB FOP support
* Initial support for FOP IB data streaming, live í¾
* Adds additional functionality to LiveOptionChainProvider
- Allows querying CME API to retrieve option chains for CME products
- Ultimately, it's also the groundwork for the CME
LiveFutureChainProvider
* Edits IDataQueueUniverseProvider interface to provide greater
control to implementors of it
* Misc. bug fixes required to get FOP data streaming through IB
* Adds comments, adds missing rategate call, and cleans up code
* Force exchange for FOP and Futures when no exchange is provided
* Fixes bug with Portfolio modeling across all asset classes
* Adds LiveOptionChainProvider tests for Future Options
* IB brokerage option symbol bug fixes and improvements
* Fixes contract multiplier lookup bug
* Fixes issue where we attempted to subscribe to IB data feed with canonical security
* Adds ES MHDB entry
* Reverts portfolio modeling changes for Futures Options
* Since IB eats into our account's cash balance when
a new FOP contract is purchased, we must model by applying funds
to our cash whenever a new purchase/sell occurs.
If we choose to model FOPs exactly as we do with futures, we
will end up with an invalid TotalPortfolioValue on algorithm
restart. By all means and purposes, FOPs are modeled exactly
the same as equity options with respect to the portfolio.
* Adds comments clarifying portfolio modeling and clarifies
existing portfolio modeling comments with additional context.
* Fixes IB symbol lookup for future options
* Fixes LiveOptionChainProvider looping 5 times per option chain
request, even on success
* Sets OptionChainedUniverseSelectionModel to produce a canonical
future/future option/option Symbol to avoid creating two Symbols
* Adds GLOBEX future option symbol mapping from future -> fop
* Fixes LiveOptionChainProvider loading wrong contract option chains
* Fixes loading of futures options ZIP files when backtesting
* Adds a string -> decimal JSON converter
* Additional fixes/refactoring to the LiveOptionChainProvider
* Adds tests for changes to Symbol and LeanData
* Reverts changes to IB-symbol-map
* Fixes Value for mapped future options tickers
* Fixes Symbol test
* Changes path of future options to future's expiry date
* Extra changes made to remove scaling from writing CSV
* Added method to map from FOP Globex -> FUT Globex
* Fixes MOO and MOC orders for future options
* Note: this order type might not be supported by IB or CME.
* Bug fixes and updates unit tests
* Update regression tests and data format
* Rebase changes
* 1. Multiple bug fixes for LiveOptionChainProvider, reverts IQFeed changes
2. Address review (partial): Code reuse and cleanup
1.
* Modifies check in
`AddFutureOptionShort(Call|Put)ITMExpiryRegressionAlgorithm`
to ensure no buys have negative quantity
* Code reuse changes in IB brokerage
* Bug fix in IB brokerage where we assigned the FOP expiry
as the futures expiry (requires verification)
* Doc changes and adds missing summaries/license banners
* Disposes of HTTP client resources in LiveOptionChainProvider
* Renames classes and adds FutureOption folder in Common/Securities
2.
* We revert back to the quotes API for the option chain,
since the settlement API sometimes had missing strikes.
* Fixes future option expiry being set as future's expiry
in LiveOptionChainProvider
* Fixes bug where wrong option chain was selected because of bad
expiry lookup in the futures expiries returned from CME
* Fixes multiple looping bug in LiveOptionChainProvider
* Adds strike price scaling for LiveOptionChainProvider
* Reverts IQFeed changes and simplifies interface upgrade changes
Some additional challenges we'll have to solve as part of FOPs:
- The `OptionSymbol.IsStandard` method makes the assumption that
weeklies contracts follow the pattern equities follows, which
does not apply to Futures Options
- The Subscription created in:
`OptionChainUniverseSubscriptionEnumeratorFactory`
...adds a Trade config. For illiquid contracts, this
will delay universe selection for the option symbol
until we get a trade. However, if we add a quote config,
the data would instead be loaded based on the first quote
we received from the brokerage.
But since we're currently using a trade config, illiquid
contracts won't start streaming data until it receives a trade.
NOTE: this commit is a WIP to addressing the reviews received in the PR,
but has been committed early for efficiency in the review process
* Fixes regression algorithms and misc. bugs
* Fixes map file lookup for non-equity options
* Adds extra assertion at end of algorithm to ensure no holdings are
left when the algorithm ends.
* Adds FutureOptionSymbol, allowing all contracts through as standard
* Changes SPDB to allow defaulting to underlying future symbol
properties if no entry is found for the given FOP
* Fixes calls to SPDB in SecurityService, IBBrokerage
* Reverts AAPL daily ZIP file to fix majority of regression algorithms
* Adds FOPs symbol properties
* Fixes existing symbol properties for a few futures
* Adds tests for changes to Symbol Properties Database
* Removes string SPDB lookup method
* Updates tests and misc callees of previous method
* Updates all regression tests to use data of already expired contracts
* Adds Futures Options Expiry Functions tests
* Adds required futures data for 2020-01-05
* Address review (partial): Expands test coverage and fixes tests
* Set option chain tests parallelism to fixture only
* Fixes broken test for contract month delta for FuturesOptionsExpiryFunctions
* Changes delisting date logic for Futures Options
* Address review: removes duplicate code, misc code fixes
* Bug fix in MarketHoursDatabase.GetDatabaseSymbolKey() where
we would use the underlying's Symbol for lookup in the MHDB
* Adds missing license banner
* Removes Futures Options entries from MHDB
* Adds new tests
* Adds SecurityType.FutureOption
* Converts any underlying comparisons and uses SecurityType directly
instead for FOP specific behavior
* Extra code modifications to acommodate new SecurityType
* Addresses review: fixes order fee bug on exercise
* Additional bug fixes and adding of SecurityType.FutureOption
* Updates regression algorithms OrderListHash
* Fixes various bugs in IB live implementation
* Fixes bug setting the right contract expiration date for FOP
generated by LiveOptionChainProvider
* Adds new function to FuturesOptionsExpiryFunctions
* Clarifies parameter names better in some functions/methods
* Fixes bugs in IB brokerage for FOPs
* Address review - code cleanup and refactor
* Remove MappingEventProvider, SplitEventProvider, and
DividendEventProvider for Futures Options in
CorporateEventEnumeratorFactory
* Address review: Use MHDB key resolver in SPDB
* Makes regression tests pass and adds comment for expiry issue
* Fixes MHDB lookup on string symbol method
* Adds Futures Options greeks regression algorithm (C# only)
* Adds explanitory comment on MHDB FOP lookup
* Remove python from FutureOptionCallITMGreeksExpiryRegressionAlgorithm
415 lines
18 KiB
C#
415 lines
18 KiB
C#
/*
|
|
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
|
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Newtonsoft.Json;
|
|
using NodaTime;
|
|
using ProtoBuf;
|
|
using QuantConnect.Data.Custom.Benzinga;
|
|
using QuantConnect.Data.Custom.Estimize;
|
|
using QuantConnect.Data.Custom.Tiingo;
|
|
using QuantConnect.Data.Market;
|
|
using QuantConnect.Util;
|
|
|
|
namespace QuantConnect.Data
|
|
{
|
|
/// <summary>
|
|
/// Abstract base data class of QuantConnect. It is intended to be extended to define
|
|
/// generic user customizable data types while at the same time implementing the basics of data where possible
|
|
/// </summary>
|
|
[ProtoContract(SkipConstructor = true)]
|
|
[ProtoInclude(8, typeof(Tick))]
|
|
[ProtoInclude(100, typeof(TradeBar))]
|
|
[ProtoInclude(200, typeof(QuoteBar))]
|
|
[ProtoInclude(300, typeof(Dividend))]
|
|
[ProtoInclude(400, typeof(Split))]
|
|
[ProtoInclude(500, typeof(TiingoNews))]
|
|
[ProtoInclude(600, typeof(BenzingaNews))]
|
|
[ProtoInclude(700, typeof(EstimizeEstimate))]
|
|
[ProtoInclude(800, typeof(EstimizeRelease))]
|
|
[ProtoInclude(900, typeof(EstimizeConsensus))]
|
|
public abstract class BaseData : IBaseData
|
|
{
|
|
private decimal _value;
|
|
|
|
/// <summary>
|
|
/// A list of all <see cref="Resolution"/>
|
|
/// </summary>
|
|
protected static readonly List<Resolution> AllResolutions =
|
|
Enum.GetValues(typeof(Resolution)).Cast<Resolution>().ToList();
|
|
|
|
/// <summary>
|
|
/// A list of <see cref="Resolution.Daily"/>
|
|
/// </summary>
|
|
protected static readonly List<Resolution> DailyResolution = new List<Resolution> { Resolution.Daily };
|
|
|
|
/// <summary>
|
|
/// A list of <see cref="Resolution.Minute"/>
|
|
/// </summary>
|
|
protected static readonly List<Resolution> MinuteResolution = new List<Resolution> { Resolution.Minute };
|
|
|
|
/// <summary>
|
|
/// Market Data Type of this data - does it come in individual price packets or is it grouped into OHLC.
|
|
/// </summary>
|
|
/// <remarks>Data is classed into two categories - streams of instantaneous prices and groups of OHLC data.</remarks>
|
|
[ProtoMember(1)]
|
|
public MarketDataType DataType { get; set; } = MarketDataType.Base;
|
|
|
|
/// <summary>
|
|
/// True if this is a fill forward piece of data
|
|
/// </summary>
|
|
public bool IsFillForward { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Current time marker of this data packet.
|
|
/// </summary>
|
|
/// <remarks>All data is timeseries based.</remarks>
|
|
[ProtoMember(2)]
|
|
public DateTime Time { get; set; }
|
|
|
|
/// <summary>
|
|
/// The end time of this data. Some data covers spans (trade bars) and as such we want
|
|
/// to know the entire time span covered
|
|
/// </summary>
|
|
public virtual DateTime EndTime
|
|
{
|
|
get { return Time; }
|
|
set { Time = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Symbol representation for underlying Security
|
|
/// </summary>
|
|
public Symbol Symbol { get; set; } = Symbol.Empty;
|
|
|
|
/// <summary>
|
|
/// Value representation of this data packet. All data requires a representative value for this moment in time.
|
|
/// For streams of data this is the price now, for OHLC packets this is the closing price.
|
|
/// </summary>
|
|
[ProtoMember(4)]
|
|
public virtual decimal Value
|
|
{
|
|
get
|
|
{
|
|
return _value;
|
|
}
|
|
set
|
|
{
|
|
_value = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// As this is a backtesting platform we'll provide an alias of value as price.
|
|
/// </summary>
|
|
public decimal Price => Value;
|
|
|
|
/// <summary>
|
|
/// Constructor for initialising the dase data class
|
|
/// </summary>
|
|
public BaseData()
|
|
{
|
|
//Empty constructor required for fast-reflection initialization
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object
|
|
/// each time it is called. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
|
|
/// </summary>
|
|
/// <param name="config">Subscription data config setup object</param>
|
|
/// <param name="line">Line of the source document</param>
|
|
/// <param name="date">Date of the requested data</param>
|
|
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
|
/// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
|
|
public virtual BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
|
{
|
|
// stub implementation to prevent compile errors in user algorithms
|
|
var dataFeed = isLiveMode ? DataFeedEndpoint.LiveTrading : DataFeedEndpoint.Backtesting;
|
|
#pragma warning disable 618 // This implementation is left here for backwards compatibility of the BaseData API
|
|
return Reader(config, line, date, dataFeed);
|
|
#pragma warning restore 618
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object
|
|
/// each time it is called. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
|
|
/// </summary>
|
|
/// <param name="config">Subscription data config setup object</param>
|
|
/// <param name="stream">The data stream</param>
|
|
/// <param name="date">Date of the requested data</param>
|
|
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
|
/// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
|
|
public virtual BaseData Reader(SubscriptionDataConfig config, StreamReader stream, DateTime date, bool isLiveMode)
|
|
{
|
|
throw new NotImplementedException("Each data types has to implement is own Stream reader");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return the URL string source of the file. This will be converted to a stream
|
|
/// </summary>
|
|
/// <param name="config">Configuration object</param>
|
|
/// <param name="date">Date of this source file</param>
|
|
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
|
/// <returns>String URL of source file.</returns>
|
|
public virtual SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
|
{
|
|
// stub implementation to prevent compile errors in user algorithms
|
|
var dataFeed = isLiveMode ? DataFeedEndpoint.LiveTrading : DataFeedEndpoint.Backtesting;
|
|
#pragma warning disable 618 // This implementation is left here for backwards compatibility of the BaseData API
|
|
var source = GetSource(config, date, dataFeed);
|
|
#pragma warning restore 618
|
|
|
|
if (isLiveMode)
|
|
{
|
|
// live trading by default always gets a rest endpoint
|
|
return new SubscriptionDataSource(source, SubscriptionTransportMedium.Rest);
|
|
}
|
|
|
|
// construct a uri to determine if we have a local or remote file
|
|
var uri = new Uri(source, UriKind.RelativeOrAbsolute);
|
|
|
|
if (uri.IsAbsoluteUri && !uri.IsLoopback)
|
|
{
|
|
return new SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile);
|
|
}
|
|
|
|
return new SubscriptionDataSource(source, SubscriptionTransportMedium.LocalFile);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indicates if there is support for mapping
|
|
/// </summary>
|
|
/// <remarks>Relies on the <see cref="Symbol"/> property value</remarks>
|
|
/// <returns>True indicates mapping should be used</returns>
|
|
public virtual bool RequiresMapping()
|
|
{
|
|
return Symbol.SecurityType == SecurityType.Equity ||
|
|
Symbol.SecurityType == SecurityType.Option;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indicates that the data set is expected to be sparse
|
|
/// </summary>
|
|
/// <remarks>Relies on the <see cref="Symbol"/> property value</remarks>
|
|
/// <remarks>This is a method and not a property so that python
|
|
/// custom data types can override it</remarks>
|
|
/// <returns>True if the data set represented by this type is expected to be sparse</returns>
|
|
public virtual bool IsSparseData()
|
|
{
|
|
// by default, we'll assume all custom data is sparse data
|
|
return Symbol.SecurityType == SecurityType.Base;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the default resolution for this data and security type
|
|
/// </summary>
|
|
/// <remarks>This is a method and not a property so that python
|
|
/// custom data types can override it</remarks>
|
|
public virtual Resolution DefaultResolution()
|
|
{
|
|
return Resolution.Minute;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the supported resolution for this data and security type
|
|
/// </summary>
|
|
/// <remarks>Relies on the <see cref="Symbol"/> property value</remarks>
|
|
/// <remarks>This is a method and not a property so that python
|
|
/// custom data types can override it</remarks>
|
|
public virtual List<Resolution> SupportedResolutions()
|
|
{
|
|
if (Symbol.SecurityType == SecurityType.Option || Symbol.SecurityType == SecurityType.FutureOption)
|
|
{
|
|
return MinuteResolution;
|
|
}
|
|
|
|
return AllResolutions;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Specifies the data time zone for this data type. This is useful for custom data types
|
|
/// </summary>
|
|
/// <remarks>Will throw <see cref="InvalidOperationException"/> for security types
|
|
/// other than <see cref="SecurityType.Base"/></remarks>
|
|
/// <returns>The <see cref="DateTimeZone"/> of this data type</returns>
|
|
public virtual DateTimeZone DataTimeZone()
|
|
{
|
|
if (Symbol.SecurityType != SecurityType.Base)
|
|
{
|
|
throw new InvalidOperationException("BaseData.DataTimeZone(): is only valid for base data types");
|
|
}
|
|
return TimeZones.NewYork;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates this base data with a new trade
|
|
/// </summary>
|
|
/// <param name="lastTrade">The price of the last trade</param>
|
|
/// <param name="tradeSize">The quantity traded</param>
|
|
public void UpdateTrade(decimal lastTrade, decimal tradeSize)
|
|
{
|
|
Update(lastTrade, 0, 0, tradeSize, 0, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates this base data with new quote information
|
|
/// </summary>
|
|
/// <param name="bidPrice">The current bid price</param>
|
|
/// <param name="bidSize">The current bid size</param>
|
|
/// <param name="askPrice">The current ask price</param>
|
|
/// <param name="askSize">The current ask size</param>
|
|
public void UpdateQuote(decimal bidPrice, decimal bidSize, decimal askPrice, decimal askSize)
|
|
{
|
|
Update(0, bidPrice, askPrice, 0, bidSize, askSize);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates this base data with the new quote bid information
|
|
/// </summary>
|
|
/// <param name="bidPrice">The current bid price</param>
|
|
/// <param name="bidSize">The current bid size</param>
|
|
public void UpdateBid(decimal bidPrice, decimal bidSize)
|
|
{
|
|
Update(0, bidPrice, 0, 0, bidSize, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates this base data with the new quote ask information
|
|
/// </summary>
|
|
/// <param name="askPrice">The current ask price</param>
|
|
/// <param name="askSize">The current ask size</param>
|
|
public void UpdateAsk(decimal askPrice, decimal askSize)
|
|
{
|
|
Update(0, 0, askPrice, 0, 0, askSize);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update routine to build a bar/tick from a data update.
|
|
/// </summary>
|
|
/// <param name="lastTrade">The last trade price</param>
|
|
/// <param name="bidPrice">Current bid price</param>
|
|
/// <param name="askPrice">Current asking price</param>
|
|
/// <param name="volume">Volume of this trade</param>
|
|
/// <param name="bidSize">The size of the current bid, if available</param>
|
|
/// <param name="askSize">The size of the current ask, if available</param>
|
|
public virtual void Update(decimal lastTrade, decimal bidPrice, decimal askPrice, decimal volume, decimal bidSize, decimal askSize)
|
|
{
|
|
Value = lastTrade;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return a new instance clone of this object, used in fill forward
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This base implementation uses reflection to copy all public fields and properties
|
|
/// </remarks>
|
|
/// <param name="fillForward">True if this is a fill forward clone</param>
|
|
/// <returns>A clone of the current object</returns>
|
|
public virtual BaseData Clone(bool fillForward)
|
|
{
|
|
var clone = Clone();
|
|
clone.IsFillForward = fillForward;
|
|
return clone;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return a new instance clone of this object, used in fill forward
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This base implementation uses reflection to copy all public fields and properties
|
|
/// </remarks>
|
|
/// <returns>A clone of the current object</returns>
|
|
public virtual BaseData Clone()
|
|
{
|
|
return (BaseData) ObjectActivator.Clone((object)this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Formats a string with the symbol and value.
|
|
/// </summary>
|
|
/// <returns>string - a string formatted as SPY: 167.753</returns>
|
|
public override string ToString()
|
|
{
|
|
return $"{Symbol}: {Value.ToStringInvariant("C")}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object
|
|
/// each time it is called.
|
|
/// </summary>
|
|
/// <remarks>OBSOLETE:: This implementation is added for backward/forward compatibility purposes. This function is no longer called by the LEAN engine.</remarks>
|
|
/// <param name="config">Subscription data config setup object</param>
|
|
/// <param name="line">Line of the source document</param>
|
|
/// <param name="date">Date of the requested data</param>
|
|
/// <param name="datafeed">Type of datafeed we're requesting - a live or backtest feed.</param>
|
|
/// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
|
|
[Obsolete("Reader(SubscriptionDataConfig, string, DateTime, DataFeedEndpoint) method has been made obsolete, use Reader(SubscriptionDataConfig, string, DateTime, bool) instead.")]
|
|
public virtual BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, DataFeedEndpoint datafeed)
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Please implement Reader(SubscriptionDataConfig, string, DateTime, bool) on your custom data type: {GetType().Name}"
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return the URL string source of the file. This will be converted to a stream
|
|
/// </summary>
|
|
/// <remarks>OBSOLETE:: This implementation is added for backward/forward compatibility purposes. This function is no longer called by the LEAN engine.</remarks>
|
|
/// <param name="config">Configuration object</param>
|
|
/// <param name="date">Date of this source file</param>
|
|
/// <param name="datafeed">Type of datafeed we're reqesting - backtest or live</param>
|
|
/// <returns>String URL of source file.</returns>
|
|
[Obsolete("GetSource(SubscriptionDataConfig, DateTime, DataFeedEndpoint) method has been made obsolete, use GetSource(SubscriptionDataConfig, DateTime, bool) instead.")]
|
|
public virtual string GetSource(SubscriptionDataConfig config, DateTime date, DataFeedEndpoint datafeed)
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Please implement GetSource(SubscriptionDataConfig, DateTime, bool) on your custom data type: {GetType().Name}"
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deserialize the message from the data server
|
|
/// </summary>
|
|
/// <param name="serialized">The data server's message</param>
|
|
/// <returns>An enumerable of base data, if unsuccessful, returns an empty enumerable</returns>
|
|
public static IEnumerable<BaseData> DeserializeMessage(string serialized)
|
|
{
|
|
var deserialized = JsonConvert.DeserializeObject(serialized, JsonSerializerSettings);
|
|
|
|
var enumerable = deserialized as IEnumerable<BaseData>;
|
|
if (enumerable != null)
|
|
{
|
|
return enumerable;
|
|
}
|
|
|
|
var data = deserialized as BaseData;
|
|
if (data != null)
|
|
{
|
|
return new[] { data };
|
|
}
|
|
|
|
return Enumerable.Empty<BaseData>();
|
|
}
|
|
|
|
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
|
|
{
|
|
TypeNameHandling = TypeNameHandling.All
|
|
};
|
|
}
|
|
}
|