kuhl-haus-mdp 0.1.0__tar.gz → 0.1.1__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.
- kuhl_haus_mdp-0.1.1/PKG-INFO +146 -0
- kuhl_haus_mdp-0.1.1/README.md +95 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/pyproject.toml +1 -1
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/integ/web_socket_message_serde.py +2 -2
- kuhl_haus_mdp-0.1.1/tests/components/test_market_data_scanner.py +55 -0
- kuhl_haus_mdp-0.1.1/tests/helpers/__init__.py +0 -0
- kuhl_haus_mdp-0.1.1/tests/test_queue_name_resolver.py +51 -0
- kuhl_haus_mdp-0.1.1/tests/test_web_socket_message_serde.py +440 -0
- kuhl_haus_mdp-0.1.0/PKG-INFO +0 -79
- kuhl_haus_mdp-0.1.0/README.md +0 -28
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/LICENSE.txt +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/__init__.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/analyzers/__init__.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/analyzers/analyzer.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/analyzers/massive_data_analyzer.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/analyzers/top_stocks.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/components/__init__.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/components/market_data_cache.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/components/market_data_scanner.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/components/widget_data_service.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/helpers/__init__.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/helpers/process_manager.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/helpers/queue_name_resolver.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/integ/__init__.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/integ/massive_data_listener.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/integ/massive_data_processor.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/integ/massive_data_queues.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/integ/utils.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/__init__.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/market_data_analyzer_result.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/market_data_cache_keys.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/market_data_pubsub_keys.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/market_data_scanner_names.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/massive_data_queue.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/tests/__init__.py +0 -0
- {kuhl_haus_mdp-0.1.0/tests/helpers → kuhl_haus_mdp-0.1.1/tests/components}/__init__.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/tests/components/test_widget_data_service.py +0 -0
- {kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/tests/helpers/test_process_manager.py +0 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: kuhl-haus-mdp
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Market data processing pipeline for stock market scanner
|
|
5
|
+
Author-Email: Tom Pounders <git@oldschool.engineer>
|
|
6
|
+
License: The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Tom Pounders
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Classifier: Development Status :: 4 - Beta
|
|
29
|
+
Classifier: Programming Language :: Python
|
|
30
|
+
Project-URL: Homepage, https://github.com/kuhl-haus/kuhl-haus-mdp
|
|
31
|
+
Project-URL: Documentation, https://github.com/kuhl-haus/kuhl-haus-mdp/wiki
|
|
32
|
+
Project-URL: Source, https://github.com/kuhl-haus/kuhl-haus-mdp.git
|
|
33
|
+
Project-URL: Changelog, https://github.com/kuhl-haus/kuhl-haus-mdp/commits
|
|
34
|
+
Project-URL: Tracker, https://github.com/kuhl-haus/kuhl-haus-mdp/issues
|
|
35
|
+
Requires-Python: <3.13,>=3.9.21
|
|
36
|
+
Requires-Dist: websockets
|
|
37
|
+
Requires-Dist: aio-pika
|
|
38
|
+
Requires-Dist: redis[asyncio]
|
|
39
|
+
Requires-Dist: tenacity
|
|
40
|
+
Requires-Dist: fastapi
|
|
41
|
+
Requires-Dist: uvicorn[standard]
|
|
42
|
+
Requires-Dist: pydantic-settings
|
|
43
|
+
Requires-Dist: python-dotenv
|
|
44
|
+
Requires-Dist: massive
|
|
45
|
+
Provides-Extra: testing
|
|
46
|
+
Requires-Dist: setuptools; extra == "testing"
|
|
47
|
+
Requires-Dist: pdm-backend; extra == "testing"
|
|
48
|
+
Requires-Dist: pytest; extra == "testing"
|
|
49
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
50
|
+
Description-Content-Type: text/markdown
|
|
51
|
+
|
|
52
|
+
<!-- These are examples of badges you might want to add to your README:
|
|
53
|
+
please update the URLs accordingly
|
|
54
|
+
|
|
55
|
+
[](https://kuhl-haus-mdp.readthedocs.io/en/stable/)
|
|
56
|
+
[](https://anaconda.org/conda-forge/kuhl-haus-mdp)
|
|
57
|
+
[](https://pepy.tech/project/kuhl-haus-mdp)
|
|
58
|
+
-->
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/blob/mainline/LICENSE.txt)
|
|
62
|
+
[](https://pypi.org/project/kuhl-haus-mdp/)
|
|
63
|
+
[](https://pepy.tech/project/kuhl-haus-mdp)
|
|
64
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/publish-to-pypi.yml)
|
|
65
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/codeql.yml)
|
|
66
|
+
[](https://codecov.io/gh/kuhl-haus/kuhl-haus-mdp)
|
|
67
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/issues)
|
|
68
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/pulls)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# kuhl-haus-mdp
|
|
72
|
+
|
|
73
|
+
Market data processing pipeline for stock market scanner.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## TL;DR
|
|
78
|
+
Non-business Massive (AKA Polygon.IO) accounts are limited to a single WebSocket connection per asset class and it has to be fast enough to handle messages in a non-blocking fashion or it'll get disconnected. The market data processing pipeline consists of loosely-coupled market data processing components so that a single WebSocket connection can handle messages fast enough to maintain a reliable connection with the market data provider.
|
|
79
|
+
|
|
80
|
+
Per, https://massive.com/docs/websocket/quickstart#connecting-to-the-websocket:
|
|
81
|
+
> *By default, one concurrent WebSocket connection per asset class is allowed. If you require multiple simultaneous connections for the same asset class, please [contact support](https://massive.com/contact).*
|
|
82
|
+
|
|
83
|
+
# Components Summary
|
|
84
|
+
|
|
85
|
+
Non-business Massive (AKA Polygon.IO) accounts are limited to a single WebSocket connection per asset class and it has to be fast enough to handle messages in a non-blocking fashion or it'll get disconnected. The Market Data Listener (MDL) connects to the Market Data Source (Massive) and subscribes to unfiltered feeds. MDL inspects the message type for selecting the appropriate serialization method and destination Market Data Queue (MDQ). The Market Data Processors (MDP) subscribe to raw market data in the MDQ and perform the heavy lifting that would otherwise constrain the message handling speed of the MDL. This decoupling allows the MDP and MDL to scale independently. Post-processed market data is stored in the MDC for consumption by the Widget Data Service (WDS). Client-side widgets receive market data from the WDS, which provides a WebSocket interface to MDC pub/sub streams and cached data.
|
|
86
|
+
|
|
87
|
+
[]
|
|
88
|
+
|
|
89
|
+
# Component Descriptions
|
|
90
|
+
|
|
91
|
+
## Market Data Listener (MDL)
|
|
92
|
+
The MDL performs minimal processing on the messages. MDL inspects the message type for selecting the appropriate serialization method and destination queue. MDL implementations may vary as new MDS become available (for example, news).
|
|
93
|
+
|
|
94
|
+
MDL runs as a container and scales independently of other components. The MDL should not be accessible outside the data plane local network.
|
|
95
|
+
|
|
96
|
+
## Market Data Queues (MDQ)
|
|
97
|
+
|
|
98
|
+
**Purpose:** Buffer high-velocity market data stream for server-side processing with aggressive freshness controls
|
|
99
|
+
- **Queue Type:** FIFO with TTL (5-second max message age)
|
|
100
|
+
- **Cleanup Strategy:** Discarded when TTL expires
|
|
101
|
+
- **Message Format:** Timestamped JSON preserving original Massive.com structure
|
|
102
|
+
- **Durability:** Non-persistent messages (speed over reliability for real-time data)
|
|
103
|
+
- **Independence:** Queues operate completely independently - one queue per subscription
|
|
104
|
+
- **Technology**: RabbitMQ
|
|
105
|
+
|
|
106
|
+
The MDQ should not be accessible outside the data plane local network.
|
|
107
|
+
|
|
108
|
+
## Market Data Processors (MDP)
|
|
109
|
+
The purpose of the MDP is to process raw real-time market data and delegate processing to data-specific handlers. This separation of concerns allows MDPs to handle any type of data and simplifies horizontal scaling. The MDP stores its processed results in the Market Data Cache (MDC).
|
|
110
|
+
|
|
111
|
+
The MDP:
|
|
112
|
+
- Hydrates the in-memory cache on MDC
|
|
113
|
+
- Processes market data
|
|
114
|
+
- Publishes messages to pub/sub channels
|
|
115
|
+
- Maintains cache entries in MDC
|
|
116
|
+
|
|
117
|
+
MDPs runs as containers and scale independently of other components. The MDPs should not be accessible outside the data plane local network.
|
|
118
|
+
|
|
119
|
+
## Market Data Cache (MDC)
|
|
120
|
+
|
|
121
|
+
**Purpose:** In-memory data store for serialized processed market data.
|
|
122
|
+
* **Cache Type**: In-memory persistent or with TTL
|
|
123
|
+
- **Queue Type:** pub/sub
|
|
124
|
+
- **Technology**: Redis
|
|
125
|
+
|
|
126
|
+
The MDC should not be accessible outside the data plane local network.
|
|
127
|
+
|
|
128
|
+
## Widget Data Service (WDS)
|
|
129
|
+
**Purpose**:
|
|
130
|
+
1. WebSocket interface provides access to processed market data for client-side code
|
|
131
|
+
2. Is the network-layer boundary between clients and the data that is available on the data plane
|
|
132
|
+
|
|
133
|
+
WDS runs as a container and scales independently of other components. WDS is the only data plane component that should be exposed to client networks.
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
## Service Control Plane (SCP)
|
|
137
|
+
**Purpose**:
|
|
138
|
+
1. Authentication and authorization
|
|
139
|
+
2. Serve static and dynamic content via py4web
|
|
140
|
+
3. Serve SPA to authenticated clients
|
|
141
|
+
4. Injects authentication token and WDS url into SPA environment for authenticated access to WDS
|
|
142
|
+
5. Control plane for managing application components at runtime
|
|
143
|
+
6. API for programmatic access to service controls and instrumentation.
|
|
144
|
+
|
|
145
|
+
The SCP requires access to the data plane network for API access to data plane components.
|
|
146
|
+
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<!-- These are examples of badges you might want to add to your README:
|
|
2
|
+
please update the URLs accordingly
|
|
3
|
+
|
|
4
|
+
[](https://kuhl-haus-mdp.readthedocs.io/en/stable/)
|
|
5
|
+
[](https://anaconda.org/conda-forge/kuhl-haus-mdp)
|
|
6
|
+
[](https://pepy.tech/project/kuhl-haus-mdp)
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/blob/mainline/LICENSE.txt)
|
|
11
|
+
[](https://pypi.org/project/kuhl-haus-mdp/)
|
|
12
|
+
[](https://pepy.tech/project/kuhl-haus-mdp)
|
|
13
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/publish-to-pypi.yml)
|
|
14
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/codeql.yml)
|
|
15
|
+
[](https://codecov.io/gh/kuhl-haus/kuhl-haus-mdp)
|
|
16
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/issues)
|
|
17
|
+
[](https://github.com/kuhl-haus/kuhl-haus-mdp/pulls)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# kuhl-haus-mdp
|
|
21
|
+
|
|
22
|
+
Market data processing pipeline for stock market scanner.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## TL;DR
|
|
27
|
+
Non-business Massive (AKA Polygon.IO) accounts are limited to a single WebSocket connection per asset class and it has to be fast enough to handle messages in a non-blocking fashion or it'll get disconnected. The market data processing pipeline consists of loosely-coupled market data processing components so that a single WebSocket connection can handle messages fast enough to maintain a reliable connection with the market data provider.
|
|
28
|
+
|
|
29
|
+
Per, https://massive.com/docs/websocket/quickstart#connecting-to-the-websocket:
|
|
30
|
+
> *By default, one concurrent WebSocket connection per asset class is allowed. If you require multiple simultaneous connections for the same asset class, please [contact support](https://massive.com/contact).*
|
|
31
|
+
|
|
32
|
+
# Components Summary
|
|
33
|
+
|
|
34
|
+
Non-business Massive (AKA Polygon.IO) accounts are limited to a single WebSocket connection per asset class and it has to be fast enough to handle messages in a non-blocking fashion or it'll get disconnected. The Market Data Listener (MDL) connects to the Market Data Source (Massive) and subscribes to unfiltered feeds. MDL inspects the message type for selecting the appropriate serialization method and destination Market Data Queue (MDQ). The Market Data Processors (MDP) subscribe to raw market data in the MDQ and perform the heavy lifting that would otherwise constrain the message handling speed of the MDL. This decoupling allows the MDP and MDL to scale independently. Post-processed market data is stored in the MDC for consumption by the Widget Data Service (WDS). Client-side widgets receive market data from the WDS, which provides a WebSocket interface to MDC pub/sub streams and cached data.
|
|
35
|
+
|
|
36
|
+
[]
|
|
37
|
+
|
|
38
|
+
# Component Descriptions
|
|
39
|
+
|
|
40
|
+
## Market Data Listener (MDL)
|
|
41
|
+
The MDL performs minimal processing on the messages. MDL inspects the message type for selecting the appropriate serialization method and destination queue. MDL implementations may vary as new MDS become available (for example, news).
|
|
42
|
+
|
|
43
|
+
MDL runs as a container and scales independently of other components. The MDL should not be accessible outside the data plane local network.
|
|
44
|
+
|
|
45
|
+
## Market Data Queues (MDQ)
|
|
46
|
+
|
|
47
|
+
**Purpose:** Buffer high-velocity market data stream for server-side processing with aggressive freshness controls
|
|
48
|
+
- **Queue Type:** FIFO with TTL (5-second max message age)
|
|
49
|
+
- **Cleanup Strategy:** Discarded when TTL expires
|
|
50
|
+
- **Message Format:** Timestamped JSON preserving original Massive.com structure
|
|
51
|
+
- **Durability:** Non-persistent messages (speed over reliability for real-time data)
|
|
52
|
+
- **Independence:** Queues operate completely independently - one queue per subscription
|
|
53
|
+
- **Technology**: RabbitMQ
|
|
54
|
+
|
|
55
|
+
The MDQ should not be accessible outside the data plane local network.
|
|
56
|
+
|
|
57
|
+
## Market Data Processors (MDP)
|
|
58
|
+
The purpose of the MDP is to process raw real-time market data and delegate processing to data-specific handlers. This separation of concerns allows MDPs to handle any type of data and simplifies horizontal scaling. The MDP stores its processed results in the Market Data Cache (MDC).
|
|
59
|
+
|
|
60
|
+
The MDP:
|
|
61
|
+
- Hydrates the in-memory cache on MDC
|
|
62
|
+
- Processes market data
|
|
63
|
+
- Publishes messages to pub/sub channels
|
|
64
|
+
- Maintains cache entries in MDC
|
|
65
|
+
|
|
66
|
+
MDPs runs as containers and scale independently of other components. The MDPs should not be accessible outside the data plane local network.
|
|
67
|
+
|
|
68
|
+
## Market Data Cache (MDC)
|
|
69
|
+
|
|
70
|
+
**Purpose:** In-memory data store for serialized processed market data.
|
|
71
|
+
* **Cache Type**: In-memory persistent or with TTL
|
|
72
|
+
- **Queue Type:** pub/sub
|
|
73
|
+
- **Technology**: Redis
|
|
74
|
+
|
|
75
|
+
The MDC should not be accessible outside the data plane local network.
|
|
76
|
+
|
|
77
|
+
## Widget Data Service (WDS)
|
|
78
|
+
**Purpose**:
|
|
79
|
+
1. WebSocket interface provides access to processed market data for client-side code
|
|
80
|
+
2. Is the network-layer boundary between clients and the data that is available on the data plane
|
|
81
|
+
|
|
82
|
+
WDS runs as a container and scales independently of other components. WDS is the only data plane component that should be exposed to client networks.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## Service Control Plane (SCP)
|
|
86
|
+
**Purpose**:
|
|
87
|
+
1. Authentication and authorization
|
|
88
|
+
2. Serve static and dynamic content via py4web
|
|
89
|
+
3. Serve SPA to authenticated clients
|
|
90
|
+
4. Injects authentication token and WDS url into SPA environment for authenticated access to WDS
|
|
91
|
+
5. Control plane for managing application components at runtime
|
|
92
|
+
6. API for programmatic access to service controls and instrumentation.
|
|
93
|
+
|
|
94
|
+
The SCP requires access to the data plane network for API access to data plane components.
|
|
95
|
+
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/integ/web_socket_message_serde.py
RENAMED
|
@@ -59,8 +59,8 @@ class WebSocketMessageSerde:
|
|
|
59
59
|
ret: dict = {
|
|
60
60
|
"event_type": message.event_type,
|
|
61
61
|
"symbol": message.symbol,
|
|
62
|
-
"
|
|
63
|
-
"
|
|
62
|
+
"high_price": message.high_price,
|
|
63
|
+
"low_price": message.low_price,
|
|
64
64
|
"indicators": message.indicators,
|
|
65
65
|
"tape": message.tape,
|
|
66
66
|
"timestamp": message.timestamp,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# tests/test_market_data_scanner.py
|
|
2
|
+
import asyncio
|
|
3
|
+
import json
|
|
4
|
+
import unittest
|
|
5
|
+
from unittest.mock import AsyncMock, patch, MagicMock
|
|
6
|
+
|
|
7
|
+
from kuhl_haus.mdp.analyzers.analyzer import Analyzer
|
|
8
|
+
from kuhl_haus.mdp.components.market_data_scanner import MarketDataScanner
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TestMarketDataScanner(unittest.IsolatedAsyncioTestCase):
|
|
12
|
+
"""Unit tests for the MarketDataScanner class."""
|
|
13
|
+
|
|
14
|
+
def setUp(self):
|
|
15
|
+
"""Set up a MarketDataScanner instance for testing."""
|
|
16
|
+
self.redis_url = "redis://localhost:6379/0"
|
|
17
|
+
self.analyzer = MagicMock(spec=Analyzer)
|
|
18
|
+
self.analyzer.cache_key = MagicMock()
|
|
19
|
+
self.analyzer.rehydrate = AsyncMock()
|
|
20
|
+
self.analyzer.analyze_data = AsyncMock()
|
|
21
|
+
self.subscriptions = ["channel_1"]
|
|
22
|
+
self.scanner = MarketDataScanner(
|
|
23
|
+
redis_url=self.redis_url,
|
|
24
|
+
analyzer=self.analyzer,
|
|
25
|
+
subscriptions=self.subscriptions,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
@patch("kuhl_haus.mdp.components.market_data_scanner.asyncio.sleep", new_callable=AsyncMock)
|
|
29
|
+
@patch("kuhl_haus.mdp.components.market_data_scanner.MarketDataScanner.start", new_callable=AsyncMock)
|
|
30
|
+
@patch("kuhl_haus.mdp.components.market_data_scanner.MarketDataScanner.stop", new_callable=AsyncMock)
|
|
31
|
+
async def test_restart(self, mock_stop, mock_start, mock_sleep):
|
|
32
|
+
"""Test the restart method stops and starts the scanner."""
|
|
33
|
+
self.scanner.start = mock_start
|
|
34
|
+
self.scanner.stop = mock_stop
|
|
35
|
+
mock_stop.return_value = None
|
|
36
|
+
|
|
37
|
+
await self.scanner.restart()
|
|
38
|
+
|
|
39
|
+
mock_stop.assert_called_once()
|
|
40
|
+
mock_start.assert_called_once()
|
|
41
|
+
self.assertEqual(self.scanner.restarts, 1)
|
|
42
|
+
|
|
43
|
+
async def test_process_message_success(self):
|
|
44
|
+
"""Test _process_message handles and processes valid data."""
|
|
45
|
+
valid_data = {"key": "value"}
|
|
46
|
+
analyzer_results = [MagicMock(), MagicMock()]
|
|
47
|
+
self.analyzer.analyze_data = AsyncMock(return_value=analyzer_results)
|
|
48
|
+
self.scanner.cache_result = AsyncMock()
|
|
49
|
+
|
|
50
|
+
await self.scanner._process_message(valid_data)
|
|
51
|
+
|
|
52
|
+
self.analyzer.analyze_data.assert_called_once_with(valid_data)
|
|
53
|
+
self.scanner.cache_result.assert_any_call(analyzer_results[0])
|
|
54
|
+
self.scanner.cache_result.assert_any_call(analyzer_results[1])
|
|
55
|
+
self.assertEqual(self.scanner.processed, 1)
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# tests/test_queue_name_resolver.py
|
|
2
|
+
|
|
3
|
+
import unittest
|
|
4
|
+
from unittest.mock import MagicMock
|
|
5
|
+
|
|
6
|
+
from kuhl_haus.mdp.helpers.queue_name_resolver import QueueNameResolver
|
|
7
|
+
from kuhl_haus.mdp.models.massive_data_queue import MassiveDataQueue
|
|
8
|
+
from massive.websocket.models import EquityAgg, EquityTrade, EquityQuote, LimitUpLimitDown, WebSocketMessage
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TestQueueNameResolver(unittest.TestCase):
|
|
12
|
+
"""Unit tests for the QueueNameResolver class."""
|
|
13
|
+
|
|
14
|
+
def test_resolves_trades_queue(self):
|
|
15
|
+
"""Test that EquityTrade messages resolve to the TRADES queue."""
|
|
16
|
+
message = MagicMock(spec=EquityTrade)
|
|
17
|
+
expected_queue = MassiveDataQueue.TRADES.value
|
|
18
|
+
resolved_queue = QueueNameResolver.queue_name_for_web_socket_message(message)
|
|
19
|
+
self.assertEqual(expected_queue, resolved_queue)
|
|
20
|
+
|
|
21
|
+
def test_resolves_aggregate_queue(self):
|
|
22
|
+
"""Test that EquityAgg messages resolve to the AGGREGATE queue."""
|
|
23
|
+
message = MagicMock(spec=EquityAgg)
|
|
24
|
+
expected_queue = MassiveDataQueue.AGGREGATE.value
|
|
25
|
+
resolved_queue = QueueNameResolver.queue_name_for_web_socket_message(message)
|
|
26
|
+
self.assertEqual(expected_queue, resolved_queue)
|
|
27
|
+
|
|
28
|
+
def test_resolves_quotes_queue(self):
|
|
29
|
+
"""Test that EquityQuote messages resolve to the QUOTES queue."""
|
|
30
|
+
message = MagicMock(spec=EquityQuote)
|
|
31
|
+
expected_queue = MassiveDataQueue.QUOTES.value
|
|
32
|
+
resolved_queue = QueueNameResolver.queue_name_for_web_socket_message(message)
|
|
33
|
+
self.assertEqual(expected_queue, resolved_queue)
|
|
34
|
+
|
|
35
|
+
def test_resolves_halts_queue(self):
|
|
36
|
+
"""Test that LimitUpLimitDown messages resolve to the HALTS queue."""
|
|
37
|
+
message = MagicMock(spec=LimitUpLimitDown)
|
|
38
|
+
expected_queue = MassiveDataQueue.HALTS.value
|
|
39
|
+
resolved_queue = QueueNameResolver.queue_name_for_web_socket_message(message)
|
|
40
|
+
self.assertEqual(expected_queue, resolved_queue)
|
|
41
|
+
|
|
42
|
+
def test_resolves_unknown_queue(self):
|
|
43
|
+
"""Test that unsupported WebSocketMessage resolves to the UNKNOWN queue."""
|
|
44
|
+
message = MagicMock(spec=WebSocketMessage) # Unsupported type
|
|
45
|
+
expected_queue = MassiveDataQueue.UNKNOWN.value
|
|
46
|
+
resolved_queue = QueueNameResolver.queue_name_for_web_socket_message(message)
|
|
47
|
+
self.assertEqual(expected_queue, resolved_queue)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == '__main__':
|
|
51
|
+
unittest.main()
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
# tests/test_web_socket_message_serde.py
|
|
2
|
+
import json
|
|
3
|
+
from argparse import ArgumentTypeError
|
|
4
|
+
import unittest
|
|
5
|
+
from unittest.mock import MagicMock
|
|
6
|
+
|
|
7
|
+
from massive.websocket.models import (
|
|
8
|
+
EquityTrade,
|
|
9
|
+
EquityQuote,
|
|
10
|
+
EquityAgg,
|
|
11
|
+
LimitUpLimitDown,
|
|
12
|
+
EventType,
|
|
13
|
+
)
|
|
14
|
+
from src.kuhl_haus.mdp.integ.web_socket_message_serde import WebSocketMessageSerde
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestWebSocketMessageSerde(unittest.TestCase):
|
|
18
|
+
"""Unit tests for the WebSocketMessageSerde class."""
|
|
19
|
+
|
|
20
|
+
# Equity Trades
|
|
21
|
+
def test_serialize_with_equity_trade_happy_path(self):
|
|
22
|
+
"""Test serialization of EquityTrade messages."""
|
|
23
|
+
message = MagicMock(
|
|
24
|
+
spec=EquityTrade,
|
|
25
|
+
event_type=EventType.EquityTrade.value,
|
|
26
|
+
symbol="TEST",
|
|
27
|
+
exchange="NYSE",
|
|
28
|
+
id="12345",
|
|
29
|
+
tape="T",
|
|
30
|
+
price=100.0,
|
|
31
|
+
size=10,
|
|
32
|
+
conditions=["C1", "C2"],
|
|
33
|
+
timestamp=1234567890,
|
|
34
|
+
sequence_number=1,
|
|
35
|
+
trf_id="54321",
|
|
36
|
+
trf_timestamp=1234567891,
|
|
37
|
+
)
|
|
38
|
+
serialized_message = WebSocketMessageSerde.serialize(message)
|
|
39
|
+
expected_message = {
|
|
40
|
+
"event_type": EventType.EquityTrade.value,
|
|
41
|
+
"symbol": "TEST",
|
|
42
|
+
"exchange": "NYSE",
|
|
43
|
+
"id": "12345",
|
|
44
|
+
"tape": "T",
|
|
45
|
+
"price": 100.0,
|
|
46
|
+
"size": 10,
|
|
47
|
+
"conditions": ["C1", "C2"],
|
|
48
|
+
"timestamp": 1234567890,
|
|
49
|
+
"sequence_number": 1,
|
|
50
|
+
"trf_id": "54321",
|
|
51
|
+
"trf_timestamp": 1234567891,
|
|
52
|
+
}
|
|
53
|
+
self.assertEqual(expected_message, json.loads(serialized_message))
|
|
54
|
+
|
|
55
|
+
def test_to_dict_with_equity_trade_happy_path(self):
|
|
56
|
+
"""Test conversion to a Python dictionary for EquityTrade messages."""
|
|
57
|
+
message = MagicMock(
|
|
58
|
+
spec=EquityTrade,
|
|
59
|
+
event_type=EventType.EquityTrade.value,
|
|
60
|
+
symbol="TEST",
|
|
61
|
+
exchange="NYSE",
|
|
62
|
+
id="12345",
|
|
63
|
+
tape="T",
|
|
64
|
+
price=100.0,
|
|
65
|
+
size=10,
|
|
66
|
+
conditions=["C1", "C2"],
|
|
67
|
+
timestamp=1234567890,
|
|
68
|
+
sequence_number=1,
|
|
69
|
+
trf_id="54321",
|
|
70
|
+
trf_timestamp=1234567891,
|
|
71
|
+
)
|
|
72
|
+
expected_dict = {
|
|
73
|
+
"event_type": EventType.EquityTrade.value,
|
|
74
|
+
"symbol": "TEST",
|
|
75
|
+
"exchange": "NYSE",
|
|
76
|
+
"id": "12345",
|
|
77
|
+
"tape": "T",
|
|
78
|
+
"price": 100.0,
|
|
79
|
+
"size": 10,
|
|
80
|
+
"conditions": ["C1", "C2"],
|
|
81
|
+
"timestamp": 1234567890,
|
|
82
|
+
"sequence_number": 1,
|
|
83
|
+
"trf_id": "54321",
|
|
84
|
+
"trf_timestamp": 1234567891,
|
|
85
|
+
}
|
|
86
|
+
self.assertEqual(expected_dict, WebSocketMessageSerde.to_dict(message))
|
|
87
|
+
|
|
88
|
+
def test_deserialize_with_equity_trade_happy_path(self):
|
|
89
|
+
"""Test deserialization of a EquityTrade message."""
|
|
90
|
+
serialized_message = json.dumps(
|
|
91
|
+
{
|
|
92
|
+
"event_type": EventType.EquityTrade.value,
|
|
93
|
+
"symbol": "TEST",
|
|
94
|
+
"exchange": "NYSE",
|
|
95
|
+
"id": "12345",
|
|
96
|
+
"tape": "T",
|
|
97
|
+
"price": 100.0,
|
|
98
|
+
"size": 10,
|
|
99
|
+
"conditions": ["C1", "C2"],
|
|
100
|
+
"timestamp": 1234567890,
|
|
101
|
+
"sequence_number": 1,
|
|
102
|
+
"trf_id": "54321",
|
|
103
|
+
"trf_timestamp": 1234567891,
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
deserialized_message = WebSocketMessageSerde.deserialize(serialized_message)
|
|
107
|
+
self.assertIsInstance(deserialized_message, EquityTrade)
|
|
108
|
+
self.assertEqual(deserialized_message.event_type, EventType.EquityTrade.value)
|
|
109
|
+
self.assertEqual(deserialized_message.symbol, "TEST")
|
|
110
|
+
self.assertEqual(deserialized_message.exchange, "NYSE")
|
|
111
|
+
self.assertEqual(deserialized_message.id, "12345")
|
|
112
|
+
self.assertEqual(deserialized_message.tape, "T")
|
|
113
|
+
self.assertEqual(deserialized_message.price, 100.0)
|
|
114
|
+
self.assertEqual(deserialized_message.size, 10)
|
|
115
|
+
self.assertEqual(deserialized_message.conditions, ["C1", "C2"])
|
|
116
|
+
self.assertEqual(deserialized_message.timestamp, 1234567890)
|
|
117
|
+
self.assertEqual(deserialized_message.sequence_number, 1)
|
|
118
|
+
self.assertEqual(deserialized_message.trf_id, "54321")
|
|
119
|
+
self.assertEqual(deserialized_message.trf_timestamp, 1234567891)
|
|
120
|
+
|
|
121
|
+
# Equity Quotes
|
|
122
|
+
def test_serialize_with_equity_quote_happy_path(self):
|
|
123
|
+
"""Test serialization for EquityQuote."""
|
|
124
|
+
message = MagicMock(
|
|
125
|
+
spec=EquityQuote,
|
|
126
|
+
event_type=EventType.EquityQuote.value,
|
|
127
|
+
symbol="TEST",
|
|
128
|
+
bid_exchange_id=11,
|
|
129
|
+
bid_price=101.0,
|
|
130
|
+
bid_size=50,
|
|
131
|
+
ask_exchange_id=12,
|
|
132
|
+
ask_price=102.0,
|
|
133
|
+
ask_size=60,
|
|
134
|
+
condition="C1",
|
|
135
|
+
indicators=["I1"],
|
|
136
|
+
timestamp=1234567892,
|
|
137
|
+
sequence_number=2,
|
|
138
|
+
tape="T1",
|
|
139
|
+
)
|
|
140
|
+
serialized_message = WebSocketMessageSerde.serialize(message)
|
|
141
|
+
expected_message = {
|
|
142
|
+
"event_type": EventType.EquityQuote.value,
|
|
143
|
+
"symbol": "TEST",
|
|
144
|
+
"bid_exchange_id": 11,
|
|
145
|
+
"bid_price": 101.0,
|
|
146
|
+
"bid_size": 50,
|
|
147
|
+
"ask_exchange_id": 12,
|
|
148
|
+
"ask_price": 102.0,
|
|
149
|
+
"ask_size": 60,
|
|
150
|
+
"condition": "C1",
|
|
151
|
+
"indicators": ["I1"],
|
|
152
|
+
"timestamp": 1234567892,
|
|
153
|
+
"sequence_number": 2,
|
|
154
|
+
"tape": "T1",
|
|
155
|
+
}
|
|
156
|
+
self.assertEqual(expected_message, json.loads(serialized_message))
|
|
157
|
+
|
|
158
|
+
def test_to_dict_with_equity_quote_happy_path(self):
|
|
159
|
+
"""Test conversion to a Python dictionary for EquityQuote."""
|
|
160
|
+
message = MagicMock(
|
|
161
|
+
spec=EquityQuote,
|
|
162
|
+
event_type=EventType.EquityQuote.value,
|
|
163
|
+
symbol="TEST",
|
|
164
|
+
bid_exchange_id=11,
|
|
165
|
+
bid_price=101.0,
|
|
166
|
+
bid_size=50,
|
|
167
|
+
ask_exchange_id=12,
|
|
168
|
+
ask_price=102.0,
|
|
169
|
+
ask_size=60,
|
|
170
|
+
condition="C1",
|
|
171
|
+
indicators=["I1"],
|
|
172
|
+
timestamp=1234567892,
|
|
173
|
+
sequence_number=2,
|
|
174
|
+
tape="T1",
|
|
175
|
+
)
|
|
176
|
+
expected_dict = {
|
|
177
|
+
"event_type": EventType.EquityQuote.value,
|
|
178
|
+
"symbol": "TEST",
|
|
179
|
+
"bid_exchange_id": 11,
|
|
180
|
+
"bid_price": 101.0,
|
|
181
|
+
"bid_size": 50,
|
|
182
|
+
"ask_exchange_id": 12,
|
|
183
|
+
"ask_price": 102.0,
|
|
184
|
+
"ask_size": 60,
|
|
185
|
+
"condition": "C1",
|
|
186
|
+
"indicators": ["I1"],
|
|
187
|
+
"timestamp": 1234567892,
|
|
188
|
+
"sequence_number": 2,
|
|
189
|
+
"tape": "T1",
|
|
190
|
+
}
|
|
191
|
+
self.assertEqual(expected_dict, WebSocketMessageSerde.to_dict(message))
|
|
192
|
+
|
|
193
|
+
def test_deserialize_with_equity_quote_happy_path(self):
|
|
194
|
+
"""Test deserialization for EquityQuote."""
|
|
195
|
+
serialized_message = json.dumps(
|
|
196
|
+
{
|
|
197
|
+
"event_type": EventType.EquityQuote.value,
|
|
198
|
+
"symbol": "TEST",
|
|
199
|
+
"bid_exchange_id": 11,
|
|
200
|
+
"bid_price": 101.0,
|
|
201
|
+
"bid_size": 50,
|
|
202
|
+
"ask_exchange_id": 12,
|
|
203
|
+
"ask_price": 102.0,
|
|
204
|
+
"ask_size": 60,
|
|
205
|
+
"condition": "C1",
|
|
206
|
+
"indicators": ["I1"],
|
|
207
|
+
"timestamp": 1234567892,
|
|
208
|
+
"sequence_number": 2,
|
|
209
|
+
"tape": "T1",
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
deserialized_message = WebSocketMessageSerde.deserialize(serialized_message)
|
|
213
|
+
self.assertIsInstance(deserialized_message, EquityQuote)
|
|
214
|
+
self.assertEqual(deserialized_message.event_type, EventType.EquityQuote.value)
|
|
215
|
+
self.assertEqual(deserialized_message.symbol, "TEST")
|
|
216
|
+
self.assertEqual(deserialized_message.bid_exchange_id, 11)
|
|
217
|
+
self.assertEqual(deserialized_message.bid_price, 101.0)
|
|
218
|
+
self.assertEqual(deserialized_message.bid_size, 50)
|
|
219
|
+
self.assertEqual(deserialized_message.ask_exchange_id, 12)
|
|
220
|
+
self.assertEqual(deserialized_message.ask_price, 102.0)
|
|
221
|
+
self.assertEqual(deserialized_message.ask_size, 60)
|
|
222
|
+
self.assertEqual(deserialized_message.condition, "C1")
|
|
223
|
+
self.assertEqual(deserialized_message.indicators, ["I1"])
|
|
224
|
+
self.assertEqual(deserialized_message.timestamp, 1234567892)
|
|
225
|
+
self.assertEqual(deserialized_message.sequence_number, 2)
|
|
226
|
+
self.assertEqual(deserialized_message.tape, "T1")
|
|
227
|
+
|
|
228
|
+
# Equity Aggregates
|
|
229
|
+
def test_serialize_with_equity_agg_happy_path(self):
|
|
230
|
+
"""Test serialization for EquityAgg."""
|
|
231
|
+
message = MagicMock(
|
|
232
|
+
spec=EquityAgg,
|
|
233
|
+
event_type=EventType.EquityAgg.value,
|
|
234
|
+
symbol="TEST",
|
|
235
|
+
volume=100,
|
|
236
|
+
accumulated_volume=1000,
|
|
237
|
+
official_open_price=10.00,
|
|
238
|
+
vwap=10.25,
|
|
239
|
+
open=10.26,
|
|
240
|
+
close=10.27,
|
|
241
|
+
high=10.28,
|
|
242
|
+
low=10.29,
|
|
243
|
+
aggregate_vwap=10.30,
|
|
244
|
+
average_size=10.31,
|
|
245
|
+
start_timestamp=1234567890,
|
|
246
|
+
end_timestamp=1234567891,
|
|
247
|
+
otc=True,
|
|
248
|
+
)
|
|
249
|
+
serialized_message = WebSocketMessageSerde.serialize(message)
|
|
250
|
+
expected_message = {
|
|
251
|
+
"event_type": EventType.EquityAgg.value,
|
|
252
|
+
"symbol": "TEST",
|
|
253
|
+
"volume": 100,
|
|
254
|
+
"accumulated_volume": 1000,
|
|
255
|
+
"official_open_price": 10.00,
|
|
256
|
+
"vwap": 10.25,
|
|
257
|
+
"open": 10.26,
|
|
258
|
+
"close": 10.27,
|
|
259
|
+
"high": 10.28,
|
|
260
|
+
"low": 10.29,
|
|
261
|
+
"aggregate_vwap": 10.30,
|
|
262
|
+
"average_size": 10.31,
|
|
263
|
+
"start_timestamp": 1234567890,
|
|
264
|
+
"end_timestamp": 1234567891,
|
|
265
|
+
"otc": True,
|
|
266
|
+
}
|
|
267
|
+
self.assertEqual(expected_message, json.loads(serialized_message))
|
|
268
|
+
|
|
269
|
+
def test_to_dict_with_equity_agg_happy_path(self):
|
|
270
|
+
"""Test conversion to a Python dictionary for EquityAgg."""
|
|
271
|
+
message = MagicMock(
|
|
272
|
+
spec=EquityAgg,
|
|
273
|
+
event_type=EventType.EquityAgg.value,
|
|
274
|
+
symbol="TEST",
|
|
275
|
+
volume=100,
|
|
276
|
+
accumulated_volume=1000,
|
|
277
|
+
official_open_price=10.00,
|
|
278
|
+
vwap=10.25,
|
|
279
|
+
open=10.26,
|
|
280
|
+
close=10.27,
|
|
281
|
+
high=10.28,
|
|
282
|
+
low=10.29,
|
|
283
|
+
aggregate_vwap=10.30,
|
|
284
|
+
average_size=10.31,
|
|
285
|
+
start_timestamp=1234567890,
|
|
286
|
+
end_timestamp=1234567891,
|
|
287
|
+
otc=True,
|
|
288
|
+
)
|
|
289
|
+
expected_dict = {
|
|
290
|
+
"event_type": EventType.EquityAgg.value,
|
|
291
|
+
"symbol": "TEST",
|
|
292
|
+
"volume": 100,
|
|
293
|
+
"accumulated_volume": 1000,
|
|
294
|
+
"official_open_price": 10.00,
|
|
295
|
+
"vwap": 10.25,
|
|
296
|
+
"open": 10.26,
|
|
297
|
+
"close": 10.27,
|
|
298
|
+
"high": 10.28,
|
|
299
|
+
"low": 10.29,
|
|
300
|
+
"aggregate_vwap": 10.30,
|
|
301
|
+
"average_size": 10.31,
|
|
302
|
+
"start_timestamp": 1234567890,
|
|
303
|
+
"end_timestamp": 1234567891,
|
|
304
|
+
"otc": True,
|
|
305
|
+
}
|
|
306
|
+
self.assertEqual(expected_dict, WebSocketMessageSerde.to_dict(message))
|
|
307
|
+
|
|
308
|
+
def test_deserialize_with_equity_agg_happy_path(self):
|
|
309
|
+
"""Test deserialization for EquityAgg."""
|
|
310
|
+
serialized_message = json.dumps({
|
|
311
|
+
"event_type": EventType.EquityAgg.value,
|
|
312
|
+
"symbol": "TEST",
|
|
313
|
+
"volume": 100,
|
|
314
|
+
"accumulated_volume": 1000,
|
|
315
|
+
"official_open_price": 10.00,
|
|
316
|
+
"vwap": 10.25,
|
|
317
|
+
"open": 10.26,
|
|
318
|
+
"close": 10.27,
|
|
319
|
+
"high": 10.28,
|
|
320
|
+
"low": 10.29,
|
|
321
|
+
"aggregate_vwap": 10.30,
|
|
322
|
+
"average_size": 10.31,
|
|
323
|
+
"start_timestamp": 1234567890,
|
|
324
|
+
"end_timestamp": 1234567891,
|
|
325
|
+
"otc": True,
|
|
326
|
+
})
|
|
327
|
+
deserialized_message = WebSocketMessageSerde.deserialize(serialized_message)
|
|
328
|
+
self.assertIsInstance(deserialized_message, EquityAgg)
|
|
329
|
+
self.assertEqual(deserialized_message.event_type, EventType.EquityAgg.value)
|
|
330
|
+
self.assertEqual(deserialized_message.symbol, "TEST")
|
|
331
|
+
self.assertEqual(deserialized_message.volume, 100)
|
|
332
|
+
self.assertEqual(deserialized_message.accumulated_volume, 1000)
|
|
333
|
+
self.assertEqual(deserialized_message.official_open_price, 10.00)
|
|
334
|
+
self.assertEqual(deserialized_message.vwap, 10.25)
|
|
335
|
+
self.assertEqual(deserialized_message.open, 10.26)
|
|
336
|
+
self.assertEqual(deserialized_message.close, 10.27)
|
|
337
|
+
self.assertEqual(deserialized_message.high, 10.28)
|
|
338
|
+
self.assertEqual(deserialized_message.low, 10.29)
|
|
339
|
+
self.assertEqual(deserialized_message.aggregate_vwap, 10.30)
|
|
340
|
+
self.assertEqual(deserialized_message.average_size, 10.31)
|
|
341
|
+
self.assertEqual(deserialized_message.start_timestamp, 1234567890)
|
|
342
|
+
self.assertEqual(deserialized_message.end_timestamp, 1234567891)
|
|
343
|
+
self.assertEqual(deserialized_message.otc, True)
|
|
344
|
+
|
|
345
|
+
# LULD
|
|
346
|
+
def test_serialize_with_limit_up_limit_down_happy_path(self):
|
|
347
|
+
"""Test serialization of LimitUpLimitDown messages."""
|
|
348
|
+
message = MagicMock(
|
|
349
|
+
spec=LimitUpLimitDown,
|
|
350
|
+
event_type=EventType.LimitUpLimitDown.value,
|
|
351
|
+
symbol="TEST",
|
|
352
|
+
high_price=100.0,
|
|
353
|
+
low_price=90.0,
|
|
354
|
+
indicators=["I1"],
|
|
355
|
+
tape="T",
|
|
356
|
+
timestamp=1234567890,
|
|
357
|
+
sequence_number=1,
|
|
358
|
+
)
|
|
359
|
+
serialized_message = WebSocketMessageSerde.serialize(message)
|
|
360
|
+
expected_message = {
|
|
361
|
+
"event_type": EventType.LimitUpLimitDown.value,
|
|
362
|
+
"symbol": "TEST",
|
|
363
|
+
"high_price": 100.0,
|
|
364
|
+
"low_price": 90.0,
|
|
365
|
+
"indicators": ["I1"],
|
|
366
|
+
"tape": "T",
|
|
367
|
+
"timestamp": 1234567890,
|
|
368
|
+
"sequence_number": 1,
|
|
369
|
+
}
|
|
370
|
+
self.assertEqual(expected_message, json.loads(serialized_message))
|
|
371
|
+
|
|
372
|
+
def test_to_dict_with_limit_up_limit_down_happy_path(self):
|
|
373
|
+
"""Test conversion to a Python dictionary for LimitUpLimitDown messages."""
|
|
374
|
+
message = MagicMock(
|
|
375
|
+
spec=LimitUpLimitDown,
|
|
376
|
+
event_type=EventType.LimitUpLimitDown.value,
|
|
377
|
+
symbol="TEST",
|
|
378
|
+
high_price=100.0,
|
|
379
|
+
low_price=90.0,
|
|
380
|
+
indicators=["I1"],
|
|
381
|
+
tape="T",
|
|
382
|
+
timestamp=1234567890,
|
|
383
|
+
sequence_number=1,
|
|
384
|
+
)
|
|
385
|
+
expected_dict = {
|
|
386
|
+
"event_type": EventType.LimitUpLimitDown.value,
|
|
387
|
+
"symbol": "TEST",
|
|
388
|
+
"high_price": 100.0,
|
|
389
|
+
"low_price": 90.0,
|
|
390
|
+
"indicators": ["I1"],
|
|
391
|
+
"tape": "T",
|
|
392
|
+
"timestamp": 1234567890,
|
|
393
|
+
"sequence_number": 1,
|
|
394
|
+
}
|
|
395
|
+
self.assertEqual(expected_dict, WebSocketMessageSerde.to_dict(message))
|
|
396
|
+
|
|
397
|
+
def test_deserialize_with_limit_up_limit_down_happy_path(self):
|
|
398
|
+
"""Test deserialization of a LimitUpLimitDown message."""
|
|
399
|
+
serialized_message = json.dumps(
|
|
400
|
+
{
|
|
401
|
+
"event_type": EventType.LimitUpLimitDown.value,
|
|
402
|
+
"symbol": "TEST",
|
|
403
|
+
"high_price": 200.0,
|
|
404
|
+
"low_price": 150.0,
|
|
405
|
+
"indicators": ["I1"],
|
|
406
|
+
"tape": "T1",
|
|
407
|
+
"timestamp": 1234567893,
|
|
408
|
+
"sequence_number": 3,
|
|
409
|
+
}
|
|
410
|
+
)
|
|
411
|
+
deserialized_message = WebSocketMessageSerde.deserialize(serialized_message)
|
|
412
|
+
self.assertIsInstance(deserialized_message, LimitUpLimitDown)
|
|
413
|
+
self.assertEqual(deserialized_message.event_type, EventType.LimitUpLimitDown.value)
|
|
414
|
+
self.assertEqual(deserialized_message.symbol, "TEST")
|
|
415
|
+
self.assertEqual(deserialized_message.high_price, 200.0)
|
|
416
|
+
self.assertEqual(deserialized_message.low_price, 150.0)
|
|
417
|
+
|
|
418
|
+
# Unsupported message types
|
|
419
|
+
def test_deserialize_with_unsupported_message_type_expect_exception(self):
|
|
420
|
+
"""Test deserialization raises an error for unsupported message types."""
|
|
421
|
+
event_type = "UnsupportedEventType"
|
|
422
|
+
serialized_message = json.dumps({"event_type": event_type})
|
|
423
|
+
with self.assertRaises(ArgumentTypeError) as e:
|
|
424
|
+
WebSocketMessageSerde.deserialize(serialized_message)
|
|
425
|
+
|
|
426
|
+
assert e.exception.args[0] == f"Unsupported message type: {event_type}"
|
|
427
|
+
|
|
428
|
+
def test_to_dict_with_unsupported_message_type_expect_dict(self):
|
|
429
|
+
"""Test conversion to a Python dictionary for unsupported message types."""
|
|
430
|
+
event_type = "UnsupportedEventType"
|
|
431
|
+
message = json.loads(json.dumps({"event_type": event_type}))
|
|
432
|
+
expected_dict = {"event_type": event_type}
|
|
433
|
+
self.assertEqual(expected_dict, WebSocketMessageSerde.to_dict(message))
|
|
434
|
+
|
|
435
|
+
def test_serialize_with_unsupported_message_type_expect_string(self):
|
|
436
|
+
"""Test serialization for unsupported message types."""
|
|
437
|
+
event_type = "UnsupportedEventType"
|
|
438
|
+
message = json.loads(json.dumps({"event_type": event_type}))
|
|
439
|
+
expected_string = '{"event_type": "UnsupportedEventType"}'
|
|
440
|
+
self.assertEqual(expected_string, WebSocketMessageSerde.serialize(message))
|
kuhl_haus_mdp-0.1.0/PKG-INFO
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: kuhl-haus-mdp
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Market data processing pipeline for stock market scanner
|
|
5
|
-
Author-Email: Tom Pounders <git@oldschool.engineer>
|
|
6
|
-
License: The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2025 Tom Pounders
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in all
|
|
18
|
-
copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
-
SOFTWARE.
|
|
27
|
-
|
|
28
|
-
Classifier: Development Status :: 4 - Beta
|
|
29
|
-
Classifier: Programming Language :: Python
|
|
30
|
-
Project-URL: Homepage, https://github.com/kuhl-haus/kuhl-haus-mdp
|
|
31
|
-
Project-URL: Documentation, https://github.com/kuhl-haus/kuhl-haus-mdp/wiki
|
|
32
|
-
Project-URL: Source, https://github.com/kuhl-haus/kuhl-haus-mdp.git
|
|
33
|
-
Project-URL: Changelog, https://github.com/kuhl-haus/kuhl-haus-mdp/commits
|
|
34
|
-
Project-URL: Tracker, https://github.com/kuhl-haus/kuhl-haus-mdp/issues
|
|
35
|
-
Requires-Python: <3.13,>=3.9.21
|
|
36
|
-
Requires-Dist: websockets
|
|
37
|
-
Requires-Dist: aio-pika
|
|
38
|
-
Requires-Dist: redis[asyncio]
|
|
39
|
-
Requires-Dist: tenacity
|
|
40
|
-
Requires-Dist: fastapi
|
|
41
|
-
Requires-Dist: uvicorn[standard]
|
|
42
|
-
Requires-Dist: pydantic-settings
|
|
43
|
-
Requires-Dist: python-dotenv
|
|
44
|
-
Requires-Dist: massive
|
|
45
|
-
Provides-Extra: testing
|
|
46
|
-
Requires-Dist: setuptools; extra == "testing"
|
|
47
|
-
Requires-Dist: pdm-backend; extra == "testing"
|
|
48
|
-
Requires-Dist: pytest; extra == "testing"
|
|
49
|
-
Requires-Dist: pytest-cov; extra == "testing"
|
|
50
|
-
Description-Content-Type: text/markdown
|
|
51
|
-
|
|
52
|
-
<!-- These are examples of badges you might want to add to your README:
|
|
53
|
-
please update the URLs accordingly
|
|
54
|
-
|
|
55
|
-
[](https://kuhl-haus-mdp.readthedocs.io/en/stable/)
|
|
56
|
-
[](https://anaconda.org/conda-forge/kuhl-haus-mdp)
|
|
57
|
-
[](https://pepy.tech/project/kuhl-haus-mdp)
|
|
58
|
-
-->
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/blob/mainline/LICENSE.txt)
|
|
62
|
-
[](https://pypi.org/project/kuhl-haus-mdp/)
|
|
63
|
-
[](https://pepy.tech/project/kuhl-haus-mdp)
|
|
64
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/publish-to-pypi.yml)
|
|
65
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/codeql.yml)
|
|
66
|
-
[](https://codecov.io/gh/kuhl-haus/kuhl-haus-mdp)
|
|
67
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/issues)
|
|
68
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/pulls)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# kuhl-haus-mdp
|
|
72
|
-
|
|
73
|
-
Market data processing pipeline for stock market scanner.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
## Note
|
|
77
|
-
|
|
78
|
-
This project has been set up using PyScaffold 4.6. For details and usage
|
|
79
|
-
information on PyScaffold see https://pyscaffold.org/.
|
kuhl_haus_mdp-0.1.0/README.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
<!-- These are examples of badges you might want to add to your README:
|
|
2
|
-
please update the URLs accordingly
|
|
3
|
-
|
|
4
|
-
[](https://kuhl-haus-mdp.readthedocs.io/en/stable/)
|
|
5
|
-
[](https://anaconda.org/conda-forge/kuhl-haus-mdp)
|
|
6
|
-
[](https://pepy.tech/project/kuhl-haus-mdp)
|
|
7
|
-
-->
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/blob/mainline/LICENSE.txt)
|
|
11
|
-
[](https://pypi.org/project/kuhl-haus-mdp/)
|
|
12
|
-
[](https://pepy.tech/project/kuhl-haus-mdp)
|
|
13
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/publish-to-pypi.yml)
|
|
14
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/codeql.yml)
|
|
15
|
-
[](https://codecov.io/gh/kuhl-haus/kuhl-haus-mdp)
|
|
16
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/issues)
|
|
17
|
-
[](https://github.com/kuhl-haus/kuhl-haus-mdp/pulls)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# kuhl-haus-mdp
|
|
21
|
-
|
|
22
|
-
Market data processing pipeline for stock market scanner.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
## Note
|
|
26
|
-
|
|
27
|
-
This project has been set up using PyScaffold 4.6. For details and usage
|
|
28
|
-
information on PyScaffold see https://pyscaffold.org/.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/analyzers/massive_data_analyzer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/components/market_data_cache.py
RENAMED
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/components/market_data_scanner.py
RENAMED
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/components/widget_data_service.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/helpers/queue_name_resolver.py
RENAMED
|
File without changes
|
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/integ/massive_data_listener.py
RENAMED
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/integ/massive_data_processor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/market_data_analyzer_result.py
RENAMED
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/market_data_cache_keys.py
RENAMED
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/market_data_pubsub_keys.py
RENAMED
|
File without changes
|
{kuhl_haus_mdp-0.1.0 → kuhl_haus_mdp-0.1.1}/src/kuhl_haus/mdp/models/market_data_scanner_names.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|