Skip to main content

cancel_batch_orders/
cancel_batch_orders.rs

1use gateio_rs::{
2    api::spot::{self, CancelOrderRequest},
3    http::Credentials,
4    ureq::GateHttpClient,
5};
6use serde_json::Value;
7
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 a list of orders to cancel - replace with actual order IDs
18    let orders_to_cancel = vec![
19        CancelOrderRequest {
20            id: "123456789".to_string(),
21            currency_pair: "BTC_USDT".to_string(),
22        },
23        CancelOrderRequest {
24            id: "987654321".to_string(),
25            currency_pair: "ETH_USDT".to_string(),
26        },
27    ];
28
29    let req = spot::cancel_batch_orders(orders_to_cancel);
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}