IBrokerage
QuantConnect.Interfaces.IBrokerage
Bases: IBrokerageCashSynchronizer, IDisposable
Brokerage interface that defines the operations all brokerages must implement. The IBrokerage implementation must have a matching IBrokerageFactory implementation.
order_id_changed
order_id_changed: _EventContainer[
Callable[[Object, BrokerageOrderIdChangedEvent], Any],
Any,
]
Event that fires each time the brokerage order id changes
orders_status_changed
orders_status_changed: _EventContainer[
Callable[[Object, List[OrderEvent]], Any], Any
]
Event that fires each time the status for a list of orders change
order_updated
order_updated: _EventContainer[
Callable[[Object, OrderUpdateEvent], Any], Any
]
Event that fires each time an order is updated in the brokerage side
option_position_assigned
option_position_assigned: _EventContainer[
Callable[[Object, OrderEvent], Any], Any
]
Event that fires each time a short option position is assigned
option_notification
option_notification: _EventContainer[
Callable[[Object, OptionNotificationEventArgs], Any],
Any,
]
Event that fires each time an option position has changed
new_brokerage_order_notification
new_brokerage_order_notification: _EventContainer[
Callable[
[Object, NewBrokerageOrderNotificationEventArgs],
Any,
],
Any,
]
Event that fires each time there's a brokerage side generated order
delisting_notification
delisting_notification: _EventContainer[
Callable[[Object, DelistingNotificationEventArgs], Any],
Any,
]
Event that fires each time a delisting occurs
account_changed
account_changed: _EventContainer[
Callable[[Object, AccountEvent], Any], Any
]
Event that fires each time a user's brokerage account is changed
message
message: _EventContainer[
Callable[[Object, BrokerageMessageEvent], Any], Any
]
Event that fires when a message is received from the brokerage
name
name: str
Gets the name of the brokerage
is_connected
is_connected: bool
Returns true if we're currently connected to the broker
account_instantly_updated
account_instantly_updated: bool
Specifies whether the brokerage will instantly update account balances
account_base_currency
account_base_currency: str
Returns the brokerage account's base currency
concurrency_enabled
concurrency_enabled: bool
Enables or disables concurrent processing of messages to and from the brokerage.
last_sync_date_time_utc
last_sync_date_time_utc: datetime
Gets the datetime of the last sync (UTC)
cancel_order
cancel_order(order: Order) -> bool
Cancels the order with the specified ID
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
Order
|
The order to cancel |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the request was made for the order to be canceled, false otherwise. |
connect
connect() -> None
Connects the client to the broker's remote servers
disconnect
disconnect() -> None
Disconnects the client from the broker's remote servers
get_account_holdings
get_account_holdings() -> List[Holding]
Gets all holdings for the account
Returns:
| Type | Description |
|---|---|
List[Holding]
|
The current holdings from the account. |
get_cash_balance
get_cash_balance() -> List[CashAmount]
Gets the current cash balance for each currency held in the brokerage account
Returns:
| Type | Description |
|---|---|
List[CashAmount]
|
The current cash balance for each currency available for trading. |
get_history
get_history(request: HistoryRequest) -> Iterable[BaseData]
Gets the history for the requested security
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
HistoryRequest
|
The historical data request |
required |
Returns:
| Type | Description |
|---|---|
Iterable[BaseData]
|
An enumerable of bars covering the span specified in the request. |
get_open_orders
get_open_orders() -> List[Order]
Gets all open orders on the account
Returns:
| Type | Description |
|---|---|
List[Order]
|
The open orders returned from IB. |
place_order
place_order(order: Order) -> bool
Places a new order and assigns a new broker ID to the order
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
Order
|
The order to be placed |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the request for a new order has been placed, false otherwise. |
update_order
update_order(order: Order) -> bool
Updates the order with the same id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
Order
|
The new order information |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the request was made for the order to be updated, false otherwise. |
perform_cash_sync
perform_cash_sync(
algorithm: IAlgorithm,
current_time_utc: Union[datetime, date],
get_time_since_last_fill: Callable[[], timedelta],
) -> bool
Synchronizes the cashbook with the brokerage account
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
IAlgorithm
|
The algorithm instance |
required |
current_time_utc
|
Union[datetime, date]
|
The current time (UTC) |
required |
get_time_since_last_fill
|
Callable[[], timedelta]
|
A function which returns the time elapsed since the last fill |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the cash sync was performed successfully. |
should_perform_cash_sync
should_perform_cash_sync(
current_time_utc: Union[datetime, date],
) -> bool
Returns whether the brokerage should perform the cash synchronization
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time_utc
|
Union[datetime, date]
|
The current time (UTC) |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the cash sync should be performed. |