Lean
$LEAN_TAG$
|
Extensions function collections - group all static extensions functions here. More...
Static Public Member Functions | |
static T | TryGetPropertyValue< T > (this JObject jObject, string name) |
Helper method to get a property in a jobject if available More... | |
static bool | IsOutOfDate (this string filepath) |
Determine if the file is out of date according to our download period. Date based files are never out of date (Files with YYYYMMDD) More... | |
static bool | IsDirectoryEmpty (this string directoryPath) |
Helper method to check if a directory exists and is not empty More... | |
static MarketHoursDatabase.Entry | GetEntry (this MarketHoursDatabase marketHoursDatabase, Symbol symbol, IEnumerable< Type > dataTypes) |
Helper method to get a market hours entry More... | |
static List< string > | DeserializeList (this string jsonArray) |
Helper method to deserialize a json array into a list also handling single json values More... | |
static List< T > | DeserializeList< T > (this string jsonArray) |
Helper method to deserialize a json array into a list also handling single json values More... | |
static string | DownloadData (this HttpClient client, string url, Dictionary< string, string > headers=null) |
Helper method to download a provided url as a string More... | |
static string | DownloadData (this string url, Dictionary< string, string > headers=null) |
Helper method to download a provided url as a string More... | |
static byte[] | DownloadByteArray (this string url) |
Helper method to download a provided url as a byte array More... | |
static decimal | SafeMultiply100 (this decimal value) |
Safe multiplies a decimal by 100 More... | |
static MemoryStream | GetMemoryStream (Guid guid) |
Will return a memory stream using the RecyclableMemoryStreamManager instance. More... | |
static byte[] | ProtobufSerialize (this List< Tick > ticks, Guid guid) |
Serialize a list of ticks using protobuf More... | |
static byte[] | ProtobufSerialize (this IBaseData baseData, Guid guid) |
Serialize a base data instance using protobuf More... | |
static void | ProtobufSerialize (this IBaseData baseData, Stream stream) |
Serialize a base data instance using protobuf More... | |
static string | GetZeroPriceMessage (this Symbol symbol) |
Extension method to get security price is 0 messages for users More... | |
static string | ToCamelCase (this string value) |
Converts the provided string into camel case notation More... | |
static AlphaResultPacket | Batch (this List< AlphaResultPacket > resultPackets) |
Helper method to batch a collection of AlphaResultPacket into 1 single instance. Will return null if the provided list is empty. Will keep the last Order instance per order id, which is the latest. Implementations trusts the provided 'resultPackets' list to batch is in order More... | |
static void | StopSafely (this Thread thread, TimeSpan timeout, CancellationTokenSource token=null) |
Helper method to safely stop a running thread More... | |
static string | GetHash (this IDictionary< int, Order > orders) |
Generates a hash code from a given collection of orders More... | |
static Func< DateTime, DateTime?> | ToFunc (this IDateRule dateRule) |
Converts a date rule into a function that receives current time and returns the next date. More... | |
static bool | IsEmpty (this BaseSeries series) |
Returns true if the specified BaseSeries instance holds no ISeriesPoint More... | |
static bool | IsEmpty (this Chart chart) |
Returns if the specified Chart instance holds no Series or they are all empty Extensions.IsEmpty(BaseSeries) More... | |
static dynamic | GetPythonMethod (this PyObject instance, string name) |
Gets a python method by name More... | |
static dynamic | GetPythonBoolProperty (this PyObject instance, string name) |
Gets a python property by name More... | |
static dynamic | GetPythonBoolPropertyWithChecks (this PyObject instance, string name) |
Gets a python property by name More... | |
static dynamic | GetPythonMethodWithChecks (this PyObject instance, string name) |
Gets a python method by name More... | |
static dynamic | GetMethod (this PyObject instance, string name) |
Gets a method from a PyObject instance by name. First, it tries to get the snake-case version of the method name, in case the user is using that style. Else, it tries to get the method with the original name, regardless of whether the class has a Python overload or not. More... | |
static int | GetPythonArgCount (this PyObject method) |
Get a python methods arg count More... | |
static IEnumerable< IPortfolioTarget > | OrderTargetsByMarginImpact (this IEnumerable< IPortfolioTarget > targets, IAlgorithm algorithm, bool targetIsDelta=false) |
Returns an ordered enumerable where position reducing orders are executed first and the remaining orders are executed in decreasing order value. Will NOT return targets during algorithm warmup. Will NOT return targets for securities that have no data yet. Will NOT return targets for which current holdings + open orders quantity, sum up to the target quantity More... | |
static BaseData | GetBaseDataInstance (this Type type) |
Given a type will create a new instance using the parameterless constructor and assert the type implements BaseData More... | |
static T | GetAndDispose< T > (this PyObject instance) |
Helper method that will cast the provided PyObject to a T type and dispose of it. More... | |
static void | Move< T > (this List< T > list, int oldIndex, int newIndex) |
Extension to move one element from list from A to position B. More... | |
static byte[] | GetBytes (this string str) |
Extension method to convert a string into a byte array More... | |
static byte[] | GetBytes (this Stream stream) |
Reads the entire content of a stream and returns it as a byte array. More... | |
static void | Clear< T > (this ConcurrentQueue< T > queue) |
Extentsion method to clear all items from a thread safe queue More... | |
static string | GetString (this byte[] bytes, Encoding encoding=null) |
Extension method to convert a byte array into a string. More... | |
static string | ToMD5 (this string str) |
Extension method to convert a string to a MD5 hash. More... | |
static string | ToSHA256 (this string data) |
Encrypt the token:time data to make our API hash. More... | |
static string | EncodeBase36 (this ulong data) |
Converts a long to an uppercase alpha numeric string More... | |
static ulong | DecodeBase36 (this string symbol) |
Converts an upper case alpha numeric string into a long More... | |
static string | EncodeBase64 (this string text) |
Convert a string to Base64 Encoding More... | |
static string | DecodeBase64 (this string base64EncodedText) |
Decode a Base64 Encoded string More... | |
static string | LazyToUpper (this string data) |
Lazy string to upper implementation. Will first verify the string is not already upper and avoid the call to string.ToUpperInvariant() if possible. More... | |
static string | LazyToLower (this string data) |
Lazy string to lower implementation. Will first verify the string is not already lower and avoid the call to string.ToLowerInvariant() if possible. More... | |
static void | AddOrUpdate< K, V > (this ConcurrentDictionary< K, V > dictionary, K key, V value) |
Extension method to automatically set the update value to same as "add" value for TryAddUpdate. This makes the API similar for traditional and concurrent dictionaries. More... | |
static TValue | AddOrUpdate< TKey, TValue > (this ConcurrentDictionary< TKey, Lazy< TValue >> dictionary, TKey key, Func< TKey, TValue > addValueFactory, Func< TKey, TValue, TValue > updateValueFactory) |
Extension method to automatically add/update lazy values in concurrent dictionary. More... | |
static void | Add< TKey, TElement, TCollection > (this IDictionary< TKey, TCollection > dictionary, TKey key, TElement element) |
Adds the specified element to the collection with the specified key. If an entry does not exist for the specified key then one will be created. More... | |
static ImmutableDictionary< TKey, ImmutableHashSet< TElement > > | Add< TKey, TElement > (this ImmutableDictionary< TKey, ImmutableHashSet< TElement >> dictionary, TKey key, TElement element) |
Adds the specified element to the collection with the specified key. If an entry does not exist for the specified key then one will be created. More... | |
static ImmutableSortedDictionary< TKey, ImmutableHashSet< TElement > > | Add< TKey, TElement > (this ImmutableSortedDictionary< TKey, ImmutableHashSet< TElement >> dictionary, TKey key, TElement element) |
Adds the specified element to the collection with the specified key. If an entry does not exist for the specified key then one will be created. More... | |
static void | Add (this Ticks dictionary, Symbol key, Tick tick) |
Adds the specified Tick to the Ticks collection. If an entry does not exist for the specified key then one will be created. More... | |
static decimal | RoundToSignificantDigits (this decimal d, int digits) |
Extension method to round a double value to a fixed number of significant figures instead of a fixed decimal places. More... | |
static string | ToFinancialFigures (this decimal number) |
Converts a decimal into a rounded number ending with K (thousands), M (millions), B (billions), etc. More... | |
static decimal | DiscretelyRoundBy (this decimal value, decimal quanta, MidpointRounding mode=MidpointRounding.AwayFromZero) |
Discretizes the value to a maximum precision specified by quanta . Quanta can be an arbitrary positive number and represents the step size. Consider a quanta equal to 0.15 and rounding a value of 1.0. Valid values would be 0.9 (6 quanta) and 1.05 (7 quanta) which would be rounded up to 1.05. More... | |
static decimal | TruncateTo3DecimalPlaces (this decimal value) |
Will truncate the provided decimal, without rounding, to 3 decimal places More... | |
static ? decimal | SmartRounding (this decimal? input) |
Provides global smart rounding, numbers larger than 1000 will round to 4 decimal places, while numbers smaller will round to 7 significant digits More... | |
static decimal | SmartRounding (this decimal input) |
Provides global smart rounding, numbers larger than 1000 will round to 4 decimal places, while numbers smaller will round to 7 significant digits More... | |
static decimal | SafeDecimalCast (this double input) |
Casts the specified input value to a decimal while acknowledging the overflow conditions More... | |
static decimal | Normalize (this decimal input) |
Will remove any trailing zeros for the provided decimal input More... | |
static string | NormalizeToStr (this decimal input) |
Will remove any trailing zeros for the provided decimal and convert to string. Uses Normalize(decimal). More... | |
static int | GetDecimalPlaces (this decimal input) |
Helper method to determine the amount of decimal places associated with the given decimal More... | |
static decimal | ToDecimal (this string str) |
Extension method for faster string to decimal conversion. More... | |
static decimal | ToNormalizedDecimal (this string str) |
Extension method for faster string to normalized decimal conversion, i.e. 20.0% should be parsed into 0.2 More... | |
static decimal | ToDecimalAllowExponent (this string str) |
Extension method for string to decimal conversion where string can represent a number with exponent xe-y More... | |
static int | ToInt32 (this string str) |
Extension method for faster string to Int32 conversion. More... | |
static long | ToInt64 (this string str) |
Extension method for faster string to Int64 conversion. More... | |
static bool | ImplementsStreamReader (this Type baseDataType) |
Helper method to determine if a data type implements the Stream reader method More... | |
static List< string > | ToCsv (this string str, int size=4) |
Breaks the specified string into csv components, all commas are considered separators More... | |
static List< string > | ToCsvData (this string str, int size=4, char delimiter=',') |
Breaks the specified string into csv components, works correctly with commas in data fields More... | |
static bool | TryGetFromCsv (this string csvLine, int index, out ReadOnlySpan< char > result) |
Gets the value at the specified index from a CSV line. More... | |
static bool | TryGetDecimalFromCsv (this string csvLine, int index, out decimal value) |
Gets the value at the specified index from a CSV line, converted into a decimal. More... | |
static decimal | GetDecimalFromCsv (this string csvLine, int index) |
Gets the value at the specified index from a CSV line, converted into a decimal. More... | |
static bool | IsNaNOrInfinity (this double value) |
Check if a number is NaN or infinity More... | |
static bool | IsNaNOrZero (this double value) |
Check if a number is NaN or equal to zero More... | |
static decimal | GetDecimalEpsilon () |
Gets the smallest positive number that can be added to a decimal instance and return a new value that does not == the old value More... | |
static string | GetExtension (this string str) |
Extension method to extract the extension part of this file name if it matches a safe list, or return a ".custom" extension for ones which do not match. More... | |
static Stream | ToStream (this string str) |
Extension method to convert strings to stream to be read. More... | |
static TimeSpan | Round (this TimeSpan time, TimeSpan roundingInterval, MidpointRounding roundingType) |
Extension method to round a timeSpan to nearest timespan period. More... | |
static TimeSpan | Round (this TimeSpan time, TimeSpan roundingInterval) |
Extension method to round timespan to nearest timespan period. More... | |
static DateTime | RoundDown (this DateTime dateTime, TimeSpan interval) |
Extension method to round a datetime down by a timespan interval. More... | |
static DateTime | RoundDownInTimeZone (this DateTime dateTime, TimeSpan roundingInterval, DateTimeZone sourceTimeZone, DateTimeZone roundingTimeZone) |
Rounds the specified date time in the specified time zone. Careful with calling this method in a loop while modifying dateTime, check unit tests. More... | |
static DateTime | ExchangeRoundDown (this DateTime dateTime, TimeSpan interval, SecurityExchangeHours exchangeHours, bool extendedMarketHours) |
Extension method to round a datetime down by a timespan interval until it's within the specified exchange's open hours. This works by first rounding down the specified time using the interval, then producing a bar between that rounded time and the interval plus the rounded time and incrementally walking backwards until the exchange is open More... | |
static DateTime | ExchangeRoundDownInTimeZone (this DateTime dateTime, TimeSpan interval, SecurityExchangeHours exchangeHours, DateTimeZone roundingTimeZone, bool extendedMarketHours) |
Extension method to round a datetime down by a timespan interval until it's within the specified exchange's open hours. The rounding is performed in the specified time zone More... | |
static bool | IsMarketOpen (this Security security, bool extendedMarketHours) |
Helper method to determine if a specific market is open More... | |
static bool | IsMarketOpen (this Symbol symbol, DateTime utcTime, bool extendedMarketHours) |
Helper method to determine if a specific market is open More... | |
static DateTime | Round (this DateTime datetime, TimeSpan roundingInterval) |
Extension method to round a datetime to the nearest unit timespan. More... | |
static DateTime | RoundUp (this DateTime time, TimeSpan interval) |
Extension method to explicitly round up to the nearest timespan interval. More... | |
static DateTime | ConvertTo (this DateTime time, DateTimeZone from, DateTimeZone to, bool strict=false) |
Converts the specified time from the from time zone to the to time zone More... | |
static DateTime | ConvertFromUtc (this DateTime time, DateTimeZone to, bool strict=false) |
Converts the specified time from UTC to the to time zone More... | |
static DateTime | ConvertToUtc (this DateTime time, DateTimeZone from, bool strict=false) |
Converts the specified time from the from time zone to TimeZones.Utc More... | |
static bool | IsCommonBusinessDay (this DateTime date) |
Business day here is defined as any day of the week that is not saturday or sunday More... | |
static void | Reset (this Timer timer) |
Add the reset method to the System.Timer class. More... | |
static bool | MatchesTypeName (this Type type, string typeName) |
Function used to match a type against a string type name. This function compares on the AssemblyQualfiedName, the FullName, and then just the Name of the type. More... | |
static bool | IsSubclassOfGeneric (this Type type, Type possibleSuperType) |
Checks the specified type to see if it is a subclass of the possibleSuperType . This method will crawl up the inheritance heirarchy to check for equality using generic type definitions (if exists) More... | |
static string | GetBetterTypeName (this Type type) |
Gets a type's name with the generic parameters filled in the way they would look when defined in code, such as converting Dictionary<1, 2> to Dictionary<string,int> More... | |
static TimeSpan | ToTimeSpan (this Resolution resolution) |
Converts the Resolution instance into a TimeSpan instance More... | |
static Resolution | ToHigherResolutionEquivalent (this TimeSpan timeSpan, bool requireExactMatch) |
Converts the specified time span into a resolution enum value. If an exact match is not found and requireExactMatch is false, then the higher resoluion will be returned. For example, timeSpan=5min will return Minute resolution. More... | |
static bool | TryParseSecurityType (this string value, out SecurityType securityType, bool ignoreCase=true) |
Attempts to convert the string into a SecurityType enum value More... | |
static T | ConvertTo< T > (this string value) |
Converts the specified string value into the specified type More... | |
static object | ConvertTo (this string value, Type type) |
Converts the specified string value into the specified type More... | |
static bool | WaitOne (this WaitHandle waitHandle, CancellationToken cancellationToken) |
Blocks the current thread until the current T:System.Threading.WaitHandle receives a signal, while observing a T:System.Threading.CancellationToken. More... | |
static bool | WaitOne (this WaitHandle waitHandle, TimeSpan timeout, CancellationToken cancellationToken) |
Blocks the current thread until the current T:System.Threading.WaitHandle is set, using a T:System.TimeSpan to measure the time interval, while observing a T:System.Threading.CancellationToken. More... | |
static bool | WaitOne (this WaitHandle waitHandle, int millisecondsTimeout, CancellationToken cancellationToken) |
Blocks the current thread until the current T:System.Threading.WaitHandle is set, using a 32-bit signed integer to measure the time interval, while observing a T:System.Threading.CancellationToken. More... | |
static byte[] | GetMD5Hash (this Stream stream) |
Gets the MD5 hash from a stream More... | |
static string | WithEmbeddedHtmlAnchors (this string source) |
Convert a string into the same string with a URL! :) More... | |
static string | GetStringBetweenChars (this string value, char left, char right) |
Get the first occurence of a string between two characters from another string More... | |
static string | SingleOrAlgorithmTypeName (this List< string > names, string algorithmTypeName) |
Return the first in the series of names, or find the one that matches the configured algorithmTypeName More... | |
static string | ToLower (this Enum @enum) |
Converts the specified enum value to its corresponding lower-case string representation More... | |
static bool | IsValid (this SecurityType securityType) |
Asserts the specified securityType value is valid More... | |
static bool | IsOption (this SecurityType securityType) |
Determines if the provided SecurityType is a type of Option. Valid option types are: Equity Options, Futures Options, and Index Options. More... | |
static bool | HasOptions (this SecurityType securityType) |
Determines if the provided SecurityType has a matching option SecurityType, used to represent the current SecurityType as a derivative. More... | |
static OptionStyle | DefaultOptionStyle (this SecurityType securityType) |
Gets the default OptionStyle for the provided SecurityType More... | |
static OptionStyle | ParseOptionStyle (this string optionStyle) |
Converts the specified string to its corresponding OptionStyle More... | |
static OptionRight | ParseOptionRight (this string optionRight) |
Converts the specified string to its corresponding OptionRight More... | |
static string | ToStringPerformance (this OptionRight optionRight) |
Converts the specified optionRight value to its corresponding string representation More... | |
static string | OptionRightToLower (this OptionRight optionRight) |
Converts the specified optionRight value to its corresponding lower-case string representation More... | |
static string | OptionStyleToLower (this OptionStyle optionStyle) |
Converts the specified optionStyle value to its corresponding lower-case string representation More... | |
static ? DataMappingMode | ParseDataMappingMode (this string dataMappingMode) |
Converts the specified string to its corresponding DataMappingMode More... | |
static string | SecurityTypeToLower (this SecurityType securityType) |
Converts the specified securityType value to its corresponding lower-case string representation More... | |
static string | TickTypeToLower (this TickType tickType) |
Converts the specified tickType value to its corresponding lower-case string representation More... | |
static string | ResolutionToLower (this Resolution resolution) |
Converts the specified resolution value to its corresponding lower-case string representation More... | |
static OrderTicket | ToOrderTicket (this Order order, SecurityTransactionManager transactionManager) |
Turn order into an order ticket More... | |
static void | ProcessUntilEmpty< T > (this IProducerConsumerCollection< T > collection, Action< T > handler) |
Process all items in collection through given handler More... | |
static string | ToSafeString (this PyObject pyObject) |
Returns a string that represents the current PyObject More... | |
static bool | TryConvert< T > (this PyObject pyObject, out T result, bool allowPythonDerivative=false) |
Tries to convert a PyObject into a managed object More... | |
static bool | TryConvertToDelegate< T > (this PyObject pyObject, out T result) |
Tries to convert a PyObject into a managed object More... | |
static dynamic | SafeAsManagedObject (this PyObject pyObject, Type typeToConvertTo=null) |
Safely convert PyObject to ManagedObject using Py.GIL Lock If no type is given it will convert the PyObject's Python Type to a ManagedObject Type in a attempt to resolve the target type to convert to. More... | |
static Func< IEnumerable< T >, IEnumerable< Symbol > > | ConvertPythonUniverseFilterFunction< T > (this PyObject universeFilterFunc) |
Converts a Python function to a managed function returning a Symbol More... | |
static Func< IEnumerable< T >, IEnumerable< Symbol > > | ConvertToUniverseSelectionSymbolDelegate< T > (this Func< IEnumerable< T >, object > selector) |
Wraps the provided universe selection selector checking if it returned Universe.Unchanged and returns it instead, else enumerates result as IEnumerable<Symbol> More... | |
static Func< T, IEnumerable< Symbol > > | ConvertSelectionSymbolDelegate< T > (this Func< T, object > selector) |
Wraps the provided universe selection selector checking if it returned Universe.Unchanged and returns it instead, else enumerates result as IEnumerable<Symbol> More... | |
static Func< T, IEnumerable< string > > | ConvertToUniverseSelectionStringDelegate< T > (this Func< T, object > selector) |
Wraps the provided universe selection selector checking if it returned Universe.Unchanged and returns it instead, else enumerates result as IEnumerable<String> More... | |
static T | ConvertToDelegate< T > (this PyObject pyObject) |
Convert a PyObject into a managed object More... | |
static Dictionary< TKey, TValue > | ConvertToDictionary< TKey, TValue > (this PyObject pyObject) |
Convert a PyObject into a managed dictionary More... | |
static IEnumerable< Symbol > | ConvertToSymbolEnumerable (this PyObject pyObject) |
Gets Enumerable of Symbol from a PyObject More... | |
static PyList | ToPyList (this IEnumerable enumerable) |
Converts an IEnumerable to a PyList More... | |
static PyList | ToPyListUnSafe (this IEnumerable enumerable) |
Converts an IEnumerable to a PyList More... | |
static string | GetEnumString (this int value, PyObject pyObject) |
Converts the numeric value of one or more enumerated constants to an equivalent enumerated string. More... | |
static bool | TryCreateType (this PyObject pyObject, out Type type) |
Try to create a type with a given name, if PyObject is not a CLR type. Otherwise, convert it. More... | |
static Type | CreateType (this PyObject pyObject) |
Creates a type with a given name, if PyObject is not a CLR type. Otherwise, convert it. More... | |
static AssemblyName | GetAssemblyName (this PyObject pyObject) |
Helper method to get the assembly name from a python type More... | |
static IEnumerable< List< T > > | BatchBy< T > (this IEnumerable< T > enumerable, int batchSize) |
Performs on-line batching of the specified enumerator, emitting chunks of the requested batch size More... | |
static TResult | SynchronouslyAwaitTaskResult< TResult > (this Task< TResult > task) |
Safely blocks until the specified task has completed executing More... | |
static void | SynchronouslyAwaitTask (this Task task) |
Safely blocks until the specified task has completed executing More... | |
static T | SynchronouslyAwaitTask< T > (this Task< T > task) |
Safely blocks until the specified task has completed executing More... | |
static string | ToQueryString (this IDictionary< string, object > pairs) |
Convert dictionary to query string More... | |
static string | RemoveFromEnd (this string s, string ending) |
Returns a new string in which specified ending in the current instance is removed. More... | |
static string | RemoveFromStart (this string s, string start) |
Returns a new string in which specified start in the current instance is removed. More... | |
static bool | TryGetLiveSubscriptionSymbol (this Symbol symbol, out Symbol mapped) |
Helper method to determine symbol for a live subscription More... | |
static DateTime | GetDelistingDate (this Symbol symbol, MapFile mapFile=null) |
Gets the delisting date for the provided Symbol More... | |
static bool | IsCustomDataType< T > (this Symbol symbol) |
Helper method to determine if a given symbol is of custom data More... | |
static Symbol | AdjustSymbolByOffset (this Symbol symbol, uint offset) |
Helper method that will return a back month, with future expiration, future contract based on the given offset More... | |
static void | UnsubscribeWithMapping (this IDataQueueHandler dataQueueHandler, SubscriptionDataConfig dataConfig) |
Helper method to unsubscribe a given configuration, handling any required mapping More... | |
static IEnumerator< BaseData > | SubscribeWithMapping (this IDataQueueHandler dataQueueHandler, SubscriptionDataConfig dataConfig, EventHandler newDataAvailableHandler, Func< SubscriptionDataConfig, bool > isExpired, out SubscriptionDataConfig subscribedConfig) |
Helper method to subscribe a given configuration, handling any required mapping More... | |
static IEnumerable< string > | ReadLines (this IDataProvider dataProvider, string file) |
Helper method to stream read lines from a file More... | |
static BaseData | Scale (this BaseData data, Func< decimal, decimal, decimal, decimal > factorFunc, decimal volumeFactor, decimal factor, decimal sumOfDividends) |
Scale data based on factor function More... | |
static BaseData | Normalize (this BaseData data, decimal factor, DataNormalizationMode normalizationMode, decimal sumOfDividends) |
Normalize prices based on configuration More... | |
static DateTime | GetUpdatePriceScaleFrontier (this BaseData data) |
Helper method to determine if price scales need an update based on the given data point More... | |
static IOrderedEnumerable< KeyValuePair< TSource, TKey > > | OrderBySafe< TSource, TKey > (this ConcurrentDictionary< TSource, TKey > source, Func< KeyValuePair< TSource, TKey >, TSource > keySelector) |
Thread safe concurrent dictionary order by implementation by using SafeEnumeration<TSource,TKey> More... | |
static IOrderedEnumerable< KeyValuePair< TSource, TKey > > | OrderBySafe< TSource, TKey > (this ConcurrentDictionary< TSource, TKey > source, Func< KeyValuePair< TSource, TKey >, TKey > keySelector) |
Thread safe concurrent dictionary order by implementation by using SafeEnumeration<TSource,TKey> More... | |
static IEnumerable< KeyValuePair< TSource, TKey > > | SafeEnumeration< TSource, TKey > (this ConcurrentDictionary< TSource, TKey > source) |
Force concurrent dictionary enumeration using a thread safe implementation More... | |
static DataNormalizationMode | GetUniverseNormalizationModeOrDefault (this UniverseSettings universeSettings, SecurityType securityType) |
Helper method to determine the right data normalization mode to use by default More... | |
static string | ToHexString (this byte[] source) |
Returns a hex string of the byte array. More... | |
static OrderDirection | GetExerciseDirection (this OptionRight right, bool isShort) |
Gets the option exercise order direction resulting from the specified right and whether or not we wrote the option (isShort is More... | |
static OrderDirection | GetOrderDirection (decimal quantity) |
Gets the OrderDirection for the specified quantity More... | |
static void | ProcessSecurityChanges (this IAlgorithm algorithm, SecurityChanges securityChanges) |
Helper method to process an algorithms security changes, will add and remove securities according to them More... | |
static void | SetRuntimeError (this IAlgorithm algorithm, Exception exception, string context) |
Helper method to set an algorithm runtime exception in a normalized fashion More... | |
static OptionChainUniverse | CreateOptionChain (this IAlgorithm algorithm, Symbol symbol, PyObject filter, UniverseSettings universeSettings=null) |
Creates a OptionChainUniverse for a given symbol More... | |
static OptionChainUniverse | CreateOptionChain (this IAlgorithm algorithm, Symbol symbol, Func< OptionFilterUniverse, OptionFilterUniverse > filter, UniverseSettings universeSettings=null) |
Creates a OptionChainUniverse for a given symbol More... | |
static IEnumerable< Universe > | CreateFutureChain (this IAlgorithm algorithm, Symbol symbol, PyObject filter, UniverseSettings universeSettings=null) |
Creates a FuturesChainUniverse for a given symbol More... | |
static IEnumerable< Universe > | CreateFutureChain (this IAlgorithm algorithm, Symbol symbol, Func< FutureFilterUniverse, FutureFilterUniverse > filter, UniverseSettings universeSettings=null) |
Creates a FuturesChainUniverse for a given symbol More... | |
static bool | GetOrAddUnrequestedSecurity (this IAlgorithm algorithm, Symbol symbol, out Security security, Action< IReadOnlyCollection< SecurityType >> onError=null) |
Gets the security for the specified symbol from the algorithm's securities collection. In case the security is not found, it will be created using the IAlgorithm.UniverseSettings and a best effort configuration setup. More... | |
static OptionRight | Invert (this OptionRight right) |
Inverts the specified right More... | |
static bool | Compare< T > (this ComparisonOperatorTypes op, T arg1, T arg2) |
Compares two values using given operator More... | |
static SubscriptionDataConfig | ToSubscriptionDataConfig (this Data.HistoryRequest request, bool isInternalFeed=false, bool isFilteredSubscription=true) |
Converts a Data.HistoryRequest instance to a SubscriptionDataConfig instance More... | |
static bool | ShouldEmitData (this SubscriptionDataConfig config, BaseData data, bool isUniverse=false) |
Centralized logic used at the top of the subscription enumerator stacks to determine if we should emit base data points based on the configuration for this subscription and the type of data we are handling. More... | |
static OrderDirection | ToOrderDirection (this PositionSide side) |
Gets the OrderDirection that corresponds to the specified side More... | |
static bool | Closes (this OrderDirection direction, PositionSide side) |
Determines if an order with the specified direction would close a position with the specified side More... | |
static bool | ListEquals< T > (this IReadOnlyList< T > left, IReadOnlyList< T > right) |
Determines if the two lists are equal, including all items at the same indices. More... | |
static int | GetListHashCode< T > (this IReadOnlyList< T > list) |
Computes a deterministic hash code based on the items in the list. This hash code is dependent on the ordering of items. More... | |
static bool | RequiresMapping (this Symbol symbol) |
Determine if this SecurityType requires mapping More... | |
static bool | IsWin (this OrderEvent fill, Security security, decimal profitLoss) |
Checks whether the fill event for closing a trade is a winning trade More... | |
static ConvertibleCashAmount | InTheMoneyAmount (this Option option, decimal quantity) |
Gets the option's ITM amount for the given quantity. More... | |
static int | GreatestCommonDivisor (this IEnumerable< int > values) |
Gets the greatest common divisor of a list of numbers More... | |
static decimal | SafeDivision (this decimal numerator, decimal denominator, decimal failValue=0) |
Safe method to perform divisions avoiding DivideByZeroException and Overflow/Underflow exceptions More... | |
static Type | GetCustomDataTypeFromSymbols (Symbol[] symbols) |
static bool | IsCustomDataType (Symbol symbol, Type type) |
Determines if certain data type is custom More... | |
static CashAmount | GetMarketOrderFees (Security security, decimal quantity, DateTime time, out MarketOrder marketOrder) |
Returns the amount of fee's charged by executing a market order with the given arguments More... | |
Properties | |
static TimeSpan | DelistingMarketCloseOffsetSpan = TimeSpan.FromMinutes(-15) [get, set] |
The offset span from the market close to liquidate or exercise a security on the delisting date More... | |
Extensions function collections - group all static extensions functions here.
Definition at line 69 of file Extensions.cs.
|
static |
Helper method to get a property in a jobject if available
T | The property type |
jObject | The jobject source |
name | The property name |
Definition at line 106 of file Extensions.cs.
|
static |
Determine if the file is out of date according to our download period. Date based files are never out of date (Files with YYYYMMDD)
filepath | Path to the file |
Definition at line 128 of file Extensions.cs.
|
static |
Helper method to check if a directory exists and is not empty
directoryPath | The path to check |
Will cache results
Definition at line 141 of file Extensions.cs.
|
static |
Helper method to get a market hours entry
marketHoursDatabase | The market hours data base instance |
symbol | The symbol to get the entry for |
dataTypes | For custom data types can optionally provide data type so that a new entry is added |
Definition at line 178 of file Extensions.cs.
|
static |
Helper method to deserialize a json array into a list also handling single json values
jsonArray | The value to deserialize |
Definition at line 212 of file Extensions.cs.
|
static |
Helper method to deserialize a json array into a list also handling single json values
jsonArray | The value to deserialize |
Definition at line 221 of file Extensions.cs.
|
static |
Helper method to download a provided url as a string
client | The http client to use |
url | The url to download data from |
headers | Add custom headers for the request |
Definition at line 252 of file Extensions.cs.
|
static |
Helper method to download a provided url as a string
url | The url to download data from |
headers | Add custom headers for the request |
Definition at line 283 of file Extensions.cs.
|
static |
Helper method to download a provided url as a byte array
url | The url to download data from |
Definition at line 293 of file Extensions.cs.
|
static |
Safe multiplies a decimal by 100
value | The decimal to multiply |
Definition at line 314 of file Extensions.cs.
|
static |
Will return a memory stream using the RecyclableMemoryStreamManager instance.
guid | Unique guid |
Definition at line 327 of file Extensions.cs.
|
static |
Serialize a list of ticks using protobuf
ticks | The list of ticks to serialize |
guid | Unique guid |
Definition at line 338 of file Extensions.cs.
|
static |
Serialize a base data instance using protobuf
baseData | The data point to serialize |
guid | Unique guid |
Definition at line 355 of file Extensions.cs.
|
static |
Serialize a base data instance using protobuf
baseData | The data point to serialize |
stream | The destination stream |
Definition at line 372 of file Extensions.cs.
|
static |
Extension method to get security price is 0 messages for users
The value of this method is normalization
Definition at line 395 of file Extensions.cs.
|
static |
Converts the provided string into camel case notation
Definition at line 403 of file Extensions.cs.
|
static |
Helper method to batch a collection of AlphaResultPacket into 1 single instance. Will return null if the provided list is empty. Will keep the last Order instance per order id, which is the latest. Implementations trusts the provided 'resultPackets' list to batch is in order
Definition at line 422 of file Extensions.cs.
|
static |
Helper method to safely stop a running thread
thread | The thread to stop |
timeout | The timeout to wait till the thread ends after which abort will be called |
token | Cancellation token source to use if any |
Definition at line 483 of file Extensions.cs.
|
static |
Generates a hash code from a given collection of orders
orders | The order collection |
Definition at line 513 of file Extensions.cs.
|
static |
Converts a date rule into a function that receives current time and returns the next date.
dateRule | The date rule to convert |
Definition at line 565 of file Extensions.cs.
|
static |
Returns true if the specified BaseSeries instance holds no ISeriesPoint
Definition at line 602 of file Extensions.cs.
|
static |
Returns if the specified Chart instance holds no Series or they are all empty Extensions.IsEmpty(BaseSeries)
Definition at line 611 of file Extensions.cs.
|
static |
Gets a python method by name
instance | The object instance to search the method in |
name | The name of the method |
Definition at line 622 of file Extensions.cs.
|
static |
Gets a python property by name
instance | The object instance to search the property in |
name | The name of the property |
Definition at line 658 of file Extensions.cs.
|
static |
Gets a python property by name
instance | The object instance to search the property in |
name | The name of the method |
Definition at line 687 of file Extensions.cs.
|
static |
Gets a python method by name
instance | The object instance to search the method in |
name | The name of the method |
Definition at line 706 of file Extensions.cs.
|
static |
Gets a method from a PyObject instance by name. First, it tries to get the snake-case version of the method name, in case the user is using that style. Else, it tries to get the method with the original name, regardless of whether the class has a Python overload or not.
instance | The object instance to search the method in |
name | The name of the method |
Definition at line 727 of file Extensions.cs.
|
static |
Get a python methods arg count
method | The Python method |
Definition at line 738 of file Extensions.cs.
|
static |
Returns an ordered enumerable where position reducing orders are executed first and the remaining orders are executed in decreasing order value. Will NOT return targets during algorithm warmup. Will NOT return targets for securities that have no data yet. Will NOT return targets for which current holdings + open orders quantity, sum up to the target quantity
targets | The portfolio targets to order by margin |
algorithm | The algorithm instance |
targetIsDelta | True if the target quantity is the delta between the desired and existing quantity |
Definition at line 765 of file Extensions.cs.
|
static |
Given a type will create a new instance using the parameterless constructor and assert the type implements BaseData
One of the objectives of this method is to normalize the creation of the BaseData instances while reducing code duplication
Definition at line 810 of file Extensions.cs.
|
static |
Helper method that will cast the provided PyObject to a T type and dispose of it.
T | The target type |
instance | The PyObject instance to cast and dispose |
Definition at line 843 of file Extensions.cs.
|
static |
Extension to move one element from list from A to position B.
T | Type of list |
list | List we're operating on. |
oldIndex | Index of variable we want to move. |
newIndex | New location for the variable |
Definition at line 862 of file Extensions.cs.
|
static |
Extension method to convert a string into a byte array
str | String to convert to bytes. |
Definition at line 875 of file Extensions.cs.
|
static |
Reads the entire content of a stream and returns it as a byte array.
stream | Stream to read bytes from |
Definition at line 887 of file Extensions.cs.
|
static |
Extentsion method to clear all items from a thread safe queue
Small risk of race condition if a producer is adding to the list.
T | Queue type |
queue | queue object |
Definition at line 900 of file Extensions.cs.
|
static |
Extension method to convert a byte array into a string.
bytes | Byte array to convert. |
encoding | The encoding to use for the conversion. Defaults to Encoding.ASCII |
Definition at line 914 of file Extensions.cs.
|
static |
Extension method to convert a string to a MD5 hash.
str | String we want to MD5 encode. |
Definition at line 926 of file Extensions.cs.
|
static |
Encrypt the token:time data to make our API hash.
data | Data to be hashed by SHA256 |
Definition at line 945 of file Extensions.cs.
|
static |
Converts a long to an uppercase alpha numeric string
Definition at line 962 of file Extensions.cs.
|
static |
Converts an upper case alpha numeric string into a long
Definition at line 981 of file Extensions.cs.
|
static |
Convert a string to Base64 Encoding
text | Text to encode |
Definition at line 1006 of file Extensions.cs.
|
static |
Decode a Base64 Encoded string
base64EncodedText | Text to decode |
Definition at line 1022 of file Extensions.cs.
|
static |
Lazy string to upper implementation. Will first verify the string is not already upper and avoid the call to string.ToUpperInvariant() if possible.
data | The string to upper |
Definition at line 1040 of file Extensions.cs.
|
static |
Lazy string to lower implementation. Will first verify the string is not already lower and avoid the call to string.ToLowerInvariant() if possible.
data | The string to lower |
Definition at line 1058 of file Extensions.cs.
|
static |
Extension method to automatically set the update value to same as "add" value for TryAddUpdate. This makes the API similar for traditional and concurrent dictionaries.
K | Key type for dictionary |
V | Value type for dictonary |
dictionary | Dictionary object we're operating on |
key | Key we want to add or update. |
value | Value we want to set. |
Definition at line 1078 of file Extensions.cs.
|
static |
Extension method to automatically add/update lazy values in concurrent dictionary.
TKey | Key type for dictionary |
TValue | Value type for dictonary |
dictionary | Dictionary object we're operating on |
key | Key we want to add or update. |
addValueFactory | The function used to generate a value for an absent key |
updateValueFactory | The function used to generate a new value for an existing key based on the key's existing value |
Definition at line 1092 of file Extensions.cs.
|
static |
Adds the specified element to the collection with the specified key. If an entry does not exist for the specified key then one will be created.
TKey | The key type |
TElement | The collection element type |
TCollection | The collection type |
dictionary | The source dictionary to be added to |
key | The key |
element | The element to be added |
TCollection | : | ICollection<TElement> | |
TCollection | : | new() |
Definition at line 1108 of file Extensions.cs.
|
static |
Adds the specified element to the collection with the specified key. If an entry does not exist for the specified key then one will be created.
TKey | The key type |
TElement | The collection element type |
dictionary | The source dictionary to be added to |
key | The key |
element | The element to be added |
Definition at line 1129 of file Extensions.cs.
|
static |
Adds the specified element to the collection with the specified key. If an entry does not exist for the specified key then one will be created.
TKey | The key type |
TElement | The collection element type |
dictionary | The source dictionary to be added to |
key | The key |
element | The element to be added |
Definition at line 1154 of file Extensions.cs.
Adds the specified Tick to the Ticks collection. If an entry does not exist for the specified key then one will be created.
dictionary | The ticks dictionary |
key | The symbol |
tick | The tick to add |
For performance we implement this method based on Add<TKey,TElement,TCollection>
Definition at line 1177 of file Extensions.cs.
|
static |
Extension method to round a double value to a fixed number of significant figures instead of a fixed decimal places.
d | Double we're rounding |
digits | Number of significant figures |
Definition at line 1193 of file Extensions.cs.
|
static |
Converts a decimal into a rounded number ending with K (thousands), M (millions), B (billions), etc.
number | Number to convert |
Definition at line 1205 of file Extensions.cs.
|
static |
Discretizes the value to a maximum precision specified by quanta . Quanta can be an arbitrary positive number and represents the step size. Consider a quanta equal to 0.15 and rounding a value of 1.0. Valid values would be 0.9 (6 quanta) and 1.05 (7 quanta) which would be rounded up to 1.05.
value | The value to be rounded by discretization |
quanta | The maximum precision allowed by the value |
mode | Specifies how to handle the rounding of half value, defaulting to away from zero. |
Definition at line 1255 of file Extensions.cs.
|
static |
Will truncate the provided decimal, without rounding, to 3 decimal places
value | The value to truncate |
Definition at line 1274 of file Extensions.cs.
|
static |
Provides global smart rounding, numbers larger than 1000 will round to 4 decimal places, while numbers smaller will round to 7 significant digits
Definition at line 1291 of file Extensions.cs.
|
static |
Provides global smart rounding, numbers larger than 1000 will round to 4 decimal places, while numbers smaller will round to 7 significant digits
Definition at line 1304 of file Extensions.cs.
|
static |
Casts the specified input value to a decimal while acknowledging the overflow conditions
input | The value to be cast |
Definition at line 1325 of file Extensions.cs.
|
static |
Will remove any trailing zeros for the provided decimal input
input | The decimal to remove trailing zeros from |
Will not have the expected behavior when called from Python, since the returned decimal will be converted to python float, NormalizeToStr
Definition at line 1349 of file Extensions.cs.
|
static |
Will remove any trailing zeros for the provided decimal and convert to string. Uses Normalize(decimal).
input | The decimal to convert to string |
Definition at line 1361 of file Extensions.cs.
|
static |
Helper method to determine the amount of decimal places associated with the given decimal
input | The value to get the decimal count from |
Definition at line 1371 of file Extensions.cs.
|
static |
Extension method for faster string to decimal conversion.
str | String to be converted to positive decimal value |
Leading and trailing whitespace chars are ignored
Definition at line 1384 of file Extensions.cs.
|
static |
Extension method for faster string to normalized decimal conversion, i.e. 20.0% should be parsed into 0.2
str | String to be converted to positive decimal value |
Leading and trailing whitespace chars are ignored
Definition at line 1435 of file Extensions.cs.
|
static |
Extension method for string to decimal conversion where string can represent a number with exponent xe-y
str | String to be converted to decimal value |
Definition at line 1452 of file Extensions.cs.
|
static |
Extension method for faster string to Int32 conversion.
str | String to be converted to positive Int32 value |
Method makes some assuptions - always numbers, no "signs" +,- etc.
Definition at line 1463 of file Extensions.cs.
|
static |
Extension method for faster string to Int64 conversion.
str | String to be converted to positive Int64 value |
Method makes some assuptions - always numbers, no "signs" +,- etc.
Definition at line 1482 of file Extensions.cs.
|
static |
Helper method to determine if a data type implements the Stream reader method
Definition at line 1498 of file Extensions.cs.
|
static |
Breaks the specified string into csv components, all commas are considered separators
str | The string to be broken into csv |
size | The expected size of the output list |
Definition at line 1521 of file Extensions.cs.
|
static |
Breaks the specified string into csv components, works correctly with commas in data fields
str | The string to be broken into csv |
size | The expected size of the output list |
delimiter | The delimiter used to separate entries in the line |
Definition at line 1546 of file Extensions.cs.
|
static |
Gets the value at the specified index from a CSV line.
csvLine | The CSV line |
index | The index of the value to be extracted from the CSV line |
result | The value at the given index |
Definition at line 1585 of file Extensions.cs.
|
static |
Gets the value at the specified index from a CSV line, converted into a decimal.
csvLine | The CSV line |
index | The index of the value to be extracted from the CSV line |
value | The decimal value at the given index |
Definition at line 1622 of file Extensions.cs.
|
static |
Gets the value at the specified index from a CSV line, converted into a decimal.
csvLine | The CSV line |
index | The index of the value to be extracted from the CSV line |
Definition at line 1640 of file Extensions.cs.
|
static |
Check if a number is NaN or infinity
value | The double value to check |
Definition at line 1651 of file Extensions.cs.
|
static |
Check if a number is NaN or equal to zero
value | The double value to check |
Definition at line 1661 of file Extensions.cs.
|
static |
Gets the smallest positive number that can be added to a decimal instance and return a new value that does not == the old value
Definition at line 1670 of file Extensions.cs.
|
static |
Extension method to extract the extension part of this file name if it matches a safe list, or return a ".custom" extension for ones which do not match.
str | String we're looking for the extension for. |
Definition at line 1680 of file Extensions.cs.
|
static |
Extension method to convert strings to stream to be read.
str | String to convert to stream |
Definition at line 1695 of file Extensions.cs.
|
static |
Extension method to round a timeSpan to nearest timespan period.
time | TimeSpan To Round |
roundingInterval | Rounding Unit |
roundingType | Rounding method |
Definition at line 1712 of file Extensions.cs.
|
static |
Extension method to round timespan to nearest timespan period.
time | Base timespan we're looking to round. |
roundingInterval | Timespan period we're rounding. |
Definition at line 1735 of file Extensions.cs.
|
static |
Extension method to round a datetime down by a timespan interval.
dateTime | Base DateTime object we're rounding down. |
interval | Timespan interval to round to |
Using this with timespans greater than 1 day may have unintended consequences. Be aware that rounding occurs against ALL time, so when using timespan such as 30 days we will see 30 day increments but it will be based on 30 day increments from the beginning of time.
Definition at line 1751 of file Extensions.cs.
|
static |
Rounds the specified date time in the specified time zone. Careful with calling this method in a loop while modifying dateTime, check unit tests.
dateTime | Date time to be rounded |
roundingInterval | Timespan rounding period |
sourceTimeZone | Time zone of the date time |
roundingTimeZone | Time zone in which the rounding is performed |
Definition at line 1776 of file Extensions.cs.
|
static |
Extension method to round a datetime down by a timespan interval until it's within the specified exchange's open hours. This works by first rounding down the specified time using the interval, then producing a bar between that rounded time and the interval plus the rounded time and incrementally walking backwards until the exchange is open
dateTime | Time to be rounded down |
interval | Timespan interval to round to. |
exchangeHours | The exchange hours to determine open times |
extendedMarketHours | True for extended market hours, otherwise false |
Definition at line 1796 of file Extensions.cs.
|
static |
Extension method to round a datetime down by a timespan interval until it's within the specified exchange's open hours. The rounding is performed in the specified time zone
dateTime | Time to be rounded down |
interval | Timespan interval to round to. |
exchangeHours | The exchange hours to determine open times |
roundingTimeZone | The time zone to perform the rounding in |
extendedMarketHours | True for extended market hours, otherwise false |
Definition at line 1821 of file Extensions.cs.
|
static |
Helper method to determine if a specific market is open
security | The target security |
extendedMarketHours | True if should consider extended market hours |
Definition at line 1850 of file Extensions.cs.
|
static |
Helper method to determine if a specific market is open
symbol | The target symbol |
utcTime | The current UTC time |
extendedMarketHours | True if should consider extended market hours |
Definition at line 1862 of file Extensions.cs.
|
static |
Extension method to round a datetime to the nearest unit timespan.
datetime | Datetime object we're rounding. |
roundingInterval | Timespan rounding period. |
Definition at line 1878 of file Extensions.cs.
|
static |
Extension method to explicitly round up to the nearest timespan interval.
time | Base datetime object to round up. |
interval | Timespan interval to round to |
Using this with timespans greater than 1 day may have unintended consequences. Be aware that rounding occurs against ALL time, so when using timespan such as 30 days we will see 30 day increments but it will be based on 30 day increments from the beginning of time.
Definition at line 1893 of file Extensions.cs.
|
static |
Converts the specified time from the from time zone to the to time zone
time | The time to be converted in terms of the from time zone |
from | The time zone the specified time is in |
to | The time zone to be converted to |
strict | True for strict conversion, this will throw during ambiguitities, false for lenient conversion |
Definition at line 1913 of file Extensions.cs.
|
static |
Converts the specified time from UTC to the to time zone
time | The time to be converted expressed in UTC |
to | The destinatio time zone |
strict | True for strict conversion, this will throw during ambiguitities, false for lenient conversion |
Definition at line 1934 of file Extensions.cs.
|
static |
Converts the specified time from the from time zone to TimeZones.Utc
time | The time to be converted in terms of the from time zone |
from | The time zone the specified time is in |
strict | True for strict conversion, this will throw during ambiguitities, false for lenient conversion |
Definition at line 1947 of file Extensions.cs.
|
static |
Business day here is defined as any day of the week that is not saturday or sunday
date | The date to be examined |
Definition at line 1965 of file Extensions.cs.
|
static |
Add the reset method to the System.Timer class.
timer | System.timer object |
Definition at line 1974 of file Extensions.cs.
|
static |
Function used to match a type against a string type name. This function compares on the AssemblyQualfiedName, the FullName, and then just the Name of the type.
type | The type to test for a match |
typeName | The name of the type to match |
Definition at line 1987 of file Extensions.cs.
|
static |
Checks the specified type to see if it is a subclass of the possibleSuperType . This method will crawl up the inheritance heirarchy to check for equality using generic type definitions (if exists)
type | The type to be checked as a subclass of possibleSuperType |
possibleSuperType | The possible superclass of type |
Definition at line 2011 of file Extensions.cs.
|
static |
Gets a type's name with the generic parameters filled in the way they would look when defined in code, such as converting Dictionary<1,
2> to Dictionary<string,int>
type | The type who's name we seek |
Definition at line 2039 of file Extensions.cs.
|
static |
Converts the Resolution instance into a TimeSpan instance
resolution | The resolution to be converted |
Definition at line 2057 of file Extensions.cs.
|
static |
Converts the specified time span into a resolution enum value. If an exact match is not found and requireExactMatch
is false, then the higher resoluion will be returned. For example, timeSpan=5min will return Minute resolution.
timeSpan | The time span to convert to resolution |
requireExactMatch | True to throw an exception if an exact match is not found |
Definition at line 2085 of file Extensions.cs.
|
static |
Attempts to convert the string into a SecurityType enum value
value | string value to convert to SecurityType |
securityType | SecurityType output |
ignoreCase | Ignore casing |
Logs once if we've encountered an invalid SecurityType
Definition at line 2116 of file Extensions.cs.
|
static |
Converts the specified string value into the specified type
T | The output type |
value | The string value to be converted |
Definition at line 2138 of file Extensions.cs.
|
static |
Converts the specified string value into the specified type
value | The string value to be converted |
type | The output type |
Definition at line 2149 of file Extensions.cs.
|
static |
Blocks the current thread until the current T:System.Threading.WaitHandle receives a signal, while observing a T:System.Threading.CancellationToken.
waitHandle | The wait handle to wait on |
cancellationToken | The T:System.Threading.CancellationToken to observe. |
T:System.InvalidOperationException | The maximum number of waiters has been exceeded. |
T:System.OperationCanceledExcepton | cancellationToken was canceled. |
T:System.ObjectDisposedException | The object has already been disposed or the T:System.Threading.CancellationTokenSource that created cancellationToken has been disposed. |
Definition at line 2180 of file Extensions.cs.
|
static |
Blocks the current thread until the current T:System.Threading.WaitHandle is set, using a T:System.TimeSpan to measure the time interval, while observing a T:System.Threading.CancellationToken.
waitHandle | The wait handle to wait on |
timeout | A T:System.TimeSpan that represents the number of milliseconds to wait, or a T:System.TimeSpan that represents -1 milliseconds to wait indefinitely. |
cancellationToken | The T:System.Threading.CancellationToken to observe. |
T:System.Threading.OperationCanceledException | cancellationToken was canceled. |
T:System.ArgumentOutOfRangeException | timeout is a negative number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater than F:System.Int32.MaxValue. |
T:System.InvalidOperationException | The maximum number of waiters has been exceeded. |
T:System.ObjectDisposedException | The object has already been disposed or the T:System.Threading.CancellationTokenSource that created cancellationToken has been disposed. |
Definition at line 2198 of file Extensions.cs.
|
static |
Blocks the current thread until the current T:System.Threading.WaitHandle is set, using a 32-bit signed integer to measure the time interval, while observing a T:System.Threading.CancellationToken.
waitHandle | The wait handle to wait on |
millisecondsTimeout | The number of milliseconds to wait, or F:System.Threading.Timeout.Infinite(-1) to wait indefinitely. |
cancellationToken | The T:System.Threading.CancellationToken to observe. |
T:System.Threading.OperationCanceledException | cancellationToken was canceled. |
T:System.ArgumentOutOfRangeException | millisecondsTimeout is a negative number other than -1, which represents an infinite time-out. |
T:System.InvalidOperationException | The maximum number of waiters has been exceeded. |
T:System.ObjectDisposedException | The object has already been disposed or the T:System.Threading.CancellationTokenSource that created cancellationToken has been disposed. |
Definition at line 2217 of file Extensions.cs.
|
static |
Gets the MD5 hash from a stream
stream | The stream to compute a hash for |
Definition at line 2227 of file Extensions.cs.
|
static |
Convert a string into the same string with a URL! :)
source | The source string to be converted |
Definition at line 2240 of file Extensions.cs.
|
static |
Get the first occurence of a string between two characters from another string
value | The original string |
left | Left bound of the substring |
right | Right bound of the substring |
Definition at line 2258 of file Extensions.cs.
|
static |
Return the first in the series of names, or find the one that matches the configured algorithmTypeName
names | The list of class names |
algorithmTypeName | The configured algorithm type name from the config |
Definition at line 2277 of file Extensions.cs.
|
static |
Converts the specified enum value to its corresponding lower-case string representation
enum | The enumeration value |
Definition at line 2294 of file Extensions.cs.
|
static |
Asserts the specified securityType value is valid
This method provides faster performance than Enum.IsDefined which uses reflection
securityType | The SecurityType value |
Definition at line 2305 of file Extensions.cs.
|
static |
Determines if the provided SecurityType is a type of Option. Valid option types are: Equity Options, Futures Options, and Index Options.
securityType | The SecurityType to check if it's an option asset |
Definition at line 2336 of file Extensions.cs.
|
static |
Determines if the provided SecurityType has a matching option SecurityType, used to represent the current SecurityType as a derivative.
securityType | The SecurityType to check if it has options available |
Definition at line 2356 of file Extensions.cs.
|
static |
Gets the default OptionStyle for the provided SecurityType
securityType | SecurityType to get default OptionStyle for |
ArgumentException | The SecurityType has no options available for it or it is not an option |
Definition at line 2376 of file Extensions.cs.
|
static |
Converts the specified string to its corresponding OptionStyle
This method provides faster performance than enum parse
optionStyle | The OptionStyle string value |
Definition at line 2400 of file Extensions.cs.
|
static |
Converts the specified string to its corresponding OptionRight
This method provides faster performance than enum parse
optionRight | The optionRight string value |
Definition at line 2419 of file Extensions.cs.
|
static |
Converts the specified optionRight value to its corresponding string representation
This method provides faster performance than enum Object.ToString
optionRight | The optionRight value |
Definition at line 2438 of file Extensions.cs.
|
static |
Converts the specified optionRight value to its corresponding lower-case string representation
This method provides faster performance than ToLower
optionRight | The optionRight value |
Definition at line 2458 of file Extensions.cs.
|
static |
Converts the specified optionStyle value to its corresponding lower-case string representation
This method provides faster performance than ToLower
optionStyle | The optionStyle value |
Definition at line 2477 of file Extensions.cs.
|
static |
Converts the specified string to its corresponding DataMappingMode
This method provides faster performance than enum parse
dataMappingMode | The dataMappingMode string value |
Definition at line 2496 of file Extensions.cs.
|
static |
Converts the specified securityType value to its corresponding lower-case string representation
This method provides faster performance than ToLower
securityType | The SecurityType value |
Definition at line 2527 of file Extensions.cs.
|
static |
Converts the specified tickType value to its corresponding lower-case string representation
This method provides faster performance than ToLower
tickType | The tickType value |
Definition at line 2567 of file Extensions.cs.
|
static |
Converts the specified resolution value to its corresponding lower-case string representation
This method provides faster performance than ToLower
resolution | The resolution value |
Definition at line 2589 of file Extensions.cs.
|
static |
Turn order into an order ticket
order | The Order being converted |
transactionManager | The transaction manager, SecurityTransactionManager |
Definition at line 2615 of file Extensions.cs.
|
static |
Process all items in collection through given handler
T |
collection | Collection to process |
handler | Handler to process those items with |
Definition at line 2694 of file Extensions.cs.
|
static |
Returns a string that represents the current PyObject
pyObject | The PyObject being converted |
Definition at line 2708 of file Extensions.cs.
|
static |
Tries to convert a PyObject into a managed object
This method is not working correctly for a wrapped TimeSpan instance, probably because it is a struct, using PyObject.As<T> is a valid work around. Not used here because it caused errors
T | Target type of the resulting managed object |
pyObject | PyObject to be converted |
result | Managed object |
allowPythonDerivative | True will convert python subclasses of T |
Definition at line 2755 of file Extensions.cs.
|
static |
Tries to convert a PyObject into a managed object
T | Target type of the resulting managed object |
pyObject | PyObject to be converted |
result | Managed object |
Definition at line 2851 of file Extensions.cs.
|
static |
Safely convert PyObject to ManagedObject using Py.GIL Lock If no type is given it will convert the PyObject's Python Type to a ManagedObject Type in a attempt to resolve the target type to convert to.
pyObject | PyObject to convert to managed |
typeToConvertTo | The target type to convert to |
Definition at line 2916 of file Extensions.cs.
|
static |
Converts a Python function to a managed function returning a Symbol
universeFilterFunc | Universe filter function from Python |
T | : | BaseData |
Definition at line 2934 of file Extensions.cs.
|
static |
Wraps the provided universe selection selector checking if it returned Universe.Unchanged and returns it instead, else enumerates result as IEnumerable<Symbol>
This method is a work around for the fact that currently we can not create a delegate which returns an IEnumerable<Symbol> from a python method returning an array, plus the fact that Universe.Unchanged can not be cast to an array
T | : | BaseData |
Definition at line 2954 of file Extensions.cs.
|
static |
Wraps the provided universe selection selector checking if it returned Universe.Unchanged and returns it instead, else enumerates result as IEnumerable<Symbol>
This method is a work around for the fact that currently we can not create a delegate which returns an IEnumerable<Symbol> from a python method returning an array, plus the fact that Universe.Unchanged can not be cast to an array
Definition at line 2970 of file Extensions.cs.
|
static |
Wraps the provided universe selection selector checking if it returned Universe.Unchanged and returns it instead, else enumerates result as IEnumerable<String>
This method is a work around for the fact that currently we can not create a delegate which returns an IEnumerable<String> from a python method returning an array, plus the fact that Universe.Unchanged can not be cast to an array
Definition at line 2995 of file Extensions.cs.
|
static |
Convert a PyObject into a managed object
T | Target type of the resulting managed object |
pyObject | PyObject to be converted |
Definition at line 3011 of file Extensions.cs.
|
static |
Convert a PyObject into a managed dictionary
TKey | Target type of the resulting dictionary key |
TValue | Target type of the resulting dictionary value |
pyObject | PyObject to be converted |
Definition at line 3031 of file Extensions.cs.
|
static |
Gets Enumerable of Symbol from a PyObject
pyObject | PyObject containing Symbol or Array of Symbol |
Definition at line 3070 of file Extensions.cs.
|
static |
Converts an IEnumerable to a PyList
enumerable | IEnumerable object to convert |
Definition at line 3137 of file Extensions.cs.
|
static |
Converts an IEnumerable to a PyList
enumerable | IEnumerable object to convert |
Requires the caller to own the GIL
Definition at line 3151 of file Extensions.cs.
|
static |
Converts the numeric value of one or more enumerated constants to an equivalent enumerated string.
value | Numeric value |
pyObject | Python object that encapsulated a Enum Type |
Definition at line 3171 of file Extensions.cs.
|
static |
Try to create a type with a given name, if PyObject is not a CLR type. Otherwise, convert it.
pyObject | Python object representing a type. |
type | Type object |
Definition at line 3193 of file Extensions.cs.
|
static |
Creates a type with a given name, if PyObject is not a CLR type. Otherwise, convert it.
pyObject | Python object representing a type. |
Definition at line 3224 of file Extensions.cs.
|
static |
Helper method to get the assembly name from a python type
pyObject | Python object pointing to the python type. PyObject.GetPythonType |
Definition at line 3257 of file Extensions.cs.
|
static |
Performs on-line batching of the specified enumerator, emitting chunks of the requested batch size
T | The enumerable item type |
enumerable | The enumerable to be batched |
batchSize | The number of items per batch |
Definition at line 3272 of file Extensions.cs.
|
static |
Safely blocks until the specified task has completed executing
TResult | The task's result type |
task | The task to be awaited |
Definition at line 3307 of file Extensions.cs.
|
static |
Safely blocks until the specified task has completed executing
task | The task to be awaited |
Definition at line 3317 of file Extensions.cs.
|
static |
Safely blocks until the specified task has completed executing
task | The task to be awaited |
Definition at line 3327 of file Extensions.cs.
|
static |
Convert dictionary to query string
pairs |
Definition at line 3337 of file Extensions.cs.
|
static |
Returns a new string in which specified ending in the current instance is removed.
s | original string value |
ending | the string to be removed |
Definition at line 3348 of file Extensions.cs.
|
static |
Returns a new string in which specified start in the current instance is removed.
s | original string value |
start | the string to be removed |
Definition at line 3366 of file Extensions.cs.
|
static |
Helper method to determine symbol for a live subscription
Useful for continuous futures where we subscribe to the underlying
Definition at line 3382 of file Extensions.cs.
|
static |
Gets the delisting date for the provided Symbol
symbol | The symbol to lookup the last trading date |
mapFile | Map file to use for delisting date. Defaults to SID.DefaultDate if no value is passed and is equity. |
Definition at line 3399 of file Extensions.cs.
|
static |
Helper method to determine if a given symbol is of custom data
Definition at line 3422 of file Extensions.cs.
|
static |
Helper method that will return a back month, with future expiration, future contract based on the given offset
symbol | The none canonical future symbol |
offset | The quantity of contracts to move into the future expiration chain |
Definition at line 3435 of file Extensions.cs.
|
static |
Helper method to unsubscribe a given configuration, handling any required mapping
Definition at line 3465 of file Extensions.cs.
|
static |
Helper method to subscribe a given configuration, handling any required mapping
Definition at line 3477 of file Extensions.cs.
|
static |
Helper method to stream read lines from a file
dataProvider | The data provider to use |
file | The file path to read from |
Definition at line 3508 of file Extensions.cs.
|
static |
Scale data based on factor function
data | Data to Adjust |
factorFunc | Function to factor prices by |
volumeFactor | Factor to multiply volume/askSize/bidSize/quantity by |
factor | Price scale |
sumOfDividends | The current dividend sum |
Volume values are rounded to the nearest integer, lot size purposefully not considered as scaling only applies to equities
Definition at line 3545 of file Extensions.cs.
|
static |
Normalize prices based on configuration
data | Data to be normalized |
factor | Price scale |
normalizationMode | The price scaling normalization mode |
sumOfDividends | The current dividend sum |
Definition at line 3642 of file Extensions.cs.
|
static |
Helper method to determine if price scales need an update based on the given data point
Definition at line 3687 of file Extensions.cs.
|
static |
Thread safe concurrent dictionary order by implementation by using SafeEnumeration<TSource,TKey>
Definition at line 3711 of file Extensions.cs.
|
static |
Thread safe concurrent dictionary order by implementation by using SafeEnumeration<TSource,TKey>
Definition at line 3722 of file Extensions.cs.
|
static |
Force concurrent dictionary enumeration using a thread safe implementation
Definition at line 3733 of file Extensions.cs.
|
static |
Helper method to determine the right data normalization mode to use by default
Definition at line 3745 of file Extensions.cs.
|
static |
Returns a hex string of the byte array.
source | the byte array to be represented as string |
Definition at line 3767 of file Extensions.cs.
|
static |
Gets the option exercise order direction resulting from the specified right and whether or not we wrote the option (isShort is
true
) or bought to option (isShort is false
)
right | The option right |
isShort | True if we wrote the option, false if we purchased the option |
Definition at line 3791 of file Extensions.cs.
|
static |
Gets the OrderDirection for the specified quantity
Definition at line 3805 of file Extensions.cs.
|
static |
Helper method to process an algorithms security changes, will add and remove securities according to them
Definition at line 3823 of file Extensions.cs.
|
static |
Helper method to set an algorithm runtime exception in a normalized fashion
Definition at line 3846 of file Extensions.cs.
|
static |
Creates a OptionChainUniverse for a given symbol
algorithm | The algorithm instance to create universes for |
symbol | Symbol of the option |
filter | The option filter to use |
universeSettings | The universe settings, will use algorithm settings if null |
Definition at line 3862 of file Extensions.cs.
|
static |
Creates a OptionChainUniverse for a given symbol
algorithm | The algorithm instance to create universes for |
symbol | Symbol of the option |
filter | The option filter to use |
universeSettings | The universe settings, will use algorithm settings if null |
Definition at line 3877 of file Extensions.cs.
|
static |
Creates a FuturesChainUniverse for a given symbol
algorithm | The algorithm instance to create universes for |
symbol | Symbol of the future |
filter | The future filter to use |
universeSettings | The universe settings, will use algorithm settings if null |
Definition at line 3913 of file Extensions.cs.
|
static |
Creates a FuturesChainUniverse for a given symbol
algorithm | The algorithm instance to create universes for |
symbol | Symbol of the future |
filter | The future filter to use |
universeSettings | The universe settings, will use algorithm settings if null |
Definition at line 3927 of file Extensions.cs.
|
static |
Gets the security for the specified symbol from the algorithm's securities collection. In case the security is not found, it will be created using the IAlgorithm.UniverseSettings and a best effort configuration setup.
algorithm | The algorithm instance |
symbol | The symbol which security is being looked up |
security | The found or added security instance |
onError | Callback to invoke in case of unsupported security type |
Definition at line 3980 of file Extensions.cs.
|
static |
Inverts the specified right
Definition at line 4035 of file Extensions.cs.
|
static |
Compares two values using given operator
T |
op | Comparison operator |
arg1 | The first value |
arg2 | The second value |
T | : | IComparable |
Definition at line 4054 of file Extensions.cs.
|
static |
Converts a Data.HistoryRequest instance to a SubscriptionDataConfig instance
request | History request |
isInternalFeed | Set to true if this subscription is added for the sole purpose of providing currency conversion rates, setting this flag to true will prevent the data from being sent into the algorithm's OnData methods |
isFilteredSubscription | True if this subscription should have filters applied to it (market hours/user filters from security), false otherwise |
Definition at line 4069 of file Extensions.cs.
|
static |
Centralized logic used at the top of the subscription enumerator stacks to determine if we should emit base data points based on the configuration for this subscription and the type of data we are handling.
Currently we only want to emit split/dividends/delisting events for non internal TradeBar configurations this last part is because equities also have QuoteBar subscriptions which will also subscribe to the same aux events and we don't want duplicate emits of these events in the TimeSliceFactory
The "TimeSliceFactory" does not allow for multiple dividends/splits per symbol in the same time slice but we don't want to rely only on that to filter out duplicated aux data so we use this at the top of our data enumerator stacks to define what subscription should emit this data.
We use this function to filter aux data at the top of the subscription enumerator stack instead of stopping the subscription stack from subscribing to aux data at the bottom because of a dependency with the FF enumerators requiring that they receive aux data to properly handle delistings. Otherwise we would have issues with delisted symbols continuing to fill forward after expiry/delisting. Reference PR #5485 and related issues for more.
Definition at line 4104 of file Extensions.cs.
|
static |
Gets the OrderDirection that corresponds to the specified side
side | The position side to be converted |
Definition at line 4150 of file Extensions.cs.
|
static |
Determines if an order with the specified direction would close a position with the specified side
direction | The direction of the order, buy/sell |
side | The side of the position, long/short |
Definition at line 4169 of file Extensions.cs.
|
static |
Determines if the two lists are equal, including all items at the same indices.
T | The element type |
left | The left list |
right | The right list |
Definition at line 4208 of file Extensions.cs.
|
static |
Computes a deterministic hash code based on the items in the list. This hash code is dependent on the ordering of items.
T | The element type |
list | The list |
Definition at line 4234 of file Extensions.cs.
|
static |
Determine if this SecurityType requires mapping
symbol | Type to check |
Definition at line 4253 of file Extensions.cs.
|
static |
Checks whether the fill event for closing a trade is a winning trade
fill | The fill event |
security | The security being traded |
profitLoss | The profit-loss for the closed trade |
Definition at line 4280 of file Extensions.cs.
|
static |
Gets the option's ITM amount for the given quantity.
option | The option security |
quantity | The quantity |
The returned value can be negative, which would mean the option is actually OTM.
Definition at line 4308 of file Extensions.cs.
|
static |
Gets the greatest common divisor of a list of numbers
values | List of numbers which greatest common divisor is requested |
Definition at line 4318 of file Extensions.cs.
|
static |
Safe method to perform divisions avoiding DivideByZeroException and Overflow/Underflow exceptions
failValue | Value to be returned if the denominator is zero |
Definition at line 4362 of file Extensions.cs.
|
static |
Determines if certain data type is custom
symbol | Symbol associated with the data type |
type | Data type to determine if it's custom |
Definition at line 4394 of file Extensions.cs.
|
static |
Returns the amount of fee's charged by executing a market order with the given arguments
security | Security for which we would like to make a market order |
quantity | Quantity of the security we are seeking to trade |
time | Time the order was placed |
marketOrder | This out parameter will contain the market order constructed |
Definition at line 4406 of file Extensions.cs.
|
staticgetset |
The offset span from the market close to liquidate or exercise a security on the delisting date
Will no be used in live trading
By default span is negative 15 minutes. We want to liquidate before market closes if not, in some cases like future options the market close would match the delisted event time and would cancel all orders and mark the security as non tradable and delisted.
Definition at line 97 of file Extensions.cs.