Base
ParamSpec
dataclass
Specification for a strategy parameter.
Defines the default value and optional constraints for a configurable strategy parameter. Used to declare tunable parameters that can be overridden at strategy instantiation.
| Field | Type | Semantics |
|---|---|---|
default |
int, float, str, bool, or Enum |
Default value of the parameter. |
min |
int, float, or None |
Minimum allowed value, if applicable. |
max |
int, float, or None |
Maximum allowed value, if applicable. |
step |
int, float, or None |
Step size for parameter sweeps, if applicable. |
choices |
list or None |
Explicit list of allowed values, if applicable. |
Source code in src/onesecondtrader/strategies/base.py
resolved_choices
property
Return the effective list of allowed values for this parameter.
If choices is explicitly set, returns that list.
If default is an enum member, returns all members of that enum type.
Otherwise, returns None.
Source code in src/onesecondtrader/strategies/base.py
OrderRecord
dataclass
Internal record of an order submitted by a strategy.
Tracks the state of an order from submission through fill or cancellation.
| Field | Type | Semantics |
|---|---|---|
order_id |
uuid.UUID |
System-assigned unique identifier for the order. |
symbol |
str |
Identifier of the traded instrument. |
order_type |
models.OrderType |
Execution constraint of the order. |
side |
models.TradeSide |
Direction of the trade. |
quantity |
float |
Requested order quantity. |
limit_price |
float or None |
Limit price, if applicable to the order type. |
stop_price |
float or None |
Stop price, if applicable to the order type. |
signal |
str or None |
Optional signal name associated with the order. |
filled_quantity |
float |
Cumulative quantity filled for this order. |
Source code in src/onesecondtrader/strategies/base.py
FillRecord
dataclass
Internal record of a fill received by a strategy.
Captures execution details for a single fill event.
| Field | Type | Semantics |
|---|---|---|
fill_id |
uuid.UUID |
System-assigned unique identifier for the fill. |
order_id |
uuid.UUID |
Identifier of the order associated with the fill. |
symbol |
str |
Identifier of the traded instrument. |
side |
models.TradeSide |
Trade direction of the executed quantity. |
quantity |
float |
Quantity executed in this fill. |
price |
float |
Execution price of the fill. |
commission |
float |
Commission or fee associated with the fill. |
ts_event |
pd.Timestamp |
Timestamp at which the fill was observed by the strategy. |
Source code in src/onesecondtrader/strategies/base.py
StrategyBase
Bases: Subscriber, ABC
Abstract base class for trading strategies.
A strategy subscribes to market data and order events, maintains position state,
and submits orders through the event bus. Subclasses implement on_bar to define
trading logic and optionally override setup to register indicators.
Class Attributes
name: Human-readable name of the strategy. symbols: List of instrument symbols the strategy trades. parameters: Dictionary mapping parameter names to their specifications.
position
property
Return the current position for the active symbol.
The active symbol is set by the most recently processed bar event.
Source code in src/onesecondtrader/strategies/base.py
avg_price
property
Return the average entry price for the current position on the active symbol.
Returns zero if there is no open position.
Source code in src/onesecondtrader/strategies/base.py
__init__(event_bus, **overrides)
Initialize the strategy and start event processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_bus
|
EventBus
|
Event bus used for subscribing to and publishing events. |
required |
**overrides
|
Parameter values to override defaults defined in |
{}
|
Source code in src/onesecondtrader/strategies/base.py
add_indicator(ind)
Register an indicator with the strategy.
Registered indicators are automatically updated on each bar event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
IndicatorBase
|
Indicator instance to register. |
required |
Returns:
| Type | Description |
|---|---|
IndicatorBase
|
The registered indicator instance. |
Source code in src/onesecondtrader/strategies/base.py
submit_order(order_type, side, quantity, limit_price=None, stop_price=None, action=None, signal=None)
Submit a new order for the active symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_type
|
OrderType
|
Execution constraint of the order. |
required |
side
|
TradeSide
|
Direction of the trade. |
required |
quantity
|
float
|
Requested order quantity. |
required |
limit_price
|
float | None
|
Limit price, if applicable to the order type. |
None
|
stop_price
|
float | None
|
Stop price, if applicable to the order type. |
None
|
action
|
ActionType | None
|
Intent of the order from the strategy's perspective (e.g., entry, exit). |
None
|
signal
|
str | None
|
Optional signal name associated with the order. |
None
|
Returns:
| Type | Description |
|---|---|
UUID
|
System-assigned unique identifier for the submitted order. |
Source code in src/onesecondtrader/strategies/base.py
submit_modification(order_id, quantity=None, limit_price=None, stop_price=None)
Submit a modification request for a pending order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_id
|
UUID
|
Identifier of the order to modify. |
required |
quantity
|
float | None
|
Updated order quantity, or |
None
|
limit_price
|
float | None
|
Updated limit price, or |
None
|
stop_price
|
float | None
|
Updated stop price, or |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/onesecondtrader/strategies/base.py
submit_cancellation(order_id)
Submit a cancellation request for a pending order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_id
|
UUID
|
Identifier of the order to cancel. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/onesecondtrader/strategies/base.py
_on_event(event)
Source code in src/onesecondtrader/strategies/base.py
_on_bar_received(event)
Source code in src/onesecondtrader/strategies/base.py
_emit_processed_bar(event)
Source code in src/onesecondtrader/strategies/base.py
_on_order_submission_accepted(event)
Source code in src/onesecondtrader/strategies/base.py
_on_order_modification_accepted(event)
Source code in src/onesecondtrader/strategies/base.py
_on_order_cancellation_accepted(event)
_on_order_submission_rejected(event)
_on_order_modification_rejected(event)
_on_order_cancellation_rejected(event)
_on_order_filled(event)
Source code in src/onesecondtrader/strategies/base.py
_update_position(event)
Source code in src/onesecondtrader/strategies/base.py
_on_order_expired(event)
setup()
Hook for subclasses to register indicators and perform initialization.
Called at the end of __init__. Override this method to register indicators
using add_indicator without needing to override __init__.
Source code in src/onesecondtrader/strategies/base.py
on_bar(event)
abstractmethod
Handle a bar event for a subscribed symbol.
Called after all registered indicators have been updated. Subclasses implement this method to define trading logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
BarReceived
|
Bar event containing OHLCV data for the current bar. |
required |