onesecondtrader 0.51.0__py3-none-any.whl → 0.52.0__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,3 @@
1
+ """
2
+ Provides a schema for creating and utilities to populate the security master database.
3
+ """
File without changes
@@ -0,0 +1,166 @@
1
+ -- Security master database schema.
2
+ --
3
+ -- The schema is designed for Databento-native ingestion via DBN files, while remaining compatible with other sources.
4
+ -- Instrument identity is modeled per publisher namespace and supports either numeric upstream identifiers or symbols.
5
+ -- Contract specifications and other static reference metadata are intentionally out of scope for this schema and should be stored separately if ingested.
6
+ --
7
+ -- | Table | Description |
8
+ -- |---------------|-------------|
9
+ -- | `publishers` | Registry of data sources and their identifier namespaces. |
10
+ -- | `instruments` | Registry of instruments observed from market data ingestion within a publisher namespace. |
11
+ -- | `ohlcv` | Aggregated OHLCV bar data keyed by instrument, bar duration (`rtype`), and event timestamp (`ts_event`). |
12
+ -- | `symbology` | Time-bounded mappings from publisher-native symbols to publisher-native instrument identifiers. |
13
+
14
+
15
+
16
+ -- Registry of all data sources used for market data and instrument ingestion.
17
+ --
18
+ -- Each row represents a distinct data source.
19
+ -- A publisher establishes the provenance of instrument definitions and price data and provides the context in which raw symbols and native instrument identifiers are interpreted.
20
+ --
21
+ -- | Field | Type | Constraints | Description |
22
+ -- |-----------------|-----------|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
23
+ -- | `publisher_id` | `INTEGER` | `PRIMARY KEY` | Internal surrogate key uniquely identifying a data source within the system. |
24
+ -- | `name` | `TEXT` | `NOT NULL`, `UNIQUE` | Human-readable identifier for the data source or vendor (e.g. `databento`, `yfinance`). |
25
+ -- | `dataset` | `TEXT` | `NOT NULL` | Identifier of the concrete data product or feed through which data is sourced; uses Databento dataset names (e.g. `GLBX.MDP3`) for Databento ingestion and internal identifiers for other sources (e.g. `YFINANCE`). |
26
+ -- | `venue` | `TEXT` | | Optional ISO 10383 Market Identifier Code (MIC) describing the primary trading venue; may be NULL for aggregated or multi-venue sources. |
27
+ --
28
+ -- **Examples**
29
+ --
30
+ -- Databento CME Globex feed:
31
+ --
32
+ -- * `name` = `'databento'`
33
+ -- * `dataset` = `'GLBX.MDP3'`
34
+ -- * `venue` = `XCME`
35
+ --
36
+ -- Yahoo Finance equity data:
37
+ --
38
+ -- * `name` = `'yfinance'`
39
+ -- * `dataset` = `'YFINANCE'`
40
+ -- * `venue` = `NULL`
41
+ --
42
+ CREATE TABLE publishers (
43
+ publisher_id INTEGER PRIMARY KEY,
44
+ name TEXT NOT NULL UNIQUE,
45
+ dataset TEXT NOT NULL,
46
+ venue TEXT
47
+ );
48
+
49
+
50
+
51
+
52
+ -- Registry of instruments observed through market data ingestion.
53
+ --
54
+ -- Each row represents an instrument identity within a publisher namespace.
55
+ -- Instruments may be identified by a publisher-native numeric identifier, a symbol identifier, or both.
56
+ -- Databento ingestion uses `source_instrument_id` as the primary identifier and may optionally store a symbol from symbology.
57
+ -- Symbol-first sources such as yfinance use `symbol` as the primary identifier and typically leave `source_instrument_id` to be `NULL`.
58
+ --
59
+ -- The table does not store contract specifications or other reference metadata.
60
+ -- Such metadata must be stored separately when available.
61
+ --
62
+ -- | Field | Type | Constraints | Description |
63
+ -- |------------------------|-----------|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
64
+ -- | `instrument_id` | `INTEGER` | `PRIMARY KEY` | Internal surrogate key identifying an instrument record within the system. |
65
+ -- | `publisher_ref` | `INTEGER` | `NOT NULL`, `FK` | Foreign key reference to `publishers.publisher_id`, defining the publisher namespace in which this instrument identity is valid. |
66
+ -- | `source_instrument_id` | `INTEGER` | | Publisher-native numeric instrument identifier as provided by the upstream data source (e.g. Databento instrument_id); may be `NULL` for symbol-only sources. |
67
+ -- | `symbol` | `TEXT` | | Publisher-native symbol string identifying the instrument (e.g. raw symbol, ticker); may be NULL when numeric identifiers are used. |
68
+ -- | `symbol_type` | `TEXT` | | Identifier describing the symbol scheme or resolution type used by the publisher (e.g. `raw_symbol`, `continuous`, `ticker`). |
69
+ --
70
+ -- Each instrument must be identifiable by at least one of `source_instrument_id` or `symbol`.
71
+ -- Uniqueness constraints ensure that instrument identities do not collide within a publisher namespace.
72
+ -- The table intentionally excludes contract specifications and other reference metadata, which must be stored separately when available.
73
+ --
74
+ CREATE TABLE instruments (
75
+ instrument_id INTEGER PRIMARY KEY,
76
+
77
+ publisher_ref INTEGER NOT NULL,
78
+
79
+ source_instrument_id INTEGER,
80
+ symbol TEXT,
81
+ symbol_type TEXT,
82
+
83
+ FOREIGN KEY (publisher_ref) REFERENCES publishers(publisher_id),
84
+
85
+ CHECK (
86
+ source_instrument_id IS NOT NULL
87
+ OR symbol IS NOT NULL
88
+ ),
89
+
90
+ UNIQUE (publisher_ref, source_instrument_id),
91
+ UNIQUE (publisher_ref, symbol, symbol_type)
92
+ );
93
+
94
+
95
+
96
+
97
+
98
+
99
+ -- Stores aggregated OHLCV bars for instruments at multiple time resolutions.
100
+ --
101
+ -- | Field | Type | Constraints | Description |
102
+ -- |-----------------|-----------|---------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
103
+ -- | `instrument_id` | `INTEGER` | `NOT NULL`, `FK` | Foreign key reference to `instruments.instrument_id`, identifying the instrument to which this bar belongs. |
104
+ -- | `rtype` | `INTEGER` | `NOT NULL`, `CHECK IN (32, 33, 34, 35, 36)` | Record type code encoding the bar duration using Databento OHLCV conventions (e.g. `32`=1s, `33`=1m, `34`=1h, `35`=1d). |
105
+ -- | `ts_event` | `INTEGER` | `NOT NULL` | Event timestamp of the bar as provided by the upstream source, stored as nanoseconds since the UTC Unix epoch. |
106
+ -- | `open` | `INTEGER` | `NOT NULL` | Opening price of the bar interval, stored as a fixed-point integer using the upstream price scaling convention. |
107
+ -- | `high` | `INTEGER` | `NOT NULL` | Highest traded price during the bar interval, stored as a fixed-point integer. |
108
+ -- | `low` | `INTEGER` | `NOT NULL`, `CHECK(low <= high)` | Lowest traded price during the bar interval, stored as a fixed-point integer. |
109
+ -- | `close` | `INTEGER` | `NOT NULL` | Closing price of the bar interval, stored as a fixed-point integer. |
110
+ -- | `volume` | `INTEGER` | `NOT NULL`, `CHECK(volume >= 0)` | Total traded volume during the bar interval. |
111
+ --
112
+ -- The composite primary key enforces uniqueness per instrument, bar duration, and event timestamp.
113
+ -- Integrity constraints ensure basic OHLC consistency and prevent invalid price relationships from being stored.
114
+ -- The table uses `WITHOUT ROWID` to store rows directly in the primary key B-tree for reduced storage overhead and faster lookups.
115
+ --
116
+ CREATE TABLE ohlcv (
117
+ instrument_id INTEGER NOT NULL,
118
+ rtype INTEGER NOT NULL CHECK(rtype IN (32, 33, 34, 35, 36)),
119
+ ts_event INTEGER NOT NULL,
120
+ open INTEGER NOT NULL,
121
+ high INTEGER NOT NULL,
122
+ low INTEGER NOT NULL,
123
+ close INTEGER NOT NULL,
124
+ volume INTEGER NOT NULL CHECK(volume >= 0),
125
+ FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
126
+ PRIMARY KEY (instrument_id, rtype, ts_event),
127
+ CHECK(low <= high),
128
+ CHECK(open BETWEEN low AND high),
129
+ CHECK(close BETWEEN low AND high)
130
+ ) WITHOUT ROWID;
131
+
132
+
133
+
134
+
135
+
136
+ -- Stores time-bounded mappings from publisher-native symbols to publisher-native instrument identifiers.
137
+ --
138
+ -- The table captures symbol resolution rules as provided by upstream data sources and must be interpreted within the namespace of a specific publisher.
139
+ --
140
+ -- | Field | Type | Constraints | Description |
141
+ -- |------------------------|-----------|------------------|----------------------------------------------------------------------------------------------------------------------------|
142
+ -- | `publisher_ref` | `INTEGER` | `NOT NULL`, `FK` | Foreign key reference to `publishers.publisher_id`, defining the publisher namespace in which the symbol mapping is valid. |
143
+ -- | `symbol` | `TEXT` | `NOT NULL` | Publisher-native symbol string as provided by the upstream source (e.g. raw symbol, continuous symbol). |
144
+ -- | `symbol_type` | `TEXT` | `NOT NULL` | Identifier describing the symbol scheme or resolution type used by the publisher (e.g. `raw_symbol`, `continuous`). |
145
+ -- | `source_instrument_id` | `INTEGER` | `NOT NULL` | Publisher-native numeric instrument identifier corresponding to the resolved symbol. |
146
+ -- | `start_date` | `TEXT` | `NOT NULL` | First calendar date (inclusive) on which this symbol-to-instrument mapping is valid, stored in YYYY-MM-DD format. |
147
+ -- | `end_date` | `TEXT` | `NOT NULL` | Last calendar date (inclusive) on which this symbol-to-instrument mapping is valid, stored in YYYY-MM-DD format. |
148
+ --
149
+ -- The primary key enforces uniqueness of symbol mappings per publisher, symbol type, and start date.
150
+ -- Date bounds are interpreted as closed intervals.
151
+ --
152
+ CREATE TABLE symbology (
153
+ publisher_ref INTEGER NOT NULL,
154
+ symbol TEXT NOT NULL,
155
+ symbol_type TEXT NOT NULL,
156
+ source_instrument_id INTEGER NOT NULL,
157
+ start_date TEXT NOT NULL,
158
+ end_date TEXT NOT NULL,
159
+ FOREIGN KEY (publisher_ref) REFERENCES publishers(publisher_id),
160
+ PRIMARY KEY (publisher_ref, symbol, symbol_type, start_date),
161
+ UNIQUE (publisher_ref, symbol_type, source_instrument_id, start_date),
162
+ CHECK (start_date <= end_date)
163
+ );
164
+
165
+
166
+ PRAGMA user_version = 1;
@@ -0,0 +1,64 @@
1
+ from __future__ import annotations
2
+
3
+ import pathlib
4
+ import sqlite3
5
+
6
+
7
+ def create_secmaster_db(db_path: pathlib.Path, schema_version: int = 1) -> pathlib.Path:
8
+ """
9
+ Create a new security master SQLite database using a selected schema version.
10
+
11
+ The database file is created at the given path and initialized by executing the SQL script located in the `schema_versions` directory adjacent to this module.
12
+
13
+ The function expects the schema script to set `PRAGMA user_version` to the corresponding schema version and verifies this after execution.
14
+
15
+ Parameters:
16
+ db_path:
17
+ Filesystem path at which the SQLite database file will be created.
18
+ schema_version:
19
+ Version number selecting the schema script to apply.
20
+
21
+ Returns:
22
+ The path to the created database file.
23
+
24
+ Raises:
25
+ FileExistsError:
26
+ If a file already exists at `db_path`.
27
+ FileNotFoundError:
28
+ If the schema script for `schema_version` does not exist.
29
+ sqlite3.DatabaseError:
30
+ If the applied schema does not set the expected `user_version`
31
+ or if SQLite fails while executing the schema.
32
+ """
33
+ if db_path.exists():
34
+ raise FileExistsError(f"Database already exists: {db_path}")
35
+
36
+ schema_path = (
37
+ pathlib.Path(__file__).resolve().parent
38
+ / "schema_versions"
39
+ / f"secmaster_schema_v{schema_version}.sql"
40
+ )
41
+
42
+ if not schema_path.is_file():
43
+ raise FileNotFoundError(
44
+ f"Schema version {schema_version} not found: {schema_path}"
45
+ )
46
+
47
+ db_path.parent.mkdir(parents=True, exist_ok=True)
48
+
49
+ schema_sql = schema_path.read_text(encoding="utf-8")
50
+
51
+ with sqlite3.connect(str(db_path)) as con:
52
+ con.execute("PRAGMA foreign_keys = ON;")
53
+ con.executescript(schema_sql)
54
+
55
+ row = con.execute("PRAGMA user_version;").fetchone()
56
+ actual_version = int(row[0]) if row else 0
57
+
58
+ if actual_version != schema_version:
59
+ raise sqlite3.DatabaseError(
60
+ f"Schema script set user_version={actual_version}, "
61
+ f"expected {schema_version}"
62
+ )
63
+
64
+ return db_path
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onesecondtrader
3
- Version: 0.51.0
3
+ Version: 0.52.0
4
4
  Summary: The Trading Infrastructure Toolkit for Python. Research, simulate, and deploy algorithmic trading strategies — all in one place.
5
5
  License-File: LICENSE
6
6
  Author: Nils P. Kujath
@@ -34,7 +34,11 @@ onesecondtrader/models/bar_period.py,sha256=J8ncVtcAxR52uD0nbC8Knds_GUP5wiuNj5rA
34
34
  onesecondtrader/models/order_types.py,sha256=SiJamarLQ7zkHzHLLbd86I_TeZrQJ4QEIMqNHj4dxXU,737
35
35
  onesecondtrader/models/rejection_reasons.py,sha256=Avp1JYf413_aUQQkEeswI-9EJBmQdd7B6bnQ1MslDNE,2132
36
36
  onesecondtrader/models/trade_sides.py,sha256=Pf9BpxoUxqgKC_EKAExfSqgfIIK9NW-RpJES0XHRF-8,583
37
- onesecondtrader-0.51.0.dist-info/METADATA,sha256=5qFkty3l7BfcTm5Ah9vlUWOEi7Ad7jtSYAj5KUNVGMo,9951
38
- onesecondtrader-0.51.0.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
39
- onesecondtrader-0.51.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
40
- onesecondtrader-0.51.0.dist-info/RECORD,,
37
+ onesecondtrader/secmaster/__init__.py,sha256=miFKJ50zz3STh2HktAjYX8fPD8mzgWipr2EeiZfKdoM,95
38
+ onesecondtrader/secmaster/schema_versions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
+ onesecondtrader/secmaster/schema_versions/secmaster_schema_v1.sql,sha256=-IeHE-nO0j8hJfgvaN07_0o4zoZ2oCsvSTncCUbrfvk,11540
40
+ onesecondtrader/secmaster/utils.py,sha256=kh7djz1o8Yxl2lSMqu1oqWYs7l8_FNMaDb_8yvItIbQ,2172
41
+ onesecondtrader-0.52.0.dist-info/METADATA,sha256=gKzl22R5cIZ8laToY-fDdURwaMDr4udUpNc3aBsVb3o,9951
42
+ onesecondtrader-0.52.0.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
43
+ onesecondtrader-0.52.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
44
+ onesecondtrader-0.52.0.dist-info/RECORD,,