gateio_rs/api/spot/create_batch_orders.rs
1use super::order::Order;
2use crate::http::{Credentials, Method, request::Request};
3
4/// # Create multiple spot orders in batch
5///
6/// Create multiple spot orders in a single request for improved efficiency.
7/// All orders will be processed together and either all succeed or all fail.
8///
9/// ## Important Notes:
10/// - Maximum 10 orders per batch request
11/// - All orders must be for the same account type
12/// - Orders are processed atomically (all or nothing)
13/// - Each order follows the same validation rules as individual orders
14///
15/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#create-a-batch-of-orders)
16pub struct CreateBatchOrders {
17 /// List of orders to create (maximum 10)
18 pub orders: Vec<Order>,
19 /// Request expiration time in milliseconds
20 pub x_gate_exp_time: Option<u128>,
21 /// API credentials for authentication
22 pub credentials: Option<Credentials>,
23}
24
25impl CreateBatchOrders {
26 /// Create a new batch orders request
27 pub fn new(orders: Vec<Order>) -> Self {
28 Self {
29 orders,
30 x_gate_exp_time: None,
31 credentials: None,
32 }
33 }
34
35 /// Set the request expiration time in milliseconds
36 pub fn x_gate_exp_time(mut self, x_gate_exp_time: u128) -> Self {
37 self.x_gate_exp_time = Some(x_gate_exp_time);
38 self
39 }
40
41 /// Set API credentials for authentication
42 pub fn credentials(mut self, creds: Credentials) -> Self {
43 self.credentials = Some(creds);
44 self
45 }
46}
47
48impl From<CreateBatchOrders> for Request {
49 fn from(request: CreateBatchOrders) -> Request {
50 let params = Vec::new();
51 let payload = serde_json::to_string(&request.orders).unwrap();
52
53 Request {
54 method: Method::Post,
55 path: "/api/v4/spot/batch_orders".into(),
56 params,
57 payload,
58 x_gate_exp_time: request.x_gate_exp_time,
59 credentials: request.credentials,
60 sign: true,
61 }
62 }
63}