Documents

go-ibkr

Try it

Unofficial Go client for the Interactive Brokers Web API (Client Portal API v1), generated with oapi-codegen from the OpenAPI document Interactive Brokers publishes. Package `ibkr` (`github.com/psyb0t/go-ibkr`) has a typed `...WithResponse` method for each of the spec's endpoints, covering session status and keepalive, accounts, portfolio positions and summary, contract search and details, market data snapshots, order submission, status, modification and cancellation, and model portfolios. It works through a local Client Portal Gateway or against `https://api.ibkr.com` with an OAuth token. Use when Go code needs to read an Interactive Brokers account, look up contracts or market data, or place orders, or already imports go-ibkr.

What it does

Unofficial, typed Go client for the Interactive Brokers Web API, in package at the module root.

The skill document

go-ibkr

Unofficial, typed Go client for the Interactive Brokers Web API, in package ibkr at the module root.

For install, both auth setups, operation lookup and response handling, see references/setup.md.

Security & safety

  • The client implements no login. With the Client Portal Gateway the user logs in in a browser and the gateway holds the session, so the code needs no credentials. With OAuth, read the access token from an environment variable or the user's own token code; never hardcode, commit or log it.
  • Requests go only to the user's gateway or to https://api.ibkr.com. Skip TLS verification only for a gateway on the user's own machine, which serves a self-signed certificate. Never skip it for any other host.
  • SubmitNewOrder, ModifyOpenOrder, CancelOpenOrder, ConfirmOrderReply, the model order endpoints and Logout act on a real brokerage account. Call them only when the user asked for that exact action, and prefer a paper trading login while developing.

When to use

  • Go code needs Interactive Brokers accounts, positions, portfolio summary, contract details or market data snapshots.
  • Go code needs to place, modify or cancel Interactive Brokers orders, at the user's request.
  • The project already imports github.com/psyb0t/go-ibkr.

When NOT to use

  • The code is not Go. This module ships only a Go package.
  • You need the TWS socket API. This client covers the Web API only.
  • You need a client maintained by Interactive Brokers. This one is unofficial and not affiliated with Interactive Brokers.
  • You want to change the generated client itself. See AGENTS.md in the repo.

Usage

The spec paths carry their full prefix (/v1/api/...), so the base URL is only the scheme and host.

import (
	"context"
	"crypto/tls"
	"errors"
	"fmt"
	"net/http"

	"github.com/psyb0t/go-ibkr"
)

// A Client Portal Gateway on this machine serves a self-signed certificate.
httpClient := &http.Client{
	Transport: &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	},
}

client, err := ibkr.NewClientWithResponses(
	"https://localhost:5000",
	ibkr.WithHTTPClient(httpClient),
)
if err != nil {
	return err
}

status, err := client.GetBrokerageStatusWithResponse(ctx)
if err != nil {
	return err // transport failure
}

if status.JSON200 == nil || status.JSON200.Authenticated == nil ||
	!*status.JSON200.Authenticated {
	return errors.New("log in to the gateway at https://localhost:5000")
}

accounts, err := client.GetBrokerageAccountsWithResponse(ctx)
if err != nil {
	return err
}

if accounts.JSON200 == nil || accounts.JSON200.Accounts == nil {
	return fmt.Errorf("accounts: %s", accounts.Status())
}

accountID := (*accounts.JSON200.Accounts)[0]

positions, err := client.GetPaginatedPositionsWithResponse(
	ctx,
	accountID,
	0, // page
	&ibkr.GetPaginatedPositionsParams{},
)
if err != nil {
	return err
}

if positions.JSON200 != nil {
	for _, position := range *positions.JSON200 {
		fmt.Println(*position.Conid, *position.ContractDesc)
	}
}

Keep a gateway session alive by calling GetSessionTokenWithResponse (POST /v1/api/tickle) about once a minute.

With OAuth, use https://api.ibkr.com as the base URL and add the token in a request editor:

auth := ibkr.WithRequestEditorFn(
	func(_ context.Context, req *http.Request) error {
		req.Header.Set("Authorization", "Bearer "+accessToken)

		return nil
	},
)

client, err := ibkr.NewClientWithResponses("https://api.ibkr.com", auth)

Most response fields are pointers; check for nil before dereferencing. The error return covers only transport and decoding failures. An API error comes back with JSON200 nil: check StatusCode() and Body.

Related skills

Join a video meeting as an AI bot with voice, avatar, and screenshare across four operating modes.

by johnpatternai22 installs8 stars

Fetch raw ad creative, app, ranking, and revenue data from AdMapix as structured JSON.

by fly0pants4.3k installs296 stars

Find why your productivity system keeps failing, then apply the smallest fix — capacity math, bottleneck routing, durable local notes.

by Iván857 installs69 stars

Stores durable facts in a categorized, plain-markdown vault on disk, alongside your agent's built-in memory.

by Iván561 installs18 stars

Generate and edit Draw.io, Mermaid, and Excalidraw diagrams from natural language using a structured JSON spec.

by nssa.io1.0k installs47 stars

More from psyb0t

Browse all skills

Drive a user-deployed mt5-httpapi MetaTrader 5 bridge over HTTP, with per-action confirmation on every real-money call.

by psyb0t108 installs4 stars

Docker-packaged browser automation for QA against anti-bot stacks and authorized detection testing.

by psyb0t138 installs2 stars

Self-hosted OpenAI-compatible speech service — transcription, translation, and synthesis from one container.

by psyb0t13 installs

Run ffmpeg, sox, and ImageMagick jobs against your files in a fixed-allowlist SSH sandbox.

by psyb0t71 installs

Generate speech audio via Qwen3-TTS over SSH with preset voices, voice cloning, and voice design.

by psyb0t55 installs

Drive one or more IMAP/SMTP mailboxes through a single REST + MCP endpoint — read, search, send, mark-seen, and delete across accounts in parallel.

by psyb0t15 installs