Skip to main content

cancel_all_open_orders/
cancel_all_open_orders.rs

1use gateio_rs::{api::spot, http::Credentials, ureq::GateHttpClient};
2use serde_json::Value;
3
4fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
5    dotenv::dotenv().ok();
6
7    // ⚠️  WARNING: This will cancel ALL open orders!
8    println!("⚠️  WARNING: This will cancel ALL open orders!");
9    println!("Proceeding in 3 seconds... Press Ctrl+C to abort");
10    std::thread::sleep(std::time::Duration::from_secs(3));
11
12    let api_key = std::env::var("GATE_API_KEY").expect("GATE_API_KEY not set");
13    let api_secret = std::env::var("GATE_API_SECRET").expect("GATE_API_SECRET not set");
14    let credentials = Credentials::new(api_key, api_secret);
15
16    let client = GateHttpClient::default().credentials(credentials.clone());
17
18    // Cancel all open orders (optionally filter by currency_pair)
19    let req = spot::cancel_all_open_orders().currency_pair("DUREV_USDT"); // Optional: cancel only for specific pair
20
21    let resp = client.send(req)?;
22    let body = resp.into_body_str()?;
23    let resp_obj: Value = serde_json::from_str(&body).unwrap();
24    println!("{:?}", resp_obj);
25
26    Ok(())
27}