Instruments
Defines tradable asset/contract instruments with specific properties dependent on the asset class and instrument class.
class Instrument
Bases: Data
Instrument(InstrumentId instrument_id, Symbol raw_symbol, AssetClass asset_class, InstrumentClass instrument_class, Currency quote_currency, bool is_inverse, int price_precision, int size_precision, Quantity size_increment, Quantity multiplier, margin_init: Decimal, margin_maint: Decimal, maker_fee: Decimal, taker_fee: Decimal, uint64_t ts_event, uint64_t ts_init, Price price_increment: Price | None = None, Quantity lot_size: Quantity | None = None, Quantity max_quantity: Quantity | None = None, Quantity min_quantity: Quantity | None = None, Money max_notional: Money | None = None, Money min_notional: Money | None = None, Price max_price: Price | None = None, Price min_price: Price | None = None, unicode tick_scheme_name=None, dict info=None)
The base class for all instruments.
Represents a tradable instrument. This class can be used to define an instrument, or act as a parent class for more specific instruments.
- Parameters:
- instrument_id (InstrumentId) – The instrument ID for the instrument.
- raw_symbol (Symbol) – The raw/local/native symbol for the instrument, assigned by the venue.
- asset_class (AssetClass) – The instrument asset class.
- instrument_class (InstrumentClass) – The instrument class.
- quote_currency (Currency) – The quote currency.
- is_inverse (bool) – If the instrument costing is inverse (quantity expressed in quote currency units).
- price_precision (int) – The price decimal precision.
- size_precision (int) – The trading size decimal precision.
- size_increment (Price) – The minimum size increment.
- multiplier (Decimal) – The contract value multiplier (determines tick value).
- lot_size (Quantity , optional) – The rounded lot unit size (standard/board).
- margin_init (Decimal) – The initial (order) margin requirement in percentage of order value.
- margin_maint (Decimal) – The maintenance (position) margin in percentage of position value.
- maker_fee (Decimal) – The fee rate for liquidity makers as a percentage of order value (where 1.0 is 100%).
- taker_fee (Decimal) – The fee rate for liquidity takers as a percentage of order value (where 1.0 is 100%).
- ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the data event occurred.
- ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the data object was initialized.
- price_increment (Price , optional) – The minimum price increment (tick size).
- max_quantity (Quantity , optional) – The maximum allowable order quantity.
- min_quantity (Quantity , optional) – The minimum allowable order quantity.
- max_notional (Money , optional) – The maximum allowable order notional value.
- min_notional (Money , optional) – The minimum allowable order notional value.
- max_price (Price , optional) – The maximum allowable quoted price.
- min_price (Price , optional) – The minimum allowable quoted price.
- tick_scheme_name (str , optional) – The name of the tick scheme.
- info (dict *[*str , object ] , optional) – The additional instrument information.
- Raises:
- ValueError – If tick_scheme_name is not a valid string.
- ValueError – If price_precision is negative (< 0).
- ValueError – If size_precision is negative (< 0).
- ValueError – If price_increment is not positive (> 0).
- ValueError – If size_increment is not positive (> 0).
- ValueError – If price_precision is not equal to price_increment.precision.
- ValueError – If size_increment is not equal to size_increment.precision.
- ValueError – If multiplier is not positive (> 0).
- ValueError – If lot size is not positive (> 0).
- ValueError – If max_quantity is not positive (> 0).
- ValueError – If min_quantity is negative (< 0).
- ValueError – If max_notional is not positive (> 0).
- ValueError – If min_notional is negative (< 0).
- ValueError – If max_price is not positive (> 0).
- ValueError – If min_price is negative (< 0).
asset_class
The asset class of the instrument.
- Returns: AssetClass
static base_from_dict(dict values) → Instrument
Return an instrument from the given initialization values.
- Parameters: values (dict *[*str , object ]) – The values to initialize the instrument with.
- Return type: Instrument
static base_to_dict(Instrument obj)
Return a dictionary representation of this object.
- Return type: dict[str, object]
calculate_base_quantity(self, Quantity quantity, Price last_px) → Quantity
Calculate the base asset quantity from the given quote asset quantity and last price.
- Parameters:
- Return type: Quantity
get_base_currency(self) → Currency
Return the instruments base currency (if applicable).
- Return type:
Currency or
None
get_settlement_currency(self) → Currency
Return the currency used to settle a trade of the instrument.
- Standard linear instruments = quote_currency
- Inverse instruments = base_currency
- Quanto instruments = settlement_currency
- Return type: Currency
id
The instrument ID.
- Returns: InstrumentId
info
The raw info for the instrument.
- Returns: dict[str, object]
instrument_class
The class of the instrument.
- Returns: InstrumentClass
is_inverse
If the quantity is expressed in quote currency.
- Returns: Currency
lot_size
The rounded lot unit size (standard/board) for the instrument.
- Returns:
Quantity or
None
make_price(self, value) → Price
Return a new price from the given value using the instruments price precision.
- Parameters: value (integer , float , str or Decimal) – The value of the price.
- Return type: Price
make_qty(self, value) → Quantity
Return a new quantity from the given value using the instruments size precision.
- Parameters: value (integer , float , str or Decimal) – The value of the quantity.
- Return type: Quantity
- Raises: ValueError – If a non zero value is rounded to zero due to the instruments size increment or size precision.
maker_fee
The fee rate for liquidity makers as a percentage of order value (where 1.0 is 100%).
- Returns: Decimal
margin_init
The initial (order) margin rate for the instrument.
- Returns: Decimal
margin_maint
The maintenance (position) margin rate for the instrument.
- Returns: Decimal
max_notional
The maximum notional order value for the instrument.
- Returns:
Money or
None
max_price
The maximum printable price for the instrument.
- Returns:
Price or
None
max_quantity
The maximum order quantity for the instrument.
- Returns:
Quantity or
None
min_notional
The minimum notional order value for the instrument.
- Returns:
Money or
None
min_price
The minimum printable price for the instrument.
- Returns:
Price or
None
min_quantity
The minimum order quantity for the instrument.
- Returns:
Quantity or
None
multiplier
The contract multiplier for the instrument (determines tick value).
- Returns: Quantity
next_ask_price(self, double value, int num_ticks=0) → Price
Return the price n ask ticks away from value.
If a given price is between two ticks, n=0 will find the nearest ask tick.
- Parameters:
- value (double) – The reference value.
- num_ticks (int , default 0) – The number of ticks to move.
- Return type: Price
- Raises: ValueError – If a tick scheme is not initialized.
next_bid_price(self, double value, int num_ticks=0) → Price
Return the price n bid ticks away from value.
If a given price is between two ticks, n=0 will find the nearest bid tick.
- Parameters:
- value (double) – The reference value.
- num_ticks (int , default 0) – The number of ticks to move.
- Return type: Price
- Raises: ValueError – If a tick scheme is not initialized.
notional_value(self, Quantity quantity, Price price, bool use_quote_for_inverse=False) → Money
Calculate the notional value.
Result will be in quote currency for standard instruments, or base currency for inverse instruments.
- Parameters:
- Return type: Money
price_increment
The minimum price increment or tick size for the instrument.
- Returns: Price
price_precision
The price precision of the instrument.
- Returns: int
quote_currency
The quote currency for the instrument.
- Returns: Currency
raw_symbol
The raw/local/native symbol for the instrument, assigned by the venue.
- Returns: Symbol
size_increment
The minimum size increment for the instrument.
- Returns: Quantity
size_precision
The size precision of the instrument.
- Returns: int
symbol
Return the instruments ticker symbol.
- Return type: Symbol
taker_fee
The fee rate for liquidity takers as a percentage of order value (where 1.0 is 100%).
- Returns: Decimal
tick_scheme_name
The tick scheme name.
- Returns:
str or
None
ts_event
UNIX timestamp (nanoseconds) when the data event occurred.
- Returns: uint64_t
ts_init
UNIX timestamp (nanoseconds) when the object was initialized.
- Returns: uint64_t
venue
Return the instruments trading venue.
- Return type: Venue
instruments_from_pyo3(list pyo3_instruments) → list
class BettingInstrument
Bases: Instrument
BettingInstrument(unicode venue_name, int event_type_id, unicode event_type_name, int competition_id, unicode competition_name, int event_id, unicode event_name, unicode event_country_code, datetime event_open_date, unicode betting_type, unicode market_id, unicode market_name, datetime market_start_time, unicode market_type, int selection_id, unicode selection_name, unicode currency, float selection_handicap, int8_t price_precision, int8_t size_precision, uint64_t ts_event, uint64_t ts_init, unicode tick_scheme_name=None, Price min_price=None, Price max_price=None, dict info=None)
Represents an instrument in a betting market.
betting_type
competition_id
competition_name
event_country_code
event_id
event_name
event_open_date
event_type_id
event_type_name
static from_dict(dict values) → BettingInstrument
Return an instrument from the given initialization values.
- Parameters: values (dict *[*str , object ]) – The values to initialize the instrument with.
- Return type: BettingInstrument