pub struct TradeService { /* private fields */ }Expand description
Trade service for order management endpoints.
Implementations§
Source§impl TradeService
impl TradeService
Sourcepub fn new(http: HttpClient) -> Self
pub fn new(http: HttpClient) -> Self
Create a new trade service.
Sourcepub async fn submit_order(
&self,
params: &OrderParams,
) -> Result<OrderResult, BybitError>
pub async fn submit_order( &self, params: &OrderParams, ) -> Result<OrderResult, BybitError>
Submit a new order.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
// Place a market order.
let params = OrderParams::market(Category::Linear, "BTCUSDT", Side::Buy, "0.001");
let result = client.trade().submit_order(¶ms).await?;
println!("Order ID: {}", result.order_id);
// Place a limit order.
let params = OrderParams::limit(Category::Spot, "BTCUSDT", Side::Buy, "0.001", "50000");
let result = client.trade().submit_order(¶ms).await?;Sourcepub async fn amend_order(
&self,
params: &AmendOrderParams,
) -> Result<OrderResult, BybitError>
pub async fn amend_order( &self, params: &AmendOrderParams, ) -> Result<OrderResult, BybitError>
Amend an existing order.
You can modify the order quantity, price, or TP/SL settings.
Either order_id or order_link_id must be provided.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
let params = AmendOrderParams::by_order_id(Category::Linear, "BTCUSDT", "order123")
.price("51000")
.qty("0.002");
let result = client.trade().amend_order(¶ms).await?;Sourcepub async fn cancel_order(
&self,
params: &CancelOrderParams,
) -> Result<OrderResult, BybitError>
pub async fn cancel_order( &self, params: &CancelOrderParams, ) -> Result<OrderResult, BybitError>
Cancel an existing order.
Either order_id or order_link_id must be provided.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
let params = CancelOrderParams::by_order_id(Category::Linear, "BTCUSDT", "order123");
let result = client.trade().cancel_order(¶ms).await?;Sourcepub async fn cancel_all_orders(
&self,
params: &CancelAllOrdersParams,
) -> Result<CancelAllResult, BybitError>
pub async fn cancel_all_orders( &self, params: &CancelAllOrdersParams, ) -> Result<CancelAllResult, BybitError>
Cancel all active orders.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
// Cancel all linear orders.
let params = CancelAllOrdersParams::new(Category::Linear);
let result = client.trade().cancel_all_orders(¶ms).await?;
// Cancel all orders for a specific symbol.
let params = CancelAllOrdersParams::new(Category::Spot)
.symbol("BTCUSDT");
let result = client.trade().cancel_all_orders(¶ms).await?;Sourcepub async fn get_open_orders(
&self,
params: &GetOpenOrdersParams,
) -> Result<OrderListResult, BybitError>
pub async fn get_open_orders( &self, params: &GetOpenOrdersParams, ) -> Result<OrderListResult, BybitError>
Get open/active orders.
Returns real-time order data. For conditional orders, use order_filter.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
let params = GetOpenOrdersParams::new(Category::Linear)
.symbol("BTCUSDT")
.limit(20);
let result = client.trade().get_open_orders(¶ms).await?;
for order in &result.list {
println!("{}: {} {} @ {}", order.order_id, order.side, order.qty, order.price);
}Sourcepub async fn get_order_history(
&self,
params: &GetOrderHistoryParams,
) -> Result<OrderListResult, BybitError>
pub async fn get_order_history( &self, params: &GetOrderHistoryParams, ) -> Result<OrderListResult, BybitError>
Get order history.
Returns historical orders including filled, cancelled, and rejected orders.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
let params = GetOrderHistoryParams::new(Category::Linear)
.symbol("BTCUSDT")
.limit(50);
let result = client.trade().get_order_history(¶ms).await?;Sourcepub async fn get_execution_list(
&self,
params: &GetExecutionListParams,
) -> Result<ExecutionListResult, BybitError>
pub async fn get_execution_list( &self, params: &GetExecutionListParams, ) -> Result<ExecutionListResult, BybitError>
Get trade execution list.
Returns the trade history (fills) for your orders.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
let params = GetExecutionListParams::new(Category::Linear)
.symbol("BTCUSDT")
.limit(50);
let result = client.trade().get_execution_list(¶ms).await?;
for exec in &result.list {
println!("{}: {} {} @ {}", exec.exec_id, exec.side, exec.exec_qty, exec.exec_price);
}Sourcepub async fn get_borrow_quota(
&self,
params: &GetBorrowQuotaParams,
) -> Result<BorrowQuotaResult, BybitError>
pub async fn get_borrow_quota( &self, params: &GetBorrowQuotaParams, ) -> Result<BorrowQuotaResult, BybitError>
Get spot borrow quota.
Check the maximum borrow amount for spot margin trading.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
let params = GetBorrowQuotaParams::new("BTCUSDT", Side::Buy);
let result = client.trade().get_borrow_quota(¶ms).await?;
println!("Max trade qty: {}", result.max_trade_qty);Sourcepub async fn batch_submit_orders(
&self,
category: Category,
orders: Vec<BatchOrderParams>,
) -> Result<BatchOperationResult, BybitError>
pub async fn batch_submit_orders( &self, category: Category, orders: Vec<BatchOrderParams>, ) -> Result<BatchOperationResult, BybitError>
Submit multiple orders in a single request.
Supports up to 10 orders for options, 20 for USDT perpetual/USDC contracts.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
let orders = vec![
BatchOrderParams::limit("BTCUSDT", Side::Buy, "0.001", "50000")
.order_link_id("batch_1"),
BatchOrderParams::limit("BTCUSDT", Side::Buy, "0.001", "49000")
.order_link_id("batch_2"),
];
let result = client.trade().batch_submit_orders(Category::Linear, orders).await?;
for order in &result.list {
println!("Created: {} - {}", order.order_id, order.order_link_id);
}Sourcepub async fn batch_amend_orders(
&self,
category: Category,
orders: Vec<BatchAmendOrderParams>,
) -> Result<BatchOperationResult, BybitError>
pub async fn batch_amend_orders( &self, category: Category, orders: Vec<BatchAmendOrderParams>, ) -> Result<BatchOperationResult, BybitError>
Amend multiple orders in a single request.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
let orders = vec![
BatchAmendOrderParams::by_order_link_id("BTCUSDT", "batch_1")
.price("51000"),
BatchAmendOrderParams::by_order_link_id("BTCUSDT", "batch_2")
.price("49500"),
];
let result = client.trade().batch_amend_orders(Category::Linear, orders).await?;Sourcepub async fn batch_cancel_orders(
&self,
category: Category,
orders: Vec<BatchCancelOrderParams>,
) -> Result<BatchOperationResult, BybitError>
pub async fn batch_cancel_orders( &self, category: Category, orders: Vec<BatchCancelOrderParams>, ) -> Result<BatchOperationResult, BybitError>
Cancel multiple orders in a single request.
§Example
let client = BybitClient::new("api_key", "api_secret")?;
let orders = vec![
BatchCancelOrderParams::by_order_link_id("BTCUSDT", "batch_1"),
BatchCancelOrderParams::by_order_link_id("BTCUSDT", "batch_2"),
];
let result = client.trade().batch_cancel_orders(Category::Linear, orders).await?;Trait Implementations§
Source§impl Clone for TradeService
impl Clone for TradeService
Source§fn clone(&self) -> TradeService
fn clone(&self) -> TradeService
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more