pub async fn cancel(&self, alpaca: &Alpaca) -> Result<()> {
      let response = alpaca.request(Method::DELETE, format!("v2/orders/{}", self.id).as_str())?
         .send().await.context(error::RequestFailed)?;

      if response.status().is_success() { return Ok(()) }
      match response.status().as_u16() {
         404 => error::OrderNotFound { order_id: self.id.clone() }.fail()?,
         422 => error::OrderNotCancelable { order_id: self.id.clone() }.fail()?,
         _ => error::Unknown.fail()?
      }
   }
/// Attempts to cancel this order. If the order is no longer cancelable (example: status=order_filled),
/// an error will be generated.
///
/// # Example
///
/// To cancel an open order:
///
/// ``` no run
/// let alpaca = Alpaca::live("KEY_ID", "SECRET").await.unwrap();
/// let open_order = ...; // some buy 
///
/// open_order.cancel().await?;
/// ```
Attempts to cancel this order. If the order is no longer cancelable (example: status=order_filled),
an error will be generated.
Attempts to cancel this order . If the order is no longer cancelable ( example : status = order_filled ) an error will be generated .
pub async fn cancel(&self, alpaca: &Alpaca) -> Result<()> {
      let response = alpaca.request(Method::DELETE, format!("v2/orders/{}", self.id).as_str())?
         .send().await.context(error::RequestFailed)?;
      if response.status().is_success() { return Ok(()) }
      match response.status().as_u16() {
         404 => error::OrderNotFound { order_id: self.id.clone() }.fail()?,
         422 => error::OrderNotCancelable { order_id: self.id.clone() }.fail()?,
         _ => error::Unknown.fail()?
      }
   }
pub async fn cancel ( & self , alpaca : & Alpaca ) -> Result < ( ) > { let response = alpaca . request ( Method :: DELETE , format ! ( " " self id ) . as_str ( ) ) ? . send ( ) . await . context ( error :: RequestFailed ) ? ; if response . status ( ) . is_success ( ) { return Ok ( ( ) ) } match response . status ( ) . as_u16 ( ) { 404 => error :: OrderNotFound { order_id : self . id . clone ( ) } . fail ( ) ? , 422 => error :: OrderNotCancelable { order_id : self . id . clone ( ) } . fail ( ) ? , _ => error :: Unknown . fail ( ) ? } }
Attempts to cancel this order.
Attempts to cancel this order .
&self
alpaca
&Alpaca
&self
alpaca
&Alpaca
example
To cancel an open order.

``` no run
let alpaca = Alpaca::live("KEY_ID", "SECRET").await.unwrap();
let open_order = ...; // some buy

open_order.cancel().await?;
```
To cancel an open order . ` ` ` no run let alpaca = Alpaca :: live ( " KEY_ID " " SECRET " ) . await . unwrap () ; let open_order = ... ; // some buy open_order . cancel () . await? ; ` ` `