Skip to main content

Order

Struct Order 

Source
pub struct Order {
Show 13 fields pub text: Option<String>, pub currency_pair: String, pub order_type: Option<String>, pub account: Option<String>, pub side: String, pub amount: String, pub price: Option<String>, pub time_in_force: Option<String>, pub iceberg: Option<String>, pub auto_borrow: Option<bool>, pub auto_repay: Option<bool>, pub stp_act: Option<String>, pub action_mode: Option<String>,
}
Expand description

Order data structure for creating and managing spot orders

Fields§

§text: Option<String>

User-defined text information for the order

§currency_pair: String

Currency pair for the order (e.g., “BTC_USDT”)

§order_type: Option<String>

Order type (“limit”, “market”, “immediate_or_cancel”, “fill_or_kill”)

§account: Option<String>

Account type (“spot”, “margin”, “cross_margin”)

§side: String

Order side (“buy” or “sell”)

§amount: String

Order amount in base currency

§price: Option<String>

Order price (required for limit orders)

§time_in_force: Option<String>

Time in force policy (“gtc”, “ioc”, “fok”)

§iceberg: Option<String>

Iceberg order visible amount

§auto_borrow: Option<bool>

Whether to automatically borrow for margin trading

§auto_repay: Option<bool>

Whether to automatically repay for margin trading

§stp_act: Option<String>

Self-trade prevention action (“cn”, “co”, “cb”)

§action_mode: Option<String>

Action mode for the order

Implementations§

Source§

impl Order

Source

pub fn new(currency_pair: &str, side: &str, amount: &str) -> Self

Creates a new Order with required parameters

Examples found in repository?
examples/sync/create_batch_orders.rs (line 19)
8fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
9    dotenv::dotenv().ok();
10
11    let api_key = std::env::var("GATE_API_KEY").expect("GATE_API_KEY not set");
12    let api_secret = std::env::var("GATE_API_SECRET").expect("GATE_API_SECRET not set");
13    let credentials = Credentials::new(api_key, api_secret);
14
15    let client = GateHttpClient::default().credentials(credentials.clone());
16
17    // Create multiple orders
18    let orders = vec![
19        Order::new("BTC_USDT", "buy", "0.001")
20            .order_type("limit")
21            .price("30000")
22            .account("spot"),
23        Order::new("ETH_USDT", "buy", "0.01")
24            .order_type("limit")
25            .price("2000")
26            .account("spot"),
27    ];
28
29    let req = spot::create_batch_orders(orders);
30
31    let resp = client.send(req)?;
32    let body = resp.into_body_str()?;
33    let resp_obj: Value = serde_json::from_str(&body).unwrap();
34    println!("{:?}", resp_obj);
35
36    Ok(())
37}
More examples
Hide additional examples
examples/sync_example.rs (line 103)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    // 1) Create Credentials
13    // TODO: Replace with your actual API credentials or use environment variables
14    let api_key = "YOUR_GATE_API_KEY";
15    let api_secret = "YOUR_GATE_API_SECRET";
16    let credentials = Credentials::new(api_key.to_owned(), api_secret.to_owned());
17
18    // 2) Configure Client
19    let client = GateHttpClient::default().credentials(credentials);
20
21    // 3) Send sync request examples
22
23    // Example 1: Get ticker
24    println!("Getting ticker for BTC_USDT...");
25    let req = get_ticker().currency_pair("BTC_USDT").timezone("utc8");
26
27    let resp = client.send(req)?;
28    let body = resp.into_body_str()?;
29    let ticker_data: Value = serde_json::from_str(&body)?;
30    println!("Ticker: {}\n", serde_json::to_string_pretty(&ticker_data)?);
31
32    // Example 2: Get account information
33    println!("Getting account information...");
34    let req = get_account();
35
36    let resp = client.send(req)?;
37    let body = resp.into_body_str()?;
38    let account_data: Value = serde_json::from_str(&body)?;
39    println!(
40        "Account: {}\n",
41        serde_json::to_string_pretty(&account_data)?
42    );
43
44    // Example 3: Get currency pairs
45    println!("Getting currency pairs...");
46    let req = get_currency_pairs();
47
48    let resp = client.send(req)?;
49    let body = resp.into_body_str()?;
50    let pairs_data: Value = serde_json::from_str(&body)?;
51    println!(
52        "Found {} currency pairs\n",
53        pairs_data.as_array().map(|a| a.len()).unwrap_or(0)
54    );
55
56    // Example 4: Get specific currency pair
57    println!("Getting LTC_USDT currency pair info...");
58    let req = get_currency_pair("LTC_USDT");
59
60    let resp = client.send(req)?;
61    let body = resp.into_body_str()?;
62    let pair_data: Value = serde_json::from_str(&body)?;
63    println!(
64        "LTC_USDT info: {}\n",
65        serde_json::to_string_pretty(&pair_data)?
66    );
67
68    // Example 5: Create order
69    println!("Creating order...");
70    let req = create_order("LTC_USDT", "buy", "0.04").price("84.2");
71
72    let resp = client.send(req)?;
73    let body = resp.into_body_str()?;
74    let order_data: Value = serde_json::from_str(&body)?;
75    println!(
76        "Order created: {}\n",
77        serde_json::to_string_pretty(&order_data)?
78    );
79
80    // Example 6: Batch user fee
81    println!("Getting batch user fee...");
82    let req = get_batch_user_fee("BTC_USDT,ETH_USDT");
83
84    let resp = client.send(req)?;
85    let body = resp.into_body_str()?;
86    let fee_data: Value = serde_json::from_str(&body)?;
87    println!("Fees: {}\n", serde_json::to_string_pretty(&fee_data)?);
88
89    // Example 7: Account book
90    println!("Getting account book...");
91    let req = get_account_book().book_type("new_order");
92
93    let resp = client.send(req)?;
94    let body = resp.into_body_str()?;
95    let book_data: Value = serde_json::from_str(&body)?;
96    println!(
97        "Account book: {}\n",
98        serde_json::to_string_pretty(&book_data)?
99    );
100
101    // Example 8: Batch orders
102    println!("Creating batch orders...");
103    let order1 = Order::new("BTC_USDT", "buy", "0.001")
104        .text("t-abc123")
105        .order_type("limit")
106        .account("unified")
107        .price("65000")
108        .time_in_force("gtc")
109        .iceberg("0");
110
111    let order2 = Order::new("ETH_USDT", "buy", "0.01")
112        .text("t-def456")
113        .order_type("limit")
114        .account("unified")
115        .price("3000")
116        .time_in_force("gtc")
117        .iceberg("0");
118
119    let orders = vec![order1, order2];
120    let req = create_batch_orders(orders);
121
122    let resp = client.send(req)?;
123    let body = resp.into_body_str()?;
124    let batch_data: Value = serde_json::from_str(&body)?;
125    println!(
126        "Batch orders: {}\n",
127        serde_json::to_string_pretty(&batch_data)?
128    );
129
130    println!("All sync examples completed successfully!");
131    Ok(())
132}
Source

pub fn text(self, text: &str) -> Self

Sets user-defined text information for the order

Examples found in repository?
examples/sync_example.rs (line 104)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    // 1) Create Credentials
13    // TODO: Replace with your actual API credentials or use environment variables
14    let api_key = "YOUR_GATE_API_KEY";
15    let api_secret = "YOUR_GATE_API_SECRET";
16    let credentials = Credentials::new(api_key.to_owned(), api_secret.to_owned());
17
18    // 2) Configure Client
19    let client = GateHttpClient::default().credentials(credentials);
20
21    // 3) Send sync request examples
22
23    // Example 1: Get ticker
24    println!("Getting ticker for BTC_USDT...");
25    let req = get_ticker().currency_pair("BTC_USDT").timezone("utc8");
26
27    let resp = client.send(req)?;
28    let body = resp.into_body_str()?;
29    let ticker_data: Value = serde_json::from_str(&body)?;
30    println!("Ticker: {}\n", serde_json::to_string_pretty(&ticker_data)?);
31
32    // Example 2: Get account information
33    println!("Getting account information...");
34    let req = get_account();
35
36    let resp = client.send(req)?;
37    let body = resp.into_body_str()?;
38    let account_data: Value = serde_json::from_str(&body)?;
39    println!(
40        "Account: {}\n",
41        serde_json::to_string_pretty(&account_data)?
42    );
43
44    // Example 3: Get currency pairs
45    println!("Getting currency pairs...");
46    let req = get_currency_pairs();
47
48    let resp = client.send(req)?;
49    let body = resp.into_body_str()?;
50    let pairs_data: Value = serde_json::from_str(&body)?;
51    println!(
52        "Found {} currency pairs\n",
53        pairs_data.as_array().map(|a| a.len()).unwrap_or(0)
54    );
55
56    // Example 4: Get specific currency pair
57    println!("Getting LTC_USDT currency pair info...");
58    let req = get_currency_pair("LTC_USDT");
59
60    let resp = client.send(req)?;
61    let body = resp.into_body_str()?;
62    let pair_data: Value = serde_json::from_str(&body)?;
63    println!(
64        "LTC_USDT info: {}\n",
65        serde_json::to_string_pretty(&pair_data)?
66    );
67
68    // Example 5: Create order
69    println!("Creating order...");
70    let req = create_order("LTC_USDT", "buy", "0.04").price("84.2");
71
72    let resp = client.send(req)?;
73    let body = resp.into_body_str()?;
74    let order_data: Value = serde_json::from_str(&body)?;
75    println!(
76        "Order created: {}\n",
77        serde_json::to_string_pretty(&order_data)?
78    );
79
80    // Example 6: Batch user fee
81    println!("Getting batch user fee...");
82    let req = get_batch_user_fee("BTC_USDT,ETH_USDT");
83
84    let resp = client.send(req)?;
85    let body = resp.into_body_str()?;
86    let fee_data: Value = serde_json::from_str(&body)?;
87    println!("Fees: {}\n", serde_json::to_string_pretty(&fee_data)?);
88
89    // Example 7: Account book
90    println!("Getting account book...");
91    let req = get_account_book().book_type("new_order");
92
93    let resp = client.send(req)?;
94    let body = resp.into_body_str()?;
95    let book_data: Value = serde_json::from_str(&body)?;
96    println!(
97        "Account book: {}\n",
98        serde_json::to_string_pretty(&book_data)?
99    );
100
101    // Example 8: Batch orders
102    println!("Creating batch orders...");
103    let order1 = Order::new("BTC_USDT", "buy", "0.001")
104        .text("t-abc123")
105        .order_type("limit")
106        .account("unified")
107        .price("65000")
108        .time_in_force("gtc")
109        .iceberg("0");
110
111    let order2 = Order::new("ETH_USDT", "buy", "0.01")
112        .text("t-def456")
113        .order_type("limit")
114        .account("unified")
115        .price("3000")
116        .time_in_force("gtc")
117        .iceberg("0");
118
119    let orders = vec![order1, order2];
120    let req = create_batch_orders(orders);
121
122    let resp = client.send(req)?;
123    let body = resp.into_body_str()?;
124    let batch_data: Value = serde_json::from_str(&body)?;
125    println!(
126        "Batch orders: {}\n",
127        serde_json::to_string_pretty(&batch_data)?
128    );
129
130    println!("All sync examples completed successfully!");
131    Ok(())
132}
Source

pub fn order_type(self, order_type: &str) -> Self

Sets the order type

Examples found in repository?
examples/sync/create_batch_orders.rs (line 20)
8fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
9    dotenv::dotenv().ok();
10
11    let api_key = std::env::var("GATE_API_KEY").expect("GATE_API_KEY not set");
12    let api_secret = std::env::var("GATE_API_SECRET").expect("GATE_API_SECRET not set");
13    let credentials = Credentials::new(api_key, api_secret);
14
15    let client = GateHttpClient::default().credentials(credentials.clone());
16
17    // Create multiple orders
18    let orders = vec![
19        Order::new("BTC_USDT", "buy", "0.001")
20            .order_type("limit")
21            .price("30000")
22            .account("spot"),
23        Order::new("ETH_USDT", "buy", "0.01")
24            .order_type("limit")
25            .price("2000")
26            .account("spot"),
27    ];
28
29    let req = spot::create_batch_orders(orders);
30
31    let resp = client.send(req)?;
32    let body = resp.into_body_str()?;
33    let resp_obj: Value = serde_json::from_str(&body).unwrap();
34    println!("{:?}", resp_obj);
35
36    Ok(())
37}
More examples
Hide additional examples
examples/sync_example.rs (line 105)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    // 1) Create Credentials
13    // TODO: Replace with your actual API credentials or use environment variables
14    let api_key = "YOUR_GATE_API_KEY";
15    let api_secret = "YOUR_GATE_API_SECRET";
16    let credentials = Credentials::new(api_key.to_owned(), api_secret.to_owned());
17
18    // 2) Configure Client
19    let client = GateHttpClient::default().credentials(credentials);
20
21    // 3) Send sync request examples
22
23    // Example 1: Get ticker
24    println!("Getting ticker for BTC_USDT...");
25    let req = get_ticker().currency_pair("BTC_USDT").timezone("utc8");
26
27    let resp = client.send(req)?;
28    let body = resp.into_body_str()?;
29    let ticker_data: Value = serde_json::from_str(&body)?;
30    println!("Ticker: {}\n", serde_json::to_string_pretty(&ticker_data)?);
31
32    // Example 2: Get account information
33    println!("Getting account information...");
34    let req = get_account();
35
36    let resp = client.send(req)?;
37    let body = resp.into_body_str()?;
38    let account_data: Value = serde_json::from_str(&body)?;
39    println!(
40        "Account: {}\n",
41        serde_json::to_string_pretty(&account_data)?
42    );
43
44    // Example 3: Get currency pairs
45    println!("Getting currency pairs...");
46    let req = get_currency_pairs();
47
48    let resp = client.send(req)?;
49    let body = resp.into_body_str()?;
50    let pairs_data: Value = serde_json::from_str(&body)?;
51    println!(
52        "Found {} currency pairs\n",
53        pairs_data.as_array().map(|a| a.len()).unwrap_or(0)
54    );
55
56    // Example 4: Get specific currency pair
57    println!("Getting LTC_USDT currency pair info...");
58    let req = get_currency_pair("LTC_USDT");
59
60    let resp = client.send(req)?;
61    let body = resp.into_body_str()?;
62    let pair_data: Value = serde_json::from_str(&body)?;
63    println!(
64        "LTC_USDT info: {}\n",
65        serde_json::to_string_pretty(&pair_data)?
66    );
67
68    // Example 5: Create order
69    println!("Creating order...");
70    let req = create_order("LTC_USDT", "buy", "0.04").price("84.2");
71
72    let resp = client.send(req)?;
73    let body = resp.into_body_str()?;
74    let order_data: Value = serde_json::from_str(&body)?;
75    println!(
76        "Order created: {}\n",
77        serde_json::to_string_pretty(&order_data)?
78    );
79
80    // Example 6: Batch user fee
81    println!("Getting batch user fee...");
82    let req = get_batch_user_fee("BTC_USDT,ETH_USDT");
83
84    let resp = client.send(req)?;
85    let body = resp.into_body_str()?;
86    let fee_data: Value = serde_json::from_str(&body)?;
87    println!("Fees: {}\n", serde_json::to_string_pretty(&fee_data)?);
88
89    // Example 7: Account book
90    println!("Getting account book...");
91    let req = get_account_book().book_type("new_order");
92
93    let resp = client.send(req)?;
94    let body = resp.into_body_str()?;
95    let book_data: Value = serde_json::from_str(&body)?;
96    println!(
97        "Account book: {}\n",
98        serde_json::to_string_pretty(&book_data)?
99    );
100
101    // Example 8: Batch orders
102    println!("Creating batch orders...");
103    let order1 = Order::new("BTC_USDT", "buy", "0.001")
104        .text("t-abc123")
105        .order_type("limit")
106        .account("unified")
107        .price("65000")
108        .time_in_force("gtc")
109        .iceberg("0");
110
111    let order2 = Order::new("ETH_USDT", "buy", "0.01")
112        .text("t-def456")
113        .order_type("limit")
114        .account("unified")
115        .price("3000")
116        .time_in_force("gtc")
117        .iceberg("0");
118
119    let orders = vec![order1, order2];
120    let req = create_batch_orders(orders);
121
122    let resp = client.send(req)?;
123    let body = resp.into_body_str()?;
124    let batch_data: Value = serde_json::from_str(&body)?;
125    println!(
126        "Batch orders: {}\n",
127        serde_json::to_string_pretty(&batch_data)?
128    );
129
130    println!("All sync examples completed successfully!");
131    Ok(())
132}
Source

pub fn account(self, account: &str) -> Self

Sets the account type for the order

Examples found in repository?
examples/sync/create_batch_orders.rs (line 22)
8fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
9    dotenv::dotenv().ok();
10
11    let api_key = std::env::var("GATE_API_KEY").expect("GATE_API_KEY not set");
12    let api_secret = std::env::var("GATE_API_SECRET").expect("GATE_API_SECRET not set");
13    let credentials = Credentials::new(api_key, api_secret);
14
15    let client = GateHttpClient::default().credentials(credentials.clone());
16
17    // Create multiple orders
18    let orders = vec![
19        Order::new("BTC_USDT", "buy", "0.001")
20            .order_type("limit")
21            .price("30000")
22            .account("spot"),
23        Order::new("ETH_USDT", "buy", "0.01")
24            .order_type("limit")
25            .price("2000")
26            .account("spot"),
27    ];
28
29    let req = spot::create_batch_orders(orders);
30
31    let resp = client.send(req)?;
32    let body = resp.into_body_str()?;
33    let resp_obj: Value = serde_json::from_str(&body).unwrap();
34    println!("{:?}", resp_obj);
35
36    Ok(())
37}
More examples
Hide additional examples
examples/sync_example.rs (line 106)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    // 1) Create Credentials
13    // TODO: Replace with your actual API credentials or use environment variables
14    let api_key = "YOUR_GATE_API_KEY";
15    let api_secret = "YOUR_GATE_API_SECRET";
16    let credentials = Credentials::new(api_key.to_owned(), api_secret.to_owned());
17
18    // 2) Configure Client
19    let client = GateHttpClient::default().credentials(credentials);
20
21    // 3) Send sync request examples
22
23    // Example 1: Get ticker
24    println!("Getting ticker for BTC_USDT...");
25    let req = get_ticker().currency_pair("BTC_USDT").timezone("utc8");
26
27    let resp = client.send(req)?;
28    let body = resp.into_body_str()?;
29    let ticker_data: Value = serde_json::from_str(&body)?;
30    println!("Ticker: {}\n", serde_json::to_string_pretty(&ticker_data)?);
31
32    // Example 2: Get account information
33    println!("Getting account information...");
34    let req = get_account();
35
36    let resp = client.send(req)?;
37    let body = resp.into_body_str()?;
38    let account_data: Value = serde_json::from_str(&body)?;
39    println!(
40        "Account: {}\n",
41        serde_json::to_string_pretty(&account_data)?
42    );
43
44    // Example 3: Get currency pairs
45    println!("Getting currency pairs...");
46    let req = get_currency_pairs();
47
48    let resp = client.send(req)?;
49    let body = resp.into_body_str()?;
50    let pairs_data: Value = serde_json::from_str(&body)?;
51    println!(
52        "Found {} currency pairs\n",
53        pairs_data.as_array().map(|a| a.len()).unwrap_or(0)
54    );
55
56    // Example 4: Get specific currency pair
57    println!("Getting LTC_USDT currency pair info...");
58    let req = get_currency_pair("LTC_USDT");
59
60    let resp = client.send(req)?;
61    let body = resp.into_body_str()?;
62    let pair_data: Value = serde_json::from_str(&body)?;
63    println!(
64        "LTC_USDT info: {}\n",
65        serde_json::to_string_pretty(&pair_data)?
66    );
67
68    // Example 5: Create order
69    println!("Creating order...");
70    let req = create_order("LTC_USDT", "buy", "0.04").price("84.2");
71
72    let resp = client.send(req)?;
73    let body = resp.into_body_str()?;
74    let order_data: Value = serde_json::from_str(&body)?;
75    println!(
76        "Order created: {}\n",
77        serde_json::to_string_pretty(&order_data)?
78    );
79
80    // Example 6: Batch user fee
81    println!("Getting batch user fee...");
82    let req = get_batch_user_fee("BTC_USDT,ETH_USDT");
83
84    let resp = client.send(req)?;
85    let body = resp.into_body_str()?;
86    let fee_data: Value = serde_json::from_str(&body)?;
87    println!("Fees: {}\n", serde_json::to_string_pretty(&fee_data)?);
88
89    // Example 7: Account book
90    println!("Getting account book...");
91    let req = get_account_book().book_type("new_order");
92
93    let resp = client.send(req)?;
94    let body = resp.into_body_str()?;
95    let book_data: Value = serde_json::from_str(&body)?;
96    println!(
97        "Account book: {}\n",
98        serde_json::to_string_pretty(&book_data)?
99    );
100
101    // Example 8: Batch orders
102    println!("Creating batch orders...");
103    let order1 = Order::new("BTC_USDT", "buy", "0.001")
104        .text("t-abc123")
105        .order_type("limit")
106        .account("unified")
107        .price("65000")
108        .time_in_force("gtc")
109        .iceberg("0");
110
111    let order2 = Order::new("ETH_USDT", "buy", "0.01")
112        .text("t-def456")
113        .order_type("limit")
114        .account("unified")
115        .price("3000")
116        .time_in_force("gtc")
117        .iceberg("0");
118
119    let orders = vec![order1, order2];
120    let req = create_batch_orders(orders);
121
122    let resp = client.send(req)?;
123    let body = resp.into_body_str()?;
124    let batch_data: Value = serde_json::from_str(&body)?;
125    println!(
126        "Batch orders: {}\n",
127        serde_json::to_string_pretty(&batch_data)?
128    );
129
130    println!("All sync examples completed successfully!");
131    Ok(())
132}
Source

pub fn price(self, price: &str) -> Self

Sets the order price (required for limit orders)

Examples found in repository?
examples/sync/create_batch_orders.rs (line 21)
8fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
9    dotenv::dotenv().ok();
10
11    let api_key = std::env::var("GATE_API_KEY").expect("GATE_API_KEY not set");
12    let api_secret = std::env::var("GATE_API_SECRET").expect("GATE_API_SECRET not set");
13    let credentials = Credentials::new(api_key, api_secret);
14
15    let client = GateHttpClient::default().credentials(credentials.clone());
16
17    // Create multiple orders
18    let orders = vec![
19        Order::new("BTC_USDT", "buy", "0.001")
20            .order_type("limit")
21            .price("30000")
22            .account("spot"),
23        Order::new("ETH_USDT", "buy", "0.01")
24            .order_type("limit")
25            .price("2000")
26            .account("spot"),
27    ];
28
29    let req = spot::create_batch_orders(orders);
30
31    let resp = client.send(req)?;
32    let body = resp.into_body_str()?;
33    let resp_obj: Value = serde_json::from_str(&body).unwrap();
34    println!("{:?}", resp_obj);
35
36    Ok(())
37}
More examples
Hide additional examples
examples/sync_example.rs (line 107)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    // 1) Create Credentials
13    // TODO: Replace with your actual API credentials or use environment variables
14    let api_key = "YOUR_GATE_API_KEY";
15    let api_secret = "YOUR_GATE_API_SECRET";
16    let credentials = Credentials::new(api_key.to_owned(), api_secret.to_owned());
17
18    // 2) Configure Client
19    let client = GateHttpClient::default().credentials(credentials);
20
21    // 3) Send sync request examples
22
23    // Example 1: Get ticker
24    println!("Getting ticker for BTC_USDT...");
25    let req = get_ticker().currency_pair("BTC_USDT").timezone("utc8");
26
27    let resp = client.send(req)?;
28    let body = resp.into_body_str()?;
29    let ticker_data: Value = serde_json::from_str(&body)?;
30    println!("Ticker: {}\n", serde_json::to_string_pretty(&ticker_data)?);
31
32    // Example 2: Get account information
33    println!("Getting account information...");
34    let req = get_account();
35
36    let resp = client.send(req)?;
37    let body = resp.into_body_str()?;
38    let account_data: Value = serde_json::from_str(&body)?;
39    println!(
40        "Account: {}\n",
41        serde_json::to_string_pretty(&account_data)?
42    );
43
44    // Example 3: Get currency pairs
45    println!("Getting currency pairs...");
46    let req = get_currency_pairs();
47
48    let resp = client.send(req)?;
49    let body = resp.into_body_str()?;
50    let pairs_data: Value = serde_json::from_str(&body)?;
51    println!(
52        "Found {} currency pairs\n",
53        pairs_data.as_array().map(|a| a.len()).unwrap_or(0)
54    );
55
56    // Example 4: Get specific currency pair
57    println!("Getting LTC_USDT currency pair info...");
58    let req = get_currency_pair("LTC_USDT");
59
60    let resp = client.send(req)?;
61    let body = resp.into_body_str()?;
62    let pair_data: Value = serde_json::from_str(&body)?;
63    println!(
64        "LTC_USDT info: {}\n",
65        serde_json::to_string_pretty(&pair_data)?
66    );
67
68    // Example 5: Create order
69    println!("Creating order...");
70    let req = create_order("LTC_USDT", "buy", "0.04").price("84.2");
71
72    let resp = client.send(req)?;
73    let body = resp.into_body_str()?;
74    let order_data: Value = serde_json::from_str(&body)?;
75    println!(
76        "Order created: {}\n",
77        serde_json::to_string_pretty(&order_data)?
78    );
79
80    // Example 6: Batch user fee
81    println!("Getting batch user fee...");
82    let req = get_batch_user_fee("BTC_USDT,ETH_USDT");
83
84    let resp = client.send(req)?;
85    let body = resp.into_body_str()?;
86    let fee_data: Value = serde_json::from_str(&body)?;
87    println!("Fees: {}\n", serde_json::to_string_pretty(&fee_data)?);
88
89    // Example 7: Account book
90    println!("Getting account book...");
91    let req = get_account_book().book_type("new_order");
92
93    let resp = client.send(req)?;
94    let body = resp.into_body_str()?;
95    let book_data: Value = serde_json::from_str(&body)?;
96    println!(
97        "Account book: {}\n",
98        serde_json::to_string_pretty(&book_data)?
99    );
100
101    // Example 8: Batch orders
102    println!("Creating batch orders...");
103    let order1 = Order::new("BTC_USDT", "buy", "0.001")
104        .text("t-abc123")
105        .order_type("limit")
106        .account("unified")
107        .price("65000")
108        .time_in_force("gtc")
109        .iceberg("0");
110
111    let order2 = Order::new("ETH_USDT", "buy", "0.01")
112        .text("t-def456")
113        .order_type("limit")
114        .account("unified")
115        .price("3000")
116        .time_in_force("gtc")
117        .iceberg("0");
118
119    let orders = vec![order1, order2];
120    let req = create_batch_orders(orders);
121
122    let resp = client.send(req)?;
123    let body = resp.into_body_str()?;
124    let batch_data: Value = serde_json::from_str(&body)?;
125    println!(
126        "Batch orders: {}\n",
127        serde_json::to_string_pretty(&batch_data)?
128    );
129
130    println!("All sync examples completed successfully!");
131    Ok(())
132}
Source

pub fn time_in_force(self, time_in_force: &str) -> Self

Sets the time in force policy

Examples found in repository?
examples/sync_example.rs (line 108)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    // 1) Create Credentials
13    // TODO: Replace with your actual API credentials or use environment variables
14    let api_key = "YOUR_GATE_API_KEY";
15    let api_secret = "YOUR_GATE_API_SECRET";
16    let credentials = Credentials::new(api_key.to_owned(), api_secret.to_owned());
17
18    // 2) Configure Client
19    let client = GateHttpClient::default().credentials(credentials);
20
21    // 3) Send sync request examples
22
23    // Example 1: Get ticker
24    println!("Getting ticker for BTC_USDT...");
25    let req = get_ticker().currency_pair("BTC_USDT").timezone("utc8");
26
27    let resp = client.send(req)?;
28    let body = resp.into_body_str()?;
29    let ticker_data: Value = serde_json::from_str(&body)?;
30    println!("Ticker: {}\n", serde_json::to_string_pretty(&ticker_data)?);
31
32    // Example 2: Get account information
33    println!("Getting account information...");
34    let req = get_account();
35
36    let resp = client.send(req)?;
37    let body = resp.into_body_str()?;
38    let account_data: Value = serde_json::from_str(&body)?;
39    println!(
40        "Account: {}\n",
41        serde_json::to_string_pretty(&account_data)?
42    );
43
44    // Example 3: Get currency pairs
45    println!("Getting currency pairs...");
46    let req = get_currency_pairs();
47
48    let resp = client.send(req)?;
49    let body = resp.into_body_str()?;
50    let pairs_data: Value = serde_json::from_str(&body)?;
51    println!(
52        "Found {} currency pairs\n",
53        pairs_data.as_array().map(|a| a.len()).unwrap_or(0)
54    );
55
56    // Example 4: Get specific currency pair
57    println!("Getting LTC_USDT currency pair info...");
58    let req = get_currency_pair("LTC_USDT");
59
60    let resp = client.send(req)?;
61    let body = resp.into_body_str()?;
62    let pair_data: Value = serde_json::from_str(&body)?;
63    println!(
64        "LTC_USDT info: {}\n",
65        serde_json::to_string_pretty(&pair_data)?
66    );
67
68    // Example 5: Create order
69    println!("Creating order...");
70    let req = create_order("LTC_USDT", "buy", "0.04").price("84.2");
71
72    let resp = client.send(req)?;
73    let body = resp.into_body_str()?;
74    let order_data: Value = serde_json::from_str(&body)?;
75    println!(
76        "Order created: {}\n",
77        serde_json::to_string_pretty(&order_data)?
78    );
79
80    // Example 6: Batch user fee
81    println!("Getting batch user fee...");
82    let req = get_batch_user_fee("BTC_USDT,ETH_USDT");
83
84    let resp = client.send(req)?;
85    let body = resp.into_body_str()?;
86    let fee_data: Value = serde_json::from_str(&body)?;
87    println!("Fees: {}\n", serde_json::to_string_pretty(&fee_data)?);
88
89    // Example 7: Account book
90    println!("Getting account book...");
91    let req = get_account_book().book_type("new_order");
92
93    let resp = client.send(req)?;
94    let body = resp.into_body_str()?;
95    let book_data: Value = serde_json::from_str(&body)?;
96    println!(
97        "Account book: {}\n",
98        serde_json::to_string_pretty(&book_data)?
99    );
100
101    // Example 8: Batch orders
102    println!("Creating batch orders...");
103    let order1 = Order::new("BTC_USDT", "buy", "0.001")
104        .text("t-abc123")
105        .order_type("limit")
106        .account("unified")
107        .price("65000")
108        .time_in_force("gtc")
109        .iceberg("0");
110
111    let order2 = Order::new("ETH_USDT", "buy", "0.01")
112        .text("t-def456")
113        .order_type("limit")
114        .account("unified")
115        .price("3000")
116        .time_in_force("gtc")
117        .iceberg("0");
118
119    let orders = vec![order1, order2];
120    let req = create_batch_orders(orders);
121
122    let resp = client.send(req)?;
123    let body = resp.into_body_str()?;
124    let batch_data: Value = serde_json::from_str(&body)?;
125    println!(
126        "Batch orders: {}\n",
127        serde_json::to_string_pretty(&batch_data)?
128    );
129
130    println!("All sync examples completed successfully!");
131    Ok(())
132}
Source

pub fn iceberg(self, iceberg: &str) -> Self

Sets the iceberg order visible amount

Examples found in repository?
examples/sync_example.rs (line 109)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    // 1) Create Credentials
13    // TODO: Replace with your actual API credentials or use environment variables
14    let api_key = "YOUR_GATE_API_KEY";
15    let api_secret = "YOUR_GATE_API_SECRET";
16    let credentials = Credentials::new(api_key.to_owned(), api_secret.to_owned());
17
18    // 2) Configure Client
19    let client = GateHttpClient::default().credentials(credentials);
20
21    // 3) Send sync request examples
22
23    // Example 1: Get ticker
24    println!("Getting ticker for BTC_USDT...");
25    let req = get_ticker().currency_pair("BTC_USDT").timezone("utc8");
26
27    let resp = client.send(req)?;
28    let body = resp.into_body_str()?;
29    let ticker_data: Value = serde_json::from_str(&body)?;
30    println!("Ticker: {}\n", serde_json::to_string_pretty(&ticker_data)?);
31
32    // Example 2: Get account information
33    println!("Getting account information...");
34    let req = get_account();
35
36    let resp = client.send(req)?;
37    let body = resp.into_body_str()?;
38    let account_data: Value = serde_json::from_str(&body)?;
39    println!(
40        "Account: {}\n",
41        serde_json::to_string_pretty(&account_data)?
42    );
43
44    // Example 3: Get currency pairs
45    println!("Getting currency pairs...");
46    let req = get_currency_pairs();
47
48    let resp = client.send(req)?;
49    let body = resp.into_body_str()?;
50    let pairs_data: Value = serde_json::from_str(&body)?;
51    println!(
52        "Found {} currency pairs\n",
53        pairs_data.as_array().map(|a| a.len()).unwrap_or(0)
54    );
55
56    // Example 4: Get specific currency pair
57    println!("Getting LTC_USDT currency pair info...");
58    let req = get_currency_pair("LTC_USDT");
59
60    let resp = client.send(req)?;
61    let body = resp.into_body_str()?;
62    let pair_data: Value = serde_json::from_str(&body)?;
63    println!(
64        "LTC_USDT info: {}\n",
65        serde_json::to_string_pretty(&pair_data)?
66    );
67
68    // Example 5: Create order
69    println!("Creating order...");
70    let req = create_order("LTC_USDT", "buy", "0.04").price("84.2");
71
72    let resp = client.send(req)?;
73    let body = resp.into_body_str()?;
74    let order_data: Value = serde_json::from_str(&body)?;
75    println!(
76        "Order created: {}\n",
77        serde_json::to_string_pretty(&order_data)?
78    );
79
80    // Example 6: Batch user fee
81    println!("Getting batch user fee...");
82    let req = get_batch_user_fee("BTC_USDT,ETH_USDT");
83
84    let resp = client.send(req)?;
85    let body = resp.into_body_str()?;
86    let fee_data: Value = serde_json::from_str(&body)?;
87    println!("Fees: {}\n", serde_json::to_string_pretty(&fee_data)?);
88
89    // Example 7: Account book
90    println!("Getting account book...");
91    let req = get_account_book().book_type("new_order");
92
93    let resp = client.send(req)?;
94    let body = resp.into_body_str()?;
95    let book_data: Value = serde_json::from_str(&body)?;
96    println!(
97        "Account book: {}\n",
98        serde_json::to_string_pretty(&book_data)?
99    );
100
101    // Example 8: Batch orders
102    println!("Creating batch orders...");
103    let order1 = Order::new("BTC_USDT", "buy", "0.001")
104        .text("t-abc123")
105        .order_type("limit")
106        .account("unified")
107        .price("65000")
108        .time_in_force("gtc")
109        .iceberg("0");
110
111    let order2 = Order::new("ETH_USDT", "buy", "0.01")
112        .text("t-def456")
113        .order_type("limit")
114        .account("unified")
115        .price("3000")
116        .time_in_force("gtc")
117        .iceberg("0");
118
119    let orders = vec![order1, order2];
120    let req = create_batch_orders(orders);
121
122    let resp = client.send(req)?;
123    let body = resp.into_body_str()?;
124    let batch_data: Value = serde_json::from_str(&body)?;
125    println!(
126        "Batch orders: {}\n",
127        serde_json::to_string_pretty(&batch_data)?
128    );
129
130    println!("All sync examples completed successfully!");
131    Ok(())
132}
Source

pub fn auto_borrow(self, auto_borrow: bool) -> Self

Sets whether to automatically borrow for margin trading

Source

pub fn auto_repay(self, auto_repay: bool) -> Self

Sets whether to automatically repay for margin trading

Source

pub fn stp_act(self, stp_act: &str) -> Self

Sets the self-trade prevention action

Source

pub fn action_mode(self, action_mode: &str) -> Self

Sets the action mode for the order

Trait Implementations§

Source§

impl Clone for Order

Source§

fn clone(&self) -> Order

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Order

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Order

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Order

§

impl RefUnwindSafe for Order

§

impl Send for Order

§

impl Sync for Order

§

impl Unpin for Order

§

impl UnsafeUnpin for Order

§

impl UnwindSafe for Order

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.