Skip to main content

CreatePriceOrder

Struct CreatePriceOrder 

Source
pub struct CreatePriceOrder {
    pub trigger: SpotPriceTrigger,
    pub put: SpotPricePutOrder,
    pub market: String,
    pub x_gate_exp_time: Option<u128>,
    pub credentials: Option<Credentials>,
}
Expand description

§Create a price-triggered order

A price-triggered order (also known as conditional order) will not enter the order book until the trigger condition is met. Once triggered, it will attempt to place a limit order at the preset price and amount.

§Important Notes:

  • The conditional order does not occupy your balance until it is triggered
  • Make sure to set aside enough balance for this order
  • A price condition order can only be triggered one time
  • When using “<=”, the trigger price should be less than the current market price
  • When using “>=”, the trigger price should be greater than the current market price
  • Only limit orders are supported as the triggered order type

§Status Values:

  • “open” : Waiting to trigger
  • “cancelled” : Manually cancelled
  • “finish” : Successfully executed
  • “failed” : Failed to execute
  • “expired” : Expired

Gate API Documentation

Fields§

§trigger: SpotPriceTrigger

Trigger conditions for the order

§put: SpotPricePutOrder

Order details to execute when triggered

§market: String

Currency pair for the order

§x_gate_exp_time: Option<u128>

Request expiration time in milliseconds

§credentials: Option<Credentials>

API credentials for authentication

Implementations§

Source§

impl CreatePriceOrder

Source

pub fn new( market: &str, trigger_price: &str, trigger_rule: &str, order_side: &str, order_price: &str, order_amount: &str, ) -> Self

Create a new price-triggered order request

Source

pub fn trigger(self, trigger: SpotPriceTrigger) -> Self

Set the trigger conditions

Source

pub fn put(self, put: SpotPricePutOrder) -> Self

Set the order details to execute when triggered

Source

pub fn trigger_expiration(self, expiration: i64) -> Self

Set the trigger expiration time in seconds

Examples found in repository?
examples/sync/create_price_order.rs (line 26)
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 price-triggered order
14    // This example creates a buy order that will trigger when BTC price goes above $50,000
15    // When triggered, it will place a limit buy order for 0.001 BTC at $49,900
16    let req = spot::create_price_order(
17        "BTC_USDT", // market (currency pair)
18        "120000",   // trigger_price
19        ">=",       // trigger_rule (trigger when price >= $50,000)
20        "buy",      // order_side
21        "49900",    // order_price (limit price when triggered)
22        "0.001",    // order_amount
23    )
24    .account("normal") // use normal spot account
25    .time_in_force("gtc") // good till cancelled
26    .trigger_expiration(86400); // expire after 24 hours if not triggered
27
28    println!("Sending price-triggered order request...");
29
30    let resp = client.send(req)?;
31    let body = resp.into_body_str()?;
32    let resp_obj: Value = serde_json::from_str(&body).unwrap();
33
34    println!("Response: {:#}", resp_obj);
35
36    Ok(())
37}
Source

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

Set the trading account type for the triggered order

Examples found in repository?
examples/sync/create_price_order.rs (line 24)
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 price-triggered order
14    // This example creates a buy order that will trigger when BTC price goes above $50,000
15    // When triggered, it will place a limit buy order for 0.001 BTC at $49,900
16    let req = spot::create_price_order(
17        "BTC_USDT", // market (currency pair)
18        "120000",   // trigger_price
19        ">=",       // trigger_rule (trigger when price >= $50,000)
20        "buy",      // order_side
21        "49900",    // order_price (limit price when triggered)
22        "0.001",    // order_amount
23    )
24    .account("normal") // use normal spot account
25    .time_in_force("gtc") // good till cancelled
26    .trigger_expiration(86400); // expire after 24 hours if not triggered
27
28    println!("Sending price-triggered order request...");
29
30    let resp = client.send(req)?;
31    let body = resp.into_body_str()?;
32    let resp_obj: Value = serde_json::from_str(&body).unwrap();
33
34    println!("Response: {:#}", resp_obj);
35
36    Ok(())
37}
Source

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

Set the time in force for the triggered order

Examples found in repository?
examples/sync/create_price_order.rs (line 25)
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 price-triggered order
14    // This example creates a buy order that will trigger when BTC price goes above $50,000
15    // When triggered, it will place a limit buy order for 0.001 BTC at $49,900
16    let req = spot::create_price_order(
17        "BTC_USDT", // market (currency pair)
18        "120000",   // trigger_price
19        ">=",       // trigger_rule (trigger when price >= $50,000)
20        "buy",      // order_side
21        "49900",    // order_price (limit price when triggered)
22        "0.001",    // order_amount
23    )
24    .account("normal") // use normal spot account
25    .time_in_force("gtc") // good till cancelled
26    .trigger_expiration(86400); // expire after 24 hours if not triggered
27
28    println!("Sending price-triggered order request...");
29
30    let resp = client.send(req)?;
31    let body = resp.into_body_str()?;
32    let resp_obj: Value = serde_json::from_str(&body).unwrap();
33
34    println!("Response: {:#}", resp_obj);
35
36    Ok(())
37}
Source

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

Specify the expiration time (milliseconds); If the GATE receives the request time greater than the expiration time, the request will be rejected

Source

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

Set API credentials for authentication

Trait Implementations§

Source§

impl From<CreatePriceOrder> for Request

Source§

fn from(request: CreatePriceOrder) -> 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.