Lean  $LEAN_TAG$
QuantConnect.Brokerages.BaseWebsocketsBrokerage Class Referenceabstract

Provides shared brokerage websockets implementation More...

Inheritance diagram for QuantConnect.Brokerages.BaseWebsocketsBrokerage:
[legend]

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< OrderGetOpenOrders ()
 Gets all open orders on the account. NOTE: The order objects returned do not have QC order IDs. More...
 
abstract List< HoldingGetAccountHoldings ()
 Gets all holdings for the account More...
 
abstract List< CashAmountGetCashBalance ()
 Gets the current cash balance for each currency held in the brokerage account More...
 
virtual IEnumerable< BaseDataGetHistory (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< SymbolGetSubscribed ()
 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< HoldingGetAccountHoldings (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< CashAmountGetCashBalance (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...
 

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.OrderCachedOrderIDs [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...
 
- 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< BrokerageOrderIdChangedEventOrderIdChanged
 Event that fires each time the brokerage order id changes More...
 
EventHandler< List< OrderEvent > > OrdersStatusChanged
 
EventHandler< OrderUpdateEventOrderUpdated
 Event that fires each time an order is updated in the brokerage side More...
 
EventHandler< OrderEventOptionPositionAssigned
 Event that fires each time a short option position is assigned More...
 
EventHandler< OptionNotificationEventArgsOptionNotification
 Event that fires each time an option position has changed More...
 
EventHandler< NewBrokerageOrderNotificationEventArgsNewBrokerageOrderNotification
 Event that fires each time there's a brokerage side generated order More...
 
EventHandler< DelistingNotificationEventArgsDelistingNotification
 Event that fires each time a delisting occurs More...
 
EventHandler< AccountEventAccountChanged
 Event that fires each time a user's brokerage account is changed More...
 
EventHandler< BrokerageMessageEventMessage
 Event that fires when an error is encountered in the brokerage More...
 
- Events inherited from QuantConnect.Interfaces.IBrokerage
EventHandler< BrokerageOrderIdChangedEventOrderIdChanged
 Event that fires each time the brokerage order id changes More...
 
EventHandler< List< OrderEvent > > OrdersStatusChanged
 
EventHandler< OrderUpdateEventOrderUpdated
 Event that fires each time an order is updated in the brokerage side More...
 
EventHandler< OrderEventOptionPositionAssigned
 Event that fires each time a short option position is assigned More...
 
EventHandler< OptionNotificationEventArgsOptionNotification
 Event that fires each time an option position has changed More...
 
EventHandler< NewBrokerageOrderNotificationEventArgsNewBrokerageOrderNotification
 Event that fires each time there's a brokerage side generated order More...
 
EventHandler< DelistingNotificationEventArgsDelistingNotification
 Event that fires each time a delisting occurs More...
 
EventHandler< AccountEventAccountChanged
 Event that fires each time a user's brokerage account is changed More...
 
EventHandler< BrokerageMessageEventMessage
 Event that fires when a message is received from the brokerage More...
 

Detailed Description

Provides shared brokerage websockets implementation

Definition at line 32 of file BaseWebsocketsBrokerage.cs.

Constructor & Destructor Documentation

◆ BaseWebsocketsBrokerage()

QuantConnect.Brokerages.BaseWebsocketsBrokerage.BaseWebsocketsBrokerage ( string  name)
protected

Creates an instance of a websockets brokerage

Parameters
nameName of brokerage

Definition at line 113 of file BaseWebsocketsBrokerage.cs.

Member Function Documentation

◆ Initialize()

void QuantConnect.Brokerages.BaseWebsocketsBrokerage.Initialize ( string  wssUrl,
IWebSocket  websocket,
IRestClient  restClient,
string  apiKey,
string  apiSecret 
)
protected

Initialize the instance of this class

Parameters
wssUrlThe web socket base url
websocketinstance of websockets client
restClientinstance of rest client
apiKeyapi key
apiSecretapi secret

Definition at line 84 of file BaseWebsocketsBrokerage.cs.

Here is the call graph for this function:

◆ OnMessage()

abstract void QuantConnect.Brokerages.BaseWebsocketsBrokerage.OnMessage ( object  sender,
WebSocketMessage  e 
)
protectedpure virtual

Handles websocket received messages

Parameters
sender
e
Here is the caller graph for this function:

◆ Connect()

override void QuantConnect.Brokerages.BaseWebsocketsBrokerage.Connect ( )
virtual

Creates wss connection, monitors for disconnection and re-connects when necessary

Implements QuantConnect.Brokerages.Brokerage.

Definition at line 127 of file BaseWebsocketsBrokerage.cs.

Here is the call graph for this function:

◆ Subscribe()

abstract bool QuantConnect.Brokerages.BaseWebsocketsBrokerage.Subscribe ( IEnumerable< Symbol symbols)
protectedpure virtual

Handles the creation of websocket subscriptions

Parameters
symbols
Here is the caller graph for this function:

◆ GetSubscribed()

virtual IEnumerable<Symbol> QuantConnect.Brokerages.BaseWebsocketsBrokerage.GetSubscribed ( )
protectedvirtual

Gets a list of current subscriptions

Returns

Definition at line 147 of file BaseWebsocketsBrokerage.cs.

Here is the caller graph for this function:

◆ ConnectSync()

void QuantConnect.Brokerages.BaseWebsocketsBrokerage.ConnectSync ( )
protected

Start websocket connect

Definition at line 155 of file BaseWebsocketsBrokerage.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

Property Documentation

◆ IsInitialized

bool QuantConnect.Brokerages.BaseWebsocketsBrokerage.IsInitialized
getsetprotected

True if the current brokerage is already initialized

Definition at line 39 of file BaseWebsocketsBrokerage.cs.

◆ WebSocket

IWebSocket QuantConnect.Brokerages.BaseWebsocketsBrokerage.WebSocket
getsetprotected

The websockets client instance

Definition at line 44 of file BaseWebsocketsBrokerage.cs.

◆ RestClient

IRestClient QuantConnect.Brokerages.BaseWebsocketsBrokerage.RestClient
getsetprotected

The rest client instance

Definition at line 49 of file BaseWebsocketsBrokerage.cs.

◆ JsonSettings

JsonSerializerSettings QuantConnect.Brokerages.BaseWebsocketsBrokerage.JsonSettings
getsetprotected

standard json parsing settings

Definition at line 54 of file BaseWebsocketsBrokerage.cs.

◆ CachedOrderIDs

ConcurrentDictionary<int, Orders.Order> QuantConnect.Brokerages.BaseWebsocketsBrokerage.CachedOrderIDs
getset

A list of currently active orders

Definition at line 59 of file BaseWebsocketsBrokerage.cs.

◆ ApiSecret

string QuantConnect.Brokerages.BaseWebsocketsBrokerage.ApiSecret
getsetprotected

The api secret

Definition at line 64 of file BaseWebsocketsBrokerage.cs.

◆ ApiKey

string QuantConnect.Brokerages.BaseWebsocketsBrokerage.ApiKey
getsetprotected

The api key

Definition at line 69 of file BaseWebsocketsBrokerage.cs.

◆ SubscriptionManager

DataQueueHandlerSubscriptionManager QuantConnect.Brokerages.BaseWebsocketsBrokerage.SubscriptionManager
getsetprotected

Count subscribers for each (symbol, tickType) combination

Definition at line 74 of file BaseWebsocketsBrokerage.cs.


The documentation for this class was generated from the following file: