bbstrader package

Module contents

Simplified Investment & Trading Toolkit with Python & C++

Subpackages

Submodules

bbstrader.compat module

bbstrader.compat.setup_mock_modules() None[source]

Mock some modules not available on some OS to prevent import errors.

bbstrader.config module

class bbstrader.config.CustomFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]

Bases: Formatter

formatTime(record: LogRecord, datefmt: str | None = None) str[source]

Return the creation time of the specified LogRecord as formatted text.

This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the ‘converter’ attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the ‘converter’ attribute in the Formatter class.

class bbstrader.config.CustomLogger(name: str, level: int = 0)[source]

Bases: Logger

log(level: int, msg: object, *args: object, custom_time: datetime | None = None, **kwargs: Any) None[source]

Log ‘msg % args’ with the integer severity ‘level’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.log(level, “We have a %s”, “mysterious problem”, exc_info=True)

class bbstrader.config.LogLevelFilter(levels: List[int])[source]

Bases: Filter

filter(record: LogRecord) bool[source]

Filters log records based on their level.

Parameters:

record – The log record to check.

Returns:

True if the record’s level is in the allowed levels, False otherwise.

bbstrader.config.config_logger(log_file: str, console_log: bool = True) Logger[source]
bbstrader.config.get_config_dir(name: str = '.bbstrader') Path[source]

Get the path to the configuration directory.

Parameters:

name – The name of the configuration directory.

Returns:

The path to the configuration directory.

bbstrader.scripts module

bbstrader.scripts.load_class(module: ModuleType, class_name: str, base_class: Type) Type[source]

Load a class from a module. :param module: The module to load the class from. :param class_name: The name of the class to load. :param base_class: The base class that the class must inherit from.

bbstrader.scripts.load_module(file_path: str) ModuleType[source]

Load a module from a file path. :param file_path: Path to the file to load.

Returns:

The loaded module.