ibkr

package module
v0.0.0-...-22cdefe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 24 Imported by: 0

README

ibkr

Another unofficial Golang Interactive Brokers TWS/IB api client.

The official and unofficial SDKs uses a pattern of sending requests and raise events when a response is received.

The library acts differently. When you call a method to send a request, the function waits until the corresponding response reaches.

For streaming methods, the response usually contains a channel to listen for incoming events.

Acknowledgements

This library is strongly based on https://github.com/scmhub/ibapi and the official SDKs.

Thanks to the authors and collaborators for the excellent job.

LICENSE

Copyright © 2025 SCM Copyright © 2025 Mauro H. Leggieri

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, opts Options) (*Client, error)

NewClient creates a new client object and establishes a connection to the given server.

func (*Client) ConnectedCh

func (c *Client) ConnectedCh() <-chan struct{}

ConnectedCh returns a channel closed if the connection goes down.

func (*Client) Destroy

func (c *Client) Destroy()

Destroy shuts down the current connection, cancels all pending requests and destroys the client object.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if the connection to the server is alive.

func (*Client) RequestContractDetails

RequestContractDetails retrieves all details for contracts matching the provided input.

func (*Client) RequestCurrentTime

func (c *Client) RequestCurrentTime(ctx context.Context) (time.Time, error)

RequestCurrentTime asks the current system time on the server side.

func (*Client) RequestHistoricalData

RequestHistoricalData retrieves historical market data.

func (*Client) RequestHistoricalTicks

RequestHistoricalTicks retrieves historical market ticks.

func (*Client) RequestManagedAccounts

func (c *Client) RequestManagedAccounts(ctx context.Context) ([]string, error)

RequestManagedAccounts requests the list of managed accounts.

func (*Client) RequestMarketDataType

func (c *Client) RequestMarketDataType(_ context.Context, opts models.MarketDataTypeRequestOptions) error

func (*Client) RequestMatchingSymbols

RequestMatchingSymbols retrieves all details for contracts matching the provided input.

func (*Client) ServerVersion

func (c *Client) ServerVersion() int

ServerVersion returns the version of the server.

type Events

type Events interface {
	ConnectionClosed(err error)
	ReceivedUnknownMessage(id uint32)

	Error(ts time.Time, code int, message string, advancedOrderRejectJson string)
}

func NewIncomingMessageLogger

func NewIncomingMessageLogger(cb EventsLoggerCallback) Events

type EventsLogger

type EventsLogger struct {
	// contains filtered or unexported fields
}

func (*EventsLogger) ConnectionClosed

func (el *EventsLogger) ConnectionClosed(err error)

func (*EventsLogger) Error

func (el *EventsLogger) Error(ts time.Time, code int, message string, advancedOrderRejectJson string)

func (*EventsLogger) ReceivedUnknownMessage

func (el *EventsLogger) ReceivedUnknownMessage(id uint32)

type EventsLoggerCallback

type EventsLoggerCallback func(msg string)

type NonIdRequestList

type NonIdRequestList struct {
	list.List
}

type Options

type Options struct {
	Address       string
	EventsHandler Events
	TzOffset      interface{}

	ConnectOptions       string
	OptionalCapabilities string
	ClientID             int32
}

type Request

type Request struct {
	// contains filtered or unexported fields
}

func (*Request) CompleteCh

func (req *Request) CompleteCh() <-chan struct{}

func (*Request) Err

func (req *Request) Err() error

func (*Request) ID

func (req *Request) ID() int32

func (*Request) Type

func (req *Request) Type() RequestType

type RequestCompleteCallback

type RequestCompleteCallback func(req *Request, err error)

type RequestError

type RequestError struct {
	Timestamp               time.Time
	Code                    int
	Message                 string
	AdvancedOrderRejectJson string
}

func (*RequestError) Error

func (r *RequestError) Error() string

type RequestManager

type RequestManager struct {
	// contains filtered or unexported fields
}

type RequestOptions

type RequestOptions struct {
	Type       RequestType
	MsgCode    int
	Response   interface{}
	CompleteCB RequestCompleteCallback
}

type RequestType

type RequestType int
const (
	RequestTypeRequestWithID RequestType = iota
	RequestTypeRequestWithoutID
	RequestTypeRequestWithTickerID
)

type WithRequestWithIdCallback

type WithRequestWithIdCallback func(resp interface{}) (done bool, err error)

type WithRequestWithTickerIdCallback

type WithRequestWithTickerIdCallback func(resp interface{}) (done bool, err error)

type WithRequestWithoutIdCallback

type WithRequestWithoutIdCallback func(resp interface{}) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL