-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtest_historical_data.py
More file actions
169 lines (132 loc) · 4 KB
/
test_historical_data.py
File metadata and controls
169 lines (132 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import pytest
import databento
from databento.common.constants import SCHEMA_STRUCT_MAP
def test_mbo_fields() -> None:
"""
Test that columns match the MBO struct.
"""
# Arrange
struct = SCHEMA_STRUCT_MAP[databento.Schema.MBO]
fields = set(f for f in dir(struct) if not f.startswith(("_", "pretty_")))
fields.remove("record_size")
fields.remove("size_hint")
fields.remove("ts_index")
fields.remove("ts_out")
# Act
difference = fields.symmetric_difference(struct._ordered_fields)
# Assert
assert not difference
@pytest.mark.parametrize(
"schema,level_count",
[
(databento.Schema.TBBO, 1),
(databento.Schema.MBP_1, 1),
(databento.Schema.MBP_10, 10),
],
)
def test_mbp_fields(
schema: databento.Schema,
level_count: int,
) -> None:
"""
Test that columns match the MBP structs.
"""
# Arrange
struct = SCHEMA_STRUCT_MAP[schema]
fields = set(f for f in dir(struct) if not f.startswith(("_", "pretty_")))
fields.remove("record_size")
fields.remove("size_hint")
fields.remove("ts_index")
fields.remove("ts_out")
# Act
difference = fields.symmetric_difference(struct._ordered_fields)
# Assert
assert "levels" in difference
# bid/ask size, price, ct for each level, plus the levels field
assert len(difference) == 6 * level_count + 1
@pytest.mark.parametrize(
"schema",
[
databento.Schema.OHLCV_1S,
databento.Schema.OHLCV_1M,
databento.Schema.OHLCV_1H,
databento.Schema.OHLCV_1D,
],
)
def test_ohlcv_fields(
schema: databento.Schema,
) -> None:
"""
Test that columns match the OHLCV structs.
"""
# Arrange
struct = SCHEMA_STRUCT_MAP[schema]
fields = set(f for f in dir(struct) if not f.startswith(("_", "pretty_")))
fields.remove("record_size")
fields.remove("size_hint")
fields.remove("ts_index")
fields.remove("ts_out")
# Act
difference = fields.symmetric_difference(struct._ordered_fields)
# Assert
assert not difference
def test_trades_struct() -> None:
"""
Test that columns match the Trades struct.
"""
# Arrange
struct = SCHEMA_STRUCT_MAP[databento.Schema.TRADES]
fields = set(f for f in dir(struct) if not f.startswith(("_", "pretty_")))
fields.remove("record_size")
fields.remove("size_hint")
fields.remove("ts_index")
fields.remove("ts_out")
# Act
difference = fields.symmetric_difference(struct._ordered_fields)
# Assert
assert not difference
def test_definition_struct() -> None:
"""
Test that columns match the Definition struct.
"""
# Arrange
struct = SCHEMA_STRUCT_MAP[databento.Schema.DEFINITION]
fields = set(f for f in dir(struct) if not f.startswith(("_", "pretty_")))
fields.remove("record_size")
fields.remove("size_hint")
fields.remove("ts_index")
fields.remove("ts_out")
# Act
difference = fields.symmetric_difference(struct._ordered_fields)
# Assert
assert not difference
def test_imbalance_struct() -> None:
"""
Test that columns match the Imbalance struct.
"""
# Arrange
struct = SCHEMA_STRUCT_MAP[databento.Schema.IMBALANCE]
fields = set(f for f in dir(struct) if not f.startswith(("_", "pretty_")))
fields.remove("record_size")
fields.remove("size_hint")
fields.remove("ts_index")
fields.remove("ts_out")
# Act
difference = fields.symmetric_difference(struct._ordered_fields)
# Assert
assert not difference
def test_statistics_struct() -> None:
"""
Test that columns match the Statistics struct.
"""
# Arrange
struct = SCHEMA_STRUCT_MAP[databento.Schema.STATISTICS]
fields = set(f for f in dir(struct) if not f.startswith(("_", "pretty_")))
fields.remove("record_size")
fields.remove("size_hint")
fields.remove("ts_index")
fields.remove("ts_out")
# Act
difference = fields.symmetric_difference(struct._ordered_fields)
# Assert
assert not difference