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