Added klines, liquidations, tickers and trades to be recorded. Bundled the stats as cli argument.

This commit is contained in:
Kalzu Rekku
2026-07-22 15:35:33 +03:00
parent 270922fb78
commit f6765fdf07
15 changed files with 2719 additions and 495 deletions
+95
View File
@@ -20,6 +20,8 @@ type Config struct {
// LogFile is the optional path to a file where logs will be written.
LogFile string `json:"log_file"`
// --- Legacy fields (still used as defaults for trades stream) ---
// HotRetentionHours is how many hours of raw ticks to keep in the hot DB.
HotRetentionHours int `json:"hot_retention_hours"`
@@ -37,6 +39,58 @@ type Config struct {
// MaintenanceIntervalMinutes controls how often the hourly maintenance runs.
MaintenanceIntervalMinutes int `json:"maintenance_interval_minutes"`
// Streams holds per-stream configuration for multi-stream support.
Streams StreamsConfig `json:"streams"`
}
// StreamsConfig holds configuration for each data stream.
type StreamsConfig struct {
Trades TradesStreamConfig `json:"trades"`
Ticker TickerStreamConfig `json:"ticker"`
Klines KlinesStreamConfig `json:"klines"`
Orderbook OrderbookStreamConfig `json:"orderbook"`
Liquidations LiquidationsStreamConfig `json:"liquidations"`
}
// TradesStreamConfig controls the publicTrade stream behavior.
type TradesStreamConfig struct {
Enabled bool `json:"enabled"`
HotRetentionHours int `json:"hot_retention_hours"`
FeatureRetentionDays int `json:"feature_retention_days"`
}
// TickerStreamConfig controls the tickers stream behavior.
type TickerStreamConfig struct {
Enabled bool `json:"enabled"`
HotRetentionHours int `json:"hot_retention_hours"`
FeatureRetentionDays int `json:"feature_retention_days"`
SnapshotIntervalMs int `json:"snapshot_interval_ms"`
}
// KlinesStreamConfig controls the kline stream behavior.
type KlinesStreamConfig struct {
Enabled bool `json:"enabled"`
Intervals []string `json:"intervals"`
ShortRetentionHours int `json:"short_retention_hours"` // 5m, 15m candles
LongRetentionWeeks int `json:"long_retention_weeks"` // 60m candles
FeatureRetentionDays int `json:"feature_retention_days"`
}
// OrderbookStreamConfig controls the orderbook stream behavior.
type OrderbookStreamConfig struct {
Enabled bool `json:"enabled"`
Depth int `json:"depth"`
SnapshotIntervalMs int `json:"snapshot_interval_ms"`
HotRetentionHours int `json:"hot_retention_hours"`
FeatureRetentionDays int `json:"feature_retention_days"`
}
// LiquidationsStreamConfig controls the allLiquidation stream behavior.
type LiquidationsStreamConfig struct {
Enabled bool `json:"enabled"`
HotRetentionHours int `json:"hot_retention_hours"`
FeatureRetentionDays int `json:"feature_retention_days"`
}
// DefaultConfig returns a Config populated with sensible defaults.
@@ -52,6 +106,38 @@ func DefaultConfig() Config {
WriterBatchSize: 100,
TickChannelBuffer: 10000,
MaintenanceIntervalMinutes: 60,
Streams: StreamsConfig{
Trades: TradesStreamConfig{
Enabled: true,
HotRetentionHours: 12,
FeatureRetentionDays: 30,
},
Ticker: TickerStreamConfig{
Enabled: true,
HotRetentionHours: 24,
FeatureRetentionDays: 30,
SnapshotIntervalMs: 5000,
},
Klines: KlinesStreamConfig{
Enabled: true,
Intervals: []string{"5", "15", "60"},
ShortRetentionHours: 24,
LongRetentionWeeks: 4,
FeatureRetentionDays: 30,
},
Orderbook: OrderbookStreamConfig{
Enabled: true,
Depth: 50,
SnapshotIntervalMs: 5000,
HotRetentionHours: 6,
FeatureRetentionDays: 30,
},
Liquidations: LiquidationsStreamConfig{
Enabled: true,
HotRetentionHours: 12,
FeatureRetentionDays: 30,
},
},
}
}
@@ -75,6 +161,15 @@ func LoadConfig(path string) (Config, error) {
return cfg, fmt.Errorf("failed to parse config: %w", err)
}
// Apply backward compatibility: if streams.trades has zero retention,
// inherit from the legacy top-level fields.
if cfg.Streams.Trades.HotRetentionHours == 0 {
cfg.Streams.Trades.HotRetentionHours = cfg.HotRetentionHours
}
if cfg.Streams.Trades.FeatureRetentionDays == 0 {
cfg.Streams.Trades.FeatureRetentionDays = cfg.FeatureRetentionDays
}
return cfg, nil
}