onesecondtrader 0.32.0__tar.gz → 0.33.0__tar.gz
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.
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/PKG-INFO +1 -1
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/pyproject.toml +1 -1
- onesecondtrader-0.33.0/src/onesecondtrader/__init__.py +49 -0
- onesecondtrader-0.33.0/src/onesecondtrader/indicators/base.py +60 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/strategies/__init__.py +2 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/strategies/base.py +2 -2
- onesecondtrader-0.33.0/src/onesecondtrader/strategies/sma_crossover.py +35 -0
- onesecondtrader-0.32.0/src/onesecondtrader/__init__.py +0 -5
- onesecondtrader-0.32.0/src/onesecondtrader/indicators/base.py +0 -50
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/LICENSE +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/README.md +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/brokers/__init__.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/brokers/base.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/brokers/simulated.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/events/__init__.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/events/bases.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/events/market.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/events/requests.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/events/responses.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/indicators/__init__.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/indicators/averages.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/indicators/bar.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/messaging/__init__.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/messaging/eventbus.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/messaging/subscriber.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/models/__init__.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/models/data.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/models/orders.py +0 -0
- {onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/models/records.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: onesecondtrader
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.33.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,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "onesecondtrader"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.33.0"
|
|
4
4
|
description = "The Trading Infrastructure Toolkit for Python. Research, simulate, and deploy algorithmic trading strategies — all in one place."
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "Nils P. Kujath",email = "63961429+NilsKujath@users.noreply.github.com"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
__all__ = [
|
|
2
|
+
"BarPeriod",
|
|
3
|
+
"BarProcessed",
|
|
4
|
+
"BarReceived",
|
|
5
|
+
"BrokerBase",
|
|
6
|
+
"Close",
|
|
7
|
+
"FillRecord",
|
|
8
|
+
"High",
|
|
9
|
+
"Indicator",
|
|
10
|
+
"InputSource",
|
|
11
|
+
"Low",
|
|
12
|
+
"Open",
|
|
13
|
+
"OrderFilled",
|
|
14
|
+
"OrderRecord",
|
|
15
|
+
"OrderSide",
|
|
16
|
+
"OrderSubmission",
|
|
17
|
+
"OrderType",
|
|
18
|
+
"SimpleMovingAverage",
|
|
19
|
+
"SimulatedBroker",
|
|
20
|
+
"SMACrossover",
|
|
21
|
+
"StrategyBase",
|
|
22
|
+
"Volume",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
from onesecondtrader.brokers import BrokerBase, SimulatedBroker
|
|
26
|
+
from onesecondtrader.events import (
|
|
27
|
+
BarProcessed,
|
|
28
|
+
BarReceived,
|
|
29
|
+
OrderFilled,
|
|
30
|
+
OrderSubmission,
|
|
31
|
+
)
|
|
32
|
+
from onesecondtrader.indicators import (
|
|
33
|
+
Close,
|
|
34
|
+
High,
|
|
35
|
+
Indicator,
|
|
36
|
+
Low,
|
|
37
|
+
Open,
|
|
38
|
+
SimpleMovingAverage,
|
|
39
|
+
Volume,
|
|
40
|
+
)
|
|
41
|
+
from onesecondtrader.models import (
|
|
42
|
+
BarPeriod,
|
|
43
|
+
FillRecord,
|
|
44
|
+
InputSource,
|
|
45
|
+
OrderRecord,
|
|
46
|
+
OrderSide,
|
|
47
|
+
OrderType,
|
|
48
|
+
)
|
|
49
|
+
from onesecondtrader.strategies import SMACrossover, StrategyBase
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import abc
|
|
4
|
+
import collections
|
|
5
|
+
import threading
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
from onesecondtrader import events
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Indicator(abc.ABC):
|
|
13
|
+
def __init__(self, max_history: int = 100, plot_at: int = 99) -> None:
|
|
14
|
+
self._lock = threading.Lock()
|
|
15
|
+
self._max_history = max(1, int(max_history))
|
|
16
|
+
self._current_symbol: str = ""
|
|
17
|
+
self._history_data: dict[str, collections.deque[float]] = {}
|
|
18
|
+
self._plot_at = plot_at
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
@abc.abstractmethod
|
|
22
|
+
def name(self) -> str:
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
@abc.abstractmethod
|
|
26
|
+
def _compute_indicator(self, incoming_bar: events.BarReceived) -> float:
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
def update(self, incoming_bar: events.BarReceived) -> None:
|
|
30
|
+
symbol = incoming_bar.symbol
|
|
31
|
+
self._current_symbol = symbol
|
|
32
|
+
value = self._compute_indicator(incoming_bar)
|
|
33
|
+
with self._lock:
|
|
34
|
+
if symbol not in self._history_data:
|
|
35
|
+
self._history_data[symbol] = collections.deque(maxlen=self._max_history)
|
|
36
|
+
self._history_data[symbol].append(value)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def latest(self) -> float:
|
|
40
|
+
with self._lock:
|
|
41
|
+
h = self._history_data.get(self._current_symbol, collections.deque())
|
|
42
|
+
return h[-1] if h else np.nan
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def history(self) -> collections.deque[float]:
|
|
46
|
+
with self._lock:
|
|
47
|
+
h = self._history_data.get(self._current_symbol, collections.deque())
|
|
48
|
+
return collections.deque(h, maxlen=self._max_history)
|
|
49
|
+
|
|
50
|
+
def __getitem__(self, index: int) -> float:
|
|
51
|
+
# Returns np.nan on out-of-bounds access. Since np.nan comparisons always
|
|
52
|
+
# return False, strategies can skip explicit length checks.
|
|
53
|
+
try:
|
|
54
|
+
return self.history[index]
|
|
55
|
+
except IndexError:
|
|
56
|
+
return np.nan
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def plot_at(self) -> int:
|
|
60
|
+
return self._plot_at
|
|
@@ -39,7 +39,7 @@ class StrategyBase(messaging.Subscriber, abc.ABC):
|
|
|
39
39
|
self._submitted_modifications: dict[uuid.UUID, models.OrderRecord] = {}
|
|
40
40
|
self._submitted_cancellations: dict[uuid.UUID, models.OrderRecord] = {}
|
|
41
41
|
|
|
42
|
-
# OHLCV as indicators for history access: self.bar.close.history
|
|
42
|
+
# OHLCV as indicators for history access: self.bar.close.history
|
|
43
43
|
self.bar = SimpleNamespace(
|
|
44
44
|
open=self.add_indicator(indicators.Open()),
|
|
45
45
|
high=self.add_indicator(indicators.High()),
|
|
@@ -195,7 +195,7 @@ class StrategyBase(messaging.Subscriber, abc.ABC):
|
|
|
195
195
|
ohlcv_names = {"OPEN", "HIGH", "LOW", "CLOSE", "VOLUME"}
|
|
196
196
|
|
|
197
197
|
indicator_values = {
|
|
198
|
-
f"{ind.plot_at:02d}_{ind.name}": ind.latest
|
|
198
|
+
f"{ind.plot_at:02d}_{ind.name}": ind.latest
|
|
199
199
|
for ind in self._indicators
|
|
200
200
|
if ind.name not in ohlcv_names
|
|
201
201
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from onesecondtrader import events, indicators, models
|
|
2
|
+
from .base import StrategyBase
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SMACrossover(StrategyBase):
|
|
6
|
+
fast_period: int = 20
|
|
7
|
+
slow_period: int = 100
|
|
8
|
+
quantity: float = 1.0
|
|
9
|
+
|
|
10
|
+
def setup(self) -> None:
|
|
11
|
+
self.fast_sma = self.add_indicator(
|
|
12
|
+
indicators.SimpleMovingAverage(period=self.fast_period)
|
|
13
|
+
)
|
|
14
|
+
self.slow_sma = self.add_indicator(
|
|
15
|
+
indicators.SimpleMovingAverage(period=self.slow_period)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def on_bar(self, event: events.BarReceived) -> None:
|
|
19
|
+
if (
|
|
20
|
+
self.fast_sma[-2] <= self.slow_sma[-2]
|
|
21
|
+
and self.fast_sma.latest > self.slow_sma.latest
|
|
22
|
+
and self.position <= 0
|
|
23
|
+
):
|
|
24
|
+
self.submit_order(
|
|
25
|
+
models.OrderType.MARKET, models.OrderSide.BUY, self.quantity
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
self.fast_sma[-2] >= self.slow_sma[-2]
|
|
30
|
+
and self.fast_sma.latest < self.slow_sma.latest
|
|
31
|
+
and self.position >= 0
|
|
32
|
+
):
|
|
33
|
+
self.submit_order(
|
|
34
|
+
models.OrderType.MARKET, models.OrderSide.SELL, self.quantity
|
|
35
|
+
)
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import abc
|
|
4
|
-
import collections
|
|
5
|
-
import threading
|
|
6
|
-
|
|
7
|
-
import numpy as np
|
|
8
|
-
|
|
9
|
-
from onesecondtrader import events
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Indicator(abc.ABC):
|
|
13
|
-
def __init__(self, max_history: int = 100, plot_at: int = 99) -> None:
|
|
14
|
-
self._lock = threading.Lock()
|
|
15
|
-
self._max_history = max(1, int(max_history))
|
|
16
|
-
# Keyed by symbol only - each strategy subscribes to one timeframe, so the indicator only sees bars from that timeframe.
|
|
17
|
-
self._history: dict[str, collections.deque[float]] = {}
|
|
18
|
-
# 0 = main price chart, 1-98 = subcharts, 99 = no plot
|
|
19
|
-
self._plot_at = plot_at
|
|
20
|
-
|
|
21
|
-
@property
|
|
22
|
-
@abc.abstractmethod
|
|
23
|
-
def name(self) -> str:
|
|
24
|
-
pass
|
|
25
|
-
|
|
26
|
-
@abc.abstractmethod
|
|
27
|
-
def _compute_indicator(self, incoming_bar: events.BarReceived) -> float:
|
|
28
|
-
pass
|
|
29
|
-
|
|
30
|
-
def update(self, incoming_bar: events.BarReceived) -> None:
|
|
31
|
-
symbol = incoming_bar.symbol
|
|
32
|
-
value = self._compute_indicator(incoming_bar)
|
|
33
|
-
with self._lock:
|
|
34
|
-
if symbol not in self._history:
|
|
35
|
-
self._history[symbol] = collections.deque(maxlen=self._max_history)
|
|
36
|
-
self._history[symbol].append(value)
|
|
37
|
-
|
|
38
|
-
def latest(self, symbol: str) -> float:
|
|
39
|
-
with self._lock:
|
|
40
|
-
history = self._history.get(symbol, collections.deque())
|
|
41
|
-
return history[-1] if history else np.nan
|
|
42
|
-
|
|
43
|
-
def history(self, symbol: str) -> collections.deque[float]:
|
|
44
|
-
with self._lock:
|
|
45
|
-
h = self._history.get(symbol, collections.deque())
|
|
46
|
-
return collections.deque(h, maxlen=self._max_history)
|
|
47
|
-
|
|
48
|
-
@property
|
|
49
|
-
def plot_at(self) -> int:
|
|
50
|
-
return self._plot_at
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/indicators/__init__.py
RENAMED
|
File without changes
|
{onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/indicators/averages.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{onesecondtrader-0.32.0 → onesecondtrader-0.33.0}/src/onesecondtrader/messaging/subscriber.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|