MLThon Instruments Package¶
Submodules¶
mlthon.instruments.future module¶
mlthon.instruments.instrument module¶
- class Instrument(instrument_id=None, instrument_type=None, instrument_group_id=None, exch_instr_id=None, exchange=None, mlt_symbol=None, price_tick_rules=None, quantity_tick_rules=None, multiplier=None, min_quantity=None, base_currency=None, quote_currency=None, quantification=None, price_precision=None, quantity_precision=None, valid_start_ts=None, valid_end_ts=None, instrument_name=None, **kwargs)[source]¶
Bases:
object
Instrument class, including all the necessary infos for an instrument/product.
mlthon.instruments.instrument_utils module¶
- class InstrumentUtils[source]¶
Bases:
object
- static exch_syms_types_to_instr_names(exchange, type_by_symbol)[source]¶
Return a list of instrument names, given the exchange, symbols and types.
- Parameters
exchange (Exchange) – exchange of these instruments.
type_by_symbol (dict) – a dictionary, whose keys are the symbols and values are the instrument types, e.g. {“BTC-USD”: InstrumentType:Perpetual}.
- Return type
a list of strings, each of which is the corresponding instrument name.
- static exch_type_sym_to_instr_name(exchange, instr_type, symbol)[source]¶
Transfer (exchange, instrument_type, symbol) into instrument_name (e.g. byt:perp:btc-usd).
- Parameters
exchange (Exchange) – exchange of this instrument.
instr_type (InstrumentType) – instrument type of this instrument.
symbol (str) – symbol (internal symbol in MLTech) of this instrument.
- Return type
a string, the instrument name.
- static get_instrument_from_json(json_object)[source]¶
Parse a json object with instrument info, and generate the corresponding Instrument object.
- Parameters
json_object (dict) – a json object (dict), with all the information of an instrument. Example: {
“instrument_type”:”spot”, # instrument type ID (e.g. perp), not the type’s whole name (e.g. PERPETUAL) “exchange_id”:”BLN”, “mlt_symbol”:”BTC-USD”, “price_tick_rules_json”:
{ “default”: “0.1”, “rules”: [] },
- “quantity_tick_rules_json”:
{ “default”: “0.00000001”, “rules”: [] },
“multiplier”:”1.0000000000”, “valid_start_ts”:1630003158, “instrument_group_id”:”spot:BTC-USD”, “base_currency”:”BTC”, “quote_currency”:”USD”, “min_quantity”:”0.0005000000”, “exch_instr_id”:”BTC-USD”, “quantification”:”base”, “instrument_id”:10000000000, “price_precision”:1, “quantity_precision”:4
}
- Return type
an Instrument (or its subclass) object
- static get_instrument_from_raw_msg(raw_msg)[source]¶
Parse the raw payload (json-formatted string) and generate the corresponding Instrument object.
- Parameters
raw_msg (str) – raw message for instrument, a string in json format, example: ```{
“instrument_type”:”SPOT”, “exchange_id”:”BLN”, “mlt_symbol”:”BTC-USD”, “price_tick_rules_json”:
{ “default”: “0.1”, “rules”: [] },
- “quantity_tick_rules_json”:
{ “default”: “0.00000001”, “rules”: [] },
“multiplier”:”1.0000000000”, “valid_start_ts”:1630003158, “instrument_group_id”:”spot:BTC-USD”, “base_currency”:”BTC”, “quote_currency”:”USD”, “min_quantity”:”0.0005000000”, “exch_instr_id”:”BTC-USD”, “quantification”:”base”, “instrument_id”:10000000000, “price_precision”:1, “quantity_precision”:4 }```
- Return type
an Instrument (or its subclass) object