bitget.rb 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  # Bitget/V2/Client.rb
2
2
  # Bitget::V2::Client
3
3
 
4
+ require 'base64'
4
5
  require 'fileutils'
5
6
  gem 'http.rb'; require 'http.rb'
6
7
  require 'json'
@@ -8,7 +9,6 @@ require 'logger'
8
9
  require 'openssl'
9
10
 
10
11
  require_relative '../Error'
11
- require_relative '../../Hash/to_parameter_string'
12
12
  require_relative '../../Hash/x_www_form_urlencode'
13
13
 
14
14
  module Bitget
@@ -42,15 +42,1111 @@ module Bitget
42
42
  end
43
43
  end # class << self
44
44
 
45
+ # Market
46
+
45
47
  # Get Coin Info
46
- # GET /api/v2/spot
48
+ # GET /api/v2/spot/public/coins
49
+ #
50
+ # Rate Limit: 3 times/1s (IP)
51
+ # Note: This endpoint retrieves information about supported cryptocurrencies
52
+ #
53
+ # @param coin [String] Optional. Filter by cryptocurrency code e.g. 'BTC', 'USDT'
54
+ # @return [Hash] Response containing:
55
+ # - code [String] Response code ('00000' for success)
56
+ # - msg [String] Response message ('success' for success, error description for failure)
57
+ # - requestTime [Integer] Request timestamp in milliseconds
58
+ # - data [Array<Hash>] Array of coin information:
59
+ # - coinId [String] Internal coin ID (e.g. '1' for BTC)
60
+ # - coin [String] Cryptocurrency code (e.g. 'BTC', 'USDT')
61
+ # - transfer [String] Whether transfers are enabled ('true'/'false')
62
+ # - areaCoin [String] Area coin status ('yes'/'no') - Note: Not documented in official API
63
+ # - chains [Array<Hash>] List of supported blockchain networks:
64
+ # - chain [String] Blockchain network name (e.g. 'BTC', 'BEP20', 'LIGHTNING')
65
+ # - needTag [String] Whether memo/tag is required ('true'/'false')
66
+ # - withdrawable [String] Whether withdrawals are enabled ('true'/'false')
67
+ # - rechargeable [String] Whether deposits are enabled ('true'/'false')
68
+ # - withdrawFee [String] Base withdrawal fee (e.g. '0.005')
69
+ # - extraWithdrawFee [String] Additional withdrawal fee (e.g. '0')
70
+ # - depositConfirm [String] Required confirmations for deposit (e.g. '1')
71
+ # - withdrawConfirm [String] Required confirmations for withdrawal (e.g. '1', '5', '15')
72
+ # - minDepositAmount [String] Minimum deposit amount (e.g. '0.00001')
73
+ # - minWithdrawAmount [String] Minimum withdrawal amount (e.g. '0.0005')
74
+ # - browserUrl [String] Block explorer URL (e.g. 'https://www.blockchain.com/explorer/transactions/btc/')
75
+ # - contractAddress [String] Token contract address if applicable (e.g. '0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c')
76
+ # - withdrawStep [String] Withdrawal step (e.g. '0')
77
+ # - withdrawMinScale [String] Withdrawal amount precision (e.g. '8')
78
+ # - congestion [String] Network congestion status ('normal'/'congested')
47
79
  def spot_public_coins(coin: nil)
48
80
  response = get(path: '/spot/public/coins', args: {coin: coin})
49
81
  handle_response(response)
50
82
  end
51
83
 
84
+ # Get Symbol Info
85
+ # GET /api/v2/spot/public/symbols
86
+ #
87
+ # Rate Limit: 20 times/1s (IP)
88
+ # Note: This endpoint retrieves information about supported trading pairs
89
+ #
90
+ # @param symbol [String] Optional. Filter by trading pair e.g. 'BTCUSDT'
91
+ # @return [Hash] Response containing:
92
+ # - code [String] Response code ('00000' for success)
93
+ # - msg [String] Response message ('success' for success, error description for failure)
94
+ # - requestTime [Integer] Request timestamp in milliseconds
95
+ # - data [Array<Hash>] Array of symbol information:
96
+ # - symbol [String] Trading pair name (e.g. 'BTCUSDT')
97
+ # - baseCoin [String] Base currency code (e.g. 'BTC')
98
+ # - quoteCoin [String] Quote currency code (e.g. 'USDT')
99
+ # - minTradeAmount [String] Minimum trade amount (e.g. '0')
100
+ # - maxTradeAmount [String] Maximum trade amount (e.g. '900000000000000000000')
101
+ # - takerFeeRate [String] Taker fee rate (e.g. '0.002')
102
+ # - makerFeeRate [String] Maker fee rate (e.g. '0.002')
103
+ # - pricePrecision [String] Price precision (decimal places) (e.g. '2')
104
+ # - quantityPrecision [String] Quantity precision (decimal places) (e.g. '6')
105
+ # - quotePrecision [String] Quote precision (decimal places) (e.g. '8')
106
+ # - status [String] Trading pair status (e.g. 'online')
107
+ # - minTradeUSDT [String] Minimum trade amount in USDT (e.g. '1')
108
+ # - buyLimitPriceRatio [String] Maximum buy price ratio (e.g. '0.05')
109
+ # - sellLimitPriceRatio [String] Maximum sell price ratio (e.g. '0.05')
110
+ # - areaSymbol [String] Area symbol status ('yes'/'no')
111
+ # - orderQuantity [String] Maximum order quantity (e.g. '200')
112
+ # - openTime [String] Trading pair open time in milliseconds (e.g. '1532454360000')
113
+ # - offTime [String] Trading pair off time in milliseconds (empty if active)
114
+ def spot_public_symbols(symbol: nil)
115
+ response = get(path: '/spot/public/symbols', args: {symbol: symbol})
116
+ handle_response(response)
117
+ end
118
+
119
+ # Get VIP Fee Rate
120
+ # GET /api/v2/spot/market/vip-fee-rate
121
+ #
122
+ # Rate Limit: 10 times/1s (IP)
123
+ # Note: This endpoint retrieves the current VIP fee rates for the user
124
+ #
125
+ # @return [Hash] Response containing:
126
+ # - code [String] Response code ('00000' for success)
127
+ # - msg [String] Response message ('success' for success, error description for failure)
128
+ # - requestTime [Integer] Request timestamp in milliseconds
129
+ # - data [Array<Hash>] Array of VIP level information:
130
+ # - level [Integer] VIP level (e.g. 1)
131
+ # - dealAmount [String] Trading volume requirement (e.g. '1000000')
132
+ # - assetAmount [String] Asset requirement (e.g. '50000')
133
+ # - takerFeeRate [String] Taker fee rate (e.g. '0')
134
+ # - makerFeeRate [String] Maker fee rate (e.g. '0')
135
+ # - btcWithdrawAmount [String] BTC withdrawal limit (e.g. '300')
136
+ # - usdtWithdrawAmount [String] USDT withdrawal limit (e.g. '5000000')
137
+ def spot_market_vip_fee_rate
138
+ response = get(path: '/spot/market/vip-fee-rate')
139
+ handle_response(response)
140
+ end
141
+
142
+ # Get Ticker Information
143
+ # GET /api/v2/spot/market/tickers
144
+ #
145
+ # Rate Limit: 20 times/1s (IP)
146
+ # Note: This endpoint retrieves 24-hour trading information for trading pairs
147
+ #
148
+ # @param symbol [String] Optional. Filter by trading pair e.g. 'BTCUSDT'
149
+ # @return [Hash] Response containing:
150
+ # - code [String] Response code ('00000' for success)
151
+ # - msg [String] Response message ('success' for success, error description for failure)
152
+ # - requestTime [Integer] Request timestamp in milliseconds
153
+ # - data [Array<Hash>] Array of ticker information:
154
+ # - symbol [String] Trading pair name (e.g. 'BTCUSDT')
155
+ # - high24h [String] Highest price in last 24 hours (e.g. '37775.65')
156
+ # - open [String] Opening price (e.g. '35134.2')
157
+ # - low24h [String] Lowest price in last 24 hours (e.g. '34413.1')
158
+ # - lastPr [String] Latest price (e.g. '34413.1')
159
+ # - quoteVolume [String] Quote currency volume (e.g. '0')
160
+ # - baseVolume [String] Base currency volume (e.g. '0')
161
+ # - usdtVolume [String] Volume in USDT equivalent (e.g. '0')
162
+ # - bidPr [String] Best bid price (e.g. '0')
163
+ # - askPr [String] Best ask price (e.g. '0')
164
+ # - bidSz [String] Best bid size (e.g. '0.0663')
165
+ # - askSz [String] Best ask size (e.g. '0.0119')
166
+ # - openUtc [String] UTC opening price (e.g. '23856.72')
167
+ # - ts [String] Timestamp in milliseconds (e.g. '1625125755277')
168
+ # - changeUtc24h [String] 24h price change in UTC (e.g. '0.00301')
169
+ # - change24h [String] 24h price change (e.g. '0.00069')
170
+ def spot_market_tickers(symbol: nil)
171
+ response = get(path: '/spot/market/tickers', args: {symbol: symbol})
172
+ handle_response(response)
173
+ end
174
+
175
+ # Get Merge Depth
176
+ # GET /api/v2/spot/market/merge-depth
177
+ #
178
+ # Rate Limit: 20 times/1s (IP)
179
+ # Note: This endpoint retrieves the merged order book depth for a trading pair
180
+ #
181
+ # @param symbol [String] Required. Trading pair name e.g. BTCUSDT
182
+ # @param precision [String] Optional. Price aggregation level (default: scale0)
183
+ # - scale0: No merge
184
+ # - scale1: Merge by quotation accuracy 10
185
+ # - scale2: Merge by quotation accuracy 100
186
+ # Note: Some pairs may not support all scales. Requests for unavailable
187
+ # scales will use the maximum available scale for that pair.
188
+ # @param limit [Integer] Optional. Number of bids and asks to return
189
+ # @return [Hash] Response containing:
190
+ # - code [String] Response code ('00000' for success)
191
+ # - msg [String] Response message ('success' for success)
192
+ # - requestTime [Integer] Request timestamp in milliseconds
193
+ # - data [Hash] Order book data containing:
194
+ # - asks [Array<Array>] Array of ask orders [price, size]
195
+ # - bids [Array<Array>] Array of bid orders [price, size]
196
+ # - ts [String] Timestamp in milliseconds
197
+ # - scale [String] Price scale (e.g. '0.01')
198
+ # - precision [String] Price aggregation level used (e.g. 'scale0')
199
+ # - isMaxPrecision [String] Whether maximum precision is used ('YES'/'NO')
200
+ def spot_market_merge_depth(symbol:, precision: nil, limit: nil)
201
+ response = get(
202
+ path: '/spot/market/merge-depth',
203
+ args: {
204
+ symbol: symbol,
205
+ precision: precision,
206
+ limit: limit,
207
+ }
208
+ )
209
+ handle_response(response)
210
+ end
211
+
212
+ # Get OrderBook Depth
213
+ # GET /api/v2/spot/market/orderbook
214
+ #
215
+ # Rate Limit: 20 times/1s (IP)
216
+ # Note: This endpoint retrieves the order book depth for a trading pair
217
+ #
218
+ # @param symbol [String] Required. Trading pair name e.g. BTCUSDT
219
+ # @param type [String] Optional. Price aggregation level (default: step0)
220
+ # Values: step0, step1, step2, step3, step4, step5
221
+ # @param limit [Integer] Optional. Number of bids and asks to return (default: 100, max: 200)
222
+ # @return [Hash] Response containing:
223
+ # - code [String] Response code ('00000' for success)
224
+ # - msg [String] Response message ('success' for success)
225
+ # - requestTime [Integer] Request timestamp in milliseconds
226
+ # - data [Hash] Order book data containing:
227
+ # - asks [Array<Array>] Array of ask orders [price, size]
228
+ # - bids [Array<Array>] Array of bid orders [price, size]
229
+ # - ts [String] Timestamp in milliseconds
230
+ def spot_market_orderbook(symbol:, type: nil, limit: nil)
231
+ response = get(
232
+ path: '/spot/market/orderbook',
233
+ args: {
234
+ symbol: symbol,
235
+ type: type,
236
+ limit: limit,
237
+ }
238
+ )
239
+ handle_response(response)
240
+ end
241
+
242
+ # Get Candlestick Data
243
+ # GET /api/v2/spot/market/candles
244
+ #
245
+ # Rate Limit: 20 times/1s (IP)
246
+ # Note: This endpoint retrieves candlestick/kline data for a trading pair
247
+ #
248
+ # @param symbol [String] Required. Trading pair name e.g. BTCUSDT
249
+ # @param granularity [String] Required. Time interval for candles
250
+ # Common values: '1min', '5min', '15min', '30min', '1h', '4h', '6h', '12h', '1d', '1w'
251
+ # @param start_time [Integer] Optional. Start time in Unix milliseconds e.g. 1659076670000
252
+ # @param end_time [Integer] Optional. End time in Unix milliseconds e.g. 1659080270000
253
+ # @param limit [Integer] Optional. Number of candles to return (default: 100)
254
+ # @return [Hash] Response containing:
255
+ # - code [String] Response code ('00000' for success)
256
+ # - msg [String] Response message ('success' for success)
257
+ # - requestTime [Integer] Request timestamp in milliseconds
258
+ # - data [Array<Array>] Array of candles, each array containing:
259
+ # - [0] [String] Timestamp in milliseconds
260
+ # - [1] [String] Opening price
261
+ # - [2] [String] Highest price
262
+ # - [3] [String] Lowest price
263
+ # - [4] [String] Closing price
264
+ # - [5] [String] Volume
265
+ # - [6] [String] Quote currency volume
266
+ # - [7] [String] Quote currency volume (duplicate)
267
+ def spot_market_candles(symbol:, granularity:, start_time: nil, end_time: nil, limit: nil)
268
+ response = get(
269
+ path: '/spot/market/candles',
270
+ args: {
271
+ symbol: symbol,
272
+ granularity: granularity,
273
+ startTime: start_time,
274
+ endTime: end_time,
275
+ limit: limit,
276
+ }
277
+ )
278
+ handle_response(response)
279
+ end
280
+
281
+ # Get History Candlestick Data
282
+ # GET /api/v2/spot/market/history-candles
283
+ #
284
+ # Rate Limit: 20 times/1s (IP)
285
+ # Note: This endpoint retrieves historical candlestick/kline data for a trading pair
286
+ #
287
+ # @param symbol [String] Required. Trading pair name e.g. BTCUSDT
288
+ # @param granularity [String] Required. Time interval for candles
289
+ # Common values: '1min', '5min', '15min', '30min', '1h', '4h', '6h', '12h', '1d', '1w'
290
+ # @param end_time [Integer] Required. End time in Unix milliseconds e.g. 1659080270000
291
+ # @param limit [Integer] Optional. Number of candles to return (default: 100)
292
+ # @return [Hash] Response containing:
293
+ # - code [String] Response code ('00000' for success)
294
+ # - msg [String] Response message ('success' for success)
295
+ # - requestTime [Integer] Request timestamp in milliseconds
296
+ # - data [Array<Array>] Array of candles, each array containing:
297
+ # - [0] [String] Timestamp in milliseconds
298
+ # - [1] [String] Opening price
299
+ # - [2] [String] Highest price
300
+ # - [3] [String] Lowest price
301
+ # - [4] [String] Closing price
302
+ # - [5] [String] Volume
303
+ # - [6] [String] Quote currency volume
304
+ # - [7] [String] Quote currency volume (duplicate)
305
+ def spot_market_history_candles(symbol:, granularity:, end_time:, limit: nil)
306
+ response = get(
307
+ path: '/spot/market/history-candles',
308
+ args: {
309
+ symbol: symbol,
310
+ granularity: granularity,
311
+ endTime: end_time,
312
+ limit: limit,
313
+ }
314
+ )
315
+ handle_response(response)
316
+ end
317
+
318
+ # Get Recent Trades
319
+ # GET /api/v2/spot/market/fills
320
+ #
321
+ # Rate Limit: 10 times/1s (IP)
322
+ # Note: This endpoint retrieves recent trades for a trading pair
323
+ #
324
+ # @param symbol [String] Required. Trading pair name e.g. BTCUSDT
325
+ # @param limit [Integer] Optional. Number of trades to return (default: 100)
326
+ # @return [Hash] Response containing:
327
+ # - code [String] Response code ('00000' for success)
328
+ # - msg [String] Response message ('success' for success)
329
+ # - requestTime [Integer] Request timestamp in milliseconds
330
+ # - data [Array<Hash>] Array of trades, each with:
331
+ # - symbol [String] Trading pair name
332
+ # - tradeId [String] Trade ID
333
+ # - side [String] Trade side ('buy' or 'sell')
334
+ # - price [String] Trade price
335
+ # - size [String] Trade size
336
+ # - ts [String] Timestamp in milliseconds
337
+ def spot_market_fills(symbol:, limit: nil)
338
+ response = get(path: '/spot/market/fills', args: {symbol: symbol, limit: limit})
339
+ handle_response(response)
340
+ end
341
+
342
+ # Get Market Trades
343
+ # GET /api/v2/spot/market/fills-history
344
+ #
345
+ # Rate Limit: 10 req/sec/IP
346
+ # Note: This endpoint retrieves historical trades for a trading pair
347
+ #
348
+ # @param symbol [String] Required. Trading pair name e.g. BTCUSDT
349
+ # @param limit [Integer] Optional. Number of trades to return (default: 100)
350
+ # @param id_less_than [String] Optional. Return trades with ID less than this value
351
+ # @param start_time [Integer] Optional. Start time in Unix milliseconds
352
+ # @param end_time [Integer] Optional. End time in Unix milliseconds
353
+ # @return [Hash] Response containing:
354
+ # - code [String] Response code ('00000' for success)
355
+ # - msg [String] Response message ('success' for success)
356
+ # - requestTime [Integer] Request timestamp in milliseconds
357
+ # - data [Array<Hash>] Array of trades, each with:
358
+ # - symbol [String] Trading pair name
359
+ # - tradeId [String] Trade ID
360
+ # - side [String] Trade side ('Buy' or 'Sell')
361
+ # - price [String] Trade price
362
+ # - size [String] Trade size
363
+ # - ts [String] Timestamp in milliseconds
364
+ def spot_market_fills_history(symbol:, limit: nil, id_less_than: nil, start_time: nil, end_time: nil)
365
+ response = get(
366
+ path: '/spot/market/fills-history',
367
+ args: {
368
+ symbol: symbol,
369
+ limit: limit,
370
+ idLessThan: id_less_than,
371
+ startTime: start_time,
372
+ endTime: end_time,
373
+ }
374
+ )
375
+ handle_response(response)
376
+ end
377
+
378
+ # Trade
379
+
380
+ # Place Order
381
+ # POST /api/v2/spot/trade/place-order
382
+ #
383
+ # Rate limit: 10 requests/second/UID
384
+ # Rate limit: 1 request/second/UID for copy trading traders
385
+ # Note: This endpoint places a new order for spot trading
386
+ #
387
+ # @param symbol [String] Required. Trading pair name e.g. 'BTCUSDT'
388
+ # @param side [String] Required. Order direction: 'buy' or 'sell'
389
+ # @param order_type [String] Required. Order type:
390
+ # - limit: Limit order
391
+ # - market: Market order
392
+ # @param size [String] Required. Order size
393
+ # @param price [String] Optional. Order price, required for limit orders
394
+ # @param client_order_id [String] Optional. Client-supplied order ID
395
+ # @param force [String] Optional. Time in force:
396
+ # - gtc: Good till cancelled
397
+ # - fok: Fill or kill
398
+ # - ioc: Immediate or cancel
399
+ # - post_only: Post only
400
+ # @param stp_mode [String] Optional. Self-trade prevention mode
401
+ # @param stp_id [String] Optional. Self-trade prevention ID
402
+ # @param request_time [Integer] Optional. Request timestamp in milliseconds
403
+ # @param receive_window [Integer] Optional. Number of milliseconds after request_time the request is valid for
404
+ # @param execute_take_profit_price [String] Optional. Execute take profit price
405
+ # @param preset_stop_loss_price [String] Optional. Preset stop loss price
406
+ # @param execute_stop_loss_price [String] Optional. Execute stop loss price
407
+ # @return [Hash] Response containing:
408
+ # - code [String] Response code ('00000' for success)
409
+ # - msg [String] Response message ('success' for success)
410
+ # - requestTime [Integer] Request timestamp in milliseconds
411
+ # - data [Hash] Order details:
412
+ # - orderId [String] Order ID
413
+ # - clientOid [String] Client order ID if provided
414
+ def spot_trade_place_order(
415
+ symbol:,
416
+ side:,
417
+ order_type:,
418
+ force:,
419
+ price: nil,
420
+ size:,
421
+ client_order_id: nil,
422
+ trigger_price: nil,
423
+ tpsl_type: nil,
424
+ request_time: nil,
425
+ receive_window: nil,
426
+ stp_mode: nil,
427
+ preset_take_profit_price: nil,
428
+ execute_take_profit_price: nil,
429
+ preset_stop_loss_price: nil,
430
+ execute_stop_loss_price: nil
431
+ )
432
+ response = post(
433
+ path: '/spot/trade/place-order',
434
+ args: {
435
+ symbol: symbol,
436
+ side: side,
437
+ orderType: order_type,
438
+ force: force,
439
+ price: price,
440
+ size: size,
441
+ clientOid: client_order_id,
442
+ triggerPrice: trigger_price,
443
+ tpslType: tpsl_type,
444
+ requestTime: request_time,
445
+ receiveWindow: receive_window,
446
+ stpMode: stp_mode,
447
+ presetTakeProfitPrice: preset_take_profit_price,
448
+ executeTakeProfitPrice: execute_take_profit_price,
449
+ presetStopLossPrice: preset_stop_loss_price,
450
+ executeStopLossPrice: execute_stop_loss_price,
451
+ }
452
+ )
453
+ handle_response(response)
454
+ end
455
+
456
+ # Cancel an Existing Order and Send a New Order
457
+ # POST /api/v2/spot/trade/cancel-replace-order
458
+ #
459
+ # Rate Limit: Rate limit: 5 requests/second/UID
460
+ # Note: This endpoint cancels an existing order and places a new one atomically
461
+ #
462
+ # @param symbol [String] Required. Trading pair name e.g. 'BTCUSDT'
463
+ # @param price [String] Required. Price for the new order
464
+ # @param size [String] Required. Size for the new order
465
+ # @param client_order_id [String] Optional. Client order ID of the order to cancel
466
+ # @param order_id [String] Optional. Order ID of the order to cancel
467
+ # Note: Either client_order_id or order_id must be provided
468
+ # @param new_client_order_id [String] Optional. Client order ID for the new order
469
+ # @param preset_take_profit_price [String] Optional. Preset take profit price
470
+ # @param execute_take_profit_price [String] Optional. Execute take profit price
471
+ # @param preset_stop_loss_price [String] Optional. Preset stop loss price
472
+ # @param execute_stop_loss_price [String] Optional. Execute stop loss price
473
+ # @return [Hash] Response containing:
474
+ # - code [String] Response code ('00000' for success)
475
+ # - msg [String] Response message ('success' for success)
476
+ # - requestTime [Integer] Request timestamp in milliseconds
477
+ # - data [Hash] Order details:
478
+ # - orderId [String] Order ID
479
+ # - clientOid [String] Client order ID if provided
480
+ # - success [String] Operation result ('success' or 'failure')
481
+ # - msg [String] Additional message about the operation
482
+ def spot_trade_cancel_replace_order(
483
+ symbol:,
484
+ price:,
485
+ size:,
486
+ client_order_id: nil,
487
+ order_id: nil,
488
+ new_client_order_id: nil,
489
+ preset_take_profit_price: nil,
490
+ execute_take_profit_price: nil,
491
+ preset_stop_loss_price: nil,
492
+ execute_stop_loss_price: nil
493
+ )
494
+ response = post(
495
+ path: '/spot/trade/cancel-replace-order',
496
+ args: {
497
+ symbol: symbol,
498
+ price: price,
499
+ size: size,
500
+ clientOid: client_order_id,
501
+ orderId: order_id,
502
+ newClientOid: new_client_order_id,
503
+ presetTakeProfitPrice: preset_take_profit_price,
504
+ executeTakeProfitPrice: execute_take_profit_price,
505
+ presetStopLossPrice: preset_stop_loss_price,
506
+ executeStopLossPrice: execute_stop_loss_price,
507
+ }
508
+ )
509
+ handle_response(response)
510
+ end
511
+
512
+ # Batch Cancel Existing Order and Send New Orders
513
+ # POST /api/v2/spot/trade/batch-cancel-replace-order
514
+ #
515
+ # Rate Limit: 5 requests/second/UID
516
+ # Note: This endpoint cancels multiple existing orders and places new ones atomically
517
+ #
518
+ # @param order_list [Array<Hash>] Collection of orders to place (max 50)
519
+ # Each order hash must contain:
520
+ # - symbol: [String] Required. Trading pair name e.g. BTCUSDT
521
+ # - price: [String] Required. Limit price
522
+ # - size: [String] Required. Order size
523
+ # - clientOid: [String] Optional. Client Order ID
524
+ # - orderId: [String] Optional. Order ID to cancel (either orderId or clientOid required)
525
+ # - newClientOid: [String] Optional. New client order ID for the replacement order
526
+ # Example order hash:
527
+ # {
528
+ # symbol: 'BTCUSDT',
529
+ # price: '25000.1',
530
+ # size: '0.01',
531
+ # orderId: '123456',
532
+ # newClientOid: 'my_new_order_1'
533
+ # }
534
+ # @return [Hash] Response containing:
535
+ # - code [String] Response code ('00000' for success)
536
+ # - msg [String] Response message ('success' for success)
537
+ # - requestTime [Integer] Request timestamp in milliseconds
538
+ # - data [Array<Hash>] Array of order results, each containing:
539
+ # - orderId [String] Order ID
540
+ # - clientOid [String] Client order ID if provided
541
+ # - success [String] Operation result ('success' or 'failure')
542
+ # - msg [String] Additional message about the operation
543
+ def spot_trade_batch_cancel_replace_order(order_list:)
544
+ response = post(path: '/spot/trade/batch-cancel-replace-order', args: {orderList: order_list})
545
+ handle_response(response)
546
+ end
547
+
548
+ # Cancel Order
549
+ # POST /api/v2/spot/trade/cancel-order
550
+ #
551
+ # Frequency limit:10 times/1s (UID)
552
+ # Note: This endpoint cancels an existing order
553
+ #
554
+ # @param symbol [String] Required. Trading pair name e.g. 'BTCUSDT'
555
+ # @param tpsl_type [String] Optional. Take profit/stop loss type: 'normal' or 'tpsl'
556
+ # @param order_id [String] Optional. Order ID to cancel
557
+ # @param client_order_id [String] Optional. Client order ID to cancel
558
+ # Note: Either order_id or client_order_id must be provided
559
+ # @return [Hash] Response containing:
560
+ # - code [String] Response code ('00000' for success)
561
+ # - message [String] Response message ('success' for success)
562
+ # - requestTime [Integer] Request timestamp in milliseconds
563
+ # - data [Hash] Order details:
564
+ # - orderId [String] Order ID
565
+ # - clientOid [String] Client order ID if provided
566
+ def spot_trade_cancel_order(symbol:, tpsl_type: nil, order_id: nil, client_order_id: nil)
567
+ response = post(
568
+ path: '/spot/trade/cancel-order',
569
+ args: {
570
+ symbol: symbol,
571
+ tpslType: tpsl_type,
572
+ orderId: order_id,
573
+ clientOid: client_order_id,
574
+ }
575
+ )
576
+ handle_response(response)
577
+ end
578
+
579
+ # Batch Place Orders
580
+ # POST /api/v2/spot/trade/batch-orders
581
+ #
582
+ # Rate limit: Frequency limit: 5 times/1s (UID)Trader frequency limit: 1 times/1s (UID)
583
+ # Note: This endpoint places multiple orders in a single request
584
+ #
585
+ # @param symbol [String] Optional. Trading pair name e.g. 'BTCUSDT'
586
+ # @param batch_mode [String] Optional. Batch mode type:
587
+ # - single: Single currency mode (symbol in orderList will be ignored)
588
+ # - multiple: Cross-currency mode
589
+ # @param order_list [Array<Hash>] Collection of orders to place (max 50)
590
+ # Each order hash must contain:
591
+ # - side: [String] Required. Order direction ('buy' or 'sell')
592
+ # - orderType: [String] Required. Order type ('limit', 'market', 'post_only', 'fok', 'ioc')
593
+ # - force: [String] Required. Time in force ('gtc', 'ioc', 'fok', 'post_only')
594
+ # - price: [String] Required for limit orders. Order price
595
+ # - size: [String] Required. Order size
596
+ # - clientOid: [String] Optional. Client order ID
597
+ # - symbol: [String] Required if batch_mode is 'multiple'. Trading pair
598
+ # Example order hash:
599
+ # {
600
+ # side: 'buy',
601
+ # orderType: 'limit',
602
+ # force: 'normal',
603
+ # price: '25000.1',
604
+ # size: '0.01',
605
+ # clientOid: 'my_order_1'
606
+ # }
607
+ # @return [Hash] Response containing:
608
+ # - code [String] Response code ('00000' for success)
609
+ # - msg [String] Response message ('success' for success)
610
+ # - requestTime [Integer] Request timestamp in milliseconds
611
+ # - data [Hash] Order results:
612
+ # - successList [Array<Hash>] Successfully placed orders:
613
+ # - orderId [String] Order ID
614
+ # - clientOid [String] Client order ID if provided
615
+ # - failureList [Array<Hash>] Failed orders (if any)
616
+ def spot_trade_batch_orders(symbol: nil, batch_mode: nil, order_list:)
617
+ response = post(
618
+ path: '/spot/trade/batch-orders',
619
+ args: {
620
+ symbol: symbol,
621
+ batchMode: batch_mode,
622
+ orderList: order_list,
623
+ }
624
+ )
625
+ handle_response(response)
626
+ end
627
+
628
+ # Batch Cancel Orders
629
+ # POST /api/v2/spot/trade/batch-cancel-order
630
+ #
631
+ # Frequency limit:10 times/1s (UID)
632
+ # Note: This endpoint cancels multiple orders in a single request
633
+ #
634
+ # @param symbol [String] Optional. Trading pair name for single currency mode
635
+ # @param batch_mode [String] Optional. Batch mode type: 'single' (default) or 'multiple'
636
+ # - single: single currency mode (symbol in orderList will be ignored)
637
+ # - multiple: cross-currency mode
638
+ # @param order_list [Array<Hash>] Required. Collection of orders to cancel
639
+ # Each order hash must contain:
640
+ # - symbol: [String] Required. Trading pair name e.g. BTCUSDT
641
+ # - orderId: [String] Optional. Order ID (either orderId or clientOid required)
642
+ # - clientOid: [String] Optional. Client Order ID (either orderId or clientOid required)
643
+ # Example order hash:
644
+ # {
645
+ # symbol: 'BTCUSDT',
646
+ # orderId: '123456',
647
+ # clientOid: 'my_order_1'
648
+ # }
649
+ # @return [Hash] Response containing:
650
+ # - code [String] Response code ('00000' for success)
651
+ # - message [String] Response message ('success' for success)
652
+ # - requestTime [Integer] Request timestamp in milliseconds
653
+ # - data [Hash] Order results:
654
+ # - successList [Array<Hash>] Successfully cancelled orders:
655
+ # - orderId [String] Order ID
656
+ # - clientOid [String] Client order ID if provided
657
+ # - failureList [Array<Hash>] Failed orders (if any):
658
+ # - orderId [String] Order ID
659
+ # - clientOid [String] Client order ID if provided
660
+ # - errorMsg [String] Error message explaining the failure
661
+ def spot_trade_batch_cancel_order(symbol: nil, batch_mode: nil, order_list:)
662
+ response = post(
663
+ path: '/spot/trade/batch-cancel-order',
664
+ args: {
665
+ symbol: symbol,
666
+ batchMode: batch_mode,
667
+ orderList: order_list,
668
+ }
669
+ )
670
+ handle_response(response)
671
+ end
672
+
673
+ # Cancel Order by Symbol
674
+ # POST /api/v2/spot/trade/cancel-symbol-order
675
+ #
676
+ # Rate Limit: Frequency limit: 5 times/1s (UID)
677
+ # Note: This endpoint cancels all orders for a specific trading pair
678
+ #
679
+ # @param symbol [String] Required. Trading pair name e.g. 'BTCUSDT'
680
+ # @return [Hash] Response containing:
681
+ # - code [String] Response code ('00000' for success)
682
+ # - msg [String] Response message ('success' for success)
683
+ # - requestTime [Integer] Request timestamp in milliseconds
684
+ # - data [Hash] Cancellation details:
685
+ # - symbol [String] Trading pair name
686
+ # - canceledList [Array<Hash>] List of cancelled orders
687
+ # - failedList [Array<Hash>] List of failed orders
688
+ def spot_trade_cancel_symbol_order(symbol:)
689
+ response = post(path: '/spot/trade/cancel-symbol-order', args: {symbol: symbol})
690
+ handle_response(response)
691
+ end
692
+
693
+ # Get Order Info
694
+ # GET /api/v2/spot/trade/orderInfo
695
+ #
696
+ # Frequency limit: 20 times/1s (UID)
697
+ # Note: This endpoint retrieves detailed information about a specific order
698
+ #
699
+ # @param order_id [String] Optional. Order ID to query
700
+ # @param client_order_id [String] Optional. Client order ID to query
701
+ # Note: Either order_id or client_order_id must be provided
702
+ # @param request_time [Integer] Optional. Current timestamp in milliseconds
703
+ # @param receive_window [Integer] Optional. The value cannot be greater than 60000
704
+ # @return [Hash] Response containing:
705
+ # - code [String] Response code ('00000' for success)
706
+ # - msg [String] Response message ('success' for success)
707
+ # - requestTime [Integer] Request timestamp in milliseconds
708
+ # - data [Array<Hash>] Array of order details, each containing:
709
+ # - userId [String] User ID
710
+ # - symbol [String] Trading pair
711
+ # - orderId [String] Order ID
712
+ # - clientOid [String] Client order ID
713
+ # - price [String] Order price
714
+ # - size [String] Order size
715
+ # - orderType [String] Order type
716
+ # - side [String] Order side ('buy' or 'sell')
717
+ # - status [String] Order status
718
+ # - priceAvg [String] Average fill price
719
+ # - baseVolume [String] Base asset volume
720
+ # - quoteVolume [String] Quote asset volume
721
+ # - enterPointSource [String] Entry point source
722
+ # - feeDetail [String] Fee details JSON string
723
+ # - orderSource [String] Order source
724
+ # - cancelReason [String] Reason for cancellation if cancelled
725
+ # - cTime [String] Creation time
726
+ # - uTime [String] Update time
727
+ def spot_trade_order_info(order_id: nil, client_order_id: nil, request_time: nil, receive_window: nil)
728
+ response = get(
729
+ path: '/spot/trade/orderInfo',
730
+ args: {
731
+ orderId: order_id,
732
+ clientOid: client_order_id,
733
+ requestTime: request_time,
734
+ receiveWindow: receive_window,
735
+ }
736
+ )
737
+ handle_response(response)
738
+ end
739
+
740
+ # Get Current Orders
741
+ # GET /api/v2/spot/trade/unfilled-orders
742
+ #
743
+ # Frequency limit: 20 times/1s (UID)
744
+ # Note: This endpoint retrieves all unfilled (open) orders for the account
745
+ #
746
+ # @param symbol [String] Optional. Trading pair name e.g. 'BTCUSDT'
747
+ # @param start_time [Integer] Optional. Start timestamp in milliseconds
748
+ # @param end_time [Integer] Optional. End timestamp in milliseconds
749
+ # @param id_less_than [String] Optional. Pagination of data to return records earlier than the requested orderId
750
+ # @param limit [Integer] Optional. Number of results per request. Maximum 100. Default 100
751
+ # @param order_id [String] Optional. Filter by order ID
752
+ # @param tpsl_type [String] Optional. Take profit/stop loss type: 'normal' or 'tpsl'
753
+ # @param request_time [Integer] Optional. Current timestamp in milliseconds
754
+ # @param receive_window [Integer] Optional. The value cannot be greater than 60000
755
+ # @return [Hash] Response containing:
756
+ # - code [String] Response code ('00000' for success)
757
+ # - message [String] Response message ('success' for success)
758
+ # - requestTime [Integer] Request timestamp in milliseconds
759
+ # - data [Array<Hash>] Array of unfilled orders, each containing:
760
+ # - userId [String] User ID
761
+ # - symbol [String] Trading pair
762
+ # - orderId [String] Order ID
763
+ # - clientOid [String] Client order ID if provided
764
+ # - priceAvg [String] Average fill price
765
+ # - size [String] Order size
766
+ # - orderType [String] Order type
767
+ # - side [String] Order side ('buy' or 'sell')
768
+ # - status [String] Order status
769
+ # - basePrice [String] Base price
770
+ # - baseVolume [String] Base asset volume
771
+ # - quoteVolume [String] Quote asset volume
772
+ # - enterPointSource [String] Entry point source
773
+ # - presetTakeProfitPrice [String] Preset take profit price
774
+ # - executeTakeProfitPrice [String] Execute take profit price
775
+ # - presetStopLossPrice [String] Preset stop loss price
776
+ # - executeStopLossPrice [String] Execute stop loss price
777
+ # - cTime [String] Creation time
778
+ # - tpslType [String] Take profit/stop loss type
779
+ # - triggerPrice [String] Trigger price
780
+ def spot_trade_unfilled_orders(symbol: nil, start_time: nil, end_time: nil, id_less_than: nil, limit: nil, order_id: nil, tpsl_type: nil, request_time: nil, receive_window: nil)
781
+ response = get(
782
+ path: '/spot/trade/unfilled-orders',
783
+ args: {
784
+ symbol: symbol,
785
+ startTime: start_time,
786
+ endTime: end_time,
787
+ idLessThan: id_less_than,
788
+ limit: limit,
789
+ orderId: order_id,
790
+ tpslType: tpsl_type,
791
+ requestTime: request_time,
792
+ receiveWindow: receive_window,
793
+ }
794
+ )
795
+ handle_response(response)
796
+ end
797
+
798
+ # Get History Orders
799
+ # GET /api/v2/spot/trade/history-orders
800
+ #
801
+ # Frequency limit: 20 times/1s (UID)
802
+ # Note: This endpoint retrieves historical orders (filled, cancelled, etc.)
803
+ #
804
+ # @param symbol [String] Optional. Trading pair name e.g. 'BTCUSDT'
805
+ # @param start_time [Integer] Optional. Start timestamp in milliseconds
806
+ # @param end_time [Integer] Optional. End timestamp in milliseconds
807
+ # @param id_less_than [String] Optional. Pagination of data to return records earlier than the requested orderId
808
+ # @param limit [Integer] Optional. Number of results per request. Maximum 100. Default 100
809
+ # @param order_id [String] Optional. Filter by order ID
810
+ # @param tpsl_type [String] Optional. Take profit/stop loss type: 'normal' or 'tpsl'
811
+ # @param request_time [Integer] Optional. Current timestamp in milliseconds
812
+ # @param receive_window [Integer] Optional. The value cannot be greater than 60000
813
+ # @return [Hash] Response containing:
814
+ # - code [String] Response code ('00000' for success)
815
+ # - message [String] Response message ('success' for success)
816
+ # - requestTime [Integer] Request timestamp in milliseconds
817
+ # - data [Array<Hash>] Array of historical orders, each containing:
818
+ # - userId [String] User ID
819
+ # - symbol [String] Trading pair
820
+ # - orderId [String] Order ID
821
+ # - clientOid [String] Client order ID if provided
822
+ # - price [String] Order price
823
+ # - size [String] Order size
824
+ # - orderType [String] Order type
825
+ # - side [String] Order side ('buy' or 'sell')
826
+ # - status [String] Order status
827
+ # - priceAvg [String] Average fill price
828
+ # - baseVolume [String] Base asset volume
829
+ # - quoteVolume [String] Quote asset volume
830
+ # - enterPointSource [String] Entry point source
831
+ # - feeDetail [String] Fee details JSON string
832
+ # - orderSource [String] Order source
833
+ # - cTime [String] Creation time
834
+ # - uTime [String] Update time
835
+ # - tpslType [String] Take profit/stop loss type
836
+ # - cancelReason [String] Reason for cancellation if cancelled
837
+ # - triggerPrice [String] Trigger price
838
+ def spot_trade_history_orders(symbol: nil, start_time: nil, end_time: nil, id_less_than: nil, limit: nil, order_id: nil, tpsl_type: nil, request_time: nil, receive_window: nil)
839
+ response = get(
840
+ path: '/spot/trade/history-orders',
841
+ args: {
842
+ symbol: symbol,
843
+ startTime: start_time,
844
+ endTime: end_time,
845
+ idLessThan: id_less_than,
846
+ limit: limit,
847
+ orderId: order_id,
848
+ tpslType: tpsl_type,
849
+ requestTime: request_time,
850
+ receiveWindow: receive_window,
851
+ }
852
+ )
853
+ handle_response(response)
854
+ end
855
+
856
+ # Get Fills
857
+ # GET /api/v2/spot/trade/fills
858
+ #
859
+ # Frequency limit:10 times/1s (UID)
860
+ # Note: This endpoint retrieves trade execution details for orders
861
+ #
862
+ # @param symbol [String] Optional. Trading pair name e.g. 'BTCUSDT'
863
+ # @param order_id [String] Optional. Filter by order ID
864
+ # @param start_time [Integer] Optional. Start timestamp in milliseconds
865
+ # @param end_time [Integer] Optional. End timestamp in milliseconds
866
+ # @param limit [Integer] Optional. Number of results per request. Maximum 100. Default 100
867
+ # @param id_less_than [String] Optional. Pagination of data to return records earlier than the requested fillId
868
+ # @return [Hash] Response containing:
869
+ # - code [String] Response code ('00000' for success)
870
+ # - msg [String] Response message ('success' for success)
871
+ # - requestTime [Integer] Request timestamp in milliseconds
872
+ # - data [Array<Hash>] Array of fills, each containing:
873
+ # - userId [String] User ID
874
+ # - symbol [String] Trading pair
875
+ # - orderId [String] Order ID
876
+ # - tradeId [String] Trade ID
877
+ # - orderType [String] Order type
878
+ # - side [String] Trade side ('buy' or 'sell')
879
+ # - priceAvg [String] Average fill price
880
+ # - size [String] Fill size
881
+ # - amount [String] Fill amount
882
+ # - feeDetail [Hash] Fee details:
883
+ # - deduction [String] Fee deduction type
884
+ # - feeCoin [String] Fee currency
885
+ # - totalDeductionFee [String] Total deduction fee
886
+ # - totalFee [String] Total fee
887
+ # - tradeScope [String] Trade scope (e.g. 'taker')
888
+ # - cTime [String] Creation time
889
+ # - uTime [String] Update time
890
+ def spot_trade_fills(symbol: nil, order_id: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil)
891
+ response = get(
892
+ path: '/spot/trade/fills',
893
+ args: {
894
+ symbol: symbol,
895
+ orderId: order_id,
896
+ startTime: start_time,
897
+ endTime: end_time,
898
+ limit: limit,
899
+ idLessThan: id_less_than,
900
+ }
901
+ )
902
+ handle_response(response)
903
+ end
904
+
905
+ # Trigger
906
+
907
+ # Place Plan Order
908
+ # POST /api/v2/spot/trade/place-plan-order
909
+ #
910
+ # Frequency limit: 20 times/1s (UID)
911
+ # Note: This endpoint places a trigger/plan order that executes when price conditions are met
912
+ #
913
+ # @param symbol [String] Required. Trading pair name e.g. 'BTCUSDT'
914
+ # @param side [String] Required. Order direction: 'buy' or 'sell'
915
+ # @param trigger_price [String] Required. Price to trigger the order
916
+ # @param order_type [String] Required. Order type: 'limit' or 'market'
917
+ # @param execute_price [String] Optional. Order execution price (required for limit orders)
918
+ # @param plan_type [String] Optional. Plan type: 'limit' or 'market'
919
+ # @param size [String] Required. Order quantity
920
+ # @param trigger_type [String] Optional. Trigger type: 'mark_price' or 'market_price'
921
+ # @param client_order_id [String] Optional. Client-supplied order ID
922
+ # @param stp_mode [String] Optional. STP mode: 'cancel_maker', 'cancel_taker', or 'cancel_both'
923
+ # @return [Hash] Response containing:
924
+ # - code [String] Response code ('00000' for success)
925
+ # - msg [String] Response message ('success' for success)
926
+ # - requestTime [Integer] Request timestamp in milliseconds
927
+ # - data [Hash] Order details containing:
928
+ # - orderId [String] Plan order ID
929
+ # - clientOid [String] Client order ID if provided
930
+ def spot_trade_place_plan_order(symbol:, side:, trigger_price:, order_type:, execute_price: nil, plan_type: nil, size: nil, trigger_type: nil, client_order_id: nil, stp_mode: nil)
931
+ response = post(
932
+ path: '/spot/trade/place-plan-order',
933
+ args: {
934
+ symbol: symbol,
935
+ side: side,
936
+ triggerPrice: trigger_price,
937
+ orderType: order_type,
938
+ executePrice: execute_price,
939
+ planType: plan_type,
940
+ size: size,
941
+ triggerType: trigger_type,
942
+ clientOid: client_order_id,
943
+ stpMode: stp_mode,
944
+ }
945
+ )
946
+ handle_response(response)
947
+ end
948
+
949
+ # Modify Plan Order
950
+ # POST /api/v2/spot/trade/modify-plan-order
951
+ #
952
+ # Frequency limit: 20 times/1s (UID)
953
+ # Note: This endpoint modifies an existing trigger/plan order
954
+ #
955
+ # @param order_id [String] Required. Order ID to modify
956
+ # @param trigger_price [String] Optional. New trigger price
957
+ # @param execute_price [String] Optional. New execution price
958
+ # @param size [String] Optional. New order quantity
959
+ # @param order_type [String] Optional. Order type: 'limit' or 'market'
960
+ # @return [Hash] Response containing:
961
+ # - code [String] Response code ('00000' for success)
962
+ # - msg [String] Response message ('success' for success)
963
+ # - requestTime [Integer] Request timestamp in milliseconds
964
+ # - data [Hash] Order details containing:
965
+ # - orderId [String] Plan order ID
966
+ # - clientOid [String] Client order ID if provided
967
+ def spot_trade_modify_plan_order(order_id:, trigger_price: nil, execute_price: nil, size: nil, order_type: nil)
968
+ response = post(
969
+ path: '/spot/trade/modify-plan-order',
970
+ args: {
971
+ orderId: order_id,
972
+ triggerPrice: trigger_price,
973
+ executePrice: execute_price,
974
+ size: size,
975
+ orderType: order_type,
976
+ }
977
+ )
978
+ handle_response(response)
979
+ end
980
+
981
+ # Cancel Plan Order
982
+ # POST /api/v2/spot/trade/cancel-plan-order
983
+ #
984
+ # Frequency limit: 20 times/1s (UID)
985
+ # Note: This endpoint cancels an existing trigger/plan order
986
+ #
987
+ # @param order_id [String] Required. Plan order ID to cancel
988
+ # @return [Hash] Response containing:
989
+ # - code [String] Response code ('00000' for success)
990
+ # - msg [String] Response message ('success' for success)
991
+ # - requestTime [Integer] Request timestamp in milliseconds
992
+ # - data [Hash] Cancellation result containing:
993
+ # - result [String] Cancellation result ('success' if successful)
994
+ def spot_trade_cancel_plan_order(order_id:)
995
+ response = post(
996
+ path: '/spot/trade/cancel-plan-order',
997
+ args: {orderId: order_id}
998
+ )
999
+ handle_response(response)
1000
+ end
1001
+
1002
+ # Get Current Plan Orders
1003
+ # GET /api/v2/spot/trade/current-plan-order
1004
+ #
1005
+ # Frequency limit: 20 times/1s (UID)
1006
+ # Note: This endpoint retrieves all active trigger/plan orders
1007
+ #
1008
+ # @param symbol [String] Required. Trading pair name e.g. 'BTCUSDT'
1009
+ # @param order_type [String] Optional. Order type: 'limit' or 'market'
1010
+ # @param side [String] Optional. Order direction: 'buy' or 'sell'
1011
+ # @param start_time [Integer] Optional. Start time in Unix milliseconds
1012
+ # @param end_time [Integer] Optional. End time in Unix milliseconds
1013
+ # @param limit [Integer] Optional. Number of results per request. Maximum 100. Default 100
1014
+ # @return [Hash] Response containing:
1015
+ # - code [String] Response code ('00000' for success)
1016
+ # - msg [String] Response message ('success' for success)
1017
+ # - requestTime [Integer] Request timestamp in milliseconds
1018
+ # - data [Hash] Order list details containing:
1019
+ # - nextFlag [Boolean] Whether there are more orders to fetch
1020
+ # - idLessThan [String] ID to use for pagination
1021
+ # - orderList [Array<Hash>] List of plan orders
1022
+ def spot_trade_current_plan_order(symbol:, order_type: nil, side: nil, start_time: nil, end_time: nil, limit: nil)
1023
+ response = get(
1024
+ path: '/spot/trade/current-plan-order',
1025
+ args: {
1026
+ symbol: symbol,
1027
+ orderType: order_type,
1028
+ side: side,
1029
+ startTime: start_time,
1030
+ endTime: end_time,
1031
+ limit: limit,
1032
+ }
1033
+ )
1034
+ handle_response(response)
1035
+ end
1036
+
1037
+ # Get Plan Sub Order
1038
+ # GET /api/v2/spot/trade/plan-sub-order
1039
+ #
1040
+ # Frequency limit: 20 times/1s (UID)
1041
+ # Note: This endpoint retrieves the executed sub-orders of a trigger/plan order
1042
+ #
1043
+ # @param order_id [String] Required. Plan order ID to query
1044
+ # @return [Hash] Response containing:
1045
+ # - code [String] Response code ('00000' for success)
1046
+ # - msg [String] Response message ('success' for success)
1047
+ # - requestTime [Integer] Request timestamp in milliseconds
1048
+ # - data [Array<Hash>] List of sub-orders, each containing:
1049
+ # - orderId [String] Sub-order ID
1050
+ # - price [String] Order price
1051
+ # - type [String] Order type
1052
+ # - status [String] Order status
1053
+ def spot_trade_plan_sub_order(order_id:)
1054
+ response = get(
1055
+ path: '/spot/trade/plan-sub-order',
1056
+ args: {orderId: order_id}
1057
+ )
1058
+ handle_response(response)
1059
+ end
1060
+
1061
+ # Get History Plan Orders
1062
+ # GET /api/v2/spot/trade/history-plan-order
1063
+ #
1064
+ # Frequency limit: 20 times/1s (UID)
1065
+ # Note: This endpoint retrieves historical trigger/plan orders (executed, cancelled, etc.)
1066
+ #
1067
+ # @param symbol [String] Required. Trading pair name e.g. 'BTCUSDT'
1068
+ # @param start_time [Integer] Required. Start time in Unix milliseconds
1069
+ # @param end_time [Integer] Required. End time in Unix milliseconds
1070
+ # @param limit [Integer] Optional. Number of results per request. Maximum 100. Default 100
1071
+ # @return [Hash] Response containing:
1072
+ # - code [String] Response code ('00000' for success)
1073
+ # - msg [String] Response message ('success' for success)
1074
+ # - requestTime [Integer] Request timestamp in milliseconds
1075
+ # - data [Hash] Order list details containing:
1076
+ # - nextFlag [Boolean] Whether there are more orders to fetch
1077
+ # - idLessThan [String] ID to use for pagination
1078
+ # - orderList [Array<Hash>] List of historical orders, each containing:
1079
+ # - orderId [String] Plan order ID
1080
+ # - clientOid [String] Client order ID if provided
1081
+ # - symbol [String] Trading pair
1082
+ # - size [String] Order size
1083
+ # - executePrice [String] Execution price
1084
+ # - triggerPrice [String] Trigger price
1085
+ # - status [String] Order status
1086
+ # - orderType [String] Order type
1087
+ # - side [String] Order side ('buy' or 'sell')
1088
+ # - planType [String] Plan type
1089
+ # - triggerType [String] Trigger type
1090
+ # - enterPointSource [String] Entry point source
1091
+ # - uTime [String] Update time
1092
+ # - cTime [String] Creation time
1093
+ def spot_trade_history_plan_order(symbol:, start_time:, end_time:, limit: nil)
1094
+ response = get(
1095
+ path: '/spot/trade/history-plan-order',
1096
+ args: {
1097
+ symbol: symbol,
1098
+ startTime: start_time,
1099
+ endTime: end_time,
1100
+ limit: limit,
1101
+ }
1102
+ )
1103
+ handle_response(response)
1104
+ end
1105
+
1106
+ # Cancel Plan Orders in Batch
1107
+ # POST /api/v2/spot/trade/batch-cancel-plan-order
1108
+ #
1109
+ # Rate limit: 5 req/sec/UID
1110
+ # Note: This endpoint cancels all trigger/plan orders for the specified trading pairs
1111
+ #
1112
+ # @param symbol_list [Array<String>] Required. List of trading pair names e.g. ['BTCUSDT', 'ETHUSDT']
1113
+ # @return [Hash] Response containing:
1114
+ # - code [String] Response code ('00000' for success)
1115
+ # - msg [String] Response message ('success' for success)
1116
+ # - requestTime [Integer] Request timestamp in milliseconds
1117
+ # - data [Hash] Cancellation results containing:
1118
+ # - successList [Array<String>] List of successfully cancelled order IDs
1119
+ # - failureList [Array<String>] List of failed order IDs
1120
+ def spot_trade_batch_cancel_plan_order(symbol_list:)
1121
+ response = post(
1122
+ path: '/spot/trade/batch-cancel-plan-order',
1123
+ args: {symbolList: symbol_list}
1124
+ )
1125
+ handle_response(response)
1126
+ end
1127
+
1128
+ # Account
1129
+
52
1130
  # Get Account Information
53
1131
  # GET /api/v2/spot/account/info
1132
+ #
1133
+ # Frequency limit: 1 time/1s (User ID)
1134
+ # Note: This endpoint retrieves basic information about the user's spot account
1135
+ #
1136
+ # @return [Hash] Response containing:
1137
+ # - code [String] Response code ('00000' for success)
1138
+ # - msg [String] Response message ('success' for success)
1139
+ # - requestTime [Integer] Request timestamp in milliseconds
1140
+ # - data [Hash] Account information containing:
1141
+ # - userId [String] User ID
1142
+ # - inviterId [String, nil] Inviter's ID if any
1143
+ # - channelCode [String] Channel code
1144
+ # - channel [String] Channel name
1145
+ # - ips [String] IP addresses
1146
+ # - authorities [Array<String>] List of user authorities
1147
+ # - parentId [Integer] Parent account ID
1148
+ # - traderType [String] Trader type
1149
+ # - regisTime [String] Registration time in milliseconds
54
1150
  def spot_account_info
55
1151
  response = get(path: '/spot/account/info')
56
1152
  handle_response(response)
@@ -58,17 +1154,685 @@ module Bitget
58
1154
 
59
1155
  # Get Account Assets
60
1156
  # GET /api/v2/spot/account/assets
61
- def spot_account_assets(**args)
62
- response = get(path: '/spot/account/assets', args: args)
1157
+ #
1158
+ # Frequency limit: 10 times/1s (User ID)
1159
+ # Note: This endpoint retrieves detailed balance information for all assets in the spot account
1160
+ #
1161
+ # @param coin [String] Optional. Cryptocurrency code e.g. 'BTC'
1162
+ # @param asset_type [String] Optional. Type of asset
1163
+ # @return [Hash] Response containing:
1164
+ # - code [String] Response code ('00000' for success)
1165
+ # - msg [String] Response message ('success' for success)
1166
+ # - requestTime [Integer] Request timestamp in milliseconds
1167
+ # - data [Array<Hash>] List of account assets with the following fields:
1168
+ # - coin [String] The coin symbol
1169
+ # - available [String] Available balance
1170
+ # - limitAvailable [String] Limit available balance
1171
+ # - frozen [String] Frozen balance
1172
+ # - locked [String] Locked balance
1173
+ # - uTime [String] Last update time in Unix milliseconds
1174
+ def spot_account_assets(coin: nil, asset_type: nil)
1175
+ response = get(
1176
+ path: '/spot/account/assets',
1177
+ args: {
1178
+ coin: coin,
1179
+ assetType: asset_type,
1180
+ }
1181
+ )
1182
+ handle_response(response)
1183
+ end
1184
+
1185
+ # Get Sub-accounts Assets
1186
+ # GET /api/v2/spot/account/subaccount-assets
1187
+ #
1188
+ # Frequency limit: 10 times/1s (User ID)
1189
+ # Note: This endpoint retrieves asset information for all sub-accounts
1190
+ # Returns only sub-accounts which have assets > 0
1191
+ # Note: ND Brokers are not allowed to call this endpoint
1192
+ #
1193
+ # @param id_less_than [String] Optional.
1194
+ # @param limit [String] Optional.
1195
+ # @return [Hash] Response hash
1196
+ # * code [String] Response code, '00000' means success
1197
+ # * msg [String] Response message
1198
+ # * requestTime [Integer] Request timestamp
1199
+ # * data [Array<Hash>] List of assets
1200
+ # * id [Integer] Sub-account ID
1201
+ # * userId [Integer] User ID of the sub-account
1202
+ # * assetsList [Array<Hash>] List of assets
1203
+ # * coin [String] Currency name
1204
+ # * available [String] Available balance
1205
+ # * limitAvailable [String] Limited available balance
1206
+ # * frozen [String] Frozen balance
1207
+ # * locked [String] Locked balance
1208
+ # * uTime [String] Last update time in Unix milliseconds
1209
+ def spot_account_subaccount_assets(id_less_than: nil, limit: nil)
1210
+ response = get(path: '/spot/account/subaccount-assets',
1211
+ args: {
1212
+ idLessThan: id_less_than,
1213
+ limit: limit
1214
+ }
1215
+ )
1216
+ handle_response(response)
1217
+ end
1218
+
1219
+ # Modify Deposit Account
1220
+ # POST /api/v2/spot/wallet/modify-deposit-account
1221
+ #
1222
+ # Frequency limit:10 times/1s (User ID)
1223
+ # Note: This endpoint modifies the deposit account type for a specific cryptocurrency
1224
+ #
1225
+ # @param account_type [String] Required. Account type. Valid values:
1226
+ # - 'spot': Spot account
1227
+ # - 'funding': Funding account
1228
+ # - 'coin-futures': Coin-M futures account
1229
+ # - 'mix_usdt': USDT-M futures account
1230
+ # - 'usdc-futures': USDC-M futures account
1231
+ # @param coin [String] Required. The cryptocurrency code e.g. 'BTC', 'USDT'
1232
+ # @return [Hash] Response containing:
1233
+ # - code [String] Response code, '00000' means success
1234
+ # - msg [String] Response message
1235
+ # - requestTime [Integer] Request timestamp
1236
+ # - data [String] 'success' if successful
1237
+ def spot_wallet_modify_deposit_account(account_type:, coin:)
1238
+ response = post(
1239
+ path: '/spot/wallet/modify-deposit-account',
1240
+ args: {
1241
+ accountType: account_type,
1242
+ coin: coin,
1243
+ }
1244
+ )
1245
+ handle_response(response)
1246
+ end
1247
+
1248
+ # Get Account Bills
1249
+ # GET /api/v2/spot/account/bills
1250
+ #
1251
+ # Frequency limit: 10 times/1s (User ID)
1252
+ # Note: This endpoint retrieves the account's transaction history including deposits, withdrawals, trades, etc.
1253
+ #
1254
+ # @param coin [String] Optional coin name
1255
+ # @param group_type [String] Optional group type (e.g., 'transaction', 'withdraw', 'transfer', 'other')
1256
+ # @param business_type [String] Optional business type (e.g., 'ORDER_DEALT_FROZEN_OUT', 'ORDER_DEALT_IN', 'WITHDRAW', 'TRANSFER_IN')
1257
+ # @param start_time [Integer] Optional start time
1258
+ # @param end_time [Integer] Optional end time
1259
+ # @param limit [Integer] Optional limit
1260
+ # @param id_less_than [Integer] Optional filter for records with ID less than this value
1261
+ #
1262
+ # @return [Hash] Response hash
1263
+ # * code [String] Response code, '00000' means success
1264
+ # * msg [String] Response message
1265
+ # * requestTime [Integer] Request timestamp
1266
+ # * data [Array<Hash>] List of bills
1267
+ # * cTime [String] Creation timestamp in Unix milliseconds
1268
+ # * coin [String] Currency name
1269
+ # * groupType [String] Group type (e.g., 'transaction', 'withdraw', 'transfer', 'other')
1270
+ # * businessType [String] Business type (e.g., 'ORDER_DEALT_FROZEN_OUT', 'ORDER_DEALT_IN', 'WITHDRAW', 'TRANSFER_IN')
1271
+ # * size [String] Transaction size/amount
1272
+ # * balance [String] Account balance after transaction
1273
+ # * fees [String] Transaction fees
1274
+ # * billId [String] Bill ID
1275
+ # * bizOrderId [String] Business order ID
1276
+ def spot_account_bills(coin: nil, group_type: nil, business_type: nil, start_time: nil, end_time: nil, limit: nil, id_less_than: nil)
1277
+ response = get(
1278
+ path: '/spot/account/bills',
1279
+ args: {
1280
+ coin: coin,
1281
+ groupType: group_type,
1282
+ businessType: business_type,
1283
+ startTime: start_time,
1284
+ endTime: end_time,
1285
+ limit: limit,
1286
+ idLessThan: id_less_than,
1287
+ }
1288
+ )
1289
+ handle_response(response)
1290
+ end
1291
+
1292
+ # Transfer
1293
+ # POST /api/v2/spot/wallet/transfer
1294
+ #
1295
+ # RRate limit: 10 requests/second/UID
1296
+ # Note: This endpoint transfers assets between different account types within Bitget
1297
+ # Note: Only available for main accounts, not sub-accounts
1298
+ #
1299
+ # @param from_type [String] Required. Source account type. Valid values:
1300
+ # - 'spot': Spot account
1301
+ # - 'p2p': P2P/funding account
1302
+ # - 'coin_futures': Coin-M futures account
1303
+ # - 'usdt_futures': USDT-M futures account
1304
+ # - 'usdc_futures': USDC-M futures account
1305
+ # - 'crossed_margin': Cross margin account
1306
+ # - 'isolated_margin': Isolated margin account
1307
+ # @param to_type [String] Required. Destination account type (same valid values as from_type)
1308
+ # @param amount [String] Required. Amount to transfer
1309
+ # @param coin [String] Required. Cryptocurrency code e.g. 'BTC', 'USDT'
1310
+ # @param symbol [String] Required. Trading pair symbol e.g. 'BTCUSDT'
1311
+ # @param client_order_id [String] Optional. Client-supplied order ID
1312
+ # @return [Hash] Response containing:
1313
+ # - transferId [String] Transfer ID assigned by Bitget
1314
+ # - clientOid [String] Client-supplied order ID
1315
+ def spot_wallet_transfer(from_type:, to_type:, amount:, coin:, symbol:, client_order_id: nil)
1316
+ response = post(
1317
+ path: '/spot/wallet/transfer',
1318
+ args: {
1319
+ fromType: from_type,
1320
+ toType: to_type,
1321
+ amount: amount,
1322
+ coin: coin,
1323
+ symbol: symbol,
1324
+ clientOid: client_order_id,
1325
+ }
1326
+ )
1327
+ handle_response(response)
1328
+ end
1329
+
1330
+ # GET Transferable Coin List
1331
+ # GET /api/v2/spot/wallet/transfer-coin-info
1332
+ #
1333
+ # Frequency limit:10 times/1s (User ID)
1334
+ # Note: This endpoint retrieves the list of coins that can be transferred between specified account types
1335
+ #
1336
+ # @param from_type [String] Required. Source account type. Valid values:
1337
+ # - 'spot': Spot account
1338
+ # - 'p2p': P2P/funding account
1339
+ # - 'coin_futures': Coin-M futures account
1340
+ # - 'usdt_futures': USDT-M futures account
1341
+ # - 'usdc_futures': USDC-M futures account
1342
+ # - 'crossed_margin': Cross margin account
1343
+ # - 'isolated_margin': Isolated margin account
1344
+ # @param to_type [String] Required. Destination account type (same valid values as from_type)
1345
+ # @return [Array<Hash>] List of transferable coins with their details:
1346
+ # - coin [String] Cryptocurrency code
1347
+ # - chain [String] Blockchain network
1348
+ # - fromMin [String] Minimum transfer amount from source account
1349
+ # - toMin [String] Minimum transfer amount to destination account
1350
+ def spot_wallet_transfer_coin_info(from_type:, to_type:)
1351
+ response = get(
1352
+ path: '/spot/wallet/transfer-coin-info',
1353
+ args: {
1354
+ fromType: from_type,
1355
+ toType: to_type,
1356
+ }
1357
+ )
1358
+ handle_response(response)
1359
+ end
1360
+
1361
+ # Sub Transfer
1362
+ # POST /api/v2/spot/wallet/subaccount-transfer
1363
+ #
1364
+ # Rate limit: 10 req/sec/UID
1365
+ # Note: This endpoint requires IP whitelist. Transfer between fromUserId and toUserId
1366
+ # should have direct/brother relationship.
1367
+ #
1368
+ # @param from_type [String] Required. Source account type. Valid values:
1369
+ # - 'spot': Spot account
1370
+ # - 'p2p': P2P/funding account
1371
+ # - 'coin_futures': Coin-M futures account
1372
+ # - 'usdt_futures': USDT-M futures account
1373
+ # - 'usdc_futures': USDC-M futures account
1374
+ # - 'crossed_margin': Cross margin account
1375
+ # - 'isolated_margin': Isolated margin account
1376
+ # @param to_type [String] Required. Destination account type (same valid values as from_type)
1377
+ # @param amount [String] Required. Amount to transfer
1378
+ # @param coin [String] Required. Cryptocurrency code e.g. 'BTC', 'USDT'
1379
+ # @param symbol [String] Optional. Trading pair symbol e.g. 'BTCUSDT'
1380
+ # @param client_order_id [String] Optional. Client-supplied order ID
1381
+ # @param from_user_id [String] Optional. Source user ID. Required for cross-user transfers
1382
+ # @param to_user_id [String] Optional. Destination user ID. Required for cross-user transfers
1383
+ # @return [Hash] Response containing:
1384
+ # - code [String] Response code, '00000' means success
1385
+ # - msg [String] Response message
1386
+ # - requestTime [Integer] Request timestamp
1387
+ # - data [Hash] Response data
1388
+ # - transferId [String] Transfer ID assigned by Bitget
1389
+ # - clientOid [String] Client-supplied order ID
1390
+ def spot_wallet_subaccount_transfer(from_type:, to_type:, amount:, coin:, symbol: nil, client_order_id: nil, from_user_id: nil, to_user_id: nil)
1391
+ response = post(
1392
+ path: '/spot/wallet/subaccount-transfer',
1393
+ args: {
1394
+ fromType: from_type,
1395
+ toType: to_type,
1396
+ amount: amount,
1397
+ coin: coin,
1398
+ clientOid: client_order_id,
1399
+ fromUserId: from_user_id,
1400
+ toUserId: to_user_id,
1401
+ }
1402
+ )
1403
+ handle_response(response)
1404
+ end
1405
+
1406
+ # Withdraw
1407
+ # POST /api/v2/spot/wallet/withdrawal
1408
+ #
1409
+ # Rate limit:5 req/sec/UID
1410
+ # Note: This endpoint requires withdrawal permission and IP whitelist.
1411
+ #
1412
+ # @param coin [String] Required. Cryptocurrency code e.g. 'BTC', 'USDT'
1413
+ # @param transfer_type [String] Required. Type of withdrawal. Valid values:
1414
+ # - 'on_chain': Withdraw to external address
1415
+ # - 'internal_transfer': Internal transfer
1416
+ # @param address [String] Required. Withdrawal address
1417
+ # @param chain [String] Optional. Blockchain network e.g. 'BTC-Bitcoin', 'ETH-ERC20'
1418
+ # @param inner_to_type [String] Optional. Type of address for internal withdrawals. Valid values:
1419
+ # - 'email': Email address
1420
+ # - 'mobile': Mobile phone number
1421
+ # - 'uid': UID (default)
1422
+ # @param area_code [String] Optional. Area code for the recipient
1423
+ # @param tag [String] Optional. Memo/Tag for coins that require it
1424
+ # @param size [String] Required. Withdrawal amount
1425
+ # @param remark [String] Optional. Withdrawal remark/note
1426
+ # @param client_order_id [String] Optional. Client-supplied order ID
1427
+ # @param member_code [String] Optional. Member code
1428
+ # @param identity_type [String] Optional. Identity type
1429
+ # @param company_name [String] Optional. Company name for business accounts
1430
+ # @param first_name [String] Optional. First name for individual accounts
1431
+ # @param last_name [String] Optional. Last name for individual accounts
1432
+ # @return [Hash] Response containing:
1433
+ # - code [String] Response code, '00000' means success
1434
+ # - msg [String] Response message
1435
+ # - requestTime [Integer] Request timestamp
1436
+ # - data [Hash] Response data
1437
+ # - orderId [String] Withdrawal ID
1438
+ # - clientOid [String] Client-supplied order ID
1439
+ def spot_wallet_withdrawal(coin:, transfer_type:, address:, chain: nil, inner_to_type: nil, area_code: nil, tag: nil, size:, remark: nil, client_order_id: nil, member_code: nil, identity_type: nil, company_name: nil, first_name: nil, last_name: nil)
1440
+ response = post(
1441
+ path: '/spot/wallet/withdrawal',
1442
+ args: {
1443
+ coin: coin,
1444
+ transferType: transfer_type,
1445
+ address: address,
1446
+ chain: chain,
1447
+ innerToType: inner_to_type,
1448
+ areaCode: area_code,
1449
+ tag: tag,
1450
+ size: size,
1451
+ remark: remark,
1452
+ clientOid: client_order_id,
1453
+ memberCode: member_code,
1454
+ identityType: identity_type,
1455
+ companyName: company_name,
1456
+ firstName: first_name,
1457
+ lastName: last_name,
1458
+ }
1459
+ )
1460
+ handle_response(response)
1461
+ end
1462
+
1463
+ # Get MainSub Transfer Record
1464
+ # GET /api/v2/spot/account/sub-main-trans-record
1465
+ #
1466
+ # Rate limit: 20 req/sec/UID
1467
+ # Note: This endpoint retrieves transfer records between main and sub-accounts
1468
+ #
1469
+ # @param coin [String] Optional. Cryptocurrency code e.g. 'BTC'
1470
+ # @param role [String] Optional. Account role
1471
+ # @param subaccount_user_id [String] Optional. Sub-account user ID
1472
+ # @param start_time [Integer] Optional. Start time in Unix milliseconds
1473
+ # @param end_time [Integer] Optional. End time in Unix milliseconds
1474
+ # @param client_order_id [String] Optional. Client-supplied order ID
1475
+ # @param limit [Integer] Optional. Number of results per request. Default: 100
1476
+ # @param id_less_than [String] Optional. Filter records with ID less than this value
1477
+ # @return [Hash] Response containing:
1478
+ # - code [String] Response code, '00000' means success
1479
+ # - msg [String] Response message
1480
+ # - requestTime [Integer] Request timestamp
1481
+ # - data [Array<Hash>] List of transfer records
1482
+ # - coin [String] Cryptocurrency code
1483
+ # - status [String] Transfer status. Valid values:
1484
+ # - 'Successful': Successful
1485
+ # - 'Failed': Failed
1486
+ # - 'Processing': Processing
1487
+ # - toType [String] Destination account type
1488
+ # - fromType [String] Source account type
1489
+ # - size [String] Transfer amount
1490
+ # - ts [String] Timestamp in Unix milliseconds
1491
+ # - clientOid [String] Client order ID
1492
+ # - transferId [String] Transfer ID
1493
+ # - fromUserId [String] Source account ID
1494
+ # - toUserId [String] Target account ID
1495
+ def spot_account_sub_main_trans_record(coin: nil, role: nil, subaccount_user_id: nil, start_time: nil, end_time: nil, client_order_id: nil, limit: nil, id_less_than: nil)
1496
+ response = get(
1497
+ path: '/spot/account/sub-main-trans-record',
1498
+ args: {
1499
+ coin: coin,
1500
+ role: role,
1501
+ subUid: subaccount_user_id,
1502
+ startTime: start_time,
1503
+ endTime: end_time,
1504
+ clientOid: client_order_id,
1505
+ limit: limit,
1506
+ idLessThan: id_less_than,
1507
+ }
1508
+ )
1509
+ handle_response(response)
1510
+ end
1511
+
1512
+ # Get Transfer Record
1513
+ # GET /api/v2/spot/account/transferRecords
1514
+ #
1515
+ # Frequency limit: 20 times/1s (User ID)
1516
+ # Note: This endpoint retrieves transfer records between different account types
1517
+ #
1518
+ # @param coin [String] Optional. Cryptocurrency code e.g. 'BTC'
1519
+ # @param from_type [String] Optional. Source account type. Valid values:
1520
+ # - 'spot': Spot account
1521
+ # - 'p2p': P2P/funding account
1522
+ # - 'coin_futures': Coin-M futures account
1523
+ # - 'usdt_futures': USDT-M futures account
1524
+ # - 'usdc_futures': USDC-M futures account
1525
+ # - 'crossed_margin': Cross margin account
1526
+ # - 'isolated_margin': Isolated margin account
1527
+ # @param start_time [Integer] Optional. Start time in Unix milliseconds
1528
+ # @param end_time [Integer] Optional. End time in Unix milliseconds
1529
+ # @param client_order_id [String] Optional. Client-supplied order ID
1530
+ # @param page_number [Integer] Optional. Page number for pagination
1531
+ # @param limit [Integer] Optional. Number of results per request. Default: 100
1532
+ # @param id_less_than [String] Optional. Filter records with ID less than this value
1533
+ # @return [Hash] Response containing:
1534
+ # - code [String] Response code, '00000' means success
1535
+ # - msg [String] Response message
1536
+ # - requestTime [Integer] Request timestamp
1537
+ # - data [Array<Hash>] List of transfer records
1538
+ # - coin [String] Cryptocurrency code
1539
+ # - status [String] Transfer status. Valid values:
1540
+ # - 'Successful': Successful
1541
+ # - 'Failed': Failed
1542
+ # - 'Processing': Processing
1543
+ # - toType [String] Target account type
1544
+ # - toSymbol [String] Target symbol
1545
+ # - fromType [String] Source account type
1546
+ # - fromSymbol [String] Source symbol
1547
+ # - size [String] Transfer amount
1548
+ # - ts [String] Timestamp in Unix milliseconds
1549
+ # - clientOid [String] Client order ID
1550
+ # - transferId [String] Transfer ID
1551
+ def spot_account_transfer_records(coin: nil, from_type: nil, start_time: nil, end_time: nil, client_order_id: nil, page_number: nil, limit: nil, id_less_than: nil)
1552
+ response = get(
1553
+ path: '/spot/account/transferRecords',
1554
+ args: {
1555
+ coin: coin,
1556
+ fromType: from_type,
1557
+ startTime: start_time,
1558
+ endTime: end_time,
1559
+ clientOid: client_order_id,
1560
+ pageNum: page_number,
1561
+ limit: limit,
1562
+ idLessThan: id_less_than,
1563
+ }
1564
+ )
1565
+ handle_response(response)
1566
+ end
1567
+
1568
+ # Switch BGB Deduct
1569
+ # POST /api/v2/spot/account/switch-deduct
1570
+ #
1571
+ # Rate Limit: 1 req/sec/UID
1572
+ # Note: This endpoint enables or disables BGB fee deduction for spot trading
1573
+ #
1574
+ # @param deduct [String] Required. Whether to enable BGB fee deduction. Valid values:
1575
+ # - 'on': Enable BGB fee deduction
1576
+ # - 'off': Disable BGB fee deduction
1577
+ # @return [Hash] Response containing:
1578
+ # - code [String] Response code, '00000' means success
1579
+ # - msg [String] Response message
1580
+ # - requestTime [Integer] Request timestamp
1581
+ # - data [Hash] Response data
1582
+ # - deduct [String] Current BGB fee deduction status ('on' or 'off')
1583
+ def spot_account_switch_deduct(deduct:)
1584
+ response = post(path: '/spot/account/switch-deduct', args: {deduct: deduct})
1585
+ handle_response(response)
1586
+ end
1587
+
1588
+ # Get Deposit Address
1589
+ # GET /api/v2/spot/wallet/deposit-address
1590
+ #
1591
+ # Frequency limit: 10 times/1s (User ID)
1592
+ # Note: This endpoint retrieves the deposit address for a specific cryptocurrency
1593
+ #
1594
+ # @param coin [String] Required. Cryptocurrency code e.g. 'BTC', 'USDT'
1595
+ # @param chain [String] Optional. Blockchain network e.g. 'BTC-Bitcoin', 'ETH-ERC20'
1596
+ # @param size [Integer] Optional. Number of addresses to generate
1597
+ # @return [Hash] Response containing:
1598
+ # - code [String] Response code, '00000' means success
1599
+ # - msg [String] Response message
1600
+ # - requestTime [Integer] Request timestamp
1601
+ # - data [Hash] Response data
1602
+ # - coin [String] Cryptocurrency code
1603
+ # - chain [String] Blockchain network
1604
+ # - address [String] Deposit address
1605
+ # - tag [String, nil] Memo/Tag if required by the coin
1606
+ # - url [String] Block explorer URL
1607
+ def spot_wallet_deposit_address(coin:, chain: nil, size: nil)
1608
+ response = get(
1609
+ path: '/spot/wallet/deposit-address',
1610
+ args: {
1611
+ coin: coin,
1612
+ chain: chain,
1613
+ size: size,
1614
+ }
1615
+ )
1616
+ handle_response(response)
1617
+ end
1618
+
1619
+ # Get SubAccount Deposit Address
1620
+ # GET /api/v2/spot/wallet/subaccount-deposit-address
1621
+ #
1622
+ # Rate limit: 10 req/sec/UID
1623
+ # Note: This endpoint retrieves the deposit address for a specific cryptocurrency in a sub-account
1624
+ #
1625
+ # @param subaccount_user_id [String] Required. Sub-account user ID (uid)
1626
+ # @param coin [String] Required. Cryptocurrency code e.g. 'BTC', 'USDT'
1627
+ # @param chain [String] Optional. Blockchain network e.g. 'BTC-Bitcoin', 'ETH-ERC20'
1628
+ # @param size [Integer] Optional. Number of addresses to generate
1629
+ # @return [Hash] Response containing:
1630
+ # - code [String] Response code, '00000' means success
1631
+ # - msg [String] Response message
1632
+ # - requestTime [Integer] Request timestamp
1633
+ # - data [Hash] Response data
1634
+ # - coin [String] Cryptocurrency code
1635
+ # - chain [String] Blockchain network
1636
+ # - address [String] Deposit address
1637
+ # - tag [String, nil] Memo/Tag if required by the coin
1638
+ # - url [String] Block explorer URL
1639
+ def spot_wallet_subaccount_deposit_address(subaccount_user_id:, coin:, chain: nil, size: nil)
1640
+ response = get(
1641
+ path: '/spot/wallet/subaccount-deposit-address',
1642
+ args: {
1643
+ subUid: subaccount_user_id,
1644
+ coin: coin,
1645
+ chain: chain,
1646
+ size: size,
1647
+ }
1648
+ )
1649
+ handle_response(response)
1650
+ end
1651
+
1652
+ # Get BGB Deduct Info
1653
+ # GET /api/v2/spot/account/deduct-info
1654
+ #
1655
+ # Rate limit: 5 req/sec/UID
1656
+ # Note: This endpoint retrieves the current BGB fee deduction settings
1657
+ #
1658
+ # @return [Hash] Response containing:
1659
+ # - code [String] Response code, '00000' means success
1660
+ # - msg [String] Response message
1661
+ # - requestTime [Integer] Request timestamp
1662
+ # - data [Hash] Response data
1663
+ # - deduct [String] Current BGB fee deduction status ('on' or 'off')
1664
+ def spot_account_deduct_info
1665
+ response = get(path: '/spot/account/deduct-info')
1666
+ handle_response(response)
1667
+ end
1668
+
1669
+ # Cancel Withdrawal
1670
+ # POST /api/v2/spot/wallet/cancel-withdrawal
1671
+ #
1672
+ # Frequency limit:10 times/1s (User ID)
1673
+ # Note: This endpoint cancels a pending withdrawal request
1674
+ #
1675
+ # @param order_id [String] Required. The withdrawal order ID to cancel
1676
+ # @return [Hash] Response containing:
1677
+ # - code [String] Response code, '00000' means success
1678
+ # - msg [String] Response message
1679
+ # - requestTime [Integer] Request timestamp
1680
+ # - data [String] 'success' if withdrawal was cancelled
1681
+ def spot_wallet_cancel_withdrawal(order_id:)
1682
+ response = post(path: '/spot/wallet/cancel-withdrawal', args: {orderId: order_id})
1683
+ handle_response(response)
1684
+ end
1685
+
1686
+ # Get SubAccount Deposit Records
1687
+ # GET /api/v2/spot/wallet/subaccount-deposit-records
1688
+ #
1689
+ # Frequency limit:10 times/1s (UID)
1690
+ # Note: This endpoint retrieves deposit records for a specific sub-account
1691
+ #
1692
+ # @param subaccount_user_id [String] Required. Sub-account user ID (uid)
1693
+ # @param coin [String] Optional. Filter by cryptocurrency code e.g. 'BTC', 'USDT'
1694
+ # @param start_time [Integer] Optional. Filter by start time in milliseconds
1695
+ # @param end_time [Integer] Optional. Filter by end time in milliseconds
1696
+ # @param id_less_than [Integer] Optional. Filter by records with ID less than this value
1697
+ # @param limit [Integer] Optional. Number of records to return (default: 100, max: 500)
1698
+ # @return [Hash] Response containing:
1699
+ # - code [String] Response code, '00000' means success
1700
+ # - msg [String] Response message
1701
+ # - requestTime [Integer] Request timestamp
1702
+ # - data [Array<Hash>] List of deposit records containing:
1703
+ # - orderId [String] Record ID
1704
+ # - tradeId [String] Trade ID
1705
+ # - coin [String] Cryptocurrency code
1706
+ # - size [String] Deposit amount
1707
+ # - status [String] Deposit status (e.g. 'success')
1708
+ # - toAddress [String] Destination address
1709
+ # - dest [String] Destination type (e.g. 'on_chain')
1710
+ # - chain [String] Blockchain network
1711
+ # - fromAddress [String] Source address
1712
+ # - cTime [String] Creation timestamp
1713
+ # - uTime [String] Last update timestamp
1714
+ def spot_wallet_subaccount_deposit_records(subaccount_user_id:, coin: nil, start_time: nil, end_time: nil, id_less_than: nil, limit: nil)
1715
+ response = get(
1716
+ path: '/spot/wallet/subaccount-deposit-records',
1717
+ args: {
1718
+ subUid: subaccount_user_id,
1719
+ coin: coin,
1720
+ startTime: start_time,
1721
+ endTime: end_time,
1722
+ idLessThan: id_less_than,
1723
+ limit: limit,
1724
+ }
1725
+ )
1726
+ handle_response(response)
1727
+ end
1728
+
1729
+ # Get Withdrawal Records
1730
+ # GET /api/v2/spot/wallet/withdrawal-records
1731
+ #
1732
+ # Frequency limit:10 times/1s (User ID)
1733
+ # Note: This endpoint retrieves withdrawal records for the account
1734
+ #
1735
+ # @param coin [String] Optional. Filter by cryptocurrency code e.g. 'BTC', 'USDT'
1736
+ # @param client_order_id [String] Optional. Filter by client order ID
1737
+ # @param start_time [Integer] Required. Filter by start time in milliseconds
1738
+ # @param end_time [Integer] Optional. Filter by end time in milliseconds
1739
+ # @param id_less_than [Integer] Optional. Filter by records with ID less than this value
1740
+ # @param order_id [String] Optional. Filter by withdrawal order ID
1741
+ # @param limit [Integer] Optional. Number of records to return (default: 100, max: 500)
1742
+ # @return [Hash] Response containing:
1743
+ # - code [String] Response code, '00000' means success
1744
+ # - msg [String] Response message
1745
+ # - requestTime [Integer] Request timestamp
1746
+ # - data [Array<Hash>] List of withdrawal records containing:
1747
+ # - orderId [String] Withdrawal order ID
1748
+ # - tradeId [String] Trade ID
1749
+ # - coin [String] Cryptocurrency code
1750
+ # - dest [String] Destination type
1751
+ # - clientOid [String] Client order ID if provided
1752
+ # - type [String] Operation type (e.g. 'withdraw')
1753
+ # - tag [String] Memo/Tag if applicable
1754
+ # - size [String] Withdrawal amount
1755
+ # - fee [String] Withdrawal fee
1756
+ # - status [String] Withdrawal status (e.g. 'success')
1757
+ # - toAddress [String] Destination address
1758
+ # - fromAddress [String] Source address
1759
+ # - confirm [String] Number of confirmations
1760
+ # - chain [String] Blockchain network
1761
+ # - cTime [String] Creation timestamp
1762
+ # - uTime [String] Last update timestamp
1763
+ def spot_wallet_withdrawal_records(coin: nil, client_order_id: nil, start_time:, end_time:, id_less_than: nil, order_id: nil, limit: nil)
1764
+ response = get(
1765
+ path: '/spot/wallet/withdrawal-records',
1766
+ args: {
1767
+ coin: coin,
1768
+ clientOid: client_order_id,
1769
+ startTime: start_time,
1770
+ endTime: end_time,
1771
+ idLessThan: id_less_than,
1772
+ orderId: order_id,
1773
+ limit: limit,
1774
+ }
1775
+ )
1776
+ handle_response(response)
1777
+ end
1778
+
1779
+ # Get Deposit Records
1780
+ # GET /api/v2/spot/wallet/deposit-records
1781
+ #
1782
+ # Frequency limit:10 times/1s (UID)
1783
+ # Note: This endpoint retrieves deposit records for the account
1784
+ #
1785
+ # @param coin [String] Optional. Filter by cryptocurrency code e.g. 'BTC', 'USDT'
1786
+ # @param order_id [String] Optional. Filter by deposit order ID
1787
+ # @param start_time [Integer] Required. Filter by start time in milliseconds
1788
+ # @param end_time [Integer] Required. Filter by end time in milliseconds
1789
+ # @param id_less_than [Integer] Optional. Filter by records with ID less than this value
1790
+ # @param limit [Integer] Optional. Number of records to return (default: 100, max: 500)
1791
+ # @return [Hash] Response containing:
1792
+ # - code [String] Response code, '00000' means success
1793
+ # - msg [String] Response message
1794
+ # - requestTime [Integer] Request timestamp
1795
+ # - data [Array<Hash>] List of deposit records containing:
1796
+ # - orderId [String] Deposit order ID
1797
+ # - tradeId [String] TX ID
1798
+ # - coin [String] Cryptocurrency code
1799
+ # - type [String] 'deposit'
1800
+ # - size [String] Quantity
1801
+ # - status [String] Deposit status (e.g. 'success')
1802
+ # - toAddress [String] Chain address if dest is on_chain or UID, email, or phone number if dest is internal_transfer
1803
+ # - dest [String] Destination type (e.g. 'on_chain')
1804
+ # - chain [String] Blockchain network
1805
+ # - fromAddress [String] Chain address if dest is on_chain or UID, email, or phone number if dest is internal_transfer
1806
+ # - cTime [String] Creation timestamp
1807
+ # - uTime [String] Last update timestamp
1808
+ def spot_wallet_deposit_records(coin: nil, order_id: nil, start_time:, end_time:, id_less_than: nil, limit: nil)
1809
+ response = get(
1810
+ path: '/spot/wallet/deposit-records',
1811
+ args: {
1812
+ coin: coin,
1813
+ orderId: order_id,
1814
+ startTime: start_time,
1815
+ endTime: end_time,
1816
+ idLessThan: id_less_than,
1817
+ limit: limit,
1818
+ }
1819
+ )
63
1820
  handle_response(response)
64
1821
  end
65
1822
 
1823
+ attr_accessor\
1824
+ :api_key,
1825
+ :api_secret,
1826
+ :api_passphrase,
1827
+ :use_logging
1828
+
66
1829
  private
67
1830
 
68
- def initialize(api_key:, api_secret:, api_passphrase:)
1831
+ def initialize(api_key:, api_secret:, api_passphrase:, use_logging: false)
69
1832
  @api_key = api_key
70
1833
  @api_secret = api_secret
71
1834
  @api_passphrase = api_passphrase
1835
+ @use_logging = use_logging
72
1836
  end
73
1837
 
74
1838
  def full_path(path)
@@ -90,7 +1854,7 @@ module Bitget
90
1854
  if args.empty?
91
1855
  [timestamp, verb, full_path(path)].join
92
1856
  else
93
- query_string = args.to_parameter_string
1857
+ query_string = args.x_www_form_urlencode
94
1858
  [timestamp, verb, full_path(path), '?', query_string].join
95
1859
  end
96
1860
  when 'POST'
@@ -124,26 +1888,37 @@ module Bitget
124
1888
  !args.values.all?(&:nil?)
125
1889
  end
126
1890
 
127
- def log_request(verb:, request_string:, args:)
128
- log_string = "#{verb} #{request_string}"
1891
+ def log_request(verb:, request_string:, args:, headers:)
1892
+ log_string = "#{verb} #{request_string}\n"
129
1893
  if log_args?(args)
130
- log_string << "?#{args.x_www_form_urlencode}"
1894
+ log_string << " Args: #{args}\n"
131
1895
  end
1896
+ log_string << " Headers: #{headers}\n"
1897
+ self.class.logger.info(log_string)
1898
+ end
1899
+
1900
+ def log_response(code:, message:, body:)
1901
+ log_string = "Code: #{code}\n"
1902
+ log_string << "Message: #{message}\n"
1903
+ log_string << "Body: #{body}\n"
132
1904
  self.class.logger.info(log_string)
133
1905
  end
134
1906
 
135
1907
  def log_error(code:, message:, body:)
136
- log_string = "#{code}\n#{message}\n#{body}"
1908
+ log_string = "Code: #{code}\n"
1909
+ log_string << "Message: #{message}\n"
1910
+ log_string << "Body: #{body}\n"
137
1911
  self.class.logger.error(log_string)
138
1912
  end
139
1913
 
140
1914
  def do_request(verb:, path:, args: {})
141
- log_request(verb: verb, request_string: request_string(path), args: args)
142
- message = message(verb: verb, path: path, args: args)
1915
+ sorted_args = args.reject{|_, v| v.nil?}.sort.to_h
1916
+ message = message(verb: verb, path: path, args: sorted_args)
143
1917
  signature = signature(message)
144
1918
  headers = headers(signature)
1919
+ log_request(verb: verb, request_string: request_string(path), args: sorted_args, headers: headers) if @use_logging
145
1920
  @timestamp = nil
146
- HTTP.send(verb.to_s.downcase, request_string(path), args, headers)
1921
+ HTTP.send(verb.to_s.downcase, request_string(path), sorted_args, headers)
147
1922
  end
148
1923
 
149
1924
  def get(path:, args: {})
@@ -156,13 +1931,19 @@ module Bitget
156
1931
 
157
1932
  def handle_response(response)
158
1933
  if response.success?
159
- JSON.parse(response.body)
1934
+ parsed_body = JSON.parse(response.body)
1935
+ log_response(
1936
+ code: response.code,
1937
+ message: response.message,
1938
+ body: response.body
1939
+ ) if @use_logging
1940
+ parsed_body
160
1941
  else
161
1942
  log_error(
162
1943
  code: response.code,
163
1944
  message: response.message,
164
1945
  body: response.body
165
- )
1946
+ ) if @use_logging
166
1947
  raise Bitget::Error.new(
167
1948
  code: response.code,
168
1949
  message: response.message,