2026-06-09 17:33:37 +02:00
|
|
|
// Stream live BTCUSDT 1-minute klines from Binance and feed each close through EMA(20).
|
2026-06-17 01:49:11 +02:00
|
|
|
// Uses Wickra's native BinanceFeed — no third-party WebSocket client. Requires
|
|
|
|
|
// network access (build-only in CI). Runs for up to 60 seconds.
|
2026-06-09 17:33:37 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
wickra "github.com/wickra-lib/wickra/bindings/go"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2026-06-17 01:49:11 +02:00
|
|
|
fmt.Println("Streaming live BTCUSDT 1-minute klines from Binance (up to 60s)...")
|
2026-06-09 17:33:37 +02:00
|
|
|
|
2026-06-17 01:49:11 +02:00
|
|
|
// Native feed: a blocking poll over the same tested stream as the Rust core.
|
|
|
|
|
feed, err := wickra.NewBinanceFeed("BTCUSDT", wickra.OneMinute, "")
|
2026-06-09 17:33:37 +02:00
|
|
|
if err != nil {
|
2026-06-17 01:49:11 +02:00
|
|
|
log.Fatalf("connect: %v", err)
|
2026-06-09 17:33:37 +02:00
|
|
|
}
|
2026-06-17 01:49:11 +02:00
|
|
|
defer feed.Close()
|
2026-06-09 17:33:37 +02:00
|
|
|
|
|
|
|
|
ema, _ := wickra.NewEma(20)
|
|
|
|
|
defer ema.Close()
|
|
|
|
|
|
2026-06-17 01:49:11 +02:00
|
|
|
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)
|
2026-06-09 17:33:37 +02:00
|
|
|
if err != nil {
|
2026-06-17 01:49:11 +02:00
|
|
|
fmt.Println("Done (feed closed).")
|
2026-06-09 17:33:37 +02:00
|
|
|
return
|
|
|
|
|
}
|
2026-06-17 01:49:11 +02:00
|
|
|
if !ok {
|
2026-06-09 17:33:37 +02:00
|
|
|
continue
|
|
|
|
|
}
|
2026-06-17 01:49:11 +02:00
|
|
|
fmt.Printf("close=%.2f EMA(20)=%.2f\n", event.Close, ema.Update(event.Close))
|
2026-06-09 17:33:37 +02:00
|
|
|
}
|
2026-06-17 01:49:11 +02:00
|
|
|
fmt.Println("Done (time limit reached).")
|
2026-06-09 17:33:37 +02:00
|
|
|
}
|