Install
openclaw skills install @psyb0t/go-trading212Typed Go client for Trading 212 Public API enabling account summary, positions, orders, history retrieval, and order placement via Go code.
openclaw skills install @psyb0t/go-trading212Unofficial, typed Go client for the Trading 212 Public API, in package trading212 at the module root.
For install, the full operation list, pagination and response fields, see references/setup.md.
TRADING212_API_KEY, TRADING212_API_SECRET). Never hardcode, commit or log them, and never print a request with its Authorization header.https://demo.trading212.com (paper trading) or https://live.trading212.com (real money). A key works only on the environment it was made for. Default to demo.github.com/psyb0t/go-trading212.AGENTS.md in the repo.import (
"context"
"fmt"
"net/http"
"os"
"github.com/psyb0t/go-trading212"
)
auth := trading212.WithRequestEditorFn(
func(_ context.Context, req *http.Request) error {
req.SetBasicAuth(
os.Getenv("TRADING212_API_KEY"),
os.Getenv("TRADING212_API_SECRET"),
)
return nil
},
)
client, err := trading212.NewClientWithResponses(
"https://demo.trading212.com",
auth,
)
if err != nil {
return err
}
summary, err := client.GetAccountSummaryWithResponse(ctx)
if err != nil {
return err // transport failure
}
if summary.JSON200 == nil {
return fmt.Errorf("account summary: %s", summary.Status())
}
total := summary.JSON200.TotalValue // *float64
positions, err := client.GetPositionsWithResponse(
ctx,
&trading212.GetPositionsParams{},
)
if err != nil {
return err
}
if positions.JSON200 != nil {
for _, position := range *positions.JSON200 {
fmt.Println(*position.Instrument.Ticker, *position.Quantity)
}
}
Most response fields are pointers; check for nil before dereferencing. The error return covers only transport and decoding failures. An API error (401, 403, 429 and so on) comes back with JSON200 nil: check StatusCode() and Body.
Some method names come straight from the spec's operation IDs and are generic: GetAll, Create, Update, Delete and GetDetailed are the pie endpoints, Orders1 is the order history, PlaceStopOrder1 places a stop order and PlaceStopOrder a stop-limit order.