@yuants/vendor-okx 0.23.24 → 0.23.25

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.
Files changed (79) hide show
  1. package/dist/account.js +9 -8
  2. package/dist/account.js.map +1 -1
  3. package/dist/api.js +444 -402
  4. package/dist/api.js.map +1 -1
  5. package/dist/index.js +5 -4
  6. package/dist/index.js.map +1 -1
  7. package/dist/loan-account.js +3 -2
  8. package/dist/loan-account.js.map +1 -1
  9. package/dist/market-order.js +1 -1
  10. package/dist/market-order.js.map +1 -1
  11. package/dist/order-actions.js +211 -0
  12. package/dist/order-actions.js.map +1 -0
  13. package/dist/order.js +3 -3
  14. package/dist/order.js.map +1 -1
  15. package/dist/public-api.js.map +1 -1
  16. package/dist/quote.js.map +1 -1
  17. package/dist/services.js +3 -2
  18. package/dist/services.js.map +1 -1
  19. package/dist/strategy-account.js +5 -4
  20. package/dist/strategy-account.js.map +1 -1
  21. package/dist/trade.js +6 -5
  22. package/dist/trade.js.map +1 -1
  23. package/dist/transfer.js +279 -0
  24. package/dist/transfer.js.map +1 -0
  25. package/dist/websocket.js.map +1 -1
  26. package/lib/account.d.ts +2 -2
  27. package/lib/account.d.ts.map +1 -1
  28. package/lib/account.js +8 -7
  29. package/lib/account.js.map +1 -1
  30. package/lib/api.d.ts +1252 -1264
  31. package/lib/api.d.ts.map +1 -1
  32. package/lib/api.js +477 -404
  33. package/lib/api.js.map +1 -1
  34. package/lib/index.d.ts +5 -4
  35. package/lib/index.d.ts.map +1 -1
  36. package/lib/index.js +5 -4
  37. package/lib/index.js.map +1 -1
  38. package/lib/loan-account.js +2 -1
  39. package/lib/loan-account.js.map +1 -1
  40. package/lib/market-order.d.ts.map +1 -1
  41. package/lib/market-order.js +1 -1
  42. package/lib/market-order.js.map +1 -1
  43. package/lib/order-actions.d.ts +2 -0
  44. package/lib/order-actions.d.ts.map +1 -0
  45. package/lib/order-actions.js +213 -0
  46. package/lib/order-actions.js.map +1 -0
  47. package/lib/order.js +2 -2
  48. package/lib/order.js.map +1 -1
  49. package/lib/public-api.js.map +1 -1
  50. package/lib/quote.d.ts +1 -1
  51. package/lib/quote.d.ts.map +1 -1
  52. package/lib/quote.js.map +1 -1
  53. package/lib/services.js +2 -1
  54. package/lib/services.js.map +1 -1
  55. package/lib/strategy-account.d.ts +2 -2
  56. package/lib/strategy-account.d.ts.map +1 -1
  57. package/lib/strategy-account.js +4 -3
  58. package/lib/strategy-account.js.map +1 -1
  59. package/lib/trade.js +6 -5
  60. package/lib/trade.js.map +1 -1
  61. package/lib/transfer.d.ts +2 -0
  62. package/lib/transfer.d.ts.map +1 -0
  63. package/lib/transfer.js +281 -0
  64. package/lib/transfer.js.map +1 -0
  65. package/lib/websocket.js.map +1 -1
  66. package/package.json +13 -12
  67. package/temp/package-deps.json +30 -29
  68. package/dist/legacy_index.js +0 -563
  69. package/dist/legacy_index.js.map +0 -1
  70. package/dist/logger.js +0 -91
  71. package/dist/logger.js.map +0 -1
  72. package/lib/legacy_index.d.ts +0 -2
  73. package/lib/legacy_index.d.ts.map +0 -1
  74. package/lib/legacy_index.js +0 -565
  75. package/lib/legacy_index.js.map +0 -1
  76. package/lib/logger.d.ts +0 -21
  77. package/lib/logger.d.ts.map +0 -1
  78. package/lib/logger.js +0 -98
  79. package/lib/logger.js.map +0 -1
package/dist/api.js CHANGED
@@ -1,407 +1,449 @@
1
1
  import { encodeBase64, formatTime, HmacSHA256 } from '@yuants/utils';
2
- /**
3
- * API v5: https://www.okx.com/docs-v5/#overview
4
- */
5
- export class OkxClient {
6
- constructor(config) {
7
- this.config = config;
8
- this.noAuth = true;
9
- /**
10
- * 获取账户资产估值
11
- *
12
- * 查看账户资产估值
13
- *
14
- * 限速:1次/s
15
- * 限速规则:UserID
16
- *
17
- * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-account-asset-valuation
18
- */
19
- this.getAssetValuation = (params) => this.request('GET', '/api/v5/asset/asset-valuation', params);
20
- /**
21
- * 查看账户配置
22
- * 查看当前账户的配置信息。
23
- *
24
- * 限速:5次/2s
25
- * 限速规则:UserID
26
- *
27
- * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-account-configuration
28
- */
29
- this.getAccountConfig = () => this.request('GET', '/api/v5/account/config');
30
- /**
31
- * 获取余币宝余额
32
- *
33
- * 限速:6次/s
34
- * 限速规则:UserID
35
- *
36
- * https://www.okx.com/docs-v5/zh/#financial-product-savings-get-saving-balance
37
- */
38
- this.getFinanceSavingsBalance = (params) => this.request('GET', '/api/v5/finance/savings/balance', params);
39
- /**
40
- * 余币宝申购/赎回
41
- *
42
- * 仅资金账户中的资产支持余币宝申购。
43
- *
44
- * 限速:6次/s
45
- *
46
- * 限速规则:UserID
47
- *
48
- * https://www.okx.com/docs-v5/zh/#financial-product-savings-post-savings-purchase-redemption
49
- */
50
- this.postFinanceSavingsPurchaseRedempt = (params) => this.request('POST', '/api/v5/finance/savings/purchase-redempt', params);
51
- /**
52
- * 提币
53
- *
54
- * 用户提币。普通子账户不支持提币。
55
- *
56
- * API只能提币到免认证地址/账户上,通过 WEB/APP 可以设置免认证地址。
57
- *
58
- * 关于标签:某些币种如XRP充币时同时需要一个充值地址和标签(又名memo/payment_id),标签是一种保证您的充币地址唯一性的数字串,与充币地址成对出现并一一对应。请您务必遵守正确的充值步骤,在提币时输入完整信息,否则将面临丢失币的风险!
59
- * 对于有标签的币种,如果是OKX用户间的提币,请走内部转账不要走链上提币。
60
- *
61
- * 限速:6次/s
62
- * 限速规则:UserID
63
- *
64
- * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-withdrawal
65
- */
66
- this.postAssetWithdrawal = (params) => this.request('POST', '/api/v5/asset/withdrawal', params);
67
- /**
68
- * 获取充值地址信息
69
- *
70
- * 获取各个币种的充值地址,包括曾使用过的老地址。
71
- *
72
- * 限速:6次/s
73
- * 限速规则:UserID
74
- *
75
- * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-deposit-address
76
- */
77
- this.getAssetDepositAddress = (params) => this.request('GET', '/api/v5/asset/deposit-address', params);
78
- /**
79
- * 获取提币记录
80
- *
81
- * 根据币种,提币状态,时间范围获取提币记录,按照时间倒序排列,默认返回100条数据。
82
- * 支持Websocket订阅,参考 提币信息频道。
83
- *
84
- * 限速:6 次/s
85
- * 限速规则:UserID
86
- *
87
- * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-withdrawal-history
88
- */
89
- this.getAssetWithdrawalHistory = (params) => this.request('GET', '/api/v5/asset/withdrawal-history', params);
90
- /**
91
- * 获取充值记录
92
- *
93
- * 根据币种,充值状态,时间范围获取充值记录,按照时间倒序排列,默认返回 100 条数据。
94
- * 支持Websocket订阅,参考 充值信息频道。
95
- *
96
- * 限速:6次/s
97
- * 限速规则:UserID
98
- *
99
- * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-deposit-history
100
- */
101
- this.getAssetDepositHistory = (params) => this.request('GET', '/api/v5/asset/deposit-history', params);
102
- /**
103
- * 获取资金账户余额
104
- *
105
- * 获取资金账户所有资产列表,查询各币种的余额、冻结和可用等信息。
106
- *
107
- * 只返回余额大于0的币资产信息。
108
- *
109
- * 限速:6次/s
110
- * 限速规则:UserID
111
- *
112
- * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-balance
113
- */
114
- this.getAssetBalances = (params) => this.request('GET', '/api/v5/asset/balances', params);
115
- /**
116
- * 资金划转
117
- *
118
- * 调用时,API Key 需要有交易权限。
119
- *
120
- * 支持母账户的资金账户划转到交易账户,母账户到子账户的资金账户和交易账户划转。
121
- *
122
- * 子账户默认可转出至母账户,划转到同一母账户下的其他子账户,需要先调用 设置子账户主动转出权限 接口进行授权。
123
- *
124
- * 请求失败不代表划转失败,建议以获取资金划转状态接口返回的状态为准。
125
- *
126
- * 限速:2 次/s
127
- * 限速规则:UserID + Currency
128
- *
129
- * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-funds-transfer
130
- */
131
- this.postAssetTransfer = (params) => this.request('POST', '/api/v5/asset/transfer', params);
132
- /**
133
- * 查看账户余额
134
- *
135
- * 获取交易账户中资金余额信息。
136
- *
137
- * 免息额度和折算率都是公共数据,不在账户接口内展示
138
- *
139
- * 限速:10次/2s
140
- * 限速规则:UserID
141
- *
142
- * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-balance
143
- */
144
- this.getAccountBalance = (params) => this.request('GET', '/api/v5/account/balance', params);
145
- /**
146
- * 查看持仓信息
147
- *
148
- * 获取该账户下拥有实际持仓的信息。账户为买卖模式会显示净持仓(net),账户为开平仓模式下会分别返回开多(long)或开空(short)的仓位。按照仓位创建时间倒序排列。
149
- *
150
- * 如果该 instId 拥有过仓位且当前持仓量为0,传 instId 时,如果当前存在有效的posId,会返回仓位信息,如果当前不存在有效的 posId 时,不会返回仓位信息;不传 instId 时,仓位信息不返回。
151
- *
152
- * 逐仓交易设置中,如果设置为自主划转模式,逐仓转入保证金后,会生成一个持仓量为0的仓位
153
- *
154
- * 限速:10次/2s
155
- * 限速规则:UserID
156
- *
157
- * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-positions
158
- */
159
- this.getAccountPositions = (params) => this.request('GET', '/api/v5/account/positions', params);
160
- /**
161
- * 获取最大可下单数量
162
- *
163
- * 获取最大可买卖/开仓数量,可对应下单时的 sz 字段
164
- *
165
- * 限速:20次/2s
166
- * 限速规则:UserID
167
- *
168
- * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-maximum-tradable-size
169
- */
170
- this.getAccountMaxSize = (params) => this.request('GET', '/api/v5/account/max-size', params);
171
- /**
172
- * 赚币
173
- * GET / 查看项目
174
- *
175
- * 限速:3次/s
176
- * 限速规则:UserID
177
- */
178
- this.getFinanceStakingDeFiOffers = (params) => this.request('GET', '/api/v5/finance/staking-defi/offers', params);
179
- /**
180
- * 赚币
181
- * GET / 查看活跃订单
182
- *
183
- * 限速:3次/s
184
- * 限速规则:UserID
185
- */
186
- this.getFinanceStakingDeFiOrdersActive = (params) => this.request('GET', '/api/v5/finance/staking-defi/orders-active', params);
187
- /**
188
- * 下单
189
- *
190
- * 只有当您的账户有足够的资金才能下单。
191
- *
192
- * 限速:60次/2s
193
- *
194
- * 跟单交易带单产品的限速:4次/2s
195
- *
196
- * 限速规则(期权以外):UserID + Instrument ID
197
- *
198
- * 限速规则(只限期权):UserID + Instrument Family
199
- *
200
- * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-place-order
201
- */
202
- this.postTradeOrder = (params) => this.request('POST', '/api/v5/trade/order', params);
203
- /**
204
- * 修改订单
205
- *
206
- * 修改当前未成交的挂单
207
- *
208
- * 限速:60次/2s
209
- *
210
- * 跟单交易带单员带单产品的限速:4个/2s
211
- *
212
- * 限速规则:User ID + Instrument ID
213
- *
214
- * 权限:交易
215
- *
216
- * 该接口限速同时受到 子账户限速 及 基于成交比率的子账户限速 限速规则的影响。
217
- *
218
- * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-amend-order
219
- */
220
- this.postTradeAmendOrder = (params) => this.request('POST', '/api/v5/trade/amend-order', params);
221
- /**
222
- * 获取未成交订单列表
223
- *
224
- * 获取当前账户下所有未成交订单信息
225
- *
226
- * 限速:60次/2s
227
- * 限速规则:UserID
228
- *
229
- * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-get-order-list
230
- */
231
- this.getTradeOrdersPending = (params) => this.request('GET', '/api/v5/trade/orders-pending', params);
232
- /**
233
- * 获取历史订单记录(近七天)
234
- *
235
- * 获取最近7天挂单,且完成的订单数据,包括7天以前挂单,但近7天才成交的订单数据。按照订单创建时间倒序排序。
236
- *
237
- * 已经撤销的未成交单 只保留2小时
238
- * 限速:40次/2s
239
- * 限速规则:User ID
240
- */
241
- this.getTradeOrdersHistory = (params) => this.request('GET', '/api/v5/trade/orders-history', params);
242
- /**
243
- * 撤单
244
- *
245
- * 撤销之前下的未完成订单。
246
- *
247
- * 限速:60次/2s
248
- *
249
- * 限速规则(期权以外):UserID + Instrument ID
250
- *
251
- * 限速规则(只限期权):UserID + Instrument Family
252
- *
253
- * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-cancel-order
254
- */
255
- this.postTradeCancelOrder = (params) => this.request('POST', '/api/v5/trade/cancel-order', params);
256
- /**
257
- * 查看子账户列表
258
- *
259
- * 仅适用于母账户。
260
- *
261
- * 限速:2次/2s
262
- *
263
- * 限速规则:UserID
264
- */
265
- this.getSubAccountList = (params) => this.request('GET', '/api/v5/users/subaccount/list', params);
266
- /**
267
- * 设置子账户主动转出权限
268
- *
269
- * 设置子账户转出权限(仅适用于母账户),默认可转出至母账户。
270
- *
271
- * 限速:1次/s
272
- *
273
- * 限速规则:UserID
274
- */
275
- this.postSetSubAccountTransferOut = (params) => this.request('POST', '/api/v5/users/subaccount/set-transfer-out', params);
276
- /**
277
- * 获取资金划转状态
278
- *
279
- * 获取最近2个星期内的资金划转状态数据
280
- *
281
- * 限速:10 次/s
282
- *
283
- * 限速规则:UserID
284
- *
285
- * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-funds-transfer-state
286
- */
287
- this.getAssetTransferState = (params) => this.request('GET', '/api/v5/asset/transfer-state', params);
288
- /**
289
- * 获取币种列表
290
- *
291
- * 获取当前用户KYC实体支持的币种列表。
292
- *
293
- * 限速:6 次/s
294
- *
295
- * 限速规则:UserID
296
- *
297
- * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-currencies
298
- */
299
- this.getAssetCurrencies = (params) => this.request('GET', '/api/v5/asset/currencies', params);
300
- /**
301
- * GET / 借贷信息
302
- * 限速:5次/2s
303
- * 限速规则:User ID
304
- * 权限:读取
305
- * HTTP请求
306
- *
307
- * https://www.okx.com/docs-v5/zh/#financial-product-flexible-loan-get-loan-info
308
- */
309
- this.getFlexibleLoanInfo = () => this.request('GET', '/api/v5/finance/flexible-loan/loan-info');
310
- /**
311
- * 账单流水查询(近七天)
312
- *
313
- *
314
- * 限速:5次/s
315
- *
316
- *
317
- * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-bills-details-last-7-days
318
- */
319
- this.getAccountBills = (params) => this.request('GET', '/api/v5/account/bills', params);
320
- /**
321
- * 账单流水查询(近三个月)
322
- *
323
- *
324
- * 限速:5次/2s
325
- *
326
- *
327
- * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-bills-details-last-3-months
328
- */
329
- this.getAccountBillsArchive = (params) => this.request('GET', '/api/v5/account/bills-archive', params);
330
- /**
331
- * POST / 网格策略委托下单
332
- * 限速:20次/2s
333
- * 限速规则:User ID + Instrument ID
334
- * 权限:交易
335
- * HTTP请求
336
- *
337
- * https://www.okx.com/docs-v5/zh/?language=shell#order-book-trading-grid-trading-post-place-grid-algo-order
338
- */
339
- this.postGridAlgoOrder = (params) => this.request('POST', '/api/v5/tradingBot/grid/order-algo', params);
340
- /**
341
- * GET / 获取未完成网格策略委托单列表
342
- * 限速:20次/2s
343
- * 限速规则:User ID
344
- * 权限:读取
345
- * HTTP请求
346
- *
347
- * https://www.okx.com/docs-v5/zh/#order-book-trading-grid-trading-get-grid-algo-order-list
348
- */
349
- this.getGridOrdersAlgoPending = (param) => this.request('GET', '/api/v5/tradingBot/grid/orders-algo-pending', param);
350
- /**
351
- * GET / 获取网格策略委托持仓
352
- * 限速:20次/2s
353
- * 限速规则:User ID
354
- * 权限:读取
355
- * HTTP请求
356
- *
357
- * https://www.okx.com/docs-v5/zh/#order-book-trading-grid-trading-get-grid-algo-order-positions
358
- */
359
- this.getGridPositions = (param) => this.request('GET', '/api/v5/tradingBot/grid/positions', param);
360
- if (config.auth.public_key && config.auth.secret_key && config.auth.passphrase) {
361
- this.noAuth = false;
362
- }
363
- }
364
- async request(method, path, params) {
365
- const url = new URL('https://www.okx.com');
366
- url.pathname = path;
367
- if (method === 'GET') {
368
- for (const key in params) {
369
- url.searchParams.set(key, params[key]);
370
- }
371
- }
372
- if (this.noAuth) {
373
- console.info(formatTime(Date.now()), method, url.href);
374
- const res = await fetch(url.href, { method });
375
- return res.json();
2
+ export const getDefaultCredential = () => ({
3
+ access_key: process.env.ACCESS_KEY,
4
+ secret_key: process.env.SECRET_KEY,
5
+ passphrase: process.env.PASSPHRASE,
6
+ });
7
+ export async function request(credential, method, path, params) {
8
+ const url = new URL('https://www.okx.com');
9
+ url.pathname = path;
10
+ if (method === 'GET' && params) {
11
+ for (const key in params) {
12
+ url.searchParams.set(key, String(params[key]));
376
13
  }
377
- const timestamp = formatTime(Date.now(), 'UTC').replace(' ', 'T');
378
- const secret_key = this.config.auth.secret_key;
379
- const body = method === 'GET' ? '' : JSON.stringify(params);
380
- const signData = timestamp + method + url.pathname + url.search + body;
381
- const str = encodeBase64(await HmacSHA256(
382
- //
383
- new TextEncoder().encode(signData), new TextEncoder().encode(secret_key)));
384
- const headers = {
385
- 'Content-Type': 'application/json',
386
- 'OK-ACCESS-KEY': this.config.auth.public_key,
387
- 'OK-ACCESS-SIGN': str,
388
- 'OK-ACCESS-TIMESTAMP': timestamp,
389
- 'OK-ACCESS-PASSPHRASE': this.config.auth.passphrase,
390
- };
391
- console.info(formatTime(Date.now()), method, url.href, JSON.stringify(headers), body, signData);
392
- const res = await fetch(url.href, {
393
- method,
394
- headers,
395
- body: body || undefined,
396
- });
397
- return res.json();
398
14
  }
15
+ const timestamp = formatTime(Date.now(), 'UTC').replace(' ', 'T');
16
+ const secret_key = credential.secret_key;
17
+ const body = method === 'GET' ? '' : JSON.stringify(params);
18
+ const signData = timestamp + method + url.pathname + url.search + body;
19
+ const str = encodeBase64(await HmacSHA256(
20
+ //
21
+ new TextEncoder().encode(signData), new TextEncoder().encode(secret_key)));
22
+ const headers = {
23
+ 'Content-Type': 'application/json',
24
+ 'OK-ACCESS-KEY': credential.access_key,
25
+ 'OK-ACCESS-SIGN': str,
26
+ 'OK-ACCESS-TIMESTAMP': timestamp,
27
+ 'OK-ACCESS-PASSPHRASE': credential.passphrase,
28
+ };
29
+ console.info(formatTime(Date.now()), method, url.href, JSON.stringify(headers), body, signData);
30
+ const res = await fetch(url.href, {
31
+ method,
32
+ headers,
33
+ body: body || undefined,
34
+ });
35
+ console.info(formatTime(Date.now()), 'PrivateApiResponse', credential.access_key, method, url.href, res.status);
36
+ return res.json();
37
+ }
38
+ /**
39
+ * 获取账户资产估值
40
+ *
41
+ * 查看账户资产估值
42
+ *
43
+ * 限速:1次/s
44
+ * 限速规则:UserID
45
+ *
46
+ * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-account-asset-valuation
47
+ */
48
+ export function getAssetValuation(credential, params) {
49
+ return request(credential, 'GET', '/api/v5/asset/asset-valuation', params);
50
+ }
51
+ /**
52
+ * 查看账户配置
53
+ * 查看当前账户的配置信息。
54
+ *
55
+ * 限速:5次/2s
56
+ * 限速规则:UserID
57
+ *
58
+ * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-account-configuration
59
+ */
60
+ export function getAccountConfig(credential) {
61
+ return request(credential, 'GET', '/api/v5/account/config');
62
+ }
63
+ /**
64
+ * 获取余币宝余额
65
+ *
66
+ * 限速:6次/s
67
+ * 限速规则:UserID
68
+ *
69
+ * https://www.okx.com/docs-v5/zh/#financial-product-savings-get-saving-balance
70
+ */
71
+ export function getFinanceSavingsBalance(credential, params) {
72
+ return request(credential, 'GET', '/api/v5/finance/savings/balance', params);
73
+ }
74
+ /**
75
+ * 余币宝申购/赎回
76
+ *
77
+ * 仅资金账户中的资产支持余币宝申购。
78
+ *
79
+ * 限速:6次/s
80
+ *
81
+ * 限速规则:UserID
82
+ *
83
+ * https://www.okx.com/docs-v5/zh/#financial-product-savings-post-savings-purchase-redemption
84
+ */
85
+ export function postFinanceSavingsPurchaseRedempt(credential, params) {
86
+ return request(credential, 'POST', '/api/v5/finance/savings/purchase-redempt', params);
87
+ }
88
+ /**
89
+ * 提币
90
+ *
91
+ * 用户提币。普通子账户不支持提币。
92
+ *
93
+ * API只能提币到免认证地址/账户上,通过 WEB/APP 可以设置免认证地址。
94
+ *
95
+ * 关于标签:某些币种如XRP充币时同时需要一个充值地址和标签(又名memo/payment_id),标签是一种保证您的充币地址唯一性的数字串,与充币地址成对出现并一一对应。请您务必遵守正确的充值步骤,在提币时输入完整信息,否则将面临丢失币的风险!
96
+ * 对于有标签的币种,如果是OKX用户间的提币,请走内部转账不要走链上提币。
97
+ *
98
+ * 限速:6次/s
99
+ * 限速规则:UserID
100
+ *
101
+ * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-withdrawal
102
+ */
103
+ export function postAssetWithdrawal(credential, params) {
104
+ return request(credential, 'POST', '/api/v5/asset/withdrawal', params);
105
+ }
106
+ /**
107
+ * 获取充值地址信息
108
+ *
109
+ * 获取各个币种的充值地址,包括曾使用过的老地址。
110
+ *
111
+ * 限速:6次/s
112
+ * 限速规则:UserID
113
+ *
114
+ * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-deposit-address
115
+ */
116
+ export function getAssetDepositAddress(credential, params) {
117
+ return request(credential, 'GET', '/api/v5/asset/deposit-address', params);
118
+ }
119
+ /**
120
+ * 获取提币记录
121
+ *
122
+ * 根据币种,提币状态,时间范围获取提币记录,按照时间倒序排列,默认返回100条数据。
123
+ * 支持Websocket订阅,参考 提币信息频道。
124
+ *
125
+ * 限速:6 次/s
126
+ * 限速规则:UserID
127
+ *
128
+ * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-withdrawal-history
129
+ */
130
+ export function getAssetWithdrawalHistory(credential, params) {
131
+ return request(credential, 'GET', '/api/v5/asset/withdrawal-history', params);
132
+ }
133
+ /**
134
+ * 获取充值记录
135
+ *
136
+ * 根据币种,充值状态,时间范围获取充值记录,按照时间倒序排列,默认返回 100 条数据。
137
+ * 支持Websocket订阅,参考 充值信息频道。
138
+ *
139
+ * 限速:6次/s
140
+ * 限速规则:UserID
141
+ *
142
+ * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-deposit-history
143
+ */
144
+ export function getAssetDepositHistory(credential, params) {
145
+ return request(credential, 'GET', '/api/v5/asset/deposit-history', params);
146
+ }
147
+ /**
148
+ * 获取资金账户余额
149
+ *
150
+ * 获取资金账户所有资产列表,查询各币种的余额、冻结和可用等信息。
151
+ *
152
+ * 只返回余额大于0的币资产信息。
153
+ *
154
+ * 限速:6次/s
155
+ * 限速规则:UserID
156
+ *
157
+ * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-balance
158
+ */
159
+ export function getAssetBalances(credential, params) {
160
+ return request(credential, 'GET', '/api/v5/asset/balances', params);
161
+ }
162
+ /**
163
+ * 资金划转
164
+ *
165
+ * 调用时,API Key 需要有交易权限。
166
+ *
167
+ * 支持母账户的资金账户划转到交易账户,母账户到子账户的资金账户和交易账户划转。
168
+ *
169
+ * 子账户默认可转出至母账户,划转到同一母账户下的其他子账户,需要先调用 设置子账户主动转出权限 接口进行授权。
170
+ *
171
+ * 请求失败不代表划转失败,建议以获取资金划转状态接口返回的状态为准。
172
+ *
173
+ * 限速:2 次/s
174
+ * 限速规则:UserID + Currency
175
+ *
176
+ * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-funds-transfer
177
+ */
178
+ export function postAssetTransfer(credential, params) {
179
+ return request(credential, 'POST', '/api/v5/asset/transfer', params);
180
+ }
181
+ /**
182
+ * 查看账户余额
183
+ *
184
+ * 获取交易账户中资金余额信息。
185
+ *
186
+ * 免息额度和折算率都是公共数据,不在账户接口内展示
187
+ *
188
+ * 限速:10次/2s
189
+ * 限速规则:UserID
190
+ *
191
+ * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-balance
192
+ */
193
+ export function getAccountBalance(credential, params) {
194
+ return request(credential, 'GET', '/api/v5/account/balance', params);
195
+ }
196
+ /**
197
+ * 查看持仓信息
198
+ *
199
+ * 获取该账户下拥有实际持仓的信息。账户为买卖模式会显示净持仓(net),账户为开平仓模式下会分别返回开多(long)或开空(short)的仓位。按照仓位创建时间倒序排列。
200
+ *
201
+ * 如果该 instId 拥有过仓位且当前持仓量为0,传 instId 时,如果当前存在有效的posId,会返回仓位信息,如果当前不存在有效的 posId 时,不会返回仓位信息;不传 instId 时,仓位信息不返回。
202
+ *
203
+ * 逐仓交易设置中,如果设置为自主划转模式,逐仓转入保证金后,会生成一个持仓量为0的仓位
204
+ *
205
+ * 限速:10次/2s
206
+ * 限速规则:UserID
207
+ *
208
+ * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-positions
209
+ */
210
+ export function getAccountPositions(credential, params) {
211
+ return request(credential, 'GET', '/api/v5/account/positions', params);
212
+ }
213
+ /**
214
+ * 获取最大可下单数量
215
+ *
216
+ * 获取最大可买卖/开仓数量,可对应下单时的 sz 字段
217
+ *
218
+ * 限速:20次/2s
219
+ * 限速规则:UserID
220
+ *
221
+ * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-maximum-tradable-size
222
+ */
223
+ export function getAccountMaxSize(credential, params) {
224
+ return request(credential, 'GET', '/api/v5/account/max-size', params);
225
+ }
226
+ /**
227
+ * 赚币
228
+ * GET / 查看项目
229
+ *
230
+ * 限速:3次/s
231
+ * 限速规则:UserID
232
+ */
233
+ export function getFinanceStakingDeFiOffers(credential, params) {
234
+ return request(credential, 'GET', '/api/v5/finance/staking-defi/offers', params);
235
+ }
236
+ /**
237
+ * 赚币
238
+ * GET / 查看活跃订单
239
+ *
240
+ * 限速:3次/s
241
+ * 限速规则:UserID
242
+ */
243
+ export function getFinanceStakingDeFiOrdersActive(credential, params) {
244
+ return request(credential, 'GET', '/api/v5/finance/staking-defi/orders-active', params);
245
+ }
246
+ /**
247
+ * 下单
248
+ *
249
+ * 只有当您的账户有足够的资金才能下单。
250
+ *
251
+ * 限速:60次/2s
252
+ *
253
+ * 跟单交易带单产品的限速:4次/2s
254
+ *
255
+ * 限速规则(期权以外):UserID + Instrument ID
256
+ *
257
+ * 限速规则(只限期权):UserID + Instrument Family
258
+ *
259
+ * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-place-order
260
+ */
261
+ export function postTradeOrder(credential, params) {
262
+ return request(credential, 'POST', '/api/v5/trade/order', params);
263
+ }
264
+ /**
265
+ * 修改订单
266
+ *
267
+ * 修改当前未成交的挂单
268
+ *
269
+ * 限速:60次/2s
270
+ *
271
+ * 跟单交易带单员带单产品的限速:4个/2s
272
+ *
273
+ * 限速规则:User ID + Instrument ID
274
+ *
275
+ * 权限:交易
276
+ *
277
+ * 该接口限速同时受到 子账户限速 及 基于成交比率的子账户限速 限速规则的影响。
278
+ *
279
+ * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-amend-order
280
+ */
281
+ export function postTradeAmendOrder(credential, params) {
282
+ return request(credential, 'POST', '/api/v5/trade/amend-order', params);
283
+ }
284
+ /**
285
+ * 获取未成交订单列表
286
+ *
287
+ * 获取当前账户下所有未成交订单信息
288
+ *
289
+ * 限速:60次/2s
290
+ * 限速规则:UserID
291
+ *
292
+ * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-get-order-list
293
+ */
294
+ export function getTradeOrdersPending(credential, params) {
295
+ return request(credential, 'GET', '/api/v5/trade/orders-pending', params);
296
+ }
297
+ /**
298
+ * 获取历史订单记录(近七天)
299
+ *
300
+ * 获取最近7天挂单,且完成的订单数据,包括7天以前挂单,但近7天才成交的订单数据。按照订单创建时间倒序排序。
301
+ *
302
+ * 已经撤销的未成交单 只保留2小时
303
+ * 限速:40次/2s
304
+ * 限速规则:User ID
305
+ */
306
+ export function getTradeOrdersHistory(credential, params) {
307
+ return request(credential, 'GET', '/api/v5/trade/orders-history', params);
308
+ }
309
+ /**
310
+ * 撤单
311
+ *
312
+ * 撤销之前下的未完成订单。
313
+ *
314
+ * 限速:60次/2s
315
+ *
316
+ * 限速规则(期权以外):UserID + Instrument ID
317
+ *
318
+ * 限速规则(只限期权):UserID + Instrument Family
319
+ *
320
+ * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-cancel-order
321
+ */
322
+ export function postTradeCancelOrder(credential, params) {
323
+ return request(credential, 'POST', '/api/v5/trade/cancel-order', params);
324
+ }
325
+ /**
326
+ * 查看子账户列表
327
+ *
328
+ * 仅适用于母账户。
329
+ *
330
+ * 限速:2次/2s
331
+ *
332
+ * 限速规则:UserID
333
+ */
334
+ export function getSubAccountList(credential, params) {
335
+ return request(credential, 'GET', '/api/v5/users/subaccount/list', params);
336
+ }
337
+ /**
338
+ * 设置子账户主动转出权限
339
+ *
340
+ * 设置子账户转出权限(仅适用于母账户),默认可转出至母账户。
341
+ *
342
+ * 限速:1次/s
343
+ *
344
+ * 限速规则:UserID
345
+ */
346
+ export function postSetSubAccountTransferOut(credential, params) {
347
+ return request(credential, 'POST', '/api/v5/users/subaccount/set-transfer-out', params);
348
+ }
349
+ /**
350
+ * 获取资金划转状态
351
+ *
352
+ * 获取最近2个星期内的资金划转状态数据
353
+ *
354
+ * 限速:10 次/s
355
+ *
356
+ * 限速规则:UserID
357
+ *
358
+ * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-funds-transfer-state
359
+ */
360
+ export function getAssetTransferState(credential, params) {
361
+ return request(credential, 'GET', '/api/v5/asset/transfer-state', params);
362
+ }
363
+ /**
364
+ * 获取币种列表
365
+ *
366
+ * 获取当前用户KYC实体支持的币种列表。
367
+ *
368
+ * 限速:6 次/s
369
+ *
370
+ * 限速规则:UserID
371
+ *
372
+ * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-currencies
373
+ */
374
+ export function getAssetCurrencies(credential, params) {
375
+ return request(credential, 'GET', '/api/v5/asset/currencies', params);
376
+ }
377
+ /**
378
+ * GET / 借贷信息
379
+ * 限速:5次/2s
380
+ * 限速规则:User ID
381
+ * 权限:读取
382
+ * HTTP请求
383
+ *
384
+ * https://www.okx.com/docs-v5/zh/#financial-product-flexible-loan-get-loan-info
385
+ */
386
+ export function getFlexibleLoanInfo(credential) {
387
+ return request(credential, 'GET', '/api/v5/finance/flexible-loan/loan-info');
388
+ }
389
+ /**
390
+ * 账单流水查询(近七天)
391
+ *
392
+ *
393
+ * 限速:5次/s
394
+ *
395
+ *
396
+ * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-bills-details-last-7-days
397
+ */
398
+ export function getAccountBills(credential, params) {
399
+ return request(credential, 'GET', '/api/v5/account/bills', params);
400
+ }
401
+ /**
402
+ * 账单流水查询(近三个月)
403
+ *
404
+ *
405
+ * 限速:5次/2s
406
+ *
407
+ *
408
+ * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-bills-details-last-3-months
409
+ */
410
+ export function getAccountBillsArchive(credential, params) {
411
+ return request(credential, 'GET', '/api/v5/account/bills-archive', params);
412
+ }
413
+ /**
414
+ * POST / 网格策略委托下单
415
+ * 限速:20次/2s
416
+ * 限速规则:User ID + Instrument ID
417
+ * 权限:交易
418
+ * HTTP请求
419
+ *
420
+ * https://www.okx.com/docs-v5/zh/?language=shell#order-book-trading-grid-trading-post-place-grid-algo-order
421
+ */
422
+ export function postGridAlgoOrder(credential, params) {
423
+ return request(credential, 'POST', '/api/v5/tradingBot/grid/order-algo', params);
424
+ }
425
+ /**
426
+ * GET / 获取未完成网格策略委托单列表
427
+ * 限速:20次/2s
428
+ * 限速规则:User ID
429
+ * 权限:读取
430
+ * HTTP请求
431
+ *
432
+ * https://www.okx.com/docs-v5/zh/#order-book-trading-grid-trading-get-grid-algo-order-list
433
+ */
434
+ export function getGridOrdersAlgoPending(credential, param) {
435
+ return request(credential, 'GET', '/api/v5/tradingBot/grid/orders-algo-pending', param);
436
+ }
437
+ /**
438
+ * GET / 获取网格策略委托持仓
439
+ * 限速:20次/2s
440
+ * 限速规则:User ID
441
+ * 权限:读取
442
+ * HTTP请求
443
+ *
444
+ * https://www.okx.com/docs-v5/zh/#order-book-trading-grid-trading-get-grid-algo-order-positions
445
+ */
446
+ export function getGridPositions(credential, param) {
447
+ return request(credential, 'GET', '/api/v5/tradingBot/grid/positions', param);
399
448
  }
400
- export const client = new OkxClient({
401
- auth: {
402
- public_key: process.env.ACCESS_KEY,
403
- secret_key: process.env.SECRET_KEY,
404
- passphrase: process.env.PASSPHRASE,
405
- },
406
- });
407
449
  //# sourceMappingURL=api.js.map