broker – Order management classes

class pyalgotrade.broker.Broker(cash, commission=None)

Class responsible for processing orders.

Parameters:
  • cash (int or float.) – The initial amount of cash.
  • commission (Commission) – An object responsible for calculating order commissions.
getCash()

Returns the amount of cash.

getShares(instrument)

Returns the number of shares for an instrument.

getValue(bars)

Returns the portfolio value (cash + shares) for the given bars prices.

Parameters:bars (pyalgotrade.bar.Bars.) – The bars to use to calculate share values.
placeOrder(order)

Submits an order.

Parameters:order (Order.) – The order to submit.
class pyalgotrade.broker.Order(action, instrument, quantity, goodTillCanceled=False)

Base class for orders.

Valid order actions are:
  • Order.Action.BUY
  • Order.Action.SELL
  • Order.Action.SELL_SHORT
Parameters:
  • action – The order action.
  • instrument (string.) – Instrument identifier.
  • quantity (int.) – Order quantity.
  • goodTillCanceled (boolean.) – True if the order is good till canceled. Orders that are not filled by the time the session closes will be will be automatically canceled if they were not set as good till canceled.

Note

This is a base class and should not be used directly.

cancel()

Cancels an accepted order. If the order is filled an Exception is raised.

getAction()

Returns the order action.

getExecutionInfo()

Returns the order execution info if the order was filled, or None otherwise.

Return type:OrderExecutionInfo.
getGoodTillCanceled()

Returns True if the order is good till canceled.

getInstrument()

Returns the instrument identifier.

getQuantity()

Returns the quantity.

getState()

Returns the order state.

Valid order states are:
  • Order.State.ACCEPTED (the initial state).
  • Order.State.CANCELED
  • Order.State.ACCEPTED
isAccepted()

Returns True if the order state is Order.State.ACCEPTED.

isCanceled()

Returns True if the order state is Order.State.CANCELED.

isFilled()

Returns True if the order state is Order.State.FILLED.

class pyalgotrade.broker.MarketOrder(action, instrument, quantity, goodTillCanceled=False, useClosingPrice=False)

An Order subclass that instructs the broker to buy or sell the stock immediately at the prevailing price, whatever that may be. If useClosingPrice is set to False then the opening price will be used to fill the order, otherwise the closing price will be used.

class pyalgotrade.broker.LimitOrder(action, instrument, price, quantity, goodTillCanceled=False)

An Order subclass that instructs the broker to buy or sell the stock stock at a particular price. The purchase or sale will not happen unless you get your price.

class pyalgotrade.broker.OrderExecutionInfo(price, commission, dateTime)

Execution information for a filled order.

getCommission()

Returns commission applied.

getDateTime()

Returns the datatime.datetime when the order was executed.

getPrice()

Returns execution price.

Previous topic

plotter – Strategy plotter

Next topic

optimizer – Parallel optimizers

This Page