Sample code for 30+ languages & platforms
Rust

ETrade List Accounts

See more ETrade Examples

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

Chilkat Rust Downloads

Rust

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

let http = chilkat::Http::new();

http.set_o_auth1(true);
http.set_o_auth_verifier("");
http.set_o_auth_consumer_key("ETRADE_CONSUMER_KEY");
http.set_o_auth_consumer_secret("ETRADE_CONSUMER_SECRET");

// Load the access token previously obtained via the OAuth1 Authorization
let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/etrade.json").is_err() {
    println!("Failed to load OAuth1 token");
    return;
}

http.set_o_auth_token(&json_token.string_of("oauth_token").unwrap_or_default());
http.set_o_auth_token_secret(&json_token.string_of("oauth_token_secret").unwrap_or_default());

let sandbox_url = "https://apisb.etrade.com/v1/accounts/list".to_string();
let live_url = "https://api.etrade.com/v1/accounts/list".to_string();

let resp = chilkat::HttpResponse::new();
if http.http_no_body("GET", &sandbox_url, &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

// Make sure a successful response was received.
if resp.status_code() >= 300 {
    println!("{}", resp.status_line());
    println!("{}", resp.header());
    println!("{}", resp.body_str());
    return;
}

if resp.status_code() == 204 {
    println!("No records available.");
    return;
}

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

let xml = chilkat::Xml::new();
let _ = xml.load_xml(&resp.body_str());
println!("{}", xml.get_xml().unwrap_or_default());

let mut i = 0;
let count_i = xml.num_children_having_tag("Accounts|Account");
while i < count_i {
    xml.set_i(i);
    let _ = xml.get_child_int_value("Accounts|Account[i]|accountId");
    let _ = xml.get_child_content("Accounts|Account[i]|accountIdKey").unwrap_or_default();
    let _ = xml.get_child_content("Accounts|Account[i]|accountMode").unwrap_or_default();
    let _ = xml.get_child_content("Accounts|Account[i]|accountDesc").unwrap_or_default();
    let _ = xml.get_child_content("Accounts|Account[i]|accountName").unwrap_or_default();
    let _ = xml.get_child_content("Accounts|Account[i]|accountType").unwrap_or_default();
    let _ = xml.get_child_content("Accounts|Account[i]|institutionType").unwrap_or_default();
    let _ = xml.get_child_content("Accounts|Account[i]|accountStatus").unwrap_or_default();
    let _ = xml.get_child_int_value("Accounts|Account[i]|closedDate");
    i = i + 1;
}

println!("Success.");