Source code for mlthon.api.istrat_env

import typing

from mlthon.basics.defs import Exchange, Side, ExecInstructions, OrderType, TIF
from mlthon.basics.mlt_enum import MltEnum
from mlthon.basics.price import Price
from mlthon.basics.qty import Qty


[docs]class MDSub(MltEnum): OrderBook = 0, LevelBook = 1, PriceLevelBook = 2, BBO = 3, PublicTrades = 4
[docs]class IStratEnv(object):
[docs] def login(self, strat_name: str): """log into the framework""" raise NotImplementedError
[docs] def add_cmd_hook(self, cmd_name_str: str, callback_func: typing.Callable[[str], None]): """ Dynamically hook a command (by name) to a callback function. Every time the environment receives that command name, the corresponding callback function will be invoked, and parameters (if any) are provided to that callback as a List of strings TODO:(review capitalization effect on cmd_name_str) """ raise NotImplementedError
[docs] def setup_timer(self, duration_ms: int, callback_func: typing.Callable[[], bool]): """ Setup a timer which will trigger the invocation of the provided callback function every duration_ms milliseconds. If the callback returns True, the timer is renewed. Any other return value (including no return value) will cause the timer to be cancelled. """ raise NotImplementedError
[docs] def setup_daily_callback(self, hh_mm_ss: str, callback_func: typing.Callable[[], bool]): """ Setup a daily callback triggering the invocation of callback_func. The daily callback is recurrent IFF it returns True, and cancelled in any other case. The format of hh_mm_ss is 'HH:mm:ss', for instance '16:30:00' is 4PM. The timezone of the system is assumed. """ raise NotImplementedError
[docs] def publish_telegram(self, msg: str): """ Publish a msg to the strategy telegram channel """ raise NotImplementedError
[docs] def send_new_order(self, client_id: str, exchange: Exchange, instrument_id: int, side: Side, price: Price, qty: Qty, exec_instr: ExecInstructions, ord_type: OrderType, time_in_force: TIF, close_position: bool): """ Create a new Order. Return the client order ID as an int. Note that price and qty parameters are strings and that the user is responsible for providing valid values. """ raise NotImplementedError
[docs] def send_modify_order(self, exchange: Exchange, client_ord_id: str, new_price: Price, new_qty: Qty): """ Modify the order with the provided client order ID, allowing users to modify only the price or only the quantity. """ raise NotImplementedError
[docs] def send_cancel_order(self, exchange: Exchange, instrument_id: int, client_ord_id: str): """ Cancel the order with the provided client order ID. """ raise NotImplementedError
[docs] def send_cancel_all(self, exchange: Exchange, instrument_id: int, ): """ Cancel all the orders on the provided Exchange, for the given instrument ID. """ raise NotImplementedError
[docs] def fetch_account_info(self, exchange: Exchange): """ Obtain account related information for that exchange. """ raise NotImplementedError
[docs] def fetch_orders_info(self, exchange: Exchange, instrument_id: int = None): """ Obtain a list of all the open orders for the provided exchange. If the instrument ID is also provided, only the orders for that instrument ID will be listed """ raise NotImplementedError
[docs] def fetch_order_status(self, exchange: Exchange, instrument_id: int, client_ord_id: str): """ Obtain order status information about the order with matching instrument and client order ID. """ raise NotImplementedError
[docs] def fetch_wallet_info(self, exchange: Exchange, coin: str): """ Obtain the wallet balance for the provided coin. """ raise NotImplementedError
[docs] def fetch_position_info(self, exchange: Exchange, instrument_id: int): """ Obtain the position for the provided derivative pair. """ raise NotImplementedError
[docs] def fetch_funding_info(self, exchange: Exchange, instrument_id: int): """ Obtain the funding rate for the provided derivative pair. """ raise NotImplementedError
[docs] def send_stop_ack(self): """ When the strategy has received an on_stop() callback from the infra, it needs to let the infra know when it is done "stopping". After having sent that, the api should no longer send requests, until it received another on_start() callback """ raise NotImplementedError