backtrader.store module

Store base classes.

Store provides per-instance state and lifecycle helpers for store implementations. LiveStoreBase builds on it as the contract for live stores. Store instances do not impose singleton behavior.

Classes:

StoreParams: Parameter management for Store classes. Store: Per-instance base class for Store implementations.

示例

Using a store to get data and broker: >>> store = bt.observers.backends.ViStore() >>> data = store.getdata() >>> broker = store.getbroker()

class backtrader.store.StoreParams[源代码]

基类:object

Simple 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.

__init__()[源代码]

Initialize parameters from the class-level params tuple.

Parses the params tuple defined at class level and creates a self.p object with all parameter values as attributes.

class backtrader.store.Store[源代码]

基类:StoreParams

Per-instance base class for store implementations.

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).

Type:

Any

DataCls

The data class to use (None by default).

Type:

Any

params = ()
BrokerCls: Any = None
DataCls: Any = None
__init__()[源代码]

Initialize parameters and per-instance Store lifecycle state.

getdata(*args, **kwargs)[源代码]

Construct the configured feed and bind it to this Store instance.

getbroker(*args, **kwargs)[源代码]

Construct the configured broker and bind it to this Store instance.

start(data=None, broker=None)[源代码]

Register Store participants and initialize common lifecycle state.

参数:
  • data -- Data feed to register with the store (optional).

  • broker -- Broker instance to register with the store (optional).

备注

On first call, initializes the notification queue and data list. Subsequent calls can add data feeds or set the broker.

stop()[源代码]

Stop the Store.

Concrete stores with resources to release should override this hook.

put_notification(msg, *args, **kwargs)[源代码]

Add a message to the notification queue.

参数:
  • msg -- The notification message.

  • *args -- Additional positional arguments to store with the message.

  • **kwargs -- Additional keyword arguments to store with the message.

get_notifications()[源代码]

Return the pending "store" notifications