Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) ETrade List AccountsReturns a list of E*TRADE accounts for the current user. For more information, see https://apisb.etrade.com/docs/api/account/api-account-v1.html
load ./chilkat.dll # 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" # resp is a CkHttpResponse set resp [CkHttp_QuickGetObj $http $sandboxUrl] if {[CkHttp_get_LastMethodSuccess $http] != 1} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkJsonObject $jsonToken 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 exit } if {[CkHttpResponse_get_StatusCode $resp] == 204} then { puts "No records available." delete_CkHttp $http delete_CkJsonObject $jsonToken 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_CkXml $xml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.