Sample code for 30+ languages & platforms
Rust

ETrade List Transactions

See more ETrade Examples

Gets transactions for the selected brokerage account.

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/{$accountIdKey}/transactions".to_string();
let live_url = "https://api.etrade.com/v1/accounts/{$accountIdKey}/transactions".to_string();

let _ = http.set_url_var("accountIdKey", "6_Dpy0rmuQ9cu9IbTfvF2A");

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() > 200 {
    println!("{}", resp.status_line());
    println!("{}", resp.header());
    println!("{}", resp.body_str());
    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"?>
// <TransactionListResponse>
//    <Transaction>
//       <transactionId>18165100001766</transactionId>
//       <accountId>83564979</accountId>
//       <transactionDate>1528948800000</transactionDate>
//       <postDate>1528948800000</postDate>
//       <amount>-2</amount>
//       <description>ACH WITHDRAWL REFID:109187276;</description>
//       <description2>109187276</description2>
//       <transactionType>Transfer</transactionType>
//       <memo />
//       <imageFlag>false</imageFlag>
//       <instType>BROKERAGE</instType>
//       <brokerage>
//          <product />
//          <quantity>0</quantity>
//          <price>0</price>
//          <settlementCurrency>USD</settlementCurrency>
//          <paymentCurrency>USD</paymentCurrency>
//          <fee>0</fee>
//          <settlementDate>1528948800000</settlementDate>
//       </brokerage>
//       <detailsURI>https://api.etrade.com/v1/accounts/yIFaUoJ81qyAhgxLWRQ42g/transactions/18165100001766</detailsURI>
//    </Transaction>
//    <Transaction>
//       <transactionId>18158100000983</transactionId>
//       <accountId>83564979</accountId>
//       <transactionDate>1528344000000</transactionDate>
//       <postDate>1528344000000</postDate>
//       <amount>-2</amount>
//       <description>ACH WITHDRAWL REFID:98655276;</description>
//       <description2>98655276</description2>
//       <transactionType>Transfer</transactionType>
//       <memo />
//       <imageFlag>false</imageFlag>
//       <instType>BROKERAGE</instType>
//       <brokerage>
//          <product />
//          <quantity>0</quantity>
//          <price>0</price>
//          <settlementCurrency>USD</settlementCurrency>
//          <paymentCurrency>USD</paymentCurrency>
//          <fee>0</fee>
//          <settlementDate>1528344000000</settlementDate>
//       </brokerage>
//       <detailsURI>https://api.etrade.com/v1/accounts/yIFaUoJ81qyAhgxLWRQ42g/transactions/18158100000983</detailsURI>
//    </Transaction>
//    <pageMarkers>eNpTsAlITE91zi%2FNK%2FHMc04syi8tTs2xM7TRxybMpWATkl%2BSmBOUmpxflAKWtTO10ccQg6mDmwEyEE0EqAbE8SvNTUotCk4tLE3NS061M9Ax0DEEYgOIA9BkuRQgmjxTfDKLQUYoQAV8E4uyU4vsDC0MzUwNDYDA0NzMrKamBmIKVJYLphpiKsyTUB7IbH1kwwFa7F0D</pageMarkers>
//    <moreTransactions>false</moreTransactions>
//    <transactionCount>5</transactionCount>
//    <totalCount>5</totalCount>
// </TransactionListResponse>

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("Transaction");
while i < count_i {
    xml.set_i(i);
    let _ = xml.get_child_content("Transaction[i]|transactionId").unwrap_or_default();
    let _ = xml.get_child_int_value("Transaction[i]|accountId");
    let _ = xml.get_child_content("Transaction[i]|transactionDate").unwrap_or_default();
    let _ = xml.get_child_content("Transaction[i]|postDate").unwrap_or_default();
    let _ = xml.get_child_int_value("Transaction[i]|amount");
    let _ = xml.get_child_content("Transaction[i]|description").unwrap_or_default();
    let _ = xml.get_child_int_value("Transaction[i]|description2");
    let _ = xml.get_child_content("Transaction[i]|transactionType").unwrap_or_default();
    let _ = xml.get_child_content("Transaction[i]|imageFlag").unwrap_or_default();
    let _ = xml.get_child_content("Transaction[i]|instType").unwrap_or_default();
    let _ = xml.get_child_int_value("Transaction[i]|brokerage|quantity");
    let _ = xml.get_child_int_value("Transaction[i]|brokerage|price");
    let _ = xml.get_child_content("Transaction[i]|brokerage|settlementCurrency").unwrap_or_default();
    let _ = xml.get_child_content("Transaction[i]|brokerage|paymentCurrency").unwrap_or_default();
    let _ = xml.get_child_int_value("Transaction[i]|brokerage|fee");
    let _ = xml.get_child_content("Transaction[i]|brokerage|settlementDate").unwrap_or_default();
    let _ = xml.get_child_content("Transaction[i]|detailsURI").unwrap_or_default();
    i = i + 1;
}

let page_markers = xml.get_child_content("pageMarkers").unwrap_or_default();
let more_transactions = xml.get_child_content("moreTransactions").unwrap_or_default();
let transaction_count = xml.get_child_int_value("transactionCount");
let total_count = xml.get_child_int_value("totalCount");

println!("Success.");