Sample code for 30+ languages & platforms
Tcl

ETrade List Accounts

See more ETrade Examples

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

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set http [new_CkHttp]

CkHttp_put_OAuth1 $http 1
CkHttp_put_OAuthVerifier $http ""
CkHttp_put_OAuthConsumerKey $http "ETRADE_CONSUMER_KEY"
CkHttp_put_OAuthConsumerSecret $http "ETRADE_CONSUMER_SECRET"

# Load the access token previously obtained via the OAuth1 Authorization
set jsonToken [new_CkJsonObject]

set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/etrade.json"]
if {$success != 1} then {
    puts "Failed to load OAuth1 token"
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    exit
}

CkHttp_put_OAuthToken $http [CkJsonObject_stringOf $jsonToken "oauth_token"]
CkHttp_put_OAuthTokenSecret $http [CkJsonObject_stringOf $jsonToken "oauth_token_secret"]

set sandboxUrl "https://apisb.etrade.com/v1/accounts/list"
set liveUrl "https://api.etrade.com/v1/accounts/list"

set resp [new_CkHttpResponse]

set success [CkHttp_HttpNoBody $http "GET" $sandboxUrl $resp]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    delete_CkHttpResponse $resp
    exit
}

# Make sure a successful response was received.
if {[CkHttpResponse_get_StatusCode $resp] >= 300} then {
    puts [CkHttpResponse_statusLine $resp]
    puts [CkHttpResponse_header $resp]
    puts [CkHttpResponse_bodyStr $resp]
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    delete_CkHttpResponse $resp
    exit
}

if {[CkHttpResponse_get_StatusCode $resp] == 204} then {
    puts "No records available."
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    delete_CkHttpResponse $resp
    exit
}

# 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>

set xml [new_CkXml]

CkXml_LoadXml $xml [CkHttpResponse_bodyStr $resp]
puts [CkXml_getXml $xml]

set i 0
set count_i [CkXml_NumChildrenHavingTag $xml "Accounts|Account"]
while {$i < $count_i} {
    CkXml_put_I $xml $i
    set accountId [CkXml_GetChildIntValue $xml "Accounts|Account[i]|accountId"]
    set accountIdKey [CkXml_getChildContent $xml "Accounts|Account[i]|accountIdKey"]
    set accountMode [CkXml_getChildContent $xml "Accounts|Account[i]|accountMode"]
    set accountDesc [CkXml_getChildContent $xml "Accounts|Account[i]|accountDesc"]
    set accountName [CkXml_getChildContent $xml "Accounts|Account[i]|accountName"]
    set accountType [CkXml_getChildContent $xml "Accounts|Account[i]|accountType"]
    set institutionType [CkXml_getChildContent $xml "Accounts|Account[i]|institutionType"]
    set accountStatus [CkXml_getChildContent $xml "Accounts|Account[i]|accountStatus"]
    set closedDate [CkXml_GetChildIntValue $xml "Accounts|Account[i]|closedDate"]
    set i [expr $i + 1]
}

puts "Success."

delete_CkHttp $http
delete_CkJsonObject $jsonToken
delete_CkHttpResponse $resp
delete_CkXml $xml