@yuants/vendor-hyperliquid 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/private-api.js +1 -1
- package/dist/api/private-api.js.map +1 -1
- package/dist/api/sign.js.map +1 -0
- package/dist/api/types.js +4 -8
- package/dist/api/types.js.map +1 -1
- package/dist/index.js +1 -7
- package/dist/index.js.map +1 -1
- package/dist/services/accounts/perp.js +4 -16
- package/dist/services/accounts/perp.js.map +1 -1
- package/dist/services/accounts/spot.js +4 -5
- package/dist/services/accounts/spot.js.map +1 -1
- package/dist/services/exchange.js +79 -0
- package/dist/services/exchange.js.map +1 -0
- package/dist/services/markets/interest-rate.js +13 -7
- package/dist/services/markets/interest-rate.js.map +1 -1
- package/dist/services/markets/ohlc.js +11 -7
- package/dist/services/markets/ohlc.js.map +1 -1
- package/dist/services/markets/product.js +6 -6
- package/dist/services/markets/product.js.map +1 -1
- package/dist/services/markets/quote.js +4 -4
- package/dist/services/markets/quote.js.map +1 -1
- package/dist/services/orders/cancelOrder.js +1 -1
- package/dist/services/orders/cancelOrder.js.map +1 -1
- package/dist/services/orders/listOrders.js +17 -38
- package/dist/services/orders/listOrders.js.map +1 -1
- package/dist/services/orders/modifyOrder.js +2 -2
- package/dist/services/orders/modifyOrder.js.map +1 -1
- package/dist/services/orders/submitOrder.js +1 -1
- package/dist/services/orders/submitOrder.js.map +1 -1
- package/dist/{utils.js → services/utils.js} +13 -6
- package/dist/services/utils.js.map +1 -0
- package/lib/api/private-api.js +1 -1
- package/lib/api/private-api.js.map +1 -1
- package/lib/api/sign.d.ts.map +1 -0
- package/lib/api/sign.js.map +1 -0
- package/lib/api/types.d.ts +3 -4
- package/lib/api/types.d.ts.map +1 -1
- package/lib/api/types.js +6 -10
- package/lib/api/types.js.map +1 -1
- package/lib/index.d.ts +1 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -7
- package/lib/index.js.map +1 -1
- package/lib/services/accounts/perp.d.ts +1 -1
- package/lib/services/accounts/perp.d.ts.map +1 -1
- package/lib/services/accounts/perp.js +6 -18
- package/lib/services/accounts/perp.js.map +1 -1
- package/lib/services/accounts/spot.d.ts +1 -1
- package/lib/services/accounts/spot.d.ts.map +1 -1
- package/lib/services/accounts/spot.js +6 -7
- package/lib/services/accounts/spot.js.map +1 -1
- package/lib/services/exchange.d.ts +2 -0
- package/lib/services/exchange.d.ts.map +1 -0
- package/lib/services/exchange.js +81 -0
- package/lib/services/exchange.js.map +1 -0
- package/lib/services/markets/interest-rate.js +13 -7
- package/lib/services/markets/interest-rate.js.map +1 -1
- package/lib/services/markets/ohlc.js +10 -6
- package/lib/services/markets/ohlc.js.map +1 -1
- package/lib/services/markets/product.d.ts +2 -1
- package/lib/services/markets/product.d.ts.map +1 -1
- package/lib/services/markets/product.js +8 -6
- package/lib/services/markets/product.js.map +1 -1
- package/lib/services/markets/quote.js +4 -4
- package/lib/services/markets/quote.js.map +1 -1
- package/lib/services/orders/cancelOrder.js +1 -1
- package/lib/services/orders/cancelOrder.js.map +1 -1
- package/lib/services/orders/listOrders.d.ts +7 -3
- package/lib/services/orders/listOrders.d.ts.map +1 -1
- package/lib/services/orders/listOrders.js +21 -41
- package/lib/services/orders/listOrders.js.map +1 -1
- package/lib/services/orders/modifyOrder.d.ts.map +1 -1
- package/lib/services/orders/modifyOrder.js +7 -7
- package/lib/services/orders/modifyOrder.js.map +1 -1
- package/lib/services/orders/submitOrder.js +1 -1
- package/lib/services/orders/submitOrder.js.map +1 -1
- package/lib/{utils.d.ts → services/utils.d.ts} +4 -0
- package/lib/services/utils.d.ts.map +1 -0
- package/lib/{utils.js → services/utils.js} +15 -7
- package/lib/services/utils.js.map +1 -0
- package/package.json +15 -15
- package/temp/package-deps.json +37 -38
- package/dist/services/account-actions-with-credential.js +0 -36
- package/dist/services/account-actions-with-credential.js.map +0 -1
- package/dist/services/legacy.js +0 -51
- package/dist/services/legacy.js.map +0 -1
- package/dist/services/order-actions-with-credential.js +0 -20
- package/dist/services/order-actions-with-credential.js.map +0 -1
- package/dist/sign.js.map +0 -1
- package/dist/utils.js.map +0 -1
- package/lib/services/account-actions-with-credential.d.ts +0 -2
- package/lib/services/account-actions-with-credential.d.ts.map +0 -1
- package/lib/services/account-actions-with-credential.js +0 -38
- package/lib/services/account-actions-with-credential.js.map +0 -1
- package/lib/services/legacy.d.ts +0 -2
- package/lib/services/legacy.d.ts.map +0 -1
- package/lib/services/legacy.js +0 -53
- package/lib/services/legacy.js.map +0 -1
- package/lib/services/order-actions-with-credential.d.ts +0 -2
- package/lib/services/order-actions-with-credential.d.ts.map +0 -1
- package/lib/services/order-actions-with-credential.js +0 -22
- package/lib/services/order-actions-with-credential.js.map +0 -1
- package/lib/sign.d.ts.map +0 -1
- package/lib/sign.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
- /package/dist/{sign.js → api/sign.js} +0 -0
- /package/lib/{sign.d.ts → api/sign.d.ts} +0 -0
- /package/lib/{sign.js → api/sign.js} +0 -0
package/dist/api/private-api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAuDnC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE9C,MAAM,SAAS,GAAG,CAAC,UAAuB,EAAE,EAAE;IAC5C,IAAI,CAAC,WAAW,CAAC,GAAG,C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,GAAG,MAAM,CAAC,SAAS,CAAC;KAC1C;IAED,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE;QACnB,WAAW,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;KACtC;IAED,OAAO,OAAO,CAuBX,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["import { Wallet } from 'ethers';\nimport { signL1Action } from './sign';\nimport { request } from './client';\nimport { ICredential } from './types';\n\n/**\n * Order payload for placing orders on Hyperliquid\n */\ntype OrderPayload = {\n /** Asset index (absolute) */\n a: number;\n /** Buy flag (true for buy, false for sell) */\n b: boolean;\n /** Limit price string */\n p: string;\n /** Size string */\n s: string;\n /** Reduce only flag */\n r: boolean;\n /** Order type configuration */\n t: {\n /** Time in force for limit orders: \"Alo\" (Post-Only), \"Ioc\" (Immediate or Cancel), \"Gtc\" (Good til Cancel) */\n limit?: { tif: string };\n /** Trigger order configuration */\n trigger?: {\n /** Is market trigger price */\n isMarket: boolean;\n /** Trigger price string */\n triggerPx: string;\n /** Take profit/stop loss indicator */\n tpsl: string;\n };\n };\n /** Order fee coefficient */\n c?: number;\n};\n\n/**\n * Cancel order payload\n */\ntype CancelPayload = {\n /** Asset index (absolute) */\n a: number;\n /** Order ID */\n o: number;\n};\n\n/**\n * Modify order payload\n */\ntype ModifyOrderPayload = {\n /** Order ID to modify */\n oid: number | string;\n /** New order parameters */\n order: OrderPayload;\n};\n\nconst walletCache = new Map<string, Wallet>();\n\nconst getWallet = (credential: ICredential) => {\n if (!walletCache.has(credential.private_key)) {\n walletCache.set(credential.private_key, new Wallet(credential.private_key));\n }\n return walletCache.get(credential.private_key)!;\n};\n\n/**\n * Place orders on Hyperliquid exchange\n * API Docs: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order\n * API Endpoint: POST /exchange\n * @param credential - User credential containing private key for signing\n * @param params - Order placement parameters\n * @returns Promise resolving to exchange response\n */\nexport const placeOrder = async (\n credential: ICredential,\n params: {\n orders: OrderPayload[];\n builder?: { b: string; f: number };\n vaultAddress?: string;\n expiresAfter?: number;\n },\n) => {\n const action: Record<string, any> = {\n type: 'order',\n orders: params.orders,\n grouping: 'na',\n };\n if (params.builder) {\n action['builder'] = params.builder;\n }\n const nonce = Date.now();\n const signature = await signL1Action(\n getWallet(credential),\n action,\n params.vaultAddress ?? null,\n nonce,\n params.expiresAfter ?? null,\n true,\n );\n return request('POST', 'exchange', { action, nonce, signature });\n};\n\n/**\n * Cancel orders on Hyperliquid exchange\n * API Docs: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s\n * API Endpoint: POST /exchange\n * @param credential - User credential containing private key for signing\n * @param params - Order cancellation parameters\n * @returns Promise resolving to exchange response\n */\nexport const cancelOrder = async (\n credential: ICredential,\n params: { cancels: CancelPayload[]; vaultAddress?: string; expiresAfter?: number },\n) => {\n const action: Record<string, any> = {\n type: 'cancel',\n cancels: params.cancels,\n };\n const nonce = Date.now();\n const signature = await signL1Action(\n getWallet(credential),\n action,\n params.vaultAddress ?? null,\n nonce,\n params.expiresAfter ?? null,\n true,\n );\n return request('POST', 'exchange', { action, nonce, signature });\n};\n\n/**\n * Modify an existing order on Hyperliquid exchange\n * API Endpoint: POST /exchange\n * @param credential - User credential containing private key for signing\n * @param params - Order modification parameters\n * @returns Promise resolving to exchange response\n */\nexport const modifyOrder = async (\n credential: ICredential,\n params: {\n oid: number | string;\n order: OrderPayload;\n vaultAddress?: string;\n expiresAfter?: number;\n },\n) => {\n const action: Record<string, any> = {\n type: 'modify',\n oid: params.oid,\n order: params.order,\n };\n const nonce = Date.now();\n const signature = await signL1Action(\n getWallet(credential),\n action,\n params.vaultAddress ?? null,\n nonce,\n params.expiresAfter ?? null,\n true,\n );\n return request('POST', 'exchange', { action, nonce, signature });\n};\n\n/**\n * Get user's fill history (trade history) from Hyperliquid\n * API Endpoint: POST /info (type: userFills)\n * @param credential - User credential containing private key for authentication\n * @param params - Optional time range parameters\n * @returns Promise resolving to user fill history with detailed trade information\n */\nexport const getUserFills = async (\n credential: ICredential,\n params?: { startTime?: number; endTime?: number },\n) => {\n const wallet = getWallet(credential);\n const address = wallet.address;\n\n const requestBody: any = {\n type: 'userFills',\n user: address,\n };\n\n if (params?.startTime) {\n requestBody.startTime = params.startTime;\n }\n\n if (params?.endTime) {\n requestBody.endTime = params.endTime;\n }\n\n return request<{\n fills: {\n time: number;\n feedId: string;\n hash: string;\n coin: string;\n side: string;\n px: string;\n sz: string;\n oid: number;\n startPos: string;\n fee: string;\n feeToken: string;\n closedSize: string;\n closedPnl: string;\n dir: string;\n source: string;\n type: string;\n positionAction: string;\n asset: number;\n tid: string;\n crossChain: any;\n }[];\n }>('POST', 'info', requestBody);\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.js","sourceRoot":"","sources":["../../src/api/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AA4B3C,SAAS,cAAc,CAAC,OAAe;IACrC,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC3E,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,UAAU,CACjB,MAAW,EACX,YAA2B,EAC3B,KAAa,EACb,YAA2B;IAE3B,IAAI,IAAI,GAAQ,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAE/C,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,IA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AC,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAErG,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC1C,MAAM,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAElD,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACrB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAc,EACd,MAAW,EACX,UAAyB,EACzB,KAAa,EACb,YAA2B,EAC3B,SAAkB;IAElB,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;IACjE,MAAM,YAAY,GAAG,qBAAqB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IACrC,OAAO,MAAM,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,qBAAqB,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { encode } from '@msgpack/msgpack';\nimport { keccak256, Wallet } from 'ethers';\n\ninterface PhantomAgent {\n source: string;\n connectionId: string;\n}\n\ninterface L1Payload {\n domain: {\n chainId: number;\n name: string;\n verifyingContract: string;\n version: string;\n };\n types: {\n Agent: Array<{ name: string; type: string }>;\n EIP712Domain: Array<{ name: string; type: string }>;\n };\n primaryType: string;\n message: PhantomAgent;\n}\n\ninterface Signature {\n r: string;\n s: string;\n v: number;\n}\n\nfunction addressToBytes(address: string): Uint8Array {\n const cleanAddress = address.startsWith('0x') ? address.slice(2) : address;\n return new Uint8Array(Buffer.from(cleanAddress, 'hex'));\n}\n\nfunction actionHash(\n action: any,\n vaultAddress: string | null,\n nonce: number,\n expiresAfter: number | null,\n): string {\n let data: any = new Uint8Array(encode(action));\n\n const nonceBytes = new Uint8Array(8);\n const nonceView = new DataView(nonceBytes.buffer);\n nonceView.setBigUint64(0, BigInt(nonce), false); // false = big endian\n data = concatUint8Arrays(data, nonceBytes);\n\n if (vaultAddress == null) {\n data = concatUint8Arrays(data, new Uint8Array([0x00]));\n } else {\n data = concatUint8Arrays(data, new Uint8Array([0x01]));\n data = concatUint8Arrays(data, addressToBytes(vaultAddress));\n }\n if (expiresAfter != null) {\n data = concatUint8Arrays(data, new Uint8Array([0x00]));\n const expiresBytes = new Uint8Array(8);\n const expiresView = new DataView(expiresBytes.buffer);\n expiresView.setBigUint64(0, BigInt(expiresAfter), false); // false = big endian\n data = concatUint8Arrays(data, expiresBytes);\n }\n\n return keccak256(data);\n}\n\nfunction concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n\n for (const arr of arrays) {\n result.set(arr, offset);\n offset += arr.length;\n }\n\n return result;\n}\n\nfunction constructPhantomAgent(hash: string, isMainnet: boolean): PhantomAgent {\n return {\n source: isMainnet ? 'a' : 'b',\n connectionId: hash,\n };\n}\n\nfunction l1Payload(phantomAgent: PhantomAgent): L1Payload {\n return {\n domain: {\n chainId: 1337,\n name: 'Exchange',\n verifyingContract: '0x0000000000000000000000000000000000000000',\n version: '1',\n },\n types: {\n Agent: [\n { name: 'source', type: 'string' },\n { name: 'connectionId', type: 'bytes32' },\n ],\n EIP712Domain: [\n { name: 'name', type: 'string' },\n { name: 'version', type: 'string' },\n { name: 'chainId', type: 'uint256' },\n { name: 'verifyingContract', type: 'address' },\n ],\n },\n primaryType: 'Agent',\n message: phantomAgent,\n };\n}\n\nasync function signInner(wallet: Wallet, data: L1Payload): Promise<Signature> {\n const signature = await wallet.signTypedData(data.domain, { Agent: data.types.Agent }, data.message);\n\n const r = signature.slice(0, 66);\n const s = '0x' + signature.slice(66, 130);\n const v = parseInt(signature.slice(130, 132), 16);\n\n return { r, s, v };\n}\n\n/**\n * 签署 L1 动作\n *\n * @param wallet - 以太坊钱包实例\n * @param action - 要签署的动作数据\n * @param activePool - 活跃池地址(可以为 null)\n * @param nonce - 随机数\n * @param expiresAfter - 过期时间(可以为 null)\n * @param isMainnet - 是否为主网\n * @returns 签名对象\n */\nexport async function signL1Action(\n wallet: Wallet,\n action: any,\n activePool: string | null,\n nonce: number,\n expiresAfter: number | null,\n isMainnet: boolean,\n): Promise<Signature> {\n const hash = actionHash(action, activePool, nonce, expiresAfter);\n const phantomAgent = constructPhantomAgent(hash, isMainnet);\n const data = l1Payload(phantomAgent);\n return await signInner(wallet, data);\n}\n\nexport { actionHash, addressToBytes, constructPhantomAgent, l1Payload };\n"]}
|
package/dist/api/types.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { Wallet } from 'ethers';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param credential 凭证对象
|
|
5
|
-
* @returns 钱包地址
|
|
3
|
+
* 获取凭证唯一标识
|
|
6
4
|
*/
|
|
7
|
-
export const
|
|
8
|
-
const wallet = new Wallet(credential.private_key);
|
|
9
|
-
return wallet.address;
|
|
10
|
-
};
|
|
5
|
+
export const getCredentialId = (credential) => `HYPERLIQUID/${credential.address.toLowerCase()}`;
|
|
11
6
|
/**
|
|
12
7
|
* 创建凭证对象
|
|
13
8
|
* @param private_key 私钥
|
|
14
9
|
* @returns 凭证对象
|
|
15
10
|
*/
|
|
16
11
|
export const createCredential = (private_key) => {
|
|
17
|
-
|
|
12
|
+
const wallet = new Wallet(private_key);
|
|
13
|
+
return { private_key, address: wallet.address };
|
|
18
14
|
};
|
|
19
15
|
/**
|
|
20
16
|
* 获取默认凭证(从环境变量)
|
package/dist/api/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAWhC;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAAuB,EAAU,EAAE,CACjE,eAAe,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AAEpD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,WAAmB,EAAe,EAAE;IACnE,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;IACvC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;AAClD,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAgB,EAAE;IACpD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAC5C,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;KAC5E;IACD,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACvC,CAAC,CAAC","sourcesContent":["import { Wallet } from 'ethers';\n\n/**\n * Hyperliquid 凭证接口\n * 仅包含核心数据,行为方法通过辅助函数提供\n */\nexport interface ICredential {\n private_key: string;\n address: string;\n}\n\n/**\n * 获取凭证唯一标识\n */\nexport const getCredentialId = (credential: ICredential): string =>\n `HYPERLIQUID/${credential.address.toLowerCase()}`;\n\n/**\n * 创建凭证对象\n * @param private_key 私钥\n * @returns 凭证对象\n */\nexport const createCredential = (private_key: string): ICredential => {\n const wallet = new Wallet(private_key);\n return { private_key, address: wallet.address };\n};\n\n/**\n * 获取默认凭证(从环境变量)\n * @returns 默认凭证对象\n */\nexport const getDefaultCredential = (): ICredential => {\n const private_key = process.env.PRIVATE_KEY;\n if (!private_key) {\n throw new Error('Missing Hyperliquid credential: PRIVATE_KEY must be set');\n }\n return createCredential(private_key);\n};\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import './services/account-actions-with-credential';
|
|
3
|
-
import './services/legacy';
|
|
1
|
+
import './services/exchange';
|
|
4
2
|
import './services/markets/interest-rate';
|
|
5
3
|
import './services/markets/ohlc';
|
|
6
4
|
import './services/markets/product';
|
|
7
5
|
import './services/markets/quote';
|
|
8
|
-
import './services/order-actions-with-credential';
|
|
9
|
-
import './services/orders/cancelOrder';
|
|
10
|
-
import './services/orders/modifyOrder';
|
|
11
|
-
import './services/orders/submitOrder';
|
|
12
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,kCAAkC,CAAC;AAC1C,OAAO,yBAAyB,CAAC;AACjC,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC","sourcesContent":["import './services/exchange';\nimport './services/markets/interest-rate';\nimport './services/markets/ohlc';\nimport './services/markets/product';\nimport './services/markets/quote';\n"]}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { encodePath, formatTime } from '@yuants/utils';
|
|
2
2
|
import { getUserPerpetualsAccountSummary } from '../../api/public-api';
|
|
3
|
-
import { getAddressFromCredential } from '../../api/types';
|
|
4
3
|
/**
|
|
5
4
|
* Get account info for perpetual account
|
|
6
5
|
*/
|
|
7
|
-
export const
|
|
8
|
-
console.info(`[${formatTime(Date.now())}] Getting perp account info for ${
|
|
9
|
-
const summary = await getUserPerpetualsAccountSummary({ user:
|
|
6
|
+
export const getPerpPositions = async (credential) => {
|
|
7
|
+
console.info(`[${formatTime(Date.now())}] Getting perp account info for ${credential.address}`);
|
|
8
|
+
const summary = await getUserPerpetualsAccountSummary({ user: credential.address });
|
|
10
9
|
// Map positions
|
|
11
10
|
const positions = summary.assetPositions.map((position) => ({
|
|
12
11
|
position_id: `${position.position.coin}-USD`,
|
|
13
12
|
datasource_id: 'HYPERLIQUID',
|
|
14
|
-
product_id: encodePath('PERPETUAL', `${position.position.coin}-USD`),
|
|
13
|
+
product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${position.position.coin}-USD`),
|
|
15
14
|
direction: +position.position.szi > 0 ? 'LONG' : 'SHORT',
|
|
16
15
|
volume: Math.abs(+position.position.szi),
|
|
17
16
|
free_volume: Math.abs(+position.position.szi),
|
|
@@ -21,17 +20,6 @@ export const getPerpAccountInfo = async (credential, account_id) => {
|
|
|
21
20
|
valuation: +position.position.positionValue,
|
|
22
21
|
margin: +position.position.marginUsed,
|
|
23
22
|
}));
|
|
24
|
-
// Map orders
|
|
25
|
-
const mapOrderDirection = (side) => {
|
|
26
|
-
const normalized = side.toUpperCase();
|
|
27
|
-
if (normalized === 'BID' || normalized === 'BUY') {
|
|
28
|
-
return 'OPEN_LONG';
|
|
29
|
-
}
|
|
30
|
-
if (normalized === 'ASK' || normalized === 'SELL') {
|
|
31
|
-
return 'OPEN_SHORT';
|
|
32
|
-
}
|
|
33
|
-
return 'OPEN_LONG';
|
|
34
|
-
};
|
|
35
23
|
return positions;
|
|
36
24
|
};
|
|
37
25
|
//# sourceMappingURL=perp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perp.js","sourceRoot":"","sources":["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GAAG,CAAC;QAC7C,cAAc,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO;QAC1C,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;QACxF,eAAe,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa;QACjD,SAAS,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa;QAC3C,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU;KACtC,CAAC,CACH,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { getUserPerpetualsAccountSummary } from '../../api/public-api';\nimport { ICredential } from '../../api/types';\n\n/**\n * Get account info for perpetual account\n */\nexport const getPerpPositions = async (credential: ICredential) => {\n console.info(`[${formatTime(Date.now())}] Getting perp account info for ${credential.address}`);\n\n const summary = await getUserPerpetualsAccountSummary({ user: credential.address });\n\n // Map positions\n const positions = summary.assetPositions.map(\n (position): IPosition => ({\n position_id: `${position.position.coin}-USD`,\n datasource_id: 'HYPERLIQUID',\n product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${position.position.coin}-USD`),\n direction: +position.position.szi > 0 ? 'LONG' : 'SHORT',\n volume: Math.abs(+position.position.szi),\n free_volume: Math.abs(+position.position.szi),\n position_price: +position.position.entryPx,\n closable_price: Math.abs(+position.position.positionValue / +position.position.szi || 0),\n floating_profit: +position.position.unrealizedPnl,\n valuation: +position.position.positionValue,\n margin: +position.position.marginUsed,\n }),\n );\n\n return positions;\n};\n"]}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { makeSpotPosition } from '@yuants/data-account';
|
|
2
2
|
import { encodePath, formatTime } from '@yuants/utils';
|
|
3
3
|
import { getUserTokenBalances } from '../../api/public-api';
|
|
4
|
-
import { getAddressFromCredential } from '../../api/types';
|
|
5
4
|
/**
|
|
6
5
|
* Get account info for spot account
|
|
7
6
|
*/
|
|
8
|
-
export const
|
|
9
|
-
console.info(`[${formatTime(Date.now())}] Getting spot account info for ${
|
|
10
|
-
const balances = await getUserTokenBalances({ user:
|
|
7
|
+
export const getSpotPositions = async (credential) => {
|
|
8
|
+
console.info(`[${formatTime(Date.now())}] Getting spot account info for ${credential.address}`);
|
|
9
|
+
const balances = await getUserTokenBalances({ user: credential.address });
|
|
11
10
|
// Map token balances to positions (using spot as "positions")
|
|
12
11
|
const positions = balances.balances
|
|
13
12
|
.filter((balance) => Number(balance.total) > 0)
|
|
14
13
|
.map((balance) => makeSpotPosition({
|
|
15
14
|
position_id: `${balance.coin}`,
|
|
16
15
|
datasource_id: 'HYPERLIQUID',
|
|
17
|
-
product_id: encodePath('SPOT', `${balance.coin}-USDC`),
|
|
16
|
+
product_id: encodePath('HYPERLIQUID', 'SPOT', `${balance.coin}-USDC`),
|
|
18
17
|
volume: Number(balance.total),
|
|
19
18
|
free_volume: Number(balance.total) - Number(balance.hold),
|
|
20
19
|
closable_price: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAChE,OAAO,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,mCAAmC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAEhG,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAE1E,8DAA8D;IAC9D,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ;SAChC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAC9C,GAAG,CACF,CAAC,OAAO,EAAa,EAAE,CACrB,gBAAgB,CAAC;QACf,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE;QAC9B,aAAa,EAAE,aAAa;QAC5B,UAAU,EAAE,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,OAAO,CAAC;QACrE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QAC7B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;QACzD,cAAc,EAAE,CAAC;KAClB,CAAC,CACL,CAAC;IAEJ,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { getUserTokenBalances } from '../../api/public-api';\nimport { ICredential } from '../../api/types';\n\n/**\n * Get account info for spot account\n */\nexport const getSpotPositions = async (credential: ICredential) => {\n console.info(`[${formatTime(Date.now())}] Getting spot account info for ${credential.address}`);\n\n const balances = await getUserTokenBalances({ user: credential.address });\n\n // Map token balances to positions (using spot as \"positions\")\n const positions = balances.balances\n .filter((balance) => Number(balance.total) > 0)\n .map(\n (balance): IPosition =>\n makeSpotPosition({\n position_id: `${balance.coin}`,\n datasource_id: 'HYPERLIQUID',\n product_id: encodePath('HYPERLIQUID', 'SPOT', `${balance.coin}-USDC`),\n volume: Number(balance.total),\n free_volume: Number(balance.total) - Number(balance.hold),\n closable_price: 1,\n }),\n );\n\n return positions;\n};\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { provideExchangeServices } from '@yuants/exchange';
|
|
2
|
+
import { Terminal } from '@yuants/protocol';
|
|
3
|
+
import { decodePath, formatTime } from '@yuants/utils';
|
|
4
|
+
import { getCredentialId as getCredentialIdFromCredential } from '../api/types';
|
|
5
|
+
import { listProducts } from './markets/product';
|
|
6
|
+
import { getPerpPositions } from './accounts/perp';
|
|
7
|
+
import { getSpotPositions } from './accounts/spot';
|
|
8
|
+
import { cancelOrderAction } from './orders/cancelOrder';
|
|
9
|
+
import { listOrdersByProductId, listPerpOrders } from './orders/listOrders';
|
|
10
|
+
import { modifyOrder } from './orders/modifyOrder';
|
|
11
|
+
import { submitOrder } from './orders/submitOrder';
|
|
12
|
+
const terminal = Terminal.fromNodeEnv();
|
|
13
|
+
const ensureHyperliquidProduct = (product_id) => {
|
|
14
|
+
if (!product_id) {
|
|
15
|
+
throw new Error('product_id is required');
|
|
16
|
+
}
|
|
17
|
+
const [exchange, instType] = decodePath(product_id);
|
|
18
|
+
if (exchange !== 'HYPERLIQUID') {
|
|
19
|
+
throw new Error(`product_id must start with HYPERLIQUID, got ${product_id}`);
|
|
20
|
+
}
|
|
21
|
+
if (instType !== 'PERPETUAL') {
|
|
22
|
+
throw new Error(`Hyperliquid only supports PERPETUAL orders for now: ${product_id}`);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
provideExchangeServices(terminal, {
|
|
26
|
+
name: 'HYPERLIQUID',
|
|
27
|
+
credentialSchema: {
|
|
28
|
+
type: 'object',
|
|
29
|
+
required: ['private_key', 'address'],
|
|
30
|
+
properties: {
|
|
31
|
+
private_key: { type: 'string' },
|
|
32
|
+
address: { type: 'string' },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
getCredentialId: async (credential) => getCredentialIdFromCredential(credential),
|
|
36
|
+
listProducts,
|
|
37
|
+
getPositions: async (credential) => {
|
|
38
|
+
console.info(`[${formatTime(Date.now())}] Fetching positions for ${getCredentialIdFromCredential(credential)}`);
|
|
39
|
+
const [perpPositions, spotPositions] = await Promise.all([
|
|
40
|
+
getPerpPositions(credential),
|
|
41
|
+
getSpotPositions(credential),
|
|
42
|
+
]);
|
|
43
|
+
return [...perpPositions, ...spotPositions];
|
|
44
|
+
},
|
|
45
|
+
getPositionsByProductId: async (credential, product_id) => {
|
|
46
|
+
const [exchange, instType] = decodePath(product_id);
|
|
47
|
+
if (exchange !== 'HYPERLIQUID') {
|
|
48
|
+
throw new Error(`Invalid product_id for Hyperliquid: ${product_id}`);
|
|
49
|
+
}
|
|
50
|
+
if (instType === 'PERPETUAL') {
|
|
51
|
+
const perpPositions = await getPerpPositions(credential);
|
|
52
|
+
return perpPositions.filter((position) => position.product_id === product_id);
|
|
53
|
+
}
|
|
54
|
+
if (instType === 'SPOT') {
|
|
55
|
+
const spotPositions = await getSpotPositions(credential);
|
|
56
|
+
return spotPositions.filter((position) => position.product_id === product_id);
|
|
57
|
+
}
|
|
58
|
+
return [];
|
|
59
|
+
},
|
|
60
|
+
getOrders: async (credential) => {
|
|
61
|
+
return listPerpOrders(credential);
|
|
62
|
+
},
|
|
63
|
+
getOrdersByProductId: async (credential, product_id) => {
|
|
64
|
+
return listOrdersByProductId(credential, product_id);
|
|
65
|
+
},
|
|
66
|
+
submitOrder: async (credential, order) => {
|
|
67
|
+
ensureHyperliquidProduct(order.product_id);
|
|
68
|
+
return submitOrder(credential, order);
|
|
69
|
+
},
|
|
70
|
+
modifyOrder: async (credential, order) => {
|
|
71
|
+
ensureHyperliquidProduct(order.product_id);
|
|
72
|
+
return modifyOrder(credential, order);
|
|
73
|
+
},
|
|
74
|
+
cancelOrder: async (credential, order) => {
|
|
75
|
+
ensureHyperliquidProduct(order.product_id);
|
|
76
|
+
return cancelOrderAction(credential, order);
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=exchange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAe,eAAe,IAAI,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,wBAAwB,GAAG,CAAC,UAAmB,EAAE,EAAE;IACvD,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;KAC3C;IACD,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACpD,IAAI,QAAQ,KAAK,aAAa,EAAE;QAC9B,MAAM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AC9C,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { ICredential, getCredentialId as getCredentialIdFromCredential } from '../api/types';\nimport { listProducts } from './markets/product';\nimport { getPerpPositions } from './accounts/perp';\nimport { getSpotPositions } from './accounts/spot';\nimport { cancelOrderAction } from './orders/cancelOrder';\nimport { listOrdersByProductId, listPerpOrders } from './orders/listOrders';\nimport { modifyOrder } from './orders/modifyOrder';\nimport { submitOrder } from './orders/submitOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst ensureHyperliquidProduct = (product_id?: string) => {\n if (!product_id) {\n throw new Error('product_id is required');\n }\n const [exchange, instType] = decodePath(product_id);\n if (exchange !== 'HYPERLIQUID') {\n throw new Error(`product_id must start with HYPERLIQUID, got ${product_id}`);\n }\n if (instType !== 'PERPETUAL') {\n throw new Error(`Hyperliquid only supports PERPETUAL orders for now: ${product_id}`);\n }\n};\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'HYPERLIQUID',\n credentialSchema: {\n type: 'object',\n required: ['private_key', 'address'],\n properties: {\n private_key: { type: 'string' },\n address: { type: 'string' },\n },\n },\n getCredentialId: async (credential) => getCredentialIdFromCredential(credential),\n listProducts,\n getPositions: async (credential: ICredential): Promise<IPosition[]> => {\n console.info(\n `[${formatTime(Date.now())}] Fetching positions for ${getCredentialIdFromCredential(credential)}`,\n );\n const [perpPositions, spotPositions] = await Promise.all([\n getPerpPositions(credential),\n getSpotPositions(credential),\n ]);\n return [...perpPositions, ...spotPositions];\n },\n getPositionsByProductId: async (credential: ICredential, product_id: string): Promise<IPosition[]> => {\n const [exchange, instType] = decodePath(product_id);\n if (exchange !== 'HYPERLIQUID') {\n throw new Error(`Invalid product_id for Hyperliquid: ${product_id}`);\n }\n if (instType === 'PERPETUAL') {\n const perpPositions = await getPerpPositions(credential);\n return perpPositions.filter((position) => position.product_id === product_id);\n }\n if (instType === 'SPOT') {\n const spotPositions = await getSpotPositions(credential);\n return spotPositions.filter((position) => position.product_id === product_id);\n }\n return [];\n },\n getOrders: async (credential: ICredential): Promise<IOrder[]> => {\n return listPerpOrders(credential);\n },\n getOrdersByProductId: async (credential: ICredential, product_id: string): Promise<IOrder[]> => {\n return listOrdersByProductId(credential, product_id);\n },\n submitOrder: async (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n ensureHyperliquidProduct(order.product_id);\n return submitOrder(credential, order);\n },\n modifyOrder: async (credential: ICredential, order: IOrder): Promise<void> => {\n ensureHyperliquidProduct(order.product_id);\n return modifyOrder(credential, order);\n },\n cancelOrder: async (credential: ICredential, order: IOrder): Promise<void> => {\n ensureHyperliquidProduct(order.product_id);\n return cancelOrderAction(credential, order);\n },\n});\n"]}
|
|
@@ -20,14 +20,14 @@ const terminal = Terminal.fromNodeEnv();
|
|
|
20
20
|
const perpetualProducts$ = defer(async () => {
|
|
21
21
|
const meta = await getPerpetualsMetaData();
|
|
22
22
|
return meta.universe.map((product) => ({
|
|
23
|
-
product_id: encodePath('PERPETUAL', `${product.name}-USD`),
|
|
23
|
+
product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${product.name}-USD`),
|
|
24
24
|
datasource_id: 'HYPERLIQUID',
|
|
25
25
|
no_interest_rate: false,
|
|
26
26
|
}));
|
|
27
27
|
}).pipe(tap({ error: (err) => console.error(formatTime(Date.now()), 'PerpetualProductFetchFailed', err) }), retry({ delay: 10000 }), repeat({ delay: 3600000 }), shareReplay({ bufferSize: 1, refCount: true }));
|
|
28
28
|
createSQLWriter(terminal, {
|
|
29
29
|
data$: perpetualProducts$.pipe(map((products) => products.filter((product) => product.no_interest_rate === false)), mergeAll(), map((product) => ({
|
|
30
|
-
series_id:
|
|
30
|
+
series_id: product.product_id,
|
|
31
31
|
table_name: 'interest_rate',
|
|
32
32
|
cron_pattern: '0 * * * *',
|
|
33
33
|
cron_timezone: 'UTC',
|
|
@@ -44,12 +44,18 @@ createSeriesProvider(terminal, {
|
|
|
44
44
|
reversed: true,
|
|
45
45
|
serviceOptions: { concurrent: 1 },
|
|
46
46
|
queryFn: function ({ series_id, started_at, ended_at }) {
|
|
47
|
+
var _a;
|
|
47
48
|
return __asyncGenerator(this, arguments, function* () {
|
|
48
49
|
const start = started_at || 0;
|
|
49
50
|
const end = ended_at || Date.now();
|
|
50
|
-
const [datasource_id,
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const [datasource_id, , instId] = decodePath(series_id);
|
|
52
|
+
if (datasource_id !== 'HYPERLIQUID') {
|
|
53
|
+
throw new Error(`Invalid datasource: ${datasource_id}`);
|
|
54
|
+
}
|
|
55
|
+
const coin = (_a = instId === null || instId === void 0 ? void 0 : instId.split('-')) === null || _a === void 0 ? void 0 : _a[0];
|
|
56
|
+
if (!coin) {
|
|
57
|
+
throw new Error(`Invalid product in series_id: ${series_id}`);
|
|
58
|
+
}
|
|
53
59
|
let current = start;
|
|
54
60
|
while (current <= end) {
|
|
55
61
|
const res = yield __await(getHistoricalFundingRates({ coin, startTime: current, endTime: end }));
|
|
@@ -62,8 +68,8 @@ createSeriesProvider(terminal, {
|
|
|
62
68
|
}
|
|
63
69
|
yield yield __await(filtered.map((v) => ({
|
|
64
70
|
series_id,
|
|
65
|
-
product_id,
|
|
66
|
-
datasource_id,
|
|
71
|
+
product_id: series_id,
|
|
72
|
+
datasource_id: 'HYPERLIQUID',
|
|
67
73
|
created_at: formatTime(v.time),
|
|
68
74
|
long_rate: `${-parseFloat(v.fundingRate)}`,
|
|
69
75
|
short_rate: `${v.fundingRate}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interest-rate.js","sourceRoot":"","sources":["../../../src/services/markets/interest-rate.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAyB,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAA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AAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;gBACvE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;oBACpB,MAAM;iBACP;gBACD,oBAAM,QAAQ,CAAC,GAAG,CAChB,CAAC,CAAC,EAAiB,EAAE,CAAC,CAAC;oBACrB,SAAS;oBACT,UAAU,EAAE,SAAS;oBACrB,aAAa,EAAE,aAAa;oBAC5B,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;oBAC9B,SAAS,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE;oBAC1C,UAAU,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE;oBAC9B,gBAAgB,EAAE,EAAE;iBACrB,CAAC,CACH,CAAA,CAAC;gBACF,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE;oBACpB,MAAM;iBACP;gBACD,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;aAClD;;KACF;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { createSeriesProvider, ISeriesCollectingTask } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { defer, map, mergeAll, repeat, retry, shareReplay, tap } from 'rxjs';\nimport { getHistoricalFundingRates, getPerpetualsMetaData } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst perpetualProducts$ = defer(async () => {\n const meta = await getPerpetualsMetaData();\n return meta.universe.map((product) => ({\n product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${product.name}-USD`),\n datasource_id: 'HYPERLIQUID',\n no_interest_rate: false,\n }));\n}).pipe(\n tap({ error: (err) => console.error(formatTime(Date.now()), 'PerpetualProductFetchFailed', err) }),\n retry({ delay: 10_000 }),\n repeat({ delay: 3600_000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\ncreateSQLWriter<ISeriesCollectingTask>(terminal, {\n data$: perpetualProducts$.pipe(\n map((products) => products.filter((product) => product.no_interest_rate === false)),\n mergeAll(),\n map(\n (product): ISeriesCollectingTask => ({\n series_id: product.product_id,\n table_name: 'interest_rate',\n cron_pattern: '0 * * * *',\n cron_timezone: 'UTC',\n disabled: false,\n replay_count: 0,\n }),\n ),\n ),\n tableName: 'series_collecting_task',\n writeInterval: 1000,\n conflictKeys: ['series_id', 'table_name'],\n});\n\ncreateSeriesProvider<IInterestRate>(terminal, {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['HYPERLIQUID'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, started_at, ended_at }) {\n const start = started_at || 0;\n const end = ended_at || Date.now();\n const [datasource_id, , instId] = decodePath(series_id);\n if (datasource_id !== 'HYPERLIQUID') {\n throw new Error(`Invalid datasource: ${datasource_id}`);\n }\n const coin = instId?.split('-')?.[0];\n if (!coin) {\n throw new Error(`Invalid product in series_id: ${series_id}`);\n }\n let current = start;\n while (current <= end) {\n const res = await getHistoricalFundingRates({ coin, startTime: current, endTime: end });\n if (!res || res.length === 0) {\n break;\n }\n const filtered = res.filter((v) => v.time >= current && v.time <= end);\n if (!filtered.length) {\n break;\n }\n yield filtered.map(\n (v): IInterestRate => ({\n series_id,\n product_id: series_id,\n datasource_id: 'HYPERLIQUID',\n created_at: formatTime(v.time),\n long_rate: `${-parseFloat(v.fundingRate)}`,\n short_rate: `${v.fundingRate}`,\n settlement_price: '',\n }),\n );\n if (res.length < 500) {\n break;\n }\n current = filtered[filtered.length - 1].time + 1;\n }\n },\n});\n"]}
|
|
@@ -12,7 +12,7 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
12
12
|
};
|
|
13
13
|
import { createSeriesProvider } from '@yuants/data-series';
|
|
14
14
|
import { Terminal } from '@yuants/protocol';
|
|
15
|
-
import { decodePath, formatTime } from '@yuants/utils';
|
|
15
|
+
import { decodePath, encodePath, formatTime } from '@yuants/utils';
|
|
16
16
|
import { getCandleSnapshot } from '../../api/public-api';
|
|
17
17
|
const terminal = Terminal.fromNodeEnv();
|
|
18
18
|
const DURATION_TO_HYPERLIQUID_INTERVAL = {
|
|
@@ -53,17 +53,21 @@ createSeriesProvider(terminal, {
|
|
|
53
53
|
reversed: true,
|
|
54
54
|
serviceOptions: { concurrent: 1 },
|
|
55
55
|
queryFn: function ({ series_id, ended_at }) {
|
|
56
|
+
var _a;
|
|
56
57
|
return __asyncGenerator(this, arguments, function* () {
|
|
57
|
-
const [datasource_id,
|
|
58
|
+
const [datasource_id, instType, symbol, duration] = decodePath(series_id);
|
|
59
|
+
const product_id = encodePath(datasource_id, instType, symbol);
|
|
58
60
|
const period_in_sec = DURATION_TO_PERIOD_IN_SEC[duration];
|
|
59
|
-
if (!datasource_id || !
|
|
61
|
+
if (!datasource_id || !instType || !symbol || !duration || !period_in_sec) {
|
|
60
62
|
throw new Error(`Invalid series_id: ${series_id}`);
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
if (datasource_id !== 'HYPERLIQUID') {
|
|
65
|
+
throw new Error(`Invalid datasource for series_id: ${series_id}`);
|
|
66
|
+
}
|
|
67
|
+
const coin = (_a = symbol === null || symbol === void 0 ? void 0 : symbol.split('-')) === null || _a === void 0 ? void 0 : _a[0];
|
|
68
|
+
if (!coin) {
|
|
69
|
+
throw new Error(`Invalid product symbol: ${symbol}`);
|
|
65
70
|
}
|
|
66
|
-
const coin = instId.split('-')[0];
|
|
67
71
|
const interval = DURATION_TO_HYPERLIQUID_INTERVAL[duration];
|
|
68
72
|
if (!interval) {
|
|
69
73
|
throw new Error(`Unsupported duration: ${duration}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ohlc.js","sourceRoot":"","sources":["../../../src/services/markets/ohlc.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"ohlc.js","sourceRoot":"","sources":["../../../src/services/markets/ohlc.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,gCAAgC,GAA2B;IAC/D,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;CACV,CAAC;AAEF,MAAM,yBAAyB,GAA2B;IACxD,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAA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C } from '@yuants/data-ohlc';\nimport { createSeriesProvider } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { getCandleSnapshot } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst DURATION_TO_HYPERLIQUID_INTERVAL: Record<string, string> = {\n PT1M: '1m',\n PT3M: '3m',\n PT5M: '5m',\n PT15M: '15m',\n PT30M: '30m',\n PT1H: '1h',\n PT2H: '2h',\n PT4H: '4h',\n PT8H: '8h',\n PT12H: '12h',\n P1D: '1d',\n P3D: '3d',\n P1W: '1w',\n P1M: '1M',\n};\n\nconst DURATION_TO_PERIOD_IN_SEC: Record<string, number> = {\n PT1M: 60,\n PT3M: 180,\n PT5M: 300,\n PT15M: 900,\n PT30M: 1800,\n PT1H: 3600,\n PT2H: 7200,\n PT4H: 14400,\n PT8H: 28800,\n PT12H: 43200,\n P1D: 86400,\n P3D: 259200,\n P1W: 604800,\n P1M: 2592000,\n};\n\ncreateSeriesProvider<IOHLC>(terminal, {\n tableName: 'ohlc',\n series_id_prefix_parts: ['HYPERLIQUID'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, ended_at }) {\n const [datasource_id, instType, symbol, duration] = decodePath(series_id);\n const product_id = encodePath(datasource_id, instType, symbol);\n const period_in_sec = DURATION_TO_PERIOD_IN_SEC[duration];\n if (!datasource_id || !instType || !symbol || !duration || !period_in_sec) {\n throw new Error(`Invalid series_id: ${series_id}`);\n }\n if (datasource_id !== 'HYPERLIQUID') {\n throw new Error(`Invalid datasource for series_id: ${series_id}`);\n }\n const coin = symbol?.split('-')?.[0];\n if (!coin) {\n throw new Error(`Invalid product symbol: ${symbol}`);\n }\n const interval = DURATION_TO_HYPERLIQUID_INTERVAL[duration];\n if (!interval) {\n throw new Error(`Unsupported duration: ${duration}`);\n }\n const startTime = 0;\n const res = await getCandleSnapshot({\n req: {\n coin,\n interval,\n startTime,\n endTime: ended_at,\n },\n });\n if (!res || !res.length) {\n return;\n }\n const data = res\n .filter((x) => x.t < ended_at)\n .map(\n (x): IOHLC => ({\n series_id,\n datasource_id,\n product_id,\n duration,\n created_at: formatTime(x.t),\n closed_at: formatTime(x.t + period_in_sec * 1000),\n open: x.o,\n high: x.h,\n low: x.l,\n close: x.c,\n volume: x.v,\n open_interest: '0',\n }),\n )\n .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());\n if (data.length > 0) {\n yield data;\n }\n },\n});\n"]}
|
|
@@ -7,10 +7,10 @@ import { getPerpetualsMetaData, getSpotMetaData } from '../../api/public-api';
|
|
|
7
7
|
const terminal = Terminal.fromNodeEnv();
|
|
8
8
|
const product$ = new Subject();
|
|
9
9
|
let latestProducts = [];
|
|
10
|
-
const
|
|
10
|
+
export const listProducts = async () => {
|
|
11
11
|
const [spotMetaData, perpetualsMetaData] = await Promise.all([getSpotMetaData(), getPerpetualsMetaData()]);
|
|
12
12
|
const spotProducts = spotMetaData.tokens.map((token) => ({
|
|
13
|
-
product_id: encodePath('SPOT', `${token.name}-USDC`),
|
|
13
|
+
product_id: encodePath('HYPERLIQUID', 'SPOT', `${token.name}-USDC`),
|
|
14
14
|
datasource_id: 'HYPERLIQUID',
|
|
15
15
|
quote_currency: 'USDC',
|
|
16
16
|
base_currency: token.name,
|
|
@@ -29,8 +29,8 @@ const fetchProducts = async () => {
|
|
|
29
29
|
market_id: 'HYPERLIQUID/SPOT',
|
|
30
30
|
no_interest_rate: true,
|
|
31
31
|
}));
|
|
32
|
-
const perpetualProducts = perpetualsMetaData.universe.map((product
|
|
33
|
-
product_id: encodePath('PERPETUAL', `${product.name}-USD`),
|
|
32
|
+
const perpetualProducts = perpetualsMetaData.universe.map((product) => ({
|
|
33
|
+
product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${product.name}-USD`),
|
|
34
34
|
datasource_id: 'HYPERLIQUID',
|
|
35
35
|
quote_currency: 'USD',
|
|
36
36
|
base_currency: product.name,
|
|
@@ -51,7 +51,7 @@ const fetchProducts = async () => {
|
|
|
51
51
|
}));
|
|
52
52
|
return [...spotProducts, ...perpetualProducts];
|
|
53
53
|
};
|
|
54
|
-
const refresh$ = defer(
|
|
54
|
+
const refresh$ = defer(listProducts).pipe(tap((products) => {
|
|
55
55
|
latestProducts = products;
|
|
56
56
|
products.forEach((product) => product$.next(product));
|
|
57
57
|
}), tap({
|
|
@@ -66,7 +66,7 @@ createSQLWriter(terminal, {
|
|
|
66
66
|
});
|
|
67
67
|
provideQueryProductsService(terminal, 'HYPERLIQUID', async (_req) => {
|
|
68
68
|
if (!latestProducts.length) {
|
|
69
|
-
latestProducts = await
|
|
69
|
+
latestProducts = await listProducts();
|
|
70
70
|
}
|
|
71
71
|
return latestProducts;
|
|
72
72
|
}, { auto_refresh_interval: 86400000 });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE9E,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAY,CAAC;AACzC,IAAI,cAAc,GAAe,EAAE,CAAC;AAEpC,MAAM,
|
|
1
|
+
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"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AAC,CAAC,EACF,GAAG,CAAC;IACF,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,sBAAsB,EAAE,GAAG,CAAC;CACnF,CAAC,EACF,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACtB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAS,EAAE,CAAC,EAC5B,WAAW,CAAC,CAAC,CAAC,CACf,CAAC;AAEF,QAAQ,CAAC,SAAS,EAAE,CAAC;AAErB,eAAe,CAAW,QAAQ,EAAE;IAClC,KAAK,EAAE,QAAQ;IACf,SAAS,EAAE,SAAS;IACpB,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC;CAC9C,CAAC,CAAC;AAEH,2BAA2B,CACzB,QAAQ,EACR,aAAa,EACb,KAAK,EAAE,IAA2B,EAAE,EAAE;IACpC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE;QAC1B,cAAc,GAAG,MAAM,YAAY,EAAE,CAAC;KACvC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC,EACD,EAAE,qBAAqB,EAAE,QAAS,EAAE,CACrC,CAAC","sourcesContent":["import { IProduct, IQueryProductsRequest, provideQueryProductsService } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { Subject, defer, repeat, retry, shareReplay, tap } from 'rxjs';\nimport { getPerpetualsMetaData, getSpotMetaData } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst product$ = new Subject<IProduct>();\nlet latestProducts: IProduct[] = [];\n\nexport const listProducts = async (): Promise<IProduct[]> => {\n const [spotMetaData, perpetualsMetaData] = await Promise.all([getSpotMetaData(), getPerpetualsMetaData()]);\n const spotProducts = spotMetaData.tokens.map(\n (token): IProduct => ({\n product_id: encodePath('HYPERLIQUID', 'SPOT', `${token.name}-USDC`),\n datasource_id: 'HYPERLIQUID',\n quote_currency: 'USDC',\n base_currency: token.name,\n price_step: 1e-2,\n volume_step: Number(`1e-${token.szDecimals}`),\n name: '',\n value_scale: 1,\n value_scale_unit: '',\n margin_rate: 1,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'HYPERLIQUID/SPOT',\n no_interest_rate: true,\n }),\n );\n const perpetualProducts = perpetualsMetaData.universe.map(\n (product): IProduct => ({\n product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${product.name}-USD`),\n datasource_id: 'HYPERLIQUID',\n quote_currency: 'USD',\n base_currency: product.name,\n price_step: 1e-2,\n volume_step: Number(`1e-${product.szDecimals}`),\n name: '',\n value_scale: 1,\n value_scale_unit: '',\n margin_rate: 1 / product.maxLeverage,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'HYPERLIQUID/PERPETUAL',\n no_interest_rate: false,\n }),\n );\n return [...spotProducts, ...perpetualProducts];\n};\n\nconst refresh$ = defer(listProducts).pipe(\n tap((products) => {\n latestProducts = products;\n products.forEach((product) => product$.next(product));\n }),\n tap({\n error: (err) => console.error(formatTime(Date.now()), 'ProductRefreshFailed', err),\n }),\n retry({ delay: 5000 }),\n repeat({ delay: 86400_000 }),\n shareReplay(1),\n);\n\nrefresh$.subscribe();\n\ncreateSQLWriter<IProduct>(terminal, {\n data$: product$,\n tableName: 'product',\n writeInterval: 1000,\n conflictKeys: ['datasource_id', 'product_id'],\n});\n\nprovideQueryProductsService(\n terminal,\n 'HYPERLIQUID',\n async (_req: IQueryProductsRequest) => {\n if (!latestProducts.length) {\n latestProducts = await listProducts();\n }\n return latestProducts;\n },\n { auto_refresh_interval: 86400_000 },\n);\n"]}
|
|
@@ -20,7 +20,7 @@ const quote$ = defer(() => getAllMids()).pipe(map((mids) => Object.entries(mids
|
|
|
20
20
|
const ctx = assetCtxMap.get(coin);
|
|
21
21
|
return {
|
|
22
22
|
datasource_id: 'HYPERLIQUID',
|
|
23
|
-
product_id: encodePath('PERPETUAL', `${coin}-USD`),
|
|
23
|
+
product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${coin}-USD`),
|
|
24
24
|
last_price: `${price}`,
|
|
25
25
|
bid_price: `${price}`,
|
|
26
26
|
ask_price: `${price}`,
|
|
@@ -40,10 +40,10 @@ if (shouldWriteQuoteToSQL) {
|
|
|
40
40
|
.subscribe();
|
|
41
41
|
}
|
|
42
42
|
terminal.channel.publishChannel('quote', { pattern: '^HYPERLIQUID/' }, (channel_id) => {
|
|
43
|
-
const [datasourceId
|
|
44
|
-
if (
|
|
43
|
+
const [datasourceId] = decodePath(channel_id);
|
|
44
|
+
if (datasourceId !== 'HYPERLIQUID') {
|
|
45
45
|
throw new Error(`Invalid channel_id: ${channel_id}`);
|
|
46
46
|
}
|
|
47
|
-
return quote$.pipe(filter((quote) => quote.product_id ===
|
|
47
|
+
return quote$.pipe(filter((quote) => quote.product_id === channel_id));
|
|
48
48
|
});
|
|
49
49
|
//# sourceMappingURL=quote.js.map
|