tensortrade.oms.instruments.quantity module¶
- class tensortrade.oms.instruments.quantity.Quantity(instrument: Instrument, size: Decimal, path_id: str = None)[source]¶
Bases:
object
A size of a financial instrument for use in trading.
- Parameters:
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.
- Raises:
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() Quantity [source]¶
Gets the free version of this quantity.
- Returns:
Quantity – The free version of the quantity.
- lock_for(path_id: str) 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() Quantity [source]¶
Computes the quantization of current quantity in terms of the instrument’s precision.
- Returns:
Quantity – The quantized quantity.
- static validate(left: Quantity | Number, right: Quantity | Number) Tuple[Quantity, Quantity] [source]¶
Validates the given left and right arguments of a numeric or boolean operation.
- Parameters:
left (Union[Quantity, Number]) – The left argument of an operation.
right (Union[Quantity, Number]) – The right argument of an operation.
- Returns:
Tuple[Quantity, Quantity] – The validated quantity arguments to use in a numeric or boolean operation.
- Raises:
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.