ghosalquant 0.2.0__tar.gz → 0.2.1__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.
- {ghosalquant-0.2.0/src/ghosalquant.egg-info → ghosalquant-0.2.1}/PKG-INFO +1 -1
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/__init__.py +1 -1
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/recording/storage.py +49 -27
- {ghosalquant-0.2.0 → ghosalquant-0.2.1/src/ghosalquant.egg-info}/PKG-INFO +1 -1
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_recording.py +34 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/LICENSE +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/README.md +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/pyproject.toml +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/setup.cfg +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/backtest_ui/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/backtest_ui/__main__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/backtest_ui/app.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/backtest_ui/runner.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/backtester/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/backtester/backtester_base.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/backtester/dataframe_backtester.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/bench/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/bench/benchmark_buy_and_hold.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/bench/benchmark_trend_vol_target.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/blocks/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/blocks/nodes.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/blocks/runner.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/blocks/schema.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/blocks/strategy.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/broker_base.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/builder.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/commissions.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/fills.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/ibkr.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/open_orders.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/order_book_sim.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/simulated.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/brokerage/simulation.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/compatibility/legacybacktester.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/compatibility/plotManager.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/compatibility/test_strategy.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/compatibility/trade.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/core/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/core/blackscholes.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/core/contracts.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/core/depth.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/core/metadata_keys.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/core/types.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/core/volatility.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/cboe_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/dataLayer.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/dataframe_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/datasource_base.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/datasource_factory.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/dolt_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/listEditor.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/list_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/live_alpaca_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/live_ibkr_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/live_polygon_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/merge.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/nse_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/parquet_polygon_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/recording_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/shocks.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/staticUpdater.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/yfinance_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/yfinance_multi_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/execution/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/execution/context.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/execution/execution_system.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/execution/sinks.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/execution/strategy_base.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/metrics/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/metrics/gates.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/metrics/markouts.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/metrics/risk_adjusted.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/portfolio/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/portfolio/attribution.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/portfolio/basic_portfolio.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/portfolio/fair_value.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/portfolio/hedging.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/portfolio/lots.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/portfolio/marks.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/portfolio/portfolio_base.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/portfolio/valuation.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/recording/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/recording/events.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/recording/intervals.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/recording/recorder.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/builder.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/buying_power.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/cash_allocation.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/risk_manager.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_buying_power.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_confidence_sizer.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_correlation_filter.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_drawdown_killswitch.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_integer_quantity.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_kelly_sizer.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_long_only.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_max_open_positions.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_max_symbol_exposure.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_price_collar.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_regime_filter.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_signal_quantity_cap.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_symbol_capital_sizer.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_tick_rounding.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/sizing.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/types.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/state/__init__.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/state/atomic.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/state/event_store.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/state/json_store.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/util/backtester_utils.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/util/config.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/util/deprecation.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/util/rounding.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/util/visualisation.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant.egg-info/SOURCES.txt +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant.egg-info/dependency_links.txt +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant.egg-info/entry_points.txt +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant.egg-info/requires.txt +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant.egg-info/top_level.txt +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_backtester.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_blocks.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_cboe_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_config.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_contracts.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_depth.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_dolt_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_example_options_momentum.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_example_order_book.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_execution.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_execution_loop.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_execution_order_book.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_fair_value.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_ibkr_broker.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_ibkr_real_client.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_legacy_backtester.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_limit_orders.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_live_sources.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_markouts.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_metrics.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_nse_datasource.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_order_book_sim_broker.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_order_book_types.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_pre_trade_rules.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_public_api.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_replace_orders.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_risk_rules.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_shocks.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_state.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_valuation.py +0 -0
- {ghosalquant-0.2.0 → ghosalquant-0.2.1}/tests/test_volatility.py +0 -0
|
@@ -18,6 +18,8 @@ DEFAULT_ROTATE_SECONDS = 24 * 60 * 60
|
|
|
18
18
|
DEFAULT_MIN_AGE_ROTATION_BYTES = 1024 * 1024
|
|
19
19
|
DEFAULT_BATCH_ROWS = 4096
|
|
20
20
|
SEGMENT_SCHEMA_VERSION = 1
|
|
21
|
+
# A segment's name starts with when its records start, in UTC; older names put `.ffffffZ` after the seconds.
|
|
22
|
+
SEGMENT_TIME_FORMAT = "%Y%m%dT%H%M%S"
|
|
21
23
|
|
|
22
24
|
STORAGE_METADATA_KEY = b"ghosalquant_storage"
|
|
23
25
|
STORAGE_METADATA_VALUE = b"segmented_recorder"
|
|
@@ -96,7 +98,7 @@ class SegmentedParquetWriter:
|
|
|
96
98
|
if self.segments_dir.is_dir():
|
|
97
99
|
self._recover_unsealed_logs()
|
|
98
100
|
if self.path.is_file() and self.path.stat().st_size >= self.rotate_bytes:
|
|
99
|
-
self.
|
|
101
|
+
compact_jsonl_segment(self._move_log_into_segments())
|
|
100
102
|
self._active_path = self._next_active_path()
|
|
101
103
|
self._open_active()
|
|
102
104
|
except Exception:
|
|
@@ -131,11 +133,7 @@ class SegmentedParquetWriter:
|
|
|
131
133
|
return None
|
|
132
134
|
|
|
133
135
|
self._file.close()
|
|
134
|
-
raw_segment = self._active_path
|
|
135
|
-
if raw_segment == self.path:
|
|
136
|
-
self.segments_dir.mkdir(parents=True, exist_ok=True)
|
|
137
|
-
raw_segment = self.segments_dir / f"segment-{_segment_id()}.jsonl"
|
|
138
|
-
retry_while_locked(lambda: self.path.replace(raw_segment))
|
|
136
|
+
raw_segment = self._move_log_into_segments() if self._active_path == self.path else self._active_path
|
|
139
137
|
try:
|
|
140
138
|
return compact_jsonl_segment(raw_segment)
|
|
141
139
|
finally:
|
|
@@ -184,11 +182,11 @@ class SegmentedParquetWriter:
|
|
|
184
182
|
for raw_path in sorted(self.segments_dir.glob("segment-*.jsonl")):
|
|
185
183
|
compact_jsonl_segment(raw_path)
|
|
186
184
|
|
|
187
|
-
def
|
|
185
|
+
def _move_log_into_segments(self) -> Path:
|
|
188
186
|
self.segments_dir.mkdir(parents=True, exist_ok=True)
|
|
189
|
-
raw_segment = self.segments_dir / f"segment-{_segment_id()}.jsonl"
|
|
187
|
+
raw_segment = self.segments_dir / f"segment-{_segment_id(_first_record_time(self.path))}.jsonl"
|
|
190
188
|
retry_while_locked(lambda: self.path.replace(raw_segment))
|
|
191
|
-
|
|
189
|
+
return raw_segment
|
|
192
190
|
|
|
193
191
|
def _acquire_lock(self) -> None:
|
|
194
192
|
lock_path = self.path.with_suffix(".writer.lock")
|
|
@@ -239,24 +237,34 @@ def discover_logical_streams(root: str | Path) -> list[Path]:
|
|
|
239
237
|
|
|
240
238
|
|
|
241
239
|
def stream_source_files(logical_path: str | Path) -> list[Path]:
|
|
242
|
-
"""
|
|
240
|
+
"""
|
|
241
|
+
The files backing a stream in time order, sealed segments preferred over their unsealed logs.
|
|
242
|
+
|
|
243
|
+
A log beside the segments goes before the first one that starts after it.
|
|
244
|
+
"""
|
|
243
245
|
logical = Path(logical_path)
|
|
244
|
-
|
|
245
|
-
if logical.is_file():
|
|
246
|
-
paths.append(logical)
|
|
246
|
+
segments: list[Path] = []
|
|
247
247
|
segments_dir = segments_dir_for(logical)
|
|
248
|
-
if
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
248
|
+
if segments_dir.is_dir():
|
|
249
|
+
by_stem: dict[str, dict[str, Path]] = {}
|
|
250
|
+
for path in segments_dir.glob("segment-*"):
|
|
251
|
+
if not path.is_file() or path.suffix not in {".jsonl", ".parquet"}:
|
|
252
|
+
continue
|
|
253
|
+
by_stem.setdefault(path.stem, {})[path.suffix] = path
|
|
254
|
+
segments = [by_stem[stem].get(".parquet") or by_stem[stem][".jsonl"] for stem in sorted(by_stem)]
|
|
255
|
+
if not logical.is_file():
|
|
256
|
+
return segments
|
|
257
|
+
|
|
258
|
+
started = _first_record_time(logical) if segments else None
|
|
259
|
+
if started is None:
|
|
260
|
+
return [logical, *segments]
|
|
261
|
+
before = len(segments)
|
|
262
|
+
for index, path in enumerate(segments):
|
|
263
|
+
segment_started = _segment_started_at(path)
|
|
264
|
+
if segment_started is not None and segment_started > started:
|
|
265
|
+
before = index
|
|
266
|
+
break
|
|
267
|
+
return [*segments[:before], logical, *segments[before:]]
|
|
260
268
|
|
|
261
269
|
|
|
262
270
|
def iter_stream_records(logical_path: str | Path) -> Iterator[dict[str, Any]]:
|
|
@@ -606,5 +614,19 @@ def _unlock(handle) -> None:
|
|
|
606
614
|
fcntl.flock(handle.fileno(), fcntl.LOCK_UN)
|
|
607
615
|
|
|
608
616
|
|
|
609
|
-
def _segment_id() -> str:
|
|
610
|
-
|
|
617
|
+
def _segment_id(started: datetime | None = None) -> str:
|
|
618
|
+
at = (started or datetime.now(timezone.utc)).astimezone(timezone.utc)
|
|
619
|
+
return f"{at.strftime(SEGMENT_TIME_FORMAT)}{at:%f}-{uuid4().hex[:8]}"
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
def _segment_started_at(path: Path) -> datetime | None:
|
|
623
|
+
seconds = path.stem.removeprefix("segment-")[: len("YYYYmmddTHHMMSS")]
|
|
624
|
+
try:
|
|
625
|
+
return datetime.strptime(seconds, SEGMENT_TIME_FORMAT).replace(tzinfo=timezone.utc)
|
|
626
|
+
except ValueError:
|
|
627
|
+
return None
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
def _first_record_time(path: Path) -> datetime | None:
|
|
631
|
+
first = next(_iter_jsonl_records(path), None)
|
|
632
|
+
return None if first is None else record_time(first[1])
|
|
@@ -109,6 +109,40 @@ def test_sealed_segment_is_preferred_over_a_stale_copy_of_its_log(tmp_path):
|
|
|
109
109
|
assert stale not in storage.stream_source_files(path)
|
|
110
110
|
|
|
111
111
|
|
|
112
|
+
def test_a_log_beside_segments_is_read_in_time_order(tmp_path):
|
|
113
|
+
path = tmp_path / "stream.jsonl"
|
|
114
|
+
segments = storage.segments_dir_for(path)
|
|
115
|
+
segments.mkdir()
|
|
116
|
+
for minutes, index in ((0, 1), (5, 3)):
|
|
117
|
+
opened = T0 + timedelta(minutes=minutes)
|
|
118
|
+
(segments / f"segment-{opened:%Y%m%dT%H%M%S%f}-{index:08x}.jsonl").write_text(
|
|
119
|
+
json.dumps({"observed_at": opened.isoformat(), "index": index}) + "\n", encoding="utf-8"
|
|
120
|
+
)
|
|
121
|
+
path.write_text(
|
|
122
|
+
json.dumps({"observed_at": (T0 + timedelta(minutes=2)).isoformat(), "index": 2}) + "\n", encoding="utf-8"
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
assert [row["index"] for row in storage.iter_stream_records(path)] == [1, 2, 3]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_a_sealed_log_keeps_its_place_among_the_segments(tmp_path):
|
|
129
|
+
path = tmp_path / "stream.jsonl"
|
|
130
|
+
segments = storage.segments_dir_for(path)
|
|
131
|
+
segments.mkdir()
|
|
132
|
+
later = T0 + timedelta(minutes=5)
|
|
133
|
+
(segments / f"segment-{later:%Y%m%dT%H%M%S%f}-00000003.jsonl").write_text(
|
|
134
|
+
json.dumps({"observed_at": later.isoformat(), "index": 3}) + "\n", encoding="utf-8"
|
|
135
|
+
)
|
|
136
|
+
path.write_text(
|
|
137
|
+
json.dumps({"observed_at": (T0 + timedelta(minutes=2)).isoformat(), "index": 2}) + "\n", encoding="utf-8"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
storage.SegmentedParquetWriter(path, rotate_bytes=1).close()
|
|
141
|
+
|
|
142
|
+
assert not path.exists()
|
|
143
|
+
assert [row["index"] for row in storage.iter_stream_records(path)] == [2, 3]
|
|
144
|
+
|
|
145
|
+
|
|
112
146
|
def test_duplicated_records_are_not_counted_twice(tmp_path):
|
|
113
147
|
path = tmp_path / "stream.jsonl"
|
|
114
148
|
with storage.SegmentedParquetWriter(path) as writer:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/live_alpaca_datasource.py
RENAMED
|
File without changes
|
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/live_polygon_datasource.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/parquet_polygon_datasource.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/data_layer/yfinance_multi_datasource.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_correlation_filter.py
RENAMED
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_drawdown_killswitch.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_max_open_positions.py
RENAMED
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_max_symbol_exposure.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_signal_quantity_cap.py
RENAMED
|
File without changes
|
{ghosalquant-0.2.0 → ghosalquant-0.2.1}/src/ghosalquant/risk/rules/rule_symbol_capital_sizer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|