Extensions
QuantConnect.Extensions
Bases: Object
Extensions function collections - group all static extensions functions here.
delisting_market_close_offset_span
delisting_market_close_offset_span: timedelta
The offset span from the market close to liquidate or exercise a security on the delisting date
convert_to
convert_to(
time: Union[datetime, date],
_from: Any,
to: Any,
strict: bool = False,
) -> datetime
convert_to(value: str, type: Type) -> Object
Signature descriptions:
-
Converts the specified time from the from time zone to the to time zone
-
Converts the specified string value into the specified type
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
Optional[Union[datetime, date]]
|
The time to be converted in terms of the from time zone |
None
|
_from
|
Optional[Any]
|
The time zone the specified time is in |
None
|
to
|
Optional[Any]
|
The time zone to be converted to |
None
|
strict
|
Optional[bool]
|
True for strict conversion, this will throw during ambiguitities, false for lenient conversion |
False
|
value
|
Optional[str]
|
The string value to be converted |
None
|
type
|
Optional[Type]
|
The output type |
None
|
Returns:
| Type | Description |
|---|---|
datetime | Object
|
Depends on the signature used. Case 1: [The time in terms of the to time zone.]; Case 2: [The converted value.] |
create_future_chain
create_future_chain(
algorithm: IAlgorithm,
symbol: Union[Symbol, str, BaseContract],
filter: Any,
universe_settings: UniverseSettings = None,
) -> Iterable[Universe]
create_future_chain(
algorithm: IAlgorithm,
symbol: Union[Symbol, str, BaseContract],
filter: Callable[
[FutureFilterUniverse], FutureFilterUniverse
],
universe_settings: UniverseSettings = None,
) -> Iterable[Universe]
Creates a FuturesChainUniverse for a given symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
IAlgorithm
|
The algorithm instance to create universes for |
required |
symbol
|
Union[Symbol, str, BaseContract]
|
Symbol of the future |
required |
filter
|
Any | Callable[[FutureFilterUniverse], FutureFilterUniverse]
|
The future filter to use |
required |
universe_settings
|
UniverseSettings
|
The universe settings, will use algorithm settings if null |
None
|
create_option_chain
create_option_chain(
algorithm: IAlgorithm,
symbol: Union[Symbol, str, BaseContract],
filter: Any,
universe_settings: UniverseSettings = None,
) -> OptionChainUniverse
create_option_chain(
algorithm: IAlgorithm,
symbol: Union[Symbol, str, BaseContract],
filter: Callable[
[OptionFilterUniverse], OptionFilterUniverse
],
universe_settings: UniverseSettings = None,
) -> OptionChainUniverse
Creates a OptionChainUniverse for a given symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
IAlgorithm
|
The algorithm instance to create universes for |
required |
symbol
|
Union[Symbol, str, BaseContract]
|
Symbol of the option |
required |
filter
|
Any | Callable[[OptionFilterUniverse], OptionFilterUniverse]
|
The option filter to use |
required |
universe_settings
|
UniverseSettings
|
The universe settings, will use algorithm settings if null |
None
|
Returns:
| Type | Description |
|---|---|
OptionChainUniverse
|
OptionChainUniverse for the given symbol. |
download_data
download_data(
client: Any,
url: str,
headers: Dictionary[str, str] = None,
) -> str
download_data(
url: str, headers: Dictionary[str, str] = None
) -> str
Helper method to download a provided url as a string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[Any]
|
The http client to use |
None
|
url
|
str
|
The url to download data from |
required |
headers
|
Dictionary[str, str]
|
Add custom headers for the request |
None
|
get_bytes
get_bytes(str: str) -> List[int]
get_bytes(stream: Stream) -> List[int]
Signature descriptions:
-
Extension method to convert a string into a byte array
-
Reads the entire content of a stream and returns it as a byte array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
Optional[str]
|
String to convert to bytes. |
None
|
stream
|
Optional[Stream]
|
Stream to read bytes from |
None
|
Returns:
| Type | Description |
|---|---|
List[int]
|
Depends on the signature used. Case 1: [Byte array.]; Case 2: [The bytes read from the stream.] |
get_enum_string
get_enum_string(value: int, py_object: Any) -> str
get_enum_string(value: Enum, py_object: Any) -> str
Converts the numeric value of one or more enumerated constants to an equivalent enumerated string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int | Enum
|
Numeric value |
required |
py_object
|
Any
|
Python object that encapsulated a Enum Type |
required |
Returns:
| Type | Description |
|---|---|
str
|
String that represents the enumerated object. |
greatest_common_divisor
greatest_common_divisor(values: List[float]) -> float
greatest_common_divisor(values: List[int]) -> int
Gets the greatest common divisor of a list of numbers
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
List[float] | List[int]
|
List of numbers which greatest common divisor is requested |
required |
Returns:
| Type | Description |
|---|---|
float | int
|
The greatest common divisor for the given list of numbers. |
is_empty
is_empty(series: BaseSeries) -> bool
is_empty(chart: Chart) -> bool
Signature descriptions:
-
Returns true if the specified BaseSeries instance holds no ISeriesPoint
-
Returns if the specified Chart instance holds no Series or they are all empty Extensions.is_empty(BaseSeries)
is_market_open
is_market_open(
security: Security, extended_market_hours: bool
) -> bool
is_market_open(
symbol: Union[Symbol, str, BaseContract],
utc_time: Union[datetime, date],
extended_market_hours: bool,
) -> bool
Helper method to determine if a specific market is open
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Optional[Security]
|
The target security |
None
|
extended_market_hours
|
bool
|
True if should consider extended market hours |
required |
symbol
|
Optional[Union[Symbol, str, BaseContract]]
|
The target symbol |
None
|
utc_time
|
Optional[Union[datetime, date]]
|
The current UTC time |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the market is open. |
normalize
normalize(input: float) -> float
normalize(
data: BaseData,
factor: float,
normalization_mode: DataNormalizationMode,
sum_of_dividends: float,
) -> BaseData
Signature descriptions:
-
Will remove any trailing zeros for the provided decimal input
-
Normalize prices based on configuration
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Optional[float]
|
The decimal to remove trailing zeros from |
None
|
data
|
Optional[BaseData]
|
Data to be normalized |
None
|
factor
|
Optional[float]
|
Price scale |
None
|
normalization_mode
|
Optional[DataNormalizationMode]
|
The price scaling normalization mode |
None
|
sum_of_dividends
|
Optional[float]
|
The current dividend sum |
None
|
Returns:
| Type | Description |
|---|---|
float | BaseData
|
Depends on the signature used. Case 1: [Provided input with no trailing zeros.]; Case 2: [The provided data point adjusted.] |
protobuf_serialize
protobuf_serialize(
ticks: List[Tick], guid: Guid
) -> List[int]
protobuf_serialize(
base_data: IBaseData, guid: Guid
) -> List[int]
protobuf_serialize(
base_data: IBaseData, stream: Stream
) -> None
Signature descriptions:
-
Serialize a list of ticks using protobuf
-
Serialize a base data instance using protobuf
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ticks
|
Optional[List[Tick]]
|
The list of ticks to serialize |
None
|
guid
|
Optional[Guid]
|
Unique guid |
None
|
base_data
|
Optional[IBaseData]
|
The data point to serialize |
None
|
stream
|
Optional[Stream]
|
The destination stream |
None
|
Returns:
| Type | Description |
|---|---|
Optional[List[int]]
|
The resulting byte array. |
round
round(
time: timedelta,
rounding_interval: timedelta,
rounding_type: MidpointRounding,
) -> timedelta
round(
time: timedelta, rounding_interval: timedelta
) -> timedelta
round(
datetime: Union[datetime, date],
rounding_interval: timedelta,
) -> datetime
Signature descriptions:
-
Extension method to round a timeSpan to nearest timespan period.
-
Extension method to round timespan to nearest timespan period.
-
Extension method to round a datetime to the nearest unit timespan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
Optional[timedelta]
|
TimeSpan To Round |
None
|
rounding_interval
|
timedelta
|
Rounding Unit |
required |
rounding_type
|
Optional[MidpointRounding]
|
Rounding method |
None
|
datetime
|
Optional[Union[datetime, date]]
|
Datetime object we're rounding. |
None
|
Returns:
| Type | Description |
|---|---|
timedelta | datetime
|
Depends on the signature used. Case 1: [Rounded timespan.]; Case 2: [Rounded timespan period.]; Case 3: [Rounded datetime.] |
smart_rounding
smart_rounding(input: Optional[float]) -> Optional[float]
smart_rounding(input: float) -> float
Provides global smart rounding, numbers larger than 1000 will round to 4 decimal places, while numbers smaller will round to 7 significant digits
synchronously_await_task
synchronously_await_task(task: Task) -> None
synchronously_await_task(task: ValueTask) -> None
Safely blocks until the specified task has completed executing
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task | ValueTask
|
The task to be awaited |
required |
Returns:
| Type | Description |
|---|---|
Optional[None]
|
The result of the task. |
wait_one
wait_one(
wait_handle: WaitHandle,
cancellation_token: CancellationToken,
) -> bool
wait_one(
wait_handle: WaitHandle,
timeout: timedelta,
cancellation_token: CancellationToken,
) -> bool
wait_one(
wait_handle: WaitHandle,
milliseconds_timeout: int,
cancellation_token: CancellationToken,
) -> bool
Signature descriptions:
-
Blocks the current thread until the current System.Threading.WaitHandle receives a signal, while observing a System.Threading.CancellationToken.
-
Blocks the current thread until the current System.Threading.WaitHandle is set, using a System.TimeSpan to measure the time interval, while observing a System.Threading.CancellationToken.
-
Blocks the current thread until the current System.Threading.WaitHandle is set, using a 32-bit signed integer to measure the time interval, while observing a System.Threading.CancellationToken.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wait_handle
|
WaitHandle
|
The wait handle to wait on |
required |
cancellation_token
|
CancellationToken
|
The System.Threading.CancellationToken to observe. |
required |
timeout
|
Optional[timedelta]
|
A System.TimeSpan that represents the number of milliseconds to wait, or a System.TimeSpan that represents -1 milliseconds to wait indefinitely. |
None
|
milliseconds_timeout
|
Optional[int]
|
The number of milliseconds to wait, or System.Threading.Timeout.Infinite(-1) to wait indefinitely. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
true if the System.Threading.WaitHandle was set; otherwise, false. |
add
add(
dictionary: Ticks,
key: Union[Symbol, str, BaseContract],
tick: Tick,
) -> None
Adds the specified Tick to the Ticks collection. If an entry does not exist for the specified key then one will be created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dictionary
|
Ticks
|
The ticks dictionary |
required |
key
|
Union[Symbol, str, BaseContract]
|
The symbol |
required |
tick
|
Tick
|
The tick to add |
required |
adjust_symbol_by_offset
adjust_symbol_by_offset(
symbol: Union[Symbol, str, BaseContract], offset: int
) -> Symbol
Helper method that will return a back month, with future expiration, future contract based on the given offset
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Union[Symbol, str, BaseContract]
|
The none canonical future symbol |
required |
offset
|
int
|
The quantity of contracts to move into the future expiration chain |
required |
Returns:
| Type | Description |
|---|---|
Symbol
|
A new future expiration symbol instance. |
batch
batch(
result_packets: List[AlphaResultPacket],
) -> AlphaResultPacket
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 'result_packets' list to batch is in order
closes
closes(
direction: OrderDirection, side: PositionSide
) -> bool
Determines if an order with the specified direction would close a position with the specified side
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
OrderDirection
|
The direction of the order, buy/sell |
required |
side
|
PositionSide
|
The side of the position, long/short |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the order direction would close the position, otherwise false. |
convert_from_utc
convert_from_utc(
time: Union[datetime, date],
to: Any,
strict: bool = False,
) -> datetime
Converts the specified time from UTC to the to time zone
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
Union[datetime, date]
|
The time to be converted expressed in UTC |
required |
to
|
Any
|
The destinatio time zone |
required |
strict
|
bool
|
True for strict conversion, this will throw during ambiguitities, false for lenient conversion |
False
|
Returns:
| Type | Description |
|---|---|
datetime
|
The time in terms of the to time zone. |
convert_to_symbol_enumerable
convert_to_symbol_enumerable(
py_object: Any,
) -> Iterable[Symbol]
Gets Enumerable of Symbol from a PyObject
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
py_object
|
Any
|
PyObject containing Symbol or Array of Symbol |
required |
Returns:
| Type | Description |
|---|---|
Iterable[Symbol]
|
Enumerable of Symbol. |
convert_to_utc
convert_to_utc(
time: Union[datetime, date],
_from: Any,
strict: bool = False,
) -> datetime
Converts the specified time from the from time zone to TimeZones.UTC
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
Union[datetime, date]
|
The time to be converted in terms of the from time zone |
required |
_from
|
Any
|
The time zone the specified time is in |
required |
strict
|
bool
|
True for strict conversion, this will throw during ambiguitities, false for lenient conversion |
False
|
Returns:
| Type | Description |
|---|---|
datetime
|
The time in terms of the to time zone. |
create_type
create_type(py_object: Any) -> Type
Creates a type with a given name, if PyObject is not a CLR type. Otherwise, convert it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
py_object
|
Any
|
Python object representing a type. |
required |
Returns:
| Type | Description |
|---|---|
Type
|
Type object. |
decode_base_36
decode_base_36(symbol: str) -> int
Converts an upper case alpha numeric string into a long
decode_base_64
decode_base_64(base_64_encoded_text: str) -> str
Decode a Base64 Encoded string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_64_encoded_text
|
str
|
Text to decode |
required |
Returns:
| Type | Description |
|---|---|
str
|
Decoded result. |
default_option_style
default_option_style(
security_type: SecurityType,
) -> OptionStyle
Gets the default OptionStyle for the provided SecurityType
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security_type
|
SecurityType
|
SecurityType to get default OptionStyle for |
required |
Returns:
| Type | Description |
|---|---|
OptionStyle
|
Default OptionStyle for the SecurityType. |
deserialize_list
deserialize_list(json_array: str) -> List[str]
Helper method to deserialize a json array into a list also handling single json values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_array
|
str
|
The value to deserialize |
required |
discretely_round_by
discretely_round_by(
value: float,
quanta: float,
mode: MidpointRounding = ...,
) -> float
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The value to be rounded by discretization |
required |
quanta
|
float
|
The maximum precision allowed by the value |
required |
mode
|
MidpointRounding
|
Specifies how to handle the rounding of half value, defaulting to away from zero. |
...
|
download_byte_array
download_byte_array(url: str) -> List[int]
Helper method to download a provided url as a byte array
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The url to download data from |
required |
encode_base_36
encode_base_36(data: int) -> str
Converts a long to an uppercase alpha numeric string
encode_base_64
encode_base_64(text: str) -> str
Convert a string to Base64 Encoding
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to encode |
required |
Returns:
| Type | Description |
|---|---|
str
|
Encoded result. |
exchange_round_down
exchange_round_down(
date_time: Union[datetime, date],
interval: timedelta,
exchange_hours: SecurityExchangeHours,
extended_market_hours: bool,
) -> datetime
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
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_time
|
Union[datetime, date]
|
Time to be rounded down |
required |
interval
|
timedelta
|
Timespan interval to round to. |
required |
exchange_hours
|
SecurityExchangeHours
|
The exchange hours to determine open times |
required |
extended_market_hours
|
bool
|
True for extended market hours, otherwise false |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
Rounded datetime. |
exchange_round_down_in_time_zone
exchange_round_down_in_time_zone(
date_time: Union[datetime, date],
interval: timedelta,
exchange_hours: SecurityExchangeHours,
rounding_time_zone: Any,
extended_market_hours: bool,
) -> datetime
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
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_time
|
Union[datetime, date]
|
Time to be rounded down |
required |
interval
|
timedelta
|
Timespan interval to round to. |
required |
exchange_hours
|
SecurityExchangeHours
|
The exchange hours to determine open times |
required |
rounding_time_zone
|
Any
|
The time zone to perform the rounding in |
required |
extended_market_hours
|
bool
|
True for extended market hours, otherwise false |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
Rounded datetime. |
get_assembly_name
get_assembly_name(py_object: Any) -> AssemblyName
Helper method to get the assembly name from a python type
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
py_object
|
Any
|
Python object pointing to the python type. PyObject.GetPythonType |
required |
Returns:
| Type | Description |
|---|---|
AssemblyName
|
The python type assembly name. |
get_base_data_instance
get_base_data_instance(type: Type) -> BaseData
Given a type will create a new instance using the parameterless constructor and assert the type implements BaseData
get_better_type_name
get_better_type_name(type: Type) -> str
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
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
Type
|
The type who's name we seek |
required |
Returns:
| Type | Description |
|---|---|
str
|
A better type name. |
get_custom_data_type_from_symbols
get_custom_data_type_from_symbols(
symbols: List[Symbol],
) -> Type
Retrieve a common custom data types from the given symbols if any
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
List[Symbol]
|
The target symbols to search |
required |
Returns:
| Type | Description |
|---|---|
Type
|
The custom data type or null. |
get_decimal_epsilon
get_decimal_epsilon() -> float
Gets the smallest positive number that can be added to a decimal instance and return a new value that does not == the old value
get_decimal_from_csv
get_decimal_from_csv(csv_line: str, index: int) -> float
Gets the value at the specified index from a CSV line, converted into a decimal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_line
|
str
|
The CSV line |
required |
index
|
int
|
The index of the value to be extracted from the CSV line |
required |
Returns:
| Type | Description |
|---|---|
float
|
The decimal value at the given index. If the index is invalid or conversion fails, it will return zero. |
get_decimal_places
get_decimal_places(input: float) -> int
Helper method to determine the amount of decimal places associated with the given decimal
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
float
|
The value to get the decimal count from |
required |
Returns:
| Type | Description |
|---|---|
int
|
The quantity of decimal places. |
get_delisting_date
get_delisting_date(
symbol: Union[Symbol, str, BaseContract],
map_file: MapFile = None,
) -> datetime
Gets the delisting date for the provided Symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Union[Symbol, str, BaseContract]
|
The symbol to lookup the last trading date |
required |
map_file
|
MapFile
|
Map file to use for delisting date. Defaults to SID.DefaultDate if no value is passed and is equity. |
None
|
get_entry
get_entry(
market_hours_database: MarketHoursDatabase,
symbol: Union[Symbol, str, BaseContract],
data_types: List[Type],
) -> Entry
Helper method to get a market hours entry
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
market_hours_database
|
MarketHoursDatabase
|
The market hours data base instance |
required |
symbol
|
Union[Symbol, str, BaseContract]
|
The symbol to get the entry for |
required |
data_types
|
List[Type]
|
For custom data types can optionally provide data type so that a new entry is added |
required |
get_exercise_direction
get_exercise_direction(
right: OptionRight, is_short: bool
) -> OrderDirection
Gets the option exercise order direction resulting from the specified right and whether or not we wrote the option (is_short is true) or bought to option (is_short is false)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
right
|
OptionRight
|
The option right |
required |
is_short
|
bool
|
True if we wrote the option, false if we purchased the option |
required |
Returns:
| Type | Description |
|---|---|
OrderDirection
|
The order direction resulting from an exercised option. |
get_extension
get_extension(str: str) -> 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
String we're looking for the extension for. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Last 4 character string of string. |
get_hash
get_hash(orders: IDictionary[int, Order]) -> str
Generates a hash code from a given collection of orders
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orders
|
IDictionary[int, Order]
|
The order collection |
required |
Returns:
| Type | Description |
|---|---|
str
|
The hash value. |
get_market_order_fees
get_market_order_fees(
security: Security,
quantity: float,
time: Union[datetime, date],
) -> CashAmount
Returns the amount of fee's charged by executing a market order with the given arguments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
Security for which we would like to make a market order |
required |
quantity
|
float
|
Quantity of the security we are seeking to trade |
required |
time
|
Union[datetime, date]
|
Time the order was placed |
required |
get_md_5_hash
get_md_5_hash(stream: Stream) -> List[int]
Gets the MD5 hash from a stream
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
Stream
|
The stream to compute a hash for |
required |
Returns:
| Type | Description |
|---|---|
List[int]
|
The MD5 hash. |
get_memory_stream
get_memory_stream(guid: Guid) -> MemoryStream
Will return a memory stream using the RecyclableMemoryStreamManager instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guid
|
Guid
|
Unique guid |
required |
Returns:
| Type | Description |
|---|---|
MemoryStream
|
A memory stream. |
get_method
get_method(instance: Any, name: str) -> Any
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Any
|
The object instance to search the method in |
required |
name
|
str
|
The name of the method |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The method matching the name. |
get_or_add_unrequested_security
get_or_add_unrequested_security(
algorithm: IAlgorithm,
symbol: Union[Symbol, str, BaseContract],
security: Optional[Security],
on_error: Callable[
[Sequence[SecurityType]], Any
] = None,
) -> Tuple[bool, Security]
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.universe_settings and a best effort configuration setup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
IAlgorithm
|
The algorithm instance |
required |
symbol
|
Union[Symbol, str, BaseContract]
|
The symbol which security is being looked up |
required |
security
|
Optional[Security]
|
The found or added security instance |
required |
on_error
|
Callable[[Sequence[SecurityType]], Any]
|
Callback to invoke in case of unsupported security type |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, Security]
|
True if the security was found or added. |
get_order_direction
get_order_direction(quantity: float) -> OrderDirection
Gets the OrderDirection for the specified quantity
get_python_arg_count
get_python_arg_count(method: Any) -> int
Get a python methods arg count
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Any
|
The Python method |
required |
Returns:
| Type | Description |
|---|---|
int
|
Count of arguments. |
get_python_bool_property
get_python_bool_property(instance: Any, name: str) -> Any
Gets a python property by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Any
|
The object instance to search the property in |
required |
name
|
str
|
The name of the property |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The python property or null if not defined or CSharp implemented. |
get_python_bool_property_with_checks
get_python_bool_property_with_checks(
instance: Any, name: str
) -> Any
Gets a python property by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Any
|
The object instance to search the property in |
required |
name
|
str
|
The name of the method |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The python property or null if not defined or CSharp implemented. |
get_python_method
get_python_method(instance: Any, name: str) -> Any
Gets a python method by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Any
|
The object instance to search the method in |
required |
name
|
str
|
The name of the method |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The python method or null if not defined or CSharp implemented. |
get_python_method_with_checks
get_python_method_with_checks(
instance: Any, name: str
) -> Any
Gets a python method by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Any
|
The object instance to search the method in |
required |
name
|
str
|
The name of the method |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The python method or null if not defined or CSharp implemented. |
get_string
get_string(
bytes: List[int], encoding: Encoding = None
) -> str
Extension method to convert a byte array into a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bytes
|
List[int]
|
Byte array to convert. |
required |
encoding
|
Encoding
|
The encoding to use for the conversion. Defaults to Encoding.ASCII |
None
|
Returns:
| Type | Description |
|---|---|
str
|
String from bytes. |
get_string_between_chars
get_string_between_chars(
value: str, left: str, right: str
) -> str
Get the first occurence of a string between two characters from another string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The original string |
required |
left
|
str
|
Left bound of the substring |
required |
right
|
str
|
Right bound of the substring |
required |
Returns:
| Type | Description |
|---|---|
str
|
Substring from original string bounded by the two characters. |
get_universe_mapping_mode_or_default
get_universe_mapping_mode_or_default(
universe_settings: UniverseSettings,
security_type: SecurityType,
market: str,
) -> DataMappingMode
Helper method to determine the right data mapping mode to use by default
get_universe_normalization_mode_or_default
get_universe_normalization_mode_or_default(
universe_settings: UniverseSettings,
security_type: SecurityType,
) -> DataNormalizationMode
Helper method to determine the right data normalization mode to use by default
get_update_price_scale_frontier
get_update_price_scale_frontier(data: BaseData) -> datetime
Helper method to determine if price scales need an update based on the given data point
get_zero_price_message
get_zero_price_message(
symbol: Union[Symbol, str, BaseContract],
) -> str
Extension method to get security price is 0 messages for users
has_options
has_options(security_type: SecurityType) -> bool
Determines if the provided SecurityType has a matching option SecurityType, used to represent the current SecurityType as a derivative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security_type
|
SecurityType
|
The SecurityType to check if it has options available |
required |
Returns:
| Type | Description |
|---|---|
bool
|
true if there are options for the SecurityType, false otherwise. |
implements_stream_reader
implements_stream_reader(base_data_type: Type) -> bool
Helper method to determine if a data type implements the Stream reader method
in_the_money_amount
in_the_money_amount(
option: Option, quantity: float
) -> ConvertibleCashAmount
Gets the option's ITM amount for the given quantity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option
|
Option
|
The option security |
required |
quantity
|
float
|
The quantity |
required |
Returns:
| Type | Description |
|---|---|
ConvertibleCashAmount
|
The ITM amount for the absolute quantity. |
is_common_business_day
is_common_business_day(date: Union[datetime, date]) -> bool
Business day here is defined as any day of the week that is not saturday or sunday
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Union[datetime, date]
|
The date to be examined |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A bool indicating wether the datetime is a weekday or not. |
is_custom_data_type
is_custom_data_type(
symbol: Union[Symbol, str, BaseContract], type: Type
) -> bool
Determines if certain data type is custom
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Union[Symbol, str, BaseContract]
|
Symbol associated with the data type |
required |
type
|
Type
|
Data type to determine if it's custom |
required |
is_directory_empty
is_directory_empty(directory_path: str) -> bool
Helper method to check if a directory exists and is not empty
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory_path
|
str
|
The path to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the directory does not exist or is empty. |
is_na_n_or_infinity
is_na_n_or_infinity(value: float) -> bool
Check if a number is NaN or infinity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The double value to check |
required |
is_na_n_or_zero
is_na_n_or_zero(value: float) -> bool
Check if a number is NaN or equal to zero
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The double value to check |
required |
is_option
is_option(security_type: SecurityType) -> bool
Determines if the provided SecurityType is a type of Option. Valid option types are: Equity Options, Futures Options, and Index Options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security_type
|
SecurityType
|
The SecurityType to check if it's an option asset |
required |
Returns:
| Type | Description |
|---|---|
bool
|
true if the asset has the makings of an option (exercisable, expires, and is a derivative of some underlying), false otherwise. |
is_out_of_date
is_out_of_date(filepath: str) -> bool
Determine if the file is out of date according to our download period. Date based files are never out of date (Files with YYYYMMDD)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the file |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the file is out of date. |
is_subclass_of_generic
is_subclass_of_generic(
type: Type, possible_super_type: Type
) -> bool
Checks the specified type to see if it is a subclass of the possible_super_type. This method will crawl up the inheritance heirarchy to check for equality using generic type definitions (if exists)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
Type
|
The type to be checked as a subclass of possible_super_type |
required |
possible_super_type
|
Type
|
The possible superclass of type |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if type is a subclass of the generic type definition possible_super_type. |
is_valid
is_valid(security_type: SecurityType) -> bool
Asserts the specified security_type value is valid
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security_type
|
SecurityType
|
The SecurityType value |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if valid security type value. |
is_win
is_win(
fill: OrderEvent, security: Security, profit_loss: float
) -> bool
Checks whether the fill event for closing a trade is a winning trade
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fill
|
OrderEvent
|
The fill event |
required |
security
|
Security
|
The security being traded |
required |
profit_loss
|
float
|
The profit-loss for the closed trade |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the trade is a win. For options assignments this depends on whether the option is ITM or OTM and the position side. See Trade.IsWin for more information. |
lazy_to_lower
lazy_to_lower(data: str) -> str
Lazy string to lower implementation. Will first verify the string is not already lower and avoid the call to string.ToLowerInvariant() if possible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
The string to lower |
required |
Returns:
| Type | Description |
|---|---|
str
|
The lower string. |
lazy_to_upper
lazy_to_upper(data: str) -> str
Lazy string to upper implementation. Will first verify the string is not already upper and avoid the call to string.ToUpperInvariant() if possible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
The string to upper |
required |
Returns:
| Type | Description |
|---|---|
str
|
The upper string. |
make_tradable
make_tradable(security: Security) -> None
Helper method to set the Security.is_tradable property to true for the given security when possible
matches_type_name
matches_type_name(type: Type, type_name: str) -> bool
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
Type
|
The type to test for a match |
required |
type_name
|
str
|
The name of the type to match |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the specified type matches the type name, false otherwise. |
normalize_to_str
normalize_to_str(input: float) -> str
Will remove any trailing zeros for the provided decimal and convert to string. Uses normalize(decimal).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
float
|
The decimal to convert to string |
required |
Returns:
| Type | Description |
|---|---|
str
|
Input converted to string with no trailing zeros. |
option_right_to_lower
option_right_to_lower(option_right: OptionRight) -> str
Converts the specified option_right value to its corresponding lower-case string representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option_right
|
OptionRight
|
The option_right value |
required |
Returns:
| Type | Description |
|---|---|
str
|
A lower case string representation of the specified OptionRight value. |
option_style_to_lower
option_style_to_lower(option_style: OptionStyle) -> str
Converts the specified option_style value to its corresponding lower-case string representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option_style
|
OptionStyle
|
The option_style value |
required |
Returns:
| Type | Description |
|---|---|
str
|
A lower case string representation of the specified option_style value. |
order_targets_by_margin_impact
order_targets_by_margin_impact(
targets: List[IPortfolioTarget],
algorithm: IAlgorithm,
target_is_delta: bool = False,
) -> Iterable[IPortfolioTarget]
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
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
List[IPortfolioTarget]
|
The portfolio targets to order by margin |
required |
algorithm
|
IAlgorithm
|
The algorithm instance |
required |
target_is_delta
|
bool
|
True if the target quantity is the delta between the desired and existing quantity |
False
|
parse_data_mapping_mode
parse_data_mapping_mode(
data_mapping_mode: str,
) -> Optional[DataMappingMode]
Converts the specified string to its corresponding DataMappingMode
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_mapping_mode
|
str
|
The data_mapping_mode string value |
required |
Returns:
| Type | Description |
|---|---|
Optional[DataMappingMode]
|
The DataMappingMode value. |
parse_option_right
parse_option_right(option_right: str) -> OptionRight
Converts the specified string to its corresponding OptionRight
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option_right
|
str
|
The option_right string value |
required |
Returns:
| Type | Description |
|---|---|
OptionRight
|
The OptionRight value. |
parse_option_style
parse_option_style(option_style: str) -> OptionStyle
Converts the specified string to its corresponding OptionStyle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option_style
|
str
|
The OptionStyle string value |
required |
Returns:
| Type | Description |
|---|---|
OptionStyle
|
The OptionStyle value. |
process_security_changes
process_security_changes(
algorithm: IAlgorithm, security_changes: SecurityChanges
) -> None
Helper method to process an algorithms security changes, will add and remove securities according to them
read_lines
read_lines(
data_provider: IDataProvider, file: str
) -> Iterable[str]
Helper method to stream read lines from a file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_provider
|
IDataProvider
|
The data provider to use |
required |
file
|
str
|
The file path to read from |
required |
Returns:
| Type | Description |
|---|---|
Iterable[str]
|
Enumeration of lines in file. |
remove_from_end
remove_from_end(s: str, ending: str) -> str
Returns a new string in which specified ending in the current instance is removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
original string value |
required |
ending
|
str
|
the string to be removed |
required |
remove_from_start
remove_from_start(s: str, start: str) -> str
Returns a new string in which specified start in the current instance is removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
original string value |
required |
start
|
str
|
the string to be removed |
required |
Returns:
| Type | Description |
|---|---|
str
|
Substring with start removed. |
requires_mapping
requires_mapping(
symbol: Union[Symbol, str, BaseContract],
) -> bool
Determine if this SecurityType requires mapping
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Union[Symbol, str, BaseContract]
|
Type to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if it needs to be mapped. |
reset
reset(timer: Timer) -> None
Add the reset method to the System.Timer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timer
|
Timer
|
System.timer object |
required |
resolution_to_lower
resolution_to_lower(resolution: Resolution) -> str
Converts the specified resolution value to its corresponding lower-case string representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
Resolution
|
The resolution value |
required |
Returns:
| Type | Description |
|---|---|
str
|
A lower-case string representation of the specified resolution value. |
round_down
round_down(
date_time: Union[datetime, date], interval: timedelta
) -> datetime
Extension method to round a datetime down by a timespan interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_time
|
Union[datetime, date]
|
Base DateTime object we're rounding down. |
required |
interval
|
timedelta
|
Timespan interval to round to |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
Rounded datetime. |
round_down_in_time_zone
round_down_in_time_zone(
date_time: Union[datetime, date],
rounding_interval: timedelta,
source_time_zone: Any,
rounding_time_zone: Any,
) -> datetime
Rounds the specified date time in the specified time zone. Careful with calling this method in a loop while modifying date_time, check unit tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_time
|
Union[datetime, date]
|
Date time to be rounded |
required |
rounding_interval
|
timedelta
|
Timespan rounding period |
required |
source_time_zone
|
Any
|
Time zone of the date time |
required |
rounding_time_zone
|
Any
|
Time zone in which the rounding is performed |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
The rounded date time in the source time zone. |
round_to_significant_digits
round_to_significant_digits(d: float, digits: int) -> float
Extension method to round a double value to a fixed number of significant figures instead of a fixed decimal places.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
float
|
Double we're rounding |
required |
digits
|
int
|
Number of significant figures |
required |
Returns:
| Type | Description |
|---|---|
float
|
New double rounded to digits-significant figures. |
round_up
round_up(
time: Union[datetime, date], interval: timedelta
) -> datetime
Extension method to explicitly round up to the nearest timespan interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
Union[datetime, date]
|
Base datetime object to round up. |
required |
interval
|
timedelta
|
Timespan interval to round to |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
Rounded datetime. |
safe_as_managed_object
safe_as_managed_object(
py_object: Any, type_to_convert_to: Type = None
) -> Any
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
py_object
|
Any
|
PyObject to convert to managed |
required |
type_to_convert_to
|
Type
|
The target type to convert to |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The resulting ManagedObject. |
safe_decimal_cast
safe_decimal_cast(input: float) -> float
Casts the specified input value to a decimal while acknowledging the overflow conditions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
float
|
The value to be cast |
required |
Returns:
| Type | Description |
|---|---|
float
|
The input value as a decimal, if the value is too large or to small to be represented as a decimal, then the closest decimal value will be returned. |
safe_division
safe_division(
numerator: float,
denominator: float,
fail_value: float = 0,
) -> float
Safe method to perform divisions avoiding DivideByZeroException and Overflow/Underflow exceptions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fail_value
|
float
|
Value to be returned if the denominator is zero |
0
|
Returns:
| Type | Description |
|---|---|
float
|
The numerator divided by the denominator if the denominator is not zero. Otherwise, the default fail_value or the provided one. |
safe_multiply_100
safe_multiply_100(value: float) -> float
Safe multiplies a decimal by 100
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The decimal to multiply |
required |
Returns:
| Type | Description |
|---|---|
float
|
The result, maxed out at decimal.MaxValue. |
scale
scale(
data: BaseData,
factor_func: Callable[[float, float, float], float],
volume_factor: float,
factor: float,
sum_of_dividends: float,
) -> BaseData
Scale data based on factor function
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
BaseData
|
Data to Adjust |
required |
factor_func
|
Callable[[float, float, float], float]
|
Function to factor prices by |
required |
volume_factor
|
float
|
Factor to multiply volume/askSize/bidSize/quantity by |
required |
factor
|
float
|
Price scale |
required |
sum_of_dividends
|
float
|
The current dividend sum |
required |
security_type_to_lower
security_type_to_lower(security_type: SecurityType) -> str
Converts the specified security_type value to its corresponding lower-case string representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security_type
|
SecurityType
|
The SecurityType value |
required |
Returns:
| Type | Description |
|---|---|
str
|
A lower-case string representation of the specified SecurityType value. |
set_runtime_error
set_runtime_error(
algorithm: IAlgorithm,
exception: Exception,
context: str,
) -> None
Helper method to set an algorithm runtime exception in a normalized fashion
should_emit_data
should_emit_data(
config: SubscriptionDataConfig,
data: BaseData,
is_universe: bool = False,
) -> bool
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
single_or_algorithm_type_name
single_or_algorithm_type_name(
names: List[str], algorithm_type_name: str
) -> str
Return the first in the series of names, or find the one that matches the configured algorithm_type_name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
List[str]
|
The list of class names |
required |
algorithm_type_name
|
str
|
The configured algorithm type name from the config |
required |
Returns:
| Type | Description |
|---|---|
str
|
The name of the class being run. |
smart_rounding_short
smart_rounding_short(input: float) -> float
Provides global smart rounding to a shorter version
stop_safely
stop_safely(
thread: Thread,
timeout: timedelta,
token: CancellationTokenSource = None,
) -> None
Helper method to safely stop a running thread
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread
|
Thread
|
The thread to stop |
required |
timeout
|
timedelta
|
The timeout to wait till the thread ends after which abort will be called |
required |
token
|
CancellationTokenSource
|
Cancellation token source to use if any |
None
|
subscribe_with_mapping
subscribe_with_mapping(
data_queue_handler: IDataQueueHandler,
data_config: SubscriptionDataConfig,
new_data_available_handler: Callable[
[Object, EventArgs], Any
],
is_expired: Callable[[SubscriptionDataConfig], bool],
subscribed_config: Optional[SubscriptionDataConfig],
) -> Tuple[IEnumerator[BaseData], SubscriptionDataConfig]
Helper method to subscribe a given configuration, handling any required mapping
tick_type_to_lower
tick_type_to_lower(tick_type: TickType) -> str
Converts the specified tick_type value to its corresponding lower-case string representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tick_type
|
TickType
|
The tick_type value |
required |
Returns:
| Type | Description |
|---|---|
str
|
A lower-case string representation of the specified tick_type value. |
to_camel_case
to_camel_case(value: str) -> str
Converts the provided string into camel case notation
to_csv
to_csv(str: str, size: int = 4) -> List[str]
Breaks the specified string into csv components, all commas are considered separators
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
The string to be broken into csv |
required |
size
|
int
|
The expected size of the output list |
4
|
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of the csv pieces. |
to_csv_data
to_csv_data(
str: str, size: int = 4, delimiter: str = ...
) -> List[str]
Breaks the specified string into csv components, works correctly with commas in data fields
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
The string to be broken into csv |
required |
size
|
int
|
The expected size of the output list |
4
|
delimiter
|
str
|
The delimiter used to separate entries in the line |
...
|
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of the csv pieces. |
to_decimal
to_decimal(str: str) -> float
Extension method for faster string to decimal conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
String to be converted to positive decimal value |
required |
Returns:
| Type | Description |
|---|---|
float
|
Decimal value of the string. |
to_decimal_allow_exponent
to_decimal_allow_exponent(str: str) -> float
Extension method for string to decimal conversion where string can represent a number with exponent xe-y
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
String to be converted to decimal value |
required |
Returns:
| Type | Description |
|---|---|
float
|
Decimal value of the string. |
to_financial_figures
to_financial_figures(number: float) -> str
Converts a decimal into a rounded number ending with K (thousands), M (millions), B (billions), etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
float
|
Number to convert |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted number with figures written in shorthand form. |
to_func
to_func(
date_rule: IDateRule,
) -> Callable[[datetime], Optional[datetime]]
Converts a date rule into a function that receives current time and returns the next date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_rule
|
IDateRule
|
The date rule to convert |
required |
Returns:
| Type | Description |
|---|---|
Callable[[datetime], Optional[datetime]]
|
A function that will enumerate the provided date rules. |
to_hex_string
to_hex_string(source: List[int]) -> str
Returns a hex string of the byte array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
List[int]
|
the byte array to be represented as string |
required |
Returns:
| Type | Description |
|---|---|
str
|
A new string containing the items in the enumerable. |
to_higher_resolution_equivalent
to_higher_resolution_equivalent(
time_span: timedelta, require_exact_match: bool
) -> Resolution
Converts the specified time span into a resolution enum value. If an exact match
is not found and require_exact_match is false, then the higher resoluion will be
returned. For example, time_span=5min will return Minute resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_span
|
timedelta
|
The time span to convert to resolution |
required |
require_exact_match
|
bool
|
True to throw an exception if an exact match is not found |
required |
Returns:
| Type | Description |
|---|---|
Resolution
|
The resolution. |
to_int_32
to_int_32(str: str) -> int
Extension method for faster string to Int32 conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
String to be converted to positive Int32 value |
required |
Returns:
| Type | Description |
|---|---|
int
|
Int32 value of the string. |
to_int_64
to_int_64(str: str) -> int
Extension method for faster string to Int64 conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
String to be converted to positive Int64 value |
required |
Returns:
| Type | Description |
|---|---|
int
|
Int32 value of the string. |
to_lower
to_lower(_enum: Enum) -> str
Converts the specified enum value to its corresponding lower-case string representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_enum
|
Enum
|
The enumeration value |
required |
Returns:
| Type | Description |
|---|---|
str
|
A lower-case string representation of the specified enumeration value. |
to_md_5
to_md_5(str: str) -> str
Extension method to convert a string to a MD5 hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
String we want to MD5 encode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
MD5 hash of a string. |
to_normalized_decimal
to_normalized_decimal(str: str) -> float
Extension method for faster string to normalized decimal conversion, i.e. 20.0% should be parsed into 0.2
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
String to be converted to positive decimal value |
required |
Returns:
| Type | Description |
|---|---|
float
|
Decimal value of the string. |
to_order_direction
to_order_direction(side: PositionSide) -> OrderDirection
Gets the OrderDirection that corresponds to the specified side
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
side
|
PositionSide
|
The position side to be converted |
required |
Returns:
| Type | Description |
|---|---|
OrderDirection
|
The order direction that maps from the provided position side. |
to_order_ticket
to_order_ticket(
order: Order,
transaction_manager: SecurityTransactionManager,
) -> OrderTicket
Turn order into an order ticket
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
Order
|
The Order being converted |
required |
transaction_manager
|
SecurityTransactionManager
|
The transaction manager, SecurityTransactionManager |
required |
to_py_list
to_py_list(enumerable: IEnumerable) -> List[Any]
Converts an IEnumerable to a PyList
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enumerable
|
IEnumerable
|
IEnumerable object to convert |
required |
Returns:
| Type | Description |
|---|---|
List[Any]
|
PyList. |
to_py_list_un_safe
to_py_list_un_safe(enumerable: IEnumerable) -> List[Any]
Converts an IEnumerable to a PyList
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enumerable
|
IEnumerable
|
IEnumerable object to convert |
required |
Returns:
| Type | Description |
|---|---|
List[Any]
|
PyList. |
to_query_string
to_query_string(pairs: IDictionary[str, Object]) -> str
Convert dictionary to query string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pairs
|
IDictionary[str, Object]
|
|
required |
to_safe_string
to_safe_string(py_object: Any) -> str
Returns a string that represents the current PyObject
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
py_object
|
Any
|
The PyObject being converted |
required |
Returns:
| Type | Description |
|---|---|
str
|
string that represents the current PyObject. |
to_sha_256
to_sha_256(data: str) -> str
Encrypt the token:time data to make our API hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
Data to be hashed by SHA256 |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hashed string. |
to_stream
to_stream(str: str) -> Stream
Extension method to convert strings to stream to be read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str
|
str
|
String to convert to stream |
required |
Returns:
| Type | Description |
|---|---|
Stream
|
Stream instance. |
to_string_performance
to_string_performance(option_right: OptionRight) -> str
Converts the specified option_right value to its corresponding string representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option_right
|
OptionRight
|
The option_right value |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the specified OptionRight value. |
to_subscription_data_config
to_subscription_data_config(
request: HistoryRequest,
is_internal_feed: bool = False,
is_filtered_subscription: bool = True,
) -> SubscriptionDataConfig
Converts a Data.HistoryRequest instance to a SubscriptionDataConfig instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
HistoryRequest
|
History request |
required |
is_internal_feed
|
bool
|
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 |
False
|
is_filtered_subscription
|
bool
|
True if this subscription should have filters applied to it (market hours/user filters from security), false otherwise |
True
|
Returns:
| Type | Description |
|---|---|
SubscriptionDataConfig
|
Subscription data configuration. |
to_time_span
to_time_span(resolution: Resolution) -> timedelta
Converts the Resolution instance into a TimeSpan instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
Resolution
|
The resolution to be converted |
required |
Returns:
| Type | Description |
|---|---|
timedelta
|
A TimeSpan instance that represents the resolution specified. |
truncate_to_3_decimal_places
truncate_to_3_decimal_places(value: float) -> float
Will truncate the provided decimal, without rounding, to 3 decimal places
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The value to truncate |
required |
Returns:
| Type | Description |
|---|---|
float
|
New instance with just 3 decimal places. |
try_create_type
try_create_type(
py_object: Any, type: Optional[Type]
) -> Tuple[bool, Type]
Try to create a type with a given name, if PyObject is not a CLR type. Otherwise, convert it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
py_object
|
Any
|
Python object representing a type. |
required |
type
|
Optional[Type]
|
Type object |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, Type]
|
True if was able to create the type. |
try_get_decimal_from_csv
try_get_decimal_from_csv(
csv_line: str, index: int, value: Optional[float]
) -> Tuple[bool, float]
Gets the value at the specified index from a CSV line, converted into a decimal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_line
|
str
|
The CSV line |
required |
index
|
int
|
The index of the value to be extracted from the CSV line |
required |
value
|
Optional[float]
|
The decimal value at the given index |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, float]
|
Whether there was a value at the given index and could be extracted and converted into a decimal. |
try_get_from_csv
try_get_from_csv(
csv_line: str,
index: int,
result: Optional[ReadOnlySpan[str]],
) -> Tuple[bool, ReadOnlySpan[str]]
Gets the value at the specified index from a CSV line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_line
|
str
|
The CSV line |
required |
index
|
int
|
The index of the value to be extracted from the CSV line |
required |
result
|
Optional[ReadOnlySpan[str]]
|
The value at the given index |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, ReadOnlySpan[str]]
|
Whether there was a value at the given index and could be extracted. |
try_get_live_subscription_symbol
try_get_live_subscription_symbol(
symbol: Union[Symbol, str, BaseContract],
mapped: Optional[Union[Symbol, str, BaseContract]],
) -> Tuple[bool, Union[Symbol, str, BaseContract]]
Helper method to determine symbol for a live subscription
try_parse_security_type
try_parse_security_type(
value: str,
security_type: Optional[SecurityType],
ignore_case: bool = True,
) -> Tuple[bool, SecurityType]
Attempts to convert the string into a SecurityType enum value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
string value to convert to SecurityType |
required |
security_type
|
Optional[SecurityType]
|
SecurityType output |
required |
ignore_case
|
bool
|
Ignore casing |
True
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, SecurityType]
|
true if parsed into a SecurityType successfully, false otherwise. |
unsubscribe_with_mapping
unsubscribe_with_mapping(
data_queue_handler: IDataQueueHandler,
data_config: SubscriptionDataConfig,
) -> None
Helper method to unsubscribe a given configuration, handling any required mapping
with_embedded_html_anchors
with_embedded_html_anchors(source: str) -> str
Convert a string into the same string with a URL! :)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
The source string to be converted |
required |
Returns:
| Type | Description |
|---|---|
str
|
The same source string but with anchor tags around substrings matching a link regex. |