MLThon basic package

Submodules

mlthon.basics.defs module

class CancelCode(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

CanceledByUser = 1
SelfTradePrevention = 2
Unset = 0
class Exchange(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

Bequant = 2
Binance = 5
Binance_fut_coin = 9
Binance_fut_usdt = 8
Blockchain = 0
Bybit = 1
Deribit = 3
Ftx = 6
Huobi = 4
Lmax = 7
property exchange_code

Get exchange code for that exchange

static parse_exchange_code(exch)[source]

Parse exchange 3 character code

static parse_str(s)[source]
static try_parse_str(s)[source]
Parameters

s (string to parse)

Returns

  • a tuple (bool,enum_val) where bool is true if parsing was a success. If so, enum_val will be the

  • corresponding parsed value

class ExecInstructions(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

PostOnly = 1
Unset = 0
static parse(string_val)[source]
class FeedHandlerStatus(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

Disconnected = 2
SnapshotEnd = 1
SnapshotStart = 0
class GtwRejectCode(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

ExchBadQty = 2009
ExchDupeOrderID = 2007
ExchForbid = 2001
ExchInsufficientBalance = 2003
ExchInvalidRequest = 2014
ExchIsClosed = 2015
ExchOrderBelowMin = 2011
ExchOrderCancelled = 2010
ExchOrderExpired = 2008
ExchOrderFilled = 2005
ExchOrderNotFound = 2006
ExchOverload = 2002
ExchPostOnlyBreach = 2016
ExchQtyCannotBeBelowCumQty = 2012
ExchRateLimitBreach = 2000
ExchReject = 2004
ExchTooLateToCancel = 2013
ExchTookTooLongToProcessRequest = 2017
GtwCannotModify = 1004
GtwCannotStackPendingRequests = 1003
GtwInvalidRequest = 1008
GtwNoRiskForSymbol = 1012
GtwNotReady = 1000
GtwOngoingCancel = 1011
GtwOrderNotFound = 1006
GtwOrderNotOpen = 1016
GtwPendingCancelAll = 1005
GtwQtyCannotBeBelowCumQty = 1009
GtwRateLimitBreach = 1002
GtwReduceMustLowerQty = 1010
GtwRiskLongPosViolation = 1015
GtwRiskMaxOrderSizeViolation = 1013
GtwRiskShortPosViolation = 1014
GtwRiskViolation = 1001
GtwUnsupportedOp = 1007
class GtwStatus(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

Connecting = 0
Disconnected = 4
Maintenance = 3
ReadyToTrade = 1
Synchronizing = 2
class InstrumentType(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

Future = 2
Perpetual = 1
Spot = 0
static parse_str(s)[source]
static try_parse_str(s)[source]

Try to parse InstrumentType from a string (type ID)

Parameters

s (str) – string to parse (type ID)

Returns

  • a tuple (bool,enum_val) where bool is true if parsing was a success. If so, enum_val will be the

  • corresponding parsed value

property type_id

Type ID of this InstrumentType.

Return type

a string, type ID for that InstrumentType.

class OrderStatus(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

Cancelled = 4
Expired = 6
Filled = 2
Open = 0
PartiallyFilled = 1
PendingCancel = 3
Rejected = 5
Suspended = 7
Unknown = -1
static parse_str(s)[source]
class OrderType(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

Limit = 0
Unset = -1
static parse(string_val)[source]
class Side(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

Buy = 0
Sell = 1
static parse(string_val)[source]
class TIF(value)[source]

Bases: mlthon.basics.mlt_enum.MltEnum

An enumeration.

GTC = 0
IOC = 1
Unset = -1
static parse(string_val)[source]

mlthon.basics.logging module

get_logger(client)[source]
get_named_logger(name)[source]
setup_logging(log_filepath, display_output_in_stdout=False)[source]

mlthon.basics.mlt_enum module

class MltEnum(value)[source]

Bases: enum.Enum

An enumeration.

mlthon.basics.price module

class Price(raw_val)[source]

Bases: object

static from_int(i)[source]
static from_str(s)[source]
is_null()[source]
static null()[source]

Note that a null Price cannot be used to perform arithmetic comparisons with other Price objects.

to_float()[source]
to_str(num_decimal=10)[source]
static zero()[source]

mlthon.basics.qty module

class Qty(raw_val)[source]

Bases: object

static from_int(i)[source]
static from_json(value)[source]
static from_str(s)[source]
is_null()[source]
static null()[source]

Note that a null Qty cannot be used to perform arithmetic comparisons with other Qty objects.

to_float()[source]
to_str(num_decimal=10)[source]
static zero()[source]

mlthon.basics.rate_tracker module

class RateTracker[source]

Bases: object

abstract is_valid_rate(ts)[source]
Parameters

ts – epoch time

Returns

property max_rate
property window
class SlicingRateTracker(max_rate, window_ms)[source]

Bases: mlthon.basics.rate_tracker.RateTracker

is_valid_rate(ts)[source]
Parameters

ts – epoch time

Returns

mlthon.basics.tick_format module

class TickFormat[source]

Bases: object

static format_price_down(price, tick_size=50, tick_unit=TickUnit.Cent)[source]
static format_price_up(price, tick_size=50, tick_unit=TickUnit.Cent)[source]
static format_qty_down(qty, tick_size=1, tick_unit=TickUnit.Satoshi)[source]
static format_qty_up(qty, tick_size=1, tick_unit=TickUnit.Satoshi)[source]
static price_down_from_float(float_price, tick_size=50, tick_unit=TickUnit.Cent)[source]
static price_up_from_float(float_price, tick_size=50, tick_unit=TickUnit.Cent)[source]
static qty_down_from_float(float_qty, tick_size=1, tick_unit=TickUnit.Satoshi)[source]
static qty_up_from_float(float_qty, tick_size=1, tick_unit=TickUnit.Satoshi)[source]
class TickUnit(value)[source]

Bases: enum.Enum

An enumeration.

Cent = 1000000
Lot = 100000000
Satoshi = 1

mlthon.basics.timer_mgr module

class TimerMgr[source]

Bases: object

process_timers()[source]
setup_daily_callback(time, callback_func)[source]
setup_timer(duration_ms, callback_func)[source]