677ea37402
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.
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
// Stream live BTCUSDT 1-minute klines from Binance and feed each close through EMA(20).
|
|
// Uses Wickra's native BinanceFeed — no third-party WebSocket client. Requires
|
|
// network access (build-only in CI). Runs for up to 60 seconds.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
wickra "github.com/wickra-lib/wickra/bindings/go"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("Streaming live BTCUSDT 1-minute klines from Binance (up to 60s)...")
|
|
|
|
// Native feed: a blocking poll over the same tested stream as the Rust core.
|
|
feed, err := wickra.NewBinanceFeed("BTCUSDT", wickra.OneMinute, "")
|
|
if err != nil {
|
|
log.Fatalf("connect: %v", err)
|
|
}
|
|
defer feed.Close()
|
|
|
|
ema, _ := wickra.NewEma(20)
|
|
defer ema.Close()
|
|
|
|
deadline := time.Now().Add(60 * time.Second)
|
|
for time.Now().Before(deadline) {
|
|
// next() returns the event and ok=true, ok=false on timeout (poll again),
|
|
// or an error once the stream is closed.
|
|
event, ok, err := feed.Next(time.Second)
|
|
if err != nil {
|
|
fmt.Println("Done (feed closed).")
|
|
return
|
|
}
|
|
if !ok {
|
|
continue
|
|
}
|
|
fmt.Printf("close=%.2f EMA(20)=%.2f\n", event.Close, ema.Update(event.Close))
|
|
}
|
|
fmt.Println("Done (time limit reached).")
|
|
}
|