pub struct GateHttpClient { /* private fields */ }Expand description
Synchronous HTTP client for Gate.io API using ureq.
This client provides blocking I/O operations and is the default client for the Gate.io Rust SDK. It automatically handles request signing, authentication, and provides a simple interface for all API endpoints.
§Features
- Request Signing: Automatic HMAC SHA-512 signing for authenticated endpoints
- Error Handling: Comprehensive error handling with detailed error types
- Flexible Configuration: Configurable base URL, timeouts, and credentials
- Thread Safe: Can be safely shared across threads using
Arc
§Examples
§Basic Usage (Public API)
use gateio_rs::{api::spot::get_ticker, ureq::GateHttpClient};
let client = GateHttpClient::default();
let request = get_ticker().currency_pair("BTC_USDT");
let response = client.send(request)?;§Authenticated Usage
use gateio_rs::{
api::spot::get_account,
http::Credentials,
ureq::GateHttpClient,
};
let credentials = Credentials::new("api_key", "api_secret");
let client = GateHttpClient::default().credentials(credentials);
let request = get_account();
let response = client.send(request)?;§Custom Configuration
use gateio_rs::{http::Credentials, ureq::GateHttpClient};
let client = GateHttpClient::with_url("https://api.gateio.ws")
.credentials(Credentials::new("api_key", "api_secret"))
.timestamp_delta(1000); // Adjust for server time differencesImplementations§
Source§impl GateHttpClient
impl GateHttpClient
Sourcepub fn default() -> Self
pub fn default() -> Self
Creates a new client with default settings and Gate.io production URL
Examples found in repository?
examples/sync/get_server_time.rs (line 7)
4fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
5 dotenv::dotenv().ok();
6
7 let client = GateHttpClient::default();
8
9 // Get server time (public endpoint, no credentials needed)
10 let req = spot::get_server_time();
11
12 let resp = client.send(req)?;
13 let body = resp.into_body_str()?;
14 let resp_obj: Value = serde_json::from_str(&body).unwrap();
15 println!("{:?}", resp_obj);
16
17 Ok(())
18}More examples
examples/sync/get_open_orders.rs (line 11)
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 let req = spot::get_open_orders().page(1).limit(100);
14
15 let resp = client.send(req)?;
16 let body = resp.into_body_str()?;
17 let resp_obj: Value = serde_json::from_str(&body).unwrap();
18 println!("{:?}", resp_obj);
19
20 Ok(())
21}examples/sync/get_currencies.rs (line 11)
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 // Get all available currencies
14 let req = spot::get_currencies();
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_currency_pairs.rs (line 11)
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 // Get all available currency pairs
14 let req = spot::get_currency_pairs();
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_currency.rs (line 11)
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 // Get details for a specific currency
14 let req = spot::get_currency("BTC");
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_currency_pair.rs (line 11)
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 // Get details for a specific currency pair
14 let req = spot::get_currency_pair("BTC_USDT");
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}Additional examples can be found in:
- examples/sync/get_orderbook.rs
- examples/sync/get_account_book.rs
- examples/sync/get_my_trades.rs
- examples/sync/get_price_orders.rs
- examples/sync/get_candlesticks.rs
- examples/sync/get_batch_user_fee.rs
- examples/sync/cancel_order.rs
- examples/sync/get_orders.rs
- examples/sync/get_market_trades.rs
- examples/sync/get_order.rs
- examples/sync/amend_order.rs
- examples/sync/get_price_order.rs
- examples/sync/get_insurance_history.rs
- examples/sync/get_account.rs
- examples/sync/get_ticker.rs
- examples/sync/create_order.rs
- examples/sync/create_batch_orders.rs
- examples/sync/cancel_all_price_orders.rs
- examples/sync/cancel_price_order.rs
- examples/sync/amend_batch_orders.rs
- examples/sync/cancel_all_open_orders.rs
- examples/sync/cancel_batch_orders.rs
- examples/sync/get_fee.rs
- examples/sync/countdown_cancel_all.rs
- examples/sync/create_cross_liquidate_orders.rs
- examples/sync/create_price_order.rs
- examples/sync_example.rs
Sourcepub fn with_custom_agent(agent: Agent, url: &str) -> Self
pub fn with_custom_agent(agent: Agent, url: &str) -> Self
Creates a new client with a custom ureq Agent and base URL
Sourcepub fn credentials(self, credentials: Credentials) -> Self
pub fn credentials(self, credentials: Credentials) -> Self
Sets the default API credentials for all requests
Examples found in repository?
examples/sync/get_open_orders.rs (line 11)
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 let req = spot::get_open_orders().page(1).limit(100);
14
15 let resp = client.send(req)?;
16 let body = resp.into_body_str()?;
17 let resp_obj: Value = serde_json::from_str(&body).unwrap();
18 println!("{:?}", resp_obj);
19
20 Ok(())
21}More examples
examples/sync/get_currencies.rs (line 11)
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 // Get all available currencies
14 let req = spot::get_currencies();
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_currency_pairs.rs (line 11)
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 // Get all available currency pairs
14 let req = spot::get_currency_pairs();
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_currency.rs (line 11)
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 // Get details for a specific currency
14 let req = spot::get_currency("BTC");
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_currency_pair.rs (line 11)
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 // Get details for a specific currency pair
14 let req = spot::get_currency_pair("BTC_USDT");
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_orderbook.rs (line 11)
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 // Get orderbook for BTC_USDT
14 let req = spot::get_orderbook("BTC_USDT").limit(100).interval("0");
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}Additional examples can be found in:
- examples/sync/get_account_book.rs
- examples/sync/get_my_trades.rs
- examples/sync/get_price_orders.rs
- examples/sync/get_candlesticks.rs
- examples/sync/get_batch_user_fee.rs
- examples/sync/cancel_order.rs
- examples/sync/get_orders.rs
- examples/sync/get_market_trades.rs
- examples/sync/get_order.rs
- examples/sync/amend_order.rs
- examples/sync/get_price_order.rs
- examples/sync/get_insurance_history.rs
- examples/sync/get_account.rs
- examples/sync/get_ticker.rs
- examples/sync/create_order.rs
- examples/sync/create_batch_orders.rs
- examples/sync/cancel_all_price_orders.rs
- examples/sync/cancel_price_order.rs
- examples/sync/amend_batch_orders.rs
- examples/sync/cancel_all_open_orders.rs
- examples/sync/cancel_batch_orders.rs
- examples/sync/get_fee.rs
- examples/sync/countdown_cancel_all.rs
- examples/sync/create_cross_liquidate_orders.rs
- examples/sync/create_price_order.rs
- examples/sync_example.rs
Sourcepub fn timestamp_delta(self, timestamp_delta: u64) -> Self
pub fn timestamp_delta(self, timestamp_delta: u64) -> Self
Sets the timestamp delta to adjust for server time differences
Sourcepub fn send<R: Into<Request>>(&self, request: R) -> Result<Response, Box<Error>>
pub fn send<R: Into<Request>>(&self, request: R) -> Result<Response, Box<Error>>
Sends an HTTP request to the Gate.io API
Examples found in repository?
examples/sync/get_server_time.rs (line 12)
4fn main() -> Result<(), Box<gateio_rs::ureq::Error>> {
5 dotenv::dotenv().ok();
6
7 let client = GateHttpClient::default();
8
9 // Get server time (public endpoint, no credentials needed)
10 let req = spot::get_server_time();
11
12 let resp = client.send(req)?;
13 let body = resp.into_body_str()?;
14 let resp_obj: Value = serde_json::from_str(&body).unwrap();
15 println!("{:?}", resp_obj);
16
17 Ok(())
18}More examples
examples/sync/get_open_orders.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 let req = spot::get_open_orders().page(1).limit(100);
14
15 let resp = client.send(req)?;
16 let body = resp.into_body_str()?;
17 let resp_obj: Value = serde_json::from_str(&body).unwrap();
18 println!("{:?}", resp_obj);
19
20 Ok(())
21}examples/sync/get_currencies.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 // Get all available currencies
14 let req = spot::get_currencies();
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_currency_pairs.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 // Get all available currency pairs
14 let req = spot::get_currency_pairs();
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_currency.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 // Get details for a specific currency
14 let req = spot::get_currency("BTC");
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}examples/sync/get_currency_pair.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 // Get details for a specific currency pair
14 let req = spot::get_currency_pair("BTC_USDT");
15
16 let resp = client.send(req)?;
17 let body = resp.into_body_str()?;
18 let resp_obj: Value = serde_json::from_str(&body).unwrap();
19 println!("{:?}", resp_obj);
20
21 Ok(())
22}Additional examples can be found in:
- examples/sync/get_orderbook.rs
- examples/sync/get_account_book.rs
- examples/sync/get_my_trades.rs
- examples/sync/get_price_orders.rs
- examples/sync/get_candlesticks.rs
- examples/sync/get_batch_user_fee.rs
- examples/sync/cancel_order.rs
- examples/sync/get_orders.rs
- examples/sync/get_market_trades.rs
- examples/sync/get_order.rs
- examples/sync/amend_order.rs
- examples/sync/get_price_order.rs
- examples/sync/get_insurance_history.rs
- examples/sync/get_account.rs
- examples/sync/get_ticker.rs
- examples/sync/create_order.rs
- examples/sync/create_batch_orders.rs
- examples/sync/cancel_all_price_orders.rs
- examples/sync/cancel_price_order.rs
- examples/sync/amend_batch_orders.rs
- examples/sync/cancel_all_open_orders.rs
- examples/sync/cancel_batch_orders.rs
- examples/sync/get_fee.rs
- examples/sync/countdown_cancel_all.rs
- examples/sync/create_cross_liquidate_orders.rs
- examples/sync/create_price_order.rs
- examples/sync_example.rs
Trait Implementations§
Source§impl Clone for GateHttpClient
impl Clone for GateHttpClient
Source§fn clone(&self) -> GateHttpClient
fn clone(&self) -> GateHttpClient
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for GateHttpClient
impl !UnwindSafe for GateHttpClient
impl Freeze for GateHttpClient
impl Send for GateHttpClient
impl Sync for GateHttpClient
impl Unpin for GateHttpClient
impl UnsafeUnpin for GateHttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more