Files
kingchenc 23d636fd97 Add the Go binding over the C ABI hub (#228)
Adds a Go binding (`bindings/go`) over the C ABI hub — the second language stecker after C#.

## What's here
- **`bindings/go`** — a cgo binding exposing all 514 indicators as idiomatic Go types with `New<Indicator>` constructors and `Update`/`Batch`/`Reset`/`Close` methods. The wrappers in `indicators_gen.go` are generated from `bindings/c/include/wickra.h` (same archetype taxonomy as the C# generator: scalar/batch, multi-output, bars, profile, profile-values, array-input). Opaque handles are freed by `Close()` with a `runtime.SetFinalizer` backstop; pointer arguments are caller-owned, panics never cross the boundary.
- **`examples/go`** — the full example suite mirroring C/C#: streaming, backtest, multi_timeframe, parallel_assets (goroutine fan-out), three strategies, and `fetch_btcusdt`/`live_binance`.
- **CI** — a `go` job builds the C ABI library, stages it, and runs `gofmt`/`go vet`/`go test` plus the offline examples on Linux, macOS and Windows.
- **Docs** — Go added to the README languages table, project layout, building/testing, CONTRIBUTING binding table + regenerate note, ARCHITECTURE, examples index, issue/PR templates, the About-description template, and the other binding READMEs.

## Linking / distribution
The binding links the prebuilt C ABI library via cgo (`libwickra.so`/`.dylib`/`wickra.dll` staged under `bindings/go/lib`, gitignored). The native libraries are already shipped per target triple by the existing `c-abi-build` release job; distribution is via the subdirectory module tag `bindings/go/vX.Y.Z` (gated), so `release.yml` needs no new publish job.

No Rust crate or `Cargo.toml` change — the Go module is standalone and additive.

Not for merge yet (gated, per request).
2026-06-09 17:33:37 +02:00

57 lines
1.4 KiB
Go

// Compute a basket of indicators over an OHLCV series and print a summary.
// Pass a CSV path (timestamp,open,high,low,close,volume) or run on synthetic data.
package main
import (
"fmt"
"log"
"math"
"os"
wickra "github.com/wickra-lib/wickra/bindings/go"
"github.com/wickra-lib/wickra/examples/go/internal/market"
)
func main() {
source := "synthetic"
var bars []market.Bar
if len(os.Args) > 1 {
source = os.Args[1]
loaded, err := market.LoadOhlcvCsv(os.Args[1])
if err != nil {
log.Fatalf("load csv: %v", err)
}
bars = loaded
} else {
bars = market.SyntheticCandles(1000)
}
fmt.Printf("Backtest over %d bars (%s):\n", len(bars), source)
sma, _ := wickra.NewSma(20)
defer sma.Close()
ema, _ := wickra.NewEma(50)
defer ema.Close()
rsi, _ := wickra.NewRsi(14)
defer rsi.Close()
atr, _ := wickra.NewAtr(14)
defer atr.Close()
var lastSma, lastEma, lastRsi, lastAtr float64
oversold := 0
for _, b := range bars {
lastSma = sma.Update(b.Close)
lastEma = ema.Update(b.Close)
lastRsi = rsi.Update(b.Close)
lastAtr = atr.Update(b.Open, b.High, b.Low, b.Close, b.Volume, b.Timestamp)
if !math.IsNaN(lastRsi) && lastRsi < 30.0 {
oversold++
}
}
fmt.Printf(" SMA(20) last = %.4f\n", lastSma)
fmt.Printf(" EMA(50) last = %.4f\n", lastEma)
fmt.Printf(" RSI(14) last = %.4f (%d oversold bars)\n", lastRsi, oversold)
fmt.Printf(" ATR(14) last = %.4f\n", lastAtr)
}