market-data-normalizer 1.3.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.
@@ -0,0 +1,330 @@
1
+ Metadata-Version: 2.4
2
+ Name: market-data-normalizer
3
+ Version: 1.3.1
4
+ Summary: Normalize heterogeneous market-data feeds (CSV, WebSocket JSON, FIX) into one exchange-agnostic schema.
5
+ Project-URL: Homepage, https://harvestgroup360.com
6
+ Project-URL: Repository, https://github.com/Harvestgroup360/market-data-normalizer
7
+ Project-URL: Changelog, https://github.com/Harvestgroup360/market-data-normalizer/blob/main/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/Harvestgroup360/market-data-normalizer/issues
9
+ Author-email: HarvestGroup360 <github@harvestgroup360.com>
10
+ License: MIT License
11
+
12
+ Copyright (c) 2026 HarvestGroup360 (AMII LTD)
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Keywords: fix-protocol,market-data,normalization,quantitative-finance,tick-data,trading
33
+ Classifier: Development Status :: 5 - Production/Stable
34
+ Classifier: Intended Audience :: Financial and Insurance Industry
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Operating System :: OS Independent
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
41
+ Classifier: Programming Language :: Python :: 3.13
42
+ Classifier: Topic :: Office/Business :: Financial :: Investment
43
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
44
+ Classifier: Typing :: Typed
45
+ Requires-Python: >=3.10
46
+ Provides-Extra: dev
47
+ Requires-Dist: pytest>=7; extra == 'dev'
48
+ Description-Content-Type: text/markdown
49
+
50
+ # market-data-normalizer (`mdnorm`)
51
+
52
+ [![CI](https://github.com/Harvestgroup360/market-data-normalizer/actions/workflows/ci.yml/badge.svg)](https://github.com/Harvestgroup360/market-data-normalizer/actions/workflows/ci.yml)
53
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
54
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](pyproject.toml)
55
+ [![PyPI](https://img.shields.io/pypi/v/market-data-normalizer.svg)](https://pypi.org/project/market-data-normalizer/)
56
+
57
+ Normalize heterogeneous market-data feeds — CSV tick dumps, exchange
58
+ WebSocket JSON, and FIX — into a single, exchange-agnostic event schema, so
59
+ downstream research and execution code never has to care where a tick came
60
+ from.
61
+
62
+ Zero runtime dependencies. Pure Python (3.10+). `Decimal` prices, integer
63
+ nanosecond timestamps.
64
+
65
+ ## Why
66
+
67
+ Every venue spells the same thing differently: `BTCUSDT` vs `XBT/USD`,
68
+ millisecond epochs vs FIX `UTCTimestamp`, `is_buyer_maker` booleans vs side
69
+ codes. Research notebooks and backtesters end up littered with per-venue
70
+ parsing branches. `mdnorm` pushes that mess to the edge and hands the rest of
71
+ your stack one clean type.
72
+
73
+ ## Install
74
+
75
+ ```console
76
+ pip install market-data-normalizer
77
+ ```
78
+
79
+ The distribution is named `market-data-normalizer`; the import name is
80
+ `mdnorm`:
81
+
82
+ ```python
83
+ import mdnorm
84
+ ```
85
+
86
+ Pure Python, no runtime dependencies, Python 3.10+.
87
+
88
+ ## Quick start
89
+
90
+ ```python
91
+ from mdnorm import from_csv_row, from_ws_json, from_fix
92
+
93
+ # CSV row (ISO-8601 timestamp)
94
+ from_csv_row(
95
+ {"symbol": "btc/usd", "ts": "2026-01-02T00:00:00Z",
96
+ "price": "42000.5", "size": "0.25", "side": "buy"},
97
+ venue="coinbase",
98
+ )
99
+
100
+ # Exchange WebSocket trade message
101
+ from_ws_json({"s": "BTCUSDT", "p": "42000.5", "q": "0.25",
102
+ "T": 1767312000000, "m": False}, venue="binance")
103
+
104
+ # FIX execution report (SOH-delimited in the wild; "|" here for readability)
105
+ from_fix("55=BTC/USD|31=42000.5|32=0.25|54=1|60=20260102-00:00:00",
106
+ venue="lmax", sep="|")
107
+ ```
108
+
109
+ All three calls above produce the **same** `MarketEvent`.
110
+
111
+ ### Quotes (bid/ask)
112
+
113
+ ```python
114
+ from mdnorm import from_ws_quote
115
+
116
+ q = from_ws_quote(
117
+ {"s": "BTCUSDT", "b": "41999.5", "B": "1.2",
118
+ "a": "42000.5", "A": "0.8", "T": 1767312000000},
119
+ venue="binance",
120
+ )
121
+ q.mid_price # Decimal("42000.0")
122
+ q.spread # Decimal("1.0")
123
+ ```
124
+
125
+ `from_csv_quote` does the same for CSV rows with bid/ask columns.
126
+
127
+ ### OHLCV bars
128
+
129
+ ```python
130
+ from mdnorm import time_bars
131
+
132
+ bars = time_bars(events, interval_ns=60_000_000_000) # 1-minute bars
133
+ bars[0].open, bars[0].high, bars[0].low, bars[0].close, bars[0].volume, bars[0].vwap
134
+ ```
135
+
136
+ `time_bars` reduces a stream of trade events into fixed-interval OHLCV `Bar`s
137
+ (with VWAP and trade count), sorting out-of-order input and skipping quotes.
138
+
139
+ `resample_bars(bars, interval_ns)` downsamples bars to a coarser interval
140
+ (e.g. 1-minute → 5-minute) with correct OHLC aggregation and volume-weighted
141
+ VWAP.
142
+
143
+ `fill_gaps(bars)` returns a gapless series, inserting flat zero-volume bars
144
+ (OHLC = previous close) for any interval with no trades — a continuous grid for
145
+ backtests and feature pipelines.
146
+
147
+ ### Event-driven bars
148
+
149
+ Time bars are not the only clock. Sample by activity instead:
150
+
151
+ ```python
152
+ from decimal import Decimal
153
+ from mdnorm import count_bars, volume_bars, dollar_bars
154
+
155
+ count_bars(events, every=500) # tick bars
156
+ volume_bars(events, min_volume=Decimal("100")) # volume bars
157
+ dollar_bars(events, min_notional=Decimal("1e6")) # dollar bars
158
+ ```
159
+
160
+ ### Trading sessions
161
+
162
+ Filter a feed down to the hours that matter, with daylight saving handled
163
+ for you:
164
+
165
+ ```python
166
+ from mdnorm import US_EQUITY_RTH, filter_session, group_by_session_date
167
+
168
+ rth = filter_session(events, US_EQUITY_RTH) # 09:30-16:00 New York
169
+ by_day = group_by_session_date(events, US_EQUITY_RTH)
170
+ ```
171
+
172
+ Overnight windows (a session that opens at 18:00 and closes at 17:00 the
173
+ next day) are supported, and `session_date` keeps a whole night in one
174
+ bucket. From the command line:
175
+
176
+ ```console
177
+ $ mdnorm bars trades.csv --interval 5m --session 09:30-16:00 --tz America/New_York -o rth.csv
178
+ ```
179
+
180
+ ### Data quality
181
+
182
+ ```python
183
+ from mdnorm.quality import find_issues, clean
184
+
185
+ find_issues(events) # list of QualityIssue (outlier / gap / out_of_order / non_positive)
186
+ cleaned, issues = clean(events) # drop bad ticks & invalid rows, keep a report
187
+ ```
188
+
189
+ `clean` removes price outliers and non-positive price/size records and returns
190
+ the surviving events plus everything it flagged.
191
+
192
+ ### Serialization
193
+
194
+ ```python
195
+ from mdnorm import to_records
196
+
197
+ to_records(events) # list of flat dicts (Decimals as strings)
198
+ to_records(bars, as_float=True) # numeric output for DataFrames
199
+ ```
200
+
201
+ `to_records` (and `event_to_dict` / `bar_to_dict`) flatten events and bars into
202
+ plain, JSON-serialisable dicts — drop straight into `pandas.DataFrame`, a
203
+ `csv.DictWriter`, or `json.dumps`.
204
+
205
+ ### Consolidating streams
206
+
207
+ ```python
208
+ from mdnorm import merge_streams, dedupe
209
+
210
+ timeline = dedupe(merge_streams(binance_events, coinbase_events))
211
+ ```
212
+
213
+ `merge_streams` interleaves multiple venue feeds into one timestamp-ordered
214
+ timeline; `dedupe` drops exact duplicate events left behind by reconnects and
215
+ replays.
216
+
217
+ ### CSV files
218
+
219
+ ```python
220
+ from mdnorm import read_csv_trades, write_records_csv
221
+
222
+ events = read_csv_trades("trades.csv", venue="coinbase") # file -> events
223
+ write_records_csv(bars, "bars.csv", as_float=True) # events/bars -> file
224
+ ```
225
+
226
+ `read_csv_trades` parses a whole CSV of trades into normalized events;
227
+ `write_records_csv` writes events or bars back out. Standard library only.
228
+
229
+ ### NDJSON / JSON Lines
230
+
231
+ ```python
232
+ from mdnorm import write_jsonl, read_jsonl_events
233
+
234
+ write_jsonl(events, "events.jsonl") # one JSON object per line
235
+ events2 = read_jsonl_events("events.jsonl") # lossless round-trip
236
+
237
+ # large files: stream lazily, .gz handled transparently
238
+ for e in iter_jsonl_events("dump.jsonl.gz"):
239
+ ...
240
+ ```
241
+
242
+ ### Pipelines
243
+
244
+ Declare a processing chain once, reuse it everywhere:
245
+
246
+ ```python
247
+ from decimal import Decimal
248
+ from mdnorm import Pipeline
249
+
250
+ pipe = (
251
+ Pipeline()
252
+ .dedupe()
253
+ .clean(max_return=Decimal("0.1"))
254
+ .time_bars(60_000_000_000) # 1-minute bars
255
+ .fill_gaps()
256
+ )
257
+ bars = pipe.run(events)
258
+ print(pipe.last_issues) # quality report from clean()
259
+ ```
260
+
261
+ ### Command line
262
+
263
+ The common conversions ship as a zero-dependency CLI:
264
+
265
+ ```console
266
+ $ mdnorm bars trades.csv --venue binance --interval 1m -o bars.csv
267
+ $ mdnorm quality trades.csv --max-gap 5m
268
+ $ mdnorm convert trades.csv -o trades.jsonl
269
+ ```
270
+
271
+ Also available as `python -m mdnorm`.
272
+
273
+ ## The unified schema
274
+
275
+ ```python
276
+ @dataclass(frozen=True, slots=True)
277
+ class MarketEvent:
278
+ symbol: str # canonical "BASE-QUOTE", e.g. "BTC-USD"
279
+ venue: str # source venue
280
+ event_type: EventType # TRADE | QUOTE
281
+ ts_ns: int # nanoseconds since Unix epoch (UTC)
282
+ price: Decimal | None
283
+ size: Decimal | None
284
+ side: Side | None # BUY | SELL
285
+ # ... plus bid/ask fields for quotes
286
+ ```
287
+
288
+ ## Design notes
289
+
290
+ - **Money is `Decimal`.** Prices and sizes never touch binary floats, so
291
+ `42000.10` stays `42000.10`.
292
+ - **Time is integer nanoseconds, UTC.** One comparable integer regardless of
293
+ whether the source gave seconds, milliseconds, or a FIX timestamp string.
294
+ - **Symbols are canonicalized** to `BASE-QUOTE`, with venue aliases resolved
295
+ (`XBT` → `BTC`) and quote currencies detected longest-match-first so
296
+ `USDT` wins over `USD`.
297
+ - **Normalizers are pure functions** — one raw record in, one `MarketEvent`
298
+ out — which keeps them trivial to unit-test and compose into any streaming
299
+ or batch pipeline.
300
+
301
+ ## Architecture
302
+
303
+ ```
304
+ raw feed ──► normalizer ─────────────► MarketEvent ──► your pipeline
305
+ (CSV / (from_csv_row / (unified, (research,
306
+ WS JSON / from_ws_json / immutable) backtest,
307
+ FIX) from_fix) execution)
308
+ │
309
+ ├── symbols.canonical_symbol() BTCUSDT → BTC-USDT
310
+ └── timeutil.*_to_ns() any time → ns UTC
311
+ ```
312
+
313
+ ## Tests
314
+
315
+ ```bash
316
+ pip install pytest
317
+ pytest -q
318
+ ```
319
+
320
+ The suite includes a cross-venue equivalence test proving CSV, WebSocket and
321
+ FIX representations of one trade collapse to an identical event.
322
+
323
+ ## License
324
+
325
+ MIT © HarvestGroup360 (AMII LTD). See [LICENSE](LICENSE).
326
+
327
+ ---
328
+
329
+ Maintained by [HarvestGroup360](https://harvestgroup360.com) as part of our
330
+ open quantitative-infrastructure tooling.
@@ -0,0 +1,21 @@
1
+ mdnorm/__init__.py,sha256=64_G8P30VnYexQt73U4WitHs8MA62yO3qtL8cQJh08s,2057
2
+ mdnorm/__main__.py,sha256=gsrjzHcpdagrMBi_jZpO8KJDStEjeeTuUfbFn8Jo8Hk,135
3
+ mdnorm/bars.py,sha256=Koqv7rKqdfQzwWFWZNxfOaXHV-gBoW2Rfz7ZpOp-pdw,8635
4
+ mdnorm/cli.py,sha256=TXpFxLh4-UKH21Fgqmu1803q_Qc16A-YZLKCbQaI2NU,8518
5
+ mdnorm/csvio.py,sha256=t66oKe7y-MokpA_iCCDdk1-wvPPNeysxBTnL1j82JGc,2461
6
+ mdnorm/fileio.py,sha256=0nXi45qca3aHx5H_jtXPvApVASHMttdxt4Sbo1lDZt0,731
7
+ mdnorm/jsonl.py,sha256=6kXYduWczuintgABDI1JJm2u2_K0qIUT0cRHRlf92YE,3410
8
+ mdnorm/normalizers.py,sha256=3AKiyxAMTh-lT0hpQL266riS4Cjfmbiz3GAWtMW2geM,6106
9
+ mdnorm/pipeline.py,sha256=E7bwB2CHKMBzXV-PP_gOAVeRAuR99135EOXnjh_ahrE,5128
10
+ mdnorm/quality.py,sha256=2AbNZErGOvZWlGn-2AFV3hrkJRepcql7eLX2b6WCzP8,3176
11
+ mdnorm/records.py,sha256=xj5jBkPEjqtIZaCD7iRwQaK9ZdoeZfFrSpYcFzBmfLI,2415
12
+ mdnorm/schema.py,sha256=ujlvpPgd_-6-ePXszAzapREmVlIHJJZpuJEVw9j4VCI,2262
13
+ mdnorm/sessions.py,sha256=I9voJ5WqHafFLYn70HoUSQtynI4ycsxsvf-QT2jO9ng,6927
14
+ mdnorm/streams.py,sha256=e-oHhSK8Fj86a0BhNf7IitB9AeIvTyUU1LSUghWGrm0,1248
15
+ mdnorm/symbols.py,sha256=j6mJMjW5i-4w6uDF8Aj3bl6XahH2H5x_ClIXmp9nJX8,1968
16
+ mdnorm/timeutil.py,sha256=MVv61eHgTWZeiie4PzAw8uhHu2BrdYiYV9ti6R5A8EQ,1525
17
+ market_data_normalizer-1.3.1.dist-info/METADATA,sha256=SCeVGy7UIGiFOIBGr0orRHKwElUDVZ-QHZAWhxbjTGk,11267
18
+ market_data_normalizer-1.3.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
19
+ market_data_normalizer-1.3.1.dist-info/entry_points.txt,sha256=n1EgYTITUpYmGCfAtrmrFVuGS0Frf691iSQlurpTUQY,43
20
+ market_data_normalizer-1.3.1.dist-info/licenses/LICENSE,sha256=HJNlUNuaSm-lzx02gw6NJPzrpidtG58PYZfLdTv1w7Y,1083
21
+ market_data_normalizer-1.3.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mdnorm = mdnorm.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HarvestGroup360 (AMII LTD)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
mdnorm/__init__.py ADDED
@@ -0,0 +1,92 @@
1
+ """market-data-normalizer (mdnorm).
2
+
3
+ Normalize heterogeneous market-data feeds (CSV, exchange WebSocket JSON, FIX)
4
+ into a single, exchange-agnostic :class:`MarketEvent` schema.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ from .bars import (
9
+ Bar,
10
+ count_bars,
11
+ dollar_bars,
12
+ fill_gaps,
13
+ resample_bars,
14
+ time_bars,
15
+ volume_bars,
16
+ )
17
+ from .csvio import iter_csv_trades, read_csv_trades, write_records_csv
18
+ from .jsonl import event_from_dict, iter_jsonl_events, read_jsonl_events, write_jsonl
19
+ from .normalizers import (
20
+ from_csv_quote,
21
+ from_csv_row,
22
+ from_fix,
23
+ from_ws_json,
24
+ from_ws_quote,
25
+ )
26
+ from .pipeline import Pipeline
27
+ from .quality import QualityIssue, clean, find_issues
28
+ from .records import bar_to_dict, event_to_dict, to_records
29
+ from .schema import EventType, MarketEvent, Side
30
+ from .sessions import (
31
+ US_EQUITY_RTH,
32
+ US_FUTURES_OVERNIGHT,
33
+ WEEKDAYS,
34
+ Session,
35
+ filter_session,
36
+ group_by_session_date,
37
+ in_session,
38
+ parse_session,
39
+ session_date,
40
+ )
41
+ from .streams import dedupe, merge_streams
42
+ from .symbols import canonical_symbol
43
+ from .timeutil import epoch_to_ns, fix_utc_to_ns, iso_to_ns
44
+
45
+ __version__ = "1.3.1"
46
+
47
+ __all__ = [
48
+ "MarketEvent",
49
+ "EventType",
50
+ "Side",
51
+ "from_csv_row",
52
+ "from_ws_json",
53
+ "from_fix",
54
+ "from_ws_quote",
55
+ "from_csv_quote",
56
+ "Bar",
57
+ "time_bars",
58
+ "resample_bars",
59
+ "fill_gaps",
60
+ "count_bars",
61
+ "volume_bars",
62
+ "dollar_bars",
63
+ "Session",
64
+ "in_session",
65
+ "filter_session",
66
+ "session_date",
67
+ "group_by_session_date",
68
+ "parse_session",
69
+ "WEEKDAYS",
70
+ "US_EQUITY_RTH",
71
+ "US_FUTURES_OVERNIGHT",
72
+ "QualityIssue",
73
+ "find_issues",
74
+ "clean",
75
+ "event_to_dict",
76
+ "bar_to_dict",
77
+ "to_records",
78
+ "merge_streams",
79
+ "dedupe",
80
+ "read_csv_trades",
81
+ "iter_csv_trades",
82
+ "write_records_csv",
83
+ "read_jsonl_events",
84
+ "iter_jsonl_events",
85
+ "write_jsonl",
86
+ "event_from_dict",
87
+ "Pipeline",
88
+ "canonical_symbol",
89
+ "epoch_to_ns",
90
+ "iso_to_ns",
91
+ "fix_utc_to_ns",
92
+ ]
mdnorm/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Allow ``python -m mdnorm ...`` to invoke the CLI."""
2
+ from .cli import main
3
+
4
+ if __name__ == "__main__":
5
+ raise SystemExit(main())