Categorygithub.com/purelightme/ibapi
modulepackage
1.0.0
Repository: https://github.com/purelightme/ibapi.git
Documentation: pkg.go.dev

# README

Interactive Brokers API - GoLang Implement

  • Interactive Brokers API 9.80
  • pure golang Implement
  • Unofficial, use at you own risk

INSTALL

go get -u github.com/purelightme/ibapi


USAGE

Implement IbWrapper to handle datas delivered via tws or gateway, Wrapper in demo is a default implement that just output data to std. Go to IbWrapper

  1. implement your own IbWrapper
  2. connect to TWS or Gateway
  3. handshake with TWS or Gateway
  4. run the loop
  5. do some request

Demo 1

import (
    . "github.com/hadrianl/ibapi"
    "time"
)

func main(){
    // internal api log is zap log, you could use GetLogger to get the logger
    // besides, you could use SetAPILogger to set you own log option
    // or you can just use the other logger  
    log := GetLogger().Sugar()
    defer log.Sync()
    // implement your own IbWrapper to handle the msg delivered via tws or gateway
    // Wrapper{} below is a default implement which just log the msg 
    ic := NewIbClient(&Wrapper{})

    // tcp connect with tws or gateway
    // fail if tws or gateway had not yet set the trust IP
    if err := ic.Connect("127.0.0.1", 4002, 0);err != nil {
        log.Panic("Connect failed:", err)
    }

    // handshake with tws or gateway, send handshake protocol to tell tws or gateway the version of client
    // and receive the server version and connection time from tws or gateway.
    // fail if someone else had already connected to tws or gateway with same clientID
    if err := ic.HandShake();err != nil {
        log.Panic("HandShake failed:", err)
    }

    // make some request, msg would be delivered via wrapper.
    // req will not send to TWS or Gateway until ic.Run()
    // you could just call ic.Run() before these
    ic.ReqCurrentTime()
    ic.ReqAutoOpenOrders(true)
    ic.ReqAccountUpdates(true, "")
    ic.ReqExecutions(ic.GetReqID(), ExecutionFilter{})

    // start to send req and receive msg from tws or gateway after this
    ic.Run()
    <-time.After(time.Second * 60)
    ic.Disconnect()
}

Demo 2 with context

import (
    . "github.com/hadrianl/ibapi"
    "time"
    "context"
)

func main(){
    var err error
    SetAPILogger(zap.NewDevelopmentConfig()) // log is default for production(json encode, info level), set to development(console encode, debug level) here
    log := GetLogger().Sugar()
    defer log.Sync()
    ibwrapper := &Wrapper{}
    ctx, _ := context.WithTimeout(context.Background(), time.Second*30)
    ic := NewIbClient(ibwrapper)
    ic.SetContext(ctx)
    err = ic.Connect("127.0.0.1", 4002, 0)
    if err != nil {
        log.Panic("Connect failed:", err)
    }

    err = ic.HandShake()
    if err != nil {
        log.Panic("HandShake failed:", err)
    }

    ic.ReqCurrentTime()
    ic.ReqAutoOpenOrders(true)
    ic.ReqAccountUpdates(true, "")
    ic.ReqExecutions(ic.GetReqID(), ExecutionFilter{})

    ic.Run()
    err = ic.LoopUntilDone()  // block until ctx or ic is done
    log.Info(err)
}


Reference

  1. Offical Document
  2. Order Types
  3. Product
  4. Margin
  5. Market Data
  6. Commissions

# Functions

GetLogger gets a clone of the internal logger with the option, see uber.org/zap for more information.
InitDefault try to init the object with the default tag, that is a common way but not a efficent way.
No description provided by the author
NewComboLeg create a default comboleg.
NewIbClient create IbClient with wrapper.
NewLimitOrder create a limit order with action, limit price and quantity.
NewMarketOrder create a market order with action and quantity.
NewMsgBuffer create a new MsgBuffer.
NewOrder create a default order.
NewScannerSubscription create a default ScannerSubscription.
APILogger sets the options of internal logger for API, such as level, encoder, output, see uber.org/zap for more information.

# Constants

tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
No description provided by the author
No description provided by the author
tick const.
No description provided by the author
No description provided by the author
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
No description provided by the author
tick const.
tick const.
No description provided by the author
ConnectionState.
ConnectionState.
tick const.
tick const.
tick const.
No description provided by the author
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
ConnectionState.
No description provided by the author
No description provided by the author
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
No description provided by the author
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
No description provided by the author
MAX_MSG_LEN is the max length that receiver could take.
MaxClientVersion is the max client version that this implement could support.
MaxRequests is the max request that tws or gateway could take pre second.
No description provided by the author
tick const.
tick const.
NO_VALID_ID represent that the callback func of wrapper is not attached to any request.
tick const.
tick const.
tick const.
tick const.
No description provided by the author
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
tick const.
ConnectionState.
tick const.
RequestInternal is the internal microseconds between requests.
tick const.
tick const.
tick const.
No description provided by the author
tick const.
tick const.
tick const.
tick const.
tick const.
No description provided by the author
No description provided by the author
No description provided by the author
tick const.
tick const.
No description provided by the author
No description provided by the author
UNSETFLOAT represent unset value of float64.
UNSETINT represent unset value of int64.
tick const.
tick const.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Account ...
AlgoParams ...
BarData ...
ComboLeg ...
CommissionReport ...
Contract describes an instrument's definition.
No description provided by the author
ContractDescription includes contract and DerivativeSecTypes.
ContractDetails contain a Contract and other details about this contract, can be request by ReqContractDetails.
DeltaNeutralContract is Delta-Neutral Contract.
DepthMktDataDescription ...
Execution is the information of an order`s execution.
No description provided by the author
ExecutionFilter ...
FamilyCode ...
HistogramData ...
No description provided by the author
HistoricalTick is the historical tick's description.
HistoricalTickBidAsk is the historical tick's description.
HistoricalTickLast is the historical last tick's description.
IbClient is the key component which is used to send request to TWS ro Gateway , such subscribe market data or place order.
IbConnection wrap the tcp connection with TWS or Gateway.
IbError is ib internal errors.
No description provided by the author
MsgBuffer is the buffer that contains a whole msg.
NewsProvider ...
No description provided by the author
Order is the origin type of order,do not try to new one unless you definitely know how to fill all the fields!Use NewDefaultOrder instead!.
OrderComboLeg ...
No description provided by the author
OrderState is the state of Order.
No description provided by the author
No description provided by the author
PriceIncrement ...
RealTimeBar ...
ScanData is the data retureed by IB, which matches the ScannerSubscription.
ScannerSubscription defines a market scanner request.
SmartComponent ...
SoftDollarTier is a container for storing Soft Dollar Tier information.
TagValue ...
TickAttrib describes additional information for price ticks.
TickAttribBidAsk ...
TickAttribLast ...
No description provided by the author
No description provided by the author
Wrapper is the default wrapper provided by this golang implement.
No description provided by the author

# Interfaces

IbWrapper contain the funcs to handle the msg from TWS or Gateway.
No description provided by the author

# Type aliases

ComboLegOpenClose ...
ComboLegShortSaleSlot ...
No description provided by the author
IN identifies the msg type of the buf received from TWS or Gateway.
OUT identifies the msg type of the buf sended to TWS or Gateway.
No description provided by the author