Rust
Rust
ETrade List Orders
See more ETrade Examples
Gets the order details for a selected brokerage account based on the search criteria provided.Chilkat Rust Downloads
// 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}/orders".to_string();
let live_url = "https://api.etrade.com/v1/accounts/{$accountIdKey}/orders".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" standalone="yes"?>
// <OrdersResponse>
// <marker>12345678999</marker>
// <next>https://api.sit.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders?marker=12345678999</next>
// <Order>
// <orderId>479</orderId>
// <details>https://api.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders/479</details>
// <orderType>OPTN</orderType>
// <OrderDetail>
// <placedTime>123453456</placedTime>
// <orderValue>123.0000</orderValue>
// <status>OPEN</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>LIMIT</priceType>
// <limitPrice>1.5</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>RIMM</symbol>
// <securityType>OPTN</securityType>
// <callPut>CALL</callPut>
// <expiryYear>2012</expiryYear>
// <expiryMonth>3</expiryMonth>
// <expiryDay>9</expiryDay>
// <strikePrice>12</strikePrice>
// </Product>
// <symbolDescription>RESEARCH IN MOTION LTD COM</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>5</orderedQuantity>
// <filledQuantity>5</filledQuantity>
// <averageExecutionPrice>0</averageExecutionPrice>
// <estimatedCommission>9.99</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// </Order>
// <Order>
// <orderId>477</orderId>
// <details>https://api.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders/477</details>
// <orderType>ONE_CANCELS_ALL</orderType>
// <totalOrderValue>209.99</totalOrderValue>
// <totalCommission>10.74</totalCommission>
// <OrderDetail>
// <orderNumber>1</orderNumber>
// <placedTime>1331699203122</placedTime>
// <orderValue>123.0000</orderValue>
// <status>OPEN</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>LIMIT</priceType>
// <limitPrice>2</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <bracketedLimitPrice>2</bracketedLimitPrice>
// <initialStopPrice>2</initialStopPrice>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>ETFC</symbol>
// <securityType>EQ</securityType>
// </Product>
// <symbolDescription>ETRADE Financials</symbolDescription>
// <orderAction>BUY</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>100</orderedQuantity>
// <filledQuantity>0</filledQuantity>
// <averageExecutionPrice>0</averageExecutionPrice>
// <estimatedCommission>9.99</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// <OrderDetail>
// <orderNumber>2</orderNumber>
// <placedTime>1331699203</placedTime>
// <orderValue>231.0000</orderValue>
// <status>OPEN</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>LIMIT</priceType>
// <limitPrice>0.5</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <initialStopPrice>0.5</initialStopPrice>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>MON</symbol>
// <securityType>OPTN</securityType>
// <callPut>CALL</callPut>
// <expiryYear>2012</expiryYear>
// <expiryMonth>4</expiryMonth>
// <expiryDay>21</expiryDay>
// <strikePrice>85</strikePrice>
// </Product>
// <symbolDescription>MON Mar 9 '12 $85 Call</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>1</orderedQuantity>
// <filledQuantity>0</filledQuantity>
// <averageExecutionPrice>0</averageExecutionPrice>
// <estimatedCommission>9.99</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// </Order>
// <Order>
// <orderId>475</orderId>
// <details>https://api.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders/475</details>
// <orderType>SPREADS</orderType>
// <OrderDetail>
// <placedTime>1331742953</placedTime>
// <executedTime>1331742955432</executedTime>
// <orderValue>4445.99</orderValue>
// <status>EXECUTED</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>NET_DEBIT</priceType>
// <limitPrice>1.5</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>REE</symbol>
// <securityType>OPTN</securityType>
// <callPut>CALL</callPut>
// <expiryYear>2012</expiryYear>
// <expiryMonth>7</expiryMonth>
// <expiryDay>21</expiryDay>
// <strikePrice>7</strikePrice>
// </Product>
// <symbolDescription>REE Jul 21 '12 $7 Call</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>2</orderedQuantity>
// <filledQuantity>2</filledQuantity>
// <averageExecutionPrice>1.5</averageExecutionPrice>
// <estimatedCommission>7.24</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <Instrument>
// <Product>
// <symbol>REE</symbol>
// <securityType>OPTN</securityType>
// <callPut>PUT</callPut>
// <expiryYear>2013</expiryYear>
// <expiryMonth>1</expiryMonth>
// <expiryDay>19</expiryDay>
// <strikePrice>12.50</strikePrice>
// </Product>
// <symbolDescription>REE Jan 19 '13 $12.50 Put</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>2</orderedQuantity>
// <filledQuantity>2</filledQuantity>
// <averageExecutionPrice>1.5</averageExecutionPrice>
// <estimatedCommission>7.24</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// </Order>
// </OrdersResponse>
//
let xml = chilkat::Xml::new();
let _ = xml.load_xml(&resp.body_str());
println!("{}", xml.get_xml().unwrap_or_default());
let mut j: i32 = 0;
let mut count_j: i32 = 0;
let mut k: i32 = 0;
let mut count_k: i32 = 0;
let marker = xml.get_child_content("marker").unwrap_or_default();
let next = xml.get_child_content("next").unwrap_or_default();
let mut i = 0;
let count_i = xml.num_children_having_tag("Order");
while i < count_i {
xml.set_i(i);
let _ = xml.get_child_int_value("Order[i]|orderId");
let _ = xml.get_child_content("Order[i]|details").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|orderType").unwrap_or_default();
j = 0;
count_j = xml.num_children_having_tag("Order[i]|OrderDetail");
while j < count_j {
xml.set_j(j);
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|placedTime").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|orderValue").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|status").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|orderTerm").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|priceType").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|limitPrice").unwrap_or_default();
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|stopPrice");
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|marketSession").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|allOrNone").unwrap_or_default();
k = 0;
count_k = xml.num_children_having_tag("Order[i]|OrderDetail[j]|Instrument");
while k < count_k {
xml.set_k(k);
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|Instrument[k]|Product|symbol").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|Instrument[k]|Product|securityType").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|Instrument[k]|Product|callPut").unwrap_or_default();
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryYear");
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryMonth");
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryDay");
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|Instrument[k]|Product|strikePrice").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|Instrument[k]|symbolDescription").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|Instrument[k]|orderAction").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|Instrument[k]|quantityType").unwrap_or_default();
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|Instrument[k]|orderedQuantity");
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|Instrument[k]|filledQuantity");
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|Instrument[k]|averageExecutionPrice").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|Instrument[k]|estimatedCommission").unwrap_or_default();
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|Instrument[k]|estimatedFees");
k = k + 1;
}
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|netPrice");
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|netBid");
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|netAsk");
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|gcd");
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|orderNumber");
let _ = xml.get_child_int_value("Order[i]|OrderDetail[j]|bracketedLimitPrice");
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|initialStopPrice").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|OrderDetail[j]|executedTime").unwrap_or_default();
j = j + 1;
}
let _ = xml.get_child_content("Order[i]|totalOrderValue").unwrap_or_default();
let _ = xml.get_child_content("Order[i]|totalCommission").unwrap_or_default();
i = i + 1;
}
println!("Success.");