Lean
$LEAN_TAG$
|
Provides shared brokerage websockets implementation More...
Public Member Functions | |
override void | Connect () |
Creates wss connection, monitors for disconnection and re-connects when necessary More... | |
Public Member Functions inherited from QuantConnect.Brokerages.Brokerage | |
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 | 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... | |
Protected Member Functions | |
void | Initialize (string wssUrl, IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret) |
Initialize the instance of this class More... | |
BaseWebsocketsBrokerage (string name) | |
Creates an instance of a websockets brokerage More... | |
abstract void | OnMessage (object sender, WebSocketMessage e) |
Handles websocket received messages More... | |
abstract bool | Subscribe (IEnumerable< Symbol > symbols) |
Handles the creation of websocket subscriptions More... | |
virtual IEnumerable< Symbol > | GetSubscribed () |
Gets a list of current subscriptions More... | |
void | ConnectSync () |
Start websocket connect More... | |
Protected Member Functions inherited from QuantConnect.Brokerages.Brokerage | |
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... | |
virtual CrossZeroOrderResponse | PlaceCrossZeroOrder (CrossZeroFirstOrderRequest crossZeroOrderRequest, bool isPlaceOrderWithLeanEvent=true) |
Places an order that crosses zero (transitions from a short position to a long position or vice versa) and returns the response. This method should be overridden in a derived class to implement brokerage-specific logic for placing such orders. More... | |
bool? | TryCrossZeroPositionOrder (Order order, decimal holdingQuantity) |
Attempts to place an order that may cross the zero position. If the order needs to be split into two parts due to crossing zero, this method handles the split and placement accordingly. More... | |
bool | TryGetUpdateCrossZeroOrderQuantity (Order leanOrder, out decimal quantity) |
Determines whether the given Lean order crosses zero quantity based on the initial order quantity. More... | |
bool | TryGetOrRemoveCrossZeroOrder (string brokerageOrderId, OrderStatus leanOrderStatus, out Order leanOrder) |
Attempts to retrieve or remove a cross-zero order based on the brokerage order ID and its filled status. More... | |
bool | TryHandleRemainingCrossZeroOrder (Order leanOrder, OrderEvent orderEvent) |
Attempts to handle any remaining orders that cross the zero boundary. More... | |
Properties | |
bool | IsInitialized [get, set] |
True if the current brokerage is already initialized More... | |
IWebSocket | WebSocket [get, set] |
The websockets client instance More... | |
IRestClient | RestClient [get, set] |
The rest client instance More... | |
JsonSerializerSettings | JsonSettings [get, set] |
standard json parsing settings More... | |
ConcurrentDictionary< int, Orders.Order > | CachedOrderIDs [get, set] |
A list of currently active orders More... | |
string | ApiSecret [get, set] |
The api secret More... | |
string | ApiKey [get, set] |
The api key More... | |
DataQueueHandlerSubscriptionManager | SubscriptionManager [get, set] |
Count subscribers for each (symbol, tickType) combination More... | |
Properties inherited from QuantConnect.Brokerages.Brokerage | |
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... | |
ConcurrentDictionary< string, Order > | LeanOrderByZeroCrossBrokerageOrderId = new() [get] |
A thread-safe dictionary that maps brokerage order IDs to their corresponding Order objects. 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... | |
Additional Inherited Members | |
Public Attributes inherited from QuantConnect.Brokerages.Brokerage | |
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... | |
Static Protected Member Functions inherited from QuantConnect.Brokerages.Brokerage | |
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 inherited from QuantConnect.Brokerages.Brokerage | |
DateTime | LastSyncDate => LastSyncDateTimeUtc.ConvertFromUtc(TimeZones.NewYork).Date |
Gets the date of the last sync (New York time zone) More... | |
Events inherited from QuantConnect.Brokerages.Brokerage | |
EventHandler< BrokerageOrderIdChangedEvent > | OrderIdChanged |
Event that fires each time the brokerage order id changes More... | |
EventHandler< List< OrderEvent > > | OrdersStatusChanged |
Event that fires each time the status for a list of orders change More... | |
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 |
Event that fires each time the status for a list of orders change More... | |
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... | |
Provides shared brokerage websockets implementation
Definition at line 32 of file BaseWebsocketsBrokerage.cs.
|
protected |
Creates an instance of a websockets brokerage
name | Name of brokerage |
Definition at line 113 of file BaseWebsocketsBrokerage.cs.
|
protected |
Initialize the instance of this class
wssUrl | The web socket base url |
websocket | instance of websockets client |
restClient | instance of rest client |
apiKey | api key |
apiSecret | api secret |
Definition at line 84 of file BaseWebsocketsBrokerage.cs.
|
protectedpure virtual |
Handles websocket received messages
sender | |
e |
|
virtual |
Creates wss connection, monitors for disconnection and re-connects when necessary
Implements QuantConnect.Brokerages.Brokerage.
Definition at line 127 of file BaseWebsocketsBrokerage.cs.
|
protectedpure virtual |
Handles the creation of websocket subscriptions
symbols |
|
protectedvirtual |
Gets a list of current subscriptions
Definition at line 147 of file BaseWebsocketsBrokerage.cs.
|
protected |
Start websocket connect
Definition at line 155 of file BaseWebsocketsBrokerage.cs.
|
getsetprotected |
True if the current brokerage is already initialized
Definition at line 39 of file BaseWebsocketsBrokerage.cs.
|
getsetprotected |
The websockets client instance
Definition at line 44 of file BaseWebsocketsBrokerage.cs.
|
getsetprotected |
The rest client instance
Definition at line 49 of file BaseWebsocketsBrokerage.cs.
|
getsetprotected |
standard json parsing settings
Definition at line 54 of file BaseWebsocketsBrokerage.cs.
|
getset |
A list of currently active orders
Definition at line 59 of file BaseWebsocketsBrokerage.cs.
|
getsetprotected |
The api secret
Definition at line 64 of file BaseWebsocketsBrokerage.cs.
|
getsetprotected |
The api key
Definition at line 69 of file BaseWebsocketsBrokerage.cs.
|
getsetprotected |
Count subscribers for each (symbol, tickType) combination
Definition at line 74 of file BaseWebsocketsBrokerage.cs.