This is a minimal Go project scaffold modeled after tr to get you started with multi-timeframe OHLC aggregation and streaming processing.
cmd/tr- main executableinternal/config- config loader (simple)internal/server- minimal HTTP server (health route)pkg/trader- demo trader with aggregators and forwardingpkg/timeframe- timeframe definitions (M1, M5, M15, M30, H1, H4, D1, WK, MN)pkg/ohlc- OHLC bar aggregation (batch and streaming)
cd /path/to/repo
go build ./...go run ./cmd/tr -port 8080Open http://localhost:8080/ or http://localhost:8080/health
Run all tests:
go test ./...Run pkg/ohlc tests specifically:
go test ./pkg/ohlc -vExpected output: 8 passed, 1 skipped
Run benchmarks with memory stats:
go test ./pkg/ohlc -bench . -benchmem -run ^$Typical results (Apple M1):
BenchmarkAggregator_AddTick-8 47M ops/sec 23.05 ns/op 1 B/op 0 allocs/op
BenchmarkChain_M1ToH1-8 42M ops/sec 28.34 ns/op 1 B/op 0 allocs/op
Performance notes:
- Single aggregator: ~23 nanoseconds per tick
- Full chain (M1→M5→M15→M30→H1): ~28 nanoseconds per tick
- Zero heap allocations (GC-friendly)
- Memory overhead: 1 byte per operation (buffered channel semantics)
For reproducible results on multi-core systems:
# Run with single CPU core
GOMAXPROCS=1 go test ./pkg/ohlc -bench . -benchmem
# Run with specific concurrency
GOMAXPROCS=4 go test ./pkg/ohlc -bench . -benchmemHardware recommendations:
- Development: Any modern CPU (M1/Intel/AMD)
- Benchmarking: Run on consistent hardware (avoid thermal throttling)
- Production: 2+ cores recommended for typical tick rates
The pkg/ohlc package provides streaming OHLC aggregation with hierarchical forwarding:
// Create aggregators for each timeframe
m1 := ohlc.NewAggregator(timeframe.M1)
m5 := ohlc.NewAggregator(timeframe.M5)
h1 := ohlc.NewAggregator(timeframe.H1)
// Wire forwarding: M1 bars → M5 → H1
go func() {
for bar := range m1.Completed {
m5.AddBar(bar)
}
}()
go func() {
for bar := range m5.Completed {
h1.AddBar(bar)
}
}()
// Feed ticks
tick := ohlc.Tick{Time: now, Price: 100.5, Volume: 10}
m1.AddTick(tick)
// Process completed bars
for bar := range h1.Completed {
// Strategy logic here
}- Unit tests: OHLC aggregation (batch & stream), boundary alignment
- Integration tests:
- M1→H1 hierarchical chain (61 min window)
- M1→D1 cross-midnight (跨日)
- D1→MN cross-month (跨月)
- Benchmarks: Throughput and memory efficiency
Run specific integration test:
go test ./pkg/ohlc -run TestHierarchicalAggregation_M1ToH1 -v
go test ./pkg/ohlc -run TestCrossDayBoundary_ChainedToD1 -v
go test ./pkg/ohlc -run TestCrossMonthBoundary_ChainedToMN_Simplified -v- Add CSV/Parquet data replay mode in
cmd/tr - Persist high-level bars to TSDB (e.g., InfluxDB)
- Implement trading strategy examples
- Add configuration file (YAML/TOML)
- Add CI pipeline (GitHub Actions)
- Extend benchmarks for high-concurrency scenarios