bybit/rest/v5/trade/
trade_order_limit.rs

1use super::enums::{OrderSide, OrderType};
2use super::requests::PlaceOrderRequest;
3use super::responses::OrderStatusResponse;
4use super::TradeV5Manager;
5use crate::rest::v5::account::enums::Category;
6use crate::rest::v5::endpoints::{TradeV5, API};
7use anyhow::Result;
8
9impl TradeV5Manager {
10  /// Place a LIMIT order - BUY
11  pub async fn place_limit_buy_order<S, Q, PR>(
12    &self,
13    category: Category,
14    symbol: S,
15    qty: Q,
16    price: PR,
17  ) -> Result<OrderStatusResponse>
18  where
19    S: Into<String>,
20    Q: Into<f64>,
21    PR: Into<f64>,
22  {
23    self
24      .place_limit_order(category, symbol, OrderSide::Buy, qty, price)
25      .await
26  }
27
28  /// Place a LIMIT order - SELL
29  pub async fn place_limit_sell_order<S, Q, PR>(
30    &self,
31    category: Category,
32    symbol: S,
33    qty: Q,
34    price: PR,
35  ) -> Result<OrderStatusResponse>
36  where
37    S: Into<String>,
38    Q: Into<f64>,
39    PR: Into<f64>,
40  {
41    self
42      .place_limit_order(category, symbol, OrderSide::Sell, qty, price)
43      .await
44  }
45
46  pub async fn place_limit_order<S, Q, PR>(
47    &self,
48    category: Category,
49    symbol: S,
50    side: OrderSide,
51    qty: Q,
52    price: PR,
53  ) -> Result<OrderStatusResponse>
54  where
55    S: Into<String>,
56    Q: Into<f64>,
57    PR: Into<f64>,
58  {
59    let mut request = PlaceOrderRequest::default();
60    request.symbol = symbol.into();
61    request.order_type = OrderType::Limit;
62    request.side = side;
63    request.qty = qty.into();
64    request.price = Some(price.into());
65
66    self
67      .client
68      .post_signed(
69        API::TradeV5(TradeV5::Place),
70        self.recv_window.into(),
71        request.to_query_string(category),
72      )
73      .await
74  }
75}