Canonical Namespaces

ATS offers extensive flexibility, allowing users to customize their trading systems by adding custom exchange classes, strategy classes, indicators, and fee structures. To streamline this customization process, ATS follows a standardized namespace definition convention.

Namespace Convention

The following naming conventions are used for defining namespaces for different types of custom classes:

  1. Strategy: strategies:<name of the strategy> Example: strategies:my_strategy for Strategy class in custom_modules/strategies/my_exchange/strategy.py

  2. Exchange: exchanges:<name of the exchange> Example: exchanges:my_exchange for Exchange class in custom_modules/exchanges/my_exchange/exchange.py

  3. Indicator: indicators:<name of the indicator> Example: indicators:my_indicator for Indicator class in custom_modules/indicators/my_indicator.py

  4. Fee: fees:<name of the fee class> Example: fees:custom_fee for Fee class in custom_modules/fees/my_fee.py

Generating a Path from Namespace

To dynamically resolve the path of a class from its namespace, ATS provides a utility function in the ats/utils/general/helpers module.

The function get_class_from_namespace(namespace: str) retrieves the corresponding class based on the given namespace.

Code Example

Here is how you can use the utility function to resolve a class from its namespace:

from src.utils.general.helpers import get_class_from_namespace

# Example: Resolving a strategy class
namespace = "strategy:my_strategy"
strategy_class = get_class_from_namespace(namespace)

print(strategy_class)  # Outputs the resolved class

Key Notes

  1. Namespace Validation: Ensure that the namespace is correctly formatted. It must contain at least two parts separated by a colon (:).

  2. Supported Namespace Types:

    • exchanges for custom exchanges.

    • strategies for custom strategies.

    • indicators for custom indicators.

    • fees for custom fee structures.

  3. Error Handling: If the namespace is invalid or the class is not found, the utility will raise appropriate exceptions (Exception or ModuleNotFoundError).

This standardized namespace convention and utility function simplify the process of adding custom classes, ensuring maintainability and reducing errors during development.

Last updated