0
# Tick Store Operations
1
2
High-frequency tick data storage with efficient columnar compression and time-based partitioning. Optimized for financial tick data with support for initial images, metadata persistence, and date range queries for maximum performance with large volumes of timestamped market data.
3
4
## Capabilities
5
6
### TickStore Class
7
8
High-frequency tick data store optimized for financial market data with efficient columnar storage and date-based partitioning.
9
10
```python { .api }
11
class TickStore:
12
"""
13
Tick-specific storage optimized for high-frequency financial data.
14
15
Provides columnar storage for tick data with efficient compression,
16
supports initial images for maintaining state, and enables fast
17
date range queries for market data analysis.
18
"""
19
20
def __init__(self, arctic_lib, chunk_size=100000):
21
"""
22
Initialize TickStore with configurable chunk size.
23
24
Parameters:
25
- arctic_lib: ArcticLibraryBinding instance
26
- chunk_size: Number of ticks per chunk (default: 100,000)
27
"""
28
```
29
30
### Symbol Management
31
32
Operations for managing tick data symbols including listing, deletion, and existence checking.
33
34
```python { .api }
35
def list_symbols(self, date_range=None):
36
"""
37
List available symbols, optionally filtered by date range.
38
39
Parameters:
40
- date_range: DateRange object to filter symbols by data availability
41
42
Returns:
43
List of symbol names that have tick data
44
"""
45
46
def delete(self, symbol, date_range=None):
47
"""
48
Delete symbol or specific date range of tick data.
49
50
Parameters:
51
- symbol: Symbol name to delete
52
- date_range: Specific date range to delete (default: all data)
53
54
Raises:
55
- NoDataFoundException: If symbol doesn't exist
56
"""
57
```
58
59
### Read Operations
60
61
Methods for retrieving tick data with date filtering, column selection, and image handling.
62
63
```python { .api }
64
def read(self, symbol, date_range=None, columns=None, include_images=False,
65
allow_secondary=None, **kwargs):
66
"""
67
Read tick data with flexible filtering and column selection.
68
69
Parameters:
70
- symbol: Symbol name to read
71
- date_range: DateRange object for temporal filtering
72
- columns: List of columns to return (default: all columns)
73
- include_images: Include initial images in results (default: False)
74
- allow_secondary: Allow reads from MongoDB secondary nodes
75
- **kwargs: Additional read parameters
76
77
Returns:
78
pandas.DataFrame: Tick data with timestamp index
79
80
Raises:
81
- NoDataFoundException: If symbol or date range has no data
82
"""
83
84
def read_metadata(self, symbol):
85
"""
86
Read symbol metadata without loading tick data.
87
88
Parameters:
89
- symbol: Symbol name
90
91
Returns:
92
dict: Symbol metadata including data statistics
93
94
Raises:
95
- NoDataFoundException: If symbol doesn't exist
96
"""
97
```
98
99
### Write Operations
100
101
Methods for storing tick data with initial image support and metadata persistence.
102
103
```python { .api }
104
def write(self, symbol, data, initial_image=None, metadata=None):
105
"""
106
Write tick data with optional initial image and metadata.
107
108
Parameters:
109
- symbol: Symbol name to write
110
- data: Tick data as pandas DataFrame with timestamp index
111
- initial_image: Dictionary representing initial state/image
112
- metadata: Optional metadata dictionary
113
114
Raises:
115
- OverlappingDataException: If data overlaps with existing ticks
116
- UnorderedDataException: If data not properly time-ordered
117
- UnhandledDtypeException: If data contains unsupported types
118
"""
119
```
120
121
### Date Range Operations
122
123
Methods for querying date boundaries and data availability for symbols.
124
125
```python { .api }
126
def max_date(self, symbol):
127
"""
128
Get maximum (latest) date for symbol's tick data.
129
130
Parameters:
131
- symbol: Symbol name
132
133
Returns:
134
datetime: Latest timestamp in the data
135
136
Raises:
137
- NoDataFoundException: If symbol has no data
138
"""
139
140
def min_date(self, symbol):
141
"""
142
Get minimum (earliest) date for symbol's tick data.
143
144
Parameters:
145
- symbol: Symbol name
146
147
Returns:
148
datetime: Earliest timestamp in the data
149
150
Raises:
151
- NoDataFoundException: If symbol has no data
152
"""
153
```
154
155
### Statistics and Information
156
157
Methods for retrieving storage statistics and performance information.
158
159
```python { .api }
160
def stats(self):
161
"""
162
Get tick store statistics and performance metrics.
163
164
Returns:
165
dict: Statistics including symbol counts, storage usage, chunk info
166
"""
167
```
168
169
## Usage Examples
170
171
### Basic Tick Data Operations
172
173
```python
174
from arctic import Arctic, TICK_STORE
175
import pandas as pd
176
import numpy as np
177
from datetime import datetime
178
179
# Setup tick store
180
arctic_conn = Arctic('mongodb://localhost:27017')
181
arctic_conn.initialize_library('ticks', TICK_STORE)
182
tick_lib = arctic_conn['ticks']
183
184
# Create sample tick data
185
timestamps = pd.date_range('2020-01-01 09:30:00',
186
'2020-01-01 16:00:00',
187
freq='100ms')
188
189
tick_data = pd.DataFrame({
190
'bid': np.random.uniform(99.95, 100.05, len(timestamps)),
191
'ask': np.random.uniform(100.00, 100.10, len(timestamps)),
192
'bid_size': np.random.randint(100, 1000, len(timestamps)),
193
'ask_size': np.random.randint(100, 1000, len(timestamps)),
194
'trade_price': np.random.uniform(99.98, 100.08, len(timestamps)),
195
'trade_size': np.random.randint(100, 5000, len(timestamps))
196
}, index=timestamps)
197
198
# Write tick data with initial image
199
initial_image = {
200
'opening_price': 100.00,
201
'previous_close': 99.95,
202
'session_date': '2020-01-01'
203
}
204
205
metadata = {
206
'exchange': 'NYSE',
207
'symbol_type': 'equity',
208
'currency': 'USD'
209
}
210
211
tick_lib.write('AAPL', tick_data,
212
initial_image=initial_image,
213
metadata=metadata)
214
```
215
216
### Reading Tick Data with Filtering
217
218
```python
219
from arctic.date import DateRange
220
221
# Read all tick data
222
all_ticks = tick_lib.read('AAPL')
223
print(f"Total ticks: {len(all_ticks)}")
224
225
# Read specific time range (morning session)
226
morning_range = DateRange(
227
datetime(2020, 1, 1, 9, 30),
228
datetime(2020, 1, 1, 12, 0)
229
)
230
morning_ticks = tick_lib.read('AAPL', date_range=morning_range)
231
print(f"Morning ticks: {len(morning_ticks)}")
232
233
# Read specific columns only
234
price_data = tick_lib.read('AAPL',
235
columns=['bid', 'ask', 'trade_price'])
236
print(f"Price columns: {list(price_data.columns)}")
237
238
# Read with initial images
239
ticks_with_images = tick_lib.read('AAPL', include_images=True)
240
# Images are included as special rows in the DataFrame
241
```
242
243
### Date Range Queries
244
245
```python
246
# Get data boundaries
247
earliest = tick_lib.min_date('AAPL')
248
latest = tick_lib.max_date('AAPL')
249
print(f"Data range: {earliest} to {latest}")
250
251
# List symbols with data in specific date range
252
symbols_today = tick_lib.list_symbols(
253
date_range=DateRange(datetime(2020, 1, 1), datetime(2020, 1, 2))
254
)
255
print(f"Symbols with data today: {symbols_today}")
256
257
# Check metadata
258
metadata = tick_lib.read_metadata('AAPL')
259
print(f"Symbol metadata: {metadata}")
260
```
261
262
### Multiple Symbol Management
263
264
```python
265
# Write data for multiple symbols
266
symbols = ['AAPL', 'GOOGL', 'MSFT']
267
268
for i, symbol in enumerate(symbols):
269
# Generate different data for each symbol
270
symbol_ticks = tick_data * (1 + i * 0.1) # Price variation
271
symbol_ticks.index = timestamps # Same time range
272
273
tick_lib.write(symbol, symbol_ticks, metadata={
274
'symbol': symbol,
275
'sector': 'technology',
276
'listing': 'NASDAQ' if symbol != 'AAPL' else 'NYSE'
277
})
278
279
# List all available symbols
280
all_symbols = tick_lib.list_symbols()
281
print(f"Available symbols: {all_symbols}")
282
283
# Get statistics
284
stats = tick_lib.stats()
285
print(f"Tick store statistics: {stats}")
286
```
287
288
### Advanced Tick Data Operations
289
290
```python
291
# Append additional tick data (must be non-overlapping)
292
additional_timestamps = pd.date_range('2020-01-01 16:00:01',
293
'2020-01-01 17:00:00',
294
freq='100ms')
295
296
additional_ticks = pd.DataFrame({
297
'bid': np.random.uniform(100.00, 100.10, len(additional_timestamps)),
298
'ask': np.random.uniform(100.05, 100.15, len(additional_timestamps)),
299
'bid_size': np.random.randint(100, 1000, len(additional_timestamps)),
300
'ask_size': np.random.randint(100, 1000, len(additional_timestamps)),
301
'trade_price': np.random.uniform(100.03, 100.13, len(additional_timestamps)),
302
'trade_size': np.random.randint(100, 5000, len(additional_timestamps))
303
}, index=additional_timestamps)
304
305
# Note: TickStore doesn't have an append method, so you would typically
306
# write new data to a different date range or use update operations
307
308
# Delete specific date range
309
lunch_range = DateRange(
310
datetime(2020, 1, 1, 12, 0),
311
datetime(2020, 1, 1, 13, 30)
312
)
313
tick_lib.delete('AAPL', date_range=lunch_range)
314
315
# Verify deletion
316
remaining_ticks = tick_lib.read('AAPL')
317
print(f"Ticks after deletion: {len(remaining_ticks)}")
318
```
319
320
### Performance Optimization
321
322
```python
323
# Use custom chunk size for better performance
324
from arctic.tickstore import TickStore
325
326
# Larger chunks for less frequent access
327
large_chunk_lib = TickStore(arctic_conn['ticks'], chunk_size=500000)
328
329
# Smaller chunks for more frequent random access
330
small_chunk_lib = TickStore(arctic_conn['ticks'], chunk_size=50000)
331
332
# Read from secondary for analytics (doesn't need latest data)
333
analytics_data = tick_lib.read('AAPL',
334
date_range=morning_range,
335
allow_secondary=True)
336
337
# Column filtering for bandwidth efficiency
338
trades_only = tick_lib.read('AAPL',
339
columns=['trade_price', 'trade_size'])
340
```