Client libraries
Two typed clients are generated from api/v1.yaml and committed under pkg/clients/. Both talk to the REST API; point them at the base URL including /v1. They are regenerated with make generate whenever the spec changes, so a client from a given tag matches the server from the same tag.
Go
The module is github.com/psyb0t/ibkr-httpapi/pkg/clients/go, generated by oapi-codegen into one file, client.gen.go. It needs Go 1.25 or newer.
go get github.com/psyb0t/ibkr-httpapi/pkg/clients/go@latest
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
ibkr "github.com/psyb0t/ibkr-httpapi/pkg/clients/go"
)
func main() {
c, err := ibkr.NewClientWithResponses(
"http://localhost:8889/v1",
ibkr.WithRequestEditorFn(func(_ context.Context, req *http.Request) error {
req.Header.Set("Authorization", "Bearer "+os.Getenv("API_TOKEN"))
return nil
}),
)
if err != nil {
log.Fatal(err)
}
resp, err := c.GetStockTickWithResponse(context.Background(), "AAPL", nil)
if err != nil {
log.Fatal(err)
}
if resp.JSON200 == nil {
log.Fatalf("status %d: %s", resp.StatusCode(), resp.Body)
}
if resp.JSON200.Last != nil {
fmt.Printf("AAPL last=%v\n", *resp.JSON200.Last)
}
}
Every operation has a <OperationId>WithResponse method. Responses carry JSON200 and the typed error bodies (ErrorEnvelope) for the statuses the spec declares.
Python
The package is ibkr-httpapi-client (import name ibkr_httpapi_client), generated by openapi-python-client. Install it straight from this repository:
pip install "git+https://github.com/psyb0t/ibkr-httpapi.git#subdirectory=pkg/clients/python/ibkr-httpapi-client"
import os
from ibkr_httpapi_client import AuthenticatedClient
from ibkr_httpapi_client.api.stocks import get_stock_tick
from ibkr_httpapi_client.models import Ticker
client = AuthenticatedClient(
base_url="http://localhost:8889/v1",
token=os.environ["API_TOKEN"],
)
with client as c:
ticker = get_stock_tick.sync(client=c, symbol="AAPL")
if isinstance(ticker, Ticker):
print(f"AAPL last={ticker.last}")
else:
print(ticker)
Modules follow the spec tags (api.system, api.stocks, api.options, api.futures, api.cfd, api.forex, api.crypto, api.orders, api.history), one module per operation. Each has sync, sync_detailed, asyncio and asyncio_detailed. sync returns the parsed model, an ErrorEnvelope for a declared error status, or None.
The generated package README, pkg/clients/python/ibkr-httpapi-client/README.md, covers TLS options and custom httpx settings.
Regenerating
Edit the spec, then:
make generate-client-go
make generate-client-python
Never edit the generated files. See Development.