mxm-refdata 0.3.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.
Files changed (63) hide show
  1. mxm_refdata-0.3.0/LICENSE +21 -0
  2. mxm_refdata-0.3.0/PKG-INFO +228 -0
  3. mxm_refdata-0.3.0/README.md +202 -0
  4. mxm_refdata-0.3.0/pyproject.toml +68 -0
  5. mxm_refdata-0.3.0/src/mxm/refdata/__init__.py +1 -0
  6. mxm_refdata-0.3.0/src/mxm/refdata/api/__init__.py +1 -0
  7. mxm_refdata-0.3.0/src/mxm/refdata/api/ref_data_api.py +607 -0
  8. mxm_refdata-0.3.0/src/mxm/refdata/cli.py +218 -0
  9. mxm_refdata-0.3.0/src/mxm/refdata/data/first_day_of_interest_rule.json +88 -0
  10. mxm_refdata-0.3.0/src/mxm/refdata/data/futures_products.csv +6 -0
  11. mxm_refdata-0.3.0/src/mxm/refdata/data/last_trading_rule.json +34 -0
  12. mxm_refdata-0.3.0/src/mxm/refdata/database/__init__.py +1 -0
  13. mxm_refdata-0.3.0/src/mxm/refdata/database/sql_session_manager.py +135 -0
  14. mxm_refdata-0.3.0/src/mxm/refdata/mappings/__init__.py +31 -0
  15. mxm_refdata-0.3.0/src/mxm/refdata/mappings/futures_contract_vs_orm.py +51 -0
  16. mxm_refdata-0.3.0/src/mxm/refdata/mappings/futures_product_vs_orm.py +56 -0
  17. mxm_refdata-0.3.0/src/mxm/refdata/mappings/period_cycles_vs_orm.py +102 -0
  18. mxm_refdata-0.3.0/src/mxm/refdata/mappings/period_vs_orm.py +40 -0
  19. mxm_refdata-0.3.0/src/mxm/refdata/models/__init__.py +31 -0
  20. mxm_refdata-0.3.0/src/mxm/refdata/models/contracts/__init__.py +0 -0
  21. mxm_refdata-0.3.0/src/mxm/refdata/models/contracts/futures_contract.py +22 -0
  22. mxm_refdata-0.3.0/src/mxm/refdata/models/currencies.py +24 -0
  23. mxm_refdata-0.3.0/src/mxm/refdata/models/months.py +72 -0
  24. mxm_refdata-0.3.0/src/mxm/refdata/models/orm/__init__.py +16 -0
  25. mxm_refdata-0.3.0/src/mxm/refdata/models/orm/base.py +3 -0
  26. mxm_refdata-0.3.0/src/mxm/refdata/models/orm/futures_contracts.py +53 -0
  27. mxm_refdata-0.3.0/src/mxm/refdata/models/orm/futures_products.py +61 -0
  28. mxm_refdata-0.3.0/src/mxm/refdata/models/orm/period_cycles.py +84 -0
  29. mxm_refdata-0.3.0/src/mxm/refdata/models/orm/periods.py +30 -0
  30. mxm_refdata-0.3.0/src/mxm/refdata/models/period_cycles.py +73 -0
  31. mxm_refdata-0.3.0/src/mxm/refdata/models/periods.py +64 -0
  32. mxm_refdata-0.3.0/src/mxm/refdata/models/products/__init__.py +1 -0
  33. mxm_refdata-0.3.0/src/mxm/refdata/models/products/futures_product.py +38 -0
  34. mxm_refdata-0.3.0/src/mxm/refdata/models/products/settlement.py +10 -0
  35. mxm_refdata-0.3.0/src/mxm/refdata/models/reference_events.py +9 -0
  36. mxm_refdata-0.3.0/src/mxm/refdata/models/units.py +28 -0
  37. mxm_refdata-0.3.0/src/mxm/refdata/models/weekdays.py +66 -0
  38. mxm_refdata-0.3.0/src/mxm/refdata/parsing/__init__.py +1 -0
  39. mxm_refdata-0.3.0/src/mxm/refdata/parsing/futures_products_from_csv.py +76 -0
  40. mxm_refdata-0.3.0/src/mxm/refdata/py.typed +0 -0
  41. mxm_refdata-0.3.0/src/mxm/refdata/scripts/__init__.py +1 -0
  42. mxm_refdata-0.3.0/src/mxm/refdata/scripts/db_utils.py +61 -0
  43. mxm_refdata-0.3.0/src/mxm/refdata/scripts/manage_static_ref_data.py +73 -0
  44. mxm_refdata-0.3.0/src/mxm/refdata/services/__init__.py +0 -0
  45. mxm_refdata-0.3.0/src/mxm/refdata/services/bootstrap.py +84 -0
  46. mxm_refdata-0.3.0/src/mxm/refdata/services/futures_contract_factory.py +127 -0
  47. mxm_refdata-0.3.0/src/mxm/refdata/services/futures_product_factory.py +132 -0
  48. mxm_refdata-0.3.0/src/mxm/refdata/services/period_factory.py +315 -0
  49. mxm_refdata-0.3.0/src/mxm/refdata/services/ref_data_service.py +322 -0
  50. mxm_refdata-0.3.0/src/mxm/refdata/services/smokecheck.py +326 -0
  51. mxm_refdata-0.3.0/src/mxm/refdata/trading_calendars/__init__.py +0 -0
  52. mxm_refdata-0.3.0/src/mxm/refdata/trading_calendars/first_day_of_interest.py +74 -0
  53. mxm_refdata-0.3.0/src/mxm/refdata/trading_calendars/last_trading_day.py +117 -0
  54. mxm_refdata-0.3.0/src/mxm/refdata/trading_calendars/nth_business_day.py +52 -0
  55. mxm_refdata-0.3.0/src/mxm/refdata/trading_calendars/nth_calendar_day_of_period.py +43 -0
  56. mxm_refdata-0.3.0/src/mxm/refdata/trading_calendars/nth_weekday_of_period.py +50 -0
  57. mxm_refdata-0.3.0/src/mxm/refdata/trading_calendars/trading_calendar.py +186 -0
  58. mxm_refdata-0.3.0/src/mxm/refdata/utils/__init__.py +1 -0
  59. mxm_refdata-0.3.0/src/mxm/refdata/utils/cache_manager.py +33 -0
  60. mxm_refdata-0.3.0/src/mxm/refdata/utils/config.py +32 -0
  61. mxm_refdata-0.3.0/src/mxm/refdata/utils/period_types_codec.py +16 -0
  62. mxm_refdata-0.3.0/src/mxm/refdata/utils/regex_patterns.py +18 -0
  63. mxm_refdata-0.3.0/src/mxm/refdata/utils/resources.py +29 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Money Ex Machina
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.
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: mxm-refdata
3
+ Version: 0.3.0
4
+ Summary: Canonical reference data for Money Ex Machina.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: mxm
8
+ Author-email: contact@moneyexmachina.com
9
+ Requires-Python: >=3.13,<4.0
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Dist: cachetools (>=7.1.1,<8.0.0)
15
+ Requires-Dist: exchange-calendars (>=4.11.1,<5.0.0)
16
+ Requires-Dist: pandas (>=2.3.3,<3.0.0)
17
+ Requires-Dist: pydantic-settings (>=2.14.1,<3.0.0)
18
+ Requires-Dist: rich (>=15.0.0,<16.0.0)
19
+ Requires-Dist: sqlalchemy (>=2.0.43,<3.0.0)
20
+ Requires-Dist: typer (>=0.25.1,<0.26.0)
21
+ Project-URL: Homepage, https://github.com/moneyexmachina/mxm-refdata
22
+ Project-URL: Issues, https://github.com/moneyexmachina/mxm-refdata/issues
23
+ Project-URL: Repository, https://github.com/moneyexmachina/mxm-refdata
24
+ Description-Content-Type: text/markdown
25
+
26
+ # mxm-refdata
27
+
28
+ ![Version](https://img.shields.io/github/v/release/moneyexmachina/mxm-refdata)
29
+ ![License](https://img.shields.io/github/license/moneyexmachina/mxm-refdata)
30
+ ![Python](https://img.shields.io/badge/python-3.13+-blue)
31
+ [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
32
+
33
+ Reference data and contract ontology for the Money Ex Machina (MXM) ecosystem.
34
+
35
+ `mxm-refdata` provides canonical, programmatic definitions of financial instruments and trading structures, currently focused on:
36
+
37
+ - futures products,
38
+ - futures contracts,
39
+ - lifecycle rules,
40
+ - trading calendars,
41
+ - periods and period cycles,
42
+ - and deterministic contract generation.
43
+
44
+ The package acts as the ontological reference layer for MXM systems such as `mxm-v1`.
45
+
46
+ ## Purpose
47
+
48
+ `mxm-refdata` defines *what financial reference objects exist* and *how they are constructed*.
49
+
50
+ For example, a futures contract such as:
51
+
52
+ ```text
53
+ cme_gbp_futures.Mar-2032
54
+ ```
55
+
56
+ is treated as a deterministic construct derived from:
57
+
58
+ - product specifications,
59
+ - listing rules,
60
+ - period systems,
61
+ - and trading-calendar semantics.
62
+
63
+ This allows MXM systems to reason about financial structures independently of any specific market-data provider.
64
+
65
+ `mxm-refdata` therefore models the constructive ontology of financial instruments, while observed prices, trades, quotes, and exchange events belong to the separate market-observation layer (`mxm-marketdata`).
66
+
67
+ ## Architecture
68
+
69
+ `mxm-refdata` consists of four main layers:
70
+
71
+ 1. **Reference specifications**
72
+ Human-authored product and lifecycle specifications bundled with the package.
73
+
74
+ 2. **Deterministic generation**
75
+ Services that construct contracts, periods, lifecycle dates, and calendar relationships.
76
+
77
+ 3. **Materialised reference store**
78
+ SQLite database containing generated products, contracts, periods, cycles, and lifecycle state.
79
+
80
+ 4. **Query and inspection interfaces**
81
+ Typed Python API and operational CLI.
82
+
83
+ ## Installation
84
+
85
+ ```bash
86
+ git clone https://github.com/moneyexmachina/mxm-refdata.git
87
+ cd mxm-refdata
88
+ poetry install
89
+ ```
90
+
91
+ ## Usage
92
+
93
+ Build the local reference database:
94
+
95
+ ```bash
96
+ mxm-refdata build
97
+ ```
98
+
99
+ Rebuild from scratch:
100
+
101
+ ```bash
102
+ mxm-refdata rebuild
103
+ ```
104
+
105
+ Inspect products:
106
+
107
+ ```bash
108
+ mxm-refdata products
109
+ ```
110
+
111
+ Inspect contract coverage:
112
+
113
+ ```bash
114
+ mxm-refdata coverage
115
+ ```
116
+
117
+ Run operational smoke checks:
118
+
119
+ ```bash
120
+ mxm-refdata smokecheck
121
+ ```
122
+
123
+ ## Python API
124
+
125
+ ```python
126
+ from datetime import date
127
+
128
+ from mxm.refdata.api.ref_data_api import RefDataAPI
129
+
130
+ api = RefDataAPI()
131
+
132
+ products = api.get_all_products()
133
+
134
+ contracts = api.get_contracts_for_product(
135
+ "comex_gold_futures"
136
+ )
137
+
138
+ active_contracts = api.get_active_contracts(
139
+ as_of_date=date(2026, 5, 1),
140
+ )
141
+ ```
142
+
143
+ ## Operating Modes
144
+
145
+ ### Buildable mode
146
+
147
+ In buildable mode, the reference database is treated as deterministic derived state.
148
+
149
+ If missing or empty, the package may automatically:
150
+
151
+ - create the schema,
152
+ - generate contracts,
153
+ - and materialise the reference universe.
154
+
155
+ This mode supports:
156
+
157
+ - development,
158
+ - CI,
159
+ - local experimentation,
160
+ - and early-stage deployments.
161
+
162
+ ### Managed mode
163
+
164
+ Managed mode treats the reference database as governed operational state.
165
+
166
+ Updates occur explicitly through controlled management and reconciliation workflows.
167
+
168
+ ## Development
169
+
170
+ `mxm-refdata` is maintained as an `mxm-foundry` compliant package.
171
+
172
+ Primary development gate:
173
+
174
+ ```bash
175
+ make check
176
+ ```
177
+
178
+ Validate repository compliance:
179
+
180
+ ```bash
181
+ mxm-foundry check .
182
+ ```
183
+
184
+ Setup:
185
+
186
+ ```bash
187
+ poetry install
188
+ ```
189
+
190
+ ## Documentation
191
+
192
+ - `docs/design.md`
193
+
194
+ ## Roadmap
195
+
196
+ ### v0
197
+
198
+ - Futures product specifications
199
+ - Deterministic futures contract generation
200
+ - Trading calendar integration
201
+ - Period and period-cycle models
202
+ - Materialised SQLite reference store
203
+ - Typed query API
204
+ - Operational CLI and smoke checks
205
+ - `mxm-foundry` compliance
206
+
207
+ ### v1
208
+
209
+ - Broader futures product coverage
210
+ - Stronger typed lifecycle-rule models
211
+ - Explicit `TradingCalendarId` abstractions
212
+ - Improved CLI inspection and filtering
213
+ - Clearer ontology boundaries and documentation
214
+
215
+ ### v2
216
+
217
+ - ETF and FX product support
218
+ - Managed reference governance
219
+ - Historical exchange rule evolution
220
+ - External reconciliation workflows
221
+ - Expanded multi-venue ontology
222
+ - Integration boundaries with `mxm-marketdata`
223
+ - Integration boundaries with future `mxm-calendar`
224
+
225
+ ## License
226
+
227
+ MIT License. See [LICENSE](LICENSE).
228
+
@@ -0,0 +1,202 @@
1
+ # mxm-refdata
2
+
3
+ ![Version](https://img.shields.io/github/v/release/moneyexmachina/mxm-refdata)
4
+ ![License](https://img.shields.io/github/license/moneyexmachina/mxm-refdata)
5
+ ![Python](https://img.shields.io/badge/python-3.13+-blue)
6
+ [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
7
+
8
+ Reference data and contract ontology for the Money Ex Machina (MXM) ecosystem.
9
+
10
+ `mxm-refdata` provides canonical, programmatic definitions of financial instruments and trading structures, currently focused on:
11
+
12
+ - futures products,
13
+ - futures contracts,
14
+ - lifecycle rules,
15
+ - trading calendars,
16
+ - periods and period cycles,
17
+ - and deterministic contract generation.
18
+
19
+ The package acts as the ontological reference layer for MXM systems such as `mxm-v1`.
20
+
21
+ ## Purpose
22
+
23
+ `mxm-refdata` defines *what financial reference objects exist* and *how they are constructed*.
24
+
25
+ For example, a futures contract such as:
26
+
27
+ ```text
28
+ cme_gbp_futures.Mar-2032
29
+ ```
30
+
31
+ is treated as a deterministic construct derived from:
32
+
33
+ - product specifications,
34
+ - listing rules,
35
+ - period systems,
36
+ - and trading-calendar semantics.
37
+
38
+ This allows MXM systems to reason about financial structures independently of any specific market-data provider.
39
+
40
+ `mxm-refdata` therefore models the constructive ontology of financial instruments, while observed prices, trades, quotes, and exchange events belong to the separate market-observation layer (`mxm-marketdata`).
41
+
42
+ ## Architecture
43
+
44
+ `mxm-refdata` consists of four main layers:
45
+
46
+ 1. **Reference specifications**
47
+ Human-authored product and lifecycle specifications bundled with the package.
48
+
49
+ 2. **Deterministic generation**
50
+ Services that construct contracts, periods, lifecycle dates, and calendar relationships.
51
+
52
+ 3. **Materialised reference store**
53
+ SQLite database containing generated products, contracts, periods, cycles, and lifecycle state.
54
+
55
+ 4. **Query and inspection interfaces**
56
+ Typed Python API and operational CLI.
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ git clone https://github.com/moneyexmachina/mxm-refdata.git
62
+ cd mxm-refdata
63
+ poetry install
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ Build the local reference database:
69
+
70
+ ```bash
71
+ mxm-refdata build
72
+ ```
73
+
74
+ Rebuild from scratch:
75
+
76
+ ```bash
77
+ mxm-refdata rebuild
78
+ ```
79
+
80
+ Inspect products:
81
+
82
+ ```bash
83
+ mxm-refdata products
84
+ ```
85
+
86
+ Inspect contract coverage:
87
+
88
+ ```bash
89
+ mxm-refdata coverage
90
+ ```
91
+
92
+ Run operational smoke checks:
93
+
94
+ ```bash
95
+ mxm-refdata smokecheck
96
+ ```
97
+
98
+ ## Python API
99
+
100
+ ```python
101
+ from datetime import date
102
+
103
+ from mxm.refdata.api.ref_data_api import RefDataAPI
104
+
105
+ api = RefDataAPI()
106
+
107
+ products = api.get_all_products()
108
+
109
+ contracts = api.get_contracts_for_product(
110
+ "comex_gold_futures"
111
+ )
112
+
113
+ active_contracts = api.get_active_contracts(
114
+ as_of_date=date(2026, 5, 1),
115
+ )
116
+ ```
117
+
118
+ ## Operating Modes
119
+
120
+ ### Buildable mode
121
+
122
+ In buildable mode, the reference database is treated as deterministic derived state.
123
+
124
+ If missing or empty, the package may automatically:
125
+
126
+ - create the schema,
127
+ - generate contracts,
128
+ - and materialise the reference universe.
129
+
130
+ This mode supports:
131
+
132
+ - development,
133
+ - CI,
134
+ - local experimentation,
135
+ - and early-stage deployments.
136
+
137
+ ### Managed mode
138
+
139
+ Managed mode treats the reference database as governed operational state.
140
+
141
+ Updates occur explicitly through controlled management and reconciliation workflows.
142
+
143
+ ## Development
144
+
145
+ `mxm-refdata` is maintained as an `mxm-foundry` compliant package.
146
+
147
+ Primary development gate:
148
+
149
+ ```bash
150
+ make check
151
+ ```
152
+
153
+ Validate repository compliance:
154
+
155
+ ```bash
156
+ mxm-foundry check .
157
+ ```
158
+
159
+ Setup:
160
+
161
+ ```bash
162
+ poetry install
163
+ ```
164
+
165
+ ## Documentation
166
+
167
+ - `docs/design.md`
168
+
169
+ ## Roadmap
170
+
171
+ ### v0
172
+
173
+ - Futures product specifications
174
+ - Deterministic futures contract generation
175
+ - Trading calendar integration
176
+ - Period and period-cycle models
177
+ - Materialised SQLite reference store
178
+ - Typed query API
179
+ - Operational CLI and smoke checks
180
+ - `mxm-foundry` compliance
181
+
182
+ ### v1
183
+
184
+ - Broader futures product coverage
185
+ - Stronger typed lifecycle-rule models
186
+ - Explicit `TradingCalendarId` abstractions
187
+ - Improved CLI inspection and filtering
188
+ - Clearer ontology boundaries and documentation
189
+
190
+ ### v2
191
+
192
+ - ETF and FX product support
193
+ - Managed reference governance
194
+ - Historical exchange rule evolution
195
+ - External reconciliation workflows
196
+ - Expanded multi-venue ontology
197
+ - Integration boundaries with `mxm-marketdata`
198
+ - Integration boundaries with future `mxm-calendar`
199
+
200
+ ## License
201
+
202
+ MIT License. See [LICENSE](LICENSE).
@@ -0,0 +1,68 @@
1
+ [tool.poetry]
2
+ name = "mxm-refdata"
3
+ version = "0.3.0"
4
+ description = "Canonical reference data for Money Ex Machina."
5
+ authors = ["mxm <contact@moneyexmachina.com>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ packages = [{ include = "mxm", from = "src" }]
9
+ include = [
10
+ "src/mxm/refdata/py.typed",
11
+ "src/mxm/refdata/data/**/*",
12
+ ]
13
+ [tool.poetry.scripts]
14
+ mxm-refdata = "mxm.refdata.cli:app"
15
+
16
+ [tool.poetry.urls]
17
+ Homepage = "https://github.com/moneyexmachina/mxm-refdata"
18
+ Repository = "https://github.com/moneyexmachina/mxm-refdata"
19
+ Issues = "https://github.com/moneyexmachina/mxm-refdata/issues"
20
+
21
+ [tool.poetry.dependencies]
22
+ python = ">=3.13,<4.0"
23
+ pandas = ">=2.3.3,<3.0.0"
24
+ sqlalchemy = ">=2.0.43,<3.0.0"
25
+ exchange-calendars = ">=4.11.1,<5.0.0"
26
+ typer = "^0.25.1"
27
+ rich = "^15.0.0"
28
+ cachetools = "^7.1.1"
29
+ pydantic-settings = "^2.14.1"
30
+
31
+ [tool.poetry.group.dev.dependencies]
32
+ black = "^25.9.0"
33
+ ruff = "^0.13.2"
34
+ isort = "^6.0.1"
35
+ pytest = "^8.4.2"
36
+ pytest-mock = "^3.15.1"
37
+ pyright = "^1.1.408"
38
+ pandas-stubs = "^3.0.0.260204"
39
+
40
+ [build-system]
41
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
42
+ build-backend = "poetry.core.masonry.api"
43
+
44
+ [tool.black]
45
+ line-length = 88
46
+ target-version = ["py313"]
47
+
48
+ [tool.isort]
49
+ profile = "black"
50
+ line_length = 88
51
+ known_first_party = ["mxm"]
52
+ combine_as_imports = true
53
+
54
+ [tool.ruff]
55
+ line-length = 88
56
+ target-version = "py313"
57
+
58
+ [tool.ruff.lint]
59
+ select = ["E","F","I","B","UP","C90","RUF"]
60
+ ignore = ["E203","E501"]
61
+
62
+ [tool.ruff.lint.isort]
63
+ known-first-party = ["mxm"]
64
+
65
+ [tool.pytest.ini_options]
66
+ addopts = "-q"
67
+ pythonpath = ["src"]
68
+
@@ -0,0 +1 @@
1
+ """Code for the core reference data service package."""
@@ -0,0 +1 @@
1
+ """Single access api for objects in the refData package."""