binance-connector-ruby 1.6.0 → 1.7.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.
@@ -9,13 +9,13 @@ module Binance
9
9
  # - trades
10
10
  # - orderbook
11
11
  # - etc
12
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#market-data-endpoints
12
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#market-data-endpoints
13
13
  module Market
14
14
  # Test Connectivity
15
15
  #
16
16
  # GET /api/v3/ping
17
17
  #
18
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#test-connectivity
18
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#test-connectivity
19
19
  def ping
20
20
  @session.public_request(path: '/api/v3/ping')
21
21
  end
@@ -24,7 +24,7 @@ module Binance
24
24
  #
25
25
  # GET /api/v3/time
26
26
  #
27
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#check-server-time
27
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#check-server-time
28
28
  def time
29
29
  @session.public_request(path: '/api/v3/time')
30
30
  end
@@ -36,7 +36,9 @@ module Binance
36
36
  # @option kwargs [string] :symbol
37
37
  # @option kwargs [string] :symbols
38
38
  # @option kwargs [string] :permissions
39
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#exchange-information
39
+ # @option kwargs [Boolean] :feature Controls whether the content of the permissionSets field is populated or not. Defaults to true
40
+ # @option kwargs [string] :symbolStatus Filters symbols that have this tradingStatus. Valid values: TRADING, HALT, BREAK. Cannot be used in combination with symbols or symbol.
41
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#exchange-information
40
42
  def exchange_info(symbol: nil, symbols: nil, permissions: nil)
41
43
  if symbols.is_a?(Array)
42
44
  symbols = symbols.map { |v| "%22#{v}%22" }.join(',')
@@ -59,7 +61,7 @@ module Binance
59
61
  # @param symbol [String] the symbol
60
62
  # @param kwargs [Hash]
61
63
  # @option kwargs [Integer] :limit Default 100; max 1000. Valid limits:[5, 10, 20, 50, 100, 500, 1000, 5000]
62
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#order-book
64
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#order-book
63
65
  def depth(symbol:, **kwargs)
64
66
  Binance::Utils::Validation.require_param('symbol', symbol)
65
67
 
@@ -76,7 +78,7 @@ module Binance
76
78
  # @param symbol [String] the symbol
77
79
  # @param kwargs [Hash]
78
80
  # @option kwargs [Integer] :limit Default 500; max 1000.
79
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#recent-trades-list
81
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#recent-trades-list
80
82
  def trades(symbol:, **kwargs)
81
83
  Binance::Utils::Validation.require_param('symbol', symbol)
82
84
 
@@ -96,7 +98,7 @@ module Binance
96
98
  # @param kwargs [Hash]
97
99
  # @option kwargs [Integer] :limit Default 500; max 1000.
98
100
  # @option kwargs [Integer] :fromId Trade id to fetch from. Default gets most recent trades.
99
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#old-trade-lookup
101
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#old-trade-lookup
100
102
  def historical_trades(symbol:, **kwargs)
101
103
  Binance::Utils::Validation.require_param('symbol', symbol)
102
104
 
@@ -118,7 +120,7 @@ module Binance
118
120
  # @option kwargs [Integer] :endTime Timestamp in ms to get aggregate trades until INCLUSIVE.
119
121
  # @option kwargs [Integer] :fromId Trade id to fetch from. Default gets most recent trades.
120
122
  # @option kwargs [Integer] :limit Default 500; max 1000.
121
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#compressedaggregate-trades-list
123
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#compressedaggregate-trades-list
122
124
  def agg_trades(symbol:, **kwargs)
123
125
  Binance::Utils::Validation.require_param('symbol', symbol)
124
126
 
@@ -140,8 +142,9 @@ module Binance
140
142
  # @param kwargs [Hash]
141
143
  # @option kwargs [Integer] :startTime Timestamp in ms to get aggregate trades from INCLUSIVE.
142
144
  # @option kwargs [Integer] :endTime Timestamp in ms to get aggregate trades until INCLUSIVE.
145
+ # @option kwargs [String] :timeZone Default: 0 (UTC)
143
146
  # @option kwargs [Integer] :limit Default 500; max 1000.
144
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#klinecandlestick-data
147
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#klinecandlestick-data
145
148
  def klines(symbol:, interval:, **kwargs)
146
149
  Binance::Utils::Validation.require_param('symbol', symbol)
147
150
  Binance::Utils::Validation.require_param('interval', interval)
@@ -155,6 +158,33 @@ module Binance
155
158
  )
156
159
  end
157
160
 
161
+ # UIKlines
162
+ #
163
+ # uiKlines return modified kline data, optimized for presentation of candlestick charts
164
+ #
165
+ # GET /api/v3/uiKlines
166
+ #
167
+ # @param symbol [String] the symbol
168
+ # @param interval [String] interval
169
+ # @param kwargs [Hash]
170
+ # @option kwargs [Integer] :startTime
171
+ # @option kwargs [Integer] :endTime
172
+ # @option kwargs [String] :timeZone Default: 0 (UTC)
173
+ # @option kwargs [Integer] :limit Default 500; max 1000.
174
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#uiklines
175
+ def ui_klines(symbol:, interval:, **kwargs)
176
+ Binance::Utils::Validation.require_param('symbol', symbol)
177
+ Binance::Utils::Validation.require_param('interval', interval)
178
+
179
+ @session.public_request(
180
+ path: '/api/v3/uiKlines',
181
+ params: kwargs.merge(
182
+ symbol: symbol,
183
+ interval: interval
184
+ )
185
+ )
186
+ end
187
+
158
188
  # Current Average Price
159
189
  #
160
190
  # Current average price for a symbol.
@@ -162,7 +192,7 @@ module Binance
162
192
  # GET /api/v3/avgPrice
163
193
  #
164
194
  # @param symbol [String] the symbol
165
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#current-average-price
195
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#current-average-price
166
196
  def avg_price(symbol:)
167
197
  Binance::Utils::Validation.require_param('symbol', symbol)
168
198
 
@@ -179,7 +209,7 @@ module Binance
179
209
  # GET /api/v3/ticker/24hr
180
210
  #
181
211
  # @param symbol [String] the symbol
182
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#24hr-ticker-price-change-statistics
212
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#24hr-ticker-price-change-statistics
183
213
  def ticker_24hr(symbol: nil)
184
214
  @session.public_request(
185
215
  path: '/api/v3/ticker/24hr',
@@ -187,6 +217,35 @@ module Binance
187
217
  )
188
218
  end
189
219
 
220
+ # Trading Day Ticker
221
+ #
222
+ # Price change statistics for a trading day.
223
+ #
224
+ # GET /api/v3/ticker/tradingDay
225
+ #
226
+ # @param kwargs [Hash]
227
+ # @option kwargs [string] :symbol Either symbol or symbols must be provided
228
+ # @option kwargs [string] :symbols
229
+ # @option kwargs [String] :timeZone Default: 0 (UTC)
230
+ # @option kwargs [String] :type Supported values: FULL or MINI. Default: FULL
231
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#trading-day-ticker
232
+ def ticker_trading_day(symbol: nil, symbols: nil, **kwargs)
233
+ raise Binance::DuplicatedParametersError.new('symbol', 'symbols') unless symbols.nil? || symbol.nil?
234
+
235
+ if symbols
236
+ symbols = symbols.map { |s| "\"#{s}\"" }.join(',')
237
+ symbols = { symbols: "\[#{symbols}\]".upcase }
238
+ end
239
+
240
+ @session.public_request(
241
+ path: '/api/v3/ticker/tradingDay',
242
+ params: kwargs.merge(
243
+ symbol: symbol,
244
+ symbols: symbols
245
+ )
246
+ )
247
+ end
248
+
190
249
  # Symbol Price Ticker
191
250
  #
192
251
  # Latest price for a symbol or symbols.
@@ -194,7 +253,7 @@ module Binance
194
253
  # GET /api/v3/ticker/price
195
254
  #
196
255
  # @param symbol [String] the symbol
197
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#symbol-price-ticker
256
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#symbol-price-ticker
198
257
  def ticker_price(symbol: nil)
199
258
  @session.public_request(
200
259
  path: '/api/v3/ticker/price',
@@ -209,7 +268,7 @@ module Binance
209
268
  # GET /api/v3/ticker/bookTicker
210
269
  #
211
270
  # @param symbol [String] the symbol
212
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#symbol-order-book-ticker
271
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#symbol-order-book-ticker
213
272
  def book_ticker(symbol: nil)
214
273
  @session.public_request(
215
274
  path: '/api/v3/ticker/bookTicker',
@@ -224,7 +283,7 @@ module Binance
224
283
  # GET /api/v3/ticker/bookTicker
225
284
  #
226
285
  # @param symbol [String] the symbol
227
- # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api#symbol-order-book-ticker
286
+ # @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#symbol-order-book-ticker
228
287
  def ticker(symbol: nil, symbols: nil, windowSize: '1d')
229
288
  raise Binance::DuplicatedParametersError.new('symbol', 'symbols') unless symbols.nil? || symbol.nil?
230
289
 
@@ -63,6 +63,7 @@ module Binance
63
63
  # @param kwargs [Hash]
64
64
  # @option kwargs [Boolean] :autoSubscribe true or false, default true
65
65
  # @option kwargs [String] :sourceAccount SPOT,FUND,ALL, default SPOT
66
+ # @option kwargs [String] :redeemTo SPOT,FLEXIBLE, default FLEXIBLE
66
67
  # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
67
68
  # @see https://developers.binance.com/docs/simple_earn/earn/Subscribe-Locked-Product
68
69
  def locked_subscribe(projectId:, amount:, **kwargs)
@@ -365,6 +366,25 @@ module Binance
365
366
  ))
366
367
  end
367
368
 
369
+ # Set Locked Product Redeem Option (USER_DATA)
370
+ #
371
+ # POST /sapi/v1/simple-earn/locked/setRedeemOption
372
+ #
373
+ # @param positionId [String]
374
+ # @param redeemTo [String] SPOT or FLEXIBLE
375
+ # @param kwargs [Hash]
376
+ # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
377
+ # @see https://developers.binance.com/docs/simple_earn/earn/Set-Locked-Redeem-Option
378
+ def locked_redeem_option(positionId:, redeemTo:, **kwargs)
379
+ Binance::Utils::Validation.require_param('positionId', positionId)
380
+ Binance::Utils::Validation.require_param('redeemTo', redeemTo)
381
+
382
+ @session.sign_request(:post, '/sapi/v1/simple-earn/locked/setRedeemOption', params: kwargs.merge(
383
+ positionId: positionId,
384
+ redeemTo: redeemTo
385
+ ))
386
+ end
387
+
368
388
  # Get Rate History (USER_DATA)
369
389
  #
370
390
  # GET /sapi/v1/simple-earn/flexible/history/rateHistory
@@ -124,6 +124,20 @@ module Binance
124
124
  @session.sign_request(:get, '/sapi/v3/sub-account/assets', params: kwargs.merge(email: email))
125
125
  end
126
126
 
127
+ # Query Sub-account Assets (For Master Account)(USER_DATA)
128
+ #
129
+ # GET /sapi/v4/sub-account/assets
130
+ #
131
+ # @param email [String]
132
+ # @param kwargs [Hash]
133
+ # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
134
+ # @see https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Assets-V4
135
+ def get_sub_account_assets_v4(email:, **kwargs)
136
+ Binance::Utils::Validation.require_param('email', email)
137
+
138
+ @session.sign_request(:get, '/sapi/v4/sub-account/assets', params: kwargs.merge(email: email))
139
+ end
140
+
127
141
  # Query Sub-account Spot Assets Summary (For Master Account)
128
142
  #
129
143
  # GET /sapi/v1/sub-account/spotSummary
@@ -214,6 +228,22 @@ module Binance
214
228
  ))
215
229
  end
216
230
 
231
+ # Enable Options for Sub-account(For Master Account)(USER_DATA)
232
+ #
233
+ # POST /sapi/v1/sub-account/eoptions/enable
234
+ #
235
+ # @param email [String] Sub user email
236
+ # @param kwargs [Hash]
237
+ # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
238
+ # @see https://developers.binance.com/docs/sub_account/account-management/Enable-Options-for-Sub-account
239
+ def sub_account_enable_options(email:, **kwargs)
240
+ Binance::Utils::Validation.require_param('email', email)
241
+
242
+ @session.sign_request(:post, '/sapi/v1/sub-account/eoptions/enable', params: kwargs.merge(
243
+ email: email
244
+ ))
245
+ end
246
+
217
247
  # Get Detail on Sub-account's Margin Account (For Master Account)
218
248
  #
219
249
  # GET /sapi/v1/sub-account/margin/account
@@ -313,6 +343,22 @@ module Binance
313
343
  ))
314
344
  end
315
345
 
346
+ # Query Sub-account Transaction Statistics(For Master Account)(USER_DATA)
347
+ #
348
+ # GET /sapi/v1/sub-account/transaction-statistics
349
+ #
350
+ # @param email [String] Sub user email
351
+ # @param kwargs [Hash]
352
+ # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
353
+ # @see https://developers.binance.com/docs/sub_account/account-management/Query-Sub-account-Transaction-Statistics
354
+ def sub_account_transaction_statistics(email:, **kwargs)
355
+ Binance::Utils::Validation.require_param('email', email)
356
+
357
+ @session.sign_request(:get, '/sapi/v1/sub-account/transaction-statistics', params: kwargs.merge(
358
+ email: email
359
+ ))
360
+ end
361
+
316
362
  # Futures Transfer for Sub-account(For Master Account)
317
363
  #
318
364
  # POST /sapi/v1/sub-account/futures/transfer
@@ -526,6 +572,34 @@ module Binance
526
572
  @session.sign_request(:get, '/sapi/v1/managed-subaccount/asset', params: kwargs.merge(email: email))
527
573
  end
528
574
 
575
+ # Query Managed Sub-account Margin Asset Details(For Investor Master Account)(USER_DATA)
576
+ #
577
+ # GET /sapi/v1/managed-subaccount/marginAsset
578
+ #
579
+ # @param email [String]
580
+ # @param kwargs [Hash]
581
+ # @option kwargs [String] :accountType No input or input "MARGIN" to get Cross Margin account details. Input "ISOLATED_MARGIN" to get Isolated Margin account details.
582
+ # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Margin-Asset-Details
583
+ def sub_account_margin_asset_details(email:, **kwargs)
584
+ Binance::Utils::Validation.require_param('email', email)
585
+
586
+ @session.sign_request(:get, '/sapi/v1/managed-subaccount/marginAsset', params: kwargs.merge(email: email))
587
+ end
588
+
589
+ # Query Managed Sub-account Futures Asset Details(For Investor Master Account)(USER_DATA)
590
+ #
591
+ # GET /sapi/v1/managed-subaccount/fetch-future-asset
592
+ #
593
+ # @param email [String]
594
+ # @param kwargs [Hash]
595
+ # @option kwargs [String] :accountType No input or input "USDT_FUTURE" to get UM Futures account details. Input "COIN_FUTURE" to get CM Futures account details.
596
+ # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Futures-Asset-Details
597
+ def sub_account_futures_asset_details(email:, **kwargs)
598
+ Binance::Utils::Validation.require_param('email', email)
599
+
600
+ @session.sign_request(:get, '/sapi/v1/managed-subaccount/fetch-future-asset', params: kwargs.merge(email: email))
601
+ end
602
+
529
603
  # Withdrawl assets from the managed sub-account (For Investor Master Account)
530
604
  #
531
605
  # POST /sapi/v1/managed-subaccount/withdraw
@@ -549,6 +623,105 @@ module Binance
549
623
  ))
550
624
  end
551
625
 
626
+ # Query Managed Sub Account Transfer Log(For Trading Team Master Account)(USER_DATA)
627
+ #
628
+ # GET /sapi/v1/managed-subaccount/queryTransLogForTradeParent
629
+ #
630
+ # @param email [String] Managed Sub Account Email
631
+ # @param startTime [Integer]
632
+ # @param endTime [Integer]
633
+ # @param page [Integer]
634
+ # @param limit [Integer] Limit (Max: 500)
635
+ # @param kwargs [Hash]
636
+ # @option kwargs [String] :transfers Transfer Direction (FROM/TO)
637
+ # @option kwargs [String] :transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE)
638
+ # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Master
639
+ def sub_account_transfer_log(email:, startTime:, endTime:, page:, limit:, **kwargs)
640
+ Binance::Utils::Validation.require_param('email', email)
641
+ Binance::Utils::Validation.require_param('startTime', startTime)
642
+ Binance::Utils::Validation.require_param('endTime', endTime)
643
+ Binance::Utils::Validation.require_param('page', page)
644
+ Binance::Utils::Validation.require_param('limit', limit)
645
+
646
+ @session.sign_request(:get, '/sapi/v1/managed-subaccount/queryTransLogForTradeParent', params: kwargs.merge(
647
+ email: email,
648
+ startTime: startTime,
649
+ endTime: endTime,
650
+ page: page,
651
+ limit: limit
652
+ ))
653
+ end
654
+
655
+ # Query Managed Sub Account Transfer Log (For Trading Team Sub Account)(USER_DATA)
656
+ #
657
+ # GET /sapi/v1/managed-subaccount/query-trans-log
658
+ #
659
+ # @param startTime [Integer]
660
+ # @param endTime [Integer]
661
+ # @param page [Integer]
662
+ # @param limit [Integer] Limit (Max: 500)
663
+ # @param kwargs [Hash]
664
+ # @option kwargs [String] :transfers Transfer Direction (FROM/TO)
665
+ # @option kwargs [String] :transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE)
666
+ # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
667
+ # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Sub
668
+ def sub_account_transfer_log_sub_account(startTime:, endTime:, page:, limit:, **kwargs)
669
+ Binance::Utils::Validation.require_param('startTime', startTime)
670
+ Binance::Utils::Validation.require_param('endTime', endTime)
671
+ Binance::Utils::Validation.require_param('page', page)
672
+ Binance::Utils::Validation.require_param('limit', limit)
673
+
674
+ @session.sign_request(:get, '/sapi/v1/managed-subaccount/query-trans-log', params: kwargs.merge(
675
+ startTime: startTime,
676
+ endTime: endTime,
677
+ page: page,
678
+ limit: limit
679
+ ))
680
+ end
681
+
682
+ # Query Managed Sub Account Transfer Log (For Investor Master Account)(USER_DATA)
683
+ #
684
+ # GET /sapi/v1/managed-subaccount/queryTransLogForInvestor
685
+ #
686
+ # @param email [String] Managed Sub Account Email
687
+ # @param startTime [Integer]
688
+ # @param endTime [Integer]
689
+ # @param page [Integer]
690
+ # @param limit [Integer] Limit (Max: 500)
691
+ # @param kwargs [Hash]
692
+ # @option kwargs [String] :transfers Transfer Direction (FROM/TO)
693
+ # @option kwargs [String] :transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE)
694
+ # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Investor
695
+ def sub_account_transfer_log_investor(email:, startTime:, endTime:, page:, limit:, **kwargs)
696
+ Binance::Utils::Validation.require_param('email', email)
697
+ Binance::Utils::Validation.require_param('startTime', startTime)
698
+ Binance::Utils::Validation.require_param('endTime', endTime)
699
+ Binance::Utils::Validation.require_param('page', page)
700
+ Binance::Utils::Validation.require_param('limit', limit)
701
+
702
+ @session.sign_request(:get, '/sapi/v1/managed-subaccount/queryTransLogForInvestor', params: kwargs.merge(
703
+ email: email,
704
+ startTime: startTime,
705
+ endTime: endTime,
706
+ page: page,
707
+ limit: limit
708
+ ))
709
+ end
710
+
711
+ # Query Managed Sub-account List (For Investor)(USER_DATA)
712
+ #
713
+ # GET /sapi/v1/managed-subaccount/info
714
+ #
715
+ # @param kwargs [Hash]
716
+ # @option kwargs [String] :email Status Managed sub-account email
717
+ # @option kwargs [Integer] :page Default: 1
718
+ # @option kwargs [Integer] :limit Default: 10, Max: 20
719
+ # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
720
+ # @see https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-List
721
+ def sub_account_list(**kwargs)
722
+ @session.sign_request(:get, '/sapi/v1/managed-subaccount/info', params: kwargs)
723
+ end
724
+
552
725
  # Enable or Disable IP Restriction for a Sub-account API Key (For Master Account)
553
726
  #
554
727
  # POST /sapi/v2/sub-account/subAccountApi/ipRestriction