|
1 | | -# ibapi |
2 | | -Unofficial Golang Interactive Brokers API |
| 1 | +[](https://goreportcard.com/report/github.com/scmhub/ibapi) |
| 2 | +[](https://pkg.go.dev/github.com/scmhub/ibapi) |
| 3 | +[](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. |
0 commit comments