API Reference

View Source

This reference guide provides detailed information about all modules and functions available in the IbkrApi library.

Core Modules

IbkrApi

IbkrApi module that serves as the entry point to the library.

IbkrApi.Config

IbkrApi.Config module for configuration management.

# Get the base URL for API requests
base_url = IbkrApi.Config.base_url()

IbkrApi.HTTP

IbkrApi.HTTP module for making requests to the Interactive Brokers Client Portal API.

# Make a GET request
{:ok, response} = IbkrApi.HTTP.get("https://localhost:5000/v1/api/endpoint")

# Make a POST request with a body
body = %{key: "value"}
{:ok, response} = IbkrApi.HTTP.post("https://localhost:5000/v1/api/endpoint", body)

Client Portal Modules

IbkrApi.ClientPortal.Auth

IbkrApi.ClientPortal.Auth module for authentication and session management.

Functions

FunctionDescriptionParametersReturn Value
ping_server/0Checks server connectivity and authentication statusNone{:ok, %PingServerResponse{}} or {:error, reason}
reauthenticate/0Attempts to reauthenticate an expired sessionNone{:ok, %ReauthenticateResponse{}} or {:error, reason}
end_session/0Ends the current sessionNone{:ok, %EndSessionResponse{}} or {:error, reason}
validate_sso/0Validates Single Sign-On statusNone{:ok, %ValidateSSOResponse{}} or {:error, reason}
check_auth_status/0Checks the current authentication statusNone{:ok, %CheckAuthStatusResponse{}} or {:error, reason}

IbkrApi.ClientPortal.Account

IbkrApi.ClientPortal.Account module for managing account information and operations.

Functions

FunctionDescriptionParametersReturn Value
list_accounts/0Lists all portfolio accountsNone{:ok, [%Account{}]} or {:error, reason}
list_sub_accounts/0Lists all sub-accountsNone{:ok, [%SubAccount{}]} or {:error, reason}
list_large_sub_accounts/1Lists sub-accounts with paginationpage (String){:ok, %LargeSubAccounts{}} or {:error, reason}
account_info/1Gets account metadataaccount_id (String){:ok, %Account{}} or {:error, reason}
account_summary/1Gets account summaryaccount_id (String){:ok, %AccountSummary{}} or {:error, reason}
account_ledger/1Gets account ledgeraccount_id (String){:ok, %AccountLedger{}} or {:error, reason}
list_brokerage_accounts/0Lists all brokerage accountsNone{:ok, %BrokerageAccountsResponse{}} or {:error, reason}
switch_account/1Switches the active accountacctId (String){:ok, %SwitchAccountResponse{}} or {:error, reason}
get_pnl/0Gets profit and loss informationNone{:ok, %PnLResponse{}} or {:error, reason}

IbkrApi.ClientPortal.Contract

IbkrApi.ClientPortal.Contract module for managing financial instruments and contracts.

Functions

FunctionDescriptionParametersReturn Value
search_by_symbol/1Searches for contracts by symbolsymbol (String){:ok, [%Contract{}]} or {:error, reason}
get_contract_details/1Gets detailed information for a contractconid (Integer){:ok, %ContractDetails{}} or {:error, reason}
get_contract_info/1Gets basic information for a contractconid (Integer){:ok, %ContractInfo{}} or {:error, reason}

IbkrApi.ClientPortal.Order

IbkrApi.ClientPortal.Order module for managing order placement and monitoring.

Functions

FunctionDescriptionParametersReturn Value
place_order/1Places a new orderorder_params (Map){:ok, %OrderResponse{}} or {:error, reason}
modify_order/2Modifies an existing orderorder_id (String), order_params (Map){:ok, %OrderResponse{}} or {:error, reason}
cancel_order/1Cancels an orderorder_id (String){:ok, %CancelResponse{}} or {:error, reason}
get_live_orders/0Gets all live ordersNone{:ok, [%Order{}]} or {:error, reason}
get_order_status/1Gets status of a specific orderorder_id (String){:ok, %Order{}} or {:error, reason}

IbkrApi.ClientPortal.Profile

IbkrApi.ClientPortal.Profile module for managing user profile information.

Functions

FunctionDescriptionParametersReturn Value
get_profile/0Gets user profile informationNone{:ok, %Profile{}} or {:error, reason}
update_profile/1Updates user profileprofile_params (Map){:ok, %UpdateProfileResponse{}} or {:error, reason}

IbkrApi.ClientPortal.Trade

IbkrApi.ClientPortal.Trade module for managing trade executions and history.

Functions

FunctionDescriptionParametersReturn Value
get_executions/1Gets trade executions for an accountaccount_id (String){:ok, [%Execution{}]} or {:error, reason}

Error Handling

All API functions return {:ok, result} on success and {:error, reason} on failure. The error reason is typically an ErrorMessage struct with the following fields:

%ErrorMessage{
  code: "1234",       # Error code
  message: "Error message description",
  description: "Detailed error description"
}

Common Error Codes

CodeDescription
"1015"Account not found or not authorized
"1021"Session expired, please reauthenticate
"1022"Invalid contract ID
"1100"Invalid order parameters
"1101"Insufficient funds
"2000"Server error