Lean
$LEAN_TAG$
|
Represents the base Brokerage implementation. This provides logging on brokerage events. More...
Public Member Functions | |
abstract bool | PlaceOrder (Order order) |
Places a new order and assigns a new broker ID to the order More... | |
abstract bool | UpdateOrder (Order order) |
Updates the order with the same id More... | |
abstract bool | CancelOrder (Order order) |
Cancels the order with the specified ID More... | |
abstract void | Connect () |
Connects the client to the broker's remote servers More... | |
abstract void | Disconnect () |
Disconnects the client from the broker's remote servers More... | |
virtual void | Dispose () |
Dispose of the brokerage instance More... | |
abstract List< Order > | GetOpenOrders () |
Gets all open orders on the account. NOTE: The order objects returned do not have QC order IDs. More... | |
abstract List< Holding > | GetAccountHoldings () |
Gets all holdings for the account More... | |
abstract List< CashAmount > | GetCashBalance () |
Gets the current cash balance for each currency held in the brokerage account More... | |
virtual IEnumerable< BaseData > | GetHistory (HistoryRequest request) |
Gets the history for the requested security More... | |
virtual bool | ShouldPerformCashSync (DateTime currentTimeUtc) |
Returns whether the brokerage should perform the cash synchronization More... | |
virtual bool | PerformCashSync (IAlgorithm algorithm, DateTime currentTimeUtc, Func< TimeSpan > getTimeSinceLastFill) |
Synchronizes the cashbook with the brokerage account More... | |
Public Attributes | |
virtual bool | AccountInstantlyUpdated => false |
Specifies whether the brokerage will instantly update account balances More... | |
DateTime | LastSyncDateTimeUtc => new DateTime(Interlocked.Read(ref _lastSyncTimeTicks)) |
Gets the datetime of the last sync (UTC) More... | |
Protected Member Functions | |
Brokerage (string name) | |
Creates a new Brokerage instance with the specified name More... | |
virtual void | OnOrderEvents (List< OrderEvent > orderEvents) |
Event invocator for the OrderFilled event More... | |
virtual void | OnOrderEvent (OrderEvent e) |
Event invocator for the OrderFilled event More... | |
virtual void | OnOrderUpdated (OrderUpdateEvent e) |
Event invocator for the OrderUpdated event More... | |
virtual void | OnOrderIdChangedEvent (BrokerageOrderIdChangedEvent e) |
Event invocator for the OrderIdChanged event More... | |
virtual void | OnOptionPositionAssigned (OrderEvent e) |
Event invocator for the OptionPositionAssigned event More... | |
virtual void | OnOptionNotification (OptionNotificationEventArgs e) |
Event invocator for the OptionNotification event More... | |
virtual void | OnNewBrokerageOrderNotification (NewBrokerageOrderNotificationEventArgs e) |
Event invocator for the NewBrokerageOrderNotification event More... | |
virtual void | OnDelistingNotification (DelistingNotificationEventArgs e) |
Event invocator for the DelistingNotification event More... | |
virtual void | OnAccountChanged (AccountEvent e) |
Event invocator for the AccountChanged event More... | |
virtual void | OnMessage (BrokerageMessageEvent e) |
Event invocator for the Message event More... | |
virtual List< Holding > | GetAccountHoldings (Dictionary< string, string > brokerageData, IEnumerable< Security > securities) |
Helper method that will try to get the live holdings from the provided brokerage data collection else will default to the algorithm state More... | |
virtual List< CashAmount > | GetCashBalance (Dictionary< string, string > brokerageData, CashBook cashBook) |
Helper method that will try to get the live cash balance from the provided brokerage data collection else will default to the algorithm state More... | |
Static Protected Member Functions | |
static OrderPosition | GetOrderPosition (OrderDirection orderDirection, decimal holdingsQuantity) |
Gets the position that might result given the specified order direction and the current holdings quantity. This is useful for brokerages that require more specific direction information than provided by the OrderDirection enum (e.g. Tradier differentiates Buy/Sell and BuyToOpen/BuyToCover/SellShort/SellToClose) More... | |
Protected Attributes | |
DateTime | LastSyncDate => LastSyncDateTimeUtc.ConvertFromUtc(TimeZones.NewYork).Date |
Gets the date of the last sync (New York time zone) More... | |
Properties | |
string | Name [get] |
Gets the name of the brokerage More... | |
abstract bool | IsConnected [get] |
Returns true if we're currently connected to the broker More... | |
virtual string | AccountBaseCurrency [get, protected set] |
Returns the brokerage account's base currency More... | |
Properties inherited from QuantConnect.Interfaces.IBrokerage | |
string | Name [get] |
Gets the name of the brokerage More... | |
bool | IsConnected [get] |
Returns true if we're currently connected to the broker More... | |
bool | AccountInstantlyUpdated [get] |
Specifies whether the brokerage will instantly update account balances More... | |
string | AccountBaseCurrency [get] |
Returns the brokerage account's base currency More... | |
Properties inherited from QuantConnect.Interfaces.IBrokerageCashSynchronizer | |
DateTime | LastSyncDateTimeUtc [get] |
Gets the datetime of the last sync (UTC) More... | |
Events | |
EventHandler< BrokerageOrderIdChangedEvent > | OrderIdChanged |
Event that fires each time the brokerage order id changes More... | |
EventHandler< List< OrderEvent > > | OrdersStatusChanged |
EventHandler< OrderUpdateEvent > | OrderUpdated |
Event that fires each time an order is updated in the brokerage side More... | |
EventHandler< OrderEvent > | OptionPositionAssigned |
Event that fires each time a short option position is assigned More... | |
EventHandler< OptionNotificationEventArgs > | OptionNotification |
Event that fires each time an option position has changed More... | |
EventHandler< NewBrokerageOrderNotificationEventArgs > | NewBrokerageOrderNotification |
Event that fires each time there's a brokerage side generated order More... | |
EventHandler< DelistingNotificationEventArgs > | DelistingNotification |
Event that fires each time a delisting occurs More... | |
EventHandler< AccountEvent > | AccountChanged |
Event that fires each time a user's brokerage account is changed More... | |
EventHandler< BrokerageMessageEvent > | Message |
Event that fires when an error is encountered in the brokerage More... | |
Events inherited from QuantConnect.Interfaces.IBrokerage | |
EventHandler< BrokerageOrderIdChangedEvent > | OrderIdChanged |
Event that fires each time the brokerage order id changes More... | |
EventHandler< List< OrderEvent > > | OrdersStatusChanged |
EventHandler< OrderUpdateEvent > | OrderUpdated |
Event that fires each time an order is updated in the brokerage side More... | |
EventHandler< OrderEvent > | OptionPositionAssigned |
Event that fires each time a short option position is assigned More... | |
EventHandler< OptionNotificationEventArgs > | OptionNotification |
Event that fires each time an option position has changed More... | |
EventHandler< NewBrokerageOrderNotificationEventArgs > | NewBrokerageOrderNotification |
Event that fires each time there's a brokerage side generated order More... | |
EventHandler< DelistingNotificationEventArgs > | DelistingNotification |
Event that fires each time a delisting occurs More... | |
EventHandler< AccountEvent > | AccountChanged |
Event that fires each time a user's brokerage account is changed More... | |
EventHandler< BrokerageMessageEvent > | Message |
Event that fires when a message is received from the brokerage More... | |
Represents the base Brokerage implementation. This provides logging on brokerage events.
Definition at line 33 of file Brokerage.cs.
|
protected |
Creates a new Brokerage instance with the specified name
name | The name of the brokerage |
Definition at line 103 of file Brokerage.cs.
|
pure virtual |
Places a new order and assigns a new broker ID to the order
order | The order to be placed |
Implements QuantConnect.Interfaces.IBrokerage.
Implemented in QuantConnect.Brokerages.Backtesting.BacktestingBrokerage.
|
pure virtual |
Updates the order with the same id
order | The new order information |
Implements QuantConnect.Interfaces.IBrokerage.
Implemented in QuantConnect.Brokerages.Backtesting.BacktestingBrokerage.
|
pure virtual |
Cancels the order with the specified ID
order | The order to cancel |
Implements QuantConnect.Interfaces.IBrokerage.
Implemented in QuantConnect.Brokerages.Backtesting.BacktestingBrokerage.
|
pure virtual |
Connects the client to the broker's remote servers
Implements QuantConnect.Interfaces.IBrokerage.
Implemented in QuantConnect.Brokerages.Backtesting.BacktestingBrokerage, and QuantConnect.Brokerages.BaseWebsocketsBrokerage.
|
pure virtual |
Disconnects the client from the broker's remote servers
Implements QuantConnect.Interfaces.IBrokerage.
Implemented in QuantConnect.Brokerages.Backtesting.BacktestingBrokerage.
|
virtual |
Dispose of the brokerage instance
Definition at line 142 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the OrderFilled event
orderEvents | The list of order events |
Reimplemented in QuantConnect.Brokerages.Backtesting.BacktestingBrokerage.
Definition at line 151 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the OrderFilled event
e | The order event |
Definition at line 167 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the OrderUpdated event
e | The update event |
Definition at line 176 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the OrderIdChanged event
e | The BrokerageOrderIdChangedEvent |
Definition at line 192 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the OptionPositionAssigned event
e | The OrderEvent |
Definition at line 208 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the OptionNotification event
e | The OptionNotification event arguments |
Definition at line 226 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the NewBrokerageOrderNotification event
e | The NewBrokerageOrderNotification event arguments |
Definition at line 244 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the DelistingNotification event
e | The DelistingNotification event arguments |
Definition at line 262 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the AccountChanged event
e | The AccountEvent |
Definition at line 280 of file Brokerage.cs.
|
protectedvirtual |
Event invocator for the Message event
e | The error |
Definition at line 298 of file Brokerage.cs.
|
protectedvirtual |
Helper method that will try to get the live holdings from the provided brokerage data collection else will default to the algorithm state
Holdings will removed from the provided collection on the first call, since this method is expected to be called only once on initialize, after which the algorithm should use Lean accounting
Definition at line 324 of file Brokerage.cs.
|
protectedvirtual |
Helper method that will try to get the live cash balance from the provided brokerage data collection else will default to the algorithm state
Cash balance will removed from the provided collection on the first call, since this method is expected to be called only once on initialize, after which the algorithm should use Lean accounting
Definition at line 353 of file Brokerage.cs.
|
pure virtual |
Gets all open orders on the account. NOTE: The order objects returned do not have QC order IDs.
Implements QuantConnect.Interfaces.IBrokerage.
Implemented in QuantConnect.Brokerages.Backtesting.BacktestingBrokerage.
|
pure virtual |
Gets all holdings for the account
Implements QuantConnect.Interfaces.IBrokerage.
Implemented in QuantConnect.Brokerages.Backtesting.BacktestingBrokerage, and QuantConnect.Brokerages.Paper.PaperBrokerage.
|
pure virtual |
Gets the current cash balance for each currency held in the brokerage account
Implements QuantConnect.Interfaces.IBrokerage.
Implemented in QuantConnect.Brokerages.Backtesting.BacktestingBrokerage, and QuantConnect.Brokerages.Paper.PaperBrokerage.
|
virtual |
Gets the history for the requested security
request | The historical data request |
Implements QuantConnect.Interfaces.IBrokerage.
Definition at line 409 of file Brokerage.cs.
|
staticprotected |
Gets the position that might result given the specified order direction and the current holdings quantity. This is useful for brokerages that require more specific direction information than provided by the OrderDirection enum (e.g. Tradier differentiates Buy/Sell and BuyToOpen/BuyToCover/SellShort/SellToClose)
orderDirection | The order direction |
holdingsQuantity | The current holdings quantity |
Definition at line 422 of file Brokerage.cs.
|
virtual |
Returns whether the brokerage should perform the cash synchronization
currentTimeUtc | The current time (UTC) |
Implements QuantConnect.Interfaces.IBrokerageCashSynchronizer.
Definition at line 449 of file Brokerage.cs.
|
virtual |
Synchronizes the cashbook with the brokerage account
algorithm | The algorithm instance |
currentTimeUtc | The current time (UTC) |
getTimeSinceLastFill | A function which returns the time elapsed since the last fill |
Implements QuantConnect.Interfaces.IBrokerageCashSynchronizer.
Definition at line 468 of file Brokerage.cs.
virtual bool QuantConnect.Brokerages.Brokerage.AccountInstantlyUpdated => false |
Specifies whether the brokerage will instantly update account balances
Definition at line 397 of file Brokerage.cs.
|
protected |
Gets the date of the last sync (New York time zone)
Definition at line 437 of file Brokerage.cs.
DateTime QuantConnect.Brokerages.Brokerage.LastSyncDateTimeUtc => new DateTime(Interlocked.Read(ref _lastSyncTimeTicks)) |
Gets the datetime of the last sync (UTC)
Definition at line 442 of file Brokerage.cs.
|
get |
Gets the name of the brokerage
Definition at line 92 of file Brokerage.cs.
|
get |
Returns true if we're currently connected to the broker
Definition at line 97 of file Brokerage.cs.
|
getprotected set |
Returns the brokerage account's base currency
Definition at line 402 of file Brokerage.cs.
EventHandler<BrokerageOrderIdChangedEvent> QuantConnect.Brokerages.Brokerage.OrderIdChanged |
Event that fires each time the brokerage order id changes
Definition at line 45 of file Brokerage.cs.
EventHandler<List<OrderEvent> > QuantConnect.Brokerages.Brokerage.OrdersStatusChanged |
Event that fires each time the status for a list of orders change
Definition at line 49 of file Brokerage.cs.
EventHandler<OrderUpdateEvent> QuantConnect.Brokerages.Brokerage.OrderUpdated |
Event that fires each time an order is updated in the brokerage side
These are not status changes but mainly price changes, like the stop price of a trailing stop order
Definition at line 57 of file Brokerage.cs.
EventHandler<OrderEvent> QuantConnect.Brokerages.Brokerage.OptionPositionAssigned |
Event that fires each time a short option position is assigned
Definition at line 62 of file Brokerage.cs.
EventHandler<OptionNotificationEventArgs> QuantConnect.Brokerages.Brokerage.OptionNotification |
Event that fires each time an option position has changed
Definition at line 67 of file Brokerage.cs.
EventHandler<NewBrokerageOrderNotificationEventArgs> QuantConnect.Brokerages.Brokerage.NewBrokerageOrderNotification |
Event that fires each time there's a brokerage side generated order
Definition at line 72 of file Brokerage.cs.
EventHandler<DelistingNotificationEventArgs> QuantConnect.Brokerages.Brokerage.DelistingNotification |
Event that fires each time a delisting occurs
Definition at line 77 of file Brokerage.cs.
EventHandler<AccountEvent> QuantConnect.Brokerages.Brokerage.AccountChanged |
Event that fires each time a user's brokerage account is changed
Definition at line 82 of file Brokerage.cs.
EventHandler<BrokerageMessageEvent> QuantConnect.Brokerages.Brokerage.Message |
Event that fires when an error is encountered in the brokerage
Definition at line 87 of file Brokerage.cs.