Skip to content

Commit 3fd76f1

Browse files
committed
Initial commit
1 parent 9e44e10 commit 3fd76f1

37 files changed

+12304
-2
lines changed

README.md

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,92 @@
1-
# ibapi
2-
Unofficial Golang Interactive Brokers API
1+
[![Go Report Card](https://goreportcard.com/badge/github.com/scmhub/ibapi)](https://goreportcard.com/report/github.com/scmhub/ibapi)
2+
[![Go Reference](https://pkg.go.dev/badge/github.com/scmhub/ibapi.svg)](https://pkg.go.dev/github.com/scmhub/ibapi)
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4+
5+
# Unofficial Golang Interactive Brokers API (Beta)
6+
7+
This package provides an **unofficial** Golang implementation of the [Interactive Brokers](https://www.interactivebrokers.com/en/home.php) API. It is designed to mirror the official Python or C++ [tws-api](https://github.com/InteractiveBrokers) provided by Interactive Brokers.
8+
**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.
9+
10+
> **Note:** This package is in the **beta phase**. While functional, it may still have bugs or incomplete features. Please test extensively in non-production environments.
11+
12+
## Getting Started
13+
14+
### Prerequisites
15+
16+
- **Go** version 1.23 or higher (recommended)
17+
- An **Interactive Brokers** account with TWS or IB Gateway installed and running
18+
19+
### Installation
20+
21+
Install the package via `go get`:
22+
23+
```bash
24+
go get -u github.com/scmhub/ibapi
25+
```
26+
27+
## Usage
28+
29+
Here’s a basic example to connect and place an order using this package:
30+
31+
```go
32+
package main
33+
34+
import (
35+
"math/rand"
36+
"time"
37+
38+
"github.com/scmhub/ibapi"
39+
)
40+
41+
const (
42+
IB_HOST = "127.0.0.1"
43+
IB_PORT = 7497
44+
)
45+
46+
func main() {
47+
// We set logger for pretty logs to console
48+
log := ibapi.Logger()
49+
ibapi.SetConsoleWriter()
50+
51+
// New IB CLient
52+
ib := ibapi.NewEClient(nil)
53+
// Connect client
54+
if err := ib.Connect(IB_HOST, IB_PORT, rand.Int63n(999999)); err != nil {
55+
log.Error().Err(err)
56+
return
57+
}
58+
59+
// Create and place order
60+
id := ib.NextID()
61+
eurusd := &ibapi.Contract{Symbol: "EUR", SecType: "CASH", Currency: "USD", Exchange: "IDEALPRO"}
62+
limitOrder := ibapi.LimitOrder("BUY", ibapi.StringToDecimal("20000"), 1.08)
63+
ib.PlaceOrder(id, eurusd, limitOrder)
64+
65+
time.Sleep(1 * time.Second)
66+
67+
err := ib.Disconnect()
68+
if err != nil {
69+
log.Error().Err(err).Msg("Disconnect")
70+
}
71+
}
72+
73+
```
74+
75+
For more information on how to use this package, please refer to the [GoDoc](https://pkg.go.dev/github.com/scmhub/ibapi) documentation.
76+
77+
## Acknowledgments
78+
79+
- Some portions of the code were adapted from [hadrianl](https://github.com/hadrianl/ibapi). Thanks to them for their valuable work!
80+
- Decimals are implemented with the [fixed](https://github.com/robaho/fixed) package
81+
82+
## Notice of Non-Affiliation and Disclaimer
83+
84+
> **Beta Release**: 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.
85+
86+
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.
87+
88+
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.
89+
90+
## License
91+
92+
Distributed under the MIT License. See [LICENSE](./LICENSE) for more information.

account_summary_tags.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package ibapi
2+
3+
import "strings"
4+
5+
// AccountSummaryTags .
6+
type AccountSummaryTags = string
7+
8+
const (
9+
AccountType AccountSummaryTags = "AccountType"
10+
NetLiquidation AccountSummaryTags = "NetLiquidation"
11+
TotalCashValue AccountSummaryTags = "TotalCashValue"
12+
SettledCash AccountSummaryTags = "SettledCash"
13+
AccruedCash AccountSummaryTags = "AccruedCash"
14+
BuyingPower AccountSummaryTags = "BuyingPower"
15+
EquityWithLoanValue AccountSummaryTags = "EquityWithLoanValue"
16+
PreviousEquityWithLoanValue AccountSummaryTags = "PreviousEquityWithLoanValue"
17+
GrossPositionValue AccountSummaryTags = "GrossPositionValue"
18+
ReqTEquity AccountSummaryTags = "ReqTEquity"
19+
ReqTMargin AccountSummaryTags = "ReqTMargin"
20+
SMA AccountSummaryTags = "SMA"
21+
InitMarginReq AccountSummaryTags = "InitMarginReq"
22+
MaintMarginReq AccountSummaryTags = "MaintMarginReq"
23+
AvailableFunds AccountSummaryTags = "AvailableFunds"
24+
ExcessLiquidity AccountSummaryTags = "ExcessLiquidity"
25+
Cushion AccountSummaryTags = "Cushion"
26+
FullInitMarginReq AccountSummaryTags = "FullInitMarginReq"
27+
FullMaintMarginReq AccountSummaryTags = "FullMaintMarginReq"
28+
FullAvailableFunds AccountSummaryTags = "FullAvailableFunds"
29+
FullExcessLiquidity AccountSummaryTags = "FullExcessLiquidity"
30+
LookAheadNextChange AccountSummaryTags = "LookAheadNextChange"
31+
LookAheadInitMarginReq AccountSummaryTags = "LookAheadInitMarginReq"
32+
LookAheadMaintMarginReq AccountSummaryTags = "LookAheadMaintMarginReq"
33+
LookAheadAvailableFunds AccountSummaryTags = "LookAheadAvailableFunds"
34+
LookAheadExcessLiquidity AccountSummaryTags = "LookAheadExcessLiquidity"
35+
HighestSeverity AccountSummaryTags = "HighestSeverity"
36+
DayTradesRemaining AccountSummaryTags = "DayTradesRemaining"
37+
Leverage AccountSummaryTags = "Leverage"
38+
)
39+
40+
func GetAllTags() string {
41+
tags := []AccountSummaryTags{
42+
AccountType,
43+
NetLiquidation,
44+
TotalCashValue,
45+
SettledCash,
46+
AccruedCash,
47+
BuyingPower,
48+
EquityWithLoanValue,
49+
PreviousEquityWithLoanValue,
50+
GrossPositionValue,
51+
ReqTEquity,
52+
ReqTMargin,
53+
SMA,
54+
InitMarginReq,
55+
MaintMarginReq,
56+
AvailableFunds,
57+
ExcessLiquidity,
58+
Cushion,
59+
FullInitMarginReq,
60+
FullMaintMarginReq,
61+
FullAvailableFunds,
62+
FullExcessLiquidity,
63+
LookAheadNextChange,
64+
LookAheadInitMarginReq,
65+
LookAheadMaintMarginReq,
66+
LookAheadAvailableFunds,
67+
LookAheadExcessLiquidity,
68+
HighestSeverity,
69+
DayTradesRemaining,
70+
Leverage,
71+
}
72+
return strings.Join(tags, ",")
73+
}

0 commit comments

Comments
 (0)