Skip to content

scmhub/ibapi

Folders and files

NameName
Last commit message
Last commit date
Apr 10, 2025
Apr 24, 2025
Apr 24, 2025
Sep 25, 2024
Jan 2, 2025
Dec 16, 2024
Sep 25, 2024
Sep 25, 2024
Apr 24, 2025
Apr 15, 2025
Apr 15, 2025
Dec 19, 2024
Apr 24, 2025
Dec 16, 2024
Apr 24, 2025
Apr 15, 2025
Nov 26, 2024
Apr 1, 2025
Apr 24, 2025
Apr 24, 2025
Nov 22, 2024
Apr 24, 2025
Sep 25, 2024
Apr 24, 2025
Apr 1, 2025
Apr 1, 2025
Apr 24, 2025
Apr 24, 2025
Apr 24, 2025
Apr 24, 2025
Apr 24, 2025
Sep 25, 2024
Mar 29, 2025
Apr 1, 2025
Apr 24, 2025
Jan 10, 2025
Nov 12, 2024
Mar 29, 2025
Feb 11, 2025
Feb 11, 2025
Dec 19, 2024
Apr 24, 2025
Oct 14, 2024
Sep 25, 2024
Sep 25, 2024
Apr 15, 2025
Sep 25, 2024
Sep 25, 2024
Apr 24, 2025
Apr 24, 2025
Apr 24, 2025
Sep 25, 2024
Apr 1, 2025
Apr 15, 2025
Apr 24, 2025

Repository files navigation

Go Report Card Go Reference License: MIT

Unofficial Golang Interactive Brokers API

ibapi package provides an unofficial Golang implementation of the Interactive Brokers API. It is designed to mirror the official Python or C++ tws-api provided by Interactive Brokers. We will do our best to keep it in sync with the official API releases to ensure compatibility and feature parity, but users should be aware that this is a community-driven project and may lag behind the official versions at times.

Caution

This package is in the beta phase. While functional, it may still have bugs or incomplete features. Please test extensively in non-production environments.

Getting Started

Prerequisites

  • Go version 1.23 or higher (recommended)
  • An Interactive Brokers account with TWS or IB Gateway installed and running

Installation

Install the package via go get:

go get -u github.com/scmhub/ibapi

Usage

Here’s a basic example to connect and place an order using this package:

package main

import (
	"math/rand"
	"time"

	"github.com/scmhub/ibapi"
)

const (
	IB_HOST = "127.0.0.1"
	IB_PORT = 7497
)

func main() {
	// We set logger for pretty logs to console
	log := ibapi.Logger()
	ibapi.SetConsoleWriter()

	// New IB CLient
	ib := ibapi.NewEClient(nil)
	
    // Connect client
	if err := ib.Connect(IB_HOST, IB_PORT, rand.Int63n(999999)); err != nil {
		log.Error().Err(err)
		return
	}

    // Create and place order
	id := 1
	eurusd := &ibapi.Contract{Symbol: "EUR", SecType: "CASH", Currency: "USD", Exchange: "IDEALPRO"}
	limitOrder := ibapi.LimitOrder("BUY", ibapi.StringToDecimal("20000"), 1.08)
	ib.PlaceOrder(id, eurusd, limitOrder)

	time.Sleep(1 * time.Second)

	err := ib.Disconnect()
	if err != nil {
		log.Error().Err(err).Msg("Disconnect")
	}
}

For more information on how to use this package, please refer to the GoDoc documentation.

Acknowledgments

  • Some portions of the code were adapted from hadrianl. Thanks to them for their valuable work!
  • Decimals are implemented with the fixed package

Notice of Non-Affiliation and Disclaimer

Caution

This project is in the beta phase and is still undergoing testing and development. Users are advised to thoroughly test the software in non-production environments before relying on it for live trading. Features may be incomplete, and bugs may exist. Use at your own risk.

Important

This project is not affiliated with Interactive Brokers Group, Inc. All references to Interactive Brokers, including trademarks, logos, and brand names, belong to their respective owners. The use of these names is purely for informational purposes and does not imply endorsement by Interactive Brokers.

Important

The authors of this package make no guarantees regarding the software's reliability, accuracy, or suitability for any particular purpose, including trading or financial decisions. No liability will be accepted for any financial losses, damages, or misinterpretations arising from the use of this software.

License

Distributed under the MIT License. See LICENSE for more information.

Author

Philippe Chavanne - contact