examples: migrate to the native data layer (drop ws/coder-websocket/jackson/jsonlite) (#316)

Stacked on #315 (the native Binance REST fetcher). Retarget to `main` once #315 merges.

Migrates the runnable examples off third-party data-I/O packages onto Wickra's
native data layer (`CandleReader`, `Resampler`, `BinanceFeed`, `fetch_*klines`).

## Third-party packages removed (the zero-dep selling point)
- **Node**: `ws` (live feed → BinanceFeed) — dropped from package.json + lockfile
- **Go**: `github.com/coder/websocket` — dropped from go.mod / go.sum (`go mod tidy`)
- **Java**: `jackson-databind` (live feed + REST fetch) — dropped from pom.xml
- **R**: `jsonlite` + `websocket` + `later` — dropped from the README notes

Each language's CSV loading now goes through `CandleReader`, manual resampling
through `Resampler`, the live feed through `BinanceFeed`, and (Java/R) the REST
download through the native fetcher.

## Verification
Ran the offline examples per language against the bundled data — backtest and
multi_timeframe produce identical output across Python / Node / Go / Java / R
(e.g. ATR(14) last 345.1010; 1h→5m resamples to 240 bars, →15m to 80 bars).

C# / C / WASM (stdlib-only, no third-party deps to remove) follow in this branch.

Note: the streaming `strategy_*` examples have pre-existing candle-indicator
runtime bugs (CI only syntax-smokes them); the CSV migration preserves their
shape and leaves those bugs for a separate fix.
This commit is contained in:
kingchenc
2026-06-17 01:49:11 +02:00
committed by GitHub
parent 2ae76bb90e
commit 677ea37402
40 changed files with 576 additions and 1102 deletions
+13 -19
View File
@@ -3,7 +3,6 @@ package main
import (
"fmt"
"math"
wickra "github.com/wickra-lib/wickra/bindings/go"
"github.com/wickra-lib/wickra/examples/go/internal/market"
@@ -29,26 +28,21 @@ func resample(source []market.Bar, factor int) []market.Bar {
if factor <= 1 {
return source
}
// Native Resampler: bucket by an absolute timeframe (the synthetic bars step
// 60_000 ms, so factor minutes == factor*60_000 ms). No hand-written bucketing.
r, _ := wickra.NewResampler(int64(factor) * 60_000)
defer r.Close()
var out []market.Bar
for i := 0; i < len(source); i += factor {
end := i + factor
if end > len(source) {
end = len(source)
emit := func(c wickra.Candle) {
out = append(out, market.Bar{Open: c.Open, High: c.High, Low: c.Low, Close: c.Close, Volume: c.Volume, Timestamp: c.Timestamp})
}
for _, b := range source {
if c, ok := r.Update(b.Open, b.High, b.Low, b.Close, b.Volume, b.Timestamp); ok {
emit(c)
}
high, low, volume := math.Inf(-1), math.Inf(1), 0.0
for j := i; j < end; j++ {
high = math.Max(high, source[j].High)
low = math.Min(low, source[j].Low)
volume += source[j].Volume
}
out = append(out, market.Bar{
Open: source[i].Open,
High: high,
Low: low,
Close: source[end-1].Close,
Volume: volume,
Timestamp: source[i].Timestamp,
})
}
if c, ok := r.Flush(); ok {
emit(c)
}
return out
}