BrokerageModelPythonWrapper
QuantConnect.Python.BrokerageModelPythonWrapper
BrokerageModelPythonWrapper(model: Any)
Bases: BasePythonWrapper[IBrokerageModel], IBrokerageModel
Provides an implementation of IBrokerageModel that wraps a PyObject object
Constructor for initialising the BrokerageModelPythonWrapper class with wrapped PyObject object
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Models brokerage transactions, fees, and order |
required |
required_free_buying_power_percent
required_free_buying_power_percent: float
Gets the brokerages model percentage factor used to determine the required unused buying power for the account. From 1 to 0. Example: 0 means no unused buying power is required. 0.5 means 50% of the buying power should be left unused.
default_markets
default_markets: Dict[SecurityType, str]
Gets a map of the default markets to be used for each security type
instance
instance: Any
Gets the underlying python instance
This Property is protected.
PythonRuntimeChecker
Bases: Object
Set of helper methods to invoke Python methods with runtime checks for return values and out parameter's conversions.
invoke_method
invoke_method: PythonRuntimeChecker_InvokeMethod
invoke_method_and_enumerate
invoke_method_and_enumerate: (
PythonRuntimeChecker_InvokeMethodAndEnumerate
)
invoke_method_and_get_dictionary
invoke_method_and_get_dictionary: (
PythonRuntimeChecker_InvokeMethodAndGetDictionary
)
invoke_method_and_wrap_result
invoke_method_and_wrap_result: (
PythonRuntimeChecker_InvokeMethodAndWrapResult
)
invoke_method_and_get_out_parameters
invoke_method_and_get_out_parameters: (
PythonRuntimeChecker_InvokeMethodAndGetOutParameters
)
convert
convert: PythonRuntimeChecker_Convert
convert_and_dispose
convert_and_dispose: PythonRuntimeChecker_ConvertAndDispose
apply_split
apply_split(
tickets: List[OrderTicket], split: Split
) -> None
Applies the split to the specified order ticket
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tickets
|
List[OrderTicket]
|
The open tickets matching the split event |
required |
split
|
Split
|
The split event data |
required |
can_execute_order
Returns true if the brokerage would be able to execute this order at this time assuming market prices are sufficient for the fill to take place. This is used to emulate the brokerage fills in backtesting and paper trading. For example some brokerages may not perform executions during extended market hours. This is not intended to be checking whether or not the exchange is open, that is handled in the Security.Exchange property.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security being ordered |
required |
order
|
Order
|
The order to test for execution |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the brokerage would be able to perform the execution, false otherwise. |
can_submit_order
can_submit_order(
security: Security,
order: Order,
message: Optional[BrokerageMessageEvent],
) -> Tuple[bool, BrokerageMessageEvent]
Returns true if the brokerage could accept this order. This takes into account order type, security type, and order size limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security being ordered |
required |
order
|
Order
|
The order to be processed |
required |
message
|
Optional[BrokerageMessageEvent]
|
If this function returns false, a brokerage message detailing why the order may not be submitted |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, BrokerageMessageEvent]
|
True if the brokerage could process the order, false otherwise. |
can_update_order
can_update_order(
security: Security,
order: Order,
request: UpdateOrderRequest,
message: Optional[BrokerageMessageEvent],
) -> Tuple[bool, BrokerageMessageEvent]
Returns true if the brokerage would allow updating the order as specified by the request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security of the order |
required |
order
|
Order
|
The order to be updated |
required |
request
|
UpdateOrderRequest
|
The requested updated to be made to the order |
required |
message
|
Optional[BrokerageMessageEvent]
|
If this function returns false, a brokerage message detailing why the order may not be updated |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, BrokerageMessageEvent]
|
True if the brokerage would allow updating the order, false otherwise. |
get_benchmark
get_benchmark(securities: SecurityManager) -> IBenchmark
Get the benchmark for this model
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
securities
|
SecurityManager
|
SecurityService to create the security with if needed |
required |
Returns:
| Type | Description |
|---|---|
IBenchmark
|
The benchmark for this brokerage. |
get_buying_power_model
get_buying_power_model(
security: Security,
) -> IBuyingPowerModel
Gets a new buying power model for the security, returning the default model with the security's configured leverage. For cash accounts, leverage = 1 is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security to get a buying power model for |
required |
Returns:
| Type | Description |
|---|---|
IBuyingPowerModel
|
The buying power model for this brokerage/security. |
get_fee_model
get_fill_model
get_fill_model(security: Security) -> IFillModel
Gets a new fill model that represents this brokerage's fill behavior
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security to get fill model for |
required |
Returns:
| Type | Description |
|---|---|
IFillModel
|
The new fill model for this brokerage. |
get_leverage
get_leverage(security: Security) -> float
Gets the brokerage's leverage for the specified security
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security's whose leverage we seek |
required |
Returns:
| Type | Description |
|---|---|
float
|
The leverage for the specified security. |
get_margin_interest_rate_model
get_margin_interest_rate_model(
security: Security,
) -> IMarginInterestRateModel
Gets a new margin interest rate model for the security
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security to get a margin interest rate model for |
required |
Returns:
| Type | Description |
|---|---|
IMarginInterestRateModel
|
The margin interest rate model for this brokerage. |
get_model
get_model() -> IBrokerageModel
Convenience method to get the underlying IBrokerageModel object from the wrapper.
Returns:
| Type | Description |
|---|---|
IBrokerageModel
|
Underlying IBrokerageModel object. |
get_settlement_model
get_settlement_model(
security: Security,
) -> ISettlementModel
Gets a new settlement model for the security
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security to get a settlement model for |
required |
Returns:
| Type | Description |
|---|---|
ISettlementModel
|
The settlement model for this brokerage. |
get_shortable_provider
get_shortable_provider(
security: Security,
) -> IShortableProvider
get_slippage_model
get_slippage_model(security: Security) -> ISlippageModel
Gets a new slippage model that represents this brokerage's fill slippage behavior
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
security
|
Security
|
The security to get a slippage model for |
required |
Returns:
| Type | Description |
|---|---|
ISlippageModel
|
The new slippage model for this brokerage. |
shortable
shortable(
algorithm: IAlgorithm,
symbol: Union[Symbol, str, BaseContract, Security],
quantity: float,
) -> bool
Determine if this symbol is shortable
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
IAlgorithm
|
The algorithm running |
required |
symbol
|
Union[Symbol, str, BaseContract, Security]
|
The symbol to short |
required |
quantity
|
float
|
The amount to short |
required |
equals
equals(
other: BasePythonWrapper[
QuantConnect_Python_BasePythonWrapper_TInterface
],
) -> bool
equals(obj: Any) -> bool
Signature descriptions:
-
Determines whether the specified instance wraps the same Python object reference as this instance, which would indicate that they are equal.
-
Determines whether the specified object is an instance of BasePythonWrapper{TInterface} and wraps the same Python object reference as this instance, which would indicate that they are equal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Optional[BasePythonWrapper[QuantConnect_Python_BasePythonWrapper_TInterface]]
|
The other object to compare this with |
None
|
obj
|
Optional[Any]
|
The other object to compare this with |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if both instances are equal, that is if both wrap the same Python object reference. |
get_property
get_property(property_name: str) -> Any
get_property(
property_name: str,
) -> QuantConnect_Python_BasePythonWrapper_GetProperty_T
Gets the Python instance property with the specified name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name
|
str
|
The name of the property |
required |
invoke_method
invoke_method(
method_name: str, *args: Union[Object, Iterable[Object]]
) -> Any
invoke_method(
method_name: str, *args: Union[Object, Iterable[Object]]
) -> QuantConnect_Python_BasePythonWrapper_InvokeMethod_T
Invokes the specified method with the specified arguments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
args
|
Union[Object, Iterable[Object]]
|
The arguments to call the method with |
()
|
Returns:
| Type | Description |
|---|---|
Any | QuantConnect_Python_BasePythonWrapper_InvokeMethod_T
|
The returned valued converted to the given type. |
invoke_method_and_enumerate
invoke_method_and_enumerate(
method_name: str, *args: Union[Object, Iterable[Object]]
) -> Sequence[
QuantConnect_Python_BasePythonWrapper_InvokeMethodAndEnumerate_T
]
Invokes the specified method with the specified arguments and iterates over the returned values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
args
|
Union[Object, Iterable[Object]]
|
The arguments to call the method with |
()
|
Returns:
| Type | Description |
|---|---|
Sequence[QuantConnect_Python_BasePythonWrapper_InvokeMethodAndEnumerate_T]
|
The returned valued converted to the given type. |
invoke_method_and_get_dictionary
invoke_method_and_get_dictionary(
method_name: str, *args: Union[Object, Iterable[Object]]
) -> Dictionary[
QuantConnect_Python_BasePythonWrapper_InvokeMethodAndGetDictionary_TKey,
QuantConnect_Python_BasePythonWrapper_InvokeMethodAndGetDictionary_TValue,
]
Invokes the specified method with the specified arguments and iterates over the returned values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
args
|
Union[Object, Iterable[Object]]
|
The arguments to call the method with |
()
|
Returns:
| Type | Description |
|---|---|
Dictionary[QuantConnect_Python_BasePythonWrapper_InvokeMethodAndGetDictionary_TKey, QuantConnect_Python_BasePythonWrapper_InvokeMethodAndGetDictionary_TValue]
|
The returned valued converted to the given type. |
invoke_method_and_wrap_result
invoke_method_and_wrap_result(
method_name: str,
wrap_result: Callable[
[Any],
QuantConnect_Python_BasePythonWrapper_InvokeMethodAndWrapResult_T,
],
*args: Union[Object, Iterable[Object]]
) -> QuantConnect_Python_BasePythonWrapper_InvokeMethodAndWrapResult_T
Invokes the specified method with the specified arguments and wraps the result by calling the given function if the result is not a C# object
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
wrap_result
|
Callable[[Any], QuantConnect_Python_BasePythonWrapper_InvokeMethodAndWrapResult_T]
|
Method that wraps a Python object in the corresponding Python Wrapper |
required |
args
|
Union[Object, Iterable[Object]]
|
The arguments to call the method with |
()
|
Returns:
| Type | Description |
|---|---|
QuantConnect_Python_BasePythonWrapper_InvokeMethodAndWrapResult_T
|
The returned value wrapped using the given method if the result is not a C# object. |
invoke_method_with_out_parameters
invoke_method_with_out_parameters(
method_name: str,
out_parameters_types: List[Type],
out_parameters: Optional[List[Object]],
*args: Union[Object, Iterable[Object]]
) -> Tuple[
QuantConnect_Python_BasePythonWrapper_InvokeMethodWithOutParameters_T,
List[Object],
]
Invokes the specified method with the specified arguments and out parameters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
out_parameters_types
|
List[Type]
|
The types of the out parameters |
required |
out_parameters
|
Optional[List[Object]]
|
The out parameters values |
required |
args
|
Union[Object, Iterable[Object]]
|
The arguments to call the method with |
()
|
Returns:
| Type | Description |
|---|---|
Tuple[QuantConnect_Python_BasePythonWrapper_InvokeMethodWithOutParameters_T, List[Object]]
|
The returned valued converted to the given type. |
set_python_instance
set_python_instance(instance: Any) -> None
set_python_instance(
instance: Any, validate_interface: bool
) -> None
Signature descriptions:
-
Sets the python instance
-
Sets the python instance and sets the validate interface flag
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Any
|
The underlying python instance |
required |
validate_interface
|
Optional[bool]
|
Whether to perform validations for interface implementation |
None
|
try_invoke_python_override
try_invoke_python_override(
method_name: str,
result: Optional[
QuantConnect_Python_BasePythonWrapper_TryInvokePythonOverride_T
],
*args: Union[Object, Iterable[Object]]
) -> Tuple[
bool,
QuantConnect_Python_BasePythonWrapper_TryInvokePythonOverride_T,
]
Attempts to invoke the method if it has been overridden in Python.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method to call on the Python instance. |
required |
result
|
Optional[QuantConnect_Python_BasePythonWrapper_TryInvokePythonOverride_T]
|
When this method returns, contains the method result if the call succeeded. |
required |
args
|
Union[Object, Iterable[Object]]
|
The arguments to pass to the Python method. |
()
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, QuantConnect_Python_BasePythonWrapper_TryInvokePythonOverride_T]
|
true if the Python method was successfully invoked, otherwise, false. |
dispose
dispose() -> None
Dispose of this instance
get_event
get_event(name: str) -> Any
Gets the Python instance event with the specified name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the event |
required |
get_hash_code
get_hash_code() -> int
Gets the hash code for the current instance
Returns:
| Type | Description |
|---|---|
int
|
The hash code of the current instance. |
get_method
get_method(
method_name: str, python_only: bool = False
) -> Any
Gets the Python instances method with the specified name and caches it
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
python_only
|
bool
|
Whether to only return python methods |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
The matched method. |
has_attr
has_attr(name: str) -> bool
Determines whether the Python instance has the specified attribute
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The attribute name |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the Python instance has the specified attribute. |
invoke_void_method
invoke_void_method(
method_name: str, *args: Union[Object, Iterable[Object]]
) -> None
Invokes the specified method with the specified arguments without returning a value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
args
|
Union[Object, Iterable[Object]]
|
The arguments to call the method with |
()
|
set_property
set_property(property_name: str, value: Any) -> None
Sets the Python instance property with the specified name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name
|
str
|
The name of the property |
required |
value
|
Any
|
The property value |
required |