binance-connector-ruby 1.0.1
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +224 -0
- data/lib/binance/authentication.rb +13 -0
- data/lib/binance/error.rb +28 -0
- data/lib/binance/session.rb +106 -0
- data/lib/binance/spot/blvt.rb +104 -0
- data/lib/binance/spot/bswap.rb +217 -0
- data/lib/binance/spot/c2c.rb +27 -0
- data/lib/binance/spot/fiat.rb +49 -0
- data/lib/binance/spot/futures.rb +357 -0
- data/lib/binance/spot/loan.rb +26 -0
- data/lib/binance/spot/margin.rb +676 -0
- data/lib/binance/spot/market.rb +220 -0
- data/lib/binance/spot/mining.rb +243 -0
- data/lib/binance/spot/savings.rb +269 -0
- data/lib/binance/spot/stream.rb +61 -0
- data/lib/binance/spot/subaccount.rb +553 -0
- data/lib/binance/spot/trade.rb +294 -0
- data/lib/binance/spot/wallet.rb +316 -0
- data/lib/binance/spot/websocket.rb +147 -0
- data/lib/binance/spot.rb +61 -0
- data/lib/binance/utils/faraday/custom_params_encoder.rb +78 -0
- data/lib/binance/utils/faraday/middleware/signature.rb +21 -0
- data/lib/binance/utils/faraday/middleware/timestamp.rb +20 -0
- data/lib/binance/utils/faraday/middleware.rb +4 -0
- data/lib/binance/utils/url.rb +26 -0
- data/lib/binance/utils/validation.rb +26 -0
- data/lib/binance/version.rb +5 -0
- data/lib/binance/websocket_base.rb +84 -0
- data/lib/binance.rb +5 -0
- metadata +161 -0
@@ -0,0 +1,676 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Binance
|
4
|
+
class Spot
|
5
|
+
# Margin endpoints
|
6
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-trade
|
7
|
+
module Margin
|
8
|
+
# Cross Margin Account Transfer (MARGIN)
|
9
|
+
#
|
10
|
+
# POST /sapi/v1/margin/transfer
|
11
|
+
#
|
12
|
+
# Execute transfer between spot account and cross margin account.
|
13
|
+
#
|
14
|
+
# @param asset [String]
|
15
|
+
# @param amount [Float]
|
16
|
+
# @param type [Integer]
|
17
|
+
# @param kwargs [Hash]
|
18
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
19
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#cross-margin-account-transfer-margin
|
20
|
+
def margin_transfer(asset:, amount:, type:, **kwargs)
|
21
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
22
|
+
Binance::Utils::Validation.require_param('amount', amount)
|
23
|
+
Binance::Utils::Validation.require_param('type', type)
|
24
|
+
|
25
|
+
@session.sign_request(:post, '/sapi/v1/margin/transfer', params: kwargs.merge(
|
26
|
+
asset: asset,
|
27
|
+
amount: amount,
|
28
|
+
type: type
|
29
|
+
))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Margin Account Borrow (MARGIN)
|
33
|
+
#
|
34
|
+
# POST /sapi/v1/margin/loan
|
35
|
+
#
|
36
|
+
# Apply for a loan.
|
37
|
+
#
|
38
|
+
# @param asset [String]
|
39
|
+
# @param amount [Float]
|
40
|
+
# @param kwargs [Hash]
|
41
|
+
# @option kwargs [String] :isIsolated for isolated margin or not, "TRUE", "FALSE"; default "FALSE"
|
42
|
+
# @option kwargs [String] :symbol isolated symbol
|
43
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
44
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-margin
|
45
|
+
def margin_borrow(asset:, amount:, **kwargs)
|
46
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
47
|
+
Binance::Utils::Validation.require_param('amount', amount)
|
48
|
+
|
49
|
+
@session.sign_request(:post, '/sapi/v1/margin/loan', params: kwargs.merge(
|
50
|
+
asset: asset,
|
51
|
+
amount: amount
|
52
|
+
))
|
53
|
+
end
|
54
|
+
|
55
|
+
# Margin Account Repay (MARGIN)
|
56
|
+
#
|
57
|
+
# POST /sapi/v1/margin/repay
|
58
|
+
#
|
59
|
+
# Repay loan for margin account.
|
60
|
+
#
|
61
|
+
# @param asset [String]
|
62
|
+
# @param amount [Float]
|
63
|
+
# @param kwargs [Hash]
|
64
|
+
# @option kwargs [String] :isIsolated for isolated margin or not, "TRUE", "FALSE"; default "FALSE"
|
65
|
+
# @option kwargs [String] :symbol isolated symbol
|
66
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
67
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-repay-margin
|
68
|
+
def margin_repay(asset:, amount:, **kwargs)
|
69
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
70
|
+
Binance::Utils::Validation.require_param('amount', amount)
|
71
|
+
|
72
|
+
@session.sign_request(:post, '/sapi/v1/margin/repay', params: kwargs.merge(
|
73
|
+
asset: asset,
|
74
|
+
amount: amount
|
75
|
+
))
|
76
|
+
end
|
77
|
+
|
78
|
+
# Query Margin Asset (MARKET_DATA)
|
79
|
+
#
|
80
|
+
# GET /sapi/v1/margin/asset
|
81
|
+
#
|
82
|
+
# @param asset [String]
|
83
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-asset-market_data
|
84
|
+
def margin_asset(asset:)
|
85
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
86
|
+
|
87
|
+
@session.limit_request(path: '/sapi/v1/margin/asset', params: { asset: asset })
|
88
|
+
end
|
89
|
+
|
90
|
+
# Query Margin Pair (MARKET_DATA)
|
91
|
+
#
|
92
|
+
# GET /sapi/v1/margin/pair
|
93
|
+
#
|
94
|
+
# @param symbol [String]
|
95
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-pair-market_data
|
96
|
+
def margin_pair(symbol:)
|
97
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
98
|
+
|
99
|
+
@session.limit_request(path: '/sapi/v1/margin/pair', params: { symbol: symbol })
|
100
|
+
end
|
101
|
+
|
102
|
+
# Get All Margin Assets (MARKET_DATA)
|
103
|
+
#
|
104
|
+
# GET /sapi/v1/margin/allAssets
|
105
|
+
#
|
106
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#get-all-margin-assets-market_data
|
107
|
+
def margin_all_assets
|
108
|
+
@session.limit_request(path: '/sapi/v1/margin/allAssets')
|
109
|
+
end
|
110
|
+
|
111
|
+
# Get All Margin Pairs (MARKET_DATA)
|
112
|
+
#
|
113
|
+
# GET /sapi/v1/margin/allPairs
|
114
|
+
#
|
115
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#get-all-margin-pairs-market_data
|
116
|
+
def margin_all_pairs
|
117
|
+
@session.limit_request(path: '/sapi/v1/margin/allPairs')
|
118
|
+
end
|
119
|
+
|
120
|
+
# Query Margin PriceIndex (MARKET_DATA)
|
121
|
+
#
|
122
|
+
# GET /sapi/v1/margin/priceIndex
|
123
|
+
#
|
124
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-priceindex-market_data
|
125
|
+
def margin_price_index(symbol:)
|
126
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
127
|
+
@session.limit_request(path: '/sapi/v1/margin/priceIndex', params: { symbol: symbol })
|
128
|
+
end
|
129
|
+
|
130
|
+
# Margin Account New Order (TRADE)
|
131
|
+
#
|
132
|
+
# POST /sapi/v1/margin/order
|
133
|
+
#
|
134
|
+
# @param symbol [String]
|
135
|
+
# @param side [String]
|
136
|
+
# @param type [String]
|
137
|
+
# @param kwargs [Hash]
|
138
|
+
# @option kwargs [String] :isIsolated for isolated margin or not, "TRUE", "FALSE", default "FALSE"
|
139
|
+
# @option kwargs [Float] :quantity
|
140
|
+
# @option kwargs [Float] :quoteOrderQty
|
141
|
+
# @option kwargs [Float] :price
|
142
|
+
# @option kwargs [Float] :stopPrice Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
|
143
|
+
# @option kwargs [String] :newClientOrderId
|
144
|
+
# @option kwargs [Float] :icebergQty Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
|
145
|
+
# @option kwargs [String] :newOrderRespType
|
146
|
+
# @option kwargs [String] :sideEffectType NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY; default NO_SIDE_EFFECT.
|
147
|
+
# @option kwargs [String] :timeInForce GTC,IOC,FOK
|
148
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
149
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-new-order-trade
|
150
|
+
def margin_new_order(symbol:, side:, type:, **kwargs)
|
151
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
152
|
+
Binance::Utils::Validation.require_param('side', side)
|
153
|
+
Binance::Utils::Validation.require_param('type', type)
|
154
|
+
|
155
|
+
@session.sign_request(:post, '/sapi/v1/margin/order', params: kwargs.merge(
|
156
|
+
symbol: symbol,
|
157
|
+
side: side,
|
158
|
+
type: type
|
159
|
+
))
|
160
|
+
end
|
161
|
+
|
162
|
+
# Margin Account Cancel Order (TRADE)
|
163
|
+
#
|
164
|
+
# DELETE /sapi/v1/margin/order
|
165
|
+
#
|
166
|
+
# @param symbol [String]
|
167
|
+
# @param kwargs [Hash]
|
168
|
+
# @option kwargs [String] :isIsolated for isolated margin or not, "TRUE", "FALSE", default "FALSE"
|
169
|
+
# @option kwargs [String] :orderId
|
170
|
+
# @option kwargs [String] :origClientOrderId
|
171
|
+
# @option kwargs [String] :newClientOrderId
|
172
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
173
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-new-order-trade
|
174
|
+
def margin_cancel_order(symbol:, **kwargs)
|
175
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
176
|
+
|
177
|
+
@session.sign_request(:delete, '/sapi/v1/margin/order', params: kwargs.merge(
|
178
|
+
symbol: symbol
|
179
|
+
))
|
180
|
+
end
|
181
|
+
|
182
|
+
# Margin Account Cancel all Open Orders on a Symbol (TRADE)
|
183
|
+
#
|
184
|
+
# DELETE /sapi/v1/margin/openOrders
|
185
|
+
#
|
186
|
+
# @param symbol [String]
|
187
|
+
# @param kwargs [Hash]
|
188
|
+
# @option kwargs [String] :isIsolated for isolated margin or not, "TRUE", "FALSE", default "FALSE"
|
189
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
190
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-cancel-all-open-orders-on-a-symbol-trade
|
191
|
+
def margin_cancel_all_order(symbol:, **kwargs)
|
192
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
193
|
+
|
194
|
+
@session.sign_request(:delete, '/sapi/v1/margin/openOrders', params: kwargs.merge(
|
195
|
+
symbol: symbol
|
196
|
+
))
|
197
|
+
end
|
198
|
+
|
199
|
+
# Get Cross Margin Transfer History (USER_DATA)
|
200
|
+
#
|
201
|
+
# GET /sapi/v1/margin/transfer
|
202
|
+
#
|
203
|
+
# @param kwargs [Hash]
|
204
|
+
# @option kwargs [String] :asset
|
205
|
+
# @option kwargs [String] :type
|
206
|
+
# @option kwargs [Integer] :startTime
|
207
|
+
# @option kwargs [Integer] :endTime
|
208
|
+
# @option kwargs [Integer] :current Currently querying page. Start from 1. Default:1
|
209
|
+
# @option kwargs [Integer] :size Default:10 Max:100
|
210
|
+
# @option kwargs [String] :archived Default: false. Set to true for archived data from 6 months ago
|
211
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
212
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#get-cross-margin-transfer-history-user_data
|
213
|
+
def margin_transfer_history(**kwargs)
|
214
|
+
@session.sign_request(:get, '/sapi/v1/margin/transfer', params: kwargs)
|
215
|
+
end
|
216
|
+
|
217
|
+
# Query Loan Record (USER_DATA)
|
218
|
+
#
|
219
|
+
# GET /sapi/v1/margin/loan
|
220
|
+
#
|
221
|
+
# @param asset [String]
|
222
|
+
# @param kwargs [Hash]
|
223
|
+
# @option kwargs [String] :isolatedSymbol
|
224
|
+
# @option kwargs [String] :txId
|
225
|
+
# @option kwargs [Integer] :startTime
|
226
|
+
# @option kwargs [Integer] :endTime
|
227
|
+
# @option kwargs [Integer] :current Currently querying page. Start from 1. Default:1
|
228
|
+
# @option kwargs [Integer] :size Default:10 Max:100
|
229
|
+
# @option kwargs [String] :archived Default: false. Set to true for archived data from 6 months ago
|
230
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
231
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-loan-record-user_data
|
232
|
+
def margin_load_record(asset:, **kwargs)
|
233
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
234
|
+
|
235
|
+
@session.sign_request(:get, '/sapi/v1/margin/loan', params: kwargs.merge(asset: asset))
|
236
|
+
end
|
237
|
+
|
238
|
+
# Query Repay Record (USER_DATA)
|
239
|
+
#
|
240
|
+
# GET /sapi/v1/margin/repay
|
241
|
+
#
|
242
|
+
# @param asset [String]
|
243
|
+
# @param kwargs [Hash]
|
244
|
+
# @option kwargs [String] :isolatedSymbol
|
245
|
+
# @option kwargs [String] :txId
|
246
|
+
# @option kwargs [Integer] :startTime
|
247
|
+
# @option kwargs [Integer] :endTime
|
248
|
+
# @option kwargs [Integer] :current Currently querying page. Start from 1. Default:1
|
249
|
+
# @option kwargs [Integer] :size Default:10 Max:100
|
250
|
+
# @option kwargs [String] :archived Default: false. Set to true for archived data from 6 months ago
|
251
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
252
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-repay-record-user_data
|
253
|
+
def margin_repay_record(asset:, **kwargs)
|
254
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
255
|
+
|
256
|
+
@session.sign_request(:get, '/sapi/v1/margin/repay', params: kwargs.merge(asset: asset))
|
257
|
+
end
|
258
|
+
|
259
|
+
# Get Interest History (USER_DATA)
|
260
|
+
#
|
261
|
+
# GET /sapi/v1/margin/interestHistory
|
262
|
+
#
|
263
|
+
# @param kwargs [Hash]
|
264
|
+
# @option kwargs [String] :asset
|
265
|
+
# @option kwargs [String] :isolatedSymbol
|
266
|
+
# @option kwargs [Integer] :startTime
|
267
|
+
# @option kwargs [Integer] :endTime
|
268
|
+
# @option kwargs [Integer] :current Currently querying page. Start from 1. Default:1
|
269
|
+
# @option kwargs [Integer] :size Default:10 Max:100
|
270
|
+
# @option kwargs [String] :archived Default: false. Set to true for archived data from 6 months ago
|
271
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
272
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#get-interest-history-user_data
|
273
|
+
def margin_interest_history(**kwargs)
|
274
|
+
@session.sign_request(:get, '/sapi/v1/margin/interestHistory', params: kwargs)
|
275
|
+
end
|
276
|
+
|
277
|
+
# Get Force Liquidation Record (USER_DATA)
|
278
|
+
#
|
279
|
+
# GET /sapi/v1/margin/forceLiquidationRec
|
280
|
+
#
|
281
|
+
# @param kwargs [Hash]
|
282
|
+
# @option kwargs [String] :isolatedSymbol
|
283
|
+
# @option kwargs [Integer] :startTime
|
284
|
+
# @option kwargs [Integer] :endTime
|
285
|
+
# @option kwargs [Integer] :current Currently querying page. Start from 1. Default:1
|
286
|
+
# @option kwargs [Integer] :size Default:10 Max:100
|
287
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
288
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#get-force-liquidation-record-user_data
|
289
|
+
def margin_force_liquidation_record(**kwargs)
|
290
|
+
@session.sign_request(:get, '/sapi/v1/margin/forceLiquidationRec', params: kwargs)
|
291
|
+
end
|
292
|
+
|
293
|
+
# Query Cross Margin Account Details (USER_DATA)
|
294
|
+
#
|
295
|
+
# GET /sapi/v1/margin/account
|
296
|
+
#
|
297
|
+
# @param kwargs [Hash]
|
298
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
299
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-cross-margin-account-details-user_data
|
300
|
+
def margin_account(**kwargs)
|
301
|
+
@session.sign_request(:get, '/sapi/v1/margin/account', params: kwargs)
|
302
|
+
end
|
303
|
+
|
304
|
+
# Query Margin Account's Order (USER_DATA)
|
305
|
+
#
|
306
|
+
# GET /sapi/v1/margin/order
|
307
|
+
#
|
308
|
+
# @param symbol [String]
|
309
|
+
# @param kwargs [Hash]
|
310
|
+
# @option kwargs [String] :isIsolated for isolated margin or not, "TRUE", "FALSE", default "FALSE"
|
311
|
+
# @option kwargs [Integer] :orderId
|
312
|
+
# @option kwargs [String] :origClientOrderId
|
313
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
314
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-order-user_data
|
315
|
+
def margin_order(symbol:, **kwargs)
|
316
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
317
|
+
|
318
|
+
@session.sign_request(:get, '/sapi/v1/margin/order', params: kwargs.merge(symbol: symbol))
|
319
|
+
end
|
320
|
+
|
321
|
+
# Query Margin Account's Open Order (USER_DATA)
|
322
|
+
#
|
323
|
+
# GET /sapi/v1/margin/openOrders
|
324
|
+
#
|
325
|
+
# @param kwargs [Hash]
|
326
|
+
# @option kwargs [String] :symbol
|
327
|
+
# @option kwargs [String] :isIsolated for isolated margin or not, "TRUE", "FALSE", default "FALSE"
|
328
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
329
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-open-orders-user_data
|
330
|
+
def margin_open_orders(**kwargs)
|
331
|
+
@session.sign_request(:get, '/sapi/v1/margin/openOrders', params: kwargs)
|
332
|
+
end
|
333
|
+
|
334
|
+
# Query Margin Account's All Order (USER_DATA)
|
335
|
+
#
|
336
|
+
# GET /sapi/v1/margin/allOrders
|
337
|
+
#
|
338
|
+
# @param symbol [String]
|
339
|
+
# @param kwargs [Hash]
|
340
|
+
# @option kwargs [String] :isIsolated for isolated margin or not, "TRUE", "FALSE", default "FALSE"
|
341
|
+
# @option kwargs [String] :orderId
|
342
|
+
# @option kwargs [Integer] :startTime
|
343
|
+
# @option kwargs [Integer] :endTime
|
344
|
+
# @option kwargs [Integer] :limit Default 500; max 1000.
|
345
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
346
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-all-orders-user_data
|
347
|
+
def margin_all_orders(symbol:, **kwargs)
|
348
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
349
|
+
|
350
|
+
@session.sign_request(:get, '/sapi/v1/margin/allOrders', params: kwargs.merge(symbol: symbol))
|
351
|
+
end
|
352
|
+
|
353
|
+
# Margin Account New OCO (TRADE)
|
354
|
+
#
|
355
|
+
# POST /sapi/v1/margin/order/oco
|
356
|
+
#
|
357
|
+
# @param symbol [String]
|
358
|
+
# @param side [String]
|
359
|
+
# @param quantity [Float]
|
360
|
+
# @param price [Float]
|
361
|
+
# @param stopPrice [Float]
|
362
|
+
# @param kwargs [Hash]
|
363
|
+
# @option kwargs [String] :isIsolated for isolated margin or not, "TRUE", "FALSE", default "FALSE"
|
364
|
+
# @option kwargs [String] :listClientOrderId
|
365
|
+
# @option kwargs [String] :limitClientOrderId
|
366
|
+
# @option kwargs [Float] :limitIcebergQty
|
367
|
+
# @option kwargs [String] :stopClientOrderId
|
368
|
+
# @option kwargs [Float] :stopLimitPrice If provided, stopLimitTimeInForce is required.
|
369
|
+
# @option kwargs [Float] :stopIcebergQty
|
370
|
+
# @option kwargs [String] :stopLimitTimeInForce Valid values are GTC/FOK/IOC
|
371
|
+
# @option kwargs [String] :newOrderRespType
|
372
|
+
# @option kwargs [String] :sideEffectType NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY; default NO_SIDE_EFFECT.
|
373
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
374
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-new-oco-trade
|
375
|
+
def margin_oco_order(symbol:, side:, quantity:, price:, stopPrice:, **kwargs)
|
376
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
377
|
+
Binance::Utils::Validation.require_param('side', side)
|
378
|
+
Binance::Utils::Validation.require_param('quantity', quantity)
|
379
|
+
Binance::Utils::Validation.require_param('price', price)
|
380
|
+
Binance::Utils::Validation.require_param('stopPrice', stopPrice)
|
381
|
+
|
382
|
+
@session.sign_request(:post, '/sapi/v1/margin/order/oco', params: kwargs.merge(
|
383
|
+
symbol: symbol,
|
384
|
+
side: side,
|
385
|
+
quantity: quantity,
|
386
|
+
price: price,
|
387
|
+
stopPrice: stopPrice
|
388
|
+
))
|
389
|
+
end
|
390
|
+
|
391
|
+
# Margin Account Cancel OCO (TRADE)
|
392
|
+
#
|
393
|
+
# DELETE /sapi/v1/margin/orderList
|
394
|
+
#
|
395
|
+
# Canceling an individual leg will cancel the entire OCO
|
396
|
+
#
|
397
|
+
# @param symbol [String]
|
398
|
+
# @param kwargs [Hash]
|
399
|
+
# @option kwargs [String] :isIsolated
|
400
|
+
# @option kwargs [Integer] :orderListId Either orderListId or listClientOrderId must be provided
|
401
|
+
# @option kwargs [String] :listClientOrderId Either orderListId or listClientOrderId must be provided
|
402
|
+
# @option kwargs [String] :newClientOrderId
|
403
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
404
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#margin-account-cancel-oco-trade
|
405
|
+
def margin_cancel_oco(symbol:, **kwargs)
|
406
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
407
|
+
|
408
|
+
@session.sign_request(:delete, '/sapi/v1/margin/orderList', params: kwargs.merge(
|
409
|
+
symbol: symbol
|
410
|
+
))
|
411
|
+
end
|
412
|
+
|
413
|
+
# Query Margin Account's OCO (USER_DATA)
|
414
|
+
#
|
415
|
+
# GET /sapi/v1/margin/orderList
|
416
|
+
#
|
417
|
+
# @param kwargs [Hash]
|
418
|
+
# @option kwargs [String] :symbol
|
419
|
+
# @option kwargs [String] :isIsolated
|
420
|
+
# @option kwargs [Integer] :orderListId Either orderListId or origClientOrderId must be provided
|
421
|
+
# @option kwargs [String] :origClientOrderId Either orderListId or origClientOrderId must be provided
|
422
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
423
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-oco-user_data
|
424
|
+
def margin_get_oco(**kwargs)
|
425
|
+
@session.sign_request(:get, '/sapi/v1/margin/orderList', params: kwargs)
|
426
|
+
end
|
427
|
+
|
428
|
+
# Query Margin Account's all OCO (USER_DATA)
|
429
|
+
#
|
430
|
+
# GET /sapi/v1/margin/allOrderList
|
431
|
+
#
|
432
|
+
# @param kwargs [Hash]
|
433
|
+
# @option kwargs [String] :symbol
|
434
|
+
# @option kwargs [String] :isIsolated
|
435
|
+
# @option kwargs [Integer] :fromId If supplied, neither startTime nor endTime can be provided
|
436
|
+
# @option kwargs [Integer] :startTime
|
437
|
+
# @option kwargs [Integer] :endTime
|
438
|
+
# @option kwargs [Integer] :limit
|
439
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
440
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-all-oco-user_data
|
441
|
+
def margin_get_all_oco(**kwargs)
|
442
|
+
@session.sign_request(:get, '/sapi/v1/margin/allOrderList', params: kwargs)
|
443
|
+
end
|
444
|
+
|
445
|
+
# Query Margin Account's Open OCO (USER_DATA)
|
446
|
+
#
|
447
|
+
# GET /sapi/v1/margin/openOrderList
|
448
|
+
#
|
449
|
+
# @param kwargs [Hash]
|
450
|
+
# @option kwargs [String] :symbol
|
451
|
+
# @option kwargs [String] :isIsolated
|
452
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
453
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-open-oco-user_data
|
454
|
+
def margin_get_open_oco(**kwargs)
|
455
|
+
@session.sign_request(:get, '/sapi/v1/margin/openOrderList', params: kwargs)
|
456
|
+
end
|
457
|
+
|
458
|
+
# Query Margin Account's Trade List (USER_DATA)
|
459
|
+
#
|
460
|
+
# GET /sapi/v1/margin/myTrades
|
461
|
+
#
|
462
|
+
# @param symbol [String]
|
463
|
+
# @param kwargs [Hash]
|
464
|
+
# @option kwargs [Integer] :startTime
|
465
|
+
# @option kwargs [Integer] :endTime
|
466
|
+
# @option kwargs [String] :orderfromIdId
|
467
|
+
# @option kwargs [Integer] :limit Default 500; max 1000.
|
468
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
469
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-trade-list-user_data
|
470
|
+
def margin_my_trades(symbol:, **kwargs)
|
471
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
472
|
+
|
473
|
+
@session.sign_request(:get, '/sapi/v1/margin/myTrades', params: kwargs.merge(symbol: symbol))
|
474
|
+
end
|
475
|
+
|
476
|
+
# Query Max Borrow (USER_DATA)
|
477
|
+
#
|
478
|
+
# GET /sapi/v1/margin/maxBorrowable
|
479
|
+
#
|
480
|
+
# @param asset [String]
|
481
|
+
# @param kwargs [Hash]
|
482
|
+
# @option kwargs [String] :isolatedSymbol
|
483
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
484
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-max-borrow-user_data
|
485
|
+
def margin_max_borrowable(asset:, **kwargs)
|
486
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
487
|
+
|
488
|
+
@session.sign_request(:get, '/sapi/v1/margin/maxBorrowable', params: kwargs.merge(asset: asset))
|
489
|
+
end
|
490
|
+
|
491
|
+
# Query Max Transfer-Out Amount (USER_DATA)
|
492
|
+
#
|
493
|
+
# GET /sapi/v1/margin/maxTransferable
|
494
|
+
#
|
495
|
+
# @param asset [String]
|
496
|
+
# @param kwargs [Hash]
|
497
|
+
# @option kwargs [String] :isolatedSymbol
|
498
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
499
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-max-transfer-out-amount-user_data
|
500
|
+
def margin_max_transferable(asset:, **kwargs)
|
501
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
502
|
+
|
503
|
+
@session.sign_request(:get, '/sapi/v1/margin/maxTransferable', params: kwargs.merge(asset: asset))
|
504
|
+
end
|
505
|
+
|
506
|
+
# Isolated Margin Account Transfer (MARGIN)
|
507
|
+
#
|
508
|
+
# POST /sapi/v1/margin/isolated/transfer
|
509
|
+
#
|
510
|
+
# @param asset [String]
|
511
|
+
# @param symbol [String]
|
512
|
+
# @param transFrom [String] "SPOT", "ISOLATED_MARGIN"
|
513
|
+
# @param transTo [String] "SPOT", "ISOLATED_MARGIN"
|
514
|
+
# @param amount [Float]
|
515
|
+
# @param kwargs [Hash]
|
516
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
517
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#isolated-margin-account-transfer-margin
|
518
|
+
def isolated_margin_transfer(asset:, symbol:, transFrom:, transTo:, amount:, **kwargs)
|
519
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
520
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
521
|
+
Binance::Utils::Validation.require_param('transFrom', transFrom)
|
522
|
+
Binance::Utils::Validation.require_param('transTo', transTo)
|
523
|
+
Binance::Utils::Validation.require_param('amount', amount)
|
524
|
+
|
525
|
+
@session.sign_request(:post, '/sapi/v1/margin/isolated/transfer', params: kwargs.merge(
|
526
|
+
asset: asset,
|
527
|
+
symbol: symbol,
|
528
|
+
transFrom: transFrom,
|
529
|
+
transTo: transTo,
|
530
|
+
amount: amount
|
531
|
+
))
|
532
|
+
end
|
533
|
+
|
534
|
+
# Get Isolated Margin Transfer History (USER_DATA)
|
535
|
+
#
|
536
|
+
# GET /sapi/v1/margin/isolated/transfer
|
537
|
+
#
|
538
|
+
# @param symbol [String]
|
539
|
+
# @param kwargs [Hash]
|
540
|
+
# @option kwargs [String] :asset
|
541
|
+
# @option kwargs [String] :transFrom "SPOT", "ISOLATED_MARGIN"
|
542
|
+
# @option kwargs [String] :transTo "SPOT", "ISOLATED_MARGIN"
|
543
|
+
# @option kwargs [Integer] :startTime
|
544
|
+
# @option kwargs [Integer] :endTime
|
545
|
+
# @option kwargs [Integer] :current Current page, default 1
|
546
|
+
# @option kwargs [Integer] :size Default 10, max 100
|
547
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
548
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#get-isolated-margin-transfer-history-user_data
|
549
|
+
def get_isolated_margin_transfer(symbol:, **kwargs)
|
550
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
551
|
+
|
552
|
+
@session.sign_request(:get, '/sapi/v1/margin/isolated/transfer', params: kwargs.merge(symbol: symbol))
|
553
|
+
end
|
554
|
+
|
555
|
+
# Query Isolated Margin Account Info (USER_DATA)
|
556
|
+
#
|
557
|
+
# GET /sapi/v1/margin/isolated/account
|
558
|
+
#
|
559
|
+
# @param kwargs [Hash]
|
560
|
+
# @option kwargs [String] :symbols Max 5 symbols can be sent; separated by ",". e.g. "BTCUSDT,BNBUSDT,ADAUSDT"
|
561
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
562
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-account-info-user_data
|
563
|
+
def get_isolated_margin_account(**kwargs)
|
564
|
+
@session.sign_request(:get, '/sapi/v1/margin/isolated/account', params: kwargs)
|
565
|
+
end
|
566
|
+
|
567
|
+
# Disable Isolated Margin Account (TRADE)
|
568
|
+
#
|
569
|
+
# DELETE /sapi/v1/margin/isolated/account
|
570
|
+
#
|
571
|
+
# @param symbol [String]
|
572
|
+
# @param kwargs [Hash]
|
573
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
574
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#disable-isolated-margin-account-trade
|
575
|
+
def disable_isolated_margin_account(symbol:, **kwargs)
|
576
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
577
|
+
|
578
|
+
@session.sign_request(:delete, '/sapi/v1/margin/isolated/account', params: kwargs.merge(symbol: symbol))
|
579
|
+
end
|
580
|
+
|
581
|
+
# Enable Isolated Margin Account (TRADE)
|
582
|
+
#
|
583
|
+
# POST /sapi/v1/margin/isolated/account
|
584
|
+
#
|
585
|
+
# @param symbol [String]
|
586
|
+
# @param kwargs [Hash]
|
587
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
588
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#enable-isolated-margin-account-trade
|
589
|
+
def enable_isolated_margin_account(symbol:, **kwargs)
|
590
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
591
|
+
|
592
|
+
@session.sign_request(:post, '/sapi/v1/margin/isolated/account', params: kwargs.merge(symbol: symbol))
|
593
|
+
end
|
594
|
+
|
595
|
+
# Query Enabled Isolated Margin Account Limit (USER_DATA)
|
596
|
+
#
|
597
|
+
# GET /sapi/v1/margin/isolated/accountLimit
|
598
|
+
#
|
599
|
+
# @param kwargs [Hash]
|
600
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
601
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-enabled-isolated-margin-account-limit-user_data
|
602
|
+
def get_isolated_margin_account_limit(**kwargs)
|
603
|
+
@session.sign_request(:get, '/sapi/v1/margin/isolated/accountLimit', params: kwargs)
|
604
|
+
end
|
605
|
+
|
606
|
+
# Query Isolated Margin Symbol (USER_DATA)
|
607
|
+
#
|
608
|
+
# GET /sapi/v1/margin/isolated/pair
|
609
|
+
#
|
610
|
+
# @param symbol [String]
|
611
|
+
# @param kwargs [Hash]
|
612
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
613
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-symbol-user_data
|
614
|
+
def get_isolated_margin_pair(symbol:, **kwargs)
|
615
|
+
Binance::Utils::Validation.require_param('symbol', symbol)
|
616
|
+
|
617
|
+
@session.sign_request(:get, '/sapi/v1/margin/isolated/pair', params: kwargs.merge(symbol: symbol))
|
618
|
+
end
|
619
|
+
|
620
|
+
# Get All Isolated Margin Symbol(USER_DATA)
|
621
|
+
#
|
622
|
+
# GET /sapi/v1/margin/isolated/allPairs
|
623
|
+
#
|
624
|
+
# @param kwargs [Hash]
|
625
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
626
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#get-all-isolated-margin-symbol-user_data
|
627
|
+
def get_all_isolated_margin_pairs(**kwargs)
|
628
|
+
@session.sign_request(:get, '/sapi/v1/margin/isolated/allPairs', params: kwargs)
|
629
|
+
end
|
630
|
+
|
631
|
+
# Toggle BNB Burn On Spot Trade And Margin Interest (USER_DATA)
|
632
|
+
#
|
633
|
+
# POST /sapi/v1/bnbBurn
|
634
|
+
#
|
635
|
+
# "spotBNBBurn" and "interestBNBBurn" should be sent at least one.
|
636
|
+
#
|
637
|
+
# @param kwargs [Hash]
|
638
|
+
# @option kwargs [String] :spotBNBBurn "true" or "false"; Determines whether to use BNB to pay for trading fees on SPOT
|
639
|
+
# @option kwargs [String] :interestBNBBurn "true" or "false"; Determines whether to use BNB to pay for margin loan's interest
|
640
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
641
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#toggle-bnb-burn-on-spot-trade-and-margin-interest-user_data
|
642
|
+
def toggle_bnb_burn(**kwargs)
|
643
|
+
@session.sign_request(:post, '/sapi/v1/bnbBurn', params: kwargs)
|
644
|
+
end
|
645
|
+
|
646
|
+
# Get BNB Burn Status (USER_DATA)
|
647
|
+
#
|
648
|
+
# GET /sapi/v1/bnbBurn
|
649
|
+
#
|
650
|
+
# @param kwargs [Hash]
|
651
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
652
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#get-bnb-burn-status-user_data
|
653
|
+
def get_bnb_burn(**kwargs)
|
654
|
+
@session.sign_request(:get, '/sapi/v1/bnbBurn', params: kwargs)
|
655
|
+
end
|
656
|
+
|
657
|
+
# Query Margin Interest Rate History (USER_DATA)
|
658
|
+
#
|
659
|
+
# GET /sapi/v1/margin/interestRateHistory
|
660
|
+
#
|
661
|
+
# @param asset [String]
|
662
|
+
# @param kwargs [Hash]
|
663
|
+
# @option vipLevel [Integer] Default: user's vip level
|
664
|
+
# @option startTime [Integer] Default: 7 days ago
|
665
|
+
# @option endTime [Integer] Default: present. Maximum range: 3 months.
|
666
|
+
# @option limit [Integer] Default: 20. Maximum: 100
|
667
|
+
# @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
|
668
|
+
# @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-interest-rate-history-user_data
|
669
|
+
def get_margin_interest_rate_history(asset:, **kwargs)
|
670
|
+
Binance::Utils::Validation.require_param('asset', asset)
|
671
|
+
|
672
|
+
@session.sign_request(:get, '/sapi/v1/margin/interestRateHistory', params: kwargs.merge(asset: asset))
|
673
|
+
end
|
674
|
+
end
|
675
|
+
end
|
676
|
+
end
|