PowerBuilder
PowerBuilder
ETrade v1 List Accounts
See more HTTP Misc Examples
List ETrade accounts 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
integer i
integer li_Count_i
string ls_TagPath
integer li_AccountId
string ls_AccountIdKey
string ls_AccountMode
string ls_AccountDesc
string ls_AccountName
string ls_AccountType
string ls_InstitutionType
string ls_AccountStatus
integer li_ClosedDate
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.
ls_RespStr = loo_Http.QuickGetStr("https://apisb.etrade.com/v1/accounts/list")
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)
i = 0
li_Count_i = loo_Xml.NumChildrenHavingTag("Accounts|Account")
do while i < li_Count_i
loo_Xml.I = i
li_AccountId = loo_Xml.GetChildIntValue("Accounts|Account[i]|accountId")
ls_AccountIdKey = loo_Xml.GetChildContent("Accounts|Account[i]|accountIdKey")
ls_AccountMode = loo_Xml.GetChildContent("Accounts|Account[i]|accountMode")
ls_AccountDesc = loo_Xml.GetChildContent("Accounts|Account[i]|accountDesc")
ls_AccountName = loo_Xml.GetChildContent("Accounts|Account[i]|accountName")
ls_AccountType = loo_Xml.GetChildContent("Accounts|Account[i]|accountType")
ls_InstitutionType = loo_Xml.GetChildContent("Accounts|Account[i]|institutionType")
ls_AccountStatus = loo_Xml.GetChildContent("Accounts|Account[i]|accountStatus")
li_ClosedDate = loo_Xml.GetChildIntValue("Accounts|Account[i]|closedDate")
i = i + 1
loop
// <?xml version="1.0" encoding="UTF-8"?>
// <AccountListResponse>
// <Accounts>
// <Account>
// <accountId>84010429</accountId>
// <accountIdKey>JIdOIAcSpwR1Jva7RQBraQ</accountIdKey>
// <accountMode>MARGIN</accountMode>
// <accountDesc>INDIVIDUAL</accountDesc>
// <accountName>Individual Brokerage</accountName>
// <accountType>INDIVIDUAL</accountType>
// <institutionType>BROKERAGE</institutionType>
// <accountStatus>ACTIVE</accountStatus>
// <closedDate>0</closedDate>
// </Account>
// <Account>
// <accountId>84010430</accountId>
// <accountIdKey>JAAOIAcSpwR1Jva7RQBraQ</accountIdKey>
// <accountMode>MARGIN</accountMode>
// <accountDesc>INDIVIDUAL</accountDesc>
// <accountName>Individual Brokerage</accountName>
// <accountType>INDIVIDUAL</accountType>
// <institutionType>BROKERAGE</institutionType>
// <accountStatus>ACTIVE</accountStatus>
// <closedDate>0</closedDate>
// </Account>
// </Accounts>
// </AccountListResponse>
destroy loo_Http
destroy loo_Json
destroy loo_Xml