backtrader.store module¶
Store Module - Data storage and broker connection management.
This module provides base classes for Store implementations, which manage connections to external data sources and brokers. It includes singleton pattern support and parameter management for store classes.
- Classes:
SingletonMixin: Mixin class to implement singleton pattern. StoreParams: Parameter management for Store classes. Store: Base class for all Store implementations.
Example
Using a store to get data and broker: >>> store = bt.observers.backends.ViStore() >>> data = store.getdata() >>> broker = store.getbroker()
- class backtrader.store.SingletonMixin[source]¶
Bases:
objectMixin class to make a class a singleton without using metaclasses.
This mixin ensures only one instance of the class exists. The instance is created on first instantiation and reused on subsequent calls.
- static __new__(cls, *args, **kwargs)[source]¶
Create and return the singleton instance.
- Parameters:
*args – Positional arguments passed to the class constructor.
**kwargs – Keyword arguments passed to the class constructor.
- Returns:
The single instance of this class.
- Return type:
- __init__(*args, **kwargs)[source]¶
Initialize the singleton instance only once.
- Parameters:
*args – Positional arguments passed to the parent __init__.
**kwargs – Keyword arguments passed to the parent __init__.
Note
If the singleton has already been initialized, this method returns immediately without reinitializing.
- class backtrader.store.StoreParams[source]¶
Bases:
objectSimple parameter management for Store classes.
This class provides automatic parameter initialization from the class-level params tuple, creating a self.p attribute with all parameter values.
- class backtrader.store.Store[source]¶
Bases:
SingletonMixin,StoreParamsBase class for all Stores.
Stores manage connections to external data sources and brokers. They provide data feeds and broker instances, and handle notifications from the external service.
- _started¶
Whether the store has been started.
- params¶
Tuple of parameter definitions.
- broker¶
The broker instance associated with this store.
- BrokerCls¶
The broker class to use (None by default).
- DataCls¶
The data class to use (None by default).
- params = ()¶
- __init__()[source]¶
Initialize the Store instance.
Sets up internal state for broker, environment, cerebro, data sources, and notifications.
- classmethod getbroker(*args, **kwargs)[source]¶
Returns broker with *args, **kwargs from registered
BrokerCls
- BrokerCls = None¶
- DataCls = None¶
- start(data=None, broker=None)[source]¶
Start the store and initialize connections.
- Parameters:
data – Data feed to register with the store (optional).
broker – Broker instance to register with the store (optional).
Note
On first call, initializes the notification queue and data list. Subsequent calls can add data feeds or set the broker.
- stop()[source]¶
Stop the store and clean up resources.
This method should be overridden by subclasses to perform any necessary cleanup.