Skip to main content

CreateOrder

Struct CreateOrder 

Source
pub struct CreateOrder {
Show 15 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>, pub x_gate_exp_time: Option<u128>, pub credentials: Option<Credentials>,
}
Expand description

Request builder for creating trading orders.

Creates a new buy or sell order on Gate.io spot markets. Supports various order types including limit, market, immediate-or-cancel (IOC), and fill-or-kill (FOK) orders.

§API Endpoint

POST /api/v4/spot/orders

§Authentication

This endpoint requires API key authentication with signing.

§Examples

use gateio_rs::{
    api::spot::create_order,
    http::Credentials,
    ureq::GateHttpClient,
};

let credentials = Credentials::new("api_key", "api_secret");
let client = GateHttpClient::default().credentials(credentials);

// Limit buy order
let request = create_order("BTC_USDT", "buy", "0.001")
    .price("50000")
    .order_type("limit")
    .time_in_force("gtc")
    .text("t-my-order-123");
let response = client.send(request)?;

// Market sell order
let request = create_order("BTC_USDT", "sell", "0.001")
    .order_type("market");
let response = client.send(request)?;

§Parameter Details

§Order Types (order_type)

  • "limit": Limit order (default) - requires price
  • "market": Market order - executes immediately at market price
  • "ioc": Immediate-or-cancel - taker only
  • "poc": Post-only - maker only (enjoys maker fee)
  • "fok": Fill-or-kill - complete fill or cancel

§Time in Force (time_in_force)

  • "gtc": Good-till-cancelled (default)
  • "ioc": Immediate-or-cancel
  • "poc": Post-only
  • "fok": Fill-or-kill

§Amount Rules

  • Limit orders: Amount refers to base currency (e.g., BTC in BTC_USDT)
  • Market buy: Amount refers to quote currency (e.g., USDT in BTC_USDT)
  • Market sell: Amount refers to base currency (e.g., BTC in BTC_USDT)

§Account Types (account)

  • "spot": Spot trading account
  • "margin": Margin trading account
  • "cross_margin": Cross margin account
  • "unified": Unified account

§Self-Trading Prevention (stp_act)

  • "cn": Cancel newest orders
  • "co": Cancel oldest orders
  • "cb": Cancel both old and new orders

§Text Field Rules

Custom order ID must:

  • Be prefixed with "t-"
  • Be no longer than 28 bytes (excluding prefix)
  • Contain only: 0-9, A-Z, a-z, underscore, hyphen, or dot

Fields§

§text: Option<String>

Custom order ID

§currency_pair: String

Trading pair

§order_type: Option<String>

Order type

§account: Option<String>

Account type

§side: String

Order side

§amount: String

Order amount

§price: Option<String>

Order price

§time_in_force: Option<String>

Time in force

§iceberg: Option<String>

Iceberg amount

§auto_borrow: Option<bool>

Auto borrow funds

§auto_repay: Option<bool>

Auto repay borrowed

§stp_act: Option<String>

Self-trade prevention

§action_mode: Option<String>

Processing mode

§x_gate_exp_time: Option<u128>

Request expiration time

§credentials: Option<Credentials>

API credentials

Implementations§

Source§

impl CreateOrder

Source

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

Create new order request

Source

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

Set custom order ID

Source

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

Set order type

Examples found in repository?
examples/sync/create_order.rs (line 15)
4fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
5    dotenv::dotenv().ok();
6
7    let api_key = std::env::var("GATE_API_KEY").expect("GATE_API_KEY not set");
8    let api_secret = std::env::var("GATE_API_SECRET").expect("GATE_API_SECRET not set");
9    let credentials = Credentials::new(api_key, api_secret);
10
11    let client = GateHttpClient::default().credentials(credentials.clone());
12
13    // Create a limit order
14    let req = spot::create_order("DUREV_USDT", "buy", "800")
15        .order_type("limit")
16        .price("0.004")
17        .time_in_force("gtc")
18        .account("spot");
19
20    // Create a market order
21    // let req = spot::create_order("DUREV_USDT", "sell", "0")
22    //     .order_type("market")
23    //     .time_in_force("ioc");
24    // .account("spot");
25
26    let resp = client.send(req)?;
27    let body = resp.into_body_str()?;
28    let resp_obj: Value = serde_json::from_str(&body).unwrap();
29    println!("{:?}", resp_obj);
30
31    Ok(())
32}
Source

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

Set account type

Examples found in repository?
examples/sync/create_order.rs (line 18)
4fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
5    dotenv::dotenv().ok();
6
7    let api_key = std::env::var("GATE_API_KEY").expect("GATE_API_KEY not set");
8    let api_secret = std::env::var("GATE_API_SECRET").expect("GATE_API_SECRET not set");
9    let credentials = Credentials::new(api_key, api_secret);
10
11    let client = GateHttpClient::default().credentials(credentials.clone());
12
13    // Create a limit order
14    let req = spot::create_order("DUREV_USDT", "buy", "800")
15        .order_type("limit")
16        .price("0.004")
17        .time_in_force("gtc")
18        .account("spot");
19
20    // Create a market order
21    // let req = spot::create_order("DUREV_USDT", "sell", "0")
22    //     .order_type("market")
23    //     .time_in_force("ioc");
24    // .account("spot");
25
26    let resp = client.send(req)?;
27    let body = resp.into_body_str()?;
28    let resp_obj: Value = serde_json::from_str(&body).unwrap();
29    println!("{:?}", resp_obj);
30
31    Ok(())
32}
Source

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

Set order price

Examples found in repository?
examples/sync/create_order.rs (line 16)
4fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
5    dotenv::dotenv().ok();
6
7    let api_key = std::env::var("GATE_API_KEY").expect("GATE_API_KEY not set");
8    let api_secret = std::env::var("GATE_API_SECRET").expect("GATE_API_SECRET not set");
9    let credentials = Credentials::new(api_key, api_secret);
10
11    let client = GateHttpClient::default().credentials(credentials.clone());
12
13    // Create a limit order
14    let req = spot::create_order("DUREV_USDT", "buy", "800")
15        .order_type("limit")
16        .price("0.004")
17        .time_in_force("gtc")
18        .account("spot");
19
20    // Create a market order
21    // let req = spot::create_order("DUREV_USDT", "sell", "0")
22    //     .order_type("market")
23    //     .time_in_force("ioc");
24    // .account("spot");
25
26    let resp = client.send(req)?;
27    let body = resp.into_body_str()?;
28    let resp_obj: Value = serde_json::from_str(&body).unwrap();
29    println!("{:?}", resp_obj);
30
31    Ok(())
32}
More examples
Hide additional examples
examples/sync_example.rs (line 70)
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

Set time in force

Examples found in repository?
examples/sync/create_order.rs (line 17)
4fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
5    dotenv::dotenv().ok();
6
7    let api_key = std::env::var("GATE_API_KEY").expect("GATE_API_KEY not set");
8    let api_secret = std::env::var("GATE_API_SECRET").expect("GATE_API_SECRET not set");
9    let credentials = Credentials::new(api_key, api_secret);
10
11    let client = GateHttpClient::default().credentials(credentials.clone());
12
13    // Create a limit order
14    let req = spot::create_order("DUREV_USDT", "buy", "800")
15        .order_type("limit")
16        .price("0.004")
17        .time_in_force("gtc")
18        .account("spot");
19
20    // Create a market order
21    // let req = spot::create_order("DUREV_USDT", "sell", "0")
22    //     .order_type("market")
23    //     .time_in_force("ioc");
24    // .account("spot");
25
26    let resp = client.send(req)?;
27    let body = resp.into_body_str()?;
28    let resp_obj: Value = serde_json::from_str(&body).unwrap();
29    println!("{:?}", resp_obj);
30
31    Ok(())
32}
Source

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

Set iceberg amount

Source

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

Enable auto borrow

Source

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

Enable auto repay

Source

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

Set self-trade prevention

Source

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

Set processing mode

Source

pub fn x_gate_exp_time(self, x_gate_exp_time: u128) -> Self

Set expiration time

Source

pub fn credentials(self, creds: Credentials) -> Self

Set API credentials

Trait Implementations§

Source§

impl From<CreateOrder> for Request

Source§

fn from(request: CreateOrder) -> Request

Converts to this type from the input type.

Auto Trait Implementations§

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> 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, 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.