1.1 KiB
1.1 KiB
Key Features of this Implementation:
File Rotation Handling: The FileTailer continuously checks the directory for the newest file matching the pattern. If a new hourly file appears, it automatically switches to it.
OHLCV Logic:
Open: Set when a candle is first created for that timestamp bucket.
High/Low: Updated via max() and min().
Close: Updated with every new trade.
Buy Volume: Calculated by filtering trades where S == "Buy".
SQLite Upsert: Uses ON CONFLICT(timeframe, timestamp) DO UPDATE. This is crucial because trades for the same minute arrive sequentially; we need to update the existing row rather than creating duplicates.
Robustness:
Wrapped in try-except blocks to prevent the service from crashing on a single malformed line.
Comprehensive logging to both file and console.
Configurable polling interval (default 200ms).
To get the live, unfinished candle data:
code Bash
''' echo "live" | nc 127.0.0.1 9999 '''
To get the general health/status: code Bash
''' echo "status" | nc 127.0.0.1 9999 '''