@yuants/vendor-huobi 0.17.6 → 0.18.1
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/public-api.js +18 -0
- package/dist/api/public-api.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/services/interest-rate-service.js +110 -0
- package/dist/services/interest-rate-service.js.map +1 -0
- package/dist/services/ohlc-service.js +119 -0
- package/dist/services/ohlc-service.js.map +1 -0
- package/lib/api/public-api.d.ts +54 -0
- package/lib/api/public-api.d.ts.map +1 -1
- package/lib/api/public-api.js +21 -1
- package/lib/api/public-api.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/services/interest-rate-service.d.ts +2 -0
- package/lib/services/interest-rate-service.d.ts.map +1 -0
- package/lib/services/interest-rate-service.js +112 -0
- package/lib/services/interest-rate-service.js.map +1 -0
- package/lib/services/ohlc-service.d.ts +2 -0
- package/lib/services/ohlc-service.d.ts.map +1 -0
- package/lib/services/ohlc-service.js +121 -0
- package/lib/services/ohlc-service.js.map +1 -0
- package/package.json +15 -14
- package/temp/package-deps.json +22 -19
package/dist/api/public-api.js
CHANGED
|
@@ -54,6 +54,16 @@ export function getSpotSymbols() {
|
|
|
54
54
|
export function getSpotTick(params) {
|
|
55
55
|
return publicRequest('GET', `/market/detail/merged`, SPOT_API_ROOT, params);
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* 【现货】获取K线数据
|
|
59
|
+
*
|
|
60
|
+
* https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3ff18-7773-11ed-9966-0242ac110003
|
|
61
|
+
*
|
|
62
|
+
* Note: HTX spot KLine uses unix seconds in `data[].id`
|
|
63
|
+
*/
|
|
64
|
+
export function getSpotHistoryKline(params) {
|
|
65
|
+
return publicRequest('GET', `/market/history/kline`, SPOT_API_ROOT, params);
|
|
66
|
+
}
|
|
57
67
|
/**
|
|
58
68
|
* 【通用】批量获取合约资金费率
|
|
59
69
|
*
|
|
@@ -126,6 +136,14 @@ export function getSwapMarketBbo(params) {
|
|
|
126
136
|
export function getSwapHistoricalFundingRate(params) {
|
|
127
137
|
return publicRequest('GET', `/linear-swap-api/v1/swap_historical_funding_rate`, SWAP_API_ROOT, params);
|
|
128
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* 【通用】获取K线数据
|
|
141
|
+
*
|
|
142
|
+
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73746-77b5-11ed-9966-0242ac110003
|
|
143
|
+
*/
|
|
144
|
+
export function getSwapHistoryKline(params) {
|
|
145
|
+
return publicRequest('GET', `/linear-swap-ex/market/history/kline`, SWAP_API_ROOT, params);
|
|
146
|
+
}
|
|
129
147
|
/**
|
|
130
148
|
* 【全仓】获取平台阶梯保证金
|
|
131
149
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,gBAAgB;AAChB,MAAM,aAAa,GAAG,cAAc,CAAC;AACrC,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC;;GAEG;AACH,KAAK,UAAU,aAAa,CAAC,MAAc,EAAE,IAAY,EAAE,QAAgB,EAAE,MAAY;IACvF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAC;IAElD,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE;YACjD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SACvC;KACF;IAED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GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAiBjC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import { formatTime } from '@yuants/utils';\n\n// Huobi API 根域名\nconst SWAP_API_ROOT = 'api.hbdm.com';\nconst SPOT_API_ROOT = 'api.huobi.pro';\n\n/**\n * 公共 API 请求方法\n */\nasync function publicRequest(method: string, path: string, api_root: string, params?: any) {\n const url = new URL(`https://${api_root}${path}`);\n\n if (method === 'GET') {\n for (const [k, v] of Object.entries(params || {})) {\n url.searchParams.append(k, String(v));\n }\n }\n\n const body = method === 'GET' ? '' : JSON.stringify(params);\n\n console.info(formatTime(Date.now()), method, url.href, body);\n\n const res = await fetch(url.href, {\n method,\n headers: { 'Content-Type': 'application/json' },\n body: body || undefined,\n });\n\n console.info(formatTime(Date.now()), 'PublicResponse', url.toString(), res.status);\n\n const retStr = await res.text();\n try {\n return JSON.parse(retStr);\n } catch (e) {\n console.error(formatTime(Date.now()), 'huobiRequestFailed', path, JSON.stringify(params), retStr);\n throw e;\n }\n}\n\n// ==================== 公共 API 方法 ====================\n\n/**\n * 获取永续合约产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72f34-77b5-11ed-9966-0242ac110003\n */\nexport function getPerpetualContractSymbols(params?: {\n contract_code?: string;\n support_margin_mode?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n symbol: string;\n contract_code: string;\n contract_size: number;\n price_tick: number;\n settlement_date: string;\n delivery_time: string;\n create_date: string;\n contract_status: number;\n support_margin_mode: string;\n contract_type: string;\n pair: string;\n business_type: string;\n delivery_date: string;\n }[];\n ts: string;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_contract_info', SWAP_API_ROOT, params);\n}\n\n/**\n * 获取现货产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec47f16-7773-11ed-9966-0242ac110003\n */\nexport function getSpotSymbols(): Promise<{\n status: string;\n data: {\n si: string;\n scr: string;\n sc: string;\n dn: string;\n bc: string;\n bcdn: string;\n qc: string;\n qcdn: string;\n state: string;\n whe: boolean;\n cd: boolean;\n te: boolean;\n toa: number;\n sp: string;\n w: number;\n ttp: number;\n tap: number;\n tpp: number;\n fp: number;\n suspend_desc: string;\n transfer_board_desc: string;\n tags: string;\n lr: number;\n smlr: number;\n flr: string;\n wr: string;\n d: number;\n elr: number;\n p: any;\n castate: string;\n ca1oa: number;\n ca2oa: number;\n }[];\n ts: string;\n full: number;\n err_code: string;\n err_msg: string;\n}> {\n return publicRequest('GET', '/v2/settings/common/symbols', SPOT_API_ROOT);\n}\n\n/**\n * 获取现货行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3fc25-7773-11ed-9966-0242ac110003\n */\nexport function getSpotTick(params: { symbol: string }): Promise<{\n status: string;\n tick: {\n close: number;\n };\n}> {\n return publicRequest('GET', `/market/detail/merged`, SPOT_API_ROOT, params);\n}\n\n/**\n * 【通用】批量获取合约资金费率\n *\n * 接口权限: 读取\n *\n * 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多240次请求(所有该IP的非行情类的公开接口请求共享3秒240次的额度)\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb71b45-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapBatchFundingRate(params: { contract_code?: string }): Promise<{\n status: string;\n ts: number;\n data: {\n estimated_rate: null;\n funding_rate: string;\n contract_code: string;\n symbol: string;\n fee_asset: string;\n funding_time: string;\n next_funding_time: null;\n trade_partition: string;\n }[];\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_batch_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最近成交记录\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73c34-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketTrade(params: { contract_code?: string; business_type?: string }): Promise<{\n ch: string;\n status: string;\n tick: {\n data: {\n amount: string;\n quantity: string;\n trade_turnover: string;\n ts: number;\n id: number;\n price: string;\n direction: string;\n contract_code: string;\n business_type: string;\n trade_partition: string;\n }[];\n id: number;\n ts: number;\n };\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/trade`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获得当前合约的总持仓量\n *\n * https://huobiapi.github.io/docs/usdt_swap/v1/cn/#3218e7531a\n */\nexport function getSwapOpenInterest(params: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n volume: number;\n amount: number;\n symbol: string;\n value: number;\n contract_code: string;\n trade_amount: number;\n trade_volume: number;\n trade_turnover: number;\n business_type: string;\n pair: string;\n contract_type: string;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_open_interest', SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最优挂单\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb735e0-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketBbo(params: { contract_code?: string }): Promise<{\n status: string;\n ticks: {\n trade_partition: string;\n business_type: string;\n contract_code: string;\n ask: number[] | null;\n bid: number[] | null;\n mrid: number;\n ts: number;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/bbo`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获取合约的历史资金费率\n *\n * 接口权限: 读取\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=5d51f1f9-77b6-11ed-9966-0242ac110003\n */\nexport function getSwapHistoricalFundingRate(params: {\n contract_code: string;\n page_index?: number;\n page_size?: number;\n}): Promise<{\n status: string;\n ts: number;\n data: {\n data: {\n symbol: string;\n contract_code: string;\n fee_asset: string;\n funding_time: string;\n funding_rate: string;\n realized_rate: string;\n avg_premium_index: string;\n }[];\n total_page: number;\n current_page: number;\n total_size: number;\n };\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_historical_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【全仓】获取平台阶梯保证金\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72290-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapCrossLadderMargin(params?: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: Array<{ contract_code: string; pair: string; list: Array<{ lever_rate: number }> }>;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_cross_ladder_margin', SWAP_API_ROOT, params);\n}\n\n/**\n * APIv2币链参考信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec478f0-7773-11ed-9966-0242ac110003\n */\nexport function getV2ReferenceCurrencies(params: { currency?: string; authorizedUser?: string }): Promise<{\n code: number;\n data: {\n currency: string;\n assetType: number;\n chains: {\n chain: string;\n displayName: string;\n fullName: string;\n baseChain?: string;\n baseChainProtocol?: string;\n isDynamic?: boolean;\n numOfConfirmations: number;\n numOfFastConfirmations: number;\n depositStatus: string;\n minDepositAmt: string;\n withdrawStatus: string;\n minWithdrawAmt: string;\n withdrawPrecision: number;\n maxWithdrawAmt: string;\n withdrawQuotaPerDay: string;\n withdrawQuotaPerYear: null;\n withdrawQuotaTotal: null;\n withdrawFeeType: string;\n transactFeeWithdraw?: string;\n addrWithTag: boolean;\n addrDepositTag: boolean;\n minTransactFeeWithdraw?: string;\n transactFeeRateWithdraw?: string;\n maxTransactFeeWithdraw?: string;\n }[];\n instStatus: string;\n }[];\n}> {\n return publicRequest('GET', '/v2/reference/currencies', SPOT_API_ROOT, params);\n}\n\n/**\n * 【现货】获取市场所有交易对的最新行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40374-7773-11ed-9966-0242ac110003\n *\n */\nexport const getSpotMarketTickers = (): Promise<{\n data: {\n symbol: string;\n open: number;\n high: number;\n low: number;\n close: number;\n amount: number;\n vol: number;\n count: number;\n bid: number;\n bidSize: number;\n ask: number;\n askSize: number;\n }[];\n status: string;\n ts: number;\n}> => publicRequest('GET', '/market/tickers', SPOT_API_ROOT);\n"]}
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,gBAAgB;AAChB,MAAM,aAAa,GAAG,cAAc,CAAC;AACrC,M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;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAkC;IAajE,OAAO,aAAa,CAAC,KAAK,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AACnF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B,CAAC,MAI5C;IAkBC,OAAO,aAAa,CAAC,KAAK,EAAE,kDAAkD,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AACzG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAMnC;IAeC,OAAO,aAAa,CAAC,KAAK,EAAE,sCAAsC,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AAC7F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAKxC;IAIC,OAAO,aAAa,CAAC,KAAK,EAAE,8CAA8C,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AACrG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAsD;IAkC7F,OAAO,aAAa,CAAC,KAAK,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAiBjC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import { formatTime } from '@yuants/utils';\n\n// Huobi API 根域名\nconst SWAP_API_ROOT = 'api.hbdm.com';\nconst SPOT_API_ROOT = 'api.huobi.pro';\n\n/**\n * 公共 API 请求方法\n */\nasync function publicRequest(method: string, path: string, api_root: string, params?: any) {\n const url = new URL(`https://${api_root}${path}`);\n\n if (method === 'GET') {\n for (const [k, v] of Object.entries(params || {})) {\n url.searchParams.append(k, String(v));\n }\n }\n\n const body = method === 'GET' ? '' : JSON.stringify(params);\n\n console.info(formatTime(Date.now()), method, url.href, body);\n\n const res = await fetch(url.href, {\n method,\n headers: { 'Content-Type': 'application/json' },\n body: body || undefined,\n });\n\n console.info(formatTime(Date.now()), 'PublicResponse', url.toString(), res.status);\n\n const retStr = await res.text();\n try {\n return JSON.parse(retStr);\n } catch (e) {\n console.error(formatTime(Date.now()), 'huobiRequestFailed', path, JSON.stringify(params), retStr);\n throw e;\n }\n}\n\n// ==================== 公共 API 方法 ====================\n\n/**\n * 获取永续合约产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72f34-77b5-11ed-9966-0242ac110003\n */\nexport function getPerpetualContractSymbols(params?: {\n contract_code?: string;\n support_margin_mode?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n symbol: string;\n contract_code: string;\n contract_size: number;\n price_tick: number;\n settlement_date: string;\n delivery_time: string;\n create_date: string;\n contract_status: number;\n support_margin_mode: string;\n contract_type: string;\n pair: string;\n business_type: string;\n delivery_date: string;\n }[];\n ts: string;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_contract_info', SWAP_API_ROOT, params);\n}\n\n/**\n * 获取现货产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec47f16-7773-11ed-9966-0242ac110003\n */\nexport function getSpotSymbols(): Promise<{\n status: string;\n data: {\n si: string;\n scr: string;\n sc: string;\n dn: string;\n bc: string;\n bcdn: string;\n qc: string;\n qcdn: string;\n state: string;\n whe: boolean;\n cd: boolean;\n te: boolean;\n toa: number;\n sp: string;\n w: number;\n ttp: number;\n tap: number;\n tpp: number;\n fp: number;\n suspend_desc: string;\n transfer_board_desc: string;\n tags: string;\n lr: number;\n smlr: number;\n flr: string;\n wr: string;\n d: number;\n elr: number;\n p: any;\n castate: string;\n ca1oa: number;\n ca2oa: number;\n }[];\n ts: string;\n full: number;\n err_code: string;\n err_msg: string;\n}> {\n return publicRequest('GET', '/v2/settings/common/symbols', SPOT_API_ROOT);\n}\n\n/**\n * 获取现货行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3fc25-7773-11ed-9966-0242ac110003\n */\nexport function getSpotTick(params: { symbol: string }): Promise<{\n status: string;\n tick: {\n close: number;\n };\n}> {\n return publicRequest('GET', `/market/detail/merged`, SPOT_API_ROOT, params);\n}\n\n/**\n * 【现货】获取K线数据\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3ff18-7773-11ed-9966-0242ac110003\n *\n * Note: HTX spot KLine uses unix seconds in `data[].id`\n */\nexport function getSpotHistoryKline(params: {\n symbol: string;\n period: string;\n size?: number;\n from?: number;\n to?: number;\n}): Promise<{\n status: string;\n ch?: string;\n ts: number;\n data: {\n id: number;\n open: number;\n close: number;\n low: number;\n high: number;\n vol: number;\n amount?: number;\n count?: number;\n }[];\n}> {\n return publicRequest('GET', `/market/history/kline`, SPOT_API_ROOT, params);\n}\n\n/**\n * 【通用】批量获取合约资金费率\n *\n * 接口权限: 读取\n *\n * 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多240次请求(所有该IP的非行情类的公开接口请求共享3秒240次的额度)\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb71b45-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapBatchFundingRate(params: { contract_code?: string }): Promise<{\n status: string;\n ts: number;\n data: {\n estimated_rate: null;\n funding_rate: string;\n contract_code: string;\n symbol: string;\n fee_asset: string;\n funding_time: string;\n next_funding_time: null;\n trade_partition: string;\n }[];\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_batch_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最近成交记录\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73c34-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketTrade(params: { contract_code?: string; business_type?: string }): Promise<{\n ch: string;\n status: string;\n tick: {\n data: {\n amount: string;\n quantity: string;\n trade_turnover: string;\n ts: number;\n id: number;\n price: string;\n direction: string;\n contract_code: string;\n business_type: string;\n trade_partition: string;\n }[];\n id: number;\n ts: number;\n };\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/trade`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获得当前合约的总持仓量\n *\n * https://huobiapi.github.io/docs/usdt_swap/v1/cn/#3218e7531a\n */\nexport function getSwapOpenInterest(params: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n volume: number;\n amount: number;\n symbol: string;\n value: number;\n contract_code: string;\n trade_amount: number;\n trade_volume: number;\n trade_turnover: number;\n business_type: string;\n pair: string;\n contract_type: string;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_open_interest', SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最优挂单\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb735e0-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketBbo(params: { contract_code?: string }): Promise<{\n status: string;\n ticks: {\n trade_partition: string;\n business_type: string;\n contract_code: string;\n ask: number[] | null;\n bid: number[] | null;\n mrid: number;\n ts: number;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/bbo`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获取合约的历史资金费率\n *\n * 接口权限: 读取\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=5d51f1f9-77b6-11ed-9966-0242ac110003\n */\nexport function getSwapHistoricalFundingRate(params: {\n contract_code: string;\n page_index?: number;\n page_size?: number;\n}): Promise<{\n status: string;\n ts: number;\n data: {\n data: {\n symbol: string;\n contract_code: string;\n fee_asset: string;\n funding_time: string;\n funding_rate: string;\n realized_rate: string;\n avg_premium_index: string;\n }[];\n total_page: number;\n current_page: number;\n total_size: number;\n };\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_historical_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取K线数据\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73746-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapHistoryKline(params: {\n contract_code: string;\n period: string;\n size?: number;\n from?: number;\n to?: number;\n}): Promise<{\n status: string;\n ch?: string;\n ts: number;\n data: {\n id: number;\n open: number;\n close: number;\n low: number;\n high: number;\n vol: number;\n amount?: number;\n count?: number;\n }[];\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/history/kline`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【全仓】获取平台阶梯保证金\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72290-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapCrossLadderMargin(params?: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: Array<{ contract_code: string; pair: string; list: Array<{ lever_rate: number }> }>;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_cross_ladder_margin', SWAP_API_ROOT, params);\n}\n\n/**\n * APIv2币链参考信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec478f0-7773-11ed-9966-0242ac110003\n */\nexport function getV2ReferenceCurrencies(params: { currency?: string; authorizedUser?: string }): Promise<{\n code: number;\n data: {\n currency: string;\n assetType: number;\n chains: {\n chain: string;\n displayName: string;\n fullName: string;\n baseChain?: string;\n baseChainProtocol?: string;\n isDynamic?: boolean;\n numOfConfirmations: number;\n numOfFastConfirmations: number;\n depositStatus: string;\n minDepositAmt: string;\n withdrawStatus: string;\n minWithdrawAmt: string;\n withdrawPrecision: number;\n maxWithdrawAmt: string;\n withdrawQuotaPerDay: string;\n withdrawQuotaPerYear: null;\n withdrawQuotaTotal: null;\n withdrawFeeType: string;\n transactFeeWithdraw?: string;\n addrWithTag: boolean;\n addrDepositTag: boolean;\n minTransactFeeWithdraw?: string;\n transactFeeRateWithdraw?: string;\n maxTransactFeeWithdraw?: string;\n }[];\n instStatus: string;\n }[];\n}> {\n return publicRequest('GET', '/v2/reference/currencies', SPOT_API_ROOT, params);\n}\n\n/**\n * 【现货】获取市场所有交易对的最新行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40374-7773-11ed-9966-0242ac110003\n *\n */\nexport const getSpotMarketTickers = (): Promise<{\n data: {\n symbol: string;\n open: number;\n high: number;\n low: number;\n close: number;\n amount: number;\n vol: number;\n count: number;\n bid: number;\n bidSize: number;\n ask: number;\n askSize: number;\n }[];\n status: string;\n ts: number;\n}> => publicRequest('GET', '/market/tickers', SPOT_API_ROOT);\n"]}
|
package/dist/index.js
CHANGED
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,sCAAsC,CAAC;AAC9C,OAAO,8BAA8B,CAAC;AACtC,OAAO,mBAAmB,CAAC","sourcesContent":["import './services/exchange';\nimport './services/market-data/interest_rate';\nimport './services/market-data/quote';\nimport './services/quotes';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,sCAAsC,CAAC;AAC9C,OAAO,8BAA8B,CAAC;AACtC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,yBAAyB,CAAC;AACjC,OAAO,kCAAkC,CAAC","sourcesContent":["import './services/exchange';\nimport './services/market-data/interest_rate';\nimport './services/market-data/quote';\nimport './services/quotes';\nimport './services/ohlc-service';\nimport './services/interest-rate-service';\n"]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { provideInterestRateService } from '@yuants/exchange';
|
|
2
|
+
import { Terminal } from '@yuants/protocol';
|
|
3
|
+
import { decodePath, formatTime } from '@yuants/utils';
|
|
4
|
+
import { getSwapHistoricalFundingRate } from '../api/public-api';
|
|
5
|
+
const terminal = Terminal.fromNodeEnv();
|
|
6
|
+
const INGEST_SERVICE_OPTIONS = {
|
|
7
|
+
concurrent: 1,
|
|
8
|
+
max_pending_requests: 20,
|
|
9
|
+
ingress_token_capacity: 2,
|
|
10
|
+
ingress_token_refill_interval: 1000,
|
|
11
|
+
egress_token_capacity: 1,
|
|
12
|
+
egress_token_refill_interval: 1000,
|
|
13
|
+
};
|
|
14
|
+
const PAGE_SIZE = 50;
|
|
15
|
+
const computePageRangeMs = (items) => {
|
|
16
|
+
if (items.length === 0)
|
|
17
|
+
return undefined;
|
|
18
|
+
let minMs = Infinity;
|
|
19
|
+
let maxMs = -Infinity;
|
|
20
|
+
for (const item of items) {
|
|
21
|
+
const ms = Number(item.funding_time);
|
|
22
|
+
if (isNaN(ms))
|
|
23
|
+
continue;
|
|
24
|
+
if (ms < minMs)
|
|
25
|
+
minMs = ms;
|
|
26
|
+
if (ms > maxMs)
|
|
27
|
+
maxMs = ms;
|
|
28
|
+
}
|
|
29
|
+
if (!isFinite(minMs) || !isFinite(maxMs))
|
|
30
|
+
return undefined;
|
|
31
|
+
return { minMs, maxMs };
|
|
32
|
+
};
|
|
33
|
+
const fetchFundingRatePage = async (params) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const res = await getSwapHistoricalFundingRate({
|
|
36
|
+
contract_code: params.contract_code,
|
|
37
|
+
page_index: params.pageIndex,
|
|
38
|
+
page_size: PAGE_SIZE,
|
|
39
|
+
});
|
|
40
|
+
if (res.status !== 'ok') {
|
|
41
|
+
throw new Error(`HTX getSwapHistoricalFundingRate failed: ${res.status}`);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
items: (_a = res.data.data) !== null && _a !== void 0 ? _a : [],
|
|
45
|
+
totalPage: res.data.total_page,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const locatePageByTimeBackward = async (params) => {
|
|
49
|
+
const first = await fetchFundingRatePage({ contract_code: params.contract_code, pageIndex: 0 });
|
|
50
|
+
const totalPage = first.totalPage;
|
|
51
|
+
if (!totalPage || totalPage <= 1)
|
|
52
|
+
return { pageIndex: 0, totalPage: totalPage || 1 };
|
|
53
|
+
const rangeCache = new Map([[0, computePageRangeMs(first.items)]]);
|
|
54
|
+
const getRange = async (pageIndex) => {
|
|
55
|
+
if (rangeCache.has(pageIndex))
|
|
56
|
+
return rangeCache.get(pageIndex);
|
|
57
|
+
const page = await fetchFundingRatePage({ contract_code: params.contract_code, pageIndex });
|
|
58
|
+
const range = computePageRangeMs(page.items);
|
|
59
|
+
rangeCache.set(pageIndex, range);
|
|
60
|
+
return range;
|
|
61
|
+
};
|
|
62
|
+
let left = 0;
|
|
63
|
+
let right = totalPage - 1;
|
|
64
|
+
while (left <= right) {
|
|
65
|
+
const mid = Math.floor((left + right) / 2);
|
|
66
|
+
const range = await getRange(mid);
|
|
67
|
+
if (!range) {
|
|
68
|
+
right = mid - 1;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (params.targetMs > range.maxMs) {
|
|
72
|
+
right = mid - 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (params.targetMs < range.minMs) {
|
|
76
|
+
left = mid + 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
return { pageIndex: mid, totalPage };
|
|
80
|
+
}
|
|
81
|
+
return { pageIndex: Math.min(Math.max(0, left), totalPage - 1), totalPage };
|
|
82
|
+
};
|
|
83
|
+
const fetchFundingRateBackward = async (req) => {
|
|
84
|
+
const [, instType, contract_code] = decodePath(req.product_id);
|
|
85
|
+
if (instType !== 'SWAP' || !contract_code)
|
|
86
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
87
|
+
const targetMs = req.time;
|
|
88
|
+
const { pageIndex } = await locatePageByTimeBackward({ contract_code, targetMs });
|
|
89
|
+
const page = await fetchFundingRatePage({ contract_code, pageIndex });
|
|
90
|
+
return page.items
|
|
91
|
+
.map((v) => {
|
|
92
|
+
const ms = Number(v.funding_time);
|
|
93
|
+
const rate = Number(v.funding_rate);
|
|
94
|
+
return {
|
|
95
|
+
series_id: req.series_id,
|
|
96
|
+
product_id: req.product_id,
|
|
97
|
+
datasource_id: 'HTX',
|
|
98
|
+
created_at: formatTime(ms),
|
|
99
|
+
long_rate: `${-rate}`,
|
|
100
|
+
short_rate: `${rate}`,
|
|
101
|
+
settlement_price: '',
|
|
102
|
+
};
|
|
103
|
+
})
|
|
104
|
+
.filter((x) => Date.parse(x.created_at) < targetMs);
|
|
105
|
+
};
|
|
106
|
+
provideInterestRateService(terminal, {
|
|
107
|
+
product_id_prefix: 'HTX/SWAP/',
|
|
108
|
+
direction: 'backward',
|
|
109
|
+
}, fetchFundingRateBackward, INGEST_SERVICE_OPTIONS);
|
|
110
|
+
//# sourceMappingURL=interest-rate-service.js.map
|
|
@@ -0,0 +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,EAAmB,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC7D,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,sBAAsB,GAAoB;IAC9C,UAAU,EAAE,CAAC;IACb,oBAAoB,EAAE,EAAE;IACxB,sBAAsB,EAAE,CAAC;IACzB,6BAA6B,EAAE,IAAI;IACnC,qBAAqB,EAAE,CAAC;IACxB,4BAA4B,EAAE,IAAI;CACnC,CAAC;AAEF,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;QACxB,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,IAAI,KAAK,CAAC,EAAE,CAAC;YAAE,SAAS;QACxB,IAAI,EAAE,GAAG,KAAK;YAAE,KAAK,GAAG,EAAE,CAAC;QAC3B,IAAI,EAAE,GAAG,KAAK;YAAE,KAA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AW;IAC9B,SAAS,EAAE,UAAU;CACtB,EACD,wBAAwB,EACxB,sBAAsB,CACvB,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { provideInterestRateService } from '@yuants/exchange';\nimport { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { getSwapHistoricalFundingRate } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst INGEST_SERVICE_OPTIONS: IServiceOptions = {\n concurrent: 1,\n max_pending_requests: 20,\n ingress_token_capacity: 2,\n ingress_token_refill_interval: 1000,\n egress_token_capacity: 1,\n egress_token_refill_interval: 1000,\n};\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 INGEST_SERVICE_OPTIONS,\n);\n"]}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { provideOHLCService } from '@yuants/exchange';
|
|
2
|
+
import { Terminal } from '@yuants/protocol';
|
|
3
|
+
import { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';
|
|
4
|
+
import { getSpotHistoryKline, getSwapHistoryKline } from '../api/public-api';
|
|
5
|
+
const terminal = Terminal.fromNodeEnv();
|
|
6
|
+
const INGEST_SERVICE_OPTIONS = {
|
|
7
|
+
concurrent: 1,
|
|
8
|
+
max_pending_requests: 20,
|
|
9
|
+
ingress_token_capacity: 2,
|
|
10
|
+
ingress_token_refill_interval: 1000,
|
|
11
|
+
egress_token_capacity: 1,
|
|
12
|
+
egress_token_refill_interval: 1000,
|
|
13
|
+
};
|
|
14
|
+
const DURATION_TO_HTX_PERIOD = {
|
|
15
|
+
PT1M: '1min',
|
|
16
|
+
PT5M: '5min',
|
|
17
|
+
PT15M: '15min',
|
|
18
|
+
PT30M: '30min',
|
|
19
|
+
PT1H: '60min',
|
|
20
|
+
PT4H: '4hour',
|
|
21
|
+
P1D: '1day',
|
|
22
|
+
P1W: '1week',
|
|
23
|
+
};
|
|
24
|
+
const DEFAULT_BAR_COUNT = 500;
|
|
25
|
+
const fetchSpotOHLCPageBackward = async (req) => {
|
|
26
|
+
var _a;
|
|
27
|
+
const [, instType, symbol] = decodePath(req.product_id);
|
|
28
|
+
if (instType !== 'SPOT' || !symbol)
|
|
29
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
30
|
+
const period = DURATION_TO_HTX_PERIOD[req.duration];
|
|
31
|
+
if (!period)
|
|
32
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
33
|
+
const offset = convertDurationToOffset(req.duration);
|
|
34
|
+
const endedAtMs = req.time;
|
|
35
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
36
|
+
const from = Math.max(0, Math.floor((endedAtMs - DEFAULT_BAR_COUNT * offset) / 1000));
|
|
37
|
+
const res = await getSpotHistoryKline({
|
|
38
|
+
symbol: symbol.toLowerCase(),
|
|
39
|
+
period,
|
|
40
|
+
size: DEFAULT_BAR_COUNT,
|
|
41
|
+
from,
|
|
42
|
+
to,
|
|
43
|
+
});
|
|
44
|
+
if (res.status !== 'ok') {
|
|
45
|
+
throw new Error(`HTX getSpotHistoryKline failed: ${res.status}`);
|
|
46
|
+
}
|
|
47
|
+
return ((_a = res.data) !== null && _a !== void 0 ? _a : [])
|
|
48
|
+
.map((k) => {
|
|
49
|
+
const createdAtMs = k.id * 1000;
|
|
50
|
+
return {
|
|
51
|
+
series_id: req.series_id,
|
|
52
|
+
datasource_id: 'HTX',
|
|
53
|
+
product_id: req.product_id,
|
|
54
|
+
duration: req.duration,
|
|
55
|
+
created_at: formatTime(createdAtMs),
|
|
56
|
+
closed_at: formatTime(createdAtMs + offset),
|
|
57
|
+
open: `${k.open}`,
|
|
58
|
+
high: `${k.high}`,
|
|
59
|
+
low: `${k.low}`,
|
|
60
|
+
close: `${k.close}`,
|
|
61
|
+
volume: `${k.vol}`,
|
|
62
|
+
open_interest: '0',
|
|
63
|
+
};
|
|
64
|
+
})
|
|
65
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
66
|
+
};
|
|
67
|
+
const fetchOHLCPageBackward = async (req) => {
|
|
68
|
+
var _a;
|
|
69
|
+
const [, instType, contract_code] = decodePath(req.product_id);
|
|
70
|
+
if (instType !== 'SWAP' || !contract_code)
|
|
71
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
72
|
+
const period = DURATION_TO_HTX_PERIOD[req.duration];
|
|
73
|
+
if (!period)
|
|
74
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
75
|
+
const offset = convertDurationToOffset(req.duration);
|
|
76
|
+
const endedAtMs = req.time;
|
|
77
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
78
|
+
const from = Math.max(0, Math.floor((endedAtMs - DEFAULT_BAR_COUNT * offset) / 1000));
|
|
79
|
+
const res = await getSwapHistoryKline({
|
|
80
|
+
contract_code,
|
|
81
|
+
period,
|
|
82
|
+
size: DEFAULT_BAR_COUNT,
|
|
83
|
+
from,
|
|
84
|
+
to,
|
|
85
|
+
});
|
|
86
|
+
if (res.status !== 'ok') {
|
|
87
|
+
throw new Error(`HTX getSwapHistoryKline failed: ${res.status}`);
|
|
88
|
+
}
|
|
89
|
+
return ((_a = res.data) !== null && _a !== void 0 ? _a : [])
|
|
90
|
+
.map((k) => {
|
|
91
|
+
const createdAtMs = k.id * 1000;
|
|
92
|
+
return {
|
|
93
|
+
series_id: req.series_id,
|
|
94
|
+
datasource_id: 'HTX',
|
|
95
|
+
product_id: req.product_id,
|
|
96
|
+
duration: req.duration,
|
|
97
|
+
created_at: formatTime(createdAtMs),
|
|
98
|
+
closed_at: formatTime(createdAtMs + offset),
|
|
99
|
+
open: `${k.open}`,
|
|
100
|
+
high: `${k.high}`,
|
|
101
|
+
low: `${k.low}`,
|
|
102
|
+
close: `${k.close}`,
|
|
103
|
+
volume: `${k.vol}`,
|
|
104
|
+
open_interest: '0',
|
|
105
|
+
};
|
|
106
|
+
})
|
|
107
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
108
|
+
};
|
|
109
|
+
provideOHLCService(terminal, {
|
|
110
|
+
product_id_prefix: 'HTX/SWAP/',
|
|
111
|
+
duration_list: Object.keys(DURATION_TO_HTX_PERIOD),
|
|
112
|
+
direction: 'backward',
|
|
113
|
+
}, fetchOHLCPageBackward, INGEST_SERVICE_OPTIONS);
|
|
114
|
+
provideOHLCService(terminal, {
|
|
115
|
+
product_id_prefix: 'HTX/SPOT/',
|
|
116
|
+
duration_list: Object.keys(DURATION_TO_HTX_PERIOD),
|
|
117
|
+
direction: 'backward',
|
|
118
|
+
}, fetchSpotOHLCPageBackward, INGEST_SERVICE_OPTIONS);
|
|
119
|
+
//# sourceMappingURL=ohlc-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ohlc-service.js","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAA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":["import { IOHLC } from '@yuants/data-ohlc';\nimport { provideOHLCService } from '@yuants/exchange';\nimport { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';\nimport { getSpotHistoryKline, getSwapHistoryKline } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst INGEST_SERVICE_OPTIONS: IServiceOptions = {\n concurrent: 1,\n max_pending_requests: 20,\n ingress_token_capacity: 2,\n ingress_token_refill_interval: 1000,\n egress_token_capacity: 1,\n egress_token_refill_interval: 1000,\n};\n\nconst DURATION_TO_HTX_PERIOD: Record<string, string> = {\n PT1M: '1min',\n PT5M: '5min',\n PT15M: '15min',\n PT30M: '30min',\n PT1H: '60min',\n PT4H: '4hour',\n P1D: '1day',\n P1W: '1week',\n};\n\nconst DEFAULT_BAR_COUNT = 500;\n\nconst fetchSpotOHLCPageBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\n const [, instType, symbol] = decodePath(req.product_id);\n if (instType !== 'SPOT' || !symbol) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const period = DURATION_TO_HTX_PERIOD[req.duration];\n if (!period) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n\n const to = Math.floor(endedAtMs / 1000);\n const from = Math.max(0, Math.floor((endedAtMs - DEFAULT_BAR_COUNT * offset) / 1000));\n\n const res = await getSpotHistoryKline({\n symbol: symbol.toLowerCase(),\n period,\n size: DEFAULT_BAR_COUNT,\n from,\n to,\n });\n if (res.status !== 'ok') {\n throw new Error(`HTX getSpotHistoryKline failed: ${res.status}`);\n }\n\n return (res.data ?? [])\n .map((k): IOHLC => {\n const createdAtMs = k.id * 1000;\n return {\n series_id: req.series_id,\n datasource_id: 'HTX',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(createdAtMs),\n closed_at: formatTime(createdAtMs + offset),\n open: `${k.open}`,\n high: `${k.high}`,\n low: `${k.low}`,\n close: `${k.close}`,\n volume: `${k.vol}`,\n open_interest: '0',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nconst fetchOHLCPageBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\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 period = DURATION_TO_HTX_PERIOD[req.duration];\n if (!period) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n\n const to = Math.floor(endedAtMs / 1000);\n const from = Math.max(0, Math.floor((endedAtMs - DEFAULT_BAR_COUNT * offset) / 1000));\n\n const res = await getSwapHistoryKline({\n contract_code,\n period,\n size: DEFAULT_BAR_COUNT,\n from,\n to,\n });\n if (res.status !== 'ok') {\n throw new Error(`HTX getSwapHistoryKline failed: ${res.status}`);\n }\n\n return (res.data ?? [])\n .map((k): IOHLC => {\n const createdAtMs = k.id * 1000;\n return {\n series_id: req.series_id,\n datasource_id: 'HTX',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(createdAtMs),\n closed_at: formatTime(createdAtMs + offset),\n open: `${k.open}`,\n high: `${k.high}`,\n low: `${k.low}`,\n close: `${k.close}`,\n volume: `${k.vol}`,\n open_interest: '0',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'HTX/SWAP/',\n duration_list: Object.keys(DURATION_TO_HTX_PERIOD),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n INGEST_SERVICE_OPTIONS,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'HTX/SPOT/',\n duration_list: Object.keys(DURATION_TO_HTX_PERIOD),\n direction: 'backward',\n },\n fetchSpotOHLCPageBackward,\n INGEST_SERVICE_OPTIONS,\n);\n"]}
|
package/lib/api/public-api.d.ts
CHANGED
|
@@ -87,6 +87,34 @@ export declare function getSpotTick(params: {
|
|
|
87
87
|
close: number;
|
|
88
88
|
};
|
|
89
89
|
}>;
|
|
90
|
+
/**
|
|
91
|
+
* 【现货】获取K线数据
|
|
92
|
+
*
|
|
93
|
+
* https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3ff18-7773-11ed-9966-0242ac110003
|
|
94
|
+
*
|
|
95
|
+
* Note: HTX spot KLine uses unix seconds in `data[].id`
|
|
96
|
+
*/
|
|
97
|
+
export declare function getSpotHistoryKline(params: {
|
|
98
|
+
symbol: string;
|
|
99
|
+
period: string;
|
|
100
|
+
size?: number;
|
|
101
|
+
from?: number;
|
|
102
|
+
to?: number;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
status: string;
|
|
105
|
+
ch?: string;
|
|
106
|
+
ts: number;
|
|
107
|
+
data: {
|
|
108
|
+
id: number;
|
|
109
|
+
open: number;
|
|
110
|
+
close: number;
|
|
111
|
+
low: number;
|
|
112
|
+
high: number;
|
|
113
|
+
vol: number;
|
|
114
|
+
amount?: number;
|
|
115
|
+
count?: number;
|
|
116
|
+
}[];
|
|
117
|
+
}>;
|
|
90
118
|
/**
|
|
91
119
|
* 【通用】批量获取合约资金费率
|
|
92
120
|
*
|
|
@@ -243,6 +271,32 @@ export declare function getSwapHistoricalFundingRate(params: {
|
|
|
243
271
|
total_size: number;
|
|
244
272
|
};
|
|
245
273
|
}>;
|
|
274
|
+
/**
|
|
275
|
+
* 【通用】获取K线数据
|
|
276
|
+
*
|
|
277
|
+
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73746-77b5-11ed-9966-0242ac110003
|
|
278
|
+
*/
|
|
279
|
+
export declare function getSwapHistoryKline(params: {
|
|
280
|
+
contract_code: string;
|
|
281
|
+
period: string;
|
|
282
|
+
size?: number;
|
|
283
|
+
from?: number;
|
|
284
|
+
to?: number;
|
|
285
|
+
}): Promise<{
|
|
286
|
+
status: string;
|
|
287
|
+
ch?: string;
|
|
288
|
+
ts: number;
|
|
289
|
+
data: {
|
|
290
|
+
id: number;
|
|
291
|
+
open: number;
|
|
292
|
+
close: number;
|
|
293
|
+
low: number;
|
|
294
|
+
high: number;
|
|
295
|
+
vol: number;
|
|
296
|
+
amount?: number;
|
|
297
|
+
count?: number;
|
|
298
|
+
}[];
|
|
299
|
+
}>;
|
|
246
300
|
/**
|
|
247
301
|
* 【全仓】获取平台阶梯保证金
|
|
248
302
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAyCA;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,CAAC,EAAE;IACnD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,mBAAmB,EAAE,MAAM,CAAC;QAC5B,aAAa,EAAE,MAAM,CAAC;QACtB,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;KACvB,EAAE,CAAC;IACJ,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC,CAED;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IA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AAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;KACjB,EAAE,CAAC;IACJ,QAAQ,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;CACZ,CAA2D,CAAC"}
|
package/lib/api/public-api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpotMarketTickers = exports.getV2ReferenceCurrencies = exports.getSwapCrossLadderMargin = exports.getSwapHistoricalFundingRate = exports.getSwapMarketBbo = exports.getSwapOpenInterest = exports.getSwapMarketTrade = exports.getSwapBatchFundingRate = exports.getSpotTick = exports.getSpotSymbols = exports.getPerpetualContractSymbols = void 0;
|
|
3
|
+
exports.getSpotMarketTickers = exports.getV2ReferenceCurrencies = exports.getSwapCrossLadderMargin = exports.getSwapHistoryKline = exports.getSwapHistoricalFundingRate = exports.getSwapMarketBbo = exports.getSwapOpenInterest = exports.getSwapMarketTrade = exports.getSwapBatchFundingRate = exports.getSpotHistoryKline = exports.getSpotTick = exports.getSpotSymbols = exports.getPerpetualContractSymbols = void 0;
|
|
4
4
|
const utils_1 = require("@yuants/utils");
|
|
5
5
|
// Huobi API 根域名
|
|
6
6
|
const SWAP_API_ROOT = 'api.hbdm.com';
|
|
@@ -60,6 +60,17 @@ function getSpotTick(params) {
|
|
|
60
60
|
return publicRequest('GET', `/market/detail/merged`, SPOT_API_ROOT, params);
|
|
61
61
|
}
|
|
62
62
|
exports.getSpotTick = getSpotTick;
|
|
63
|
+
/**
|
|
64
|
+
* 【现货】获取K线数据
|
|
65
|
+
*
|
|
66
|
+
* https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3ff18-7773-11ed-9966-0242ac110003
|
|
67
|
+
*
|
|
68
|
+
* Note: HTX spot KLine uses unix seconds in `data[].id`
|
|
69
|
+
*/
|
|
70
|
+
function getSpotHistoryKline(params) {
|
|
71
|
+
return publicRequest('GET', `/market/history/kline`, SPOT_API_ROOT, params);
|
|
72
|
+
}
|
|
73
|
+
exports.getSpotHistoryKline = getSpotHistoryKline;
|
|
63
74
|
/**
|
|
64
75
|
* 【通用】批量获取合约资金费率
|
|
65
76
|
*
|
|
@@ -137,6 +148,15 @@ function getSwapHistoricalFundingRate(params) {
|
|
|
137
148
|
return publicRequest('GET', `/linear-swap-api/v1/swap_historical_funding_rate`, SWAP_API_ROOT, params);
|
|
138
149
|
}
|
|
139
150
|
exports.getSwapHistoricalFundingRate = getSwapHistoricalFundingRate;
|
|
151
|
+
/**
|
|
152
|
+
* 【通用】获取K线数据
|
|
153
|
+
*
|
|
154
|
+
* https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73746-77b5-11ed-9966-0242ac110003
|
|
155
|
+
*/
|
|
156
|
+
function getSwapHistoryKline(params) {
|
|
157
|
+
return publicRequest('GET', `/linear-swap-ex/market/history/kline`, SWAP_API_ROOT, params);
|
|
158
|
+
}
|
|
159
|
+
exports.getSwapHistoryKline = getSwapHistoryKline;
|
|
140
160
|
/**
|
|
141
161
|
* 【全仓】获取平台阶梯保证金
|
|
142
162
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAE3C,gBAAgB;AAChB,MAAM,aAAa,GAAG,cAAc,CAAC;AACrC,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC;;GAEG;AACH,KAAK,UAAU,aAAa,CAAC,MAAc,EAAE,IAAY,EAAE,QAAgB,EAAE,MAAY;IACvF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAC;IAElD,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,KAAK,MAAM,CAAC,CAAC,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SAAgB,wBAAwB,CAAC,MAKxC;IAIC,OAAO,aAAa,CAAC,KAAK,EAAE,8CAA8C,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AACrG,CAAC;AAVD,4DAUC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,MAAsD;IAkC7F,OAAO,aAAa,CAAC,KAAK,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AAnCD,4DAmCC;AAED;;;;;GAKG;AACI,MAAM,oBAAoB,GAAG,GAiBjC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAjBhD,QAAA,oBAAoB,wBAiB4B","sourcesContent":["import { formatTime } from '@yuants/utils';\n\n// Huobi API 根域名\nconst SWAP_API_ROOT = 'api.hbdm.com';\nconst SPOT_API_ROOT = 'api.huobi.pro';\n\n/**\n * 公共 API 请求方法\n */\nasync function publicRequest(method: string, path: string, api_root: string, params?: any) {\n const url = new URL(`https://${api_root}${path}`);\n\n if (method === 'GET') {\n for (const [k, v] of Object.entries(params || {})) {\n url.searchParams.append(k, String(v));\n }\n }\n\n const body = method === 'GET' ? '' : JSON.stringify(params);\n\n console.info(formatTime(Date.now()), method, url.href, body);\n\n const res = await fetch(url.href, {\n method,\n headers: { 'Content-Type': 'application/json' },\n body: body || undefined,\n });\n\n console.info(formatTime(Date.now()), 'PublicResponse', url.toString(), res.status);\n\n const retStr = await res.text();\n try {\n return JSON.parse(retStr);\n } catch (e) {\n console.error(formatTime(Date.now()), 'huobiRequestFailed', path, JSON.stringify(params), retStr);\n throw e;\n }\n}\n\n// ==================== 公共 API 方法 ====================\n\n/**\n * 获取永续合约产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72f34-77b5-11ed-9966-0242ac110003\n */\nexport function getPerpetualContractSymbols(params?: {\n contract_code?: string;\n support_margin_mode?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n symbol: string;\n contract_code: string;\n contract_size: number;\n price_tick: number;\n settlement_date: string;\n delivery_time: string;\n create_date: string;\n contract_status: number;\n support_margin_mode: string;\n contract_type: string;\n pair: string;\n business_type: string;\n delivery_date: string;\n }[];\n ts: string;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_contract_info', SWAP_API_ROOT, params);\n}\n\n/**\n * 获取现货产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec47f16-7773-11ed-9966-0242ac110003\n */\nexport function getSpotSymbols(): Promise<{\n status: string;\n data: {\n si: string;\n scr: string;\n sc: string;\n dn: string;\n bc: string;\n bcdn: string;\n qc: string;\n qcdn: string;\n state: string;\n whe: boolean;\n cd: boolean;\n te: boolean;\n toa: number;\n sp: string;\n w: number;\n ttp: number;\n tap: number;\n tpp: number;\n fp: number;\n suspend_desc: string;\n transfer_board_desc: string;\n tags: string;\n lr: number;\n smlr: number;\n flr: string;\n wr: string;\n d: number;\n elr: number;\n p: any;\n castate: string;\n ca1oa: number;\n ca2oa: number;\n }[];\n ts: string;\n full: number;\n err_code: string;\n err_msg: string;\n}> {\n return publicRequest('GET', '/v2/settings/common/symbols', SPOT_API_ROOT);\n}\n\n/**\n * 获取现货行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3fc25-7773-11ed-9966-0242ac110003\n */\nexport function getSpotTick(params: { symbol: string }): Promise<{\n status: string;\n tick: {\n close: number;\n };\n}> {\n return publicRequest('GET', `/market/detail/merged`, SPOT_API_ROOT, params);\n}\n\n/**\n * 【通用】批量获取合约资金费率\n *\n * 接口权限: 读取\n *\n * 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多240次请求(所有该IP的非行情类的公开接口请求共享3秒240次的额度)\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb71b45-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapBatchFundingRate(params: { contract_code?: string }): Promise<{\n status: string;\n ts: number;\n data: {\n estimated_rate: null;\n funding_rate: string;\n contract_code: string;\n symbol: string;\n fee_asset: string;\n funding_time: string;\n next_funding_time: null;\n trade_partition: string;\n }[];\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_batch_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最近成交记录\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73c34-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketTrade(params: { contract_code?: string; business_type?: string }): Promise<{\n ch: string;\n status: string;\n tick: {\n data: {\n amount: string;\n quantity: string;\n trade_turnover: string;\n ts: number;\n id: number;\n price: string;\n direction: string;\n contract_code: string;\n business_type: string;\n trade_partition: string;\n }[];\n id: number;\n ts: number;\n };\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/trade`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获得当前合约的总持仓量\n *\n * https://huobiapi.github.io/docs/usdt_swap/v1/cn/#3218e7531a\n */\nexport function getSwapOpenInterest(params: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n volume: number;\n amount: number;\n symbol: string;\n value: number;\n contract_code: string;\n trade_amount: number;\n trade_volume: number;\n trade_turnover: number;\n business_type: string;\n pair: string;\n contract_type: string;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_open_interest', SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最优挂单\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb735e0-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketBbo(params: { contract_code?: string }): Promise<{\n status: string;\n ticks: {\n trade_partition: string;\n business_type: string;\n contract_code: string;\n ask: number[] | null;\n bid: number[] | null;\n mrid: number;\n ts: number;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/bbo`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获取合约的历史资金费率\n *\n * 接口权限: 读取\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=5d51f1f9-77b6-11ed-9966-0242ac110003\n */\nexport function getSwapHistoricalFundingRate(params: {\n contract_code: string;\n page_index?: number;\n page_size?: number;\n}): Promise<{\n status: string;\n ts: number;\n data: {\n data: {\n symbol: string;\n contract_code: string;\n fee_asset: string;\n funding_time: string;\n funding_rate: string;\n realized_rate: string;\n avg_premium_index: string;\n }[];\n total_page: number;\n current_page: number;\n total_size: number;\n };\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_historical_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【全仓】获取平台阶梯保证金\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72290-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapCrossLadderMargin(params?: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: Array<{ contract_code: string; pair: string; list: Array<{ lever_rate: number }> }>;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_cross_ladder_margin', SWAP_API_ROOT, params);\n}\n\n/**\n * APIv2币链参考信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec478f0-7773-11ed-9966-0242ac110003\n */\nexport function getV2ReferenceCurrencies(params: { currency?: string; authorizedUser?: string }): Promise<{\n code: number;\n data: {\n currency: string;\n assetType: number;\n chains: {\n chain: string;\n displayName: string;\n fullName: string;\n baseChain?: string;\n baseChainProtocol?: string;\n isDynamic?: boolean;\n numOfConfirmations: number;\n numOfFastConfirmations: number;\n depositStatus: string;\n minDepositAmt: string;\n withdrawStatus: string;\n minWithdrawAmt: string;\n withdrawPrecision: number;\n maxWithdrawAmt: string;\n withdrawQuotaPerDay: string;\n withdrawQuotaPerYear: null;\n withdrawQuotaTotal: null;\n withdrawFeeType: string;\n transactFeeWithdraw?: string;\n addrWithTag: boolean;\n addrDepositTag: boolean;\n minTransactFeeWithdraw?: string;\n transactFeeRateWithdraw?: string;\n maxTransactFeeWithdraw?: string;\n }[];\n instStatus: string;\n }[];\n}> {\n return publicRequest('GET', '/v2/reference/currencies', SPOT_API_ROOT, params);\n}\n\n/**\n * 【现货】获取市场所有交易对的最新行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40374-7773-11ed-9966-0242ac110003\n *\n */\nexport const getSpotMarketTickers = (): Promise<{\n data: {\n symbol: string;\n open: number;\n high: number;\n low: number;\n close: number;\n amount: number;\n vol: number;\n count: number;\n bid: number;\n bidSize: number;\n ask: number;\n askSize: number;\n }[];\n status: string;\n ts: number;\n}> => publicRequest('GET', '/market/tickers', SPOT_API_ROOT);\n"]}
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAE3C,gBAAgB;AAChB,MAAM,aAAa,GAAG,cAAc,CAAC;AACrC,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC;;GAEG;AACH,KAAK,UAAU,aAAa,CAAC,MAAc,EAAE,IAAY,EAAE,QAAgB,EAAE,MAAY;IACvF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAC;IAElD,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE;YACjD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SACvC;KACF;IAED,MAAM,IAAI,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE5D,OAAO,CAAC,IAAI,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE7D,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE;QAChC,MAAM;QACN,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,IAAI,SAAS;KACxB,CAAC,CAAC;IAEH,OAAO,CAAC,IAAI,CAAC,IAAA,kBAAU,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aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAjBhD,QAAA,oBAAoB,wBAiB4B","sourcesContent":["import { formatTime } from '@yuants/utils';\n\n// Huobi API 根域名\nconst SWAP_API_ROOT = 'api.hbdm.com';\nconst SPOT_API_ROOT = 'api.huobi.pro';\n\n/**\n * 公共 API 请求方法\n */\nasync function publicRequest(method: string, path: string, api_root: string, params?: any) {\n const url = new URL(`https://${api_root}${path}`);\n\n if (method === 'GET') {\n for (const [k, v] of Object.entries(params || {})) {\n url.searchParams.append(k, String(v));\n }\n }\n\n const body = method === 'GET' ? '' : JSON.stringify(params);\n\n console.info(formatTime(Date.now()), method, url.href, body);\n\n const res = await fetch(url.href, {\n method,\n headers: { 'Content-Type': 'application/json' },\n body: body || undefined,\n });\n\n console.info(formatTime(Date.now()), 'PublicResponse', url.toString(), res.status);\n\n const retStr = await res.text();\n try {\n return JSON.parse(retStr);\n } catch (e) {\n console.error(formatTime(Date.now()), 'huobiRequestFailed', path, JSON.stringify(params), retStr);\n throw e;\n }\n}\n\n// ==================== 公共 API 方法 ====================\n\n/**\n * 获取永续合约产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72f34-77b5-11ed-9966-0242ac110003\n */\nexport function getPerpetualContractSymbols(params?: {\n contract_code?: string;\n support_margin_mode?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n symbol: string;\n contract_code: string;\n contract_size: number;\n price_tick: number;\n settlement_date: string;\n delivery_time: string;\n create_date: string;\n contract_status: number;\n support_margin_mode: string;\n contract_type: string;\n pair: string;\n business_type: string;\n delivery_date: string;\n }[];\n ts: string;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_contract_info', SWAP_API_ROOT, params);\n}\n\n/**\n * 获取现货产品信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec47f16-7773-11ed-9966-0242ac110003\n */\nexport function getSpotSymbols(): Promise<{\n status: string;\n data: {\n si: string;\n scr: string;\n sc: string;\n dn: string;\n bc: string;\n bcdn: string;\n qc: string;\n qcdn: string;\n state: string;\n whe: boolean;\n cd: boolean;\n te: boolean;\n toa: number;\n sp: string;\n w: number;\n ttp: number;\n tap: number;\n tpp: number;\n fp: number;\n suspend_desc: string;\n transfer_board_desc: string;\n tags: string;\n lr: number;\n smlr: number;\n flr: string;\n wr: string;\n d: number;\n elr: number;\n p: any;\n castate: string;\n ca1oa: number;\n ca2oa: number;\n }[];\n ts: string;\n full: number;\n err_code: string;\n err_msg: string;\n}> {\n return publicRequest('GET', '/v2/settings/common/symbols', SPOT_API_ROOT);\n}\n\n/**\n * 获取现货行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3fc25-7773-11ed-9966-0242ac110003\n */\nexport function getSpotTick(params: { symbol: string }): Promise<{\n status: string;\n tick: {\n close: number;\n };\n}> {\n return publicRequest('GET', `/market/detail/merged`, SPOT_API_ROOT, params);\n}\n\n/**\n * 【现货】获取K线数据\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec3ff18-7773-11ed-9966-0242ac110003\n *\n * Note: HTX spot KLine uses unix seconds in `data[].id`\n */\nexport function getSpotHistoryKline(params: {\n symbol: string;\n period: string;\n size?: number;\n from?: number;\n to?: number;\n}): Promise<{\n status: string;\n ch?: string;\n ts: number;\n data: {\n id: number;\n open: number;\n close: number;\n low: number;\n high: number;\n vol: number;\n amount?: number;\n count?: number;\n }[];\n}> {\n return publicRequest('GET', `/market/history/kline`, SPOT_API_ROOT, params);\n}\n\n/**\n * 【通用】批量获取合约资金费率\n *\n * 接口权限: 读取\n *\n * 限频: 其他非行情类的公开接口,比如获取指数信息,限价信息,交割结算、平台持仓信息等,所有用户都是每个IP3秒最多240次请求(所有该IP的非行情类的公开接口请求共享3秒240次的额度)\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb71b45-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapBatchFundingRate(params: { contract_code?: string }): Promise<{\n status: string;\n ts: number;\n data: {\n estimated_rate: null;\n funding_rate: string;\n contract_code: string;\n symbol: string;\n fee_asset: string;\n funding_time: string;\n next_funding_time: null;\n trade_partition: string;\n }[];\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_batch_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最近成交记录\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73c34-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketTrade(params: { contract_code?: string; business_type?: string }): Promise<{\n ch: string;\n status: string;\n tick: {\n data: {\n amount: string;\n quantity: string;\n trade_turnover: string;\n ts: number;\n id: number;\n price: string;\n direction: string;\n contract_code: string;\n business_type: string;\n trade_partition: string;\n }[];\n id: number;\n ts: number;\n };\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/trade`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获得当前合约的总持仓量\n *\n * https://huobiapi.github.io/docs/usdt_swap/v1/cn/#3218e7531a\n */\nexport function getSwapOpenInterest(params: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: {\n volume: number;\n amount: number;\n symbol: string;\n value: number;\n contract_code: string;\n trade_amount: number;\n trade_volume: number;\n trade_turnover: number;\n business_type: string;\n pair: string;\n contract_type: string;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_open_interest', SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取市场最优挂单\n *\n * 接口权限: 读取\n *\n * 限频: 行情类的公开接口,比如:获取K线数据、获取聚合行情、市场行情、获取行情深度数据、获取溢价指数K线、获取实时预测资金费率k线,获取基差数据、获取市场最近成交记录:\n *\n * (1) restful接口:同一个IP, 所有业务(交割合约、币本位永续合约和U本位合约)总共1秒最多800个请求\n *\n * 接口描述: 该接口支持全仓模式和逐仓模式\n *\n * 请求参数contract_code支持交割合约代码,格式为BTC-USDT-210625;同时支持合约标识,格式为 BTC-USDT(永续)、BTC-USDT-CW(当周)、BTC-USDT-NW(次周)、BTC-USDT-CQ(当季)、BTC-USDT-NQ(次季)。\n *\n * business_type 在查询交割合约数据时为必填参数。且参数值要传:futures 或 all 。\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb735e0-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapMarketBbo(params: { contract_code?: string }): Promise<{\n status: string;\n ticks: {\n trade_partition: string;\n business_type: string;\n contract_code: string;\n ask: number[] | null;\n bid: number[] | null;\n mrid: number;\n ts: number;\n }[];\n ts: number;\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/bbo`, SWAP_API_ROOT, params);\n}\n\n/**\n * 获取合约的历史资金费率\n *\n * 接口权限: 读取\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=5d51f1f9-77b6-11ed-9966-0242ac110003\n */\nexport function getSwapHistoricalFundingRate(params: {\n contract_code: string;\n page_index?: number;\n page_size?: number;\n}): Promise<{\n status: string;\n ts: number;\n data: {\n data: {\n symbol: string;\n contract_code: string;\n fee_asset: string;\n funding_time: string;\n funding_rate: string;\n realized_rate: string;\n avg_premium_index: string;\n }[];\n total_page: number;\n current_page: number;\n total_size: number;\n };\n}> {\n return publicRequest('GET', `/linear-swap-api/v1/swap_historical_funding_rate`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【通用】获取K线数据\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb73746-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapHistoryKline(params: {\n contract_code: string;\n period: string;\n size?: number;\n from?: number;\n to?: number;\n}): Promise<{\n status: string;\n ch?: string;\n ts: number;\n data: {\n id: number;\n open: number;\n close: number;\n low: number;\n high: number;\n vol: number;\n amount?: number;\n count?: number;\n }[];\n}> {\n return publicRequest('GET', `/linear-swap-ex/market/history/kline`, SWAP_API_ROOT, params);\n}\n\n/**\n * 【全仓】获取平台阶梯保证金\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=8cb72290-77b5-11ed-9966-0242ac110003\n */\nexport function getSwapCrossLadderMargin(params?: {\n contract_code?: string;\n pair?: string;\n contract_type?: string;\n business_type?: string;\n}): Promise<{\n status: string;\n data: Array<{ contract_code: string; pair: string; list: Array<{ lever_rate: number }> }>;\n}> {\n return publicRequest('GET', '/linear-swap-api/v1/swap_cross_ladder_margin', SWAP_API_ROOT, params);\n}\n\n/**\n * APIv2币链参考信息\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec478f0-7773-11ed-9966-0242ac110003\n */\nexport function getV2ReferenceCurrencies(params: { currency?: string; authorizedUser?: string }): Promise<{\n code: number;\n data: {\n currency: string;\n assetType: number;\n chains: {\n chain: string;\n displayName: string;\n fullName: string;\n baseChain?: string;\n baseChainProtocol?: string;\n isDynamic?: boolean;\n numOfConfirmations: number;\n numOfFastConfirmations: number;\n depositStatus: string;\n minDepositAmt: string;\n withdrawStatus: string;\n minWithdrawAmt: string;\n withdrawPrecision: number;\n maxWithdrawAmt: string;\n withdrawQuotaPerDay: string;\n withdrawQuotaPerYear: null;\n withdrawQuotaTotal: null;\n withdrawFeeType: string;\n transactFeeWithdraw?: string;\n addrWithTag: boolean;\n addrDepositTag: boolean;\n minTransactFeeWithdraw?: string;\n transactFeeRateWithdraw?: string;\n maxTransactFeeWithdraw?: string;\n }[];\n instStatus: string;\n }[];\n}> {\n return publicRequest('GET', '/v2/reference/currencies', SPOT_API_ROOT, params);\n}\n\n/**\n * 【现货】获取市场所有交易对的最新行情\n *\n * https://www.htx.com/zh-cn/opend/newApiPages/?id=7ec40374-7773-11ed-9966-0242ac110003\n *\n */\nexport const getSpotMarketTickers = (): Promise<{\n data: {\n symbol: string;\n open: number;\n high: number;\n low: number;\n close: number;\n amount: number;\n vol: number;\n count: number;\n bid: number;\n bidSize: number;\n ask: number;\n askSize: number;\n }[];\n status: string;\n ts: number;\n}> => publicRequest('GET', '/market/tickers', SPOT_API_ROOT);\n"]}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,sCAAsC,CAAC;AAC9C,OAAO,8BAA8B,CAAC;AACtC,OAAO,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,sCAAsC,CAAC;AAC9C,OAAO,8BAA8B,CAAC;AACtC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,yBAAyB,CAAC;AACjC,OAAO,kCAAkC,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -4,4 +4,6 @@ require("./services/exchange");
|
|
|
4
4
|
require("./services/market-data/interest_rate");
|
|
5
5
|
require("./services/market-data/quote");
|
|
6
6
|
require("./services/quotes");
|
|
7
|
+
require("./services/ohlc-service");
|
|
8
|
+
require("./services/interest-rate-service");
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,gDAA8C;AAC9C,wCAAsC;AACtC,6BAA2B","sourcesContent":["import './services/exchange';\nimport './services/market-data/interest_rate';\nimport './services/market-data/quote';\nimport './services/quotes';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,gDAA8C;AAC9C,wCAAsC;AACtC,6BAA2B;AAC3B,mCAAiC;AACjC,4CAA0C","sourcesContent":["import './services/exchange';\nimport './services/market-data/interest_rate';\nimport './services/market-data/quote';\nimport './services/quotes';\nimport './services/ohlc-service';\nimport './services/interest-rate-service';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest-rate-service.d.ts","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const exchange_1 = require("@yuants/exchange");
|
|
4
|
+
const protocol_1 = require("@yuants/protocol");
|
|
5
|
+
const utils_1 = require("@yuants/utils");
|
|
6
|
+
const public_api_1 = require("../api/public-api");
|
|
7
|
+
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
8
|
+
const INGEST_SERVICE_OPTIONS = {
|
|
9
|
+
concurrent: 1,
|
|
10
|
+
max_pending_requests: 20,
|
|
11
|
+
ingress_token_capacity: 2,
|
|
12
|
+
ingress_token_refill_interval: 1000,
|
|
13
|
+
egress_token_capacity: 1,
|
|
14
|
+
egress_token_refill_interval: 1000,
|
|
15
|
+
};
|
|
16
|
+
const PAGE_SIZE = 50;
|
|
17
|
+
const computePageRangeMs = (items) => {
|
|
18
|
+
if (items.length === 0)
|
|
19
|
+
return undefined;
|
|
20
|
+
let minMs = Infinity;
|
|
21
|
+
let maxMs = -Infinity;
|
|
22
|
+
for (const item of items) {
|
|
23
|
+
const ms = Number(item.funding_time);
|
|
24
|
+
if (isNaN(ms))
|
|
25
|
+
continue;
|
|
26
|
+
if (ms < minMs)
|
|
27
|
+
minMs = ms;
|
|
28
|
+
if (ms > maxMs)
|
|
29
|
+
maxMs = ms;
|
|
30
|
+
}
|
|
31
|
+
if (!isFinite(minMs) || !isFinite(maxMs))
|
|
32
|
+
return undefined;
|
|
33
|
+
return { minMs, maxMs };
|
|
34
|
+
};
|
|
35
|
+
const fetchFundingRatePage = async (params) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const res = await (0, public_api_1.getSwapHistoricalFundingRate)({
|
|
38
|
+
contract_code: params.contract_code,
|
|
39
|
+
page_index: params.pageIndex,
|
|
40
|
+
page_size: PAGE_SIZE,
|
|
41
|
+
});
|
|
42
|
+
if (res.status !== 'ok') {
|
|
43
|
+
throw new Error(`HTX getSwapHistoricalFundingRate failed: ${res.status}`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
items: (_a = res.data.data) !== null && _a !== void 0 ? _a : [],
|
|
47
|
+
totalPage: res.data.total_page,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const locatePageByTimeBackward = async (params) => {
|
|
51
|
+
const first = await fetchFundingRatePage({ contract_code: params.contract_code, pageIndex: 0 });
|
|
52
|
+
const totalPage = first.totalPage;
|
|
53
|
+
if (!totalPage || totalPage <= 1)
|
|
54
|
+
return { pageIndex: 0, totalPage: totalPage || 1 };
|
|
55
|
+
const rangeCache = new Map([[0, computePageRangeMs(first.items)]]);
|
|
56
|
+
const getRange = async (pageIndex) => {
|
|
57
|
+
if (rangeCache.has(pageIndex))
|
|
58
|
+
return rangeCache.get(pageIndex);
|
|
59
|
+
const page = await fetchFundingRatePage({ contract_code: params.contract_code, pageIndex });
|
|
60
|
+
const range = computePageRangeMs(page.items);
|
|
61
|
+
rangeCache.set(pageIndex, range);
|
|
62
|
+
return range;
|
|
63
|
+
};
|
|
64
|
+
let left = 0;
|
|
65
|
+
let right = totalPage - 1;
|
|
66
|
+
while (left <= right) {
|
|
67
|
+
const mid = Math.floor((left + right) / 2);
|
|
68
|
+
const range = await getRange(mid);
|
|
69
|
+
if (!range) {
|
|
70
|
+
right = mid - 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (params.targetMs > range.maxMs) {
|
|
74
|
+
right = mid - 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (params.targetMs < range.minMs) {
|
|
78
|
+
left = mid + 1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
return { pageIndex: mid, totalPage };
|
|
82
|
+
}
|
|
83
|
+
return { pageIndex: Math.min(Math.max(0, left), totalPage - 1), totalPage };
|
|
84
|
+
};
|
|
85
|
+
const fetchFundingRateBackward = async (req) => {
|
|
86
|
+
const [, instType, contract_code] = (0, utils_1.decodePath)(req.product_id);
|
|
87
|
+
if (instType !== 'SWAP' || !contract_code)
|
|
88
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
89
|
+
const targetMs = req.time;
|
|
90
|
+
const { pageIndex } = await locatePageByTimeBackward({ contract_code, targetMs });
|
|
91
|
+
const page = await fetchFundingRatePage({ contract_code, pageIndex });
|
|
92
|
+
return page.items
|
|
93
|
+
.map((v) => {
|
|
94
|
+
const ms = Number(v.funding_time);
|
|
95
|
+
const rate = Number(v.funding_rate);
|
|
96
|
+
return {
|
|
97
|
+
series_id: req.series_id,
|
|
98
|
+
product_id: req.product_id,
|
|
99
|
+
datasource_id: 'HTX',
|
|
100
|
+
created_at: (0, utils_1.formatTime)(ms),
|
|
101
|
+
long_rate: `${-rate}`,
|
|
102
|
+
short_rate: `${rate}`,
|
|
103
|
+
settlement_price: '',
|
|
104
|
+
};
|
|
105
|
+
})
|
|
106
|
+
.filter((x) => Date.parse(x.created_at) < targetMs);
|
|
107
|
+
};
|
|
108
|
+
(0, exchange_1.provideInterestRateService)(terminal, {
|
|
109
|
+
product_id_prefix: 'HTX/SWAP/',
|
|
110
|
+
direction: 'backward',
|
|
111
|
+
}, fetchFundingRateBackward, INGEST_SERVICE_OPTIONS);
|
|
112
|
+
//# sourceMappingURL=interest-rate-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest-rate-service.js","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":";;AACA,+CAA8D;AAC9D,+CAA6D;AAC7D,yCAAuD;AACvD,kDAAiE;AAEjE,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,sBAAsB,GAAoB;IAC9C,UAAU,EAAE,CAAC;IACb,oBAAoB,EAAE,EAAE;IACxB,sBAAsB,EAAE,CAAC;IACzB,6BAA6B,EAAE,IAAI;IACnC,qBAAqB,EAAE,CAAC;IACxB,4BAA4B,EAAE,IAAI;CACnC,CAAC;AAEF,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;QACxB,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,IAAI,KAAK,CAAC,EAAE,CAAC;YAAE,SAAS;QACxB,IAAI,EAAE,GAAG,KAAK;YAAE,KAAK,GAAG,EAAE,CAAC;QAC3B,IAAI,EAAE,GAAG,KAAK;YAAE,KAAK,GAAG,EAAE,CAAC;KAC5B;IACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3D,OAAO,E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provideInterestRateService } from '@yuants/exchange';\nimport { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { getSwapHistoricalFundingRate } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst INGEST_SERVICE_OPTIONS: IServiceOptions = {\n concurrent: 1,\n max_pending_requests: 20,\n ingress_token_capacity: 2,\n ingress_token_refill_interval: 1000,\n egress_token_capacity: 1,\n egress_token_refill_interval: 1000,\n};\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 INGEST_SERVICE_OPTIONS,\n);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ohlc-service.d.ts","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const exchange_1 = require("@yuants/exchange");
|
|
4
|
+
const protocol_1 = require("@yuants/protocol");
|
|
5
|
+
const utils_1 = require("@yuants/utils");
|
|
6
|
+
const public_api_1 = require("../api/public-api");
|
|
7
|
+
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
8
|
+
const INGEST_SERVICE_OPTIONS = {
|
|
9
|
+
concurrent: 1,
|
|
10
|
+
max_pending_requests: 20,
|
|
11
|
+
ingress_token_capacity: 2,
|
|
12
|
+
ingress_token_refill_interval: 1000,
|
|
13
|
+
egress_token_capacity: 1,
|
|
14
|
+
egress_token_refill_interval: 1000,
|
|
15
|
+
};
|
|
16
|
+
const DURATION_TO_HTX_PERIOD = {
|
|
17
|
+
PT1M: '1min',
|
|
18
|
+
PT5M: '5min',
|
|
19
|
+
PT15M: '15min',
|
|
20
|
+
PT30M: '30min',
|
|
21
|
+
PT1H: '60min',
|
|
22
|
+
PT4H: '4hour',
|
|
23
|
+
P1D: '1day',
|
|
24
|
+
P1W: '1week',
|
|
25
|
+
};
|
|
26
|
+
const DEFAULT_BAR_COUNT = 500;
|
|
27
|
+
const fetchSpotOHLCPageBackward = async (req) => {
|
|
28
|
+
var _a;
|
|
29
|
+
const [, instType, symbol] = (0, utils_1.decodePath)(req.product_id);
|
|
30
|
+
if (instType !== 'SPOT' || !symbol)
|
|
31
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
32
|
+
const period = DURATION_TO_HTX_PERIOD[req.duration];
|
|
33
|
+
if (!period)
|
|
34
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
35
|
+
const offset = (0, utils_1.convertDurationToOffset)(req.duration);
|
|
36
|
+
const endedAtMs = req.time;
|
|
37
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
38
|
+
const from = Math.max(0, Math.floor((endedAtMs - DEFAULT_BAR_COUNT * offset) / 1000));
|
|
39
|
+
const res = await (0, public_api_1.getSpotHistoryKline)({
|
|
40
|
+
symbol: symbol.toLowerCase(),
|
|
41
|
+
period,
|
|
42
|
+
size: DEFAULT_BAR_COUNT,
|
|
43
|
+
from,
|
|
44
|
+
to,
|
|
45
|
+
});
|
|
46
|
+
if (res.status !== 'ok') {
|
|
47
|
+
throw new Error(`HTX getSpotHistoryKline failed: ${res.status}`);
|
|
48
|
+
}
|
|
49
|
+
return ((_a = res.data) !== null && _a !== void 0 ? _a : [])
|
|
50
|
+
.map((k) => {
|
|
51
|
+
const createdAtMs = k.id * 1000;
|
|
52
|
+
return {
|
|
53
|
+
series_id: req.series_id,
|
|
54
|
+
datasource_id: 'HTX',
|
|
55
|
+
product_id: req.product_id,
|
|
56
|
+
duration: req.duration,
|
|
57
|
+
created_at: (0, utils_1.formatTime)(createdAtMs),
|
|
58
|
+
closed_at: (0, utils_1.formatTime)(createdAtMs + offset),
|
|
59
|
+
open: `${k.open}`,
|
|
60
|
+
high: `${k.high}`,
|
|
61
|
+
low: `${k.low}`,
|
|
62
|
+
close: `${k.close}`,
|
|
63
|
+
volume: `${k.vol}`,
|
|
64
|
+
open_interest: '0',
|
|
65
|
+
};
|
|
66
|
+
})
|
|
67
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
68
|
+
};
|
|
69
|
+
const fetchOHLCPageBackward = async (req) => {
|
|
70
|
+
var _a;
|
|
71
|
+
const [, instType, contract_code] = (0, utils_1.decodePath)(req.product_id);
|
|
72
|
+
if (instType !== 'SWAP' || !contract_code)
|
|
73
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
74
|
+
const period = DURATION_TO_HTX_PERIOD[req.duration];
|
|
75
|
+
if (!period)
|
|
76
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
77
|
+
const offset = (0, utils_1.convertDurationToOffset)(req.duration);
|
|
78
|
+
const endedAtMs = req.time;
|
|
79
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
80
|
+
const from = Math.max(0, Math.floor((endedAtMs - DEFAULT_BAR_COUNT * offset) / 1000));
|
|
81
|
+
const res = await (0, public_api_1.getSwapHistoryKline)({
|
|
82
|
+
contract_code,
|
|
83
|
+
period,
|
|
84
|
+
size: DEFAULT_BAR_COUNT,
|
|
85
|
+
from,
|
|
86
|
+
to,
|
|
87
|
+
});
|
|
88
|
+
if (res.status !== 'ok') {
|
|
89
|
+
throw new Error(`HTX getSwapHistoryKline failed: ${res.status}`);
|
|
90
|
+
}
|
|
91
|
+
return ((_a = res.data) !== null && _a !== void 0 ? _a : [])
|
|
92
|
+
.map((k) => {
|
|
93
|
+
const createdAtMs = k.id * 1000;
|
|
94
|
+
return {
|
|
95
|
+
series_id: req.series_id,
|
|
96
|
+
datasource_id: 'HTX',
|
|
97
|
+
product_id: req.product_id,
|
|
98
|
+
duration: req.duration,
|
|
99
|
+
created_at: (0, utils_1.formatTime)(createdAtMs),
|
|
100
|
+
closed_at: (0, utils_1.formatTime)(createdAtMs + offset),
|
|
101
|
+
open: `${k.open}`,
|
|
102
|
+
high: `${k.high}`,
|
|
103
|
+
low: `${k.low}`,
|
|
104
|
+
close: `${k.close}`,
|
|
105
|
+
volume: `${k.vol}`,
|
|
106
|
+
open_interest: '0',
|
|
107
|
+
};
|
|
108
|
+
})
|
|
109
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
110
|
+
};
|
|
111
|
+
(0, exchange_1.provideOHLCService)(terminal, {
|
|
112
|
+
product_id_prefix: 'HTX/SWAP/',
|
|
113
|
+
duration_list: Object.keys(DURATION_TO_HTX_PERIOD),
|
|
114
|
+
direction: 'backward',
|
|
115
|
+
}, fetchOHLCPageBackward, INGEST_SERVICE_OPTIONS);
|
|
116
|
+
(0, exchange_1.provideOHLCService)(terminal, {
|
|
117
|
+
product_id_prefix: 'HTX/SPOT/',
|
|
118
|
+
duration_list: Object.keys(DURATION_TO_HTX_PERIOD),
|
|
119
|
+
direction: 'backward',
|
|
120
|
+
}, fetchSpotOHLCPageBackward, INGEST_SERVICE_OPTIONS);
|
|
121
|
+
//# sourceMappingURL=ohlc-service.js.map
|
|
@@ -0,0 +1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tB,EACD,yBAAyB,EACzB,sBAAsB,CACvB,CAAC","sourcesContent":["import { IOHLC } from '@yuants/data-ohlc';\nimport { provideOHLCService } from '@yuants/exchange';\nimport { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';\nimport { getSpotHistoryKline, getSwapHistoryKline } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst INGEST_SERVICE_OPTIONS: IServiceOptions = {\n concurrent: 1,\n max_pending_requests: 20,\n ingress_token_capacity: 2,\n ingress_token_refill_interval: 1000,\n egress_token_capacity: 1,\n egress_token_refill_interval: 1000,\n};\n\nconst DURATION_TO_HTX_PERIOD: Record<string, string> = {\n PT1M: '1min',\n PT5M: '5min',\n PT15M: '15min',\n PT30M: '30min',\n PT1H: '60min',\n PT4H: '4hour',\n P1D: '1day',\n P1W: '1week',\n};\n\nconst DEFAULT_BAR_COUNT = 500;\n\nconst fetchSpotOHLCPageBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\n const [, instType, symbol] = decodePath(req.product_id);\n if (instType !== 'SPOT' || !symbol) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const period = DURATION_TO_HTX_PERIOD[req.duration];\n if (!period) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n\n const to = Math.floor(endedAtMs / 1000);\n const from = Math.max(0, Math.floor((endedAtMs - DEFAULT_BAR_COUNT * offset) / 1000));\n\n const res = await getSpotHistoryKline({\n symbol: symbol.toLowerCase(),\n period,\n size: DEFAULT_BAR_COUNT,\n from,\n to,\n });\n if (res.status !== 'ok') {\n throw new Error(`HTX getSpotHistoryKline failed: ${res.status}`);\n }\n\n return (res.data ?? [])\n .map((k): IOHLC => {\n const createdAtMs = k.id * 1000;\n return {\n series_id: req.series_id,\n datasource_id: 'HTX',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(createdAtMs),\n closed_at: formatTime(createdAtMs + offset),\n open: `${k.open}`,\n high: `${k.high}`,\n low: `${k.low}`,\n close: `${k.close}`,\n volume: `${k.vol}`,\n open_interest: '0',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nconst fetchOHLCPageBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\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 period = DURATION_TO_HTX_PERIOD[req.duration];\n if (!period) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n\n const to = Math.floor(endedAtMs / 1000);\n const from = Math.max(0, Math.floor((endedAtMs - DEFAULT_BAR_COUNT * offset) / 1000));\n\n const res = await getSwapHistoryKline({\n contract_code,\n period,\n size: DEFAULT_BAR_COUNT,\n from,\n to,\n });\n if (res.status !== 'ok') {\n throw new Error(`HTX getSwapHistoryKline failed: ${res.status}`);\n }\n\n return (res.data ?? [])\n .map((k): IOHLC => {\n const createdAtMs = k.id * 1000;\n return {\n series_id: req.series_id,\n datasource_id: 'HTX',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(createdAtMs),\n closed_at: formatTime(createdAtMs + offset),\n open: `${k.open}`,\n high: `${k.high}`,\n low: `${k.low}`,\n close: `${k.close}`,\n volume: `${k.vol}`,\n open_interest: '0',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'HTX/SWAP/',\n duration_list: Object.keys(DURATION_TO_HTX_PERIOD),\n direction: 'backward',\n },\n fetchOHLCPageBackward,\n INGEST_SERVICE_OPTIONS,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'HTX/SPOT/',\n duration_list: Object.keys(DURATION_TO_HTX_PERIOD),\n direction: 'backward',\n },\n fetchSpotOHLCPageBackward,\n INGEST_SERVICE_OPTIONS,\n);\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-huobi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -8,18 +8,19 @@
|
|
|
8
8
|
"temp"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@yuants/protocol": "0.53.
|
|
12
|
-
"@yuants/data-account": "0.11.
|
|
13
|
-
"@yuants/data-order": "0.7.
|
|
14
|
-
"@yuants/
|
|
15
|
-
"@yuants/
|
|
16
|
-
"@yuants/
|
|
17
|
-
"@yuants/
|
|
18
|
-
"@yuants/
|
|
19
|
-
"@yuants/data-
|
|
20
|
-
"@yuants/data-
|
|
21
|
-
"@yuants/data-
|
|
22
|
-
"@yuants/
|
|
11
|
+
"@yuants/protocol": "0.53.4",
|
|
12
|
+
"@yuants/data-account": "0.11.1",
|
|
13
|
+
"@yuants/data-order": "0.7.2",
|
|
14
|
+
"@yuants/data-ohlc": "0.5.0",
|
|
15
|
+
"@yuants/transfer": "0.2.41",
|
|
16
|
+
"@yuants/utils": "0.16.0",
|
|
17
|
+
"@yuants/cache": "0.3.5",
|
|
18
|
+
"@yuants/sql": "0.9.32",
|
|
19
|
+
"@yuants/data-product": "0.5.2",
|
|
20
|
+
"@yuants/data-series": "0.3.54",
|
|
21
|
+
"@yuants/data-interest-rate": "0.2.0",
|
|
22
|
+
"@yuants/data-quote": "0.4.1",
|
|
23
|
+
"@yuants/exchange": "0.8.2",
|
|
23
24
|
"rxjs": "~7.5.6"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"@rushstack/heft-node-rig": "~1.10.7",
|
|
30
31
|
"@types/heft-jest": "1.0.3",
|
|
31
32
|
"@types/node": "22",
|
|
32
|
-
"@yuants/extension": "0.2.
|
|
33
|
+
"@yuants/extension": "0.2.33",
|
|
33
34
|
"@yuants/tool-kit": "0.2.1",
|
|
34
35
|
"typescript": "~4.7.4"
|
|
35
36
|
},
|
package/temp/package-deps.json
CHANGED
|
@@ -1,44 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
"apps/vendor-huobi/CHANGELOG.json": "
|
|
3
|
-
"apps/vendor-huobi/CHANGELOG.md": "
|
|
2
|
+
"apps/vendor-huobi/CHANGELOG.json": "b87c078102293ee7c80474a084743fb2dd531f17",
|
|
3
|
+
"apps/vendor-huobi/CHANGELOG.md": "ad98f1e8fb2e802dd24337a1657e1b6a14511570",
|
|
4
4
|
"apps/vendor-huobi/README.md": "d7bf0149513114eab5500a6b5c9e7cba10565572",
|
|
5
5
|
"apps/vendor-huobi/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
6
6
|
"apps/vendor-huobi/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
|
|
7
7
|
"apps/vendor-huobi/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
8
8
|
"apps/vendor-huobi/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
9
9
|
"apps/vendor-huobi/etc/vendor-huobi.api.md": "dc8cbf2a044a227b30a4ee9701b0c97328244724",
|
|
10
|
-
"apps/vendor-huobi/package.json": "
|
|
10
|
+
"apps/vendor-huobi/package.json": "83d6d2e053bc8bf021bcee92b4198e90d337859e",
|
|
11
11
|
"apps/vendor-huobi/src/__archived/account-info.ts": "5c325d3bb8839476c11f25693326ce05f3321ebd",
|
|
12
12
|
"apps/vendor-huobi/src/__archived/api.ts": "8366151dc881b177d0478fb328a601a11e33cd35",
|
|
13
13
|
"apps/vendor-huobi/src/__archived/transfer.ts": "fd299ad82ff31344460967f2a938b8f36c879259",
|
|
14
14
|
"apps/vendor-huobi/src/api/private-api.ts": "8f552b84956a1c65077e194dcf481924204f4662",
|
|
15
|
-
"apps/vendor-huobi/src/api/public-api.ts": "
|
|
16
|
-
"apps/vendor-huobi/src/index.ts": "
|
|
15
|
+
"apps/vendor-huobi/src/api/public-api.ts": "730d77c55ae5bf5022c5ccdc964f874131f8b341",
|
|
16
|
+
"apps/vendor-huobi/src/index.ts": "997283c933e2df8c6d35ce3d2f40d7d0c33c469b",
|
|
17
17
|
"apps/vendor-huobi/src/services/accounts/spot.ts": "9b214135dd375822ea5ef03c0fee108873ccc264",
|
|
18
18
|
"apps/vendor-huobi/src/services/accounts/super-margin.ts": "ff885947334f43085aacb6e8c37b997afee2b7f6",
|
|
19
19
|
"apps/vendor-huobi/src/services/accounts/swap.ts": "91ef044f09ed3dddd7b0d32116a16c78f74ba9be",
|
|
20
20
|
"apps/vendor-huobi/src/services/exchange.ts": "6fed94206a22c43d3c6890cf52ff054a24d98d82",
|
|
21
|
+
"apps/vendor-huobi/src/services/interest-rate-service.ts": "55fd2de153c25ccd7074ed2a866af703c6fed143",
|
|
21
22
|
"apps/vendor-huobi/src/services/market-data/interest_rate.ts": "79aa362f9fa90e612f9813d0b45d357b96189f3e",
|
|
22
23
|
"apps/vendor-huobi/src/services/market-data/quote.ts": "2f5883a95b11cf19c1a9a595567f9369b360cccf",
|
|
24
|
+
"apps/vendor-huobi/src/services/ohlc-service.ts": "6a050e775c2be85afdad90b68a52e9b2b82676f5",
|
|
23
25
|
"apps/vendor-huobi/src/services/orders/listOrders.ts": "1cf4621727fb290f8e5fd1439765fd73387bda7a",
|
|
24
26
|
"apps/vendor-huobi/src/services/orders/submitOrder.ts": "c6b0625d4922d5188ef042893865e029f5123f24",
|
|
25
27
|
"apps/vendor-huobi/src/services/product.ts": "096feb6e1348910242e814ca45848afa3b5bff98",
|
|
26
28
|
"apps/vendor-huobi/src/services/quotes.ts": "a99185c9d2e95da220919deef49357ec6280ee78",
|
|
27
29
|
"apps/vendor-huobi/src/services/uid.ts": "b71c27a6a0debdd9365dea35306f4763327aca2f",
|
|
28
30
|
"apps/vendor-huobi/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
|
|
29
|
-
"apps/vendor-huobi/.rush/temp/shrinkwrap-deps.json": "
|
|
30
|
-
"libraries/protocol/temp/package-deps.json": "
|
|
31
|
-
"libraries/data-account/temp/package-deps.json": "
|
|
32
|
-
"libraries/data-order/temp/package-deps.json": "
|
|
33
|
-
"libraries/
|
|
34
|
-
"libraries/
|
|
35
|
-
"libraries/
|
|
36
|
-
"libraries/
|
|
37
|
-
"libraries/
|
|
38
|
-
"libraries/data-
|
|
39
|
-
"libraries/data-
|
|
40
|
-
"libraries/data-
|
|
41
|
-
"libraries/
|
|
42
|
-
"libraries/
|
|
31
|
+
"apps/vendor-huobi/.rush/temp/shrinkwrap-deps.json": "237a816d6e825b5bd2a0fc742f5d055c19e37d3d",
|
|
32
|
+
"libraries/protocol/temp/package-deps.json": "a30b39ceb4cd530ed6bc4e97433f995b026b26d9",
|
|
33
|
+
"libraries/data-account/temp/package-deps.json": "363f171a8ec4ae558e4b20626b06bc8ae145ce8a",
|
|
34
|
+
"libraries/data-order/temp/package-deps.json": "daedd350fe85f0564f7739c73689fb09664132de",
|
|
35
|
+
"libraries/data-ohlc/temp/package-deps.json": "2115e384567d1b0958c085f455da9bed5a638780",
|
|
36
|
+
"libraries/transfer/temp/package-deps.json": "6d0942aa4c50b35a8e47a500fe494fb4a08a99e5",
|
|
37
|
+
"libraries/utils/temp/package-deps.json": "7a9e2336d7ad44e827d81e9722767d6cdf99fc1f",
|
|
38
|
+
"libraries/cache/temp/package-deps.json": "2e6c6db8f750a2e173a3c4b9a57d22fbd6f9181d",
|
|
39
|
+
"libraries/sql/temp/package-deps.json": "252d819797cb0a4bbc579075867624b05b19dabb",
|
|
40
|
+
"libraries/data-product/temp/package-deps.json": "4f525fda6d65677f9fbdcd1b4480970dd6ff9e5b",
|
|
41
|
+
"libraries/data-series/temp/package-deps.json": "71b373ec83ce1188001e341aefaca704aa4a5c38",
|
|
42
|
+
"libraries/data-interest-rate/temp/package-deps.json": "0aa2057c1c5c432be87e97b8df22984bdcab307c",
|
|
43
|
+
"libraries/data-quote/temp/package-deps.json": "07e342d9dba4d5f5d89b62c74f079425b560cb1f",
|
|
44
|
+
"libraries/exchange/temp/package-deps.json": "5267eb70cd2e7df4a645f94133ad3428b52c567e",
|
|
45
|
+
"libraries/extension/temp/package-deps.json": "fcddc4a668ecf969ca593c67ff02543fe69a6829",
|
|
43
46
|
"tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
|
|
44
47
|
}
|