23d636fd97
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).
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// Download real BTCUSDT hourly klines from the Binance REST API into a CSV that the
|
|
// other examples can consume. Requires network access (build-only in CI).
|
|
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
const url = "https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1h&limit=500"
|
|
fmt.Printf("Fetching %s\n", url)
|
|
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
log.Fatalf("request: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
log.Fatalf("read body: %v", err)
|
|
}
|
|
|
|
// Binance kline array: [openTime, open, high, low, close, volume, ...].
|
|
var klines [][]any
|
|
if err := json.Unmarshal(body, &klines); err != nil {
|
|
log.Fatalf("parse json: %v", err)
|
|
}
|
|
|
|
dir := "data"
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
log.Fatalf("mkdir: %v", err)
|
|
}
|
|
path := filepath.Join(dir, "btcusdt_1h.csv")
|
|
file, err := os.Create(path)
|
|
if err != nil {
|
|
log.Fatalf("create: %v", err)
|
|
}
|
|
defer file.Close()
|
|
|
|
writer := bufio.NewWriter(file)
|
|
defer writer.Flush()
|
|
fmt.Fprintln(writer, "timestamp,open,high,low,close,volume")
|
|
count := 0
|
|
for _, k := range klines {
|
|
ts := int64(k[0].(float64))
|
|
fmt.Fprintf(writer, "%d,%s,%s,%s,%s,%s\n", ts, k[1], k[2], k[3], k[4], k[5])
|
|
count++
|
|
}
|
|
|
|
fmt.Printf("Wrote %d klines to %s\n", count, path)
|
|
}
|