kuhl-haus-mdp 0.0.1__py3-none-any.whl → 0.1.1__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.
@@ -10,16 +10,26 @@ logger = logging.getLogger(__name__)
10
10
 
11
11
 
12
12
  def get_massive_api_key():
13
+ # MASSIVE_API_KEY environment variable takes precedence over POLYGON_API_KEY
13
14
  logger.info("Getting Massive API key...")
14
15
  api_key = os.environ.get("MASSIVE_API_KEY")
16
+
17
+ # If MASSIVE_API_KEY is not set, try POLYGON_API_KEY
15
18
  if not api_key:
16
- logger.info("MASSIVE_API_KEY environment variable not set; trying Massive API key...")
19
+ logger.info("MASSIVE_API_KEY environment variable not set; trying POLYGON_API_KEY...")
17
20
  api_key = os.environ.get("POLYGON_API_KEY")
21
+
22
+ # If POLYGON_API_KEY is not set, try reading from file
18
23
  if not api_key:
19
24
  logger.info("POLYGON_API_KEY environment variable not set; trying Massive API key file...")
20
- api_key_path = '/app/polygon_api_key.txt'
21
- with open(api_key_path, 'r') as f:
22
- api_key = f.read().strip()
25
+ api_key_path = '/app/massive_api_key.txt'
26
+ try:
27
+ with open(api_key_path, 'r') as f:
28
+ api_key = f.read().strip()
29
+ except FileNotFoundError:
30
+ logger.info(f"No Massive API key file found at {api_key_path}")
31
+
32
+ # Raise error if neither POLYGON_API_KEY nor MASSIVE_API_KEY are set
23
33
  if not api_key:
24
34
  logger.error("No Massive API key found")
25
35
  raise ValueError("MASSIVE_API_KEY environment variable not set")
@@ -59,8 +59,8 @@ class WebSocketMessageSerde:
59
59
  ret: dict = {
60
60
  "event_type": message.event_type,
61
61
  "symbol": message.symbol,
62
- "high": message.high_price,
63
- "low": message.low_price,
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,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
+ [![ReadTheDocs](https://readthedocs.org/projects/kuhl-haus-mdp/badge/?version=latest)](https://kuhl-haus-mdp.readthedocs.io/en/stable/)
56
+ [![Conda-Forge](https://img.shields.io/conda/vn/conda-forge/kuhl-haus-mdp.svg)](https://anaconda.org/conda-forge/kuhl-haus-mdp)
57
+ [![Monthly Downloads](https://pepy.tech/badge/kuhl-haus-mdp/month)](https://pepy.tech/project/kuhl-haus-mdp)
58
+ -->
59
+
60
+
61
+ [![License](https://img.shields.io/github/license/kuhl-haus/kuhl-haus-mdp)](https://github.com/kuhl-haus/kuhl-haus-mdp/blob/mainline/LICENSE.txt)
62
+ [![PyPI](https://img.shields.io/pypi/v/kuhl-haus-mdp.svg)](https://pypi.org/project/kuhl-haus-mdp/)
63
+ [![Downloads](https://static.pepy.tech/badge/kuhl-haus-mdp/month)](https://pepy.tech/project/kuhl-haus-mdp)
64
+ [![Build Status](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/publish-to-pypi.yml)
65
+ [![CodeQL Advanced](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/codeql.yml/badge.svg)](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/codeql.yml)
66
+ [![codecov](https://codecov.io/gh/kuhl-haus/kuhl-haus-mdp/branch/mainline/graph/badge.svg)](https://codecov.io/gh/kuhl-haus/kuhl-haus-mdp)
67
+ [![GitHub issues](https://img.shields.io/github/issues/kuhl-haus/kuhl-haus-mdp)](https://github.com/kuhl-haus/kuhl-haus-mdp/issues)
68
+ [![GitHub pull requests](https://img.shields.io/github/issues-pr/kuhl-haus/kuhl-haus-mdp)](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
+ [![Market Data Processing C4-V1.drawio.png](docs/Market_Data_Processing_C4.png)]
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
+
@@ -14,16 +14,16 @@ kuhl_haus/mdp/integ/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
14
14
  kuhl_haus/mdp/integ/massive_data_listener.py,sha256=fPEYc6zZzHzFFjbP3zFInajKtEGInj8UQKKo3nKQEwQ,5098
15
15
  kuhl_haus/mdp/integ/massive_data_processor.py,sha256=9I0tH9sZNs9Y0TyKIBKix_qlEksEZt5NRfP-Zf3FovE,8708
16
16
  kuhl_haus/mdp/integ/massive_data_queues.py,sha256=zC_uV2vwZCMyVerDQ18RAQwIMMF75iK4qUSqwuWqgwc,5050
17
- kuhl_haus/mdp/integ/utils.py,sha256=4YVJQjfiygM_yXWPuwmNMDuKBQ_ZynSFy5cIO09AKTM,905
18
- kuhl_haus/mdp/integ/web_socket_message_serde.py,sha256=jPXMVO-4RaZ8yrnqfgckeHEv_96_9yXj_keMq42NqJY,5456
17
+ kuhl_haus/mdp/integ/utils.py,sha256=9JEpl2yr2LghOLrJUDxi-4dtDK3DZ1wBTZ1uxBJsFbQ,1309
18
+ kuhl_haus/mdp/integ/web_socket_message_serde.py,sha256=XdaoaByc7IhtzbPDXBtXKOTjyDzfPSDuZVCoHSIaTl4,5468
19
19
  kuhl_haus/mdp/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  kuhl_haus/mdp/models/market_data_analyzer_result.py,sha256=iICb5GVCtuqARNbR1JNCAfbxMijM3uppDNdL8_FB3eI,422
21
21
  kuhl_haus/mdp/models/market_data_cache_keys.py,sha256=5iScBMhVQaG3p9P45veE-uRT7c6JY7k6j4DcvSEXENA,942
22
22
  kuhl_haus/mdp/models/market_data_pubsub_keys.py,sha256=PEIPXK9jBehJB7G4pqoSuQZcfMZgOQq8Yho1itqv-1A,1306
23
23
  kuhl_haus/mdp/models/market_data_scanner_names.py,sha256=BYn1C0rYgGF1Sq583BkHADKUu-28ytNZQ-XgptuCH-Y,260
24
24
  kuhl_haus/mdp/models/massive_data_queue.py,sha256=MfYBcjVc4Fi61DWIvvhhWLUOiLmRpE9egtW-2KH6FTE,188
25
- kuhl_haus_mdp-0.0.1.dist-info/METADATA,sha256=lGEPOXMMCCEbQsffzCI92WbeQ4QwiPL6LkiZrL69TX0,4258
26
- kuhl_haus_mdp-0.0.1.dist-info/WHEEL,sha256=tsUv_t7BDeJeRHaSrczbGeuK-TtDpGsWi_JfpzD255I,90
27
- kuhl_haus_mdp-0.0.1.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
28
- kuhl_haus_mdp-0.0.1.dist-info/licenses/LICENSE.txt,sha256=DRkJftAJcMqoTkQ_Y6-HtKj3nm4pZah_p8XBZiYnw-c,1079
29
- kuhl_haus_mdp-0.0.1.dist-info/RECORD,,
25
+ kuhl_haus_mdp-0.1.1.dist-info/METADATA,sha256=Pwfg52rEA4A6MQdJtiUdF4BgL-U2NjSFPDCAYJYdaYE,8688
26
+ kuhl_haus_mdp-0.1.1.dist-info/WHEEL,sha256=tsUv_t7BDeJeRHaSrczbGeuK-TtDpGsWi_JfpzD255I,90
27
+ kuhl_haus_mdp-0.1.1.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
28
+ kuhl_haus_mdp-0.1.1.dist-info/licenses/LICENSE.txt,sha256=DRkJftAJcMqoTkQ_Y6-HtKj3nm4pZah_p8XBZiYnw-c,1079
29
+ kuhl_haus_mdp-0.1.1.dist-info/RECORD,,
@@ -1,79 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: kuhl-haus-mdp
3
- Version: 0.0.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
- [![ReadTheDocs](https://readthedocs.org/projects/kuhl-haus-mdp/badge/?version=latest)](https://kuhl-haus-mdp.readthedocs.io/en/stable/)
56
- [![Conda-Forge](https://img.shields.io/conda/vn/conda-forge/kuhl-haus-mdp.svg)](https://anaconda.org/conda-forge/kuhl-haus-mdp)
57
- [![Monthly Downloads](https://pepy.tech/badge/kuhl-haus-mdp/month)](https://pepy.tech/project/kuhl-haus-mdp)
58
- -->
59
-
60
-
61
- [![License](https://img.shields.io/github/license/kuhl-haus/kuhl-haus-mdp)](https://github.com/kuhl-haus/kuhl-haus-mdp/blob/mainline/LICENSE.txt)
62
- [![PyPI](https://img.shields.io/pypi/v/kuhl-haus-mdp.svg)](https://pypi.org/project/kuhl-haus-mdp/)
63
- [![Downloads](https://static.pepy.tech/badge/kuhl-haus-mdp/month)](https://pepy.tech/project/kuhl-haus-mdp)
64
- [![Build Status](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/publish-to-pypi.yml)
65
- [![CodeQL](https://github.com/kuhl-haus/kuhl-haus-mdp/workflows/CodeQL/badge.svg)](https://github.com/kuhl-haus/kuhl-haus-mdp/actions/workflows/github-code-scanning/codeql/)
66
- [![codecov](https://codecov.io/gh/kuhl-haus/kuhl-haus-mdp/branch/mainline/graph/badge.svg)](https://codecov.io/gh/kuhl-haus/kuhl-haus-mdp)
67
- [![GitHub issues](https://img.shields.io/github/issues/kuhl-haus/kuhl-haus-mdp)](https://github.com/kuhl-haus/kuhl-haus-mdp/issues)
68
- [![GitHub pull requests](https://img.shields.io/github/issues-pr/kuhl-haus/kuhl-haus-mdp)](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/.