onesecondtrader 0.13.1__py3-none-any.whl → 0.14.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.
@@ -2,26 +2,6 @@ from dataclasses import dataclass
2
2
  import enum
3
3
 
4
4
 
5
- class BrokerType(enum.Enum):
6
- """
7
- Enum for broker types.
8
-
9
- **Attributes:**
10
-
11
- | Enum | Value | Description |
12
- |------|-------|-------------|
13
- | `LOCAL_SIMULATED` | `enum.auto()` | Locally simulated broker |
14
- | `IB_SIMULATED` | `enum.auto()` | Interactive Brokers paper trading account |
15
- | `IB_LIVE` | `enum.auto()` | Interactive Brokers live trading account |
16
- | `MT5` | `enum.auto()` | MetaTrader 5 |
17
- """
18
-
19
- LOCAL_SIMULATED = enum.auto()
20
- IB_SIMULATED = enum.auto()
21
- IB_LIVE = enum.auto()
22
- MT5 = enum.auto()
23
-
24
-
25
5
  @dataclass(frozen=True, slots=True)
26
6
  class Bar:
27
7
  """
@@ -101,8 +81,8 @@ class OrderLifecycleState(enum.Enum):
101
81
 
102
82
  | Enum | Value | Description |
103
83
  |------|-------|-------------|
104
- | `PENDING` | `enum.auto()` | Order has been submitted, but not yet acknowledged by the broker |
105
- | `OPEN` | `enum.auto()` | Order has been acknowledged by the broker, but not yet filled or cancelled |
84
+ | `PENDING` | `enum.auto()` | Order has been submitted, but not yet acknowledged by the brokers |
85
+ | `OPEN` | `enum.auto()` | Order has been acknowledged by the brokers, but not yet filled or cancelled |
106
86
  | `FILLED` | `enum.auto()` | Order has been filled |
107
87
  | `CANCELLED` | `enum.auto()` | Order has been cancelled |
108
88
  """
@@ -186,3 +166,23 @@ class XMAMode(enum.Enum):
186
166
  CLOSE = enum.auto()
187
167
  TYPICAL_PRICE = enum.auto()
188
168
  WEIGHTED_CLOSE = enum.auto()
169
+
170
+
171
+ class Position:
172
+ pass
173
+
174
+
175
+ class StrategyShutdownMode(enum.Enum):
176
+ """
177
+ Enum for strategy shutdown modes.
178
+
179
+ **Attributes:**
180
+
181
+ | Enum | Value | Description |
182
+ |------|-------|-------------|
183
+ | `SOFT` | `enum.auto()` | Do not open new positions; wait until current positions close naturally |
184
+ | `HARD` | `enum.auto()` | Close all positions immediately with market orders |
185
+ """
186
+
187
+ SOFT = enum.auto()
188
+ HARD = enum.auto()
@@ -12,14 +12,10 @@ class BaseDatafeed(abc.ABC):
12
12
  Base class for all datafeeds.
13
13
  """
14
14
 
15
- def __init__(self, event_bus: messaging.EventBus):
16
- """
17
- Initialize the datafeed with an event bus.
18
-
19
- Args:
20
- event_bus (messaging.EventBus): Event bus to publish market data events to.
21
- """
22
- self.event_bus: messaging.EventBus = event_bus
15
+ def __init__(self, event_bus: messaging.EventBus | None = None):
16
+ self.event_bus: messaging.EventBus = (
17
+ event_bus if event_bus else messaging.system_event_bus
18
+ )
23
19
 
24
20
  @abc.abstractmethod
25
21
  def connect(self):
@@ -1,8 +1,9 @@
1
- from .eventbus import EventBus as EventBus
1
+ from .eventbus import EventBus as EventBus, system_event_bus as system_event_bus
2
2
  from .events import (
3
3
  Base as Base,
4
4
  Market as Market,
5
5
  Request as Request,
6
6
  Response as Response,
7
7
  System as System,
8
+ Portfolio as Portfolio,
8
9
  )
@@ -12,6 +12,12 @@ from onesecondtrader.messaging import events
12
12
  from onesecondtrader.monitoring import console
13
13
 
14
14
 
15
+ __all__ = [
16
+ "EventBus",
17
+ "system_event_bus",
18
+ ]
19
+
20
+
15
21
  class EventBus:
16
22
  # noinspection PyTypeChecker
17
23
  """
@@ -488,3 +494,6 @@ class EventBus:
488
494
  f"total handlers: "
489
495
  f"{sum(len(handlers) for handlers in new_cache.values())}"
490
496
  )
497
+
498
+
499
+ system_event_bus = EventBus()
@@ -23,11 +23,13 @@ Dataclass field validation logic is grouped under the `_Validate` namespace.
23
23
  R22[events.Base.CancelRequest]
24
24
  R3[events.Base.Response]
25
25
  R4[events.Base.System]
26
+ R5[events.Base.Portfolio]
26
27
 
27
28
  R --> R1
28
29
  R --> R2
29
30
  R --> R3
30
31
  R --> R4
32
+ R --> R5
31
33
 
32
34
  R2 --> R21
33
35
  R2 --> R22
@@ -83,6 +85,11 @@ Dataclass field validation logic is grouped under the `_Validate` namespace.
83
85
 
84
86
  style D1 fill:#6F42C1,fill-opacity:0.3
85
87
 
88
+ E1[events.Portfolio.SymbolRelease]
89
+
90
+ R5 --> E1
91
+
92
+ style E1 fill:#6F42C1,fill-opacity:0.3
86
93
 
87
94
  subgraph Market ["Market Update Event Messages"]
88
95
  R1
@@ -143,6 +150,16 @@ Dataclass field validation logic is grouped under the `_Validate` namespace.
143
150
  D1
144
151
  end
145
152
 
153
+ end
154
+
155
+ subgraph Portfolio ["Portfolio Coord. Event Messages"]
156
+ R5
157
+ E1
158
+
159
+ subgraph PortfolioNamespace ["events.Portfolio Namespace"]
160
+ E1
161
+ end
162
+
146
163
  end
147
164
  ```
148
165
  """
@@ -345,6 +362,28 @@ class Base:
345
362
  )
346
363
  return super().__new__(cls)
347
364
 
365
+ @dataclasses.dataclass(kw_only=True, frozen=True)
366
+ class Portfolio(Event):
367
+ """
368
+ Base event message dataclass for portfolio coordination messages.
369
+ This dataclass cannot be instantiated directly.
370
+
371
+ Attributes:
372
+ ts_event: Timestamp of the event. (defaults to current UTC time;
373
+ auto-generated)
374
+ """
375
+
376
+ ts_event: pd.Timestamp = dataclasses.field(
377
+ default_factory=lambda: pd.Timestamp.now(tz="UTC")
378
+ )
379
+
380
+ def __new__(cls, *args, **kwargs):
381
+ if cls is Base.Portfolio:
382
+ console.logger.error(
383
+ f"Cannot instantiate abstract class '{cls.__name__}' directly"
384
+ )
385
+ return super().__new__(cls)
386
+
348
387
 
349
388
  class Market:
350
389
  """
@@ -699,6 +738,25 @@ class System:
699
738
  pass
700
739
 
701
740
 
741
+ class Portfolio:
742
+ """
743
+ Namespace for portfolio coordination event messages.
744
+ """
745
+
746
+ @dataclasses.dataclass(kw_only=True, frozen=True)
747
+ class SymbolRelease(Base.Portfolio):
748
+ """
749
+ Event to indicate a strategy releases ownership of a symbol.
750
+ """
751
+
752
+ symbol: str
753
+ strategy_name: str
754
+
755
+ def __post_init__(self) -> None:
756
+ super().__post_init__()
757
+ _Validate.symbol(self.symbol, "Portfolio.SymbolRelease")
758
+
759
+
702
760
  class _Validate:
703
761
  """Internal validation utilities for events."""
704
762
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onesecondtrader
3
- Version: 0.13.1
3
+ Version: 0.14.0
4
4
  Summary: The Trading Infrastructure Toolkit for Python. Research, simulate, and deploy algorithmic trading strategies — all in one place.
5
5
  License-File: LICENSE
6
6
  Author: Nils P. Kujath
@@ -1,21 +1,21 @@
1
1
  onesecondtrader/__init__.py,sha256=TNqlT20sH46-J7F6giBxwWYG1-wFZZt7toDbZeQK6KQ,210
2
2
  onesecondtrader/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- onesecondtrader/core/models.py,sha256=253_5DtMS4mQA1IAVrEbw-rpCcyyKtB3HaORFyF2jdU,4823
3
+ onesecondtrader/core/models.py,sha256=fPI9gpgAhd2JREoo77jwf2x-QZTrSLg8_SWYKLSqwGQ,4721
4
4
  onesecondtrader/core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  onesecondtrader/datafeeds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- onesecondtrader/datafeeds/base_datafeed.py,sha256=QGXtkVUVN7PsDYeIH8h7Hi_kiDDFcqRyW8K8LzZkRTk,1394
6
+ onesecondtrader/datafeeds/base_datafeed.py,sha256=WViw7tzsVoZku-V-DxbqKSjNPkvaiA8G-J5Rs9eKKn8,1299
7
7
  onesecondtrader/datafeeds/csv_datafeed.py,sha256=WMoZpoian_93CdAzo36hJoF15T0ywRADfuFQcfsPQNc,10957
8
8
  onesecondtrader/indicators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  onesecondtrader/indicators/base_indicator.py,sha256=eGv5_WYOSsuLXX8MbnyE3_Y8owH-2bpUT_GczOXDHVE,4359
10
10
  onesecondtrader/indicators/moving_averages.py,sha256=ddZy640Z2aVgeiZ4SFRWsHDFaOBCW7u3mqBmc1wZrmQ,4678
11
- onesecondtrader/messaging/__init__.py,sha256=9GBHlh6pXweknEacXVBvzpdoTJgVyb3ROLqe1Fhz2ww,179
12
- onesecondtrader/messaging/eventbus.py,sha256=R2K85INeYVwJ1tMOybC3WpRraK0ZKVe8WehCbAzzznU,19359
13
- onesecondtrader/messaging/events.py,sha256=eaWXQQIUnRNOR-9n5-6lyLbZ6bUtzjD4GI567U_vh4g,23625
11
+ onesecondtrader/messaging/__init__.py,sha256=vTusKryf0oCh8SCw5syfkdEp50JZYjhFM3RzNuohH28,245
12
+ onesecondtrader/messaging/eventbus.py,sha256=sEp5ebYNRHiqTRXaTqytZ2PV2wKDXj5NlWNi1OKn2_4,19447
13
+ onesecondtrader/messaging/events.py,sha256=N7m0mba7xXiM59lrsAsQnGGrgKzRAqFeEGNHGfIFEwQ,25182
14
14
  onesecondtrader/monitoring/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  onesecondtrader/monitoring/console.py,sha256=1mrojXkyL4ro7ebkvDMGNQiCL-93WEylRuwnfmEKzVs,299
16
16
  onesecondtrader/monitoring/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  onesecondtrader/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- onesecondtrader-0.13.1.dist-info/METADATA,sha256=n-al9PSl41obJX0fZho4HxUmvyKIyz74mQdUMYfGksg,9638
19
- onesecondtrader-0.13.1.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
20
- onesecondtrader-0.13.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
21
- onesecondtrader-0.13.1.dist-info/RECORD,,
18
+ onesecondtrader-0.14.0.dist-info/METADATA,sha256=4kpM3crGY6U9diMfEoxuWviz66skRwZCt0gdac-tS08,9638
19
+ onesecondtrader-0.14.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
20
+ onesecondtrader-0.14.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
21
+ onesecondtrader-0.14.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.2.0
2
+ Generator: poetry-core 2.2.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any