@yuants/vendor-okx 0.23.24 → 0.23.26

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