bitget 0.6.8

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