gateio-rs 0.1.0

Comprehensive Rust SDK for Gate.io cryptocurrency exchange API with sync and async support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
//! # Gate.io Spot Trading API
//!
//! This module provides a comprehensive interface to Gate.io's Spot trading API endpoints.
//! All functions return request builders that can be configured with additional parameters
//! before sending via the HTTP client.
//!
//! ## Categories
//!
//! ### Market Data (Public)
//! - [`get_currencies`] - List all supported currencies
//! - [`get_currency`] - Get specific currency details
//! - [`get_currency_pairs`] - List all trading pairs
//! - [`get_currency_pair`] - Get specific pair details
//! - [`get_ticker`] - Get ticker information
//! - [`get_orderbook`] - Get order book data
//! - [`get_market_trades`] - Get recent market trades
//! - [`get_candlesticks`] - Get historical price data
//! - [`get_server_time`] - Get server timestamp
//!
//! ### Account Management (Private)
//! - [`get_account`] - List spot account balances
//! - [`get_account_book`] - Query account transaction history
//! - [`get_fee`] - Get trading fee rates
//! - [`get_batch_user_fee`] - Get fee rates for multiple pairs
//!
//! ### Order Management (Private)
//! - [`create_order`] - Place a new order
//! - [`create_batch_orders`] - Place multiple orders
//! - [`get_orders`] - List order history
//! - [`get_order`] - Get specific order details
//! - [`get_open_orders`] - List active orders
//! - [`amend_order`] - Modify an existing order
//! - [`amend_batch_orders`] - Modify multiple orders
//! - [`cancel_order`] - Cancel a specific order
//! - [`cancel_batch_orders`] - Cancel multiple orders
//! - [`cancel_all_open_orders`] - Cancel all open orders
//! - [`countdown_cancel_all`] - Set auto-cancel timer
//!
//! ### Advanced Orders (Private)
//! - [`create_price_order`] - Create stop/trigger orders
//! - [`get_price_orders`] - List active trigger orders
//! - [`get_price_order`] - Get specific trigger order
//! - [`cancel_price_order`] - Cancel trigger order
//! - [`cancel_all_price_orders`] - Cancel all trigger orders
//! - [`create_cross_liquidate_orders`] - Cross-currency liquidation
//!
//! ### Trading History (Private)
//! - [`get_my_trades`] - Get personal trade history
//! - [`get_insurance_history`] - Get insurance fund data
//!
//! ## Example Usage
//!
//! ```rust,no_run
//! use gateio_rs::{
//!     api::spot::{get_ticker, create_order},
//!     http::Credentials,
//!     ureq::GateHttpClient,
//! };
//!
//! // Public API - no authentication needed
//! let client = GateHttpClient::default();
//! let ticker_req = get_ticker().currency_pair("BTC_USDT");
//! let response = client.send(ticker_req)?;
//!
//! // Private API - requires authentication
//! let credentials = Credentials::new("api_key", "api_secret");
//! let client = GateHttpClient::default().credentials(credentials);
//! let order_req = create_order("BTC_USDT", "buy", "0.001").price("50000");
//! let response = client.send(order_req)?;
//! # Ok::<(), Box<dyn std::error::Error>>(()).expect("");
//! ```
//!
//! For detailed parameter documentation, see the [Gate.io API Documentation](https://www.gate.com/docs/developers/apiv4/#spot).

/// Amend multiple orders in batch
pub mod amend_batch_orders;
/// Amend a single order
pub mod amend_order;
/// Cancel all open orders
pub mod cancel_all_open_orders;
/// Cancel all price orders
pub mod cancel_all_price_orders;
/// Cancel multiple orders in batch
pub mod cancel_batch_orders;
/// Cancel a single order
pub mod cancel_order;
/// Cancel a price order
pub mod cancel_price_order;
/// Set countdown timer to cancel all orders
pub mod countdown_cancel_all;
/// Create multiple orders in batch
pub mod create_batch_orders;
/// Create cross liquidate orders
pub mod create_cross_liquidate_orders;
/// Create a single order
pub mod create_order;
/// Create a price order
pub mod create_price_order;
/// Get account information
pub mod get_account;
/// Get account transaction history
pub mod get_account_book;
/// Get batch user fee rates
pub mod get_batch_user_fee;
/// Get candlestick data
pub mod get_candlesticks;
/// Get all supported currencies
pub mod get_currencies;
/// Get single currency information
pub mod get_currency;
/// Get currency pair details
pub mod get_currency_pair;
/// Get all currency pairs
pub mod get_currency_pairs;
/// Get trading fees
pub mod get_fee;
/// Get insurance fund history
pub mod get_insurance_history;
/// Get market trade history
pub mod get_market_trades;
/// Get user's trade history
pub mod get_my_trades;
/// Get open orders
pub mod get_open_orders;
/// Get single order details
pub mod get_order;
/// Get order book
pub mod get_orderbook;
/// Get order history
pub mod get_orders;
/// Get single price order
pub mod get_price_order;
/// Get price order history
pub mod get_price_orders;
/// Get server time
pub mod get_server_time;
/// Get ticker information
pub mod get_ticker;
/// Order data structures
pub mod order;

use get_account::GetAccount;
use get_account_book::GetAccountBook;
use get_batch_user_fee::GetBatchUserFee;
use get_candlesticks::GetCandlesticks;
use get_currencies::GetCurrencies;
use get_currency::GetCurrency;
use get_currency_pair::GetCurrencyPair;
use get_currency_pairs::GetCurrencyPairs;
use get_market_trades::GetMarketTrades;
use get_orderbook::GetOrderbook;
use get_ticker::GetTicker;

use amend_batch_orders::AmendBatchOrders;
pub use amend_batch_orders::OrderAmendment;
use amend_order::AmendOrder;
use cancel_all_open_orders::CancelAllOpenOrders;
use cancel_all_price_orders::CancelAllPriceOrders;
use cancel_batch_orders::CancelBatchOrders;
pub use cancel_batch_orders::CancelOrderRequest;
use cancel_order::CancelOrder;
use cancel_price_order::CancelPriceOrder;
use countdown_cancel_all::CountdownCancelAll;
use create_batch_orders::CreateBatchOrders;
use create_cross_liquidate_orders::CreateCrossLiquidateOrders;
pub use create_cross_liquidate_orders::CrossLiquidateOrder;
use create_order::CreateOrder;
use create_price_order::CreatePriceOrder;
use get_fee::GetFee;
use get_insurance_history::GetInsuranceHistory;
use get_my_trades::GetMyTrades;
use get_open_orders::GetOpenOrders;
use get_order::GetOrder;
use get_orders::GetOrders;
use get_price_order::GetPriceOrder;
use get_price_orders::GetPriceOrders;
use get_server_time::GetServerTime;
pub use order::Order;

/// List all currencies' details <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#list-all-currencies-details)
pub fn get_currencies() -> GetCurrencies {
    GetCurrencies::new()
}

/// Get details of a specific currency <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#get-details-of-a-specific-currency)
pub fn get_currency(currency: &str) -> GetCurrency {
    GetCurrency::new(currency)
}

/// List all currency pairs supported <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#list-all-currency-pairs-supported)
pub fn get_currency_pairs() -> GetCurrencyPairs {
    GetCurrencyPairs::new()
}

/// Get details of a specific currency pair <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#get-details-of-a-specifc-currency-pair)
pub fn get_currency_pair(currency_pair: &str) -> GetCurrencyPair {
    GetCurrencyPair::new(currency_pair)
}

/// Retrieve ticker information for currency pairs.
///
/// Returns 24hr trading statistics including price, volume, and changes.
/// Can be used to get data for a specific pair or all pairs at once.
///
/// # Parameters
/// - `currency_pair`: Optional. Specific trading pair (e.g., "BTC_USDT")
/// - `timezone`: Optional. Timezone for calculation ("utc0" to "utc12", "utc-12" to "utc-1")
///
/// # Examples
///
/// ```rust,no_run
/// use gateio_rs::{api::spot::get_ticker, ureq::GateHttpClient};
///
/// let client = GateHttpClient::default();
///
/// // Get ticker for specific pair
/// let request = get_ticker().currency_pair("BTC_USDT");
/// let response = client.send(request)?;
///
/// // Get all tickers
/// let request = get_ticker();
/// let response = client.send(request)?;
/// # Ok::<(), Box<dyn std::error::Error>>(()).expect("");
/// ```
///
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#retrieve-ticker-information)
pub fn get_ticker() -> GetTicker {
    GetTicker::new()
}

/// Retrieve order book <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#retrieve-order-book)
pub fn get_orderbook(currency_pair: &str) -> GetOrderbook {
    GetOrderbook::new(currency_pair)
}

/// Retrieve market trades
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#retrieve-market-trades)
pub fn get_market_trades(currency_pair: &str) -> GetMarketTrades {
    GetMarketTrades::new(currency_pair)
}

/// Market candlesticks
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#market-candlesticks)
pub fn get_candlesticks(currency_pair: &str) -> GetCandlesticks {
    GetCandlesticks::new(currency_pair)
}

/// Query a batch of user trading fee rates
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#query-a-batch-of-user-trading-fee-rates)
pub fn get_batch_user_fee(currency_pairs: &str) -> GetBatchUserFee {
    GetBatchUserFee::new(currency_pairs)
}

/// List spot account balances and information.
///
/// Returns account balances for all currencies in the spot trading account.
/// Shows available balance, locked balance, and total balance for each currency.
///
/// # Authentication
/// This endpoint requires API key authentication.
///
/// # Optional Parameters (via builder methods)
/// - `currency`: Filter by specific currency (e.g., "BTC", "USDT")
///
/// # Examples
///
/// ```rust,no_run
/// 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);
///
/// // Get all account balances
/// let request = get_account();
/// let response = client.send(request)?;
///
/// // Get specific currency balance
/// let request = get_account().currency("BTC");
/// let response = client.send(request)?;
/// # Ok::<(), Box<dyn std::error::Error>>(()).expect("");
/// ```
///
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#list-spot-accounts)
pub fn get_account() -> GetAccount {
    GetAccount::new()
}

/// Query account book <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#query-account-book)
pub fn get_account_book() -> GetAccountBook {
    GetAccountBook::new()
}

/// List all open orders <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#list-all-open-orders)
pub fn get_open_orders() -> GetOpenOrders {
    GetOpenOrders::new()
}

/// Create a new trading order.
///
/// Places a buy or sell order on the specified trading pair. Supports various order types
/// including market, limit, and immediate-or-cancel orders.
///
/// # Parameters
/// - `currency_pair`: Trading pair (e.g., "BTC_USDT")
/// - `side`: Order side ("buy" or "sell")
/// - `amount`: Order amount in base currency
///
/// # Optional Parameters (via builder methods)
/// - `price`: Order price (required for limit orders)
/// - `order_type`: "limit", "market", "ioc", "poc", "fok" (default: "limit")
/// - `account`: Account type ("spot", "margin", "cross_margin", "unified")
/// - `time_in_force`: "gtc", "ioc", "poc", "fok" (default: "gtc")
/// - `text`: Custom order ID for identification
///
/// # Examples
///
/// ```rust,no_run
/// 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");
/// 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)?;
/// # Ok::<(), Box<dyn std::error::Error>>(()).expect("");
/// ```
///
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#create-an-order)
pub fn create_order(currency_pair: &str, side: &str, amount: &str) -> CreateOrder {
    CreateOrder::new(currency_pair, side, amount)
}

/// List orders <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#list-orders)
pub fn get_orders() -> GetOrders {
    GetOrders::new()
}

/// Get a single order <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#get-a-single-order)
pub fn get_order(order_id: &str, currency_pair: &str) -> GetOrder {
    GetOrder::new(order_id, currency_pair)
}

/// Cancel a batch of orders <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#cancel-a-batch-of-orders-with-an-id-list)
pub fn cancel_batch_orders(orders: Vec<CancelOrderRequest>) -> CancelBatchOrders {
    CancelBatchOrders::new(orders)
}

/// List personal trading history <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#list-personal-trading-history)
pub fn get_my_trades() -> GetMyTrades {
    GetMyTrades::new()
}

/// Query user trading fee rates <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#query-user-trading-fee-rates)
pub fn get_fee() -> GetFee {
    GetFee::new()
}

/// Cancel a single order <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#cancel-a-single-order)
pub fn cancel_order(order_id: &str, currency_pair: &str) -> CancelOrder {
    CancelOrder::new(order_id, currency_pair)
}

/// Amend an order <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#amend-an-order)
pub fn amend_order(order_id: &str, currency_pair: &str) -> AmendOrder {
    AmendOrder::new(order_id, currency_pair)
}

/// Create a batch of orders <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#create-a-batch-of-orders)
pub fn create_batch_orders(orders: Vec<Order>) -> CreateBatchOrders {
    CreateBatchOrders::new(orders)
}

/// Create a price-triggered order <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#create-a-price-triggered-order)
pub fn create_price_order(
    market: &str,
    trigger_price: &str,
    trigger_rule: &str,
    order_side: &str,
    order_price: &str,
    order_amount: &str,
) -> CreatePriceOrder {
    CreatePriceOrder::new(
        market,
        trigger_price,
        trigger_rule,
        order_side,
        order_price,
        order_amount,
    )
}

/// Retrieve running auto order list <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#retrieve-running-auto-order-list)
pub fn get_price_orders() -> GetPriceOrders {
    GetPriceOrders::new()
}

/// Cancel all price-triggered orders <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#cancel-all-price-triggered-orders)
pub fn cancel_all_price_orders() -> CancelAllPriceOrders {
    CancelAllPriceOrders::new()
}

/// Get a price-triggered order <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#get-a-price-triggered-order)
pub fn get_price_order(order_id: &str) -> GetPriceOrder {
    GetPriceOrder::new(order_id)
}

/// Cancel a price-triggered order <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#cancel-a-price-triggered-order)
pub fn cancel_price_order(order_id: &str) -> CancelPriceOrder {
    CancelPriceOrder::new(order_id)
}

/// Get server current time <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#get-server-current-time)
pub fn get_server_time() -> GetServerTime {
    GetServerTime::new()
}

/// Cancel all open orders <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#cancel-all-open-orders)
pub fn cancel_all_open_orders() -> CancelAllOpenOrders {
    CancelAllOpenOrders::new()
}

/// Countdown cancel orders <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#countdown-cancel-orders)
pub fn countdown_cancel_all(timeout: i64) -> CountdownCancelAll {
    CountdownCancelAll::new(timeout)
}

/// Amend multiple orders <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#batch-modification-of-orders)
pub fn amend_batch_orders(orders: Vec<OrderAmendment>) -> AmendBatchOrders {
    AmendBatchOrders::new(orders)
}

/// Create cross liquidation orders <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#close-position-when-cross-currency-is-disabled)
pub fn create_cross_liquidate_orders(
    orders: Vec<CrossLiquidateOrder>,
) -> CreateCrossLiquidateOrders {
    CreateCrossLiquidateOrders::new(orders)
}

/// Query insurance fund history <br/>
/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#query-spot-insurance-fund-historical-data)
pub fn get_insurance_history(
    business: &str,
    currency: &str,
    from: i64,
    to: i64,
) -> GetInsuranceHistory {
    GetInsuranceHistory::new(business, currency, from, to)
}