@yuants/vendor-huobi 0.18.2 → 0.18.4
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/private-api.js +50 -25
- package/dist/api/private-api.js.map +1 -1
- package/dist/api/public-api.js +86 -16
- package/dist/api/public-api.js.map +1 -1
- package/dist/services/accounts/swap.js +3 -3
- package/dist/services/accounts/swap.js.map +1 -1
- package/dist/services/orders/submitOrder.js +2 -2
- package/dist/services/orders/submitOrder.js.map +1 -1
- package/lib/api/private-api.d.ts +1 -1
- package/lib/api/private-api.d.ts.map +1 -1
- package/lib/api/private-api.js +50 -26
- package/lib/api/private-api.js.map +1 -1
- package/lib/api/public-api.d.ts +1 -1
- package/lib/api/public-api.d.ts.map +1 -1
- package/lib/api/public-api.js +85 -15
- package/lib/api/public-api.js.map +1 -1
- package/lib/services/accounts/swap.js +3 -3
- package/lib/services/accounts/swap.js.map +1 -1
- package/lib/services/orders/submitOrder.js +2 -2
- package/lib/services/orders/submitOrder.js.map +1 -1
- package/package.json +15 -15
- package/temp/package-deps.json +21 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":";;;AAAA,yCAAqE;AAO9D,MAAM,oBAAoB,GAAG,GAAgB,EAAE;IACpD,OAAO;QACL,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;QACnC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;KACpC,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,oBAAoB,wBAK/B;AAEK,MAAM,cAAc,GAAG,KAAK,EACjC,UAAuB,EACvB,MAAc,EACd,IAAY,EACZ,QAAgB,EAChB,MAAY,EACZ,EAAE;IACF,MAAM,aAAa,GAAG,eACpB,UAAU,CAAC,UACb,4DAA4D,kBAAkB,CAC5E,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,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gBzB;AAEF;;;;;;;;;;;;;GAaG;AACI,MAAM,yBAAyB,GAAG,CACvC,UAAuB,EAQtB,EAAE;IACH,OAAO,IAAA,sBAAc,EAAC,UAAU,EAAE,KAAK,EAAE,+CAA+C,EAAE,cAAc,CAAC,CAAC;AAC5G,CAAC,CAAC;AAXW,QAAA,yBAAyB,6BAWpC;AAEF;;;;;;;;;;;;GAYG;AACI,MAAM,yBAAyB,GAAG,CACvC,UAAuB,EACvB,MAAgC,EAQ/B,EAAE;IACH,OAAO,IAAA,sBAAc,EACnB,UAAU,EACV,MAAM,EACN,8CAA8C,EAC9C,cAAc,EACd,MAAM,CACP,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,yBAAyB,6BAkBpC;AAEF;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,CACtC,UAAuB,EACvB,MAGC,EAkCA,EAAE;IACH,OAAO,IAAA,sBAAc,EAAC,UAAU,EAAE,KAAK,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;AAChG,CAAC,CAAC;AAzCW,QAAA,wBAAwB,4BAyCnC;AAEF;;;;GAIG;AACI,MAAM,iBAAiB,GAAG,CAC/B,UAAuB,EACvB,MASC,EAmBA,EAAE;IACH,OAAO,IAAA,sBAAc,EAAC,UAAU,EAAE,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;AAC3F,CAAC,CAAC;AAhCW,QAAA,iBAAiB,qBAgC5B","sourcesContent":["import { encodeBase64, formatTime, HmacSHA256 } from '@yuants/utils';\n\nexport interface ICredential {\n access_key: string;\n secret_key: string;\n}\n\nexport const getDefaultCredential = (): ICredential => {\n return {\n access_key: process.env.ACCESS_KEY!,\n secret_key: process.env.SECRET_KEY!,\n };\n};\n\nexport const privateRequest = async (\n credential: ICredential,\n method: string,\n path: string,\n api_root: string,\n params?: any,\n) => {\n const requestParams = `AccessKeyId=${\n credential.access_key\n }&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=${encodeURIComponent(\n new Date().toISOString().split('.')[0],\n )}${\n method === 'GET' && params !== undefined\n ? `&${Object.entries(params)\n .filter(([, v]) => v !== undefined)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([k, v]) => `${k}=${v}`)\n .join('&')}`\n : ''\n }`;\n\n const body = method === 'GET' ? '' : JSON.stringify(params);\n\n const requestString = `${method}\\n${api_root}\\n${path}\\n${requestParams}`;\n\n const str = encodeBase64(\n await HmacSHA256(\n new TextEncoder().encode(requestString),\n new TextEncoder().encode(credential.secret_key),\n ),\n );\n\n const url = new URL(`https://${api_root}${path}?${requestParams}&Signature=${encodeURIComponent(str)}`);\n // url.searchParams.sort();\n console.info(formatTime(Date.now()), method, url.href, body);\n const res = await fetch(url.href, {\n method,\n headers: { 'Content-Type': 'application/json' },\n body: body || undefined,\n });\n\n const retStr = await res.text();\n console.info(formatTime(Date.now()), 'PrivateResponse', url.toString(), res.status);\n try {\n return JSON.parse(retStr);\n } catch (e) {\n console.error(formatTime(Date.now()), 'huobiRequestFailed', path, JSON.stringify(params), retStr);\n throw e;\n }\n};\n\n/**\n * 获取账户信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40743-7773-11ed-9966-0242ac110003\n */\nexport const getAccount = (\n credential: ICredential,\n): Promise<{\n status: string;\n data: {\n id: number;\n type: string;\n state: string;\n subtype: string;\n }[];\n}> => {\n return privateRequest(credential, 'GET', '/v1/account/accounts', 'api.huobi.pro');\n};\n\n/**\n * 获取用户ID\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec491c9-7773-11ed-9966-0242ac110003\n */\nexport const getUid = (credential: ICredential): Promise<{ data: number; code: number }> => {\n return privateRequest(credential, 'GET', '/v2/user/uid', 'api.huobi.pro');\n};\n\n/**\n * 获取统一账户信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=10000073-77b7-11ed-9966-0242ac110003\n */\nexport const getUnifiedAccountInfo = (\n credential: ICredential,\n): Promise<{\n status: string;\n code: number;\n msg: string;\n data: {\n margin_asset: string;\n margin_balance: number;\n cross_margin_static: number;\n cross_profit_unreal: number;\n withdraw_available: number;\n }[];\n}> => {\n return privateRequest(credential, 'GET', '/linear-swap-api/v3/unified_account_info', 'api.hbdm.com');\n};\n\n/**\n * 获取合约持仓信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb74963-77b5-11ed-9966-0242ac110003\n */\nexport const getSwapCrossPositionInfo = (\n credential: ICredential,\n params?: {\n contract_code?: string;\n pair?: string;\n contract_type: string;\n },\n): Promise<{\n status: string;\n ts: number;\n data: {\n symbol: string;\n contract_code: string;\n volume: number;\n available: number;\n frozen: number;\n cost_open: number;\n cost_hold: number;\n profit_unreal: number;\n profit_rate: number;\n lever_rate: number;\n position_margin: number;\n direction: string;\n profit: number;\n last_price: number;\n margin_asset: string;\n margin_mode: string;\n margin_account: string;\n contract_type: string;\n pair: string;\n business_type: string;\n position_mode: string;\n adl_risk_percent: string;\n liquidation_price?: number;\n }[];\n}> => {\n return privateRequest(\n credential,\n 'POST',\n '/linear-swap-api/v1/swap_cross_position_info',\n 'api.hbdm.com',\n params,\n );\n};\n\n/**\n * 获取合约挂单\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb784d4-77b5-11ed-9966-0242ac110003\n */\nexport const getSwapOpenOrders = (\n credential: ICredential,\n params?: {\n contract_code?: string;\n pair?: string;\n page_index?: number;\n page_size?: number;\n sort_by?: string;\n trade_type?: string;\n },\n): Promise<{\n status: string;\n data: {\n orders: {\n order_id_str: string;\n contract_code: string;\n order_price_type: string;\n direction: string;\n offset: string;\n volume: number;\n created_at: number;\n price: number;\n trade_volume: number;\n }[];\n };\n}> => {\n return privateRequest(\n credential,\n 'POST',\n '/linear-swap-api/v1/swap_cross_openorders',\n 'api.hbdm.com',\n params,\n );\n};\n\n/**\n * 获取现货账户余额\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40922-7773-11ed-9966-0242ac110003\n */\nexport const getSpotAccountBalance = (\n credential: ICredential,\n account_uid: number,\n): Promise<{\n status: string;\n data: {\n list: {\n currency: string;\n balance: string;\n type: string;\n }[];\n };\n}> => {\n return privateRequest(credential, 'GET', `/v1/account/accounts/${account_uid}/balance`, 'api.huobi.pro');\n};\n\n/**\n * 获取杠杆借贷信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41863-7773-11ed-9966-0242ac110003\n */\nexport const getCrossMarginLoanInfo = (\n credential: ICredential,\n): Promise<{\n status: string;\n code: number;\n data: {\n currency: string;\n 'loanable-amt': string;\n }[];\n}> => {\n return privateRequest(credential, 'GET', '/v1/cross-margin/loan-info', 'api.huobi.pro');\n};\n\n/**\n * 现货下单\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=10000065-77b7-11ed-9966-0242ac110003\n */\nexport const postSpotOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n 'account-id': string;\n amount: string;\n market_amount?: string;\n 'borrow-amount'?: string;\n type: string;\n 'trade-purpose': string;\n price?: string;\n source: string;\n 'client-order-id'?: string;\n },\n): Promise<{ success: boolean; code: number; message: string; data: { orderId: number } }> => {\n return privateRequest(credential, 'POST', `/v1/order/auto/place`, 'api.huobi.pro', params);\n};\n\n/**\n * 合约下单\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb77159-77b5-11ed-9966-0242ac110003\n */\nexport const postSwapOrder = (\n credential: ICredential,\n params: {\n contract_code: string;\n contract_type: string;\n price?: number;\n volume: number;\n offset: string;\n direction: string;\n lever_rate: number;\n order_price_type: string;\n channel_code?: string;\n },\n): Promise<{ status: string; ts: number; data: { order_id: number; order_id_str: string } }> => {\n return privateRequest(credential, 'POST', '/linear-swap-api/v1/swap_cross_order', 'api.hbdm.com', params);\n};\n\n/**\n * 获取现货存款地址\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec45fb7-7773-11ed-9966-0242ac110003\n */\nexport const getSpotAccountDepositAddresses = (\n credential: ICredential,\n params: { currency: string },\n): Promise<{\n code: number;\n message: string;\n data: {\n currency: string;\n chain: string;\n address: string;\n }[];\n}> => {\n return privateRequest(credential, 'GET', `/v2/account/deposit/address`, 'api.huobi.pro', params);\n};\n\n/**\n * 获取账户流水\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec4610b-7773-11ed-9966-0242ac110003\n */\nexport const getAccountLedger = (\n credential: ICredential,\n params: { accountId: string; currency: string },\n): Promise<{\n status: string;\n data: {\n transactTime: number;\n transactAmt: number;\n }[];\n}> => {\n return privateRequest(credential, 'GET', `/v2/account/ledger`, 'api.huobi.pro', params);\n};\n\n/**\n * 超级杠杆转出\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41ff0-7773-11ed-9966-0242ac110003\n */\nexport const postSuperMarginAccountTransferOut = (\n credential: ICredential,\n params: {\n currency: string;\n amount: string;\n },\n): Promise<{ status: string; data: number }> => {\n return privateRequest(credential, 'POST', `/v1/cross-margin/transfer-out`, 'api.huobi.pro', params);\n};\n\n/**\n * 超级杠杆转入\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41f0e-7773-11ed-9966-0242ac110003\n */\nexport const postSuperMarginAccountTransferIn = (\n credential: ICredential,\n params: {\n currency: string;\n amount: string;\n },\n): Promise<{ status: string; data: number }> => {\n return privateRequest(credential, 'POST', `/v1/cross-margin/transfer-in`, 'api.huobi.pro', params);\n};\n\n/**\n * 现货账户转账\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=10000095-77b7-11ed-9966-0242ac110003\n */\nexport const postSpotAccountTransfer = (\n credential: ICredential,\n params: {\n from: string;\n to: string;\n currency: string;\n amount: number;\n 'margin-account': string;\n },\n): Promise<{ success: boolean; data: number; code: number; message: string }> => {\n return privateRequest(credential, 'POST', `/v2/account/transfer`, 'api.huobi.pro', params);\n};\n\n/**\n * 借贷\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41b5d-7773-11ed-9966-0242ac110003\n */\nexport const postBorrow = (\n credential: ICredential,\n params: { currency: string; amount: string },\n): Promise<{\n status: string;\n data: number;\n}> => {\n return privateRequest(credential, 'POST', `/v1/cross-margin/orders`, 'api.huobi.pro', params);\n};\n\n/**\n * 提现\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec42cfd-7773-11ed-9966-0242ac110003\n */\nexport const postWithdraw = (\n credential: ICredential,\n params: {\n address: string;\n amount: string;\n currency: string;\n fee: string;\n chain: string;\n },\n): Promise<{\n status: string;\n data: number;\n}> => {\n return privateRequest(credential, 'POST', `/v1/dw/withdraw/api/create`, 'api.huobi.pro', params);\n};\n\n/**\n * 获取充提历史\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec44f99-7773-11ed-9966-0242ac110003\n */\nexport const getDepositWithdrawHistory = (\n credential: ICredential,\n params: {\n currency: string;\n type: string;\n from?: string;\n size?: string;\n direct?: string;\n },\n): Promise<{\n status: string;\n 'error-code': string;\n 'error-msg': string;\n data: {\n id: number;\n type: string;\n currency: string;\n 'tx-hash': string;\n chain: string;\n amount: string;\n address: string;\n 'address-tag': string;\n fee: string;\n state: string;\n 'create-at': number;\n 'update-at': number;\n }[];\n}> => {\n return privateRequest(credential, 'GET', `/v1/query/deposit-withdraw`, 'api.huobi.pro', params);\n};\n\n/**\n * 资产划转(母子用户之间)\n *\n * 接口权限: 交易\n *\n * 限频: 2次/2s\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec45d8e-7773-11ed-9966-0242ac110003\n */\nexport const postSubUserTransfer = (\n credential: ICredential,\n params: {\n 'sub-uid': number;\n currency: string;\n amount: number;\n 'client-order-id'?: string;\n type: string;\n },\n): Promise<{\n data: number;\n status: string;\n}> => {\n return privateRequest(credential, 'POST', '/v1/subuser/transfer', 'api.huobi.pro', params);\n};\n\n/**\n * 获取子用户列表\n *\n * 接口权限: 读取\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec48f09-7773-11ed-9966-0242ac110003\n */\nexport const getSubUserList = (\n credential: ICredential,\n params?: { fromId?: number },\n): Promise<{\n code: number;\n message?: string;\n data: {\n uid: number;\n userState: string;\n subUserName: string;\n note: string;\n }[];\n nextId?: number;\n ok: boolean;\n}> => {\n return privateRequest(credential, 'GET', `/v2/sub-user/user-list`, 'api.huobi.pro', params);\n};\n\n/**\n * 账户类型查询\n *\n * 是否验签: 是\n *\n * 接口权限: 读取\n *\n * 限频: 每个UID 3秒最多 144 次请求(交易接口3秒最多 72 次请求,查询接口3秒最多 72 次请求) (该UID的所有币种和不同到期日的合约的所有私有接口共享该限制) 。\n *\n * 接口描述: 此接口用于客户查询的账号类型,当前U本位合约有统一账户和非统一账户(全仓逐仓账户)类型。统一账户类型资产放在USDT一个账户上,全仓逐仓账户类型资产放在不同的币对。\n * 统一账户类型为最新升级的,当前不支持API下单。若需要用用API下单请切换账户类型为非统一账户。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb71825-77b5-11ed-9966-0242ac110003\n */\nexport const getSwapUnifiedAccountType = (\n credential: ICredential,\n): Promise<{\n code: number;\n msg: string;\n ts: number;\n data: {\n account_type: number;\n };\n}> => {\n return privateRequest(credential, 'GET', '/linear-swap-api/v3/swap_unified_account_type', 'api.hbdm.com');\n};\n\n/**\n * 账户类型更改接口\n *\n * 是否验签: 是\n *\n * 接口权限: 交易\n *\n * 限频: 每个UID 3秒最多 144 次请求(交易接口3秒最多 72 次请求,查询接口3秒最多 72 次请求) (该UID的所有币种和不同到期日的合约的所有私有接口共享该限制) 。\n *\n * 接口描述: 调用该接口前需要保证U本位合约无持仓和挂单,当由非统一账户(全仓逐仓账户)变为统一账户还需将资产从逐仓账户划转到全仓账户。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb7196b-77b5-11ed-9966-0242ac110003\n */\nexport const postSwapSwitchAccountType = (\n credential: ICredential,\n params: { account_type: number },\n): Promise<{\n code: number;\n msg: string;\n ts: number;\n data: {\n account_type: number;\n };\n}> => {\n return privateRequest(\n credential,\n 'POST',\n '/linear-swap-api/v3/swap_switch_account_type',\n 'api.hbdm.com',\n params,\n );\n};\n\n/**\n * APIv2币链参考信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec478f0-7773-11ed-9966-0242ac110003\n */\nexport const getV2ReferenceCurrencies = (\n credential: ICredential,\n params: {\n currency?: string;\n authorizedUser?: string;\n },\n): Promise<{\n code: number;\n data: {\n currency: string;\n assetType: number;\n chains: {\n chain: string;\n displayName: string;\n fullName: string;\n baseChain?: string;\n baseChainProtocol?: string;\n isDynamic?: boolean;\n numOfConfirmations: number;\n numOfFastConfirmations: number;\n depositStatus: string;\n minDepositAmt: string;\n withdrawStatus: string;\n minWithdrawAmt: string;\n withdrawPrecision: number;\n maxWithdrawAmt: string;\n withdrawQuotaPerDay: string;\n withdrawQuotaPerYear: null;\n withdrawQuotaTotal: null;\n withdrawFeeType: string;\n transactFeeWithdraw?: string;\n addrWithTag: boolean;\n addrDepositTag: boolean;\n minTransactFeeWithdraw?: string;\n transactFeeRateWithdraw?: string;\n maxTransactFeeWithdraw?: string;\n }[];\n instStatus: string;\n }[];\n}> => {\n return privateRequest(credential, 'GET', '/v2/reference/currencies', 'api.huobi.pro', params);\n};\n\n/**\n * 获取账户历史\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41049-7773-11ed-9966-0242ac110003\n */\nexport const getAccountHistory = (\n credential: ICredential,\n params: {\n 'account-id': string;\n currency?: string;\n 'transact-types'?: number;\n 'start-time'?: number;\n 'end-time'?: number;\n sort?: 'asc' | 'desc';\n size?: number;\n 'from-id'?: number;\n },\n): Promise<{\n // code: number;\n 'transact-amt': string;\n 'avail-balance': string;\n 'acct-balance': string;\n 'transact-time': string;\n 'record-id': string;\n status: string;\n data: {\n 'account-id': string;\n currency: string;\n 'record-id': string;\n 'transact-amt': string;\n 'transact-type': string;\n 'avail-balance': string;\n 'acct-balance': string;\n 'transact-time': string;\n }[];\n}> => {\n return privateRequest(credential, 'GET', '/v1/account/history', 'api.huobi.pro', params);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":";;;AAAA,yCAA8F;AAE9F,MAAM,aAAa,GAAG,eAAe,CAAC;AACtC,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAOrC,MAAM,oBAAoB,GAAG,GAAgB,EAAE;IACpD,OAAO;QACL,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;QACnC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAW;KACpC,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,oBAAoB,wBAK/B;AAMF,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;AACzC,MAAM,wBAAwB,GAAG,CAAC,QAAgB,EAAE,EAAE;IACpD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;QACjC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,IAAA,mBAAW,EAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;KACjF;IACD,OAAO,IAAA,mBAAW,EAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,IAA6B,EAAE,EAAE;IACzE,MAAM,MAAM,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAClD,IAAA,kBAAU,EAAC,sBAAsB,kCAAO,IAAI,KAAE,QAAQ,KAAI,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACzF,CAAC,CAAC;AAEF,MAAM,2BAA2B,GAAG,KAAK,EACvC,UAAuB,EACvB,aAAwC,EACxC,QAAuB,EACvB,MAAc,EACd,IAAY,EACZ,QAAgB,EAChB,MAAY,EACZ,EAAE;IACF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CAA+C,CAAC,CAAC;AAC3G,CAAC,CAAC;AAXW,QAAA,yBAAyB,6BAWpC;AAEF;;;;;;;;;;;;GAYG;AACI,MAAM,yBAAyB,GAAG,CACvC,UAAuB,EACvB,MAAgC,EAQ/B,EAAE;IACH,OAAO,6BAA6B,CAClC,UAAU,EACV,MAAM,EACN,8CAA8C,EAC9C,MAAM,CACP,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,yBAAyB,6BAiBpC;AAEF;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,CACtC,UAAuB,EACvB,MAGC,EAkCA,EAAE;IACH,OAAO,uBAAuB,CAAC,UAAU,EAAE,KAAK,EAAE,0BAA0B,EAAE,MAAM,CAAC,CAAC;AACxF,CAAC,CAAC;AAzCW,QAAA,wBAAwB,4BAyCnC;AAEF;;;;GAIG;AACI,MAAM,iBAAiB,GAAG,CAC/B,UAAuB,EACvB,MASC,EAmBA,EAAE;IACH,OAAO,uBAAuB,CAAC,UAAU,EAAE,KAAK,EAAE,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACnF,CAAC,CAAC;AAhCW,QAAA,iBAAiB,qBAgC5B","sourcesContent":["import { encodeBase64, formatTime, HmacSHA256, scopeError, tokenBucket } from '@yuants/utils';\n\nconst SPOT_API_ROOT = 'api.huobi.pro';\nconst LINEAR_SWAP_API_ROOT = 'api.hbdm.com';\n\nexport interface ICredential {\n access_key: string;\n secret_key: string;\n}\n\nexport const getDefaultCredential = (): ICredential => {\n return {\n access_key: process.env.ACCESS_KEY!,\n secret_key: process.env.SECRET_KEY!,\n };\n};\n\n// https://www.htx.com/zh-cn/opend/newApiPages/?id=474\ntype HuobiBusiness = 'spot' | 'linear-swap';\ntype HuobiPrivateInterfaceType = 'trade' | 'query';\n\nconst createdBuckets = new Set<string>();\nconst getOrCreatePrivateBucket = (bucketId: string) => {\n if (!createdBuckets.has(bucketId)) {\n createdBuckets.add(bucketId);\n tokenBucket(bucketId, { capacity: 36, refillAmount: 36, refillInterval: 3000 });\n }\n return tokenBucket(bucketId);\n};\n\nconst acquirePrivate = (bucketId: string, meta: Record<string, unknown>) => {\n const bucket = getOrCreatePrivateBucket(bucketId);\n scopeError('HUOBI_API_RATE_LIMIT', { ...meta, bucketId }, () => bucket.acquireSync(1));\n};\n\nconst privateRequestWithRateLimit = async (\n credential: ICredential,\n interfaceType: HuobiPrivateInterfaceType,\n business: HuobiBusiness,\n method: string,\n path: string,\n api_root: string,\n params?: any,\n) => {\n const meta = { method, api_root, path, business, interfaceType, access_key: credential.access_key };\n\n const interfaceTypeUpper = interfaceType.toUpperCase();\n const businessUpper = business.toUpperCase();\n const globalBucketId = `HUOBI_PRIVATE_${interfaceTypeUpper}_UID_3S_ALL:${credential.access_key}`;\n const businessBucketId = `HUOBI_PRIVATE_${interfaceTypeUpper}_UID_3S_${businessUpper}:${credential.access_key}`;\n acquirePrivate(globalBucketId, meta);\n acquirePrivate(businessBucketId, meta);\n\n const requestParams = `AccessKeyId=${\n credential.access_key\n }&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=${encodeURIComponent(\n new Date().toISOString().split('.')[0],\n )}${\n method === 'GET' && params !== undefined\n ? `&${Object.entries(params)\n .filter(([, v]) => v !== undefined)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([k, v]) => `${k}=${v}`)\n .join('&')}`\n : ''\n }`;\n\n const body = method === 'GET' ? '' : JSON.stringify(params);\n\n const requestString = `${method}\\n${api_root}\\n${path}\\n${requestParams}`;\n\n const str = encodeBase64(\n await HmacSHA256(\n new TextEncoder().encode(requestString),\n new TextEncoder().encode(credential.secret_key),\n ),\n );\n\n const url = new URL(`https://${api_root}${path}?${requestParams}&Signature=${encodeURIComponent(str)}`);\n // url.searchParams.sort();\n console.info(formatTime(Date.now()), method, url.href, body);\n const res = await fetch(url.href, {\n method,\n headers: { 'Content-Type': 'application/json' },\n body: body || undefined,\n });\n\n const retStr = await res.text();\n console.info(formatTime(Date.now()), 'PrivateResponse', url.toString(), res.status);\n try {\n return JSON.parse(retStr);\n } catch (e) {\n console.error(formatTime(Date.now()), 'huobiRequestFailed', path, JSON.stringify(params), retStr);\n throw e;\n }\n};\n\nconst spotPrivateQueryRequest = (credential: ICredential, method: string, path: string, params?: any) =>\n privateRequestWithRateLimit(credential, 'query', 'spot', method, path, SPOT_API_ROOT, params);\n\nconst spotPrivateTradeRequest = (credential: ICredential, method: string, path: string, params?: any) =>\n privateRequestWithRateLimit(credential, 'trade', 'spot', method, path, SPOT_API_ROOT, params);\n\nconst linearSwapPrivateQueryRequest = (credential: ICredential, method: string, path: string, params?: any) =>\n privateRequestWithRateLimit(credential, 'query', 'linear-swap', method, path, LINEAR_SWAP_API_ROOT, params);\n\nconst linearSwapPrivateTradeRequest = (credential: ICredential, method: string, path: string, params?: any) =>\n privateRequestWithRateLimit(credential, 'trade', 'linear-swap', method, path, LINEAR_SWAP_API_ROOT, params);\n\n/**\n * 获取账户信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40743-7773-11ed-9966-0242ac110003\n */\nexport const getAccount = (\n credential: ICredential,\n): Promise<{\n status: string;\n data: {\n id: number;\n type: string;\n state: string;\n subtype: string;\n }[];\n}> => {\n return spotPrivateQueryRequest(credential, 'GET', '/v1/account/accounts');\n};\n\n/**\n * 获取用户ID\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec491c9-7773-11ed-9966-0242ac110003\n */\nexport const getUid = (credential: ICredential): Promise<{ data: number; code: number }> => {\n return spotPrivateQueryRequest(credential, 'GET', '/v2/user/uid');\n};\n\n/**\n * 获取统一账户信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=10000073-77b7-11ed-9966-0242ac110003\n */\nexport const getUnifiedAccountInfo = (\n credential: ICredential,\n): Promise<{\n status: string;\n code: number;\n msg: string;\n data: {\n margin_asset: string;\n margin_balance: number;\n margin_static: number;\n cross_margin_static: number;\n cross_profit_unreal: number;\n withdraw_available: number;\n }[];\n}> => {\n return linearSwapPrivateQueryRequest(credential, 'GET', '/linear-swap-api/v3/unified_account_info');\n};\n\n/**\n * 获取合约持仓信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb74963-77b5-11ed-9966-0242ac110003\n */\nexport const getSwapCrossPositionInfo = (\n credential: ICredential,\n params?: {\n contract_code?: string;\n pair?: string;\n contract_type: string;\n },\n): Promise<{\n status: string;\n ts: number;\n data: {\n symbol: string;\n contract_code: string;\n volume: number;\n available: number;\n frozen: number;\n cost_open: number;\n cost_hold: number;\n profit_unreal: number;\n profit_rate: number;\n lever_rate: number;\n position_margin: number;\n direction: string;\n profit: number;\n last_price: number;\n margin_asset: string;\n margin_mode: string;\n margin_account: string;\n contract_type: string;\n pair: string;\n business_type: string;\n position_mode: string;\n adl_risk_percent: string;\n liquidation_price?: number;\n }[];\n}> => {\n return linearSwapPrivateQueryRequest(\n credential,\n 'POST',\n '/linear-swap-api/v1/swap_cross_position_info',\n params,\n );\n};\n\n/**\n * 获取合约挂单\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb784d4-77b5-11ed-9966-0242ac110003\n */\nexport const getSwapOpenOrders = (\n credential: ICredential,\n params?: {\n contract_code?: string;\n pair?: string;\n page_index?: number;\n page_size?: number;\n sort_by?: string;\n trade_type?: string;\n },\n): Promise<{\n status: string;\n data: {\n orders: {\n order_id_str: string;\n contract_code: string;\n order_price_type: string;\n direction: string;\n offset: string;\n volume: number;\n created_at: number;\n price: number;\n trade_volume: number;\n }[];\n };\n}> => {\n return linearSwapPrivateQueryRequest(\n credential,\n 'POST',\n '/linear-swap-api/v1/swap_cross_openorders',\n params,\n );\n};\n\n/**\n * 获取现货账户余额\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40922-7773-11ed-9966-0242ac110003\n */\nexport const getSpotAccountBalance = (\n credential: ICredential,\n account_uid: number,\n): Promise<{\n status: string;\n data: {\n list: {\n currency: string;\n balance: string;\n type: string;\n }[];\n };\n}> => {\n return spotPrivateQueryRequest(credential, 'GET', `/v1/account/accounts/${account_uid}/balance`);\n};\n\n/**\n * 获取杠杆借贷信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41863-7773-11ed-9966-0242ac110003\n */\nexport const getCrossMarginLoanInfo = (\n credential: ICredential,\n): Promise<{\n status: string;\n code: number;\n data: {\n currency: string;\n 'loanable-amt': string;\n }[];\n}> => {\n return spotPrivateQueryRequest(credential, 'GET', '/v1/cross-margin/loan-info');\n};\n\n/**\n * 现货下单\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=10000065-77b7-11ed-9966-0242ac110003\n */\nexport const postSpotOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n 'account-id': string;\n amount: string;\n market_amount?: string;\n 'borrow-amount'?: string;\n type: string;\n 'trade-purpose': string;\n price?: string;\n source: string;\n 'client-order-id'?: string;\n },\n): Promise<{ success: boolean; code: number; message: string; data: { orderId: number } }> => {\n return spotPrivateTradeRequest(credential, 'POST', `/v1/order/auto/place`, params);\n};\n\n/**\n * 合约下单\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb77159-77b5-11ed-9966-0242ac110003\n */\nexport const postSwapOrder = (\n credential: ICredential,\n params: {\n contract_code: string;\n contract_type: string;\n price?: number;\n volume: number;\n offset: string;\n direction: string;\n lever_rate: number;\n order_price_type: string;\n channel_code?: string;\n },\n): Promise<{ status: string; ts: number; data: { order_id: number; order_id_str: string } }> => {\n return linearSwapPrivateTradeRequest(credential, 'POST', '/linear-swap-api/v1/swap_cross_order', params);\n};\n\n/**\n * 获取现货存款地址\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec45fb7-7773-11ed-9966-0242ac110003\n */\nexport const getSpotAccountDepositAddresses = (\n credential: ICredential,\n params: { currency: string },\n): Promise<{\n code: number;\n message: string;\n data: {\n currency: string;\n chain: string;\n address: string;\n }[];\n}> => {\n return spotPrivateQueryRequest(credential, 'GET', `/v2/account/deposit/address`, params);\n};\n\n/**\n * 获取账户流水\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec4610b-7773-11ed-9966-0242ac110003\n */\nexport const getAccountLedger = (\n credential: ICredential,\n params: { accountId: string; currency: string },\n): Promise<{\n status: string;\n data: {\n transactTime: number;\n transactAmt: number;\n }[];\n}> => {\n return spotPrivateQueryRequest(credential, 'GET', `/v2/account/ledger`, params);\n};\n\n/**\n * 超级杠杆转出\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41ff0-7773-11ed-9966-0242ac110003\n */\nexport const postSuperMarginAccountTransferOut = (\n credential: ICredential,\n params: {\n currency: string;\n amount: string;\n },\n): Promise<{ status: string; data: number }> => {\n return spotPrivateTradeRequest(credential, 'POST', `/v1/cross-margin/transfer-out`, params);\n};\n\n/**\n * 超级杠杆转入\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41f0e-7773-11ed-9966-0242ac110003\n */\nexport const postSuperMarginAccountTransferIn = (\n credential: ICredential,\n params: {\n currency: string;\n amount: string;\n },\n): Promise<{ status: string; data: number }> => {\n return spotPrivateTradeRequest(credential, 'POST', `/v1/cross-margin/transfer-in`, params);\n};\n\n/**\n * 现货账户转账\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=10000095-77b7-11ed-9966-0242ac110003\n */\nexport const postSpotAccountTransfer = (\n credential: ICredential,\n params: {\n from: string;\n to: string;\n currency: string;\n amount: number;\n 'margin-account': string;\n },\n): Promise<{ success: boolean; data: number; code: number; message: string }> => {\n return spotPrivateTradeRequest(credential, 'POST', `/v2/account/transfer`, params);\n};\n\n/**\n * 借贷\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41b5d-7773-11ed-9966-0242ac110003\n */\nexport const postBorrow = (\n credential: ICredential,\n params: { currency: string; amount: string },\n): Promise<{\n status: string;\n data: number;\n}> => {\n return spotPrivateTradeRequest(credential, 'POST', `/v1/cross-margin/orders`, params);\n};\n\n/**\n * 提现\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec42cfd-7773-11ed-9966-0242ac110003\n */\nexport const postWithdraw = (\n credential: ICredential,\n params: {\n address: string;\n amount: string;\n currency: string;\n fee: string;\n chain: string;\n },\n): Promise<{\n status: string;\n data: number;\n}> => {\n return spotPrivateTradeRequest(credential, 'POST', `/v1/dw/withdraw/api/create`, params);\n};\n\n/**\n * 获取充提历史\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec44f99-7773-11ed-9966-0242ac110003\n */\nexport const getDepositWithdrawHistory = (\n credential: ICredential,\n params: {\n currency: string;\n type: string;\n from?: string;\n size?: string;\n direct?: string;\n },\n): Promise<{\n status: string;\n 'error-code': string;\n 'error-msg': string;\n data: {\n id: number;\n type: string;\n currency: string;\n 'tx-hash': string;\n chain: string;\n amount: string;\n address: string;\n 'address-tag': string;\n fee: string;\n state: string;\n 'create-at': number;\n 'update-at': number;\n }[];\n}> => {\n return spotPrivateQueryRequest(credential, 'GET', `/v1/query/deposit-withdraw`, params);\n};\n\n/**\n * 资产划转(母子用户之间)\n *\n * 接口权限: 交易\n *\n * 限频: 2次/2s\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec45d8e-7773-11ed-9966-0242ac110003\n */\nexport const postSubUserTransfer = (\n credential: ICredential,\n params: {\n 'sub-uid': number;\n currency: string;\n amount: number;\n 'client-order-id'?: string;\n type: string;\n },\n): Promise<{\n data: number;\n status: string;\n}> => {\n return spotPrivateTradeRequest(credential, 'POST', '/v1/subuser/transfer', params);\n};\n\n/**\n * 获取子用户列表\n *\n * 接口权限: 读取\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec48f09-7773-11ed-9966-0242ac110003\n */\nexport const getSubUserList = (\n credential: ICredential,\n params?: { fromId?: number },\n): Promise<{\n code: number;\n message?: string;\n data: {\n uid: number;\n userState: string;\n subUserName: string;\n note: string;\n }[];\n nextId?: number;\n ok: boolean;\n}> => {\n return spotPrivateQueryRequest(credential, 'GET', `/v2/sub-user/user-list`, params);\n};\n\n/**\n * 账户类型查询\n *\n * 是否验签: 是\n *\n * 接口权限: 读取\n *\n * 限频: 每个UID 3秒最多 144 次请求(交易接口3秒最多 72 次请求,查询接口3秒最多 72 次请求) (该UID的所有币种和不同到期日的合约的所有私有接口共享该限制) 。\n *\n * 接口描述: 此接口用于客户查询的账号类型,当前U本位合约有统一账户和非统一账户(全仓逐仓账户)类型。统一账户类型资产放在USDT一个账户上,全仓逐仓账户类型资产放在不同的币对。\n * 统一账户类型为最新升级的,当前不支持API下单。若需要用用API下单请切换账户类型为非统一账户。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb71825-77b5-11ed-9966-0242ac110003\n */\nexport const getSwapUnifiedAccountType = (\n credential: ICredential,\n): Promise<{\n code: number;\n msg: string;\n ts: number;\n data: {\n account_type: number;\n };\n}> => {\n return linearSwapPrivateQueryRequest(credential, 'GET', '/linear-swap-api/v3/swap_unified_account_type');\n};\n\n/**\n * 账户类型更改接口\n *\n * 是否验签: 是\n *\n * 接口权限: 交易\n *\n * 限频: 每个UID 3秒最多 144 次请求(交易接口3秒最多 72 次请求,查询接口3秒最多 72 次请求) (该UID的所有币种和不同到期日的合约的所有私有接口共享该限制) 。\n *\n * 接口描述: 调用该接口前需要保证U本位合约无持仓和挂单,当由非统一账户(全仓逐仓账户)变为统一账户还需将资产从逐仓账户划转到全仓账户。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb7196b-77b5-11ed-9966-0242ac110003\n */\nexport const postSwapSwitchAccountType = (\n credential: ICredential,\n params: { account_type: number },\n): Promise<{\n code: number;\n msg: string;\n ts: number;\n data: {\n account_type: number;\n };\n}> => {\n return linearSwapPrivateTradeRequest(\n credential,\n 'POST',\n '/linear-swap-api/v3/swap_switch_account_type',\n params,\n );\n};\n\n/**\n * APIv2币链参考信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec478f0-7773-11ed-9966-0242ac110003\n */\nexport const getV2ReferenceCurrencies = (\n credential: ICredential,\n params: {\n currency?: string;\n authorizedUser?: string;\n },\n): Promise<{\n code: number;\n data: {\n currency: string;\n assetType: number;\n chains: {\n chain: string;\n displayName: string;\n fullName: string;\n baseChain?: string;\n baseChainProtocol?: string;\n isDynamic?: boolean;\n numOfConfirmations: number;\n numOfFastConfirmations: number;\n depositStatus: string;\n minDepositAmt: string;\n withdrawStatus: string;\n minWithdrawAmt: string;\n withdrawPrecision: number;\n maxWithdrawAmt: string;\n withdrawQuotaPerDay: string;\n withdrawQuotaPerYear: null;\n withdrawQuotaTotal: null;\n withdrawFeeType: string;\n transactFeeWithdraw?: string;\n addrWithTag: boolean;\n addrDepositTag: boolean;\n minTransactFeeWithdraw?: string;\n transactFeeRateWithdraw?: string;\n maxTransactFeeWithdraw?: string;\n }[];\n instStatus: string;\n }[];\n}> => {\n return spotPrivateQueryRequest(credential, 'GET', '/v2/reference/currencies', params);\n};\n\n/**\n * 获取账户历史\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec41049-7773-11ed-9966-0242ac110003\n */\nexport const getAccountHistory = (\n credential: ICredential,\n params: {\n 'account-id': string;\n currency?: string;\n 'transact-types'?: number;\n 'start-time'?: number;\n 'end-time'?: number;\n sort?: 'asc' | 'desc';\n size?: number;\n 'from-id'?: number;\n },\n): Promise<{\n // code: number;\n 'transact-amt': string;\n 'avail-balance': string;\n 'acct-balance': string;\n 'transact-time': string;\n 'record-id': string;\n status: string;\n data: {\n 'account-id': string;\n currency: string;\n 'record-id': string;\n 'transact-amt': string;\n 'transact-type': string;\n 'avail-balance': string;\n 'acct-balance': string;\n 'transact-time': string;\n }[];\n}> => {\n return spotPrivateQueryRequest(credential, 'GET', '/v1/account/history', params);\n};\n"]}
|
package/lib/api/public-api.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ export declare function getSpotHistoryKline(params: {
|
|
|
120
120
|
*
|
|
121
121
|
* 接口权限: 读取
|
|
122
122
|
*
|
|
123
|
-
* 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多
|
|
123
|
+
* 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多120次请求(所有该IP的非行情类的公开接口请求共享3秒120次的额度)
|
|
124
124
|
*
|
|
125
125
|
* 接口描述: 该接口支持全仓模式和逐仓模式
|
|
126
126
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AA2HA;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,CAAC,EAAE;IACnD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,mBAAmB,EAAE,MAAM,CAAC;QAC5B,aAAa,EAAE,MAAM,CAAC;QACtB,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;KACvB,EAAE,CAAC;IACJ,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC,CAED;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAA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,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;KACjB,EAAE,CAAC;IACJ,QAAQ,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;CACZ,CAAgD,CAAC"}
|
package/lib/api/public-api.js
CHANGED
|
@@ -5,8 +5,32 @@ const utils_1 = require("@yuants/utils");
|
|
|
5
5
|
// Huobi API 根域名
|
|
6
6
|
const SWAP_API_ROOT = 'api.hbdm.com';
|
|
7
7
|
const SPOT_API_ROOT = 'api.huobi.pro';
|
|
8
|
+
const acquire = (bucketId, meta) => {
|
|
9
|
+
const bucket = (0, utils_1.tokenBucket)(bucketId);
|
|
10
|
+
(0, utils_1.scopeError)('HUOBI_API_RATE_LIMIT', Object.assign(Object.assign({}, meta), { bucketId }), () => bucket.acquireSync(1));
|
|
11
|
+
};
|
|
12
|
+
// https://www.htx.com/zh-cn/opend/newApiPages/?id=474
|
|
13
|
+
// 行情类:同一个 IP,总共 1s 最多 800 个请求(合约业务共享总额度)
|
|
14
|
+
const marketDataIPAllBucketId = 'HUOBI_PUBLIC_MARKET_IP_1S_ALL';
|
|
15
|
+
(0, utils_1.tokenBucket)(marketDataIPAllBucketId, {
|
|
16
|
+
capacity: 800,
|
|
17
|
+
refillInterval: 1000,
|
|
18
|
+
refillAmount: 800,
|
|
19
|
+
});
|
|
20
|
+
// 行情类:按业务线拆分(用于交割/币本位永续/U本位分开限频)
|
|
21
|
+
const marketDataSpotBucketId = 'HUOBI_PUBLIC_MARKET_IP_1S_SPOT';
|
|
22
|
+
(0, utils_1.tokenBucket)(marketDataSpotBucketId, { capacity: 800, refillInterval: 1000, refillAmount: 800 });
|
|
23
|
+
const marketDataLinearSwapBucketId = 'HUOBI_PUBLIC_MARKET_IP_1S_LINEAR_SWAP';
|
|
24
|
+
(0, utils_1.tokenBucket)(marketDataLinearSwapBucketId, { capacity: 800, refillInterval: 1000, refillAmount: 800 });
|
|
25
|
+
// 非行情类公开接口:同一个 IP,3s 最多 120 次请求
|
|
26
|
+
const nonMarketDataIPBucketId = 'HUOBI_PUBLIC_NON_MARKET_IP_3S_ALL';
|
|
27
|
+
(0, utils_1.tokenBucket)(nonMarketDataIPBucketId, {
|
|
28
|
+
capacity: 120,
|
|
29
|
+
refillInterval: 3000,
|
|
30
|
+
refillAmount: 120,
|
|
31
|
+
});
|
|
8
32
|
/**
|
|
9
|
-
* 公共 API
|
|
33
|
+
* 公共 API 请求方法(不负责限流;限流由调用点选择对应 helper)
|
|
10
34
|
*/
|
|
11
35
|
async function publicRequest(method, path, api_root, params) {
|
|
12
36
|
const url = new URL(`https://${api_root}${path}`);
|
|
@@ -32,6 +56,52 @@ async function publicRequest(method, path, api_root, params) {
|
|
|
32
56
|
throw e;
|
|
33
57
|
}
|
|
34
58
|
}
|
|
59
|
+
const spotMarketRequest = async (method, path, params) => {
|
|
60
|
+
const meta = {
|
|
61
|
+
method,
|
|
62
|
+
api_root: SPOT_API_ROOT,
|
|
63
|
+
path,
|
|
64
|
+
business: 'spot',
|
|
65
|
+
interfaceType: 'market',
|
|
66
|
+
};
|
|
67
|
+
acquire(marketDataIPAllBucketId, meta);
|
|
68
|
+
acquire(marketDataSpotBucketId, meta);
|
|
69
|
+
return publicRequest(method, path, SPOT_API_ROOT, params);
|
|
70
|
+
};
|
|
71
|
+
const spotNonMarketRequest = async (method, path, params) => {
|
|
72
|
+
const meta = {
|
|
73
|
+
method,
|
|
74
|
+
api_root: SPOT_API_ROOT,
|
|
75
|
+
path,
|
|
76
|
+
business: 'spot',
|
|
77
|
+
interfaceType: 'non-market',
|
|
78
|
+
};
|
|
79
|
+
acquire(nonMarketDataIPBucketId, meta);
|
|
80
|
+
return publicRequest(method, path, SPOT_API_ROOT, params);
|
|
81
|
+
};
|
|
82
|
+
const linearSwapMarketRequest = async (method, path, params) => {
|
|
83
|
+
const meta = {
|
|
84
|
+
method,
|
|
85
|
+
api_root: SWAP_API_ROOT,
|
|
86
|
+
path,
|
|
87
|
+
business: 'linear-swap',
|
|
88
|
+
interfaceType: 'market',
|
|
89
|
+
};
|
|
90
|
+
acquire(marketDataIPAllBucketId, meta);
|
|
91
|
+
acquire(marketDataLinearSwapBucketId, meta);
|
|
92
|
+
return publicRequest(method, path, SWAP_API_ROOT, params);
|
|
93
|
+
};
|
|
94
|
+
const linearSwapNonMarketRequest = async (method, path, params) => {
|
|
95
|
+
const meta = {
|
|
96
|
+
method,
|
|
97
|
+
api_root: SWAP_API_ROOT,
|
|
98
|
+
path,
|
|
99
|
+
business: 'linear-swap',
|
|
100
|
+
interfaceType: 'non-market',
|
|
101
|
+
};
|
|
102
|
+
acquire(nonMarketDataIPBucketId, meta);
|
|
103
|
+
return publicRequest(method, path, SWAP_API_ROOT, params);
|
|
104
|
+
};
|
|
35
105
|
// ==================== 公共 API 方法 ====================
|
|
36
106
|
/**
|
|
37
107
|
* 获取永续合约产品信息
|
|
@@ -39,7 +109,7 @@ async function publicRequest(method, path, api_root, params) {
|
|
|
39
109
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72f34-77b5-11ed-9966-0242ac110003
|
|
40
110
|
*/
|
|
41
111
|
function getPerpetualContractSymbols(params) {
|
|
42
|
-
return
|
|
112
|
+
return linearSwapNonMarketRequest('GET', '/linear-swap-api/v1/swap_contract_info', params);
|
|
43
113
|
}
|
|
44
114
|
exports.getPerpetualContractSymbols = getPerpetualContractSymbols;
|
|
45
115
|
/**
|
|
@@ -48,7 +118,7 @@ exports.getPerpetualContractSymbols = getPerpetualContractSymbols;
|
|
|
48
118
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec47f16-7773-11ed-9966-0242ac110003
|
|
49
119
|
*/
|
|
50
120
|
function getSpotSymbols() {
|
|
51
|
-
return
|
|
121
|
+
return spotNonMarketRequest('GET', '/v2/settings/common/symbols');
|
|
52
122
|
}
|
|
53
123
|
exports.getSpotSymbols = getSpotSymbols;
|
|
54
124
|
/**
|
|
@@ -57,7 +127,7 @@ exports.getSpotSymbols = getSpotSymbols;
|
|
|
57
127
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3fc25-7773-11ed-9966-0242ac110003
|
|
58
128
|
*/
|
|
59
129
|
function getSpotTick(params) {
|
|
60
|
-
return
|
|
130
|
+
return spotMarketRequest('GET', `/market/detail/merged`, params);
|
|
61
131
|
}
|
|
62
132
|
exports.getSpotTick = getSpotTick;
|
|
63
133
|
/**
|
|
@@ -68,7 +138,7 @@ exports.getSpotTick = getSpotTick;
|
|
|
68
138
|
* Note: HTX spot KLine uses unix seconds in `data[].id`
|
|
69
139
|
*/
|
|
70
140
|
function getSpotHistoryKline(params) {
|
|
71
|
-
return
|
|
141
|
+
return spotMarketRequest('GET', `/market/history/kline`, params);
|
|
72
142
|
}
|
|
73
143
|
exports.getSpotHistoryKline = getSpotHistoryKline;
|
|
74
144
|
/**
|
|
@@ -76,14 +146,14 @@ exports.getSpotHistoryKline = getSpotHistoryKline;
|
|
|
76
146
|
*
|
|
77
147
|
* 接口权限: 读取
|
|
78
148
|
*
|
|
79
|
-
* 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多
|
|
149
|
+
* 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多120次请求(所有该IP的非行情类的公开接口请求共享3秒120次的额度)
|
|
80
150
|
*
|
|
81
151
|
* 接口描述: 该接口支持全仓模式和逐仓模式
|
|
82
152
|
*
|
|
83
153
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb71b45-77b5-11ed-9966-0242ac110003
|
|
84
154
|
*/
|
|
85
155
|
function getSwapBatchFundingRate(params) {
|
|
86
|
-
return
|
|
156
|
+
return linearSwapNonMarketRequest('GET', `/linear-swap-api/v1/swap_batch_funding_rate`, params);
|
|
87
157
|
}
|
|
88
158
|
exports.getSwapBatchFundingRate = getSwapBatchFundingRate;
|
|
89
159
|
/**
|
|
@@ -104,7 +174,7 @@ exports.getSwapBatchFundingRate = getSwapBatchFundingRate;
|
|
|
104
174
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73c34-77b5-11ed-9966-0242ac110003
|
|
105
175
|
*/
|
|
106
176
|
function getSwapMarketTrade(params) {
|
|
107
|
-
return
|
|
177
|
+
return linearSwapMarketRequest('GET', `/linear-swap-ex/market/trade`, params);
|
|
108
178
|
}
|
|
109
179
|
exports.getSwapMarketTrade = getSwapMarketTrade;
|
|
110
180
|
/**
|
|
@@ -113,7 +183,7 @@ exports.getSwapMarketTrade = getSwapMarketTrade;
|
|
|
113
183
|
* https://huobiapi.github.io/docs/usdt_swap/v1/cn/#3218e7531a
|
|
114
184
|
*/
|
|
115
185
|
function getSwapOpenInterest(params) {
|
|
116
|
-
return
|
|
186
|
+
return linearSwapMarketRequest('GET', '/linear-swap-api/v1/swap_open_interest', params);
|
|
117
187
|
}
|
|
118
188
|
exports.getSwapOpenInterest = getSwapOpenInterest;
|
|
119
189
|
/**
|
|
@@ -134,7 +204,7 @@ exports.getSwapOpenInterest = getSwapOpenInterest;
|
|
|
134
204
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb735e0-77b5-11ed-9966-0242ac110003
|
|
135
205
|
*/
|
|
136
206
|
function getSwapMarketBbo(params) {
|
|
137
|
-
return
|
|
207
|
+
return linearSwapMarketRequest('GET', `/linear-swap-ex/market/bbo`, params);
|
|
138
208
|
}
|
|
139
209
|
exports.getSwapMarketBbo = getSwapMarketBbo;
|
|
140
210
|
/**
|
|
@@ -145,7 +215,7 @@ exports.getSwapMarketBbo = getSwapMarketBbo;
|
|
|
145
215
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=5d51f1f9-77b6-11ed-9966-0242ac110003
|
|
146
216
|
*/
|
|
147
217
|
function getSwapHistoricalFundingRate(params) {
|
|
148
|
-
return
|
|
218
|
+
return linearSwapNonMarketRequest('GET', `/linear-swap-api/v1/swap_historical_funding_rate`, params);
|
|
149
219
|
}
|
|
150
220
|
exports.getSwapHistoricalFundingRate = getSwapHistoricalFundingRate;
|
|
151
221
|
/**
|
|
@@ -154,7 +224,7 @@ exports.getSwapHistoricalFundingRate = getSwapHistoricalFundingRate;
|
|
|
154
224
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73746-77b5-11ed-9966-0242ac110003
|
|
155
225
|
*/
|
|
156
226
|
function getSwapHistoryKline(params) {
|
|
157
|
-
return
|
|
227
|
+
return linearSwapMarketRequest('GET', `/linear-swap-ex/market/history/kline`, params);
|
|
158
228
|
}
|
|
159
229
|
exports.getSwapHistoryKline = getSwapHistoryKline;
|
|
160
230
|
/**
|
|
@@ -163,7 +233,7 @@ exports.getSwapHistoryKline = getSwapHistoryKline;
|
|
|
163
233
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72290-77b5-11ed-9966-0242ac110003
|
|
164
234
|
*/
|
|
165
235
|
function getSwapCrossLadderMargin(params) {
|
|
166
|
-
return
|
|
236
|
+
return linearSwapNonMarketRequest('GET', '/linear-swap-api/v1/swap_cross_ladder_margin', params);
|
|
167
237
|
}
|
|
168
238
|
exports.getSwapCrossLadderMargin = getSwapCrossLadderMargin;
|
|
169
239
|
/**
|
|
@@ -172,7 +242,7 @@ exports.getSwapCrossLadderMargin = getSwapCrossLadderMargin;
|
|
|
172
242
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec478f0-7773-11ed-9966-0242ac110003
|
|
173
243
|
*/
|
|
174
244
|
function getV2ReferenceCurrencies(params) {
|
|
175
|
-
return
|
|
245
|
+
return spotNonMarketRequest('GET', '/v2/reference/currencies', params);
|
|
176
246
|
}
|
|
177
247
|
exports.getV2ReferenceCurrencies = getV2ReferenceCurrencies;
|
|
178
248
|
/**
|
|
@@ -181,6 +251,6 @@ exports.getV2ReferenceCurrencies = getV2ReferenceCurrencies;
|
|
|
181
251
|
* https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40374-7773-11ed-9966-0242ac110003
|
|
182
252
|
*
|
|
183
253
|
*/
|
|
184
|
-
const getSpotMarketTickers = () =>
|
|
254
|
+
const getSpotMarketTickers = () => spotMarketRequest('GET', '/market/tickers');
|
|
185
255
|
exports.getSpotMarketTickers = getSpotMarketTickers;
|
|
186
256
|
//# sourceMappingURL=public-api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAE3C,gBAAgB;AAChB,MAAM,aAAa,GAAG,cAAc,CAAC;AACrC,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC;;GAEG;AACH,KAAK,UAAU,aAAa,CAAC,MAAc,EAAE,IAAY,EAAE,QAAgB,EAAE,MAAY;IACvF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAC;IAElD,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE;YACjD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SACvC;KACF;IAED,MAAM,IAAI,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE5D,OAAO,CAAC,IAAI,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE7D,MAAM,GAAG,GAAG,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,SAAgB,wBAAwB,CAAC,MAAsD;IAkC7F,OAAO,aAAa,CAAC,KAAK,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AAnCD,4DAmCC;AAED;;;;;GAKG;AACI,MAAM,oBAAoB,GAAG,GAiBjC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAjBhD,QAAA,oBAAoB,wBAiB4B","sourcesContent":["import { formatTime } from '@yuants/utils';\n\n// Huobi API 根域名\nconst SWAP_API_ROOT = 'api.hbdm.com';\nconst SPOT_API_ROOT = 'api.huobi.pro';\n\n/**\n * 公共 API 请求方法\n */\nasync function publicRequest(method: string, path: string, api_root: string, params?: any) {\n const url = new URL(`https://${api_root}${path}`);\n\n if (method === 'GET') {\n for (const [k, v] of Object.entries(params || {})) {\n url.searchParams.append(k, String(v));\n }\n }\n\n const body = method === 'GET' ? '' : JSON.stringify(params);\n\n console.info(formatTime(Date.now()), method, url.href, body);\n\n const res = await fetch(url.href, {\n method,\n headers: { 'Content-Type': 'application/json' },\n body: body || undefined,\n });\n\n console.info(formatTime(Date.now()), 'PublicResponse', url.toString(), res.status);\n\n const retStr = await res.text();\n try {\n return JSON.parse(retStr);\n } catch (e) {\n console.error(formatTime(Date.now()), 'huobiRequestFailed', path, JSON.stringify(params), retStr);\n throw e;\n }\n}\n\n// ==================== 公共 API 方法 ====================\n\n/**\n * 获取永续合约产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72f34-77b5-11ed-9966-0242ac110003\n */\nexport function getPerpetualContractSymbols(params?: {\n contract_code?: string;\n support_margin_mode?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n symbol: string;\n contract_code: string;\n contract_size: number;\n price_tick: number;\n settlement_date: string;\n delivery_time: string;\n create_date: string;\n contract_status: number;\n support_margin_mode: string;\n contract_type: string;\n pair: string;\n business_type: string;\n delivery_date: string;\n }[];\n ts: string;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_contract_info', SWAP_API_ROOT, params);\n}\n\n/**\n * 获取现货产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec47f16-7773-11ed-9966-0242ac110003\n */\nexport function getSpotSymbols(): Promise<{\n status: string;\n data: {\n si: string;\n scr: string;\n sc: string;\n dn: string;\n bc: string;\n bcdn: string;\n qc: string;\n qcdn: string;\n state: string;\n whe: boolean;\n cd: boolean;\n te: boolean;\n toa: number;\n sp: string;\n w: number;\n ttp: number;\n tap: number;\n tpp: number;\n fp: number;\n suspend_desc: string;\n transfer_board_desc: string;\n tags: string;\n lr: number;\n smlr: number;\n flr: string;\n wr: string;\n d: number;\n elr: number;\n p: any;\n castate: string;\n ca1oa: number;\n ca2oa: number;\n }[];\n ts: string;\n full: number;\n err_code: string;\n err_msg: string;\n}> {\n return publicRequest('GET', '/v2/settings/common/symbols', SPOT_API_ROOT);\n}\n\n/**\n * 获取现货行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3fc25-7773-11ed-9966-0242ac110003\n */\nexport function getSpotTick(params: { symbol: string }): Promise<{\n status: string;\n tick: {\n close: number;\n };\n}> {\n return publicRequest('GET', `/market/detail/merged`, SPOT_API_ROOT, params);\n}\n\n/**\n * 【现货】获取K线数据\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3ff18-7773-11ed-9966-0242ac110003\n *\n * Note: HTX spot KLine uses unix seconds in `data[].id`\n */\nexport function getSpotHistoryKline(params: {\n symbol: string;\n period: string;\n size?: number;\n from?: number;\n to?: number;\n}): Promise<{\n status: string;\n ch?: string;\n ts: number;\n data: {\n id: number;\n open: number;\n close: number;\n low: number;\n high: number;\n vol: number;\n amount?: number;\n count?: number;\n }[];\n}> {\n return publicRequest('GET', `/market/history/kline`, SPOT_API_ROOT, params);\n}\n\n/**\n * 【通用】批量获取合约资金费率\n *\n * 接口权限: 读取\n *\n * 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多240次请求(所有该IP的非行情类的公开接口请求共享3秒240次的额度)\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb71b45-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapBatchFundingRate(params: { contract_code?: string }): Promise<{\n status: string;\n ts: number;\n data: {\n estimated_rate: null;\n funding_rate: string;\n contract_code: string;\n symbol: string;\n fee_asset: string;\n funding_time: string;\n next_funding_time: null;\n trade_partition: string;\n }[];\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_batch_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最近成交记录\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73c34-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketTrade(params: { contract_code?: string; business_type?: string }): Promise<{\n ch: string;\n status: string;\n tick: {\n data: {\n amount: string;\n quantity: string;\n trade_turnover: string;\n ts: number;\n id: number;\n price: string;\n direction: string;\n contract_code: string;\n business_type: string;\n trade_partition: string;\n }[];\n id: number;\n ts: number;\n };\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/trade`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获得当前合约的总持仓量\n *\n * https://huobiapi.github.io/docs/usdt_swap/v1/cn/#3218e7531a\n */\nexport function getSwapOpenInterest(params: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n volume: number;\n amount: number;\n symbol: string;\n value: number;\n contract_code: string;\n trade_amount: number;\n trade_volume: number;\n trade_turnover: number;\n business_type: string;\n pair: string;\n contract_type: string;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_open_interest', SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最优挂单\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb735e0-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketBbo(params: { contract_code?: string }): Promise<{\n status: string;\n ticks: {\n trade_partition: string;\n business_type: string;\n contract_code: string;\n ask: number[] | null;\n bid: number[] | null;\n mrid: number;\n ts: number;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/bbo`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获取合约的历史资金费率\n *\n * 接口权限: 读取\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=5d51f1f9-77b6-11ed-9966-0242ac110003\n */\nexport function getSwapHistoricalFundingRate(params: {\n contract_code: string;\n page_index?: number;\n page_size?: number;\n}): Promise<{\n status: string;\n ts: number;\n data: {\n data: {\n symbol: string;\n contract_code: string;\n fee_asset: string;\n funding_time: string;\n funding_rate: string;\n realized_rate: string;\n avg_premium_index: string;\n }[];\n total_page: number;\n current_page: number;\n total_size: number;\n };\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_historical_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取K线数据\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73746-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapHistoryKline(params: {\n contract_code: string;\n period: string;\n size?: number;\n from?: number;\n to?: number;\n}): Promise<{\n status: string;\n ch?: string;\n ts: number;\n data: {\n id: number;\n open: number;\n close: number;\n low: number;\n high: number;\n vol: number;\n amount?: number;\n count?: number;\n }[];\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/history/kline`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【全仓】获取平台阶梯保证金\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72290-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapCrossLadderMargin(params?: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: Array<{ contract_code: string; pair: string; list: Array<{ lever_rate: number }> }>;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_cross_ladder_margin', SWAP_API_ROOT, params);\n}\n\n/**\n * APIv2币链参考信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec478f0-7773-11ed-9966-0242ac110003\n */\nexport function getV2ReferenceCurrencies(params: { currency?: string; authorizedUser?: string }): Promise<{\n code: number;\n data: {\n currency: string;\n assetType: number;\n chains: {\n chain: string;\n displayName: string;\n fullName: string;\n baseChain?: string;\n baseChainProtocol?: string;\n isDynamic?: boolean;\n numOfConfirmations: number;\n numOfFastConfirmations: number;\n depositStatus: string;\n minDepositAmt: string;\n withdrawStatus: string;\n minWithdrawAmt: string;\n withdrawPrecision: number;\n maxWithdrawAmt: string;\n withdrawQuotaPerDay: string;\n withdrawQuotaPerYear: null;\n withdrawQuotaTotal: null;\n withdrawFeeType: string;\n transactFeeWithdraw?: string;\n addrWithTag: boolean;\n addrDepositTag: boolean;\n minTransactFeeWithdraw?: string;\n transactFeeRateWithdraw?: string;\n maxTransactFeeWithdraw?: string;\n }[];\n instStatus: string;\n }[];\n}> {\n return publicRequest('GET', '/v2/reference/currencies', SPOT_API_ROOT, params);\n}\n\n/**\n * 【现货】获取市场所有交易对的最新行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40374-7773-11ed-9966-0242ac110003\n *\n */\nexport const getSpotMarketTickers = (): Promise<{\n data: {\n symbol: string;\n open: number;\n high: number;\n low: number;\n close: number;\n amount: number;\n vol: number;\n count: number;\n bid: number;\n bidSize: number;\n ask: number;\n askSize: number;\n }[];\n status: string;\n ts: number;\n}> => publicRequest('GET', '/market/tickers', SPOT_API_ROOT);\n"]}
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":";;;AAAA,yCAAoE;AAEpE,gBAAgB;AAChB,MAAM,aAAa,GAAG,cAAc,CAAC;AACrC,MAAM,aAAa,GAAG,eAAe,CAAC;AAKtC,MAAM,OAAO,GAAG,CAAC,QAAgB,EAAE,IAA6B,EAAE,EAAE;IAClE,MAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,QAAQ,CAAC,CAAC;IACrC,IAAA,kBAAU,EAAC,sBAAsB,kCAAO,IAAI,KAAE,QAAQ,KAAI,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACzF,CAAC,CAAC;AAEF,sDAAsD;AACtD,yCAAyC;AACzC,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAChE,IAAA,mBAAW,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,CAAC;AACvG,CAAC;AAvBD,oEAuBC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,MAMnC;IAeC,OAAO,uBAAuB,CAAC,KAAK,EAAE,sCAAsC,EAAE,MAAM,CAAC,CAAC;AACxF,CAAC;AAtBD,kDAsBC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,MAKxC;IAIC,OAAO,0BAA0B,CAAC,KAAK,EAAE,8CAA8C,EAAE,MAAM,CAAC,CAAC;AACnG,CAAC;AAVD,4DAUC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,MAAsD;IAkC7F,OAAO,oBAAoB,CAAC,KAAK,EAAE,0BAA0B,EAAE,MAAM,CAAC,CAAC;AACzE,CAAC;AAnCD,4DAmCC;AAED;;;;;GAKG;AACI,MAAM,oBAAoB,GAAG,GAiBjC,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAjBrC,QAAA,oBAAoB,wBAiBiB","sourcesContent":["import { formatTime, scopeError, tokenBucket } from '@yuants/utils';\n\n// Huobi API 根域名\nconst SWAP_API_ROOT = 'api.hbdm.com';\nconst SPOT_API_ROOT = 'api.huobi.pro';\n\ntype HuobiBusiness = 'spot' | 'linear-swap';\ntype HuobiPublicInterfaceType = 'market' | 'non-market';\n\nconst acquire = (bucketId: string, meta: Record<string, unknown>) => {\n const bucket = tokenBucket(bucketId);\n scopeError('HUOBI_API_RATE_LIMIT', { ...meta, bucketId }, () => bucket.acquireSync(1));\n};\n\n// https://www.htx.com/zh-cn/opend/newApiPages/?id=474\n// 行情类:同一个 IP,总共 1s 最多 800 个请求(合约业务共享总额度)\nconst marketDataIPAllBucketId = 'HUOBI_PUBLIC_MARKET_IP_1S_ALL';\ntokenBucket(marketDataIPAllBucketId, {\n capacity: 800,\n refillInterval: 1000,\n refillAmount: 800,\n});\n\n// 行情类:按业务线拆分(用于交割/币本位永续/U本位分开限频)\nconst marketDataSpotBucketId = 'HUOBI_PUBLIC_MARKET_IP_1S_SPOT';\ntokenBucket(marketDataSpotBucketId, { capacity: 800, refillInterval: 1000, refillAmount: 800 });\n\nconst marketDataLinearSwapBucketId = 'HUOBI_PUBLIC_MARKET_IP_1S_LINEAR_SWAP';\ntokenBucket(marketDataLinearSwapBucketId, { capacity: 800, refillInterval: 1000, refillAmount: 800 });\n\n// 非行情类公开接口:同一个 IP,3s 最多 120 次请求\nconst nonMarketDataIPBucketId = 'HUOBI_PUBLIC_NON_MARKET_IP_3S_ALL';\ntokenBucket(nonMarketDataIPBucketId, {\n capacity: 120,\n refillInterval: 3000,\n refillAmount: 120,\n});\n\n/**\n * 公共 API 请求方法(不负责限流;限流由调用点选择对应 helper)\n */\nasync function publicRequest(method: string, path: string, api_root: string, params?: any) {\n const url = new URL(`https://${api_root}${path}`);\n\n if (method === 'GET') {\n for (const [k, v] of Object.entries(params || {})) {\n url.searchParams.append(k, String(v));\n }\n }\n\n const body = method === 'GET' ? '' : JSON.stringify(params);\n\n console.info(formatTime(Date.now()), method, url.href, body);\n\n const res = await fetch(url.href, {\n method,\n headers: { 'Content-Type': 'application/json' },\n body: body || undefined,\n });\n\n console.info(formatTime(Date.now()), 'PublicResponse', url.toString(), res.status);\n\n const retStr = await res.text();\n try {\n return JSON.parse(retStr);\n } catch (e) {\n console.error(formatTime(Date.now()), 'huobiRequestFailed', path, JSON.stringify(params), retStr);\n throw e;\n }\n}\n\nconst spotMarketRequest = async (method: string, path: string, params?: any) => {\n const meta = {\n method,\n api_root: SPOT_API_ROOT,\n path,\n business: 'spot' as HuobiBusiness,\n interfaceType: 'market' as HuobiPublicInterfaceType,\n };\n acquire(marketDataIPAllBucketId, meta);\n acquire(marketDataSpotBucketId, meta);\n return publicRequest(method, path, SPOT_API_ROOT, params);\n};\n\nconst spotNonMarketRequest = async (method: string, path: string, params?: any) => {\n const meta = {\n method,\n api_root: SPOT_API_ROOT,\n path,\n business: 'spot' as HuobiBusiness,\n interfaceType: 'non-market' as HuobiPublicInterfaceType,\n };\n acquire(nonMarketDataIPBucketId, meta);\n return publicRequest(method, path, SPOT_API_ROOT, params);\n};\n\nconst linearSwapMarketRequest = async (method: string, path: string, params?: any) => {\n const meta = {\n method,\n api_root: SWAP_API_ROOT,\n path,\n business: 'linear-swap' as HuobiBusiness,\n interfaceType: 'market' as HuobiPublicInterfaceType,\n };\n acquire(marketDataIPAllBucketId, meta);\n acquire(marketDataLinearSwapBucketId, meta);\n return publicRequest(method, path, SWAP_API_ROOT, params);\n};\n\nconst linearSwapNonMarketRequest = async (method: string, path: string, params?: any) => {\n const meta = {\n method,\n api_root: SWAP_API_ROOT,\n path,\n business: 'linear-swap' as HuobiBusiness,\n interfaceType: 'non-market' as HuobiPublicInterfaceType,\n };\n acquire(nonMarketDataIPBucketId, meta);\n return publicRequest(method, path, SWAP_API_ROOT, params);\n};\n\n// ==================== 公共 API 方法 ====================\n\n/**\n * 获取永续合约产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72f34-77b5-11ed-9966-0242ac110003\n */\nexport function getPerpetualContractSymbols(params?: {\n contract_code?: string;\n support_margin_mode?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n symbol: string;\n contract_code: string;\n contract_size: number;\n price_tick: number;\n settlement_date: string;\n delivery_time: string;\n create_date: string;\n contract_status: number;\n support_margin_mode: string;\n contract_type: string;\n pair: string;\n business_type: string;\n delivery_date: string;\n }[];\n ts: string;\n}> {\n return linearSwapNonMarketRequest('GET', '/linear-swap-api/v1/swap_contract_info', params);\n}\n\n/**\n * 获取现货产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec47f16-7773-11ed-9966-0242ac110003\n */\nexport function getSpotSymbols(): Promise<{\n status: string;\n data: {\n si: string;\n scr: string;\n sc: string;\n dn: string;\n bc: string;\n bcdn: string;\n qc: string;\n qcdn: string;\n state: string;\n whe: boolean;\n cd: boolean;\n te: boolean;\n toa: number;\n sp: string;\n w: number;\n ttp: number;\n tap: number;\n tpp: number;\n fp: number;\n suspend_desc: string;\n transfer_board_desc: string;\n tags: string;\n lr: number;\n smlr: number;\n flr: string;\n wr: string;\n d: number;\n elr: number;\n p: any;\n castate: string;\n ca1oa: number;\n ca2oa: number;\n }[];\n ts: string;\n full: number;\n err_code: string;\n err_msg: string;\n}> {\n return spotNonMarketRequest('GET', '/v2/settings/common/symbols');\n}\n\n/**\n * 获取现货行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3fc25-7773-11ed-9966-0242ac110003\n */\nexport function getSpotTick(params: { symbol: string }): Promise<{\n status: string;\n tick: {\n close: number;\n };\n}> {\n return spotMarketRequest('GET', `/market/detail/merged`, params);\n}\n\n/**\n * 【现货】获取K线数据\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3ff18-7773-11ed-9966-0242ac110003\n *\n * Note: HTX spot KLine uses unix seconds in `data[].id`\n */\nexport function getSpotHistoryKline(params: {\n symbol: string;\n period: string;\n size?: number;\n from?: number;\n to?: number;\n}): Promise<{\n status: string;\n ch?: string;\n ts: number;\n data: {\n id: number;\n open: number;\n close: number;\n low: number;\n high: number;\n vol: number;\n amount?: number;\n count?: number;\n }[];\n}> {\n return spotMarketRequest('GET', `/market/history/kline`, params);\n}\n\n/**\n * 【通用】批量获取合约资金费率\n *\n * 接口权限: 读取\n *\n * 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多120次请求(所有该IP的非行情类的公开接口请求共享3秒120次的额度)\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb71b45-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapBatchFundingRate(params: { contract_code?: string }): Promise<{\n status: string;\n ts: number;\n data: {\n estimated_rate: null;\n funding_rate: string;\n contract_code: string;\n symbol: string;\n fee_asset: string;\n funding_time: string;\n next_funding_time: null;\n trade_partition: string;\n }[];\n}> {\n return linearSwapNonMarketRequest('GET', `/linear-swap-api/v1/swap_batch_funding_rate`, params);\n}\n\n/**\n * 【通用】获取市场最近成交记录\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73c34-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketTrade(params: { contract_code?: string; business_type?: string }): Promise<{\n ch: string;\n status: string;\n tick: {\n data: {\n amount: string;\n quantity: string;\n trade_turnover: string;\n ts: number;\n id: number;\n price: string;\n direction: string;\n contract_code: string;\n business_type: string;\n trade_partition: string;\n }[];\n id: number;\n ts: number;\n };\n ts: number;\n}> {\n return linearSwapMarketRequest('GET', `/linear-swap-ex/market/trade`, params);\n}\n\n/**\n * 获得当前合约的总持仓量\n *\n * https://huobiapi.github.io/docs/usdt_swap/v1/cn/#3218e7531a\n */\nexport function getSwapOpenInterest(params: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n volume: number;\n amount: number;\n symbol: string;\n value: number;\n contract_code: string;\n trade_amount: number;\n trade_volume: number;\n trade_turnover: number;\n business_type: string;\n pair: string;\n contract_type: string;\n }[];\n ts: number;\n}> {\n return linearSwapMarketRequest('GET', '/linear-swap-api/v1/swap_open_interest', params);\n}\n\n/**\n * 【通用】获取市场最优挂单\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb735e0-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketBbo(params: { contract_code?: string }): Promise<{\n status: string;\n ticks: {\n trade_partition: string;\n business_type: string;\n contract_code: string;\n ask: number[] | null;\n bid: number[] | null;\n mrid: number;\n ts: number;\n }[];\n ts: number;\n}> {\n return linearSwapMarketRequest('GET', `/linear-swap-ex/market/bbo`, params);\n}\n\n/**\n * 获取合约的历史资金费率\n *\n * 接口权限: 读取\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=5d51f1f9-77b6-11ed-9966-0242ac110003\n */\nexport function getSwapHistoricalFundingRate(params: {\n contract_code: string;\n page_index?: number;\n page_size?: number;\n}): Promise<{\n status: string;\n ts: number;\n data: {\n data: {\n symbol: string;\n contract_code: string;\n fee_asset: string;\n funding_time: string;\n funding_rate: string;\n realized_rate: string;\n avg_premium_index: string;\n }[];\n total_page: number;\n current_page: number;\n total_size: number;\n };\n}> {\n return linearSwapNonMarketRequest('GET', `/linear-swap-api/v1/swap_historical_funding_rate`, params);\n}\n\n/**\n * 【通用】获取K线数据\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73746-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapHistoryKline(params: {\n contract_code: string;\n period: string;\n size?: number;\n from?: number;\n to?: number;\n}): Promise<{\n status: string;\n ch?: string;\n ts: number;\n data: {\n id: number;\n open: number;\n close: number;\n low: number;\n high: number;\n vol: number;\n amount?: number;\n count?: number;\n }[];\n}> {\n return linearSwapMarketRequest('GET', `/linear-swap-ex/market/history/kline`, params);\n}\n\n/**\n * 【全仓】获取平台阶梯保证金\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72290-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapCrossLadderMargin(params?: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: Array<{ contract_code: string; pair: string; list: Array<{ lever_rate: number }> }>;\n}> {\n return linearSwapNonMarketRequest('GET', '/linear-swap-api/v1/swap_cross_ladder_margin', params);\n}\n\n/**\n * APIv2币链参考信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec478f0-7773-11ed-9966-0242ac110003\n */\nexport function getV2ReferenceCurrencies(params: { currency?: string; authorizedUser?: string }): Promise<{\n code: number;\n data: {\n currency: string;\n assetType: number;\n chains: {\n chain: string;\n displayName: string;\n fullName: string;\n baseChain?: string;\n baseChainProtocol?: string;\n isDynamic?: boolean;\n numOfConfirmations: number;\n numOfFastConfirmations: number;\n depositStatus: string;\n minDepositAmt: string;\n withdrawStatus: string;\n minWithdrawAmt: string;\n withdrawPrecision: number;\n maxWithdrawAmt: string;\n withdrawQuotaPerDay: string;\n withdrawQuotaPerYear: null;\n withdrawQuotaTotal: null;\n withdrawFeeType: string;\n transactFeeWithdraw?: string;\n addrWithTag: boolean;\n addrDepositTag: boolean;\n minTransactFeeWithdraw?: string;\n transactFeeRateWithdraw?: string;\n maxTransactFeeWithdraw?: string;\n }[];\n instStatus: string;\n }[];\n}> {\n return spotNonMarketRequest('GET', '/v2/reference/currencies', params);\n}\n\n/**\n * 【现货】获取市场所有交易对的最新行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40374-7773-11ed-9966-0242ac110003\n *\n */\nexport const getSpotMarketTickers = (): Promise<{\n data: {\n symbol: string;\n open: number;\n high: number;\n low: number;\n close: number;\n amount: number;\n vol: number;\n count: number;\n bid: number;\n bidSize: number;\n ask: number;\n askSize: number;\n }[];\n status: string;\n ts: number;\n}> => spotMarketRequest('GET', '/market/tickers');\n"]}
|
|
@@ -17,10 +17,10 @@ const getSwapAccountInfo = async (credential) => {
|
|
|
17
17
|
if (v.margin_balance === 0)
|
|
18
18
|
continue;
|
|
19
19
|
positions.push((0, data_account_1.makeSpotPosition)({
|
|
20
|
-
position_id: (0, utils_1.encodePath)('HTX', 'SWAP-
|
|
20
|
+
position_id: (0, utils_1.encodePath)('HTX', 'SWAP-ASSET', v.margin_asset),
|
|
21
21
|
datasource_id: 'HTX',
|
|
22
|
-
product_id: (0, utils_1.encodePath)('HTX', 'SWAP-
|
|
23
|
-
volume: +v.
|
|
22
|
+
product_id: (0, utils_1.encodePath)('HTX', 'SWAP-ASSET', v.margin_asset),
|
|
23
|
+
volume: +v.margin_static,
|
|
24
24
|
free_volume: +v.withdraw_available,
|
|
25
25
|
closable_price: usdAssets.has(v.margin_asset) ? 1 : 0,
|
|
26
26
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swap.js","sourceRoot":"","sources":["../../../src/services/accounts/swap.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AACnE,yCAA2C;AAC3C,uDAAqG;AACrG,wCAA0C;AAE1C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE7C,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IACxF,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,UAAU;IACV,MAAM,OAAO,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,CAAC,CAAC;IACxD,IAAI,CAAC,O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CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AA5CW,QAAA,kBAAkB,sBA4C7B","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getSwapCrossPositionInfo, getUnifiedAccountInfo, ICredential } from '../../api/private-api';\nimport { productCache } from '../product';\n\nconst usdAssets = new Set(['USDT', 'USDC', 'USDD']);\n\nexport const getSwapAccountInfo = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n // balance\n const balance = await getUnifiedAccountInfo(credential);\n if (!balance.data) {\n throw new Error('Failed to get unified account info');\n }\n\n for (const v of balance.data || []) {\n if (v.margin_balance === 0) continue;\n positions.push(\n makeSpotPosition({\n position_id: encodePath('HTX', 'SWAP-ASSET', v.margin_asset),\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP-ASSET', v.margin_asset),\n volume: +v.margin_static,\n free_volume: +v.withdraw_available,\n closable_price: usdAssets.has(v.margin_asset) ? 1 : 0,\n }),\n );\n }\n\n // positions\n const positionsRes = await getSwapCrossPositionInfo(credential);\n for (const v of positionsRes.data || []) {\n const product_id = encodePath('HTX', 'SWAP', v.contract_code);\n const theProduct = await productCache.query(product_id);\n const valuation = v.volume * v.last_price * (theProduct?.value_scale || 1);\n positions.push({\n position_id: `${product_id}/${v.contract_type}/${v.direction}/${v.margin_mode}`,\n datasource_id: 'HTX',\n product_id,\n direction: v.direction === 'buy' ? 'LONG' : 'SHORT',\n volume: v.volume,\n free_volume: v.available,\n position_price: v.cost_hold,\n closable_price: v.last_price,\n floating_profit: v.profit_unreal,\n liquidation_price: v.liquidation_price ? `${v.liquidation_price}` : undefined,\n valuation,\n });\n }\n\n return positions;\n};\n"]}
|
|
@@ -14,8 +14,8 @@ async function handleSwapOrder(order, credential) {
|
|
|
14
14
|
// 获取仓位信息
|
|
15
15
|
const positionInfo = await (0, private_api_1.getSwapCrossPositionInfo)(credential);
|
|
16
16
|
const mapContractCodeToRate = Object.fromEntries(positionInfo.data.map((v) => [v.contract_code, v.lever_rate]));
|
|
17
|
-
const lever_rate = (_a = mapContractCodeToRate[order.product_id]) !== null && _a !== void 0 ? _a : 20;
|
|
18
17
|
const [, instType, contractCode] = (0, utils_1.decodePath)(order.product_id);
|
|
18
|
+
const lever_rate = (_a = mapContractCodeToRate[contractCode]) !== null && _a !== void 0 ? _a : 20;
|
|
19
19
|
const params = {
|
|
20
20
|
contract_code: contractCode,
|
|
21
21
|
contract_type: 'swap',
|
|
@@ -31,7 +31,7 @@ async function handleSwapOrder(order, credential) {
|
|
|
31
31
|
const result = await (0, private_api_1.postSwapOrder)(credential, params);
|
|
32
32
|
console.info((0, utils_1.formatTime)(Date.now()), 'SubmitOrder', JSON.stringify(result), JSON.stringify(params));
|
|
33
33
|
if (result.status !== 'ok') {
|
|
34
|
-
throw
|
|
34
|
+
throw (0, utils_1.newError)(`HTX_SUBMIT_ORDER_FAILED`, { result });
|
|
35
35
|
}
|
|
36
36
|
return { order_id: result.data.order_id_str };
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,yCAA8E;AAC9E,uDAO+B;AAC/B,qDAAmD;AACnD,wCAA0C;AAC1C,gCAAoD;AAEpD;;GAEG;AACH,KAAK,UAAU,eAAe,CAAC,KAAa,EAAE,UAAuB;;IACnE,SAAS;IACT,MAAM,YAAY,GAAG,MAAM,IAAA,sCAAwB,EAAC,UAAU,CAAC,CAAC;IAChE,MAAM,qBAAqB,GAAG,MAAM,CAAC,WAAW,CAC9C,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAC9D,CAAC;IAEF,MAAM,
|
|
1
|
+
{"version":3,"file":"submitOrder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IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;AACtD,CAAC;AAEM,MAAM,WAAW,GAAG,CAAC,UAAuB,EAAE,KAAa,EAAiC,EAAE;IACnG,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAClD,IAAI,QAAQ,KAAK,MAAM,EAAE;QACvB,OAAO,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;KAC3C;IACD,IAAI,QAAQ,KAAK,cAAc,EAAE;QAC/B,OAAO,sBAAsB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;KAClD;IACD,MAAM,IAAA,gBAAQ,EAAC,uBAAuB,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;AACpE,CAAC,CAAC;AATW,QAAA,WAAW,eAStB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, newError, roundToStep } from '@yuants/utils';\nimport {\n ICredential,\n getCrossMarginLoanInfo,\n getSpotAccountBalance,\n getSwapCrossPositionInfo,\n postSpotOrder,\n postSwapOrder,\n} from '../../api/private-api';\nimport { getSpotTick } from '../../api/public-api';\nimport { productCache } from '../product';\nimport { superMarginAccountUidCache } from '../uid';\n\n/**\n * 处理 swap 账户订单提交\n */\nasync function handleSwapOrder(order: IOrder, credential: ICredential): Promise<{ order_id: string }> {\n // 获取仓位信息\n const positionInfo = await getSwapCrossPositionInfo(credential);\n const mapContractCodeToRate = Object.fromEntries(\n positionInfo.data.map((v) => [v.contract_code, v.lever_rate]),\n );\n\n const [, instType, contractCode] = decodePath(order.product_id);\n const lever_rate = mapContractCodeToRate[contractCode] ?? 20;\n const params = {\n contract_code: contractCode,\n contract_type: 'swap',\n price: order.price,\n volume: order.volume,\n offset:\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'OPEN_SHORT' ? 'open' : 'close',\n direction:\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'buy' : 'sell',\n // dynamically adjust the leverage\n lever_rate,\n order_price_type: order.order_type === 'MARKET' ? 'market' : 'limit',\n channel_code: process.env.BROKER_ID,\n };\n\n const result = await postSwapOrder(credential, params);\n console.info(formatTime(Date.now()), 'SubmitOrder', JSON.stringify(result), JSON.stringify(params));\n\n if (result.status !== 'ok') {\n throw newError(`HTX_SUBMIT_ORDER_FAILED`, { result });\n }\n return { order_id: result.data.order_id_str };\n}\n\n/**\n * 处理 super-margin 账户订单提交\n */\nasync function handleSuperMarginOrder(order: IOrder, credential: ICredential): Promise<{ order_id: string }> {\n // 获取可贷款金额\n const superMarginAccountUid = await superMarginAccountUidCache.query(JSON.stringify(credential));\n if (!superMarginAccountUid) throw new Error('Super margin account UID not found');\n const loanInfo = await getCrossMarginLoanInfo(credential);\n const usdtLoanable = loanInfo.data.find((v) => v.currency === 'usdt');\n if (!usdtLoanable) throw new Error('USDT loanable amount not found');\n const loanable = +usdtLoanable['loanable-amt'];\n\n const [, instType, contractCode] = decodePath(order.product_id);\n\n // 获取账户余额, 产品信息和价格\n const [balanceRes, theProduct, priceRes] = await Promise.all([\n getSpotAccountBalance(credential, superMarginAccountUid),\n productCache.query(order.product_id),\n getSpotTick({ symbol: contractCode }),\n ]);\n\n const balance = balanceRes.data.list\n .filter((v) => v.currency === 'usdt' && v.type === 'trade')\n .reduce((acc, cur) => acc + +cur.balance, 0);\n\n if (!theProduct) throw newError('HUOBI_SUBMIT_ORDER_PRODUCT_NOT_FOUND', { product_id: order.product_id });\n\n const price = priceRes.tick.close;\n const borrow_amount =\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? Math.max(Math.min(loanable, order.volume * price - balance), 0)\n : undefined;\n\n const params = {\n symbol: contractCode,\n 'account-id': '' + superMarginAccountUid,\n amount:\n '' +\n (order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? roundToStep(order.volume * price, theProduct?.volume_step!)\n : order.volume),\n 'borrow-amount': '' + borrow_amount,\n type: `${\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'buy' : 'sell'\n }-${'LIMIT' === order.order_type ? 'limit' : 'market'}`,\n 'trade-purpose':\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? '1' // auto borrow\n : '2', // auto repay\n price: order.order_type === 'MARKET' ? undefined : '' + order.price,\n source: 'super-margin-api',\n 'client-order-id': process.env.BROKER_ID,\n };\n\n const result = await postSpotOrder(credential, params);\n console.info(formatTime(Date.now()), 'SubmitOrder', JSON.stringify(result), JSON.stringify(params));\n\n if (result.success === false) {\n throw new Error(`Failed to submit super margin order: code=${result.code} message=${result.message}`);\n }\n\n return { order_id: result.data.orderId.toString() };\n}\n\nexport const submitOrder = (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const [, instType] = decodePath(order.product_id);\n if (instType === 'SWAP') {\n return handleSwapOrder(order, credential);\n }\n if (instType === 'SUPER-MARGIN') {\n return handleSuperMarginOrder(order, credential);\n }\n throw newError('UNSUPPORTED_INST_TYPE', { order_type: instType });\n};\n"]}
|