-
Notifications
You must be signed in to change notification settings - Fork 47
API Reference ‐ Utils
A class to encapsulate query parameters for filtering stock data.
This class is used to define a set of criteria for filtering stocks, which includes the stock symbol, name matching pattern, and conditions for instruments and contracts.
Attributes:
-
symbolstr - The stock symbol to query. -
name_matchOptional[str], optional - A string pattern to match against stock names. Optional. -
instrument_conditionsOptional[dict], optional - Key-value pairs representing conditions to apply to stock instruments. Each condition is matched exactly against the instrument's attributes. -
contract_conditionsOptional[dict], optional - Key-value pairs representing conditions to apply to stock contracts. Each condition is matched exactly against the contract's attributes.
def make_order_request(conid: Union[int, str],
side: str,
quantity: float,
order_type: str,
acct_id: str,
price: float = None,
conidex: str = None,
sec_type: str = None,
coid: str = None,
parent_id: str = None,
listing_exchange: str = None,
is_single_group: bool = None,
outside_rth: bool = None,
aux_price: float = None,
ticker: str = None,
tif: str = 'GTC',
trailing_amt: float = None,
trailing_type: str = None,
referrer: str = None,
cash_qty: float = None,
fx_qty: float = None,
use_adaptive: bool = None,
is_ccy_conv: bool = None,
allocation_method: str = None,
strategy: str = None,
strategy_parameters=None)Create an order request object. Arguments set as None will not be included.
Arguments:
-
conidint | str - Identifier of the security to trade. -
sidestr - Order side, either 'SELL' or 'BUY'. -
quantityint - Order quantity in number of shares. -
order_typestr - Type of the order (e.g., LMT, MKT, STP). -
pricefloat - Order limit price, depends on order type. -
coidstr - Customer Order ID, unique for a 24h span. -
acctIdstr, optional - Account ID, defaults to the first account if not provided. -
conidexstr, Optional - Concatenated value of contract identifier and exchange. -
sec_typestr, Optional - Concatenated value of contract-identifier and security type. -
parent_idstr, Optional - Used for child orders in bracket orders, must match the parent's cOID. -
listing_exchangestr, Optional, optional - Exchange for order routing, default is "SMART". -
is_single_groupbool, Optional - Set to True for placing single group orders (OCA). -
outside_rthbool, Optional - Set to True if the order can be executed outside regular trading hours. -
aux_pricefloat, Optional - Auxiliary price parameter. -
tickerstr, Optional - Underlying symbol for the contract. -
tifstr, Optional - Time-In-Force for the order (e.g., GTC, OPG, DAY, IOC). Default: "GTC". -
trailing_amtfloat, Optional - Trailing amount for TRAIL or TRAILLMT orders. -
trailing_typestr, Optional - Trailing type ('amt' or '%') for TRAIL or TRAILLMT orders. -
referrerstr, Optional - Custom order reference. -
cash_qtyfloat, Optional - Cash Quantity for the order. -
fx_qtyfloat, Optional - Cash quantity for Currency Conversion Orders. -
use_adaptivebool, Optional - Set to True to use the Price Management Algo. -
is_ccy_convbool, Optional - Set to True for FX conversion orders. -
allocation_methodstr, Optional - Allocation method for FA account orders. -
strategystr, Optional - IB Algo algorithm to use for the order. -
strategy_parametersdict, Optional - Parameters for the specified IB Algo algorithm.
def ibind_logs_initialize(log_to_console: bool = var.LOG_TO_CONSOLE,
log_to_file: bool = var.LOG_TO_FILE,
log_level: str = var.LOG_LEVEL,
log_format: str = var.LOG_FORMAT)Initialises the logging system.
Arguments:
-
log_to_consolebool - Whether the logs should be output to the current console,Trueby default -
log_to_filebool - Whether the logs should be written to a daily log file,Trueby default. -
log_levelstr - What is the minimum log level ofibindlogs,INFOby default. -
log_formatstr - What is the log format to be used,'%(asctime)s|%(levelname)-.1s| %(message)s'by default.
Notes:
- All of these parameters are read from the environment variables by default.
- The daily file logs are saved in the directory specified by the
IBIND_LOGS_DIRenvironment variable, the system temp directory by default. - To get more verbose logs, set either the
log_levelparameter or theIBIND_LOG_LEVELenvironment variable to'DEBUG'
def execute_in_parallel(func: callable,
requests: Union[List[dict], Dict[str, dict]],
max_workers: int = None,
max_per_second: int = 20) -> Union[dict, list]Executes a function in parallel using multiple sets of arguments with rate limiting.
This function utilises a thread pool to execute the given 'func' concurrently across different sets of arguments specified in 'requests'. The 'requests' can be either a list or a dictionary.
Arguments:
-
funccallable - The function to be executed in parallel. -
requestsdict[str, dict] or list - A dictionary where keys are unique identifiers and values are dictionaries with 'args' and 'kwargs' for the 'func', or a list of such dictionaries. -
max_workersint, optional - The maximum number of threads to use. -
max_per_secondint, optional - The maximum number of function executions per second. Defaults to 20.
Returns:
Union[dict, list]: A collection of results from the function executions, keyed by the same keys as 'requests' if it is a dictionary, or a list in the same order as the 'requests' list. The function returns results in a dictionary if 'requests' was a dictionary, and a list if 'requests' was a list.
See any error on this page? Create an Issue and let us know.