tensortrade.oms.orders.order module

class tensortrade.oms.orders.order.Order(step: int, side: tensortrade.oms.orders.trade.TradeSide, trade_type: tensortrade.oms.orders.trade.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: tensortrade.core.base.TimedIdentifiable, tensortrade.core.base.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_pair : ExchangePair
The exchange pair to perform the order for.
price : float
The price of the order.
trade_type : TradeType
The type of trade being made.
exchange_pair : ExchangePair
The exchange pair that the order is made for.
quantity : Quantity
The quantity of the order.
portfolio : Portfolio
The portfolio being used in the order.
criteria : Callable[[Order, Exchange], bool], optional
The criteria under which the order will be considered executable.
path_id : str, optional
The path order id.
start : int, optional
The start time of the order.
end : int, 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.
base_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() → tensortrade.oms.orders.order.Order[source]

Completes an order.

Returns:Order – The completed order.
execute() → None[source]

Executes the order.

fill(trade: tensortrade.oms.orders.trade.Trade) → None[source]

Fills the order.

Parameters:trade (Trade) – A trade to fill the order.
is_active

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

is_buy

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

is_cancelled

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

is_complete

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

is_executable

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

is_expired

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

is_limit_order

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

is_market_order

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

is_sell

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

pair

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

quote_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.
size

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[source]

Bases: enum.Enum

An enumeration for the status of an order.

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