pub async fn place(&self, alpaca: &Alpaca) -> Result<Order> {
      // pre-conditions
      if (self.order_type == OrderType::Limit || self.order_type == OrderType::StopLimit) && self.limit_price == None {
         error::OrderInvalid { reason: "Limit orders need a limit price.".to_string() }.fail()?
      }
      if (self.order_type == OrderType::Stop || self.order_type == OrderType::StopLimit) && self.stop_price == None {
         error::OrderInvalid { reason: "Stop orders need a stop price.".to_string() }.fail()?
      }
      if self.extended_hours && (self.order_type != OrderType::Limit && self.time_in_force != TimeInForce::DAY) {
         error::OrderInvalid { reason: "Extended hours only works with limit orders for today".to_string() }.fail()?
      }

      let response = alpaca.request(Method::POST, "v2/orders")?
         .json::<OrderBuilder>(self)
         .send()
         .await.context(error::BadData)?;

      if response.status().is_success() { return Ok(response.json::<Order>().await.context(error::BadData)?) }

      match response.status().as_u16() {
         403 => error::OrderForbidden.fail()?,
         _ => error::Unknown.fail()?
      }
   }
/// Attempts to place the order.  Will fail if certain preconditions aren't met, including:
///  * Limit order with no limit price
///  * Stop order with no stop price
///  * Extended hours requested for non limit orders where time_in_force is not Day
//
//  Will also fail if the buying power or shares are not sufficient.
Attempts to place the order.  Will fail if certain preconditions aren't met, including:
Limit order with no limit price
Stop order with no stop price
Extended hours requested for non limit orders where time_in_force is not Day

Will also fail if the buying power or shares are not sufficient.
Attempts to place the order . Will fail if certain preconditions aren ' t met including : Limit order with no limit price Stop order with no stop price Extended hours requested for non limit orders where time_in_force is not Day Will also fail if the buying power or shares are not sufficient .
pub async fn place(&self, alpaca: &Alpaca) -> Result<Order> {
      // pre-conditions
      if (self.order_type == OrderType::Limit || self.order_type == OrderType::StopLimit) && self.limit_price == None {
         error::OrderInvalid { reason: "Limit orders need a limit price.".to_string() }.fail()?
      }
      if (self.order_type == OrderType::Stop || self.order_type == OrderType::StopLimit) && self.stop_price == None {
         error::OrderInvalid { reason: "Stop orders need a stop price.".to_string() }.fail()?
      }
      if self.extended_hours && (self.order_type != OrderType::Limit && self.time_in_force != TimeInForce::DAY) {
         error::OrderInvalid { reason: "Extended hours only works with limit orders for today".to_string() }.fail()?
      }
      let response = alpaca.request(Method::POST, "v2/orders")?
         .json::<OrderBuilder>(self)
         .send()
         .await.context(error::BadData)?;
      if response.status().is_success() { return Ok(response.json::<Order>().await.context(error::BadData)?) }
      match response.status().as_u16() {
         403 => error::OrderForbidden.fail()?,
         _ => error::Unknown.fail()?
      }
   }
pub async fn place ( & self , alpaca : & Alpaca ) -> Result < Order > { // pre-conditions if ( self . order_type == OrderType :: Limit || self . order_type == OrderType :: StopLimit ) && self . limit_price == None { error :: OrderInvalid { reason : " " . to_string ( ) } . fail ( ) ? } if ( self . order_type == OrderType :: Stop || self . order_type == OrderType :: StopLimit ) && self . stop_price == None { error :: OrderInvalid { reason : " " . to_string ( ) } . fail ( ) ? } if self . extended_hours && ( self . order_type != OrderType :: Limit && self . time_in_force != TimeInForce :: DAY ) { error :: OrderInvalid { reason : " " . to_string ( ) } . fail ( ) ? } let response = alpaca . request ( Method :: POST , " " ) ? . json :: < OrderBuilder > ( self ) . send ( ) . await . context ( error :: BadData ) ? ; if response . status ( ) . is_success ( ) { return Ok ( response . json :: < Order > ( ) . await . context ( error :: BadData ) ? ) } match response . status ( ) . as_u16 ( ) { 403 => error :: OrderForbidden . fail ( ) ? , _ => error :: Unknown . fail ( ) ? } }
Attempts to place the order.
Attempts to place the order .
&self
alpaca
&Alpaca
&self
alpaca
&Alpaca