onesecondtrader 0.3.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ Research, simulate, and deploy algorithmic trading strategies — all in one pla
8
8
  from .log_config import logger
9
9
 
10
10
  # Domain models
11
- from .domain_models import MarketData, PositionManagement
11
+ from .domain_models import MarketData, PositionManagement, SystemManagement
12
12
 
13
13
  __all__ = [
14
14
  # Core infrastructure
@@ -16,4 +16,5 @@ __all__ = [
16
16
  # Domain models
17
17
  "MarketData",
18
18
  "PositionManagement",
19
+ "SystemManagement",
19
20
  ]
@@ -1,30 +1,7 @@
1
1
  """
2
- Domain models for trading infrastructure.
3
-
4
- This module defines the core domain models used across the trading infrastructure.
5
- The design follows Domain-Driven Design (DDD) principles to structure domain logic
6
- into semantically cohesive and type-safe groupings. The models reflect foundational
7
- concepts such as orders, execution states, and position lifecycles. This establishes a
8
- ubiquitous language that is shared across modules, interfaces, and system components.
9
-
10
- Using enums to define these domain models provides the following benefits:
11
-
12
- 1. **Type Safety** – Prevents invalid states (e.g., avoids `"buy"` vs `"BUY"` bugs)
13
- 2. **Compile-Time Validation** – Enables early detection of missing cases (e.g., in match statements)
14
- 3. **Semantic Precision** – Improves self-documentation and system comprehensibility
15
- 4. **Refactor Robustness** – Reduces breakage when business rules evolve
16
- 5. **Performance** – More efficient than string comparisons at runtime
17
- 6. **Domain Vocabulary** – Aligns code with trading terminology
18
- (e.g., `OrderType.LIMIT`)
19
-
20
- All enums use `enum.auto()` to delegate value assignment unless interoperability with
21
- external systems requires explicit values. This minimizes maintenance overhead and
22
- ensures uniqueness without manual management.
23
-
24
- The domain models are grouped into the following classes:
25
-
26
- - **MarketData** – Market data feeds, aggregated bars, record metadata
27
- - **PositionManagement** – Orders, execution states, trade lifecycle controls
2
+ This module defines the core domain models for trading infrastructure.
3
+ These models are organised into namespaces to provide clear semantic groupings
4
+ (e.g.: `PositionManagement.OrderType.MARKET`).
28
5
  """
29
6
 
30
7
  import collections
@@ -33,27 +10,38 @@ import enum
33
10
 
34
11
  class MarketData:
35
12
  """
36
- Domain model for market data representation.
37
-
38
- This namespace defines core data structures and enums related to market data,
39
- such as aggregated price bars and data record types.
13
+ Domain model namespace for market data related concepts.
14
+
15
+ ???+ note "Market Data Record Types"
16
+
17
+ ```mermaid
18
+ ---
19
+ config:
20
+ themeVariables:
21
+ fontSize: "11px"
22
+ ---
23
+ graph LR
24
+ A0[MarketData]
25
+ A[MarketData.OHLCV]
26
+ B[MarketData.RecordType]
27
+ A0 --> A
28
+ A0 --> B
29
+
30
+ ```
40
31
  """
41
32
 
42
33
  OHLCV = collections.namedtuple("OHLCV", ["open", "high", "low", "close", "volume"])
43
34
 
44
35
  class RecordType(enum.Enum):
45
36
  """
46
- Market data record type identifiers using Databento rtype integers.
47
-
48
- The `MarketData.RecordType` enum preserves compatibility with format by using
49
- their specified `rtype` integer assignments. This allows tight integration with
50
- Databento data streams while remaining agnostic to any specific vendor.
51
-
52
- Values:
53
- - OHLCV_1S (32): 1-second bars
54
- - OHLCV_1M (33): 1-minute bars
55
- - OHLCV_1H (34): 1-hour bars
56
- - OHLCV_1D (35): Daily bars
37
+ Market data record type identifiers that preserve compatibility with Databento's
38
+ rtype integers identifiers:
39
+
40
+ quote:
41
+ - `OHLCV_1S` (`32`): 1-second bars
42
+ - `OHLCV_1M` (`33`): 1-minute bars
43
+ - `OHLCV_1H` (`34`): 1-hour bars
44
+ - `OHLCV_1D` (`35`): Daily bars
57
45
  """
58
46
 
59
47
  OHLCV_1S = 32
@@ -62,9 +50,9 @@ class MarketData:
62
50
  OHLCV_1D = 35
63
51
 
64
52
  @classmethod
65
- def to_string(cls, rtype: int) -> str:
53
+ def to_string(cls, record_type: int) -> str:
66
54
  """Convert record type integer to human-readable description."""
67
- match rtype:
55
+ match record_type:
68
56
  case cls.OHLCV_1S.value:
69
57
  return "1-second bars"
70
58
  case cls.OHLCV_1M.value:
@@ -74,25 +62,45 @@ class MarketData:
74
62
  case cls.OHLCV_1D.value:
75
63
  return "daily bars"
76
64
  case _:
77
- return f"unknown ({rtype})"
65
+ return f"unknown ({record_type})"
78
66
 
79
67
 
80
68
  class PositionManagement:
81
69
  """
82
- Trading domain concepts for managing orders and positions.
83
-
84
- This namespace defines core abstractions related to the lifecycle of orders.
70
+ Domain model namespace for position management related concepts.
71
+
72
+ ???+ note "Position Management Concepts"
73
+
74
+ ```mermaid
75
+ ---
76
+ config:
77
+ themeVariables:
78
+ fontSize: "11px"
79
+ ---
80
+ graph LR
81
+ A0[PositionManagement]
82
+ A[PositionManagement.OrderType]
83
+ B[PositionManagement.OrderState]
84
+ C[PositionManagement.Side]
85
+ D[PositionManagement.TimeInForce]
86
+ E[PositionManagement.CancelReason]
87
+ A0 --> A
88
+ A0 --> B
89
+ A0 --> C
90
+ A0 --> D
91
+ A0 --> E
92
+ ```
85
93
  """
86
94
 
87
95
  class OrderType(enum.Enum):
88
96
  """
89
97
  Order execution types.
90
98
 
91
- Values:
92
- - MARKET: Execute immediately at best available price
93
- - LIMIT: Execute only at specified price or better
94
- - STOP: Becomes market order when trigger price is reached
95
- - STOP_LIMIT: Becomes limit order when trigger price is reached
99
+ quote:
100
+ - `MARKET`: Execute immediately at best available price
101
+ - `LIMIT`: Execute only at specified price or better
102
+ - `STOP`: Becomes market order when trigger price is reached
103
+ - `STOP_LIMIT`: Becomes limit order when trigger price is reached
96
104
  """
97
105
 
98
106
  MARKET = enum.auto()
@@ -102,18 +110,18 @@ class PositionManagement:
102
110
 
103
111
  class OrderState(enum.Enum):
104
112
  """
105
- Order lifecycle states from creation to completion.
106
-
107
- Values:
108
- - NEW: Created but not submitted
109
- - SUBMITTED: Sent to broker/exchange
110
- - ACTIVE: Live in market
111
- - PARTIALLY_FILLED: Partially executed
112
- - FILLED: Completely executed
113
- - CANCELLED: Cancelled before first fill
114
- - CANCELLED_AT_PARTIAL_FILL: Cancelled after partial fill
115
- - REJECTED: Rejected by broker/exchange
116
- - EXPIRED: Expired due to time-in-force constraints
113
+ Order lifecycle states.
114
+
115
+ quote:
116
+ - `NEW`: Created but not submitted
117
+ - `SUBMITTED`: Sent to broker/exchange
118
+ - `ACTIVE`: Live in market
119
+ - `PARTIALLY_FILLED`: Partially executed
120
+ - `FILLED`: Completely executed
121
+ - `CANCELLED`: Cancelled before first fill
122
+ - `CANCELLED_AT_PARTIAL_FILL`: Cancelled after partial fill
123
+ - `REJECTED`: Rejected by broker/exchange
124
+ - `EXPIRED`: Expired due to time-in-force constraints
117
125
  """
118
126
 
119
127
  NEW = enum.auto()
@@ -130,9 +138,9 @@ class PositionManagement:
130
138
  """
131
139
  Order direction - buy or sell.
132
140
 
133
- Values:
134
- - BUY: Buy the financial instrument
135
- - SELL: Sell the financial instrument
141
+ quote:
142
+ - `BUY`: Buy the financial instrument
143
+ - `SELL`: Sell the financial instrument
136
144
  """
137
145
 
138
146
  BUY = enum.auto()
@@ -142,12 +150,13 @@ class PositionManagement:
142
150
  """
143
151
  Order time-in-force specifications.
144
152
 
145
- Values:
146
- - DAY: Valid until end of trading day
147
- - FOK: Fill entire order immediately or cancel (Fill-or-Kill)
148
- - GTC: Active until explicitly cancelled (Good-Till-Cancelled)
149
- - GTD: Active until specified date (Good-Till-Date)
150
- - IOC: Execute available quantity immediately, cancel rest (Immediate-or-Cancel)
153
+ quote:
154
+ - `DAY`: Valid until end of trading day
155
+ - `FOK`: Fill entire order immediately or cancel (Fill-or-Kill)
156
+ - `GTC`: Active until explicitly cancelled (Good-Till-Cancelled)
157
+ - `GTD`: Active until specified date (Good-Till-Date)
158
+ - `IOC`: Execute available quantity immediately, cancel rest
159
+ (Immediate-or-Cancel)
151
160
  """
152
161
 
153
162
  DAY = enum.auto()
@@ -155,3 +164,53 @@ class PositionManagement:
155
164
  GTC = enum.auto()
156
165
  GTD = enum.auto()
157
166
  IOC = enum.auto()
167
+
168
+ class CancelReason(enum.Enum):
169
+ """
170
+ Reasons for order cancellation.
171
+
172
+ quote:
173
+ - `CLIENT_REQUEST`: Order cancelled by client/trader request
174
+ - `EXPIRED_TIME_IN_FORCE`: Order expired due to time-in-force constraints
175
+ - `BROKER_REJECTED_AT_SUBMISSION`: Broker rejected order during submission
176
+ - `BROKER_FORCED_CANCEL`: Broker cancelled order due to risk or other constraints
177
+ - `UNKNOWN`: Cancellation reason not specified or unknown
178
+ """
179
+
180
+ CLIENT_REQUEST = enum.auto()
181
+ EXPIRED_TIME_IN_FORCE = enum.auto()
182
+ BROKER_REJECTED_AT_SUBMISSION = enum.auto()
183
+ BROKER_FORCED_CANCEL = enum.auto()
184
+ UNKNOWN = enum.auto()
185
+
186
+
187
+ class SystemManagement:
188
+ """
189
+ Domain model namespace for system management related concepts.
190
+
191
+ ???+ note "System Management Concepts"
192
+
193
+ ```mermaid
194
+ ---
195
+ config:
196
+ themeVariables:
197
+ fontSize: "11px"
198
+ ---
199
+ graph LR
200
+ A0[SystemManagement]
201
+ A[SystemManagement.StopReason]
202
+ A0 --> A
203
+ ```
204
+ """
205
+
206
+ class StopReason(enum.Enum):
207
+ """
208
+ Reasons for system or component shutdown.
209
+
210
+ quote:
211
+ - `SYSTEM_SHUTDOWN`: Coordinated shutdown of entire system
212
+ - `COMPONENT_DISCONNECT`: Single component disconnect
213
+ """
214
+
215
+ SYSTEM_SHUTDOWN = enum.auto()
216
+ COMPONENT_DISCONNECT = enum.auto()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: onesecondtrader
3
- Version: 0.3.0
3
+ Version: 0.5.0
4
4
  Summary: The Trading Infrastructure Toolkit for Python. Research, simulate, and deploy algorithmic trading strategies — all in one place.
5
5
  Author: Nils P. Kujath
6
6
  Author-email: 63961429+NilsKujath@users.noreply.github.com
@@ -0,0 +1,7 @@
1
+ onesecondtrader/__init__.py,sha256=xB2oXIiffWA19eaQbdEn3GZyymhyLHaxPLO-DhP4CLc,430
2
+ onesecondtrader/domain_models.py,sha256=3UigXXEBlZehQupwM_LnLh4rlsOil9e_iPMosjWKFcw,6229
3
+ onesecondtrader/log_config.py,sha256=TGm53SD_TA4Xa57Go91BGHV3SEIA6MflwSO63r9Jt6g,366
4
+ onesecondtrader-0.5.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
5
+ onesecondtrader-0.5.0.dist-info/METADATA,sha256=FRJXLOfZEs1Pr3PFNqfV41cBDNk1oT49RiO9cFYDwRw,1220
6
+ onesecondtrader-0.5.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
7
+ onesecondtrader-0.5.0.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- onesecondtrader/__init__.py,sha256=YWe2rJwheKv4oytgJk3nODWfoMJAVzpMc9OJmNBGjc4,388
2
- onesecondtrader/domain_models.py,sha256=01UEmX0S2WquspbMII826uS-Qo47XukvFl-niirviV4,5537
3
- onesecondtrader/log_config.py,sha256=TGm53SD_TA4Xa57Go91BGHV3SEIA6MflwSO63r9Jt6g,366
4
- onesecondtrader-0.3.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
5
- onesecondtrader-0.3.0.dist-info/METADATA,sha256=b_2UMpNoMHmtMhpqmhrV84YJxSURPBxbt5mbtVB5sqk,1220
6
- onesecondtrader-0.3.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
7
- onesecondtrader-0.3.0.dist-info/RECORD,,