Xbase++
Xbase++
ETrade v1 Get Account Balances
See more HTTP Misc Examples
Get account balances using the ETrade v1 API.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL cRespStr
LOCAL nStatusCode
LOCAL oXml
LOCAL cTagPath
LOCAL nAccountId
LOCAL cAccountType
LOCAL cOptionLevel
LOCAL cAccountDescription
LOCAL nQuoteMode
LOCAL cDayTraderStatus
LOCAL cAccountMode
LOCAL nFundsForOpenOrdersCash
LOCAL nMoneyMktBalance
LOCAL nCashAvailableForInvestment
LOCAL cNetCash
LOCAL cCashBalance
LOCAL nSettledCashForInvestment
LOCAL nUnSettledCashForInvestment
LOCAL nFundsWithheldFromPurchasePower
LOCAL nFundsWithheldFromWithdrawal
LOCAL nMarginBuyingPower
LOCAL cCashBuyingPower
LOCAL nDtMarginBuyingPower
LOCAL nDtCashBuyingPower
LOCAL nShortAdjustBalance
LOCAL nRegtEquity
LOCAL nRegtEquityPercent
LOCAL nAccountBalance
LOCAL nDtCashOpenOrderReserve
LOCAL nDtMarginOpenOrderReserve
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
oHttp:OAuth1 := 1
oHttp:OAuthVerifier := ""
oHttp:OAuthConsumerKey := "ETRADE_CONSUMER_KEY"
oHttp:OAuthConsumerSecret := "ETRADE_CONSUMER_SECRET"
// Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2.
oJson := CreateObject("Chilkat.JsonObject")
nSuccess := oJson:LoadFile("qa_data/tokens/etrade.json")
IF (nSuccess != 1)
? "Failed to load OAuth1 token"
oHttp:destroy()
oJson:destroy()
RETURN
ENDIF
oHttp:OAuthToken := oJson:StringOf("oauth_token")
oHttp:OAuthTokenSecret := oJson:StringOf("oauth_token_secret")
// See the ETrade v1 API documentation HERE.
oHttp:SetUrlVar("accountIdKey", "vsnhtF7d9jXxBy6HyaAC4vQ")
oHttp:SetUrlVar("instType", "BROKERAGE")
cRespStr := oHttp:QuickGetStr("https://apisb.etrade.com/v1/accounts/{$accountIdKey}/balance?instType={$instType}&realTimeNAV=true")
IF (oHttp:LastMethodSuccess != 1)
? oHttp:LastErrorText
oHttp:destroy()
oJson:destroy()
RETURN
ENDIF
// A 200 status code indicates success.
nStatusCode := oHttp:LastStatus
? "statusCode = " + Str(nStatusCode)
// Use the following online tool to generate parsing code from sample XML:
// Generate Parsing Code from XML
// A sample XML response is shown below...
oXml := CreateObject("Chilkat.Xml")
oXml:LoadXml(cRespStr)
nAccountId := oXml:GetChildIntValue("accountId")
cAccountType := oXml:GetChildContent("accountType")
cOptionLevel := oXml:GetChildContent("optionLevel")
cAccountDescription := oXml:GetChildContent("accountDescription")
nQuoteMode := oXml:GetChildIntValue("quoteMode")
cDayTraderStatus := oXml:GetChildContent("dayTraderStatus")
cAccountMode := oXml:GetChildContent("accountMode")
nFundsForOpenOrdersCash := oXml:GetChildIntValue("Cash|fundsForOpenOrdersCash")
nMoneyMktBalance := oXml:GetChildIntValue("Cash|moneyMktBalance")
nCashAvailableForInvestment := oXml:GetChildIntValue("Computed|cashAvailableForInvestment")
cNetCash := oXml:GetChildContent("Computed|netCash")
cCashBalance := oXml:GetChildContent("Computed|cashBalance")
nSettledCashForInvestment := oXml:GetChildIntValue("Computed|settledCashForInvestment")
nUnSettledCashForInvestment := oXml:GetChildIntValue("Computed|unSettledCashForInvestment")
nFundsWithheldFromPurchasePower := oXml:GetChildIntValue("Computed|fundsWithheldFromPurchasePower")
nFundsWithheldFromWithdrawal := oXml:GetChildIntValue("Computed|fundsWithheldFromWithdrawal")
nMarginBuyingPower := oXml:GetChildIntValue("Computed|marginBuyingPower")
cCashBuyingPower := oXml:GetChildContent("Computed|cashBuyingPower")
nDtMarginBuyingPower := oXml:GetChildIntValue("Computed|dtMarginBuyingPower")
nDtCashBuyingPower := oXml:GetChildIntValue("Computed|dtCashBuyingPower")
nShortAdjustBalance := oXml:GetChildIntValue("Computed|shortAdjustBalance")
nRegtEquity := oXml:GetChildIntValue("Computed|regtEquity")
nRegtEquityPercent := oXml:GetChildIntValue("Computed|regtEquityPercent")
nAccountBalance := oXml:GetChildIntValue("Computed|accountBalance")
nDtCashOpenOrderReserve := oXml:GetChildIntValue("Margin|dtCashOpenOrderReserve")
nDtMarginOpenOrderReserve := oXml:GetChildIntValue("Margin|dtMarginOpenOrderReserve")
// <?xml version="1.0" encoding="UTF-8"?>
// <BalanceResponse>
// <accountId>83564979</accountId>
// <accountType>PDT_ACCOUNT</accountType>
// <optionLevel>LEVEL_4</optionLevel>
// <accountDescription>KRITHH TT</accountDescription>
// <quoteMode>6</quoteMode>
// <dayTraderStatus>PDT_MIN_EQUITY_RES_1XK</dayTraderStatus>
// <accountMode>PDT ACCOUNT</accountMode>
// <Cash>
// <fundsForOpenOrdersCash>0</fundsForOpenOrdersCash>
// <moneyMktBalance>0</moneyMktBalance>
// </Cash>
// <Computed>
// <cashAvailableForInvestment>0</cashAvailableForInvestment>
// <netCash>93921.44</netCash>
// <cashBalance>93921.44</cashBalance>
// <settledCashForInvestment>0</settledCashForInvestment>
// <unSettledCashForInvestment>0</unSettledCashForInvestment>
// <fundsWithheldFromPurchasePower>0</fundsWithheldFromPurchasePower>
// <fundsWithheldFromWithdrawal>0</fundsWithheldFromWithdrawal>
// <marginBuyingPower>0</marginBuyingPower>
// <cashBuyingPower>93921.44</cashBuyingPower>
// <dtMarginBuyingPower>0</dtMarginBuyingPower>
// <dtCashBuyingPower>0</dtCashBuyingPower>
// <shortAdjustBalance>0</shortAdjustBalance>
// <regtEquity>0</regtEquity>
// <regtEquityPercent>0</regtEquityPercent>
// <accountBalance>0</accountBalance>
// </Computed>
// <Margin>
// <dtCashOpenOrderReserve>0</dtCashOpenOrderReserve>
// <dtMarginOpenOrderReserve>0</dtMarginOpenOrderReserve>
// </Margin>
// </BalanceResponse>
oHttp:destroy()
oJson:destroy()
oXml:destroy()