Lean  $LEAN_TAG$
QuantConnect.Brokerages.Paper.PaperBrokerage Class Reference

Paper Trading Brokerage More...

Inheritance diagram for QuantConnect.Brokerages.Paper.PaperBrokerage:
[legend]

Public Member Functions

 PaperBrokerage (IAlgorithm algorithm, LiveNodePacket job)
 Creates a new PaperBrokerage More...
 
override List< CashAmountGetCashBalance ()
 Gets the current cash balance for each currency held in the brokerage account More...
 
override List< HoldingGetAccountHoldings ()
 Gets all holdings for the account More...
 
override void Scan ()
 Scans all the outstanding orders and applies the algorithm model fills to generate the order events. This override adds dividend detection and application More...
 
- Public Member Functions inherited from QuantConnect.Brokerages.Backtesting.BacktestingBrokerage
 BacktestingBrokerage (IAlgorithm algorithm)
 Creates a new BacktestingBrokerage for the specified algorithm More...
 
override List< OrderGetOpenOrders ()
 Gets all open orders on the account More...
 
override bool PlaceOrder (Order order)
 Places a new order and assigns a new broker ID to the order More...
 
override bool UpdateOrder (Order order)
 Updates the order with the same ID More...
 
override bool CancelOrder (Order order)
 Cancels the order with the specified ID More...
 
override void Connect ()
 The BacktestingBrokerage is always connected. This is a no-op. More...
 
override void Disconnect ()
 The BacktestingBrokerage is always connected. This is a no-op. More...
 
void ProcessDelistings (Delistings delistings)
 Process delistings More...
 
- Public Member Functions inherited from QuantConnect.Brokerages.Brokerage
virtual void Dispose ()
 Dispose of the brokerage instance 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...
 

Additional Inherited Members

- Public Attributes inherited from QuantConnect.Brokerages.Backtesting.BacktestingBrokerage
override bool IsConnected => true
 Gets the connection status More...
 
- 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...
 
- Protected Member Functions inherited from QuantConnect.Brokerages.Backtesting.BacktestingBrokerage
 BacktestingBrokerage (IAlgorithm algorithm, string name)
 Creates a new BacktestingBrokerage for the specified algorithm More...
 
override void OnOrderEvents (List< OrderEvent > orderEvents)
 Event invocator for the OrderFilled event More...
 
- Protected Member Functions inherited from QuantConnect.Brokerages.Brokerage
 Brokerage (string name)
 Creates a new Brokerage instance with the specified name 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...
 
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...
 
- 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...
 
- Properties inherited from QuantConnect.Brokerages.Backtesting.BacktestingBrokerage
IAlgorithm Algorithm [get]
 This is the algorithm under test 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, OrderLeanOrderByZeroCrossBrokerageOrderId = 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...
 
- Events inherited from QuantConnect.Brokerages.Brokerage
EventHandler< BrokerageOrderIdChangedEventOrderIdChanged
 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< 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
 Event that fires each time the status for a list of orders change More...
 
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

Paper Trading Brokerage

Definition at line 29 of file PaperBrokerage.cs.

Constructor & Destructor Documentation

◆ PaperBrokerage()

QuantConnect.Brokerages.Paper.PaperBrokerage.PaperBrokerage ( IAlgorithm  algorithm,
LiveNodePacket  job 
)

Creates a new PaperBrokerage

Parameters
algorithmThe algorithm under analysis
jobThe job packet

Definition at line 39 of file PaperBrokerage.cs.

Member Function Documentation

◆ GetCashBalance()

override List<CashAmount> QuantConnect.Brokerages.Paper.PaperBrokerage.GetCashBalance ( )
virtual

Gets the current cash balance for each currency held in the brokerage account

Returns
The current cash balance for each currency available for trading

Reimplemented from QuantConnect.Brokerages.Backtesting.BacktestingBrokerage.

Definition at line 49 of file PaperBrokerage.cs.

◆ GetAccountHoldings()

override List<Holding> QuantConnect.Brokerages.Paper.PaperBrokerage.GetAccountHoldings ( )
virtual

Gets all holdings for the account

Returns
The current holdings from the account

Reimplemented from QuantConnect.Brokerages.Backtesting.BacktestingBrokerage.

Definition at line 58 of file PaperBrokerage.cs.

◆ Scan()

override void QuantConnect.Brokerages.Paper.PaperBrokerage.Scan ( )
virtual

Scans all the outstanding orders and applies the algorithm model fills to generate the order events. This override adds dividend detection and application

Reimplemented from QuantConnect.Brokerages.Backtesting.BacktestingBrokerage.

Definition at line 67 of file PaperBrokerage.cs.

Here is the call graph for this function:

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