Rust
Rust
ETrade Cancel Order
See more ETrade Examples
The cancel order API is used to cancel an existing order.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/cancel".to_string();
let live_url = "https://api.etrade.com/v1/accounts/{$accountIdKey}/orders/cancel".to_string();
let _ = http.set_url_var("accountIdKey", "6_Dpy0rmuQ9cu9IbTfvF2A");
// Send a PUT with the following XML body
// Use this online tool to generate the code from sample XML:
// Generate Code to Create XML
// <CancelOrderRequest>
// <orderId>11</orderId>
// </CancelOrderRequest>
let xml = chilkat::Xml::new();
xml.set_tag("CancelOrderRequest");
xml.update_child_content("orderId", "11");
xml.set_emit_compact(true);
let http_request_body = xml.get_xml().unwrap_or_default();
let resp = chilkat::HttpResponse::new();
if http.http_str("PUT", &sandbox_url, &http_request_body, "utf-8", "application/xml", &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
// <CancelOrderResponse>
// <accountId>63438617</accountId>
// <orderId>11</orderId>
// <cancelTime>1529563499081</cancelTime>
// <Messages>
// <Message>
// <code>5011</code>
// <description>200|Your request to cancel your order is being processed.</description>
// <type>WARNING</type>
// </Message>
// </Messages>
// </CancelOrderResponse>
let _ = xml.load_xml(&resp.body_str());
println!("{}", xml.get_xml().unwrap_or_default());
let account_id = xml.get_child_int_value("accountId");
let order_id = xml.get_child_int_value("orderId");
let cancel_time = xml.get_child_content("cancelTime").unwrap_or_default();
let code = xml.get_child_int_value("Messages|Message|code");
let description = xml.get_child_content("Messages|Message|description").unwrap_or_default();
let v_type = xml.get_child_content("Messages|Message|type").unwrap_or_default();
println!("Success.");