Lua
Lua
ETrade v1 List Accounts
See more HTTP Misc Examples
List ETrade accounts using the ETrade v1 API.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
http.oauth1 = true
http.oauth_verifier = ""
http.oauth_consumer_key = "ETRADE_CONSUMER_KEY"
http.oauth_consumer_secret = "ETRADE_CONSUMER_SECRET"
-- Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2.
local json = chilkat.JsonObject.new()
local success = json:load_file("qa_data/tokens/etrade.json")
if not success then
print("Failed to load OAuth1 token")
return
end
http.oauth_token = json:string_of("oauth_token")
http.oauth_token_secret = json:string_of("oauth_token_secret")
-- See the ETrade v1 API documentation HERE.
local respStr = http:quick_get_str("https://apisb.etrade.com/v1/accounts/list")
if not http.last_method_success then
print(http.last_error_text)
return
end
-- A 200 status code indicates success.
local statusCode = http.last_status
print("statusCode = " .. 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...
local xml = chilkat.Xml.new()
xml:load_xml(respStr)
local tagPath = ""
local accountId = 0
local accountIdKey = ""
local accountMode = ""
local accountDesc = ""
local accountName = ""
local accountType = ""
local institutionType = ""
local accountStatus = ""
local closedDate = 0
local i = 0
local count_i = xml:num_children_having_tag("Accounts|Account")
while i < count_i do
xml.i = i
accountId = xml:get_child_int_value("Accounts|Account[i]|accountId")
accountIdKey = xml:get_child_content("Accounts|Account[i]|accountIdKey")
accountMode = xml:get_child_content("Accounts|Account[i]|accountMode")
accountDesc = xml:get_child_content("Accounts|Account[i]|accountDesc")
accountName = xml:get_child_content("Accounts|Account[i]|accountName")
accountType = xml:get_child_content("Accounts|Account[i]|accountType")
institutionType = xml:get_child_content("Accounts|Account[i]|institutionType")
accountStatus = xml:get_child_content("Accounts|Account[i]|accountStatus")
closedDate = xml:get_child_int_value("Accounts|Account[i]|closedDate")
i = i + 1
end
-- <?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>