Source code for mlthon.instruments.instrument
from typing import *
from decimal import Decimal
from mlthon.basics.defs import Exchange, InstrumentType
from mlthon.basics.mldecimal import MLDecimal
from mlthon.basics.qty import Qty
[docs]class Instrument(object):
"""
Instrument class, including all the necessary infos for an instrument/product.
"""
def __init__(self, instrument_id: int = None, instrument_type: InstrumentType = None,
instrument_group_id: str = None, exch_instr_id: str = None,
exchange: Exchange = None, mlt_symbol: str = None,
price_tick_rules: dict = None, quantity_tick_rules: dict = None, multiplier: MLDecimal = None,
min_quantity: Qty = None, base_currency: str = None, quote_currency: str = None,
quantification: str = None, price_precision: int = None, quantity_precision: int = None,
valid_start_ts: int = None, valid_end_ts: int = None, instrument_name: str = None, **kwargs):
"""Construct a new Instrument object.
Parameters
----------
instrument_id: int
ID used to uniquely identify this instrument (different for each exchange).
instrument_type: :obj:`.InstrumentType`
specifies instrument type.
instrument_group_id: str
ID used to group instruments considered to be equivalent across exchanges.
exch_instr_id: str
instrument ID used by the exchange.
exchange: :obj:`.Exchange`
the exchange this instrument exists on.
mlt_symbol: str
symbol used by the exchange to identify the instrument.
price_tick_rules: dict
contains tick rules for different price ranges.
quantity_tick_rules: dict
contains tick rules for different quantity ranges.
multiplier: :obj:`.MLDecimal`
quantification multiplier for a particular instrument.
min_quantity: :obj:`.Qty`
minimum quantity allowed for this instrument on the exchange.
base_currency: str
the base currency of the pair used in this instrument.
quote_currency: str
the quote currency of the pair used in this instrument.
quantification: str
whether qty of this instrument are expressed in base or quote currency. Possible value: 'base', 'quote'.
price_precision: int
price precision for the instrument.
quantity_precision: int
quantity precision for the instrument.
valid_start_ts: int
timestamp that specifies when this instrument data started to be valid.
valid_end_ts: int
timestamp that specifies the end of the valid period.
instrument_name: str
generated at construction time as <exchange_id>:<type_id>:<mlt_symbol>.
kwargs: dict
some unused arguments in instrument msg.
"""
self.instrument_id_ = instrument_id
self.instrument_type_ = instrument_type
self.instrument_group_id_ = instrument_group_id
self.exch_instr_id_ = exch_instr_id
self.exchange_ = exchange
self.mlt_symbol_ = mlt_symbol
self.price_tick_rules_ = price_tick_rules
self.quantity_tick_rules_ = quantity_tick_rules
self.multiplier_ = multiplier
self.min_quantity_ = min_quantity
self.base_currency_ = base_currency
self.quote_currency_ = quote_currency
self.quantification_ = quantification
self.price_precision_ = price_precision
self.quantity_precision_ = quantity_precision
self.valid_start_ts_ = valid_start_ts
self.valid_end_ts_ = valid_end_ts
self.instrument_name_ = instrument_name
# Public get methods
[docs] def get_instrument_id(self) -> int:
return self.instrument_id_
[docs] def get_instrument_type(self) -> InstrumentType:
return self.instrument_type_
[docs] def get_instrument_group_id(self) -> str:
return self.instrument_group_id_
[docs] def get_exch_instr_id(self) -> str:
return self.exch_instr_id_
[docs] def get_exchange(self) -> Exchange:
return self.exchange_
[docs] def get_mlt_symbol(self) -> str:
return self.mlt_symbol_
[docs] def get_price_tick_rules(self) -> dict:
return self.price_tick_rules_
[docs] def get_quantity_tick_rules(self) -> dict:
return self.quantity_tick_rules_
[docs] def get_multiplier(self) -> MLDecimal:
return self.multiplier_
[docs] def get_min_quantity(self) -> Qty:
return self.min_quantity_
[docs] def get_base_currency(self) -> str:
return self.base_currency_
[docs] def get_quote_currency(self) -> str:
return self.quote_currency_
[docs] def get_quantification(self) -> str:
return self.quantification_
[docs] def get_price_precision(self) -> int:
return self.price_precision_
[docs] def get_quantity_precision(self) -> int:
return self.quantity_precision_
[docs] def get_valid_start_ts(self) -> int:
return self.valid_start_ts_
[docs] def get_valid_end_ts(self) -> int:
return self.valid_end_ts_
[docs] def get_instrument_name(self) -> str:
return self.instrument_name_
def __str__(self) -> str:
return self.instrument_name_ # consistent with Java side, return instrument name as string