@yuants/vendor-huobi 0.18.12 → 0.19.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/private-api.js +8 -0
- package/dist/api/private-api.js.map +1 -1
- package/dist/api/public-api.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/accounts/spot.js.map +1 -1
- package/dist/services/accounts/super-margin.js.map +1 -1
- package/dist/services/accounts/swap.js.map +1 -1
- package/dist/services/exchange.js +1 -1
- package/dist/services/exchange.js.map +1 -1
- package/dist/services/interest-ledger-service.js +63 -0
- package/dist/services/interest-ledger-service.js.map +1 -0
- package/dist/services/interest-rate-service.js.map +1 -1
- package/dist/services/market-data/quote.js.map +1 -1
- package/dist/services/ohlc-service.js.map +1 -1
- package/dist/services/orders/listOrders.js +2 -2
- package/dist/services/orders/listOrders.js.map +1 -1
- package/dist/services/orders/submitOrder.js +1 -1
- package/dist/services/orders/submitOrder.js.map +1 -1
- package/dist/services/product.js.map +1 -1
- package/lib/api/private-api.d.ts +61 -32
- package/lib/api/private-api.d.ts.map +1 -1
- package/lib/api/private-api.js +10 -1
- package/lib/api/private-api.js.map +1 -1
- package/lib/api/public-api.d.ts.map +1 -1
- package/lib/api/public-api.js +13 -13
- package/lib/api/public-api.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/services/accounts/spot.js.map +1 -1
- package/lib/services/accounts/super-margin.js.map +1 -1
- package/lib/services/accounts/swap.d.ts.map +1 -1
- package/lib/services/accounts/swap.js.map +1 -1
- package/lib/services/exchange.js +1 -1
- package/lib/services/exchange.js.map +1 -1
- package/lib/services/interest-ledger-service.d.ts +2 -0
- package/lib/services/interest-ledger-service.d.ts.map +1 -0
- package/lib/services/interest-ledger-service.js +65 -0
- package/lib/services/interest-ledger-service.js.map +1 -0
- package/lib/services/interest-rate-service.js.map +1 -1
- package/lib/services/market-data/quote.js.map +1 -1
- package/lib/services/ohlc-service.js.map +1 -1
- package/lib/services/orders/listOrders.d.ts.map +1 -1
- package/lib/services/orders/listOrders.js +2 -2
- package/lib/services/orders/listOrders.js.map +1 -1
- package/lib/services/orders/submitOrder.d.ts.map +1 -1
- package/lib/services/orders/submitOrder.js +1 -1
- package/lib/services/orders/submitOrder.js.map +1 -1
- package/lib/services/product.d.ts.map +1 -1
- package/lib/services/product.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +43 -43
- package/temp/build/typescript/ts_pRZ94LVe.json +1 -0
- package/temp/package-deps.json +23 -23
- package/temp/test/jest/haste-map-fefe7499bc87b2b52172761a7fafd5ee-e0af843dfeade9e9ece596ee0c4ddcd4-4c5295047830cedf09a623a6f26c8535 +0 -0
- package/temp/vendor-huobi.api.json +18 -2
- package/dist/services/market-data/interest_rate.js +0 -62
- package/dist/services/market-data/interest_rate.js.map +0 -1
- package/lib/services/market-data/interest_rate.d.ts +0 -2
- package/lib/services/market-data/interest_rate.d.ts.map +0 -1
- package/lib/services/market-data/interest_rate.js +0 -64
- package/lib/services/market-data/interest_rate.js.map +0 -1
package/dist/api/private-api.js
CHANGED
|
@@ -289,4 +289,12 @@ export const getUnionAccountBalance = (credential) => {
|
|
|
289
289
|
export const getUnionAccountPositions = (credential) => {
|
|
290
290
|
return linearSwapPrivateQueryRequest(credential, 'GET', '/v5/trade/position/opens');
|
|
291
291
|
};
|
|
292
|
+
/**
|
|
293
|
+
* 组合查询用户财务记录 (新))
|
|
294
|
+
*
|
|
295
|
+
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb75a91-77b5-11ed-9966-0242ac110003
|
|
296
|
+
*/
|
|
297
|
+
export const getAccountFinancialRecordExact = (credential, params) => {
|
|
298
|
+
return linearSwapPrivateTradeRequest(credential, 'POST', '/linear-swap-api/v3/swap_financial_record_exact', params);
|
|
299
|
+
};
|
|
292
300
|
//# sourceMappingURL=private-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M,CAAC,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;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,UAAuB,EAQtB,EAAE;IACH,OAAO,6BAA6B,CAAC,UAAU,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAC;AACpF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,UAAuB,EAgCtB,EAAE;IACH,OAAO,6BAA6B,CAAC,UAAU,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC;AACjF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,UAAuB,EA2BtB,EAAE;IACH,OAAO,6BAA6B,CAAC,UAAU,EAAE,KAAK,EAAE,0BAA0B,CAAC,CAAC;AACtF,CAAC,CAAC","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 acquirePrivate = (bucketId: string, meta: Record<string, unknown>) => {\n scopeError('HUOBI_API_RATE_LIMIT', { ...meta, bucketId }, () =>\n tokenBucket(bucketId, { capacity: 36, refillAmount: 36, refillInterval: 3000 }).acquireSync(1),\n );\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=8cb89359-77b5-11ed-9966-1957dd521e6\n */\nexport const postUnionAccountSwapOrder = (\n credential: ICredential,\n params: {\n time_in_force?: string;\n price_protect?: string;\n contract_code: string;\n margin_mode: string;\n position_side: string;\n price?: number;\n volume: number;\n side: string;\n type: string;\n tp_trigger_price?: string;\n tp_order_price?: string;\n tp_trigger_price_type?: string;\n tp_type?: string;\n sl_trigger_price?: string;\n sl_order_price?: string;\n sl_trigger_price_type?: string;\n sl_type?: string;\n },\n): Promise<{ code: number; message: string; data: { order_id: number; order_id_str: string } }> => {\n return linearSwapPrivateTradeRequest(credential, 'POST', '/v5/trade/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\n/**\n * 查询资产模式\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1957dd37de0\n */\nexport const getAccountAssetsMode = (\n credential: ICredential,\n): Promise<{\n code: number;\n msg: string;\n data: {\n asset_mode: number;\n };\n ts: number;\n}> => {\n return linearSwapPrivateQueryRequest(credential, 'GET', '/v5/account/asset_mode');\n};\n\n/**\n * 查询联合保证金账户余额\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-195703a12d5\n */\nexport const getUnionAccountBalance = (\n credential: ICredential,\n): Promise<{\n code: number;\n message: string;\n data: {\n available_margin: string;\n created_time: number;\n details: {\n available: string;\n created_time: number;\n currency: string;\n equity: string;\n initial_margin: string;\n initial_margin_rate: string;\n maintenance_margin: string;\n maintenance_margin_rate: string;\n profit_unreal: string;\n voucher: string;\n voucher_value: string;\n withdraw_available: string;\n updated_time: number;\n }[];\n equity: string;\n initial_margin: string;\n maintenance_margin: string;\n maintenance_margin_rate: string;\n profit_unreal: string;\n state: string;\n voucher_value: string;\n updated_time: number;\n };\n ts: number;\n}> => {\n return linearSwapPrivateQueryRequest(credential, 'GET', '/v5/account/balance');\n};\n\n/**\n * 查询联合保证金账户持仓\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1957f1fbee4\n */\nexport const getUnionAccountPositions = (\n credential: ICredential,\n): Promise<{\n code: number;\n message: string;\n data: {\n contract_code: string;\n position_side: string;\n direction: string;\n margin_mode: string;\n open_avg_price: string;\n volume: string;\n available: string;\n lever_rate: number;\n adl_risk_percent: null;\n liquidation_price: string;\n initial_margin: string;\n maintenance_margin: string;\n profit_unreal: string;\n profit_rate: string;\n margin_rate: string;\n mark_price: string;\n margin_currency: string;\n contract_type: string;\n created_time: number;\n updated_time: number;\n }[];\n ts: number;\n}> => {\n return linearSwapPrivateQueryRequest(credential, 'GET', '/v5/trade/position/opens');\n};\n"]}
|
|
1
|
+
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE9F,MAAM,aAAa,GAAG,eAAe,CAAC;AACtC,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAO5C,MAAM,CAAC,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;AAMF,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,IAA6B,EAAE,EAAE;IACzE,UAAU,CAAC,sBAAsB,kCAAO,IAAI,KAAE,QAAQ,KAAI,GAAG,EAAE,CAC7D,WAAW,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAC/F,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,2BAA2B,GAAG,KAAK,EACvC,UAAuB,EACvB,aAAwC,EACxC,QAAuB,EACvB,MAAc,EACd,IAAY,EACZ,QAAgB,EAChB,MAAY,EACZ,EAAE;IACF,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE,CAAC;IAEpG,MAAM,kBAAkB,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IACvD,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC7C,MAAM,cAAc,GAAG,iBAAiB,kBAAkB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,CAAC,CAAC;AACxF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,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;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,UAAuB,EAQtB,EAAE;IACH,OAAO,6BAA6B,CAAC,UAAU,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAC;AACpF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,UAAuB,EAgCtB,EAAE;IACH,OAAO,6BAA6B,CAAC,UAAU,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC;AACjF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,UAAuB,EA2BtB,EAAE;IACH,OAAO,6BAA6B,CAAC,UAAU,EAAE,KAAK,EAAE,0BAA0B,CAAC,CAAC;AACtF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,UAAuB,EACvB,MAQC,EAgBA,EAAE;IACH,OAAO,6BAA6B,CAClC,UAAU,EACV,MAAM,EACN,iDAAiD,EACjD,MAAM,CACP,CAAC;AACJ,CAAC,CAAC","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 acquirePrivate = (bucketId: string, meta: Record<string, unknown>) => {\n scopeError('HUOBI_API_RATE_LIMIT', { ...meta, bucketId }, () =>\n tokenBucket(bucketId, { capacity: 36, refillAmount: 36, refillInterval: 3000 }).acquireSync(1),\n );\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=8cb89359-77b5-11ed-9966-1957dd521e6\n */\nexport const postUnionAccountSwapOrder = (\n credential: ICredential,\n params: {\n time_in_force?: string;\n price_protect?: string;\n contract_code: string;\n margin_mode: string;\n position_side: string;\n price?: number;\n volume: number;\n side: string;\n type: string;\n tp_trigger_price?: string;\n tp_order_price?: string;\n tp_trigger_price_type?: string;\n tp_type?: string;\n sl_trigger_price?: string;\n sl_order_price?: string;\n sl_trigger_price_type?: string;\n sl_type?: string;\n },\n): Promise<{ code: number; message: string; data: { order_id: number; order_id_str: string } }> => {\n return linearSwapPrivateTradeRequest(credential, 'POST', '/v5/trade/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\n/**\n * 查询资产模式\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1957dd37de0\n */\nexport const getAccountAssetsMode = (\n credential: ICredential,\n): Promise<{\n code: number;\n msg: string;\n data: {\n asset_mode: number;\n };\n ts: number;\n}> => {\n return linearSwapPrivateQueryRequest(credential, 'GET', '/v5/account/asset_mode');\n};\n\n/**\n * 查询联合保证金账户余额\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-195703a12d5\n */\nexport const getUnionAccountBalance = (\n credential: ICredential,\n): Promise<{\n code: number;\n message: string;\n data: {\n available_margin: string;\n created_time: number;\n details: {\n available: string;\n created_time: number;\n currency: string;\n equity: string;\n initial_margin: string;\n initial_margin_rate: string;\n maintenance_margin: string;\n maintenance_margin_rate: string;\n profit_unreal: string;\n voucher: string;\n voucher_value: string;\n withdraw_available: string;\n updated_time: number;\n }[];\n equity: string;\n initial_margin: string;\n maintenance_margin: string;\n maintenance_margin_rate: string;\n profit_unreal: string;\n state: string;\n voucher_value: string;\n updated_time: number;\n };\n ts: number;\n}> => {\n return linearSwapPrivateQueryRequest(credential, 'GET', '/v5/account/balance');\n};\n\n/**\n * 查询联合保证金账户持仓\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1957f1fbee4\n */\nexport const getUnionAccountPositions = (\n credential: ICredential,\n): Promise<{\n code: number;\n message: string;\n data: {\n contract_code: string;\n position_side: string;\n direction: string;\n margin_mode: string;\n open_avg_price: string;\n volume: string;\n available: string;\n lever_rate: number;\n adl_risk_percent: null;\n liquidation_price: string;\n initial_margin: string;\n maintenance_margin: string;\n profit_unreal: string;\n profit_rate: string;\n margin_rate: string;\n mark_price: string;\n margin_currency: string;\n contract_type: string;\n created_time: number;\n updated_time: number;\n }[];\n ts: number;\n}> => {\n return linearSwapPrivateQueryRequest(credential, 'GET', '/v5/trade/position/opens');\n};\n\n/**\n * 组合查询用户财务记录 (新))\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb75a91-77b5-11ed-9966-0242ac110003\n */\nexport const getAccountFinancialRecordExact = (\n credential: ICredential,\n params: {\n mar_acct: string;\n contract?: string;\n type?: string;\n start_time?: number;\n end_time?: number;\n direct?: string;\n from_id?: number;\n },\n): Promise<{\n code: number;\n msg: string;\n data: {\n query_id: number;\n id: number;\n type: number;\n amount: number;\n ts: number;\n contract_code: string;\n asset: string;\n margin_account: string;\n face_margin_account: string;\n }[];\n ts: number;\n}> => {\n return linearSwapPrivateTradeRequest(\n credential,\n 'POST',\n '/linear-swap-api/v3/swap_financial_record_exact',\n params,\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;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,WAAW,CAAC,QAAQ,CAAC,CAAC;IACrC,UAAU,CAAC,sBAAsB,kCAAO,IAAI,KAAE,QAAQ,KAAI,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,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;AACvG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAMnC;IAeC,OAAO,uBAAuB,CAAC,KAAK,EAAE,sCAAsC,EAAE,MAAM,CAAC,CAAC;AACxF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAKxC;IAIC,OAAO,0BAA0B,CAAC,KAAK,EAAE,8CAA8C,EAAE,MAAM,CAAC,CAAC;AACnG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAsD;IAkC7F,OAAO,oBAAoB,CAAC,KAAK,EAAE,0BAA0B,EAAE,MAAM,CAAC,CAAC;AACzE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAiBjC,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC","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"]}
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;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,WAAW,CAAC,QAAQ,CAAC,CAAC;IACrC,UAAU,CAAC,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,WAAW,CAAC,uBAAuB,EAAE;IACnC,QAAQ,EAAE,GAAG;IACb,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,GAAG;CAClB,CAAC,CAAC;AAEH,iCAAiC;AACjC,MAAM,sBAAsB,GAAG,gCAAgC,CAAC;AAChE,WAAW,CAAC,sBAAsB,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;AAEhG,MAAM,4BAA4B,GAAG,uCAAuC,CAAC;AAC7E,WAAW,CAAC,4BAA4B,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;AAEtG,gCAAgC;AAChC,M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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"]}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import './services/exchange';
|
|
2
|
-
import './services/market-data/interest_rate';
|
|
3
2
|
import './services/market-data/quote';
|
|
4
3
|
import './services/quotes';
|
|
5
4
|
import './services/ohlc-service';
|
|
6
5
|
import './services/interest-rate-service';
|
|
6
|
+
import './services/interest-ledger-service';
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,8BAA8B,CAAC;AACtC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,yBAAyB,CAAC;AACjC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,oCAAoC,CAAC","sourcesContent":["import './services/exchange';\nimport './services/market-data/quote';\nimport './services/quotes';\nimport './services/ohlc-service';\nimport './services/interest-rate-service';\nimport './services/interest-ledger-service';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,qBAAqB,EAAe,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,CAAC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;;IAClG,MAAM,cAAc,GAAG,MAAM,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACnF,IAAI,CAAC,cAAc;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAE5E,MAAM,SAAS,GAAgB,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/acc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C5B,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,UAAU;YACtB,MAAM,EAAE,CAAC,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC;YACzB,WAAW,EAAE,CAAC,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC;YAC9B,cAAc,EAAE,cAAc;YAC9B,IAAI,EAAE,CAAC,CAAC,OAAO;SAChB,CAAC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { getSpotAccountBalance, ICredential } from '../../api/private-api';\nimport { spotAccountUidCache } from '../uid';\nimport { encodePath } from '@yuants/utils';\nimport { quoteCache } from '../market-data/quote';\n\nexport const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const spotAccountUid = await spotAccountUidCache.query(JSON.stringify(credential));\n if (!spotAccountUid) throw new Error('Failed to get Spot Account UID');\n const spotBalance = await getSpotAccountBalance(credential, spotAccountUid);\n\n const positions: IPosition[] = [];\n\n for (const v of spotBalance.data.list) {\n if (v.balance === '0') continue;\n const product_id = encodePath('HTX', 'SPOT', v.currency + 'usdt');\n const quote = await quoteCache.query(product_id);\n const closable_price = v.currency === 'usdt' ? 1 : +(quote?.ask_price ?? 0);\n positions.push(\n makeSpotPosition({\n position_id: `${v.currency}`,\n datasource_id: 'HTX',\n product_id: product_id,\n volume: +(v.balance ?? 0),\n free_volume: +(v.balance ?? 0),\n closable_price: closable_price,\n size: v.balance,\n }),\n );\n }\n return positions;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"super-margin.js","sourceRoot":"","sources":["../../../src/services/accounts/super-margin.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,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AAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACjG,IAAI,CAAC,qBAAqB;QAAE,OAAO,EAAE,CAAC;IACtC,MAAM,cAAc,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC;IACtF,MAAM,WAAW,GAAG,CAAA,MAAA,cAAc,CAAC,IAAI,0CAAE,IAAI,KAAI,EAAE,CAAC;IAEpD,kCAAkC;IAClC,KAAK,MAAM,YAAY,IAAI,WAAW,EAAE,CAAC;QACvC,IAAI,YAAY,CAAC,OAAO,KAAK,GAAG;YAAE,SAAS;QAC3C,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,YAAY,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAC;QACrF,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC5D,MAAM,cAAc,GAAG,YAAY,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,mCAAI,CAAC,CAAC,CAAC;QAEvF,SAAS,CAAC,IAAI,CACZ,gBAAgB,CAAC;YACf,WAAW,EAAE,GAAG,YAAY,CAAC,QAAQ,YAAY;YACjD,UAAU,EAAE,UAAU;YACtB,MAAM,EAAE,CAAC,YAAY,CAAC,OAAO;YAC7B,WAAW,EAAE,CAAC,YAAY,CAAC,OAAO;YAClC,cAAc,EAAE,cAAc;YAC9B,IAAI,EAAE,YAAY,CAAC,OAAO;SAC3B,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getSpotAccountBalance, ICredential } from '../../api/private-api';\nimport { quoteCache } from '../market-data/quote';\nimport { superMarginAccountUidCache } from '../uid';\n\n/**\n * 全仓杠杆账户 (Super Margin Account)\n */\nexport const getSuperMarginAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const positions: IPosition[] = [];\n // get account balance\n const superMarginAccountUid = await superMarginAccountUidCache.query(JSON.stringify(credential));\n if (!superMarginAccountUid) return [];\n const accountBalance = await getSpotAccountBalance(credential, superMarginAccountUid);\n const balanceList = accountBalance.data?.list || [];\n\n // get prices and create positions\n for (const currencyData of balanceList) {\n if (currencyData.balance === '0') continue;\n const product_id = encodePath('HTX', 'SUPER-MARGIN', currencyData.currency + 'usdt');\n const quote = await quoteCache.query(currencyData.currency);\n const closable_price = currencyData.currency === 'usdt' ? 1 : +(quote?.ask_price ?? 0);\n\n positions.push(\n makeSpotPosition({\n position_id: `${currencyData.currency}/usdt/spot`,\n product_id: product_id,\n volume: +currencyData.balance,\n free_volume: +currencyData.balance,\n closable_price: closable_price,\n size: currencyData.balance,\n }),\n );\n }\n\n return positions;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swap.js","sourceRoot":"","sources":["../../../src/services/accounts/swap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,GAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IACxF,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,UAAU;IACV,MAAM,OAAO,GAAG,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AI,IAAI,EAAE,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC;QAC9D,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACxD,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,WAAW,KAAI,CAAC,CAAC,CAAC;QAC7E,SAAS,CAAC,IAAI,CAAC;YACb,WAAW,EAAE,GAAG,UAAU,IAAI,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,WAAW,EAAE;YAC/E,aAAa,EAAE,KAAK;YACpB,UAAU;YACV,SAAS,EAAE,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;YACnD,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM;YACjB,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;YACzB,cAAc,EAAE,CAAC,CAAC,CAAC,cAAc;YACjC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;YAC7B,eAAe,EAAE,CAAC,CAAC,CAAC,aAAa;YACjC,iBAAiB,EAAE,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS;YAC7E,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport {\n getSwapCrossPositionInfo,\n getUnifiedAccountInfo,\n getUnionAccountBalance,\n getUnionAccountPositions,\n ICredential,\n} 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\nexport const getUnionAccountInfo = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n // balance\n const [balance, position] = await Promise.all([\n getUnionAccountBalance(credential),\n getUnionAccountPositions(credential),\n ]);\n\n if (!balance.data || !balance.data.details) {\n throw new Error('Failed to get union account balance');\n }\n for (const v of balance.data.details || []) {\n positions.push(\n makeSpotPosition({\n position_id: encodePath('HTX', 'SWAP-ASSET', v.currency),\n datasource_id: 'HTX',\n product_id: encodePath('HTX', 'SWAP-ASSET', v.currency),\n volume: +v.available,\n free_volume: +v.withdraw_available,\n closable_price: usdAssets.has(v.currency) ? 1 : 0,\n size: v.available,\n }),\n );\n }\n if (!position || !position.data) {\n throw new Error('Failed to get union account positions');\n }\n for (const v of position.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.mark_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.open_avg_price,\n closable_price: +v.mark_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"]}
|
|
@@ -16,7 +16,7 @@ export const accountModeCache = createCache(async (credentialKey) => {
|
|
|
16
16
|
const res = await getAccountAssetsMode(credential);
|
|
17
17
|
return res.data.asset_mode;
|
|
18
18
|
}, {
|
|
19
|
-
expire: 600000,
|
|
19
|
+
expire: 600000, // 10 minutes
|
|
20
20
|
swrAfter: 60000, // 1 minute
|
|
21
21
|
});
|
|
22
22
|
provideExchangeServices(terminal, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAe,oBAAoB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAA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AC,CAAC;QACnE,CAAC;QACD,MAAM,QAAQ,CAAC,sBAAsB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACzD,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, encodePath, newError } from '@yuants/utils';\nimport { ICredential, getAccountAssetsMode, getUid } from '../api/private-api';\nimport { getSpotAccountInfo } from './accounts/spot';\nimport { getSuperMarginAccountInfo } from './accounts/super-margin';\nimport { getSwapAccountInfo, getUnionAccountInfo } from './accounts/swap';\nimport { listSwapOrders } from './orders/listOrders';\nimport { submitOrder } from './orders/submitOrder';\nimport { listProducts } from './product';\nimport { createCache } from '@yuants/cache';\n\nconst terminal = Terminal.fromNodeEnv();\n\nexport const accountModeCache = createCache(\n async (credentialKey: string) => {\n const [access_key, secret_key] = decodePath(credentialKey);\n const credential = { access_key, secret_key };\n const res = await getAccountAssetsMode(credential);\n return res.data.asset_mode;\n },\n {\n expire: 600_000, // 10 minutes\n swrAfter: 60_000, // 1 minute\n },\n);\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'HTX',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n getCredentialId: async (credential) => {\n const res = await getUid(credential);\n return encodePath('HTX', res.data);\n },\n listProducts,\n getPositions: async (credential) => {\n const accountMode = await accountModeCache.query(\n encodePath(credential.access_key, credential.secret_key),\n );\n if (accountMode === 1) {\n const [swap, spot, superMargin] = await Promise.all([\n getUnionAccountInfo(credential),\n getSpotAccountInfo(credential, 'spot'),\n getSuperMarginAccountInfo(credential, 'super-margin'),\n ]);\n return [...swap, ...spot, ...superMargin];\n } else {\n const [swap, spot, superMargin] = await Promise.all([\n getSwapAccountInfo(credential),\n getSpotAccountInfo(credential, 'spot'),\n getSuperMarginAccountInfo(credential, 'super-margin'),\n ]);\n return [...swap, ...spot, ...superMargin];\n }\n },\n getOrders: async (credential) => {\n const swapOrders = await listSwapOrders(credential);\n return swapOrders;\n },\n submitOrder,\n cancelOrder: async (credential, order) => {\n throw new Error('Not Implemented');\n },\n modifyOrder: async (credential, order) => {\n throw new Error('Not Implemented');\n },\n getPositionsByProductId: async (credential, product_id) => {\n const [, instType] = decodePath(product_id);\n if (instType === 'SPOT') {\n const positions = await getSpotAccountInfo(credential, product_id);\n return positions.filter((pos) => pos.product_id === product_id);\n }\n if (instType === 'SWAP') {\n const positions = await getSwapAccountInfo(credential);\n return positions.filter((pos) => pos.product_id === product_id);\n }\n if (instType === 'SUPER-MARGIN') {\n const positions = await getSuperMarginAccountInfo(credential, product_id);\n return positions.filter((pos) => pos.product_id === product_id);\n }\n throw newError('UnsupportedProductId', { product_id });\n },\n getOrdersByProductId: async (credential: ICredential, product_id: string): Promise<IOrder[]> => {\n const [, instType] = decodePath(product_id);\n // if (instType === 'SPOT') {\n // const orders = await listSpotOrders(credential, product_id);\n // return orders.filter((order) => order.product_id === product_id);\n // }\n if (instType === 'SWAP') {\n const orders = await listSwapOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw newError('UnsupportedProductId', { product_id });\n },\n});\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Terminal } from '@yuants/protocol';
|
|
2
|
+
import { encodePath, formatTime } from '@yuants/utils';
|
|
3
|
+
import { provideInterestLedgerService } from '@yuants/exchange';
|
|
4
|
+
import { getAccountFinancialRecordExact } from '../api/private-api';
|
|
5
|
+
const terminal = Terminal.fromNodeEnv();
|
|
6
|
+
const WINDOW_MS = 2 * 24 * 3600000;
|
|
7
|
+
const fetchInterestRateLedgerBackward = async (req) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const params = {
|
|
10
|
+
end_time: req.time,
|
|
11
|
+
start_time: req.time - WINDOW_MS,
|
|
12
|
+
type: req.ledger_type,
|
|
13
|
+
direct: 'prev',
|
|
14
|
+
mar_acct: 'USDT',
|
|
15
|
+
};
|
|
16
|
+
const res = await getAccountFinancialRecordExact(req.credential.payload, params);
|
|
17
|
+
return ((_a = res.data) !== null && _a !== void 0 ? _a : [])
|
|
18
|
+
.map((v) => {
|
|
19
|
+
const ms = v.ts;
|
|
20
|
+
return {
|
|
21
|
+
id: v.id.toString(),
|
|
22
|
+
product_id: encodePath('HTX', 'SWAP', v.contract_code),
|
|
23
|
+
amount: v.amount.toString(),
|
|
24
|
+
account_id: req.account_id,
|
|
25
|
+
currency: v.asset,
|
|
26
|
+
created_at: formatTime(ms),
|
|
27
|
+
};
|
|
28
|
+
})
|
|
29
|
+
.filter((x) => Date.parse(x.created_at) <= req.time);
|
|
30
|
+
};
|
|
31
|
+
const fetchInterestRateLedgerForward = async (req) => {
|
|
32
|
+
var _a;
|
|
33
|
+
const params = {
|
|
34
|
+
end_time: req.time,
|
|
35
|
+
start_time: req.time - WINDOW_MS,
|
|
36
|
+
type: req.ledger_type,
|
|
37
|
+
direct: 'next',
|
|
38
|
+
mar_acct: 'USDT',
|
|
39
|
+
};
|
|
40
|
+
const res = await getAccountFinancialRecordExact(req.credential.payload, params);
|
|
41
|
+
return ((_a = res.data) !== null && _a !== void 0 ? _a : [])
|
|
42
|
+
.map((v) => {
|
|
43
|
+
const ms = v.ts;
|
|
44
|
+
return {
|
|
45
|
+
id: v.id.toString(),
|
|
46
|
+
product_id: encodePath('HTX', 'SWAP', v.contract_code),
|
|
47
|
+
amount: v.amount.toString(),
|
|
48
|
+
account_id: req.account_id,
|
|
49
|
+
currency: v.asset,
|
|
50
|
+
created_at: formatTime(ms),
|
|
51
|
+
};
|
|
52
|
+
})
|
|
53
|
+
.filter((x) => Date.parse(x.created_at) >= params.start_time);
|
|
54
|
+
};
|
|
55
|
+
provideInterestLedgerService(terminal, {
|
|
56
|
+
direction: 'backward',
|
|
57
|
+
type: 'HTX',
|
|
58
|
+
}, fetchInterestRateLedgerBackward);
|
|
59
|
+
provideInterestLedgerService(terminal, {
|
|
60
|
+
direction: 'forward',
|
|
61
|
+
type: 'HTX',
|
|
62
|
+
}, fetchInterestRateLedgerForward);
|
|
63
|
+
//# sourceMappingURL=interest-ledger-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest-ledger-service.js","sourceRoot":"","sources":["../../src/services/interest-ledger-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AAOpE,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,OAAQ,CAAC;AAEpC,MAAM,+BAA+B,GAAG,KAAK,EAAE,GAK9C,EAA8B,EAAE;;IAC/B,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,GAAG,CAAC,IAAI;QAClB,UAAU,EAAE,GAAG,CAAC,IAAI,GAAG,SAAS;QAChC,IAAI,EAAE,GAAG,CAAC,WAAW;QACrB,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,MAAM;KACjB,CAAC;IACF,MAAM,GAAG,GAAG,MAAM,8BAA8B,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjF,OAAO,CAAC,MAAA,GAAG,CAAC,IAAI,mCAAI,EAAE,CAAC;SACpB,GAAG,CAAC,CAAC,CAAC,EAAmB,EAAE;QAC1B,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;QAChB,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE;YACnB,UAAU,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,aAAa,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M,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAW,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,4BAA4B,CAC1B,QAAQ,EACR;IACE,SAAS,EAAE,UAAU;IACrB,IAAI,EAAE,KAAK;CACZ,EACD,+BAA+B,CAChC,CAAC;AAEF,4BAA4B,CAC1B,QAAQ,EACR;IACE,SAAS,EAAE,SAAS;IACpB,IAAI,EAAE,KAAK;CACZ,EACD,8BAA8B,CAC/B,CAAC","sourcesContent":["import { IInterestLedger } from '@yuants/data-interest-rate';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { provideInterestLedgerService } from '@yuants/exchange';\nimport { getAccountFinancialRecordExact } from '../api/private-api';\n\ninterface IExchangeCredential {\n type: string;\n payload: any;\n}\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst WINDOW_MS = 2 * 24 * 3600_000;\n\nconst fetchInterestRateLedgerBackward = async (req: {\n credential: IExchangeCredential;\n account_id: string;\n time: number;\n ledger_type: string;\n}): Promise<IInterestLedger[]> => {\n const params = {\n end_time: req.time,\n start_time: req.time - WINDOW_MS,\n type: req.ledger_type,\n direct: 'prev',\n mar_acct: 'USDT',\n };\n const res = await getAccountFinancialRecordExact(req.credential.payload, params);\n return (res.data ?? [])\n .map((v): IInterestLedger => {\n const ms = v.ts;\n return {\n id: v.id.toString(),\n product_id: encodePath('HTX', 'SWAP', v.contract_code),\n amount: v.amount.toString(),\n account_id: req.account_id,\n currency: v.asset,\n created_at: formatTime(ms),\n } as IInterestLedger;\n })\n .filter((x) => Date.parse(x.created_at!) <= req.time);\n};\n\nconst fetchInterestRateLedgerForward = async (req: {\n credential: IExchangeCredential;\n account_id: string;\n time: number;\n ledger_type: string;\n}): Promise<IInterestLedger[]> => {\n const params = {\n end_time: req.time,\n start_time: req.time - WINDOW_MS,\n type: req.ledger_type,\n direct: 'next',\n mar_acct: 'USDT',\n };\n const res = await getAccountFinancialRecordExact(req.credential.payload, params);\n\n return (res.data ?? [])\n .map((v): IInterestLedger => {\n const ms = v.ts;\n return {\n id: v.id.toString(),\n product_id: encodePath('HTX', 'SWAP', v.contract_code),\n amount: v.amount.toString(),\n account_id: req.account_id,\n currency: v.asset,\n created_at: formatTime(ms),\n } as IInterestLedger;\n })\n .filter((x) => Date.parse(x.created_at!) >= params.start_time);\n};\n\nprovideInterestLedgerService(\n terminal,\n {\n direction: 'backward',\n type: 'HTX',\n },\n fetchInterestRateLedgerBackward,\n);\n\nprovideInterestLedgerService(\n terminal,\n {\n direction: 'forward',\n type: 'HTX',\n },\n fetchInterestRateLedgerForward,\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interest-rate-service.js","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAEjE,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,SAAS,GAAG,EAAE,CAAC;AAIrB,MAAM,kBAAkB,GAAG,CAAC,KAAsC,EAA0B,EAAE;IAC5F,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,KAAK,GAAG,QAAQ,CAAC;IACrB,IAAI,KAAK,GAAG,CAAC,QAAQ,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;
|
|
1
|
+
{"version":3,"file":"interest-rate-service.js","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0B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AwB,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC;IAClF,MAAM,IAAI,GAAG,MAAM,oBAAoB,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,CAAC;IAEtE,OAAO,IAAI,CAAC,KAAK;SACd,GAAG,CAAC,CAAC,CAAC,EAAiB,EAAE;QACxB,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QACpC,OAAO;YACL,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC;YAC1B,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE;YACrB,UAAU,EAAE,GAAG,IAAI,EAAE;YACrB,gBAAgB,EAAE,EAAE;SACrB,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF,0BAA0B,CACxB,QAAQ,EACR;IACE,iBAAiB,EAAE,WAAW;IAC9B,SAAS,EAAE,UAAU;CACtB,EACD,wBAAwB,CACzB,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { provideInterestRateService } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { getSwapHistoricalFundingRate } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst PAGE_SIZE = 50;\n\ntype IPageRange = { minMs: number; maxMs: number };\n\nconst computePageRangeMs = (items: Array<{ funding_time: string }>): IPageRange | undefined => {\n if (items.length === 0) return undefined;\n let minMs = Infinity;\n let maxMs = -Infinity;\n for (const item of items) {\n const ms = Number(item.funding_time);\n if (isNaN(ms)) continue;\n if (ms < minMs) minMs = ms;\n if (ms > maxMs) maxMs = ms;\n }\n if (!isFinite(minMs) || !isFinite(maxMs)) return undefined;\n return { minMs, maxMs };\n};\n\nconst fetchFundingRatePage = async (params: {\n contract_code: string;\n pageIndex: number;\n}): Promise<{\n items: Array<{ funding_rate: string; funding_time: string }>;\n totalPage: number;\n}> => {\n const res = await getSwapHistoricalFundingRate({\n contract_code: params.contract_code,\n page_index: params.pageIndex,\n page_size: PAGE_SIZE,\n });\n if (res.status !== 'ok') {\n throw new Error(`HTX getSwapHistoricalFundingRate failed: ${res.status}`);\n }\n return {\n items: res.data.data ?? [],\n totalPage: res.data.total_page,\n };\n};\n\nconst locatePageByTimeBackward = async (params: {\n contract_code: string;\n targetMs: number;\n}): Promise<{ pageIndex: number; totalPage: number }> => {\n const first = await fetchFundingRatePage({ contract_code: params.contract_code, pageIndex: 0 });\n const totalPage = first.totalPage;\n if (!totalPage || totalPage <= 1) return { pageIndex: 0, totalPage: totalPage || 1 };\n\n const rangeCache = new Map<number, IPageRange | undefined>([[0, computePageRangeMs(first.items)]]);\n\n const getRange = async (pageIndex: number): Promise<IPageRange | undefined> => {\n if (rangeCache.has(pageIndex)) return rangeCache.get(pageIndex);\n const page = await fetchFundingRatePage({ contract_code: params.contract_code, pageIndex });\n const range = computePageRangeMs(page.items);\n rangeCache.set(pageIndex, range);\n return range;\n };\n\n let left = 0;\n let right = totalPage - 1;\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n const range = await getRange(mid);\n if (!range) {\n right = mid - 1;\n continue;\n }\n if (params.targetMs > range.maxMs) {\n right = mid - 1;\n continue;\n }\n if (params.targetMs < range.minMs) {\n left = mid + 1;\n continue;\n }\n return { pageIndex: mid, totalPage };\n }\n\n return { pageIndex: Math.min(Math.max(0, left), totalPage - 1), totalPage };\n};\n\nconst fetchFundingRateBackward = async (req: {\n product_id: string;\n time: number;\n series_id: string;\n}): Promise<IInterestRate[]> => {\n const [, instType, contract_code] = decodePath(req.product_id);\n if (instType !== 'SWAP' || !contract_code) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const targetMs = req.time;\n const { pageIndex } = await locatePageByTimeBackward({ contract_code, targetMs });\n const page = await fetchFundingRatePage({ contract_code, pageIndex });\n\n return page.items\n .map((v): IInterestRate => {\n const ms = Number(v.funding_time);\n const rate = Number(v.funding_rate);\n return {\n series_id: req.series_id,\n product_id: req.product_id,\n datasource_id: 'HTX',\n created_at: formatTime(ms),\n long_rate: `${-rate}`,\n short_rate: `${rate}`,\n settlement_price: '',\n };\n })\n .filter((x) => Date.parse(x.created_at) < targetMs);\n};\n\nprovideInterestRateService(\n terminal,\n {\n product_id_prefix: 'HTX/SWAP/',\n direction: 'backward',\n },\n fetchFundingRateBackward,\n);\n"]}
|