Sample code for 30+ languages & platforms
AutoIt

ETrade List Accounts

See more ETrade Examples

Returns a list of E*TRADE accounts for the current user.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oHttp = ObjCreate("Chilkat.Http")

$oHttp.OAuth1 = True
$oHttp.OAuthVerifier = ""
$oHttp.OAuthConsumerKey = "ETRADE_CONSUMER_KEY"
$oHttp.OAuthConsumerSecret = "ETRADE_CONSUMER_SECRET"

;  Load the access token previously obtained via the OAuth1 Authorization
$oJsonToken = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oJsonToken.LoadFile("qa_data/tokens/etrade.json")
If ($bSuccess <> True) Then
    ConsoleWrite("Failed to load OAuth1 token" & @CRLF)
    Exit
EndIf

$oHttp.OAuthToken = $oJsonToken.StringOf("oauth_token")
$oHttp.OAuthTokenSecret = $oJsonToken.StringOf("oauth_token_secret")

Local $sandboxUrl = "https://apisb.etrade.com/v1/accounts/list"
Local $sLiveUrl = "https://api.etrade.com/v1/accounts/list"

$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpNoBody("GET",$sandboxUrl,$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

;  Make sure a successful response was received.
If ($oResp.StatusCode >= 300) Then
    ConsoleWrite($oResp.StatusLine & @CRLF)
    ConsoleWrite($oResp.Header & @CRLF)
    ConsoleWrite($oResp.BodyStr & @CRLF)
    Exit
EndIf

If ($oResp.StatusCode = 204) Then
    ConsoleWrite("No records available." & @CRLF)
    Exit
EndIf

;  Sample XML response:

;  Use this online tool to generate parsing code from sample XML: 
;  Generate Parsing Code from XML

;  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
;  <AccountListResponse>
;      <Accounts>
;          <Account>
;              <accountId>82314598</accountId>
;              <accountIdKey>dBZOKt9xDrtRSAOl4MSiiA</accountIdKey>
;              <accountMode>IRA</accountMode>
;              <accountDesc>Brokerage</accountDesc>
;              <accountName>NickName-1</accountName>
;              <accountType>MARGIN</accountType>
;              <institutionType>BROKERAGE</institutionType>
;              <accountStatus>ACTIVE</accountStatus>
;              <closedDate>0</closedDate>
;          </Account>
;          <Account>
;              <accountId>58315636</accountId>
;              <accountIdKey>vQMsebA1H5WltUfDkJP48g</accountIdKey>
;              <accountMode>BROKERAGE</accountMode>
;              <accountDesc>Complete Savings</accountDesc>
;              <accountName>NickName-2</accountName>
;              <accountType>INDIVIDUAL</accountType>
;              <institutionType>BROKERAGE</institutionType>
;              <accountStatus>ACTIVE</accountStatus>
;              <closedDate>0</closedDate>
;          </Account>
;          <Account>
;              <accountId>70700418</accountId>
;              <accountIdKey>6_Dpy0rmuQ9cu9IbTfvF2A</accountIdKey>
;              <accountMode>CASH</accountMode>
;              <accountDesc>INDIVIDUAL</accountDesc>
;              <accountName>NickName-3</accountName>
;              <accountType>INDIVIDUAL</accountType>
;              <institutionType>BROKERAGE</institutionType>
;              <accountStatus>ACTIVE</accountStatus>
;              <closedDate>0</closedDate>
;          </Account>
;          <Account>
;              <accountId>83515143</accountId>
;              <accountIdKey>xj1Dc18FTqWPqkEEVUr5rw</accountIdKey>
;              <accountMode>CASH</accountMode>
;              <accountDesc>INDIVIDUAL</accountDesc>
;              <accountName/>
;              <accountType>CASH</accountType>
;              <institutionType>BROKERAGE</institutionType>
;              <accountStatus>CLOSED</accountStatus>
;              <closedDate>1521027780</closedDate>
;  
;          </Account>
;      </Accounts>
;  </AccountListResponse>

$oXml = ObjCreate("Chilkat.Xml")
$oXml.LoadXml($oResp.BodyStr)
ConsoleWrite($oXml.GetXml() & @CRLF)

Local $iAccountId
Local $sAccountIdKey
Local $sAccountMode
Local $sAccountDesc
Local $sAccountName
Local $sAccountType
Local $sInstitutionType
Local $sAccountStatus
Local $iClosedDate

Local $i = 0
Local $iCount_i = $oXml.NumChildrenHavingTag("Accounts|Account")
While $i < $iCount_i
    $oXml.I = $i
    $iAccountId = $oXml.GetChildIntValue("Accounts|Account[i]|accountId")
    $sAccountIdKey = $oXml.GetChildContent("Accounts|Account[i]|accountIdKey")
    $sAccountMode = $oXml.GetChildContent("Accounts|Account[i]|accountMode")
    $sAccountDesc = $oXml.GetChildContent("Accounts|Account[i]|accountDesc")
    $sAccountName = $oXml.GetChildContent("Accounts|Account[i]|accountName")
    $sAccountType = $oXml.GetChildContent("Accounts|Account[i]|accountType")
    $sInstitutionType = $oXml.GetChildContent("Accounts|Account[i]|institutionType")
    $sAccountStatus = $oXml.GetChildContent("Accounts|Account[i]|accountStatus")
    $iClosedDate = $oXml.GetChildIntValue("Accounts|Account[i]|closedDate")
    $i = $i + 1
Wend

ConsoleWrite("Success." & @CRLF)