tensortrade.oms.instruments.quantity module

class tensortrade.oms.instruments.quantity.Quantity(instrument: Instrument, size: decimal.Decimal, path_id: str = None)[source]

Bases: object

A size of a financial instrument for use in trading.

  • instrument (Instrument) – The unit of the quantity.
  • size (Decimal) – The number of units of the instrument.
  • path_id (str, optional) – The path order_id that this quantity is allocated for and associated with.

InvalidNegativeQuantity – Raised if the size of the quantity being created is negative.

as_float() → float[source]

Gets the size as a float.

Returns:float – The size as a floating point number.
contain(exchange_pair: ExchangePair)[source]

Contains the size of the quantity to be compatible with the settings of a given exchange.

Parameters:exchange_pair (ExchangePair) – The exchange pair containing the exchange the quantity must be compatible with.
Returns:Quantity – A quantity compatible with the given exchange.
convert(exchange_pair: ExchangePair) → Quantity[source]

Converts the quantity into the value of another instrument based on its exchange rate from an exchange.

Parameters:exchange_pair (ExchangePair) – The exchange pair to use for getting the quoted price to perform the conversion.
Returns:Quantity – The value of the current quantity in terms of the quote instrument.
free() → tensortrade.oms.instruments.quantity.Quantity[source]

Gets the free version of this quantity.

Returns:Quantity – The free version of the quantity.

If quantity is locked for an order. (bool, read-only)

lock_for(path_id: str) → tensortrade.oms.instruments.quantity.Quantity[source]

Locks a quantity for an Order identified associated with path_id.

Parameters:path_id (str) – The identification of the order path.
Returns:Quantity – A locked quantity for an order path.
quantize() → tensortrade.oms.instruments.quantity.Quantity[source]

Computes the quantization of current quantity in terms of the instrument’s precision.

Returns:Quantity – The quantized quantity.
static validate(left: Union[tensortrade.oms.instruments.quantity.Quantity, numbers.Number], right: Union[tensortrade.oms.instruments.quantity.Quantity, numbers.Number]) → Tuple[tensortrade.oms.instruments.quantity.Quantity, tensortrade.oms.instruments.quantity.Quantity][source]

Validates the given left and right arguments of a numeric or boolean operation.

  • left (Union[Quantity, Number]) – The left argument of an operation.
  • right (Union[Quantity, Number]) – The right argument of an operation.

Tuple[Quantity, Quantity] – The validated quantity arguments to use in a numeric or boolean operation.

  • IncompatibleInstrumentOperation – Raised if the instruments left and right quantities are not equal.
  • QuantityOpPathMismatch – Raised if
    • One argument is locked and the other argument is not.
    • Both arguments are locked quantities with unequal path_ids.
  • InvalidNonNumericQuantity – Raised if either argument is a non-numeric object.
  • Exception – If the operation is not valid.