Sample code for 30+ languages & platforms
Lianja

ETrade v1 List Accounts

See more HTTP Misc Examples

List ETrade accounts using the ETrade v1 API.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loHttp = createobject("CkHttp")

loHttp.OAuth1 = .T.
loHttp.OAuthVerifier = ""
loHttp.OAuthConsumerKey = "ETRADE_CONSUMER_KEY"
loHttp.OAuthConsumerSecret = "ETRADE_CONSUMER_SECRET"

// Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2.
loJson = createobject("CkJsonObject")
llSuccess = loJson.LoadFile("qa_data/tokens/etrade.json")
if (llSuccess <> .T.) then
    ? "Failed to load OAuth1 token"
    release loHttp
    release loJson
    return
endif

loHttp.OAuthToken = loJson.StringOf("oauth_token")
loHttp.OAuthTokenSecret = loJson.StringOf("oauth_token_secret")

// See the ETrade v1 API documentation HERE.

lcRespStr = loHttp.QuickGetStr("https://apisb.etrade.com/v1/accounts/list")
if (loHttp.LastMethodSuccess <> .T.) then
    ? loHttp.LastErrorText
    release loHttp
    release loJson
    return
endif

// A 200 status code indicates success.
lnStatusCode = loHttp.LastStatus
? "statusCode = " + str(lnStatusCode)

// Use the following online tool to generate parsing code from sample XML: 
// Generate Parsing Code from XML

// A sample XML response is shown below...

loXml = createobject("CkXml")
loXml.LoadXml(lcRespStr)

i = 0
lnCount_i = loXml.NumChildrenHavingTag("Accounts|Account")
do while i < lnCount_i
    loXml.I = i
    lnAccountId = loXml.GetChildIntValue("Accounts|Account[i]|accountId")
    lcAccountIdKey = loXml.GetChildContent("Accounts|Account[i]|accountIdKey")
    lcAccountMode = loXml.GetChildContent("Accounts|Account[i]|accountMode")
    lcAccountDesc = loXml.GetChildContent("Accounts|Account[i]|accountDesc")
    lcAccountName = loXml.GetChildContent("Accounts|Account[i]|accountName")
    lcAccountType = loXml.GetChildContent("Accounts|Account[i]|accountType")
    lcInstitutionType = loXml.GetChildContent("Accounts|Account[i]|institutionType")
    lcAccountStatus = loXml.GetChildContent("Accounts|Account[i]|accountStatus")
    lnClosedDate = loXml.GetChildIntValue("Accounts|Account[i]|closedDate")
    i = i + 1
enddo

// <?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>


release loHttp
release loJson
release loXml