PowerBuilder
PowerBuilder
ETrade v1 Get Account Balances
See more HTTP Misc Examples
Get account balances using the ETrade v1 API.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
string ls_RespStr
integer li_StatusCode
oleobject loo_Xml
string ls_TagPath
integer li_AccountId
string ls_AccountType
string ls_OptionLevel
string ls_AccountDescription
integer li_QuoteMode
string ls_DayTraderStatus
string ls_AccountMode
integer li_FundsForOpenOrdersCash
integer li_MoneyMktBalance
integer li_CashAvailableForInvestment
string ls_NetCash
string ls_CashBalance
integer li_SettledCashForInvestment
integer li_UnSettledCashForInvestment
integer li_FundsWithheldFromPurchasePower
integer li_FundsWithheldFromWithdrawal
integer li_MarginBuyingPower
string ls_CashBuyingPower
integer li_DtMarginBuyingPower
integer li_DtCashBuyingPower
integer li_ShortAdjustBalance
integer li_RegtEquity
integer li_RegtEquityPercent
integer li_AccountBalance
integer li_DtCashOpenOrderReserve
integer li_DtMarginOpenOrderReserve
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.OAuth1 = 1
loo_Http.OAuthVerifier = ""
loo_Http.OAuthConsumerKey = "ETRADE_CONSUMER_KEY"
loo_Http.OAuthConsumerSecret = "ETRADE_CONSUMER_SECRET"
// Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Json.LoadFile("qa_data/tokens/etrade.json")
if li_Success <> 1 then
Write-Debug "Failed to load OAuth1 token"
destroy loo_Http
destroy loo_Json
return
end if
loo_Http.OAuthToken = loo_Json.StringOf("oauth_token")
loo_Http.OAuthTokenSecret = loo_Json.StringOf("oauth_token_secret")
// See the ETrade v1 API documentation HERE.
loo_Http.SetUrlVar("accountIdKey","vsnhtF7d9jXxBy6HyaAC4vQ")
loo_Http.SetUrlVar("instType","BROKERAGE")
ls_RespStr = loo_Http.QuickGetStr("https://apisb.etrade.com/v1/accounts/{$accountIdKey}/balance?instType={$instType}&realTimeNAV=true")
if loo_Http.LastMethodSuccess <> 1 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
return
end if
// A 200 status code indicates success.
li_StatusCode = loo_Http.LastStatus
Write-Debug "statusCode = " + string(li_StatusCode)
// Use the following online tool to generate parsing code from sample XML:
// Generate Parsing Code from XML
// A sample XML response is shown below...
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
loo_Xml.LoadXml(ls_RespStr)
li_AccountId = loo_Xml.GetChildIntValue("accountId")
ls_AccountType = loo_Xml.GetChildContent("accountType")
ls_OptionLevel = loo_Xml.GetChildContent("optionLevel")
ls_AccountDescription = loo_Xml.GetChildContent("accountDescription")
li_QuoteMode = loo_Xml.GetChildIntValue("quoteMode")
ls_DayTraderStatus = loo_Xml.GetChildContent("dayTraderStatus")
ls_AccountMode = loo_Xml.GetChildContent("accountMode")
li_FundsForOpenOrdersCash = loo_Xml.GetChildIntValue("Cash|fundsForOpenOrdersCash")
li_MoneyMktBalance = loo_Xml.GetChildIntValue("Cash|moneyMktBalance")
li_CashAvailableForInvestment = loo_Xml.GetChildIntValue("Computed|cashAvailableForInvestment")
ls_NetCash = loo_Xml.GetChildContent("Computed|netCash")
ls_CashBalance = loo_Xml.GetChildContent("Computed|cashBalance")
li_SettledCashForInvestment = loo_Xml.GetChildIntValue("Computed|settledCashForInvestment")
li_UnSettledCashForInvestment = loo_Xml.GetChildIntValue("Computed|unSettledCashForInvestment")
li_FundsWithheldFromPurchasePower = loo_Xml.GetChildIntValue("Computed|fundsWithheldFromPurchasePower")
li_FundsWithheldFromWithdrawal = loo_Xml.GetChildIntValue("Computed|fundsWithheldFromWithdrawal")
li_MarginBuyingPower = loo_Xml.GetChildIntValue("Computed|marginBuyingPower")
ls_CashBuyingPower = loo_Xml.GetChildContent("Computed|cashBuyingPower")
li_DtMarginBuyingPower = loo_Xml.GetChildIntValue("Computed|dtMarginBuyingPower")
li_DtCashBuyingPower = loo_Xml.GetChildIntValue("Computed|dtCashBuyingPower")
li_ShortAdjustBalance = loo_Xml.GetChildIntValue("Computed|shortAdjustBalance")
li_RegtEquity = loo_Xml.GetChildIntValue("Computed|regtEquity")
li_RegtEquityPercent = loo_Xml.GetChildIntValue("Computed|regtEquityPercent")
li_AccountBalance = loo_Xml.GetChildIntValue("Computed|accountBalance")
li_DtCashOpenOrderReserve = loo_Xml.GetChildIntValue("Margin|dtCashOpenOrderReserve")
li_DtMarginOpenOrderReserve = loo_Xml.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>
destroy loo_Http
destroy loo_Json
destroy loo_Xml