tensortrade.oms.orders.order module

class tensortrade.oms.orders.order.Order(step: int, side: TradeSide, trade_type: TradeType, exchange_pair: ExchangePair, quantity: Quantity, portfolio: Portfolio, price: float, criteria: Callable[[Order, Exchange], bool] = None, path_id: str = None, start: int = None, end: int = None)[source]

Bases: TimedIdentifiable, Observable

A class to represent ordering an amount of a financial instrument.

Responsibilities of the Order:
  1. Confirming its own validity.

  2. Tracking its trades and reporting it back to the broker.

  3. Managing movement of quantities from order to order.

  4. Generating the next order in its path given that there is a ‘OrderSpec’ for how to make the next order.

  5. Managing its own state changes when it can.

Parameters:

side (TradeSide) – The side of the order.

exchange_pairExchangePair

The exchange pair to perform the order for.

pricefloat

The price of the order.

trade_typeTradeType

The type of trade being made.

exchange_pairExchangePair

The exchange pair that the order is made for.

quantityQuantity

The quantity of the order.

portfolioPortfolio

The portfolio being used in the order.

criteriaCallable[[Order, Exchange], bool], optional

The criteria under which the order will be considered executable.

path_idstr, optional

The path order id.

startint, optional

The start time of the order.

endint, optional

The end time of the order.

Raises:

InvalidOrderQuantity – Raised if the given quantity has a size of 0.

add_order_spec(order_spec: OrderSpec) Order[source]

Adds an order specification to the order.

Parameters:

order_spec (OrderSpec) – An order specification.

Returns:

Order – The current order.

property base_instrument: Instrument

The base instrument of the pair being traded.

cancel(reason: str = 'CANCELLED') None[source]

Cancels an order.

Parameters:

reason (str, default 'CANCELLED') – The reason for canceling the order.

complete() Order[source]

Completes an order.

Returns:

Order – The completed order.

execute() None[source]

Executes the order.

fill(trade: Trade) None[source]

Fills the order.

Parameters:

trade (Trade) – A trade to fill the order.

property is_active: bool

If this order is active. (bool, read-only)

property is_buy: bool

If this is a buy order. (bool, read-only)

property is_cancelled: bool

If this order is cancelled. (bool, read-only)

property is_complete: bool

If this order is complete. (bool, read-only)

property is_executable: bool

If this order is executable. (bool, read-only)

property is_expired: bool

If this order is expired. (bool, read-only)

property is_limit_order: bool

If this is a limit order. (bool, read-only)

property is_market_order: bool

If this is a market order. (bool, read-only)

property is_sell: bool

If this is a sell order. (bool, read-only)

property pair: TradingPair

The trading pair of the order. (TradingPair, read-only)

property quote_instrument: Instrument

The quote instrument of the pair being traded.

release(reason: str = 'RELEASE (NO REASON)') None[source]

Releases all quantities from every wallet that have been allocated for this order.

Parameters:

reason (str, default 'RELEASE (NO REASON)') – The reason for releasing all locked quantities associated with the order.

property size: Decimal

The size of the order. (Decimal, read-only)

to_dict() dict[source]

Creates a dictionary representation of the order.

Returns:

dict – The dictionary representation of the order.

to_json() dict[source]

Creates a json dictionary representation of the order.

Returns:

dict – The json dictionary representation of the order

class tensortrade.oms.orders.order.OrderStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

An enumeration for the status of an order.

CANCELLED = 'cancelled'
FILLED = 'filled'
OPEN = 'open'
PARTIALLY_FILLED = 'partially_filled'
PENDING = 'pending'