ibkr

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: BSD-3-Clause Imports: 29 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MarketDataPeriodSeconds = "S"
	MarketDataPeriodDay     = "d"
	MarketDataPeriodWeek    = "w"
	MarketDataPeriodMonth   = "m"
	MarketDataPeriodYear    = "y"
)
View Source
const (
	MarketDataBarSeconds = "secs"
	MarketDataBarMinutes = "mins"
	MarketDataBarHours   = "hrs"
	MarketDataBarDay     = "d"
	MarketDataBarWeek    = "w"
	MarketDataBarMonth   = "m"
)
View Source
const (
	MessageIdImmediateFill          = "o403"
	MessageIdMarketOrderRisk        = "o10151"
	MessageIdOrderWithoutMarketData = "o354"
)
View Source
const DefaultUserAgent = "schmidthole/ibkr-webapi-go/1"
View Source
const GatewayBaseUrl = "https://localhost:5000"
View Source
const ProdBaseUrl = "https://api.ibkr.com"

Variables

View Source
var IbkrGlobalRateLimit = 50
View Source
var LstExpirationThreshold int64 = 900

Functions

func ImportDhParametersFromPem

func ImportDhParametersFromPem(pemPath string) (*dsa.Parameters, error)

func ImportRsaKeyFromPem

func ImportRsaKeyFromPem(pemPath string) (*rsa.PrivateKey, error)

func SignRsa

func SignRsa(input []byte, key *rsa.PrivateKey) ([]byte, error)

Types

type AccountLedger

type AccountLedger struct {
	SettledCash         float64 `json:"settledCash" validation:"required"`
	CashBalance         float64 `json:"cashBalance" validation:"required"`
	NetLiquidationValue float64 `json:"netLiquidationValue" validation:"required"`
	UnrealizedPnL       float64 `json:"unrealizedpnl" validation:"required"`
	RealizedPnL         float64 `json:"realizedpnl" validation:"required"`
	Funds               float64 `json:"funds" validation:"required"`
}

type AuthStatus

type AuthStatus struct {
	Authenticated bool       `json:"authenticated" validation:"required"`
	Competing     bool       `json:"competing" validation:"required"`
	Connected     bool       `json:"connected" validation:"required"`
	Message       string     `json:"message" validation:"required"`
	MAC           string     `json:"MAC" validation:"required"`
	ServerInfo    ServerInfo `json:"serverInfo" validation:"required"`
}

type CancelOrderErrorResponse

type CancelOrderErrorResponse struct {
	Error string `json:"error" validation:"required"`
}

type CancelOrderResponse

type CancelOrderResponse struct {
	Message string `json:"msg" validation:"required"`
	OrderID int    `json:"order_id" validation:"required"`
	ConID   int    `json:"conid" validation:"required"`
	Account string `json:"account" validation:"required"`
}

type GetAccountsResponse added in v1.0.0

type GetAccountsResponse struct {
	Accounts []string `json:"accounts" validate:"required"`
}

type HMDSDetails

type HMDSDetails struct {
	Error string `json:"error"`
}

type IServerDetails

type IServerDetails struct {
	AuthStatus AuthStatus `json:"authStatus"`
}

type IbkrOAuthContext

type IbkrOAuthContext struct {
	ConsumerKey    string
	SigningKey     *rsa.PrivateKey
	EncryptionKey  *rsa.PrivateKey
	DhParams       *dsa.Parameters
	AccessToken    string
	AccessSecret   string
	LstExpiration  int64
	Lst            string
	VerboseLogging bool
}

func NewIbkrOAuthContext

func NewIbkrOAuthContext(
	consumerKey string,
	accessToken string,
	accessSecret string,
	signingKeyPemPath string,
	encryptionKeyPemPath string,
	dhParamsPemPath string,
) (*IbkrOAuthContext, error)

func NewIbkrOAuthContextFromFile

func NewIbkrOAuthContextFromFile(credentialsFilePath string) (*IbkrOAuthContext, error)

func (*IbkrOAuthContext) GenerateLiveSessionToken

func (i *IbkrOAuthContext) GenerateLiveSessionToken(client *http.Client, baseUrl string) error

func (*IbkrOAuthContext) GetOAuthHeader

func (i *IbkrOAuthContext) GetOAuthHeader(method string, requestUrl string) (string, error)

func (*IbkrOAuthContext) Reset added in v1.1.0

func (i *IbkrOAuthContext) Reset()

func (*IbkrOAuthContext) ShouldReAuthenticate added in v1.0.5

func (i *IbkrOAuthContext) ShouldReAuthenticate() bool

type IbkrOAuthCredentials

type IbkrOAuthCredentials struct {
	CustomerKey       string `yaml:"customer_key"`
	AccessToken       string `yaml:"access_token"`
	AccessSecret      string `yaml:"access_secret"`
	SigningKeyPath    string `yaml:"signing_key_path"`
	EncryptionKeyPath string `yaml:"encryption_key_path"`
	DHParamsPath      string `yaml:"dh_params_path"`
}

type IbkrWebClient

type IbkrWebClient struct {
	VerboseLogging bool
	BaseUrl        string
	// contains filtered or unexported fields
}

func NewIbkrWebClient

func NewIbkrWebClient(baseUrl string, authContext OAuthContext) *IbkrWebClient

func (*IbkrWebClient) AuthStatus

func (c *IbkrWebClient) AuthStatus() (*AuthStatus, error)

func (*IbkrWebClient) Authenticate

func (c *IbkrWebClient) Authenticate() error

func (*IbkrWebClient) CancelOrder

func (c *IbkrWebClient) CancelOrder(accountId string, orderId string) (*CancelOrderResponse, error)

func (*IbkrWebClient) Delete

func (c *IbkrWebClient) Delete(path string, queryParams map[string]string) (*clientResponse, error)

func (*IbkrWebClient) DoRequest

func (c *IbkrWebClient) DoRequest(
	method string,
	path string,
	queryParams map[string]string,
	body interface{},
) (*clientResponse, error)

func (*IbkrWebClient) Get

func (c *IbkrWebClient) Get(path string, queryParams map[string]string) (*clientResponse, error)

func (*IbkrWebClient) GetAccounts added in v1.0.0

func (c *IbkrWebClient) GetAccounts() ([]string, error)

func (*IbkrWebClient) GetLiveOrders

func (c *IbkrWebClient) GetLiveOrders() (*LiveOrdersResponse, error)

func (*IbkrWebClient) GetPortfolioAccountLedger

func (c *IbkrWebClient) GetPortfolioAccountLedger(acctId string) (*PortfolioAccountLedger, error)

func (*IbkrWebClient) GetPortfolioSubaccounts

func (c *IbkrWebClient) GetPortfolioSubaccounts() ([]PortfolioSubaccount, error)

func (*IbkrWebClient) GetPositions

func (c *IbkrWebClient) GetPositions(acctId string, page int32) ([]Position, error)

func (*IbkrWebClient) InitializeBrokerSession

func (c *IbkrWebClient) InitializeBrokerSession() (*AuthStatus, error)

func (*IbkrWebClient) Logout

func (c *IbkrWebClient) Logout() error

func (*IbkrWebClient) MarketDataHistory

func (c *IbkrWebClient) MarketDataHistory(
	conId int,
	period string,
	barType string,
) (*MarketDataHistoryResponse, error)

func (*IbkrWebClient) MarketDataSnapshot

func (c *IbkrWebClient) MarketDataSnapshot(
	conIds []int,
) ([]MarketDataSnapshot, error)

func (*IbkrWebClient) ParseJsonResponse

func (c *IbkrWebClient) ParseJsonResponse(response *clientResponse, v interface{}) error

func (*IbkrWebClient) PlaceOrder

func (c *IbkrWebClient) PlaceOrder(accountId string, order Order) (*PlaceOrderResponse, error)

func (*IbkrWebClient) Post

func (c *IbkrWebClient) Post(path string, queryParams map[string]string, body interface{}) (*clientResponse, error)

func (*IbkrWebClient) ResetAuthentication added in v1.1.0

func (c *IbkrWebClient) ResetAuthentication()

func (*IbkrWebClient) SearchContractBySymbol

func (c *IbkrWebClient) SearchContractBySymbol(symbol string) ([]SearchContractBySymbolResponse, error)

func (*IbkrWebClient) SuppressMessages added in v0.4.0

func (c *IbkrWebClient) SuppressMessages() error

func (*IbkrWebClient) SwitchAccount

func (c *IbkrWebClient) SwitchAccount(accountId string) error

func (*IbkrWebClient) Tickle

func (c *IbkrWebClient) Tickle() (*TickleResponse, error)

type InitializeBrokerageSessionRequest

type InitializeBrokerageSessionRequest struct {
	Publish bool `json:"publish" validation:"required"`
	Compete bool `json:"compete" validation:"required"`
}

type LiveOrdersResponse

type LiveOrdersResponse struct {
	Orders []OrderStatus `json:"orders" validation:"required"`
}

type LogoutResponse

type LogoutResponse struct {
	Status bool `json:"status" validation:"required"`
}

type MarketDataHistoryResponse

type MarketDataHistoryResponse struct {
	StartTime       string    `json:"startTime" validation:"required"`
	Data            []OHLCBar `json:"data" validation:"required"`
	Points          int       `json:"points" validation:"required"`
	MarketDataDelay int       `json:"mktDataDelay" validation:"required"`
}

type MarketDataSnapshot

type MarketDataSnapshot struct {
	ConID         int
	TradingHalted bool
	TradingActive bool
	LastPrice     float64
}

type MarketDataSnapshotResponse

type MarketDataSnapshotResponse struct {
	ConID      int    `json:"conid" validation:"required"`
	LastPrice  string `json:"31" validation:"required"`
	High       string `json:"70" validation:"required"`
	Low        string `json:"71" validation:"required"`
	Open       string `json:"7295" validation:"required"`
	Mark       string `json:"7635" validation:"required"`
	PriorClose string `json:"7741" validation:"required"`
}

type OAuthContext

type OAuthContext interface {
	GenerateLiveSessionToken(client *http.Client, baseUrl string) error
	GetOAuthHeader(method string, requestUrl string) (string, error)
	ShouldReAuthenticate() bool
	Reset()
}

type OAuthParams

type OAuthParams map[string]string

func (OAuthParams) ToHeaderString

func (p OAuthParams) ToHeaderString() string

func (OAuthParams) ToSignatureString

func (p OAuthParams) ToSignatureString() string

type OHLCBar

type OHLCBar struct {
	T int     `json:"t" validation:"required"`
	O float64 `json:"o" validation:"required"`
	C float64 `json:"c" validation:"required"`
	H float64 `json:"h" validation:"required"`
	L float64 `json:"l" validation:"required"`
	V float64 `json:"v" validation:"required"`
}

type Order

type Order struct {
	AccountId   string  `json:"acctId"`
	ConID       int32   `json:"conid"`
	OrderType   string  `json:"orderType"`
	Side        string  `json:"side"`
	TimeInForce string  `json:"tif"`
	Quantity    float64 `json:"quantity"`
}

type OrderStatus

type OrderStatus struct {
	Account           string  `json:"acct" validation:"required"`
	ConID             int32   `json:"conid" validation:"required"`
	OrderID           int32   `json:"orderId" validation:"required"`
	Ticker            string  `json:"ticker" validation:"required"`
	RemainingQuantity float64 `json:"remainingQuantity" validation:"required"`
	FilledQuantity    float64 `json:"filledQuantity" validation:"required"`
	Status            string  `json:"status" validation:"required"`
	OrderType         string  `json:"orderType" validation:"required"`
	Side              string  `json:"side" validation:"required"`
	TimeInForce       string  `json:"timeInForce" validation:"required"`
}

type PlaceOrderRejectResponse

type PlaceOrderRejectResponse struct {
	Error string `json:"error" validation:"required"`
}

type PlaceOrderRequest

type PlaceOrderRequest struct {
	Orders []Order `json:"orders"`
}

type PlaceOrderResponse

type PlaceOrderResponse struct {
	ID         string
	Status     string
	Message    string
	MessageIDs []string
}

type PlaceOrderResponseMessage

type PlaceOrderResponseMessage struct {
	ID           string   `json:"id" validation:"required"`
	Message      string   `json:"message" validation:"required"`
	IsSuppressed bool     `json:"isSupressed" validation:"required"`
	MessageIDs   []string `json:"messageIds" validation:"required"`
}

type PlaceOrderResponsePlain

type PlaceOrderResponsePlain struct {
	OrderID     string `json:"order_id" validation:"required"`
	OrderStatus string `json:"order_status" validation:"required"`
}

type PortfolioAccountLedger

type PortfolioAccountLedger struct {
	Base AccountLedger `json:"BASE" validation:"required"`
}

type PortfolioSubaccount

type PortfolioSubaccount struct {
	ID              string `json:"id" validation:"required"`
	Currency        string `json:"currency" validation:"required"`
	Type            string `json:"type" validation:"required"`
	BusinessType    string `json:"businessType" validation:"required"`
	IBEntity        string `json:"ibEntity" validation:"required"`
	ClearingStatus  string `json:"clearingStatus" validation:"required"`
	NoClientTrading bool   `json:"noClientTrading" validation:"required"`
}

type Position

type Position struct {
	AccountID     string  `json:"acctId" validation:"required"`
	ConID         int32   `json:"conid" validation:"required"`
	ContractDesc  string  `json:"contractDesc" validation:"required"`
	Position      float64 `json:"position" validation:"required"`
	MarketPrice   float64 `json:"mktPrice" validation:"required"`
	MarketValue   float64 `json:"mktValue" validation:"required"`
	AveragePrice  float64 `json:"avgPrice" validation:"required"`
	AverageCost   float64 `json:"avgCost" validation:"required"`
	RealizedPnL   float64 `json:"realizedPnl" validation:"required"`
	UnrealizedPnL float64 `json:"unrealizedPnl" validation:"required"`
	Name          string  `json:"name" validation:"required"`
	Ticker        string  `json:"ticker" validation:"required"`
	PageSize      int32   `json:"pageSize" validation:"required"`
}

type SearchContractBySymbolResponse

type SearchContractBySymbolResponse struct {
	ConID       string `json:"conid" validate:"required"`
	CompanyName string `json:"companyName" validate:"required"`
}

type ServerInfo

type ServerInfo struct {
	ServerName    string `json:"serverName" validation:"required"`
	ServerVersion string `json:"serverVersion" validation:"required"`
}

type SupressMessagesRequest added in v0.4.0

type SupressMessagesRequest struct {
	MessageIDs []string `json:"messageIds"`
}

type SwitchAccountRequest

type SwitchAccountRequest struct {
	AccountID string `json:"acctId"`
}

type SwitchAccountResponse

type SwitchAccountResponse struct {
	Set       bool   `json:"set" validate:"required"`
	AccountID string `json:"acctId"`
}

type SwitchAccountResponseAlreadySet added in v1.1.1

type SwitchAccountResponseAlreadySet struct {
	Success string `json:"success" validate:"required"`
}

type TickleResponse

type TickleResponse struct {
	Session    string         `json:"session" validation:"required"`
	SSOExpires int32          `json:"ssoExpires" validation:"required"`
	Collission bool           `json:"collission" validation:"required"`
	UserID     int32          `json:"userId" validation:"required"`
	HMDS       HMDSDetails    `json:"hmds" validation:"required"`
	IServer    IServerDetails `json:"iserver" validation:"required"`
}

Jump to

Keyboard shortcuts

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