@yuants/vendor-okx 0.17.3 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.js CHANGED
@@ -304,6 +304,8 @@ export class OkxClient {
304
304
  * 权限:交易
305
305
  *
306
306
  * 该接口限速同时受到 子账户限速 及 基于成交比率的子账户限速 限速规则的影响。
307
+ *
308
+ * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-amend-order
307
309
  */
308
310
  this.postTradeAmendOrder = (params) => this.request('POST', '/api/v5/trade/amend-order', params);
309
311
  /**
package/dist/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,aAAa;AACb,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC;;GAEG;AACH,MAAM,OAAO,SAAS;IAEpB,YACS,MAMN;QANM,WAAM,GAAN,MAAM,CAMZ;QARH,WAAM,GAAG,IAAI,CAAC;QAmDd;;;;;;;;;WASG;QACH,qBAAgB,GAAG,CAAC,MAInB,EAqBE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,wBAAwB,EAAE,MAAM,CAAC,CAAC;QAE5D;;;;;;;;;WASG;QACH,sBAAiB,GAAG,CAAC,MAEpB,EAaE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,+BAA+B,EAAE,MAAM,CAAC,CAAC;QAEnE;;;;;;;;;WASG;QACH,oBAAe,GAAG,CAAC,MAKlB,EAUE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,8BAA8B,EAAE,MAAM,CAAC,CAAC;QAElE;;;;;;;;WAQG;QACH,qBAAgB,GAAG,GAyBhB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;QAEpD;;;;;;;W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AO,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAChG,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE;YAChC,MAAM;YACN,OAAO;YACP,IAAI,EAAE,IAAI,IAAI,SAAS;SACxB,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;CAu4CF;AAgCD,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAClC,IAAI,EAAE;QACJ,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;QACnC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;QACnC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;KACpC;CACF,CAAC,CAAC","sourcesContent":["import { formatTime } from '@yuants/utils';\n// @ts-ignore\nimport CryptoJS from 'crypto-js';\n\n/**\n * API v5: https://www.okx.com/docs-v5/#overview\n */\nexport class OkxClient {\n noAuth = true;\n constructor(\n public config: {\n auth: {\n public_key: string;\n secret_key: string;\n passphrase: string;\n };\n },\n ) {\n if (config.auth.public_key && config.auth.secret_key && config.auth.passphrase) {\n this.noAuth = false;\n }\n }\n\n async request(method: string, path: string, params?: any) {\n const url = new URL('https://www.okx.com');\n url.pathname = path;\n if (method === 'GET') {\n for (const key in params) {\n url.searchParams.set(key, params[key]);\n }\n }\n if (this.noAuth) {\n console.info(formatTime(Date.now()), method, url.href);\n const res = await fetch(url.href, { method });\n return res.json();\n }\n const timestamp = formatTime(Date.now(), 'UTC').replace(' ', 'T');\n const secret_key = this.config.auth.secret_key;\n const body = method === 'GET' ? '' : JSON.stringify(params);\n const signData = timestamp + method + url.pathname + url.search + body;\n const str = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(signData, secret_key));\n\n const headers = {\n 'Content-Type': 'application/json',\n 'OK-ACCESS-KEY': this.config.auth.public_key!,\n 'OK-ACCESS-SIGN': str,\n 'OK-ACCESS-TIMESTAMP': timestamp,\n 'OK-ACCESS-PASSPHRASE': this.config.auth.passphrase,\n };\n\n console.info(formatTime(Date.now()), method, url.href, JSON.stringify(headers), body, signData);\n const res = await fetch(url.href, {\n method,\n headers,\n body: body || undefined,\n });\n return res.json();\n }\n\n /**\n * 获取所有产品行情信息\n *\n * 获取产品行情信息\n *\n * 限速:20次/2s\n * 限速规则:IP\n *\n * https://www.okx.com/docs-v5/zh/#order-book-trading-market-data-get-tickers\n */\n getMarketTickers = (params: {\n instType: string;\n uly?: string;\n instFamily?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n instType: string;\n instId: string;\n last: string;\n lastSz: string;\n askPx: string;\n askSz: string;\n bidPx: string;\n bidSz: string;\n open24h: string;\n high24h: string;\n low24h: string;\n volCcy24h: string;\n vol24h: string;\n sodUtc0: string;\n sodUtc8: string;\n ts: string;\n }>;\n }> => this.request('GET', '/api/v5/market/tickers', params);\n\n /**\n * 获取账户资产估值\n *\n * 查看账户资产估值\n *\n * 限速:1次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-account-asset-valuation\n */\n getAssetValuation = (params?: {\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n details: {\n classic: string;\n earn: string;\n funding: string;\n trading: string;\n };\n totalBal: string;\n ts: string;\n }>;\n }> => this.request('GET', '/api/v5/asset/asset-valuation', params);\n\n /**\n * 获取持仓总量\n *\n * 查询单个交易产品的市场的持仓总量\n *\n * 限速:20次/2s\n * 限速规则:IP + instrumentID\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-open-interest\n */\n getOpenInterest = (params: {\n instType: string;\n uly?: string;\n instFamily?: string;\n instId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n instType: string;\n instId: string;\n oi: string;\n oiCcy: string;\n ts: string;\n }[];\n }> => this.request('GET', '/api/v5/public/open-interest', params);\n\n /**\n * 查看账户配置\n * 查看当前账户的配置信息。\n *\n * 限速:5次/2s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-account-configuration\n */\n getAccountConfig = (): Promise<{\n code: string;\n data: Array<{\n acctLv: string;\n autoLoan: boolean;\n ctIsoMode: string;\n greeksType: string;\n level: string;\n levelTmp: string;\n mgnIsoMode: string;\n posMode: string;\n spotOffsetType: string;\n uid: string;\n label: string;\n roleType: string;\n traderInsts: any[];\n spotRoleType: string;\n spotTraderInsts: any[];\n opAuth: string;\n kycLv: string;\n ip: string;\n perm: string;\n mainUid: string;\n }>;\n msg: string;\n }> => this.request('GET', '/api/v5/account/config');\n\n /**\n * 获取市场借币杠杆利率和借币限额\n *\n * 限速:2次/2s\n * 限速规则:IP\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-interest-rate-and-loan-quota\n */\n getInterestRateLoanQuota = (): Promise<{\n code: string;\n data?: Array<{\n basic: Array<{\n ccy: string;\n rate: string;\n quota: string;\n }>;\n vip: Array<{\n loanQuotaCoef: string;\n level: string;\n }>;\n regular: Array<{\n loanQuotaCoef: string;\n level: string;\n }>;\n }>;\n }> => this.request('GET', '/api/v5/public/interest-rate-loan-quota');\n\n /**\n * 获取交易产品基础信息\n *\n * 获取所有可交易产品的信息列表。\n *\n * 限速:20次/2s\n * 限速规则:IP +instType\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-instruments\n */\n getInstruments = (params: {\n instType: string;\n uly?: string;\n instFamily?: string;\n instId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n alias: string;\n baseCcy: string;\n category: string;\n ctMult: string;\n ctType: string;\n ctVal: string;\n ctValCcy: string;\n expTime: string;\n instFamily: string;\n instId: string;\n instType: string;\n lever: string;\n listTime: string;\n lotSz: string;\n maxIcebergSz: string;\n maxLmtAmt: string;\n maxLmtSz: string;\n maxMktAmt: string;\n maxMktSz: string;\n maxStopSz: string;\n maxTriggerSz: string;\n maxTwapSz: string;\n minSz: string;\n optType: string;\n quoteCcy: string;\n settleCcy: string;\n state: string;\n stk: string;\n tickSz: string;\n uly: string;\n }>;\n }> => this.request('GET', '/api/v5/public/instruments', params);\n\n /**\n * 获取永续合约当前资金费率\n * 获取当前资金费率\n *\n * 限速:20次/2s\n * 限速规则:IP +instrumentID\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-funding-rate\n */\n getFundingRate = (params: {\n instId: string;\n }): Promise<{\n code: string;\n data: Array<{\n fundingRate: string;\n fundingTime: string;\n instId: string;\n instType: string;\n method: string;\n maxFundingRate: string;\n minFundingRate: string;\n nextFundingRate: string;\n nextFundingTime: string;\n premium: string;\n settFundingRate: string;\n settState: string;\n ts: string;\n }>;\n msg: string;\n }> => this.request('GET', '/api/v5/public/funding-rate', params);\n\n /**\n * 获取永续合约历史资金费率\n *\n * 获取最近3个月的历史资金费率\n *\n * 限速:10次/2s\n * 限速规则:IP +instrumentID\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-funding-rate-history\n */\n getFundingRateHistory = (params: {\n instId: string;\n before?: string;\n after?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n fundingRate: string;\n fundingTime: string;\n instId: string;\n instType: string;\n method: string;\n realizedRate: string;\n }>;\n }> => this.request('GET', '/api/v5/public/funding-rate-history', params);\n\n /**\n * 获取标记价格历史K线数据\n *\n * 获取最近几年的标记价格K线数据\n *\n * 限速:10次/2s\n * 限速规则:IP\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-mark-price-candlesticks-history\n */\n getHistoryMarkPriceCandles = (params: {\n instId: string;\n bar?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<[ts: string, o: string, h: string, l: string, c: string, confirm: string]>;\n }> => this.request('GET', '/api/v5/market/history-mark-price-candles', params);\n\n /**\n * GET / 获取交易产品历史K线数据\n *\n * 获取最近几年的历史k线数据(1s k线支持查询最近3个月的数据)\n *\n * 限速:20次/2s\n *\n * 限速规则:IP\n *\n * 期权不支持 1s K线, 其他业务线 (币币, 杠杆, 交割和永续)支持\n */\n getHistoryCandles = (params: {\n instId: string;\n bar?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<\n [\n ts: string,\n o: string,\n h: string,\n l: string,\n c: string,\n vol: string,\n volCcy: string,\n volCcyQuote: string,\n confirm: string,\n ]\n >;\n }> => this.request('GET', '/api/v5/market/history-candles', params);\n\n /**\n * 获取余币宝余额\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#financial-product-savings-get-saving-balance\n */\n getFinanceSavingsBalance = (params: {\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n earnings: string;\n redemptAmt: string;\n rate: string;\n ccy: string;\n amt: string;\n loanAmt: string;\n pendingAmt: string;\n }[];\n }> => this.request('GET', '/api/v5/finance/savings/balance', params);\n\n /**\n * 余币宝申购/赎回\n *\n * 仅资金账户中的资产支持余币宝申购。\n *\n * 限速:6次/s\n *\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#financial-product-savings-post-savings-purchase-redemption\n */\n postFinanceSavingsPurchaseRedempt = (params: {\n ccy: string;\n amt: string;\n side: string;\n rate: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n ccy: string;\n amt: string;\n side: string;\n rate: string;\n }[];\n }> => this.request('POST', '/api/v5/finance/savings/purchase-redempt', params);\n\n /**\n * GET / 获取市场借贷历史(公共)\n *\n * 公共接口无须鉴权\n *\n * 返回2021年12月14日后的记录\n *\n * 限速:6次/s\n * 限速规则:IP\n *\n * https://www.okx.com/docs-v5/zh/#financial-product-savings-get-public-borrow-history-public\n */\n getLendingRateHistory = (params: {\n ccy?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n ccy: string;\n amt: string;\n rate: string;\n ts: string;\n }>;\n }> => this.request('GET', '/api/v5/finance/savings/lending-rate-history', params);\n\n /**\n * 提币\n *\n * 用户提币。普通子账户不支持提币。\n *\n * API只能提币到免认证地址/账户上,通过 WEB/APP 可以设置免认证地址。\n *\n * 关于标签:某些币种如XRP充币时同时需要一个充值地址和标签(又名memo/payment_id),标签是一种保证您的充币地址唯一性的数字串,与充币地址成对出现并一一对应。请您务必遵守正确的充值步骤,在提币时输入完整信息,否则将面临丢失币的风险!\n * 对于有标签的币种,如果是OKX用户间的提币,请走内部转账不要走链上提币。\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-withdrawal\n */\n postAssetWithdrawal = (params: {\n amt: string;\n fee: string;\n dest: string;\n ccy: string;\n chain?: string;\n toAddr: string;\n clientId?: string;\n rcvrInfo?: {\n walletType: string;\n exchId: string;\n rcvrFirstName: string;\n rcvrLastName: string;\n };\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n amt: string;\n wdId: string;\n ccy: string;\n clientId: string;\n chain: string;\n }>;\n }> => this.request('POST', '/api/v5/asset/withdrawal', params);\n\n /**\n * 获取充值地址信息\n *\n * 获取各个币种的充值地址,包括曾使用过的老地址。\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-deposit-address\n */\n getAssetDepositAddress = (params: {\n ccy: string;\n }): Promise<{\n code: string;\n data: {\n chain: string;\n ctAddr: string;\n ccy: string;\n to: string;\n addr: string;\n verifiedName: string;\n selected: boolean;\n }[];\n msg: string;\n }> => this.request('GET', '/api/v5/asset/deposit-address', params);\n\n /**\n * 获取提币记录\n *\n * 根据币种,提币状态,时间范围获取提币记录,按照时间倒序排列,默认返回100条数据。\n * 支持Websocket订阅,参考 提币信息频道。\n *\n * 限速:6 次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-withdrawal-history\n */\n getAssetWithdrawalHistory = (params: {\n ccy?: string;\n wdId?: string;\n clientId?: string;\n txId?: string;\n type?: string;\n state?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n chain: string;\n fee: string;\n feeCcy: string;\n ccy: string;\n clientId: string;\n amt: string;\n txId: string;\n from: string;\n areaCodeFrom: string;\n to: string;\n areaCodeTo: string;\n state: string;\n ts: string;\n nonTradableAsset: boolean;\n wdId: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/withdrawal-history', params);\n\n /**\n * 获取充值记录\n *\n * 根据币种,充值状态,时间范围获取充值记录,按照时间倒序排列,默认返回 100 条数据。\n * 支持Websocket订阅,参考 充值信息频道。\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-deposit-history\n */\n getAssetDepositHistory = (params: {\n ccy?: string;\n depId?: string;\n state?: string;\n fromWdId?: string;\n txId?: string;\n type?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n actualDepBlkConfirm: string;\n amt: string;\n areaCodeFrom: string;\n ccy: string;\n chain: string;\n depId: string;\n from: string;\n fromWdId: string;\n state: string;\n to: string;\n ts: string;\n txId: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/deposit-history', params);\n\n /**\n * 获取资金账户余额\n *\n * 获取资金账户所有资产列表,查询各币种的余额、冻结和可用等信息。\n *\n * 只返回余额大于0的币资产信息。\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-balance\n */\n getAssetBalances = (params: {\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n availBal: string;\n bal: string;\n ccy: string;\n frozenBal: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/balances', params);\n\n /**\n * 资金划转\n *\n * 调用时,API Key 需要有交易权限。\n *\n * 支持母账户的资金账户划转到交易账户,母账户到子账户的资金账户和交易账户划转。\n *\n * 子账户默认可转出至母账户,划转到同一母账户下的其他子账户,需要先调用 设置子账户主动转出权限 接口进行授权。\n *\n * 请求失败不代表划转失败,建议以获取资金划转状态接口返回的状态为准。\n *\n * 限速:2 次/s\n * 限速规则:UserID + Currency\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-funds-transfer\n */\n postAssetTransfer = (params: {\n ccy: string;\n type?: string;\n amt: string;\n from: string;\n to: string;\n subAcct?: string;\n loanTrans?: boolean;\n omitPosRisk?: string;\n clientId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n transId: string;\n ccy: string;\n clientId: string;\n from: string;\n amt: string;\n to: string;\n }[];\n }> => this.request('POST', '/api/v5/asset/transfer', params);\n\n /**\n * 查看账户余额\n *\n * 获取交易账户中资金余额信息。\n *\n * 免息额度和折算率都是公共数据,不在账户接口内展示\n *\n * 限速:10次/2s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-balance\n */\n getAccountBalance = (params: {\n ccy?: string;\n }): Promise<{\n code: string;\n data: {\n adjEq: string;\n borrowFroz: string;\n details: {\n availBal: string;\n availEq: string;\n borrowFroz: string;\n cashBal: string;\n ccy: string;\n crossLiab: string;\n disEq: string;\n eq: string;\n eqUsd: string;\n fixedBal: string;\n frozenBal: string;\n imr: string;\n interest: string;\n isoEq: string;\n isoLiab: string;\n isoUpl: string;\n liab: string;\n maxLoan: string;\n mgnRatio: string;\n mmr: string;\n notionalLever: string;\n ordFrozen: string;\n rewardBal: string;\n spotInUseAmt: string;\n spotIsoBal: string;\n stgyEq: string;\n twap: string;\n uTime: string;\n upl: string;\n uplLiab: string;\n openAvgPx: string;\n spotUpl: string;\n accAvgPx: string;\n totalPnl: string;\n spotBal: string;\n }[];\n imr: string;\n isoEq: string;\n mgnRatio: string;\n mmr: string;\n notionalUsd: string;\n ordFroz: string;\n totalEq: string;\n uTime: string;\n upl: string;\n }[];\n msg: string;\n }> => this.request('GET', '/api/v5/account/balance', params);\n\n /**\n * 查看持仓信息\n *\n * 获取该账户下拥有实际持仓的信息。账户为买卖模式会显示净持仓(net),账户为开平仓模式下会分别返回开多(long)或开空(short)的仓位。按照仓位创建时间倒序排列。\n *\n * 如果该 instId 拥有过仓位且当前持仓量为0,传 instId 时,如果当前存在有效的posId,会返回仓位信息,如果当前不存在有效的 posId 时,不会返回仓位信息;不传 instId 时,仓位信息不返回。\n *\n * 逐仓交易设置中,如果设置为自主划转模式,逐仓转入保证金后,会生成一个持仓量为0的仓位\n *\n * 限速:10次/2s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-positions\n */\n getAccountPositions = (params: {\n instType?: string;\n instId?: string;\n posId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n adl: string;\n availPos: string;\n avgPx: string;\n cTime: string;\n ccy: string;\n deltaBS: string;\n deltaPA: string;\n gammaBS: string;\n gammaPA: string;\n imr: string;\n instId: string;\n instType: string;\n interest: string;\n idxPx: string;\n last: string;\n usdPx: string;\n bePx: string;\n lever: string;\n liab: string;\n liabCcy: string;\n liqPx: string;\n markPx: string;\n margin: string;\n mgnMode: string;\n mgnRatio: string;\n mmr: string;\n notionalUsd: string;\n optVal: string;\n pTime: string;\n pos: string;\n posCcy: string;\n posId: string;\n posSide: string;\n spotInUseAmt: string;\n spotInUseCcy: string;\n thetaBS: string;\n thetaPA: string;\n tradeId: string;\n bizRefId: string;\n bizRefType: string;\n quoteBal: string;\n baseBal: string;\n baseBorrowed: string;\n baseInterest: string;\n quoteBorrowed: string;\n quoteInterest: string;\n uTime: string;\n upl: string;\n uplLastPx: string;\n uplRatio: string;\n uplRatioLastPx: string;\n vegaBS: string;\n vegaPA: string;\n realizedPnl: string;\n pnl: string;\n fee: string;\n fundingFee: string;\n liqPenalty: string;\n closeOrderAlgo: {\n algoId: string;\n slTriggerPx: string;\n slTriggerPxType: string;\n tpTriggerPx: string;\n tpTriggerPxType: string;\n closeFraction: string;\n }[];\n }[];\n }> => this.request('GET', '/api/v5/account/positions', params);\n\n /**\n * 赚币\n * GET / 查看项目\n *\n * 限速:3次/s\n * 限速规则:UserID\n */\n getFinanceStakingDeFiOffers = (params: {\n productId?: string;\n protocolType?: string;\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n ccy: string;\n productId: string;\n protocol: string;\n protocolType: string;\n term: string;\n apy: string;\n earlyRedeem: boolean;\n investData: {\n ccy: string;\n bal: string;\n minAmt: string;\n maxAmt: string;\n }[];\n earningData: {\n ccy: string;\n earningType: string;\n }[];\n state: string;\n earningCcy?: string[];\n }[];\n }> => this.request('GET', '/api/v5/finance/staking-defi/offers', params);\n\n /**\n * 赚币\n * GET / 查看活跃订单\n *\n * 限速:3次/s\n * 限速规则:UserID\n */\n getFinanceStakingDeFiOrdersActive = (params: {\n productId?: string;\n protocolType?: string;\n ccy?: string;\n state?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n ordId: string;\n state: string;\n ccy: string;\n protocol: string;\n protocolType: string;\n term: string;\n apy: string;\n investData: {\n ccy: string;\n amt: string;\n minAmt?: string;\n maxAmt?: string;\n }[];\n earningData: {\n ccy: string;\n earningType: string;\n earnings: string;\n }[];\n purchasedTime: string;\n estSettlementTime: string;\n cancelRedemptionDeadline: string;\n tag: string;\n earningCcy?: string[];\n }[];\n }> => this.request('GET', '/api/v5/finance/staking-defi/orders-active', params);\n\n /**\n * 下单\n *\n * 只有当您的账户有足够的资金才能下单。\n *\n * 限速:60次/2s\n *\n * 跟单交易带单产品的限速:4次/2s\n *\n * 限速规则(期权以外):UserID + Instrument ID\n *\n * 限速规则(只限期权):UserID + Instrument Family\n *\n * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-place-order\n */\n postTradeOrder = (params: {\n instId: string;\n tdMode: string;\n ccy?: string;\n clOrdId?: string;\n tag?: string;\n side: string;\n posSide?: string;\n ordType: string;\n sz: string;\n px?: string;\n pxUsd?: string;\n pxVol?: string;\n reduceOnly?: string;\n tgtCcy?: string;\n banAmend?: string;\n quickMgnType?: string;\n stpId?: string;\n stpMode?: string;\n attachAlgoOrds?: Array<{\n attachAlgoClOrdId?: string;\n tpTriggerPx?: string;\n tpOrdPx?: string;\n tpOrdKind?: string;\n slTriggerPx?: string;\n slOrdPx?: string;\n tpTriggerPxType?: string;\n slTriggerPxType?: string;\n sz?: string;\n amendPxOnTriggerType?: string;\n }>;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n clOrdId: string;\n ordId: string;\n tag: string;\n sCode: string;\n sMsg: string;\n }[];\n inTime: string;\n outTime: string;\n }> => this.request('POST', '/api/v5/trade/order', params);\n\n /**\n * 修改订单\n *\n * 修改当前未成交的挂单\n *\n * 限速:60次/2s\n *\n * 跟单交易带单员带单产品的限速:4个/2s\n *\n * 限速规则:User ID + Instrument ID\n *\n * 权限:交易\n *\n * 该接口限速同时受到 子账户限速 及 基于成交比率的子账户限速 限速规则的影响。\n */\n postTradeAmendOrder = (params: {\n instId: string;\n cxIOnFail?: boolean;\n ordId?: string;\n clOrdId?: string;\n reqId?: string;\n newSz?: string;\n newPx?: string;\n newPxUsd?: string;\n newPxVol?: string;\n attachAlgoOrds?: Array<{\n attachAlgoId?: string;\n attachAlgoClOrdId?: string;\n newTpTriggerPx?: string;\n newTpOrdPx?: string;\n newTpOrdKind?: string;\n newSlTriggerPx?: string;\n newSlOrdPx?: string;\n newTpTriggerPxType?: string;\n newSlTriggerPxType?: string;\n sz?: string;\n amendPxOnTriggerType?: string;\n }>;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n clOrdId: string;\n ordId: string;\n ts: string;\n reqId: string;\n sCode: string;\n sMsg: string;\n }[];\n inTime: string;\n outTime: string;\n }> => this.request('POST', '/api/v5/trade/amend-order', params);\n\n /**\n * 获取未成交订单列表\n *\n * 获取当前账户下所有未成交订单信息\n *\n * 限速:60次/2s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-get-order-list\n */\n getTradeOrdersPending = (params: {\n instType?: string;\n uly?: string;\n instFamily?: string;\n instId?: string;\n ordType?: string;\n state?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n accFillSz: string;\n avgPx: string;\n cTime: string;\n category: string;\n ccy: string;\n clOrdId: string;\n fee: string;\n feeCcy: string;\n fillPx: string;\n fillSz: string;\n fillTime: string;\n instId: string;\n instType: string;\n lever: string;\n ordId: string;\n ordType: string;\n pnl: string;\n posSide: string;\n px: string;\n pxUsd: string;\n pxVol: string;\n pxType: string;\n rebate: string;\n rebateCcy: string;\n side: string;\n attachAlgoClOrdId: string;\n slOrdPx: string;\n slTriggerPx: string;\n slTriggerPxType: string;\n attachAlgoOrds: any[];\n source: string;\n state: string;\n stpId: string;\n stpMode: string;\n sz: string;\n tag: string;\n tdMode: string;\n tgtCcy: string;\n tpOrdPx: string;\n tpTriggerPx: string;\n tpTriggerPxType: string;\n tradeId: string;\n reduceOnly: string;\n quickMgnType: string;\n algoClOrdId: string;\n algoId: string;\n isTpLimit: string;\n uTime: string;\n }[];\n }> => this.request('GET', '/api/v5/trade/orders-pending', params);\n\n /**\n * 获取历史订单记录(近七天)\n *\n * 获取最近7天挂单,且完成的订单数据,包括7天以前挂单,但近7天才成交的订单数据。按照订单创建时间倒序排序。\n *\n * 已经撤销的未成交单 只保留2小时\n * 限速:40次/2s\n * 限速规则:User ID\n */\n getTradeOrdersHistory = (params: {\n instType: string;\n uly?: string;\n instFamily?: string;\n instId?: string;\n ordType?: string;\n state?: string;\n category?: string;\n after?: string;\n before?: string;\n begin?: string;\n end?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n instType: string;\n instId: string;\n tgtCcy: string;\n ccy: string;\n ordId: string;\n clOrdId: string;\n tag: string;\n px: string;\n pxUsd: string;\n pxVol: string;\n pxType: string;\n sz: string;\n ordType: string;\n side: string;\n posSide: string;\n tdMode: string;\n accFillSz: string;\n fillPx: string;\n tradeId: string;\n fillSz: string;\n fillTime: string;\n avgPx: string;\n state: string;\n lever: string;\n attachAlgoClOrdId: string;\n tpTriggerPx: string;\n tpTriggerPxType: string;\n tpOrdPx: string;\n slTriggerPx: string;\n slTriggerPxType: string;\n slOrdPx: string;\n attachAlgoOrds: any[];\n linkedAlgoOrd: any[];\n stpId: string;\n stpMode: string;\n feeCcy: string;\n fee: string;\n rebateCcy: string;\n source: string;\n rebate: string;\n pnl: string;\n category: string;\n reduceOnly: string;\n cancelSource: string;\n cancelSourceReason: string;\n algoClOrdId: string;\n algoId: string;\n isTpLimit: string;\n uTime: string;\n cTime: string;\n tradeQuoteCcy: string;\n }>;\n }> => this.request('GET', '/api/v5/trade/orders-history', params);\n\n /**\n * 撤单\n *\n * 撤销之前下的未完成订单。\n *\n * 限速:60次/2s\n *\n * 限速规则(期权以外):UserID + Instrument ID\n *\n * 限速规则(只限期权):UserID + Instrument Family\n *\n * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-cancel-order\n */\n postTradeCancelOrder = (params: {\n instId: string;\n ordId?: string;\n clOrdId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n clOrdId: string;\n ordId: string;\n sCode: string;\n sMsg: string;\n }[];\n inTime: string;\n outTime: string;\n }> => this.request('POST', '/api/v5/trade/cancel-order', params);\n\n /**\n * 查看子账户列表\n *\n * 仅适用于母账户。\n *\n * 限速:2次/2s\n *\n * 限速规则:UserID\n */\n getSubAccountList = (params?: {\n enable?: string;\n subAct?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n data: {\n type: string;\n enable: string;\n subAcct: string;\n uid: string;\n label: string;\n mobile: string;\n gAuth: boolean;\n frozenFunc: string[];\n canTransOut: boolean;\n ts: string;\n }[];\n code: string;\n msg: string;\n }> => this.request('GET', '/api/v5/users/subaccount/list', params);\n\n /**\n * 设置子账户主动转出权限\n *\n * 设置子账户转出权限(仅适用于母账户),默认可转出至母账户。\n *\n * 限速:1次/s\n *\n * 限速规则:UserID\n */\n postSetSubAccountTransferOut = (params: {\n subAcct: string;\n canTransOut: boolean;\n }): Promise<{\n subAcct: string;\n canTransOut: boolean;\n }> => this.request('POST', '/api/v5/users/subaccount/set-transfer-out', params);\n\n /**\n * 获取资金划转状态\n *\n * 获取最近2个星期内的资金划转状态数据\n *\n * 限速:10 次/s\n *\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-funds-transfer-state\n */\n getAssetTransferState = (params: {\n transId?: string;\n clientId?: string;\n type?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n transId: string;\n clientId: string;\n ccy: string;\n amt: string;\n type: string;\n from: string;\n to: string;\n subAcct: string;\n // success | pending | failed\n state: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/transfer-state', params);\n\n /**\n * 获取币种列表\n *\n * 获取当前用户KYC实体支持的币种列表。\n *\n * 限速:6 次/s\n *\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-currencies\n */\n getAssetCurrencies = (params?: {\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n ccy: string;\n name: string;\n chain: string;\n canWd: boolean;\n canInternal: boolean;\n minWd: string;\n maxWd: string;\n wdTickSz: string;\n wdQuota: string;\n usedWdQuota: string;\n minFee: string;\n maxFee: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/currencies', params);\n\n /**\n * 获取指数行情数据\n *\n *\n * 限速:20 次/2s\n *\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-index-tickers\n */\n getMarketIndexTicker = (params?: {\n quoteCcy?: string;\n instId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n instId: string;\n idxPx: string;\n high24h: string;\n sodUtc0: string;\n open24h: string;\n low24h: string;\n sodUtc8: string;\n ts: string;\n }[];\n }> => this.request('GET', '/api/v5/market/index-tickers', params);\n\n /**\n * 账单流水查询(近七天)\n *\n *\n * 限速:5次/s\n *\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-bills-details-last-7-days\n */\n getAccountBills = (params?: {\n instType?: string;\n instId?: string;\n ccy?: string;\n mgnMode?: 'isolated' | 'cross';\n ctType?: 'linear' | 'inverse';\n type?: AccountBillType;\n subType?: string;\n after?: string; //请求此id之前(更旧的数据)的分页内容,传的值为对应接口的billId\n before?: string; //请求此id之后(更新的数据)的分页内容,传的值为对应接口的billId\n begin?: string; //筛选的开始时间戳 ts,Unix 时间戳为毫秒数格式,如 1597026383085\n end?: string;\n limit?: string; //分页返回的结果集数量,最大为100,不填默认返回100条\n }): Promise<{\n code: string;\n msg: string;\n data: {\n instType: string;\n billId: string;\n type: string;\n subType: string;\n ts: string;\n balChg: string;\n posBalChg: string;\n bal: string;\n posBal: string;\n sz: string;\n px: string;\n ccy: string;\n pnl: string;\n fee: string;\n mgnMode: 'isolated' | 'cross' | 'cash' | '';\n instId: string;\n ordId: string;\n execType: string;\n from: string;\n to: string;\n notes: string;\n interest: string;\n tag: string;\n fillTime: string;\n tradeId: string;\n clOrdId: string;\n fillIdxPx: string;\n fillMarkPx: string;\n fillPxVol: string;\n fillPxUsd: string;\n fillMarkVol: string;\n fillFwdPx: string;\n }[];\n }> => this.request('GET', '/api/v5/account/bills', params);\n\n /**\n * 账单流水查询(近三个月)\n *\n *\n * 限速:5次/2s\n *\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-bills-details-last-3-months\n */\n getAccountBillsArchive = (params?: {\n instType?: string;\n instId?: string;\n ccy?: string;\n mgnMode?: 'isolated' | 'cross';\n ctType?: 'linear' | 'inverse';\n type?: AccountBillType;\n subType?: string;\n after?: string; //请求此id之前(更旧的数据)的分页内容,传的值为对应接口的billId\n before?: string; //请求此id之后(更新的数据)的分页内容,传的值为对应接口的billId\n begin?: string; //筛选的开始时间戳 ts,Unix 时间戳为毫秒数格式,如 1597026383085\n end?: string;\n limit?: string; //分页返回的结果集数量,最大为100,不填默认返回100条\n }): Promise<{\n code: string;\n msg: string;\n data: {\n instType: string;\n billId: string;\n type: string;\n subType: string;\n ts: string;\n balChg: string;\n posBalChg: string;\n bal: string;\n posBal: string;\n sz: string;\n px: string;\n ccy: string;\n pnl: string;\n fee: string;\n mgnMode: 'isolated' | 'cross' | 'cash' | '';\n instId: string;\n ordId: string;\n execType: string;\n from: string;\n to: string;\n notes: string;\n interest: string;\n tag: string;\n fillTime: string;\n tradeId: string;\n clOrdId: string;\n fillIdxPx: string;\n fillMarkPx: string;\n fillPxVol: string;\n fillPxUsd: string;\n fillMarkVol: string;\n fillFwdPx: string;\n }[];\n }> => this.request('GET', '/api/v5/account/bills-archive', params);\n}\n\ntype AccountBillType =\n | '1'\n | '2'\n | '3'\n | '4'\n | '5'\n | '6'\n | '7'\n | '8'\n | '9'\n | '10'\n | '11'\n | '12'\n | '13'\n | '14'\n | '15'\n | '16'\n | '22'\n | '24'\n | '26'\n | '27'\n | '28'\n | '29'\n | '30'\n | '32'\n | '33'\n | '34'\n | '250'\n | '251';\n\nexport const client = new OkxClient({\n auth: {\n public_key: process.env.ACCESS_KEY!,\n secret_key: process.env.SECRET_KEY!,\n passphrase: process.env.PASSPHRASE!,\n },\n});\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,aAAa;AACb,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC;;GAEG;AACH,MAAM,OAAO,SAAS;IAEpB,YACS,MAMN;QANM,WAAM,GAAN,MAAM,CAMZ;QARH,WAAM,GAAG,IAAI,CAAC;QAmDd;;;;;;;;;WASG;QACH,qBAAgB,GAAG,CAAC,MAInB,EAqBE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,wBAAwB,EAAE,MAAM,CAAC,CAAC;QAE5D;;;;;;;;;WASG;QACH,sBAAiB,GAAG,CAAC,MAEpB,EAaE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,+BAA+B,EAAE,MAAM,CAAC,CA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AAC,UAAW;YAC7C,gBAAgB,EAAE,GAAG;YACrB,qBAAqB,EAAE,SAAS;YAChC,sBAAsB,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU;SACpD,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAChG,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE;YAChC,MAAM;YACN,OAAO;YACP,IAAI,EAAE,IAAI,IAAI,SAAS;SACxB,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;CAy4CF;AAgCD,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAClC,IAAI,EAAE;QACJ,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;QACnC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;QACnC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;KACpC;CACF,CAAC,CAAC","sourcesContent":["import { formatTime } from '@yuants/utils';\n// @ts-ignore\nimport CryptoJS from 'crypto-js';\n\n/**\n * API v5: https://www.okx.com/docs-v5/#overview\n */\nexport class OkxClient {\n noAuth = true;\n constructor(\n public config: {\n auth: {\n public_key: string;\n secret_key: string;\n passphrase: string;\n };\n },\n ) {\n if (config.auth.public_key && config.auth.secret_key && config.auth.passphrase) {\n this.noAuth = false;\n }\n }\n\n async request(method: string, path: string, params?: any) {\n const url = new URL('https://www.okx.com');\n url.pathname = path;\n if (method === 'GET') {\n for (const key in params) {\n url.searchParams.set(key, params[key]);\n }\n }\n if (this.noAuth) {\n console.info(formatTime(Date.now()), method, url.href);\n const res = await fetch(url.href, { method });\n return res.json();\n }\n const timestamp = formatTime(Date.now(), 'UTC').replace(' ', 'T');\n const secret_key = this.config.auth.secret_key;\n const body = method === 'GET' ? '' : JSON.stringify(params);\n const signData = timestamp + method + url.pathname + url.search + body;\n const str = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(signData, secret_key));\n\n const headers = {\n 'Content-Type': 'application/json',\n 'OK-ACCESS-KEY': this.config.auth.public_key!,\n 'OK-ACCESS-SIGN': str,\n 'OK-ACCESS-TIMESTAMP': timestamp,\n 'OK-ACCESS-PASSPHRASE': this.config.auth.passphrase,\n };\n\n console.info(formatTime(Date.now()), method, url.href, JSON.stringify(headers), body, signData);\n const res = await fetch(url.href, {\n method,\n headers,\n body: body || undefined,\n });\n return res.json();\n }\n\n /**\n * 获取所有产品行情信息\n *\n * 获取产品行情信息\n *\n * 限速:20次/2s\n * 限速规则:IP\n *\n * https://www.okx.com/docs-v5/zh/#order-book-trading-market-data-get-tickers\n */\n getMarketTickers = (params: {\n instType: string;\n uly?: string;\n instFamily?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n instType: string;\n instId: string;\n last: string;\n lastSz: string;\n askPx: string;\n askSz: string;\n bidPx: string;\n bidSz: string;\n open24h: string;\n high24h: string;\n low24h: string;\n volCcy24h: string;\n vol24h: string;\n sodUtc0: string;\n sodUtc8: string;\n ts: string;\n }>;\n }> => this.request('GET', '/api/v5/market/tickers', params);\n\n /**\n * 获取账户资产估值\n *\n * 查看账户资产估值\n *\n * 限速:1次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-account-asset-valuation\n */\n getAssetValuation = (params?: {\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n details: {\n classic: string;\n earn: string;\n funding: string;\n trading: string;\n };\n totalBal: string;\n ts: string;\n }>;\n }> => this.request('GET', '/api/v5/asset/asset-valuation', params);\n\n /**\n * 获取持仓总量\n *\n * 查询单个交易产品的市场的持仓总量\n *\n * 限速:20次/2s\n * 限速规则:IP + instrumentID\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-open-interest\n */\n getOpenInterest = (params: {\n instType: string;\n uly?: string;\n instFamily?: string;\n instId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n instType: string;\n instId: string;\n oi: string;\n oiCcy: string;\n ts: string;\n }[];\n }> => this.request('GET', '/api/v5/public/open-interest', params);\n\n /**\n * 查看账户配置\n * 查看当前账户的配置信息。\n *\n * 限速:5次/2s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-account-configuration\n */\n getAccountConfig = (): Promise<{\n code: string;\n data: Array<{\n acctLv: string;\n autoLoan: boolean;\n ctIsoMode: string;\n greeksType: string;\n level: string;\n levelTmp: string;\n mgnIsoMode: string;\n posMode: string;\n spotOffsetType: string;\n uid: string;\n label: string;\n roleType: string;\n traderInsts: any[];\n spotRoleType: string;\n spotTraderInsts: any[];\n opAuth: string;\n kycLv: string;\n ip: string;\n perm: string;\n mainUid: string;\n }>;\n msg: string;\n }> => this.request('GET', '/api/v5/account/config');\n\n /**\n * 获取市场借币杠杆利率和借币限额\n *\n * 限速:2次/2s\n * 限速规则:IP\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-interest-rate-and-loan-quota\n */\n getInterestRateLoanQuota = (): Promise<{\n code: string;\n data?: Array<{\n basic: Array<{\n ccy: string;\n rate: string;\n quota: string;\n }>;\n vip: Array<{\n loanQuotaCoef: string;\n level: string;\n }>;\n regular: Array<{\n loanQuotaCoef: string;\n level: string;\n }>;\n }>;\n }> => this.request('GET', '/api/v5/public/interest-rate-loan-quota');\n\n /**\n * 获取交易产品基础信息\n *\n * 获取所有可交易产品的信息列表。\n *\n * 限速:20次/2s\n * 限速规则:IP +instType\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-instruments\n */\n getInstruments = (params: {\n instType: string;\n uly?: string;\n instFamily?: string;\n instId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n alias: string;\n baseCcy: string;\n category: string;\n ctMult: string;\n ctType: string;\n ctVal: string;\n ctValCcy: string;\n expTime: string;\n instFamily: string;\n instId: string;\n instType: string;\n lever: string;\n listTime: string;\n lotSz: string;\n maxIcebergSz: string;\n maxLmtAmt: string;\n maxLmtSz: string;\n maxMktAmt: string;\n maxMktSz: string;\n maxStopSz: string;\n maxTriggerSz: string;\n maxTwapSz: string;\n minSz: string;\n optType: string;\n quoteCcy: string;\n settleCcy: string;\n state: string;\n stk: string;\n tickSz: string;\n uly: string;\n }>;\n }> => this.request('GET', '/api/v5/public/instruments', params);\n\n /**\n * 获取永续合约当前资金费率\n * 获取当前资金费率\n *\n * 限速:20次/2s\n * 限速规则:IP +instrumentID\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-funding-rate\n */\n getFundingRate = (params: {\n instId: string;\n }): Promise<{\n code: string;\n data: Array<{\n fundingRate: string;\n fundingTime: string;\n instId: string;\n instType: string;\n method: string;\n maxFundingRate: string;\n minFundingRate: string;\n nextFundingRate: string;\n nextFundingTime: string;\n premium: string;\n settFundingRate: string;\n settState: string;\n ts: string;\n }>;\n msg: string;\n }> => this.request('GET', '/api/v5/public/funding-rate', params);\n\n /**\n * 获取永续合约历史资金费率\n *\n * 获取最近3个月的历史资金费率\n *\n * 限速:10次/2s\n * 限速规则:IP +instrumentID\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-funding-rate-history\n */\n getFundingRateHistory = (params: {\n instId: string;\n before?: string;\n after?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n fundingRate: string;\n fundingTime: string;\n instId: string;\n instType: string;\n method: string;\n realizedRate: string;\n }>;\n }> => this.request('GET', '/api/v5/public/funding-rate-history', params);\n\n /**\n * 获取标记价格历史K线数据\n *\n * 获取最近几年的标记价格K线数据\n *\n * 限速:10次/2s\n * 限速规则:IP\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-mark-price-candlesticks-history\n */\n getHistoryMarkPriceCandles = (params: {\n instId: string;\n bar?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<[ts: string, o: string, h: string, l: string, c: string, confirm: string]>;\n }> => this.request('GET', '/api/v5/market/history-mark-price-candles', params);\n\n /**\n * GET / 获取交易产品历史K线数据\n *\n * 获取最近几年的历史k线数据(1s k线支持查询最近3个月的数据)\n *\n * 限速:20次/2s\n *\n * 限速规则:IP\n *\n * 期权不支持 1s K线, 其他业务线 (币币, 杠杆, 交割和永续)支持\n */\n getHistoryCandles = (params: {\n instId: string;\n bar?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<\n [\n ts: string,\n o: string,\n h: string,\n l: string,\n c: string,\n vol: string,\n volCcy: string,\n volCcyQuote: string,\n confirm: string,\n ]\n >;\n }> => this.request('GET', '/api/v5/market/history-candles', params);\n\n /**\n * 获取余币宝余额\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#financial-product-savings-get-saving-balance\n */\n getFinanceSavingsBalance = (params: {\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n earnings: string;\n redemptAmt: string;\n rate: string;\n ccy: string;\n amt: string;\n loanAmt: string;\n pendingAmt: string;\n }[];\n }> => this.request('GET', '/api/v5/finance/savings/balance', params);\n\n /**\n * 余币宝申购/赎回\n *\n * 仅资金账户中的资产支持余币宝申购。\n *\n * 限速:6次/s\n *\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#financial-product-savings-post-savings-purchase-redemption\n */\n postFinanceSavingsPurchaseRedempt = (params: {\n ccy: string;\n amt: string;\n side: string;\n rate: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n ccy: string;\n amt: string;\n side: string;\n rate: string;\n }[];\n }> => this.request('POST', '/api/v5/finance/savings/purchase-redempt', params);\n\n /**\n * GET / 获取市场借贷历史(公共)\n *\n * 公共接口无须鉴权\n *\n * 返回2021年12月14日后的记录\n *\n * 限速:6次/s\n * 限速规则:IP\n *\n * https://www.okx.com/docs-v5/zh/#financial-product-savings-get-public-borrow-history-public\n */\n getLendingRateHistory = (params: {\n ccy?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n ccy: string;\n amt: string;\n rate: string;\n ts: string;\n }>;\n }> => this.request('GET', '/api/v5/finance/savings/lending-rate-history', params);\n\n /**\n * 提币\n *\n * 用户提币。普通子账户不支持提币。\n *\n * API只能提币到免认证地址/账户上,通过 WEB/APP 可以设置免认证地址。\n *\n * 关于标签:某些币种如XRP充币时同时需要一个充值地址和标签(又名memo/payment_id),标签是一种保证您的充币地址唯一性的数字串,与充币地址成对出现并一一对应。请您务必遵守正确的充值步骤,在提币时输入完整信息,否则将面临丢失币的风险!\n * 对于有标签的币种,如果是OKX用户间的提币,请走内部转账不要走链上提币。\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-withdrawal\n */\n postAssetWithdrawal = (params: {\n amt: string;\n fee: string;\n dest: string;\n ccy: string;\n chain?: string;\n toAddr: string;\n clientId?: string;\n rcvrInfo?: {\n walletType: string;\n exchId: string;\n rcvrFirstName: string;\n rcvrLastName: string;\n };\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n amt: string;\n wdId: string;\n ccy: string;\n clientId: string;\n chain: string;\n }>;\n }> => this.request('POST', '/api/v5/asset/withdrawal', params);\n\n /**\n * 获取充值地址信息\n *\n * 获取各个币种的充值地址,包括曾使用过的老地址。\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-deposit-address\n */\n getAssetDepositAddress = (params: {\n ccy: string;\n }): Promise<{\n code: string;\n data: {\n chain: string;\n ctAddr: string;\n ccy: string;\n to: string;\n addr: string;\n verifiedName: string;\n selected: boolean;\n }[];\n msg: string;\n }> => this.request('GET', '/api/v5/asset/deposit-address', params);\n\n /**\n * 获取提币记录\n *\n * 根据币种,提币状态,时间范围获取提币记录,按照时间倒序排列,默认返回100条数据。\n * 支持Websocket订阅,参考 提币信息频道。\n *\n * 限速:6 次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-withdrawal-history\n */\n getAssetWithdrawalHistory = (params: {\n ccy?: string;\n wdId?: string;\n clientId?: string;\n txId?: string;\n type?: string;\n state?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n chain: string;\n fee: string;\n feeCcy: string;\n ccy: string;\n clientId: string;\n amt: string;\n txId: string;\n from: string;\n areaCodeFrom: string;\n to: string;\n areaCodeTo: string;\n state: string;\n ts: string;\n nonTradableAsset: boolean;\n wdId: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/withdrawal-history', params);\n\n /**\n * 获取充值记录\n *\n * 根据币种,充值状态,时间范围获取充值记录,按照时间倒序排列,默认返回 100 条数据。\n * 支持Websocket订阅,参考 充值信息频道。\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-deposit-history\n */\n getAssetDepositHistory = (params: {\n ccy?: string;\n depId?: string;\n state?: string;\n fromWdId?: string;\n txId?: string;\n type?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n actualDepBlkConfirm: string;\n amt: string;\n areaCodeFrom: string;\n ccy: string;\n chain: string;\n depId: string;\n from: string;\n fromWdId: string;\n state: string;\n to: string;\n ts: string;\n txId: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/deposit-history', params);\n\n /**\n * 获取资金账户余额\n *\n * 获取资金账户所有资产列表,查询各币种的余额、冻结和可用等信息。\n *\n * 只返回余额大于0的币资产信息。\n *\n * 限速:6次/s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-balance\n */\n getAssetBalances = (params: {\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n availBal: string;\n bal: string;\n ccy: string;\n frozenBal: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/balances', params);\n\n /**\n * 资金划转\n *\n * 调用时,API Key 需要有交易权限。\n *\n * 支持母账户的资金账户划转到交易账户,母账户到子账户的资金账户和交易账户划转。\n *\n * 子账户默认可转出至母账户,划转到同一母账户下的其他子账户,需要先调用 设置子账户主动转出权限 接口进行授权。\n *\n * 请求失败不代表划转失败,建议以获取资金划转状态接口返回的状态为准。\n *\n * 限速:2 次/s\n * 限速规则:UserID + Currency\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-funds-transfer\n */\n postAssetTransfer = (params: {\n ccy: string;\n type?: string;\n amt: string;\n from: string;\n to: string;\n subAcct?: string;\n loanTrans?: boolean;\n omitPosRisk?: string;\n clientId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n transId: string;\n ccy: string;\n clientId: string;\n from: string;\n amt: string;\n to: string;\n }[];\n }> => this.request('POST', '/api/v5/asset/transfer', params);\n\n /**\n * 查看账户余额\n *\n * 获取交易账户中资金余额信息。\n *\n * 免息额度和折算率都是公共数据,不在账户接口内展示\n *\n * 限速:10次/2s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-balance\n */\n getAccountBalance = (params: {\n ccy?: string;\n }): Promise<{\n code: string;\n data: {\n adjEq: string;\n borrowFroz: string;\n details: {\n availBal: string;\n availEq: string;\n borrowFroz: string;\n cashBal: string;\n ccy: string;\n crossLiab: string;\n disEq: string;\n eq: string;\n eqUsd: string;\n fixedBal: string;\n frozenBal: string;\n imr: string;\n interest: string;\n isoEq: string;\n isoLiab: string;\n isoUpl: string;\n liab: string;\n maxLoan: string;\n mgnRatio: string;\n mmr: string;\n notionalLever: string;\n ordFrozen: string;\n rewardBal: string;\n spotInUseAmt: string;\n spotIsoBal: string;\n stgyEq: string;\n twap: string;\n uTime: string;\n upl: string;\n uplLiab: string;\n openAvgPx: string;\n spotUpl: string;\n accAvgPx: string;\n totalPnl: string;\n spotBal: string;\n }[];\n imr: string;\n isoEq: string;\n mgnRatio: string;\n mmr: string;\n notionalUsd: string;\n ordFroz: string;\n totalEq: string;\n uTime: string;\n upl: string;\n }[];\n msg: string;\n }> => this.request('GET', '/api/v5/account/balance', params);\n\n /**\n * 查看持仓信息\n *\n * 获取该账户下拥有实际持仓的信息。账户为买卖模式会显示净持仓(net),账户为开平仓模式下会分别返回开多(long)或开空(short)的仓位。按照仓位创建时间倒序排列。\n *\n * 如果该 instId 拥有过仓位且当前持仓量为0,传 instId 时,如果当前存在有效的posId,会返回仓位信息,如果当前不存在有效的 posId 时,不会返回仓位信息;不传 instId 时,仓位信息不返回。\n *\n * 逐仓交易设置中,如果设置为自主划转模式,逐仓转入保证金后,会生成一个持仓量为0的仓位\n *\n * 限速:10次/2s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-positions\n */\n getAccountPositions = (params: {\n instType?: string;\n instId?: string;\n posId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n adl: string;\n availPos: string;\n avgPx: string;\n cTime: string;\n ccy: string;\n deltaBS: string;\n deltaPA: string;\n gammaBS: string;\n gammaPA: string;\n imr: string;\n instId: string;\n instType: string;\n interest: string;\n idxPx: string;\n last: string;\n usdPx: string;\n bePx: string;\n lever: string;\n liab: string;\n liabCcy: string;\n liqPx: string;\n markPx: string;\n margin: string;\n mgnMode: string;\n mgnRatio: string;\n mmr: string;\n notionalUsd: string;\n optVal: string;\n pTime: string;\n pos: string;\n posCcy: string;\n posId: string;\n posSide: string;\n spotInUseAmt: string;\n spotInUseCcy: string;\n thetaBS: string;\n thetaPA: string;\n tradeId: string;\n bizRefId: string;\n bizRefType: string;\n quoteBal: string;\n baseBal: string;\n baseBorrowed: string;\n baseInterest: string;\n quoteBorrowed: string;\n quoteInterest: string;\n uTime: string;\n upl: string;\n uplLastPx: string;\n uplRatio: string;\n uplRatioLastPx: string;\n vegaBS: string;\n vegaPA: string;\n realizedPnl: string;\n pnl: string;\n fee: string;\n fundingFee: string;\n liqPenalty: string;\n closeOrderAlgo: {\n algoId: string;\n slTriggerPx: string;\n slTriggerPxType: string;\n tpTriggerPx: string;\n tpTriggerPxType: string;\n closeFraction: string;\n }[];\n }[];\n }> => this.request('GET', '/api/v5/account/positions', params);\n\n /**\n * 赚币\n * GET / 查看项目\n *\n * 限速:3次/s\n * 限速规则:UserID\n */\n getFinanceStakingDeFiOffers = (params: {\n productId?: string;\n protocolType?: string;\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n ccy: string;\n productId: string;\n protocol: string;\n protocolType: string;\n term: string;\n apy: string;\n earlyRedeem: boolean;\n investData: {\n ccy: string;\n bal: string;\n minAmt: string;\n maxAmt: string;\n }[];\n earningData: {\n ccy: string;\n earningType: string;\n }[];\n state: string;\n earningCcy?: string[];\n }[];\n }> => this.request('GET', '/api/v5/finance/staking-defi/offers', params);\n\n /**\n * 赚币\n * GET / 查看活跃订单\n *\n * 限速:3次/s\n * 限速规则:UserID\n */\n getFinanceStakingDeFiOrdersActive = (params: {\n productId?: string;\n protocolType?: string;\n ccy?: string;\n state?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n ordId: string;\n state: string;\n ccy: string;\n protocol: string;\n protocolType: string;\n term: string;\n apy: string;\n investData: {\n ccy: string;\n amt: string;\n minAmt?: string;\n maxAmt?: string;\n }[];\n earningData: {\n ccy: string;\n earningType: string;\n earnings: string;\n }[];\n purchasedTime: string;\n estSettlementTime: string;\n cancelRedemptionDeadline: string;\n tag: string;\n earningCcy?: string[];\n }[];\n }> => this.request('GET', '/api/v5/finance/staking-defi/orders-active', params);\n\n /**\n * 下单\n *\n * 只有当您的账户有足够的资金才能下单。\n *\n * 限速:60次/2s\n *\n * 跟单交易带单产品的限速:4次/2s\n *\n * 限速规则(期权以外):UserID + Instrument ID\n *\n * 限速规则(只限期权):UserID + Instrument Family\n *\n * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-place-order\n */\n postTradeOrder = (params: {\n instId: string;\n tdMode: string;\n ccy?: string;\n clOrdId?: string;\n tag?: string;\n side: string;\n posSide?: string;\n ordType: string;\n sz: string;\n px?: string;\n pxUsd?: string;\n pxVol?: string;\n reduceOnly?: string;\n tgtCcy?: string;\n banAmend?: string;\n quickMgnType?: string;\n stpId?: string;\n stpMode?: string;\n attachAlgoOrds?: Array<{\n attachAlgoClOrdId?: string;\n tpTriggerPx?: string;\n tpOrdPx?: string;\n tpOrdKind?: string;\n slTriggerPx?: string;\n slOrdPx?: string;\n tpTriggerPxType?: string;\n slTriggerPxType?: string;\n sz?: string;\n amendPxOnTriggerType?: string;\n }>;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n clOrdId: string;\n ordId: string;\n tag: string;\n sCode: string;\n sMsg: string;\n }[];\n inTime: string;\n outTime: string;\n }> => this.request('POST', '/api/v5/trade/order', params);\n\n /**\n * 修改订单\n *\n * 修改当前未成交的挂单\n *\n * 限速:60次/2s\n *\n * 跟单交易带单员带单产品的限速:4个/2s\n *\n * 限速规则:User ID + Instrument ID\n *\n * 权限:交易\n *\n * 该接口限速同时受到 子账户限速 及 基于成交比率的子账户限速 限速规则的影响。\n *\n * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-amend-order\n */\n postTradeAmendOrder = (params: {\n instId: string;\n cxIOnFail?: boolean;\n ordId?: string;\n clOrdId?: string;\n reqId?: string;\n newSz?: string;\n newPx?: string;\n newPxUsd?: string;\n newPxVol?: string;\n attachAlgoOrds?: Array<{\n attachAlgoId?: string;\n attachAlgoClOrdId?: string;\n newTpTriggerPx?: string;\n newTpOrdPx?: string;\n newTpOrdKind?: string;\n newSlTriggerPx?: string;\n newSlOrdPx?: string;\n newTpTriggerPxType?: string;\n newSlTriggerPxType?: string;\n sz?: string;\n amendPxOnTriggerType?: string;\n }>;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n clOrdId: string;\n ordId: string;\n ts: string;\n reqId: string;\n sCode: string;\n sMsg: string;\n }[];\n inTime: string;\n outTime: string;\n }> => this.request('POST', '/api/v5/trade/amend-order', params);\n\n /**\n * 获取未成交订单列表\n *\n * 获取当前账户下所有未成交订单信息\n *\n * 限速:60次/2s\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-get-order-list\n */\n getTradeOrdersPending = (params: {\n instType?: string;\n uly?: string;\n instFamily?: string;\n instId?: string;\n ordType?: string;\n state?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n accFillSz: string;\n avgPx: string;\n cTime: string;\n category: string;\n ccy: string;\n clOrdId: string;\n fee: string;\n feeCcy: string;\n fillPx: string;\n fillSz: string;\n fillTime: string;\n instId: string;\n instType: string;\n lever: string;\n ordId: string;\n ordType: string;\n pnl: string;\n posSide: string;\n px: string;\n pxUsd: string;\n pxVol: string;\n pxType: string;\n rebate: string;\n rebateCcy: string;\n side: string;\n attachAlgoClOrdId: string;\n slOrdPx: string;\n slTriggerPx: string;\n slTriggerPxType: string;\n attachAlgoOrds: any[];\n source: string;\n state: string;\n stpId: string;\n stpMode: string;\n sz: string;\n tag: string;\n tdMode: string;\n tgtCcy: string;\n tpOrdPx: string;\n tpTriggerPx: string;\n tpTriggerPxType: string;\n tradeId: string;\n reduceOnly: string;\n quickMgnType: string;\n algoClOrdId: string;\n algoId: string;\n isTpLimit: string;\n uTime: string;\n }[];\n }> => this.request('GET', '/api/v5/trade/orders-pending', params);\n\n /**\n * 获取历史订单记录(近七天)\n *\n * 获取最近7天挂单,且完成的订单数据,包括7天以前挂单,但近7天才成交的订单数据。按照订单创建时间倒序排序。\n *\n * 已经撤销的未成交单 只保留2小时\n * 限速:40次/2s\n * 限速规则:User ID\n */\n getTradeOrdersHistory = (params: {\n instType: string;\n uly?: string;\n instFamily?: string;\n instId?: string;\n ordType?: string;\n state?: string;\n category?: string;\n after?: string;\n before?: string;\n begin?: string;\n end?: string;\n limit?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: Array<{\n instType: string;\n instId: string;\n tgtCcy: string;\n ccy: string;\n ordId: string;\n clOrdId: string;\n tag: string;\n px: string;\n pxUsd: string;\n pxVol: string;\n pxType: string;\n sz: string;\n ordType: string;\n side: string;\n posSide: string;\n tdMode: string;\n accFillSz: string;\n fillPx: string;\n tradeId: string;\n fillSz: string;\n fillTime: string;\n avgPx: string;\n state: string;\n lever: string;\n attachAlgoClOrdId: string;\n tpTriggerPx: string;\n tpTriggerPxType: string;\n tpOrdPx: string;\n slTriggerPx: string;\n slTriggerPxType: string;\n slOrdPx: string;\n attachAlgoOrds: any[];\n linkedAlgoOrd: any[];\n stpId: string;\n stpMode: string;\n feeCcy: string;\n fee: string;\n rebateCcy: string;\n source: string;\n rebate: string;\n pnl: string;\n category: string;\n reduceOnly: string;\n cancelSource: string;\n cancelSourceReason: string;\n algoClOrdId: string;\n algoId: string;\n isTpLimit: string;\n uTime: string;\n cTime: string;\n tradeQuoteCcy: string;\n }>;\n }> => this.request('GET', '/api/v5/trade/orders-history', params);\n\n /**\n * 撤单\n *\n * 撤销之前下的未完成订单。\n *\n * 限速:60次/2s\n *\n * 限速规则(期权以外):UserID + Instrument ID\n *\n * 限速规则(只限期权):UserID + Instrument Family\n *\n * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-cancel-order\n */\n postTradeCancelOrder = (params: {\n instId: string;\n ordId?: string;\n clOrdId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n clOrdId: string;\n ordId: string;\n sCode: string;\n sMsg: string;\n }[];\n inTime: string;\n outTime: string;\n }> => this.request('POST', '/api/v5/trade/cancel-order', params);\n\n /**\n * 查看子账户列表\n *\n * 仅适用于母账户。\n *\n * 限速:2次/2s\n *\n * 限速规则:UserID\n */\n getSubAccountList = (params?: {\n enable?: string;\n subAct?: string;\n after?: string;\n before?: string;\n limit?: string;\n }): Promise<{\n data: {\n type: string;\n enable: string;\n subAcct: string;\n uid: string;\n label: string;\n mobile: string;\n gAuth: boolean;\n frozenFunc: string[];\n canTransOut: boolean;\n ts: string;\n }[];\n code: string;\n msg: string;\n }> => this.request('GET', '/api/v5/users/subaccount/list', params);\n\n /**\n * 设置子账户主动转出权限\n *\n * 设置子账户转出权限(仅适用于母账户),默认可转出至母账户。\n *\n * 限速:1次/s\n *\n * 限速规则:UserID\n */\n postSetSubAccountTransferOut = (params: {\n subAcct: string;\n canTransOut: boolean;\n }): Promise<{\n subAcct: string;\n canTransOut: boolean;\n }> => this.request('POST', '/api/v5/users/subaccount/set-transfer-out', params);\n\n /**\n * 获取资金划转状态\n *\n * 获取最近2个星期内的资金划转状态数据\n *\n * 限速:10 次/s\n *\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-funds-transfer-state\n */\n getAssetTransferState = (params: {\n transId?: string;\n clientId?: string;\n type?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n transId: string;\n clientId: string;\n ccy: string;\n amt: string;\n type: string;\n from: string;\n to: string;\n subAcct: string;\n // success | pending | failed\n state: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/transfer-state', params);\n\n /**\n * 获取币种列表\n *\n * 获取当前用户KYC实体支持的币种列表。\n *\n * 限速:6 次/s\n *\n * 限速规则:UserID\n *\n * https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-currencies\n */\n getAssetCurrencies = (params?: {\n ccy?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n ccy: string;\n name: string;\n chain: string;\n canWd: boolean;\n canInternal: boolean;\n minWd: string;\n maxWd: string;\n wdTickSz: string;\n wdQuota: string;\n usedWdQuota: string;\n minFee: string;\n maxFee: string;\n }[];\n }> => this.request('GET', '/api/v5/asset/currencies', params);\n\n /**\n * 获取指数行情数据\n *\n *\n * 限速:20 次/2s\n *\n *\n * https://www.okx.com/docs-v5/zh/#public-data-rest-api-get-index-tickers\n */\n getMarketIndexTicker = (params?: {\n quoteCcy?: string;\n instId?: string;\n }): Promise<{\n code: string;\n msg: string;\n data: {\n instId: string;\n idxPx: string;\n high24h: string;\n sodUtc0: string;\n open24h: string;\n low24h: string;\n sodUtc8: string;\n ts: string;\n }[];\n }> => this.request('GET', '/api/v5/market/index-tickers', params);\n\n /**\n * 账单流水查询(近七天)\n *\n *\n * 限速:5次/s\n *\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-bills-details-last-7-days\n */\n getAccountBills = (params?: {\n instType?: string;\n instId?: string;\n ccy?: string;\n mgnMode?: 'isolated' | 'cross';\n ctType?: 'linear' | 'inverse';\n type?: AccountBillType;\n subType?: string;\n after?: string; //请求此id之前(更旧的数据)的分页内容,传的值为对应接口的billId\n before?: string; //请求此id之后(更新的数据)的分页内容,传的值为对应接口的billId\n begin?: string; //筛选的开始时间戳 ts,Unix 时间戳为毫秒数格式,如 1597026383085\n end?: string;\n limit?: string; //分页返回的结果集数量,最大为100,不填默认返回100条\n }): Promise<{\n code: string;\n msg: string;\n data: {\n instType: string;\n billId: string;\n type: string;\n subType: string;\n ts: string;\n balChg: string;\n posBalChg: string;\n bal: string;\n posBal: string;\n sz: string;\n px: string;\n ccy: string;\n pnl: string;\n fee: string;\n mgnMode: 'isolated' | 'cross' | 'cash' | '';\n instId: string;\n ordId: string;\n execType: string;\n from: string;\n to: string;\n notes: string;\n interest: string;\n tag: string;\n fillTime: string;\n tradeId: string;\n clOrdId: string;\n fillIdxPx: string;\n fillMarkPx: string;\n fillPxVol: string;\n fillPxUsd: string;\n fillMarkVol: string;\n fillFwdPx: string;\n }[];\n }> => this.request('GET', '/api/v5/account/bills', params);\n\n /**\n * 账单流水查询(近三个月)\n *\n *\n * 限速:5次/2s\n *\n *\n * https://www.okx.com/docs-v5/zh/#trading-account-rest-api-get-bills-details-last-3-months\n */\n getAccountBillsArchive = (params?: {\n instType?: string;\n instId?: string;\n ccy?: string;\n mgnMode?: 'isolated' | 'cross';\n ctType?: 'linear' | 'inverse';\n type?: AccountBillType;\n subType?: string;\n after?: string; //请求此id之前(更旧的数据)的分页内容,传的值为对应接口的billId\n before?: string; //请求此id之后(更新的数据)的分页内容,传的值为对应接口的billId\n begin?: string; //筛选的开始时间戳 ts,Unix 时间戳为毫秒数格式,如 1597026383085\n end?: string;\n limit?: string; //分页返回的结果集数量,最大为100,不填默认返回100条\n }): Promise<{\n code: string;\n msg: string;\n data: {\n instType: string;\n billId: string;\n type: string;\n subType: string;\n ts: string;\n balChg: string;\n posBalChg: string;\n bal: string;\n posBal: string;\n sz: string;\n px: string;\n ccy: string;\n pnl: string;\n fee: string;\n mgnMode: 'isolated' | 'cross' | 'cash' | '';\n instId: string;\n ordId: string;\n execType: string;\n from: string;\n to: string;\n notes: string;\n interest: string;\n tag: string;\n fillTime: string;\n tradeId: string;\n clOrdId: string;\n fillIdxPx: string;\n fillMarkPx: string;\n fillPxVol: string;\n fillPxUsd: string;\n fillMarkVol: string;\n fillFwdPx: string;\n }[];\n }> => this.request('GET', '/api/v5/account/bills-archive', params);\n}\n\ntype AccountBillType =\n | '1'\n | '2'\n | '3'\n | '4'\n | '5'\n | '6'\n | '7'\n | '8'\n | '9'\n | '10'\n | '11'\n | '12'\n | '13'\n | '14'\n | '15'\n | '16'\n | '22'\n | '24'\n | '26'\n | '27'\n | '28'\n | '29'\n | '30'\n | '32'\n | '33'\n | '34'\n | '250'\n | '251';\n\nexport const client = new OkxClient({\n auth: {\n public_key: process.env.ACCESS_KEY!,\n secret_key: process.env.SECRET_KEY!,\n passphrase: process.env.PASSPHRASE!,\n },\n});\n"]}
@@ -398,6 +398,8 @@ defer(async () => {
398
398
  return 'limit';
399
399
  case 'MARKET':
400
400
  return 'market';
401
+ case 'MAKER':
402
+ return 'post_only';
401
403
  }
402
404
  throw new Error(`Unknown order type: ${order_type}`);
403
405
  };
@@ -415,6 +417,9 @@ defer(async () => {
415
417
  if (order.order_type === 'LIMIT') {
416
418
  return order.volume;
417
419
  }
420
+ if (order.order_type === 'MAKER') {
421
+ return order.volume;
422
+ }
418
423
  if (order.order_type === 'MARKET') {
419
424
  if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {
420
425
  return order.volume;
@@ -501,6 +506,9 @@ defer(async () => {
501
506
  if (order.order_type === 'LIMIT') {
502
507
  params.newSz = order.volume.toString();
503
508
  }
509
+ if (order.order_type === 'MAKER') {
510
+ params.newSz = order.volume.toString();
511
+ }
504
512
  if (order.order_type === 'MARKET') {
505
513
  // 对于市价单,可能需要根据当前价格计算新的数量
506
514
  const price = await firstValueFrom(spotMarketTickers$.pipe(map((x) => order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'
@@ -1 +1 @@
1
- {"version":3,"file":"legacy_index.js","sourceRoot":"","sources":["../src/legacy_index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACtG,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,EA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CACL,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport { decodePath, encodePath, formatTime, roundToStep } from '@yuants/utils';\nimport { defer, filter, firstValueFrom, from, map, mergeMap, repeat, retry, shareReplay } from 'rxjs';\nimport { accountConfig$, tradingAccountInfo$ } from './account';\nimport { client } from './api';\nimport { mapProductIdToMarginProduct$ } from './product';\nimport { spotMarketTickers$ } from './quote';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconsole.info(formatTime(Date.now()), 'Terminal', terminal.terminalInfo.terminal_id);\n\nconst resOfAssetCurrencies = defer(() => client.getAssetCurrencies()).pipe(\n repeat({ delay: 3600_000 }),\n retry({ delay: 10_000 }),\n shareReplay(1),\n);\n\nresOfAssetCurrencies.subscribe(); // make it hot\n\nconst memoizeMap = <T extends (...params: any[]) => any>(fn: T): T => {\n const cache: Record<string, any> = {};\n return ((...params: any[]) => (cache[encodePath(params)] ??= fn(...params))) as T;\n};\n\nconst fundingRate$ = memoizeMap((product_id: string) =>\n defer(() => client.getFundingRate({ instId: decodePath(product_id)[1] })).pipe(\n mergeMap((x) => x.data),\n repeat({ delay: 5000 }),\n retry({ delay: 5000 }),\n shareReplay(1),\n ),\n);\n\nconst interestRateLoanQuota$ = defer(() => client.getInterestRateLoanQuota()).pipe(\n repeat({ delay: 60_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\nconst interestRateByCurrency$ = memoizeMap((currency: string) =>\n interestRateLoanQuota$.pipe(\n mergeMap((x) =>\n from(x.data || []).pipe(\n mergeMap((x) => x.basic),\n filter((x) => x.ccy === currency),\n map((x) => +x.rate),\n ),\n ),\n shareReplay(1),\n ),\n);\n\n// provideTicks(terminal, 'OKX', (product_id) => {\n// const [instType, instId] = decodePath(product_id);\n// if (instType === 'SWAP') {\n// return defer(async () => {\n// const products = await firstValueFrom(usdtSwapProducts$);\n// const theProduct = products.find((x) => x.product_id === product_id);\n// if (!theProduct) throw `No Found ProductID ${product_id}`;\n// const theTicker$ = swapMarketTickers$.pipe(\n// map((x) => x[instId]),\n// shareReplay(1),\n// );\n// return [of(theProduct), theTicker$, fundingRate$(product_id), swapOpenInterest$] as const;\n// }).pipe(\n// catchError(() => EMPTY),\n// mergeMap((x) =>\n// combineLatest(x).pipe(\n// map(([theProduct, ticker, fundingRate, swapOpenInterest]): ITick => {\n// return {\n// datasource_id: 'OKX',\n// product_id,\n// updated_at: Date.now(),\n// settlement_scheduled_at: +fundingRate.fundingTime,\n// price: +ticker.last,\n// ask: +ticker.askPx,\n// bid: +ticker.bidPx,\n// volume: +ticker.lastSz,\n// interest_rate_for_long: -+fundingRate.fundingRate,\n// interest_rate_for_short: +fundingRate.fundingRate,\n// open_interest: swapOpenInterest.get(instId),\n// };\n// }),\n// ),\n// ),\n// );\n// }\n// if (instType === 'MARGIN') {\n// return defer(async () => {\n// const products = await firstValueFrom(marginProducts$);\n// const theProduct = products.find((x) => x.product_id === product_id);\n// if (!theProduct) throw `No Found ProductID ${product_id}`;\n// const theTicker$ = spotMarketTickers$.pipe(\n// map((x) => x[instId]),\n// shareReplay(1),\n// );\n// return [\n// of(theProduct),\n// theTicker$,\n// interestRateByCurrency$(theProduct.base_currency!),\n// interestRateByCurrency$(theProduct.quote_currency!),\n// ] as const;\n// }).pipe(\n// catchError(() => EMPTY),\n// mergeMap((x) =>\n// combineLatest(x).pipe(\n// map(\n// ([theProduct, ticker, interestRateForBase, interestRateForQuote]): ITick => ({\n// datasource_id: 'OKX',\n// product_id,\n// updated_at: Date.now(),\n// price: +ticker.last,\n// volume: +ticker.lastSz,\n// // 在下一个整点扣除利息 See 如何计算利息 https://www.okx.com/zh-hans/help/how-to-calculate-borrowing-interest\n// settlement_scheduled_at: new Date().setMinutes(0, 0, 0) + 3600_000,\n// interest_rate_for_long: -interestRateForQuote / 24,\n// interest_rate_for_short: -interestRateForBase / 24,\n// }),\n// ),\n// ),\n// ),\n// );\n// }\n// return EMPTY;\n// });\n\ndefer(async () => {\n const account_config = await firstValueFrom(accountConfig$);\n console.info(formatTime(Date.now()), 'AccountConfig', JSON.stringify(account_config));\n const { mainUid, uid } = account_config.data[0];\n const isMainAccount = mainUid === uid;\n\n const TRADING_ACCOUNT_ID = `okx/${uid}/trading`;\n const FUNDING_ACCOUNT_ID = `okx/${uid}/funding/USDT`;\n const EARNING_ACCOUNT_ID = `okx/${uid}/earning/USDT`;\n\n // BLOCK_CHAIN: only available for main account\n if (isMainAccount) {\n const depositAddressRes = await client.getAssetDepositAddress({ ccy: 'USDT' });\n console.info(formatTime(Date.now()), 'DepositAddress', JSON.stringify(depositAddressRes.data));\n const addresses = depositAddressRes.data.filter((v) => v.chain === 'USDT-TRC20' && v.to === '6');\n for (const address of addresses) {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: 'TRC20',\n currency: 'USDT',\n address: address.addr,\n onApply: {\n INIT: async (order) => {\n if (\n !order.current_amount ||\n order.current_amount < 3 // 最小提币额度\n ) {\n return { state: 'ERROR', message: 'Amount too small' };\n }\n const res = await firstValueFrom(resOfAssetCurrencies);\n const theRes = res.data?.find((x) => x.ccy === 'USDT' && x.chain === 'USDT-TRC20');\n const _fee = theRes?.minFee;\n if (!_fee) return { state: 'ERROR', message: 'Currency Info not found, cannot get fee' };\n const fee = +_fee;\n const amt = Math.floor(order.current_amount - fee);\n const transferResult = await client.postAssetWithdrawal({\n amt: `${amt}`,\n ccy: 'USDT',\n chain: 'USDT-TRC20',\n fee: `${fee}`,\n dest: '4', // 链上提币\n toAddr: order.current_rx_address!,\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const wdId = transferResult.data[0]?.wdId;\n return { state: 'AWAIT_TX_ID', context: wdId };\n },\n AWAIT_TX_ID: async (transferOrder) => {\n const wdId = transferOrder.current_tx_context;\n const withdrawalHistory = await client.getAssetWithdrawalHistory({ wdId });\n const txId = withdrawalHistory.data?.[0]?.txId;\n if (!txId) {\n return { state: 'AWAIT_TX_ID', context: wdId };\n }\n return { state: 'COMPLETE', transaction_id: txId };\n },\n },\n onEval: async (transferOrder) => {\n const checkResult = await client.getAssetDepositHistory({\n ccy: 'USDT',\n txId: transferOrder.current_transaction_id,\n type: '4',\n });\n\n if (checkResult.code !== '0') {\n return {\n state: 'INIT',\n };\n }\n\n if (checkResult.data[0].state !== '2') {\n return { state: 'PENDING' };\n }\n const received_amount = +checkResult.data[0].amt;\n return { state: 'COMPLETE', received_amount };\n },\n });\n }\n }\n\n // Funding-Trading\n {\n const FUNDING_TRADING_NETWORK_ID = `OKX/${uid}/Funding-Trading`;\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: FUNDING_TRADING_NETWORK_ID,\n currency: 'USDT',\n address: 'funding',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postAssetTransfer({\n type: '0',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '18',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n addAccountTransferAddress({\n terminal,\n account_id: TRADING_ACCOUNT_ID,\n network_id: FUNDING_TRADING_NETWORK_ID,\n currency: 'USDT',\n address: 'trading',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postAssetTransfer({\n type: '0',\n ccy: order.currency,\n amt: `${order.current_amount}`,\n from: '18',\n to: '6',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n }\n // Funding-Earning\n {\n const FUNDING_EARNING_NETWORK_ID = `OKX/${uid}/Funding-Earning`;\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: FUNDING_EARNING_NETWORK_ID,\n currency: 'USDT',\n address: 'funding',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postFinanceSavingsPurchaseRedempt({\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n side: 'purchase',\n rate: '0.01',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: 'ok' };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n addAccountTransferAddress({\n terminal,\n account_id: EARNING_ACCOUNT_ID,\n network_id: FUNDING_EARNING_NETWORK_ID,\n currency: 'USDT',\n address: 'earning',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postFinanceSavingsPurchaseRedempt({\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n side: 'redempt',\n rate: '0.01',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: 'ok' };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n }\n\n // SubAccount\n {\n const getSubAccountNetworkId = (subUid: string) => `OKX/${mainUid}/SubAccount/${subUid}`;\n if (isMainAccount) {\n const subAcctsRes = await client.getSubAccountList();\n for (const item of subAcctsRes.data || []) {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: getSubAccountNetworkId(item.uid),\n currency: 'USDT',\n address: 'main',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postAssetTransfer({\n type: '1',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '6',\n subAcct: item.subAcct,\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (order) => {\n // ISSUE: OKX API Issue: transId is incorrect or transId does not match with ‘ type’\n // const checkResult = await client.getAssetTransferState({ transId: order.current_transaction_id });\n // const received_amount = checkResult?.data?.[0]?.amt;\n // if (!received_amount) {\n // return { state: 'INIT', message: checkResult.msg };\n // }\n // return { state: 'COMPLETE', received_amount: +received_amount };\n\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n }\n }\n // SubAccount API\n else {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: getSubAccountNetworkId(uid),\n currency: 'USDT',\n address: 'sub',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postAssetTransfer({\n type: '3',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '6',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (order) => {\n // ISSUE: OKX API Issue: transId is incorrect or transId does not match with ‘ type’\n // const checkResult = await client.getAssetTransferState({ transId: order.current_transaction_id });\n // const received_amount = checkResult?.data?.[0]?.amt;\n // if (!received_amount) {\n // return { state: 'INIT', message: checkResult.msg };\n // }\n // return { state: 'COMPLETE', received_amount: +received_amount };\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n }\n }\n}).subscribe();\n\ndefer(async () => {\n const tradingAccountInfo = await firstValueFrom(tradingAccountInfo$);\n terminal.provideService(\n 'SubmitOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountInfo.account_id },\n },\n },\n async (msg) => {\n console.info(formatTime(Date.now()), 'SubmitOrder', JSON.stringify(msg));\n const order = msg.req;\n const [instType, instId] = decodePath(order.product_id);\n\n const mapOrderDirectionToSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'buy';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'sell';\n }\n throw new Error(`Unknown direction: ${direction}`);\n };\n const mapOrderDirectionToPosSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'long';\n case 'CLOSE_SHORT':\n case 'OPEN_SHORT':\n return 'short';\n }\n throw new Error(`Unknown direction: ${direction}`);\n };\n const mapOrderTypeToOrdType = (order_type?: string) => {\n switch (order_type) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n };\n\n // 交易数量,表示要购买或者出售的数量。\n // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。\n // 当币币杠杆以市价买入时,指计价货币的数量。\n // 当币币杠杆以市价卖出时,指交易货币的数量。\n // 对于币币市价单,单位由 tgtCcy 决定\n // 当交割、永续、期权买入和卖出时,指合约张数。\n const mapOrderVolumeToSz = async (order: IOrder) => {\n if (instType === 'SWAP') {\n return order.volume;\n }\n if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n return order.volume;\n }\n if (order.order_type === 'MARKET') {\n if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {\n return order.volume;\n }\n //\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n mapOrderDirectionToPosSide(order.order_direction) === 'long'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);\n const theProduct = await firstValueFrom(\n mapProductIdToMarginProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n return roundToStep(order.volume * price, theProduct.volume_step!);\n }\n\n return 0;\n }\n\n if (instType === 'SPOT') {\n return order.volume;\n }\n\n throw new Error(`Unknown instType: ${instType}`);\n };\n\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n instType === 'MARGIN' || instType === 'SPOT'\n ? 'net'\n : mapOrderDirectionToPosSide(order.order_direction),\n ordType: mapOrderTypeToOrdType(order.order_type),\n sz: (await mapOrderVolumeToSz(order)).toString(),\n tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,\n reduceOnly:\n instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes(order.order_direction ?? '')\n ? 'true'\n : undefined,\n px: order.order_type === 'LIMIT' ? order.price!.toString() : undefined,\n ccy: instType === 'MARGIN' ? 'USDT' : undefined,\n };\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const res = await client.postTradeOrder(params);\n if (res.code === '0' && res.data?.[0]?.ordId) {\n return {\n res: {\n code: 0,\n message: 'OK',\n data: {\n order_id: res.data[0].ordId,\n },\n },\n };\n }\n return { res: { code: +res.code, message: res.msg } };\n },\n );\n\n terminal.provideService(\n 'ModifyOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountInfo.account_id },\n },\n },\n async (msg) => {\n console.info(formatTime(Date.now()), 'ModifyOrder', JSON.stringify(msg));\n const order = msg.req;\n const [instType, instId] = decodePath(order.product_id);\n\n const params: any = {\n instId,\n ordId: order.order_id, // 使用现有订单ID\n };\n\n // 如果需要修改价格\n if (order.price !== undefined) {\n params.newPx = order.price.toString();\n }\n\n // 如果需要修改数量\n if (order.volume !== undefined) {\n // 处理数量修改,类似于 SubmitOrder 中的逻辑\n if (instType === 'SWAP') {\n params.newSz = order.volume.toString();\n } else if (instType === 'SPOT') {\n params.newSz = order.volume.toString();\n } else if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MARKET') {\n // 对于市价单,可能需要根据当前价格计算新的数量\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'ModifyOrder', 'price', price);\n const theProduct = await firstValueFrom(\n mapProductIdToMarginProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n params.newSz = roundToStep(order.volume * price, theProduct.volume_step!).toString();\n }\n } else {\n throw new Error(`Unknown instType: ${instType}`);\n }\n }\n\n console.info(formatTime(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));\n\n const res = await client.postTradeAmendOrder(params);\n if (res.code !== '0') {\n return {\n res: {\n code: +res.code,\n message: res.msg,\n },\n };\n }\n\n return { res: { code: 0, message: 'OK' } };\n },\n );\n\n terminal.provideService(\n 'CancelOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountInfo.account_id },\n },\n },\n (msg) =>\n defer(async () => {\n const order = msg.req;\n const [instType, instId] = decodePath(order.product_id);\n const res = await client.postTradeCancelOrder({\n instId,\n ordId: order.order_id,\n });\n if (res.code !== '0') {\n return { res: { code: +res.code, message: res.msg } };\n }\n return { res: { code: 0, message: 'OK' } };\n }),\n );\n}).subscribe();\n"]}
1
+ {"version":3,"file":"legacy_index.js","sourceRoot":"","sources":["../src/legacy_index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK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AE,kBAAkB,CAAC,UAAU,EAAE;SACrD;KACF,EACD,CAAC,GAAG,EAAE,EAAE,CACN,KAAK,CAAC,KAAK,IAAI,EAAE;QACf,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;QACtB,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACxD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC;YAC5C,MAAM;YACN,KAAK,EAAE,KAAK,CAAC,QAAQ;SACtB,CAAC,CAAC;QACH,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;YACpB,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC;SACvD;QACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;IAC7C,CAAC,CAAC,CACL,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport { decodePath, encodePath, formatTime, roundToStep } from '@yuants/utils';\nimport { defer, filter, firstValueFrom, from, map, mergeMap, repeat, retry, shareReplay } from 'rxjs';\nimport { accountConfig$, tradingAccountInfo$ } from './account';\nimport { client } from './api';\nimport { mapProductIdToMarginProduct$ } from './product';\nimport { spotMarketTickers$ } from './quote';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconsole.info(formatTime(Date.now()), 'Terminal', terminal.terminalInfo.terminal_id);\n\nconst resOfAssetCurrencies = defer(() => client.getAssetCurrencies()).pipe(\n repeat({ delay: 3600_000 }),\n retry({ delay: 10_000 }),\n shareReplay(1),\n);\n\nresOfAssetCurrencies.subscribe(); // make it hot\n\nconst memoizeMap = <T extends (...params: any[]) => any>(fn: T): T => {\n const cache: Record<string, any> = {};\n return ((...params: any[]) => (cache[encodePath(params)] ??= fn(...params))) as T;\n};\n\nconst fundingRate$ = memoizeMap((product_id: string) =>\n defer(() => client.getFundingRate({ instId: decodePath(product_id)[1] })).pipe(\n mergeMap((x) => x.data),\n repeat({ delay: 5000 }),\n retry({ delay: 5000 }),\n shareReplay(1),\n ),\n);\n\nconst interestRateLoanQuota$ = defer(() => client.getInterestRateLoanQuota()).pipe(\n repeat({ delay: 60_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\nconst interestRateByCurrency$ = memoizeMap((currency: string) =>\n interestRateLoanQuota$.pipe(\n mergeMap((x) =>\n from(x.data || []).pipe(\n mergeMap((x) => x.basic),\n filter((x) => x.ccy === currency),\n map((x) => +x.rate),\n ),\n ),\n shareReplay(1),\n ),\n);\n\n// provideTicks(terminal, 'OKX', (product_id) => {\n// const [instType, instId] = decodePath(product_id);\n// if (instType === 'SWAP') {\n// return defer(async () => {\n// const products = await firstValueFrom(usdtSwapProducts$);\n// const theProduct = products.find((x) => x.product_id === product_id);\n// if (!theProduct) throw `No Found ProductID ${product_id}`;\n// const theTicker$ = swapMarketTickers$.pipe(\n// map((x) => x[instId]),\n// shareReplay(1),\n// );\n// return [of(theProduct), theTicker$, fundingRate$(product_id), swapOpenInterest$] as const;\n// }).pipe(\n// catchError(() => EMPTY),\n// mergeMap((x) =>\n// combineLatest(x).pipe(\n// map(([theProduct, ticker, fundingRate, swapOpenInterest]): ITick => {\n// return {\n// datasource_id: 'OKX',\n// product_id,\n// updated_at: Date.now(),\n// settlement_scheduled_at: +fundingRate.fundingTime,\n// price: +ticker.last,\n// ask: +ticker.askPx,\n// bid: +ticker.bidPx,\n// volume: +ticker.lastSz,\n// interest_rate_for_long: -+fundingRate.fundingRate,\n// interest_rate_for_short: +fundingRate.fundingRate,\n// open_interest: swapOpenInterest.get(instId),\n// };\n// }),\n// ),\n// ),\n// );\n// }\n// if (instType === 'MARGIN') {\n// return defer(async () => {\n// const products = await firstValueFrom(marginProducts$);\n// const theProduct = products.find((x) => x.product_id === product_id);\n// if (!theProduct) throw `No Found ProductID ${product_id}`;\n// const theTicker$ = spotMarketTickers$.pipe(\n// map((x) => x[instId]),\n// shareReplay(1),\n// );\n// return [\n// of(theProduct),\n// theTicker$,\n// interestRateByCurrency$(theProduct.base_currency!),\n// interestRateByCurrency$(theProduct.quote_currency!),\n// ] as const;\n// }).pipe(\n// catchError(() => EMPTY),\n// mergeMap((x) =>\n// combineLatest(x).pipe(\n// map(\n// ([theProduct, ticker, interestRateForBase, interestRateForQuote]): ITick => ({\n// datasource_id: 'OKX',\n// product_id,\n// updated_at: Date.now(),\n// price: +ticker.last,\n// volume: +ticker.lastSz,\n// // 在下一个整点扣除利息 See 如何计算利息 https://www.okx.com/zh-hans/help/how-to-calculate-borrowing-interest\n// settlement_scheduled_at: new Date().setMinutes(0, 0, 0) + 3600_000,\n// interest_rate_for_long: -interestRateForQuote / 24,\n// interest_rate_for_short: -interestRateForBase / 24,\n// }),\n// ),\n// ),\n// ),\n// );\n// }\n// return EMPTY;\n// });\n\ndefer(async () => {\n const account_config = await firstValueFrom(accountConfig$);\n console.info(formatTime(Date.now()), 'AccountConfig', JSON.stringify(account_config));\n const { mainUid, uid } = account_config.data[0];\n const isMainAccount = mainUid === uid;\n\n const TRADING_ACCOUNT_ID = `okx/${uid}/trading`;\n const FUNDING_ACCOUNT_ID = `okx/${uid}/funding/USDT`;\n const EARNING_ACCOUNT_ID = `okx/${uid}/earning/USDT`;\n\n // BLOCK_CHAIN: only available for main account\n if (isMainAccount) {\n const depositAddressRes = await client.getAssetDepositAddress({ ccy: 'USDT' });\n console.info(formatTime(Date.now()), 'DepositAddress', JSON.stringify(depositAddressRes.data));\n const addresses = depositAddressRes.data.filter((v) => v.chain === 'USDT-TRC20' && v.to === '6');\n for (const address of addresses) {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: 'TRC20',\n currency: 'USDT',\n address: address.addr,\n onApply: {\n INIT: async (order) => {\n if (\n !order.current_amount ||\n order.current_amount < 3 // 最小提币额度\n ) {\n return { state: 'ERROR', message: 'Amount too small' };\n }\n const res = await firstValueFrom(resOfAssetCurrencies);\n const theRes = res.data?.find((x) => x.ccy === 'USDT' && x.chain === 'USDT-TRC20');\n const _fee = theRes?.minFee;\n if (!_fee) return { state: 'ERROR', message: 'Currency Info not found, cannot get fee' };\n const fee = +_fee;\n const amt = Math.floor(order.current_amount - fee);\n const transferResult = await client.postAssetWithdrawal({\n amt: `${amt}`,\n ccy: 'USDT',\n chain: 'USDT-TRC20',\n fee: `${fee}`,\n dest: '4', // 链上提币\n toAddr: order.current_rx_address!,\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const wdId = transferResult.data[0]?.wdId;\n return { state: 'AWAIT_TX_ID', context: wdId };\n },\n AWAIT_TX_ID: async (transferOrder) => {\n const wdId = transferOrder.current_tx_context;\n const withdrawalHistory = await client.getAssetWithdrawalHistory({ wdId });\n const txId = withdrawalHistory.data?.[0]?.txId;\n if (!txId) {\n return { state: 'AWAIT_TX_ID', context: wdId };\n }\n return { state: 'COMPLETE', transaction_id: txId };\n },\n },\n onEval: async (transferOrder) => {\n const checkResult = await client.getAssetDepositHistory({\n ccy: 'USDT',\n txId: transferOrder.current_transaction_id,\n type: '4',\n });\n\n if (checkResult.code !== '0') {\n return {\n state: 'INIT',\n };\n }\n\n if (checkResult.data[0].state !== '2') {\n return { state: 'PENDING' };\n }\n const received_amount = +checkResult.data[0].amt;\n return { state: 'COMPLETE', received_amount };\n },\n });\n }\n }\n\n // Funding-Trading\n {\n const FUNDING_TRADING_NETWORK_ID = `OKX/${uid}/Funding-Trading`;\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: FUNDING_TRADING_NETWORK_ID,\n currency: 'USDT',\n address: 'funding',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postAssetTransfer({\n type: '0',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '18',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n addAccountTransferAddress({\n terminal,\n account_id: TRADING_ACCOUNT_ID,\n network_id: FUNDING_TRADING_NETWORK_ID,\n currency: 'USDT',\n address: 'trading',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postAssetTransfer({\n type: '0',\n ccy: order.currency,\n amt: `${order.current_amount}`,\n from: '18',\n to: '6',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n }\n // Funding-Earning\n {\n const FUNDING_EARNING_NETWORK_ID = `OKX/${uid}/Funding-Earning`;\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: FUNDING_EARNING_NETWORK_ID,\n currency: 'USDT',\n address: 'funding',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postFinanceSavingsPurchaseRedempt({\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n side: 'purchase',\n rate: '0.01',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: 'ok' };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n addAccountTransferAddress({\n terminal,\n account_id: EARNING_ACCOUNT_ID,\n network_id: FUNDING_EARNING_NETWORK_ID,\n currency: 'USDT',\n address: 'earning',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postFinanceSavingsPurchaseRedempt({\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n side: 'redempt',\n rate: '0.01',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n return { state: 'COMPLETE', transaction_id: 'ok' };\n },\n },\n onEval: async (transferOrder) => {\n return { state: 'COMPLETE', received_amount: transferOrder.current_amount };\n },\n });\n }\n\n // SubAccount\n {\n const getSubAccountNetworkId = (subUid: string) => `OKX/${mainUid}/SubAccount/${subUid}`;\n if (isMainAccount) {\n const subAcctsRes = await client.getSubAccountList();\n for (const item of subAcctsRes.data || []) {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: getSubAccountNetworkId(item.uid),\n currency: 'USDT',\n address: 'main',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postAssetTransfer({\n type: '1',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '6',\n subAcct: item.subAcct,\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (order) => {\n // ISSUE: OKX API Issue: transId is incorrect or transId does not match with ‘ type’\n // const checkResult = await client.getAssetTransferState({ transId: order.current_transaction_id });\n // const received_amount = checkResult?.data?.[0]?.amt;\n // if (!received_amount) {\n // return { state: 'INIT', message: checkResult.msg };\n // }\n // return { state: 'COMPLETE', received_amount: +received_amount };\n\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n }\n }\n // SubAccount API\n else {\n addAccountTransferAddress({\n terminal,\n account_id: FUNDING_ACCOUNT_ID,\n network_id: getSubAccountNetworkId(uid),\n currency: 'USDT',\n address: 'sub',\n onApply: {\n INIT: async (order) => {\n const transferResult = await client.postAssetTransfer({\n type: '3',\n ccy: 'USDT',\n amt: `${order.current_amount}`,\n from: '6',\n to: '6',\n });\n if (transferResult.code !== '0') {\n return { state: 'INIT', message: transferResult.msg };\n }\n const transaction_id = transferResult.data[0].transId;\n return { state: 'COMPLETE', transaction_id };\n },\n },\n onEval: async (order) => {\n // ISSUE: OKX API Issue: transId is incorrect or transId does not match with ‘ type’\n // const checkResult = await client.getAssetTransferState({ transId: order.current_transaction_id });\n // const received_amount = checkResult?.data?.[0]?.amt;\n // if (!received_amount) {\n // return { state: 'INIT', message: checkResult.msg };\n // }\n // return { state: 'COMPLETE', received_amount: +received_amount };\n return { state: 'COMPLETE', received_amount: order.current_amount };\n },\n });\n }\n }\n}).subscribe();\n\ndefer(async () => {\n const tradingAccountInfo = await firstValueFrom(tradingAccountInfo$);\n terminal.provideService(\n 'SubmitOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountInfo.account_id },\n },\n },\n async (msg) => {\n console.info(formatTime(Date.now()), 'SubmitOrder', JSON.stringify(msg));\n const order = msg.req;\n const [instType, instId] = decodePath(order.product_id);\n\n const mapOrderDirectionToSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'buy';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'sell';\n }\n throw new Error(`Unknown direction: ${direction}`);\n };\n const mapOrderDirectionToPosSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'long';\n case 'CLOSE_SHORT':\n case 'OPEN_SHORT':\n return 'short';\n }\n throw new Error(`Unknown direction: ${direction}`);\n };\n const mapOrderTypeToOrdType = (order_type?: string) => {\n switch (order_type) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n case 'MAKER':\n return 'post_only';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n };\n\n // 交易数量,表示要购买或者出售的数量。\n // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。\n // 当币币杠杆以市价买入时,指计价货币的数量。\n // 当币币杠杆以市价卖出时,指交易货币的数量。\n // 对于币币市价单,单位由 tgtCcy 决定\n // 当交割、永续、期权买入和卖出时,指合约张数。\n const mapOrderVolumeToSz = async (order: IOrder) => {\n if (instType === 'SWAP') {\n return order.volume;\n }\n if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n return order.volume;\n }\n if (order.order_type === 'MAKER') {\n return order.volume;\n }\n if (order.order_type === 'MARKET') {\n if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {\n return order.volume;\n }\n //\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n mapOrderDirectionToPosSide(order.order_direction) === 'long'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);\n const theProduct = await firstValueFrom(\n mapProductIdToMarginProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n return roundToStep(order.volume * price, theProduct.volume_step!);\n }\n\n return 0;\n }\n\n if (instType === 'SPOT') {\n return order.volume;\n }\n\n throw new Error(`Unknown instType: ${instType}`);\n };\n\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n instType === 'MARGIN' || instType === 'SPOT'\n ? 'net'\n : mapOrderDirectionToPosSide(order.order_direction),\n ordType: mapOrderTypeToOrdType(order.order_type),\n sz: (await mapOrderVolumeToSz(order)).toString(),\n tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,\n reduceOnly:\n instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes(order.order_direction ?? '')\n ? 'true'\n : undefined,\n px: order.order_type === 'LIMIT' ? order.price!.toString() : undefined,\n ccy: instType === 'MARGIN' ? 'USDT' : undefined,\n };\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const res = await client.postTradeOrder(params);\n if (res.code === '0' && res.data?.[0]?.ordId) {\n return {\n res: {\n code: 0,\n message: 'OK',\n data: {\n order_id: res.data[0].ordId,\n },\n },\n };\n }\n return { res: { code: +res.code, message: res.msg } };\n },\n );\n\n terminal.provideService(\n 'ModifyOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountInfo.account_id },\n },\n },\n async (msg) => {\n console.info(formatTime(Date.now()), 'ModifyOrder', JSON.stringify(msg));\n const order = msg.req;\n const [instType, instId] = decodePath(order.product_id);\n\n const params: any = {\n instId,\n ordId: order.order_id, // 使用现有订单ID\n };\n\n // 如果需要修改价格\n if (order.price !== undefined) {\n params.newPx = order.price.toString();\n }\n\n // 如果需要修改数量\n if (order.volume !== undefined) {\n // 处理数量修改,类似于 SubmitOrder 中的逻辑\n if (instType === 'SWAP') {\n params.newSz = order.volume.toString();\n } else if (instType === 'SPOT') {\n params.newSz = order.volume.toString();\n } else if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MAKER') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MARKET') {\n // 对于市价单,可能需要根据当前价格计算新的数量\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'ModifyOrder', 'price', price);\n const theProduct = await firstValueFrom(\n mapProductIdToMarginProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n params.newSz = roundToStep(order.volume * price, theProduct.volume_step!).toString();\n }\n } else {\n throw new Error(`Unknown instType: ${instType}`);\n }\n }\n\n console.info(formatTime(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));\n\n const res = await client.postTradeAmendOrder(params);\n if (res.code !== '0') {\n return {\n res: {\n code: +res.code,\n message: res.msg,\n },\n };\n }\n\n return { res: { code: 0, message: 'OK' } };\n },\n );\n\n terminal.provideService(\n 'CancelOrder',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountInfo.account_id },\n },\n },\n (msg) =>\n defer(async () => {\n const order = msg.req;\n const [instType, instId] = decodePath(order.product_id);\n const res = await client.postTradeCancelOrder({\n instId,\n ordId: order.order_id,\n });\n if (res.code !== '0') {\n return { res: { code: +res.code, message: res.msg } };\n }\n return { res: { code: 0, message: 'OK' } };\n }),\n );\n}).subscribe();\n"]}
package/lib/api.d.ts CHANGED
@@ -920,6 +920,8 @@ export declare class OkxClient {
920
920
  * 权限:交易
921
921
  *
922
922
  * 该接口限速同时受到 子账户限速 及 基于成交比率的子账户限速 限速规则的影响。
923
+ *
924
+ * https://www.okx.com/docs-v5/zh/#order-book-trading-trade-post-amend-order
923
925
  */
924
926
  postTradeAmendOrder: (params: {
925
927
  instId: string;