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:
Strategy:
strategies:<name of the strategy>Example:strategies:my_strategyforStrategyclass incustom_modules/strategies/my_exchange/strategy.pyExchange:
exchanges:<name of the exchange>Example:exchanges:my_exchangeforExchangeclass incustom_modules/exchanges/my_exchange/exchange.pyIndicator:
indicators:<name of the indicator>Example:indicators:my_indicatorforIndicatorclass incustom_modules/indicators/my_indicator.pyFee:
fees:<name of the fee class>Example:fees:custom_feeforFeeclass incustom_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 classKey Notes
Namespace Validation: Ensure that the namespace is correctly formatted. It must contain at least two parts separated by a colon (
:).Supported Namespace Types:
exchangesfor custom exchanges.strategiesfor custom strategies.indicatorsfor custom indicators.feesfor custom fee structures.
Error Handling: If the namespace is invalid or the class is not found, the utility will raise appropriate exceptions (
ExceptionorModuleNotFoundError).
This standardized namespace convention and utility function simplify the process of adding custom classes, ensuring maintainability and reducing errors during development.
Last updated