tradeflow.common package

Submodules

tradeflow.common.config module

tradeflow.common.ctypes_utils module

class tradeflow.common.ctypes_utils.CArray[source]

Bases: object

static of(c_type_str: Literal['int', 'double'], arr: Any) Array[source]

Create a ctypes array from a Python list.

Parameters:
  • c_type_str ({'int', 'double'}) – The type of the array to be created.

  • arr (array_like) – The array from which to create the ctypes array.

Returns:

The ctypes array containing the elements of arr.

Return type:

ct.Array

class tradeflow.common.ctypes_utils.CArrayEmpty[source]

Bases: object

static of(c_type_str: Literal['int', 'double'], size: int) Array[source]

Create an empty ctypes array of a given size.

Parameters:
  • c_type_str ({'int', 'double'}) – The type of elements in the array to be created.

  • size (int) – The size of the ctypes array to create.

Returns:

The empty ctypes array of size size.

Return type:

ct.Array

tradeflow.common.ctypes_utils.get_c_type_from_string(c_type_str: Literal['int', 'double']) Any[source]

Return a ctypes type corresponding to a given C data type (from a string).

Parameters:

c_type_str{‘int’, ‘double’}

A string indicating the desired C data type.

Returns:

ct._SimpleCData

The corresponding ctypes type.

tradeflow.common.exceptions module

exception tradeflow.common.exceptions.EnumValueException[source]

Bases: Exception

Raised when the enum value is not valid

exception tradeflow.common.exceptions.SharedLibraryNotFoundException[source]

Bases: Exception

Raised if the shared library is not found in the registry

exception tradeflow.common.exceptions.UnsupportedOsException[source]

Bases: Exception

Raised if the OS is not supported when loading a shared library

tradeflow.common.general_utils module

tradeflow.common.general_utils.check_condition(condition: bool, exception: Exception) None[source]

Raise an exception if a condition is false, otherwise do nothing.

Parameters:
  • condition (bool) – The condition to check.

  • exception (Exception) – The exception to raise if the condition is false.

Raises:

Exception – If the condition is false.

tradeflow.common.general_utils.check_enum_value_is_valid(enum_obj: <module 'enum' from '/opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/enum.py'>, value: object | None, is_none_valid: bool, parameter_name: str) Enum | None[source]

Raise an EnumValueException if a value is not within an enum.

Parameters:
  • enum_obj (enum.EnumType) – The enum to check the value against.

  • value (object or None) – The value to verify.

  • is_none_valid (bool) – Flag indicating whether None is allowed.

  • parameter_name (str) – Variable name for exceptions.

Returns:

Enum associated to the passed value or None if the value is None and is_none_valid is true.

Return type:

enum.Enum or None

Raises:

EnumValueException – If the value does not exist withing the enum or if the value is None and is_none_valid is false.

tradeflow.common.general_utils.get_enum_values(enum_obj: <module 'enum' from '/opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/enum.py'>) List[Any][source]

Return a list containing the values of an enum.

Parameters:

enum_obj (enum.EnumType) – The enum for which the values will be retrieved.

Returns:

The values of the enum.

Return type:

list of any

tradeflow.common.general_utils.is_value_within_interval_exclusive(value: int | float, lower_bound: int | float, upper_bound: int | float) bool[source]

Return whether a value is strictly within an interval or not.

Parameters:
  • value (int or float) – The value to check.

  • lower_bound (int or float) – The strict lower bound of the interval.

  • upper_bound (int or float) – The strict upper bound of the interval

Returns:

True if the value is strictly within the interval, false otherwise.

Return type:

bool

tradeflow.common.logger_utils module

tradeflow.common.logger_utils.get_logger(name: str) Logger[source]

tradeflow.common.shared_libraries_registry module

class tradeflow.common.shared_libraries_registry.Function(name: str, argtypes: List[ct._CData | ct.POINTER(ct._CData)], restype: ct._CData | ct.POINTER(ct._CData))[source]

Bases: object

property argtypes: Tuple[ct._CData | ct.POINTER(ct._CData), ...]
property name: str
property restype: ct._CData | ct.POINTER(ct._CData)
class tradeflow.common.shared_libraries_registry.SharedLibrariesRegistry(*args, **kwargs)[source]

Bases: object

find_shared_library(name: str) SharedLibrary[source]
class tradeflow.common.shared_libraries_registry.SharedLibrary(name: str, directory: Path, functions: List[Function])[source]

Bases: object

ARGUMENT_TYPES = 'argtypes'
DARWIN = 'darwin'
DLL = 'dll'
DYLIB = 'dylib'
LINUX = 'linux'
RESULT_TYPE = 'restype'
SO = 'so'
WINDOWS = 'windows'
static get_shared_library_extension() str[source]

Determine the shared library file extension based on the operating system.

Returns:

The file extension for shared libraries, specific to the current operating system.

Return type:

str

Raises:

UnsupportedOsException – If the operating system is not Linux, Darwin (macOS), or Windows.

load() CDLL[source]

Return the shared library of the project.

Returns:

The loaded shared library.

Return type:

ct.CDLL

property name

tradeflow.common.singleton module

class tradeflow.common.singleton.Singleton[source]

Bases: type

Module contents