@yuants/vendor-hyperliquid 0.7.4 → 0.7.6

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.
@@ -1,13 +1,14 @@
1
+ import { makeSpotPosition } from '@yuants/data-account';
1
2
  import { encodePath, formatTime } from '@yuants/utils';
2
3
  import { getUserPerpetualsAccountSummary } from '../../api/public-api';
3
4
  /**
4
5
  * Get account info for perpetual account
5
6
  */
6
7
  export const getPerpPositions = async (credential) => {
7
- console.info(`[${formatTime(Date.now())}] Getting perp account info for ${credential.address}`);
8
+ var _a, _b;
9
+ console.info(formatTime(Date.now()), `Getting perp account info for ${credential.address}`);
8
10
  const summary = await getUserPerpetualsAccountSummary({ user: credential.address });
9
- // Map positions
10
- const positions = summary.assetPositions.map((position) => ({
11
+ const perpPositions = summary.assetPositions.map((position) => ({
11
12
  position_id: `${position.position.coin}-USD`,
12
13
  datasource_id: 'HYPERLIQUID',
13
14
  product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${position.position.coin}-USD`),
@@ -20,6 +21,21 @@ export const getPerpPositions = async (credential) => {
20
21
  valuation: +position.position.positionValue,
21
22
  margin: +position.position.marginUsed,
22
23
  }));
23
- return positions;
24
+ const totalUnrealizedPnl = summary.assetPositions.reduce((acc, assetPosition) => acc + Number(assetPosition.position.unrealizedPnl || 0), 0);
25
+ const accountValue = Number((_b = (_a = summary.marginSummary) === null || _a === void 0 ? void 0 : _a.accountValue) !== null && _b !== void 0 ? _b : 0);
26
+ const usdcBalance = accountValue - totalUnrealizedPnl;
27
+ const usdcPositions = usdcBalance > 0
28
+ ? [
29
+ makeSpotPosition({
30
+ position_id: 'USDC',
31
+ datasource_id: 'HYPERLIQUID',
32
+ product_id: encodePath('HYPERLIQUID', 'PERPETUAL-ASSET', 'USDC'),
33
+ volume: usdcBalance,
34
+ free_volume: usdcBalance,
35
+ closable_price: 1,
36
+ }),
37
+ ]
38
+ : [];
39
+ return [...usdcPositions, ...perpPositions];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G,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
+ {"version":3,"file":"perp.js","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CA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C,QAAQ,CAAC,QAAQ,CAAC,UAAU;KACtC,CAAC,CACH,CAAC;IAEF,MAAM,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CACtD,CAAC,GAAG,EAAE,aAAa,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,aAAa,IAAI,CAAC,CAAC,EAC/E,CAAC,CACF,CAAC;IACF,MAAM,YAAY,GAAG,MAAM,CAAC,MAAA,MAAA,OAAO,CAAC,aAAa,0CAAE,YAAY,mCAAI,CAAC,CAAC,CAAC;IACtE,MAAM,WAAW,GAAG,YAAY,GAAG,kBAAkB,CAAC;IACtD,MAAM,aAAa,GACjB,WAAW,GAAG,CAAC;QACb,CAAC,CAAC;YACE,gBAAgB,CAAC;gBACf,WAAW,EAAE,MAAM;gBACnB,aAAa,EAAE,aAAa;gBAC5B,UAAU,EAAE,UAAU,CAAC,aAAa,EAAE,iBAAiB,EAAE,MAAM,CAAC;gBAChE,MAAM,EAAE,WAAW;gBACnB,WAAW,EAAE,WAAW;gBACxB,cAAc,EAAE,CAAC;aAClB,CAAC;SACH;QACH,CAAC,CAAC,EAAE,CAAC;IAET,OAAO,CAAC,GAAG,aAAa,EAAE,GAAG,aAAa,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["import { IPosition, makeSpotPosition } 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 const perpPositions = 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 const totalUnrealizedPnl = summary.assetPositions.reduce(\n (acc, assetPosition) => acc + Number(assetPosition.position.unrealizedPnl || 0),\n 0,\n );\n const accountValue = Number(summary.marginSummary?.accountValue ?? 0);\n const usdcBalance = accountValue - totalUnrealizedPnl;\n const usdcPositions =\n usdcBalance > 0\n ? [\n makeSpotPosition({\n position_id: 'USDC',\n datasource_id: 'HYPERLIQUID',\n product_id: encodePath('HYPERLIQUID', 'PERPETUAL-ASSET', 'USDC'),\n volume: usdcBalance,\n free_volume: usdcBalance,\n closable_price: 1,\n }),\n ]\n : [];\n\n return [...usdcPositions, ...perpPositions];\n};\n"]}
@@ -1,23 +1,29 @@
1
1
  import { makeSpotPosition } from '@yuants/data-account';
2
2
  import { encodePath, formatTime } from '@yuants/utils';
3
- import { getUserTokenBalances } from '../../api/public-api';
3
+ import { getAllMids, getUserTokenBalances } from '../../api/public-api';
4
4
  /**
5
5
  * Get account info for spot account
6
6
  */
7
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 });
8
+ console.info(formatTime(Date.now()), `Getting spot account info for ${credential.address}`);
9
+ const [balances, mids] = await Promise.all([
10
+ getUserTokenBalances({ user: credential.address }),
11
+ getAllMids(),
12
+ ]);
10
13
  // Map token balances to positions (using spot as "positions")
11
14
  const positions = balances.balances
12
15
  .filter((balance) => Number(balance.total) > 0)
13
- .map((balance) => makeSpotPosition({
14
- position_id: `${balance.coin}`,
15
- datasource_id: 'HYPERLIQUID',
16
- product_id: encodePath('HYPERLIQUID', 'SPOT', `${balance.coin}-USDC`),
17
- volume: Number(balance.total),
18
- free_volume: Number(balance.total) - Number(balance.hold),
19
- closable_price: 1,
20
- }));
16
+ .map((balance) => {
17
+ var _a;
18
+ return makeSpotPosition({
19
+ position_id: `${balance.coin}`,
20
+ datasource_id: 'HYPERLIQUID',
21
+ product_id: encodePath('HYPERLIQUID', 'SPOT', `${balance.coin}-USDC`),
22
+ volume: Number(balance.total),
23
+ free_volume: Number(balance.total) - Number(balance.hold),
24
+ closable_price: balance.coin === 'USDC' ? 1 : Number((_a = mids === null || mids === void 0 ? void 0 : mids[balance.coin]) !== null && _a !== void 0 ? _a : 0),
25
+ });
26
+ });
21
27
  return positions;
22
28
  };
23
29
  //# sourceMappingURL=spot.js.map
@@ -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;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"]}
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,UAAU,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGxE;;GAEG;AACH,MAAM,CAAC,MAAM,gBAA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/utils';\nimport { getAllMids, 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, mids] = await Promise.all([\n getUserTokenBalances({ user: credential.address }),\n getAllMids(),\n ]);\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: balance.coin === 'USDC' ? 1 : Number(mids?.[balance.coin] ?? 0),\n }),\n );\n\n return positions;\n};\n"]}
@@ -51,6 +51,10 @@ provideExchangeServices(terminal, {
51
51
  const perpPositions = await getPerpPositions(credential);
52
52
  return perpPositions.filter((position) => position.product_id === product_id);
53
53
  }
54
+ if (instType === 'PERPETUAL-ASSET') {
55
+ const perpPositions = await getPerpPositions(credential);
56
+ return perpPositions.filter((position) => position.product_id === product_id);
57
+ }
54
58
  if (instType === 'SPOT') {
55
59
  const spotPositions = await getSpotPositions(credential);
56
60
  return spotPositions.filter((position) => position.product_id === product_id);
@@ -1 +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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AuB,EAAE,UAAkB,EAAqB,EAAE;QAC7F,OAAO,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvD,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiC,EAAE;QAC3F,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,WAAW,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiB,EAAE;QAC3E,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,WAAW,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiB,EAAE;QAC3E,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,iBAAiB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC9C,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"]}
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src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/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 === 'PERPETUAL-ASSET') {\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"]}
@@ -41,6 +41,9 @@ export const listPerpOrders = async (credential) => {
41
41
  console.info(`[${formatTime(Date.now())}] Listing perpetual orders for ${credential.address}`);
42
42
  try {
43
43
  const orders = await getUserOpenOrders({ user: credential.address });
44
+ if (!orders || !Array.isArray(orders)) {
45
+ return [];
46
+ }
44
47
  return orders.map((order) => mapOrder(order));
45
48
  }
46
49
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzD;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAkB,EAAE;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACtC,IAAI,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,KAAK,EAAE;QAChD,OAAO,WAA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nE,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { ICredential, getCredentialId } from '../../api/types';\nimport { getUserOpenOrders } from '../../api/public-api';\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\n/**\n * Map order direction based on side and reduce-only logic\n */\nconst mapOrderDirection = (side: string): OrderDirection => {\n const normalized = side.toUpperCase();\n if (normalized === 'BID' || normalized === 'BUY') {\n return 'OPEN_LONG';\n }\n if (normalized === 'ASK' || normalized === 'SELL') {\n return 'OPEN_SHORT';\n }\n return 'OPEN_LONG';\n};\n\n/**\n * Map Hyperliquid order to Yuan IOrder format\n */\nconst mapOrder = (order: any): IOrder => {\n const volume = Number(order.sz) || 0;\n const price = Number(order.limitPx) || 0;\n\n return {\n order_id: `${order.oid}`,\n account_id: '',\n product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${order.coin?.trim()}-USD`),\n order_type: 'LIMIT', // Hyperliquid primarily uses limit orders\n order_direction: mapOrderDirection(order.side),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) && price > 0 ? price : undefined,\n submit_at: Number(order.timestamp ?? Date.now()),\n order_status: 'open', // Since these are open orders\n // Additional fields that might be useful\n comment: order.coin ? JSON.stringify({ asset_id: order.coin }) : undefined,\n };\n};\n\n/**\n * List perpetual orders\n */\nexport const listPerpOrders = async (credential: ICredential): Promise<IOrder[]> => {\n console.info(`[${formatTime(Date.now())}] Listing perpetual orders for ${credential.address}`);\n\n try {\n const orders = await getUserOpenOrders({ user: credential.address });\n return orders.map((order) => mapOrder(order));\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error';\n console.error(`[${formatTime(Date.now())}] Failed to list perpetual orders: ${errorMessage}`);\n throw new Error(`Failed to list perpetual orders: ${errorMessage}`);\n }\n};\n\n/**\n * List orders by product_id\n */\nexport const listOrdersByProductId = async (\n credential: ICredential,\n product_id: string,\n): Promise<IOrder[]> => {\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 return [];\n }\n const orders = await listPerpOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n};\n"]}
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzD;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAkB,EAAE;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACtC,IAAI,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,KAAK,EAAE;QAChD,OAAO,WAAW,CAAC;KACpB;IACD,IAAI,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,MAAM,EAAE;QACjD,OAAO,YAAY,CAAC;KACrB;IACD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAU,EAAE;;IACtC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC,OAAO;QACL,QAAQ,EAAE,GAAG,KAAK,CAAC,GAAG,EAAE;QACxB,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,UAAU,CAAC,aAAa,EAAE,WAAW,EAAE,GAAG,MAAA,KAAK,CAAC,IAAI,0CAAE,IAAI,EAAE,MAAM,CAAC;QAC/E,UAAU,EAAE,OAAO;QACnB,eAAe,EAAE,i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C,eAAe,CAAC;QAC9E,OAAO,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,sCAAsC,YAAY,EAAE,CAAC,CAAC;QAC9F,MAAM,IAAI,KAAK,CAAC,oCAAoC,YAAY,EAAE,CAAC,CAAC;KACrE;AACH,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EACxC,UAAuB,EACvB,UAAkB,EACC,EAAE;IACrB,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACpD,IAAI,QAAQ,KAAK,aAAa,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,uCAAuC,UAAU,EAAE,CAAC,CAAC;KACtE;IACD,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC5B,OAAO,EAAE,CAAC;KACX;IACD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;AACnE,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { ICredential, getCredentialId } from '../../api/types';\nimport { getUserOpenOrders } from '../../api/public-api';\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\n/**\n * Map order direction based on side and reduce-only logic\n */\nconst mapOrderDirection = (side: string): OrderDirection => {\n const normalized = side.toUpperCase();\n if (normalized === 'BID' || normalized === 'BUY') {\n return 'OPEN_LONG';\n }\n if (normalized === 'ASK' || normalized === 'SELL') {\n return 'OPEN_SHORT';\n }\n return 'OPEN_LONG';\n};\n\n/**\n * Map Hyperliquid order to Yuan IOrder format\n */\nconst mapOrder = (order: any): IOrder => {\n const volume = Number(order.sz) || 0;\n const price = Number(order.limitPx) || 0;\n\n return {\n order_id: `${order.oid}`,\n account_id: '',\n product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${order.coin?.trim()}-USD`),\n order_type: 'LIMIT', // Hyperliquid primarily uses limit orders\n order_direction: mapOrderDirection(order.side),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) && price > 0 ? price : undefined,\n submit_at: Number(order.timestamp ?? Date.now()),\n order_status: 'open', // Since these are open orders\n // Additional fields that might be useful\n comment: order.coin ? JSON.stringify({ asset_id: order.coin }) : undefined,\n };\n};\n\n/**\n * List perpetual orders\n */\nexport const listPerpOrders = async (credential: ICredential): Promise<IOrder[]> => {\n console.info(`[${formatTime(Date.now())}] Listing perpetual orders for ${credential.address}`);\n\n try {\n const orders = await getUserOpenOrders({ user: credential.address });\n if (!orders || !Array.isArray(orders)) {\n return [];\n }\n return orders.map((order) => mapOrder(order));\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error';\n console.error(`[${formatTime(Date.now())}] Failed to list perpetual orders: ${errorMessage}`);\n throw new Error(`Failed to list perpetual orders: ${errorMessage}`);\n }\n};\n\n/**\n * List orders by product_id\n */\nexport const listOrdersByProductId = async (\n credential: ICredential,\n product_id: string,\n): Promise<IOrder[]> => {\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 return [];\n }\n const orders = await listPerpOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"perp.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,gBAAgB,eAAsB,WAAW,yBAuB7D,CAAC"}
1
+ {"version":3,"file":"perp.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,gBAAgB,eAAsB,WAAW,yBA0C7D,CAAC"}
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPerpPositions = void 0;
4
+ const data_account_1 = require("@yuants/data-account");
4
5
  const utils_1 = require("@yuants/utils");
5
6
  const public_api_1 = require("../../api/public-api");
6
7
  /**
7
8
  * Get account info for perpetual account
8
9
  */
9
10
  const getPerpPositions = async (credential) => {
10
- console.info(`[${(0, utils_1.formatTime)(Date.now())}] Getting perp account info for ${credential.address}`);
11
+ var _a, _b;
12
+ console.info((0, utils_1.formatTime)(Date.now()), `Getting perp account info for ${credential.address}`);
11
13
  const summary = await (0, public_api_1.getUserPerpetualsAccountSummary)({ user: credential.address });
12
- // Map positions
13
- const positions = summary.assetPositions.map((position) => ({
14
+ const perpPositions = summary.assetPositions.map((position) => ({
14
15
  position_id: `${position.position.coin}-USD`,
15
16
  datasource_id: 'HYPERLIQUID',
16
17
  product_id: (0, utils_1.encodePath)('HYPERLIQUID', 'PERPETUAL', `${position.position.coin}-USD`),
@@ -23,7 +24,22 @@ const getPerpPositions = async (credential) => {
23
24
  valuation: +position.position.positionValue,
24
25
  margin: +position.position.marginUsed,
25
26
  }));
26
- return positions;
27
+ const totalUnrealizedPnl = summary.assetPositions.reduce((acc, assetPosition) => acc + Number(assetPosition.position.unrealizedPnl || 0), 0);
28
+ const accountValue = Number((_b = (_a = summary.marginSummary) === null || _a === void 0 ? void 0 : _a.accountValue) !== null && _b !== void 0 ? _b : 0);
29
+ const usdcBalance = accountValue - totalUnrealizedPnl;
30
+ const usdcPositions = usdcBalance > 0
31
+ ? [
32
+ (0, data_account_1.makeSpotPosition)({
33
+ position_id: 'USDC',
34
+ datasource_id: 'HYPERLIQUID',
35
+ product_id: (0, utils_1.encodePath)('HYPERLIQUID', 'PERPETUAL-ASSET', 'USDC'),
36
+ volume: usdcBalance,
37
+ free_volume: usdcBalance,
38
+ closable_price: 1,
39
+ }),
40
+ ]
41
+ : [];
42
+ return [...usdcPositions, ...perpPositions];
27
43
  };
28
44
  exports.getPerpPositions = getPerpPositions;
29
45
  //# sourceMappingURL=perp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"perp.js","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":";;;AACA,yCAAuD;AACvD,qDAAuE;AAGvE;;GAEG;AACI,MAAM,gBAAgB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAChE,OAAO,CAAC,IAAI,CAAC,IAAI,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,mCAAmC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAEhG,MAAM,OAAO,GAAG,MAAM,IAAA,4CAA+B,EAAC,EAAE,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAEpF,gBAAgB;IAChB,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,CAC1C,CAAC,QAAQ,EAAa,EAAE,CAAC,CAAC;QACxB,WAAW,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM;QAC5C,aAAa,EAAE,aAAa;QAC5B,UAAU,EAAE,IAAA,kBAAU,EAAC,aAAa,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC;QACnF,SAAS,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;QACxD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QACxC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,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;AAvBW,QAAA,gBAAgB,oBAuB3B","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 }),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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,MAAM,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CACtD,CAAC,GAAG,EAAE,aAAa,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,aAAa,IAAI,CAAC,CAAC,EAC/E,CAAC,CACF,CAAC;IACF,MAAM,YAAY,GAAG,MAAM,CAAC,MAAA,MAAA,OAAO,CAAC,aAAa,0CAAE,YAAY,mCAAI,CAAC,CAAC,CAAC;IACtE,MAAM,WAAW,GAAG,YAAY,GAAG,kBAAkB,CAAC;IACtD,MAAM,aAAa,GACjB,WAAW,GAAG,CAAC;QACb,CAAC,CAAC;YACE,IAAA,+BAAgB,EAAC;gBACf,WAAW,EAAE,MAAM;gBACnB,aAAa,EAAE,aAAa;gBAC5B,UAAU,EAAE,IAAA,kBAAU,EAAC,aAAa,EAAE,iBAAiB,EAAE,MAAM,CAAC;gBAChE,MAAM,EAAE,WAAW;gBACnB,WAAW,EAAE,WAAW;gBACxB,cAAc,EAAE,CAAC;aAClB,CAAC;SACH;QACH,CAAC,CAAC,EAAE,CAAC;IAET,OAAO,CAAC,GAAG,aAAa,EAAE,GAAG,aAAa,CAAC,CAAC;AAC9C,CAAC,CAAC;AA1CW,QAAA,gBAAgB,oBA0C3B","sourcesContent":["import { IPosition, makeSpotPosition } 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 const perpPositions = 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 const totalUnrealizedPnl = summary.assetPositions.reduce(\n (acc, assetPosition) => acc + Number(assetPosition.position.unrealizedPnl || 0),\n 0,\n );\n const accountValue = Number(summary.marginSummary?.accountValue ?? 0);\n const usdcBalance = accountValue - totalUnrealizedPnl;\n const usdcPositions =\n usdcBalance > 0\n ? [\n makeSpotPosition({\n position_id: 'USDC',\n datasource_id: 'HYPERLIQUID',\n product_id: encodePath('HYPERLIQUID', 'PERPETUAL-ASSET', 'USDC'),\n volume: usdcBalance,\n free_volume: usdcBalance,\n closable_price: 1,\n }),\n ]\n : [];\n\n return [...usdcPositions, ...perpPositions];\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,gBAAgB,eAAsB,WAAW,yBAqB7D,CAAC"}
1
+ {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,gBAAgB,eAAsB,WAAW,yBAwB7D,CAAC"}
@@ -8,19 +8,25 @@ const public_api_1 = require("../../api/public-api");
8
8
  * Get account info for spot account
9
9
  */
10
10
  const getSpotPositions = async (credential) => {
11
- console.info(`[${(0, utils_1.formatTime)(Date.now())}] Getting spot account info for ${credential.address}`);
12
- const balances = await (0, public_api_1.getUserTokenBalances)({ user: credential.address });
11
+ console.info((0, utils_1.formatTime)(Date.now()), `Getting spot account info for ${credential.address}`);
12
+ const [balances, mids] = await Promise.all([
13
+ (0, public_api_1.getUserTokenBalances)({ user: credential.address }),
14
+ (0, public_api_1.getAllMids)(),
15
+ ]);
13
16
  // Map token balances to positions (using spot as "positions")
14
17
  const positions = balances.balances
15
18
  .filter((balance) => Number(balance.total) > 0)
16
- .map((balance) => (0, data_account_1.makeSpotPosition)({
17
- position_id: `${balance.coin}`,
18
- datasource_id: 'HYPERLIQUID',
19
- product_id: (0, utils_1.encodePath)('HYPERLIQUID', 'SPOT', `${balance.coin}-USDC`),
20
- volume: Number(balance.total),
21
- free_volume: Number(balance.total) - Number(balance.hold),
22
- closable_price: 1,
23
- }));
19
+ .map((balance) => {
20
+ var _a;
21
+ return (0, data_account_1.makeSpotPosition)({
22
+ position_id: `${balance.coin}`,
23
+ datasource_id: 'HYPERLIQUID',
24
+ product_id: (0, utils_1.encodePath)('HYPERLIQUID', 'SPOT', `${balance.coin}-USDC`),
25
+ volume: Number(balance.total),
26
+ free_volume: Number(balance.total) - Number(balance.hold),
27
+ closable_price: balance.coin === 'USDC' ? 1 : Number((_a = mids === null || mids === void 0 ? void 0 : mids[balance.coin]) !== null && _a !== void 0 ? _a : 0),
28
+ });
29
+ });
24
30
  return positions;
25
31
  };
26
32
  exports.getSpotPositions = getSpotPositions;
@@ -1 +1 @@
1
- {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AACnE,yCAAuD;AACvD,qDAA4D;AAG5D;;GAEG;AACI,MAAM,gBAAgB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAChE,OAAO,CAAC,IAAI,CAAC,IAAI,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,mCAAmC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAEhG,MAAM,QAAQ,GAAG,MAAM,IAAA,iCAAoB,EAAC,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,IAAA,+BAAgB,EAAC;QACf,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE;QAC9B,aAAa,EAAE,aAAa;QAC5B,UAAU,EAAE,IAAA,kBAAU,EAAC,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;AArBW,QAAA,gBAAgB,oBAqB3B","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"]}
1
+ {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AACnE,yCAAuD;AACvD,qDAAwE;AAGxE;;GAEG;AACI,MAAM,gBAAgB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAChE,OAAO,CAAC,IAAI,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,iCAAiC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAE5F,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACzC,IAAA,iCAAoB,EAAC,EAAE,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;QAClD,IAAA,uBAAU,GAAE;KACb,CAAC,CAAC;IAEH,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;;QACrB,OAAA,IAAA,+BAAgB,EAAC;YACf,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE;YAC9B,aAAa,EAAE,aAAa;YAC5B,UAAU,EAAE,IAAA,kBAAU,EAAC,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,OAAO,CAAC;YACrE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAC7B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;YACzD,cAAc,EAAE,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,OAAO,CAAC,IAAI,CAAC,mCAAI,CAAC,CAAC;SAChF,CAAC,CAAA;KAAA,CACL,CAAC;IAEJ,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAxBW,QAAA,gBAAgB,oBAwB3B","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { getAllMids, 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, mids] = await Promise.all([\n getUserTokenBalances({ user: credential.address }),\n getAllMids(),\n ]);\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: balance.coin === 'USDC' ? 1 : Number(mids?.[balance.coin] ?? 0),\n }),\n );\n\n return positions;\n};\n"]}
@@ -53,6 +53,10 @@ const ensureHyperliquidProduct = (product_id) => {
53
53
  const perpPositions = await (0, perp_1.getPerpPositions)(credential);
54
54
  return perpPositions.filter((position) => position.product_id === product_id);
55
55
  }
56
+ if (instType === 'PERPETUAL-ASSET') {
57
+ const perpPositions = await (0, perp_1.getPerpPositions)(credential);
58
+ return perpPositions.filter((position) => position.product_id === product_id);
59
+ }
56
60
  if (instType === 'SPOT') {
57
61
  const spotPositions = await (0, spot_1.getSpotPositions)(credential);
58
62
  return spotPositions.filter((position) => position.product_id === product_id);
@@ -1 +1 @@
1
- {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AAEA,+CAA2D;AAC3D,+CAA4C;AAC5C,yCAAuD;AACvD,wCAA6F;AAC7F,+CAAiD;AACjD,0CAAmD;AACnD,0CAAmD;AACnD,sDAAyD;AACzD,oDAA4E;AAC5E,sDAAmD;AACnD,sDAAmD;AAEnD,MAAM,QAAQ,GAAG,mBAAQ,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,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;IACpD,IAAI,QAAQ,KAAK,aAAa,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,+CAA+C,UAAU,EAAE,CAAC,CAAC;KAC9E;IACD,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,uDAAuD,UAAU,EAAE,CAAC,CAAC;KACtF;AACH,CAAC,CAAC;AAEF,IAAA,kCAAuB,EAAc,QAAQ,EAAE;IAC7C,IAAI,EAAE,aAAa;IACnB,gBAAgB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC;QACpC,UAAU,EAAE;YACV,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC/B,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SA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AAU,KAAK,UAAU,CAAC,CAAC;SAC/E;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,SAAS,EAAE,KAAK,EAAE,UAAuB,EAAqB,EAAE;QAC9D,OAAO,IAAA,2BAAc,EAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IACD,oBAAoB,EAAE,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAqB,EAAE;QAC7F,OAAO,IAAA,kCAAqB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvD,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiC,EAAE;QAC3F,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,IAAA,yBAAW,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiB,EAAE;QAC3E,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,IAAA,yBAAW,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiB,EAAE;QAC3E,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,IAAA,+BAAiB,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC9C,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"]}
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AAEA,+CAA2D;AAC3D,+CAA4C;AAC5C,yCAAuD;AACvD,wCAA6F;AAC7F,+CAAiD;AACjD,0CAAmD;AACnD,0CAAmD;AACnD,sDAAyD;AACzD,oDAA4E;AAC5E,sDAAmD;AACnD,sDAAmD;AAEnD,MAAM,QAAQ,GAAG,mBAAQ,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,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;IACpD,IAAI,QAAQ,KAAK,aAAa,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,+CAA+C,UAAU,EAAE,CAAC,CAAC;KAC9E;IACD,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,uDAAuD,UAAU,EAAE,CAAC,CAAC;KACtF;AACH,CAAC,CAAC;AAEF,IAAA,kCAAuB,EAAc,QAAQ,EAAE;IAC7C,IAAI,EAAE,aAAa;IACnB,gBAAgB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC;QACpC,UAAU,EAAE;YACV,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC/B,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC5B;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U,KAAK,UAAU,CAAC,CAAC;SAC/E;QACD,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,MAAM,aAAa,GAAG,MAAM,IAAA,uBAAgB,EAAC,UAAU,CAAC,CAAC;YACzD,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAC/E;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,SAAS,EAAE,KAAK,EAAE,UAAuB,EAAqB,EAAE;QAC9D,OAAO,IAAA,2BAAc,EAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IACD,oBAAoB,EAAE,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAqB,EAAE;QAC7F,OAAO,IAAA,kCAAqB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvD,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiC,EAAE;QAC3F,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,IAAA,yBAAW,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiB,EAAE;QAC3E,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,IAAA,yBAAW,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiB,EAAE;QAC3E,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,IAAA,+BAAiB,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC9C,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 === 'PERPETUAL-ASSET') {\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AAyC/D;;GAEG;AACH,eAAO,MAAM,cAAc,eAAsB,WAAW,KAAG,QAAQ,MAAM,EAAE,CAW9E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,eACpB,WAAW,cACX,MAAM,KACjB,QAAQ,MAAM,EAAE,CAUlB,CAAC"}
1
+ {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AAyC/D;;GAEG;AACH,eAAO,MAAM,cAAc,eAAsB,WAAW,KAAG,QAAQ,MAAM,EAAE,CAc9E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,eACpB,WAAW,cACX,MAAM,KACjB,QAAQ,MAAM,EAAE,CAUlB,CAAC"}
@@ -44,6 +44,9 @@ const listPerpOrders = async (credential) => {
44
44
  console.info(`[${(0, utils_1.formatTime)(Date.now())}] Listing perpetual orders for ${credential.address}`);
45
45
  try {
46
46
  const orders = await (0, public_api_1.getUserOpenOrders)({ user: credential.address });
47
+ if (!orders || !Array.isArray(orders)) {
48
+ return [];
49
+ }
47
50
  return orders.map((order) => mapOrder(order));
48
51
  }
49
52
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,yCAAmE;AAEnE,qDAAyD;AAIzD;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAkB,EAAE;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACtC,IAAI,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,KAAK,EAAE;QAChD,OAAO,WAAW,CAAC;KACpB;IACD,IAAI,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,MAAM,EAAE;QACjD,OAAO,YAAY,CAAC;KACrB;IACD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAU,EAAE;;IACtC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC,OAAO;QACL,QAAQ,EAAE,GAAG,KAAK,CAAC,GAAG,EAAE;QACxB,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,IAAA,kBAAU,EAAC,aAAa,EAAE,WAAW,EAAE,GAAG,MAAA,KAAK,CAAC,IAAI,0CAAE,IAAI,EAAE,MAAM,CAAC;QAC/E,UAAU,EAAE,OAAO;QACnB,eAAe,EAAE,iBAA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,YAAY,EAAE,CAAC,CAAC;QAC9F,MAAM,IAAI,KAAK,CAAC,oCAAoC,YAAY,EAAE,CAAC,CAAC;KACrE;AACH,CAAC,CAAC;AAXW,QAAA,cAAc,kBAWzB;AAEF;;GAEG;AACI,MAAM,qBAAqB,GAAG,KAAK,EACxC,UAAuB,EACvB,UAAkB,EACC,EAAE;IACrB,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;IACpD,IAAI,QAAQ,KAAK,aAAa,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,uCAAuC,UAAU,EAAE,CAAC,CAAC;KACtE;IACD,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC5B,OAAO,EAAE,CAAC;KACX;IACD,MAAM,MAAM,GAAG,MAAM,IAAA,sBAAc,EAAC,UAAU,CAAC,CAAC;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;AACnE,CAAC,CAAC;AAbW,QAAA,qBAAqB,yBAahC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { ICredential, getCredentialId } from '../../api/types';\nimport { getUserOpenOrders } from '../../api/public-api';\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\n/**\n * Map order direction based on side and reduce-only logic\n */\nconst mapOrderDirection = (side: string): OrderDirection => {\n const normalized = side.toUpperCase();\n if (normalized === 'BID' || normalized === 'BUY') {\n return 'OPEN_LONG';\n }\n if (normalized === 'ASK' || normalized === 'SELL') {\n return 'OPEN_SHORT';\n }\n return 'OPEN_LONG';\n};\n\n/**\n * Map Hyperliquid order to Yuan IOrder format\n */\nconst mapOrder = (order: any): IOrder => {\n const volume = Number(order.sz) || 0;\n const price = Number(order.limitPx) || 0;\n\n return {\n order_id: `${order.oid}`,\n account_id: '',\n product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${order.coin?.trim()}-USD`),\n order_type: 'LIMIT', // Hyperliquid primarily uses limit orders\n order_direction: mapOrderDirection(order.side),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) && price > 0 ? price : undefined,\n submit_at: Number(order.timestamp ?? Date.now()),\n order_status: 'open', // Since these are open orders\n // Additional fields that might be useful\n comment: order.coin ? JSON.stringify({ asset_id: order.coin }) : undefined,\n };\n};\n\n/**\n * List perpetual orders\n */\nexport const listPerpOrders = async (credential: ICredential): Promise<IOrder[]> => {\n console.info(`[${formatTime(Date.now())}] Listing perpetual orders for ${credential.address}`);\n\n try {\n const orders = await getUserOpenOrders({ user: credential.address });\n return orders.map((order) => mapOrder(order));\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error';\n console.error(`[${formatTime(Date.now())}] Failed to list perpetual orders: ${errorMessage}`);\n throw new Error(`Failed to list perpetual orders: ${errorMessage}`);\n }\n};\n\n/**\n * List orders by product_id\n */\nexport const listOrdersByProductId = async (\n credential: ICredential,\n product_id: string,\n): Promise<IOrder[]> => {\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 return [];\n }\n const orders = await listPerpOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n};\n"]}
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,yCAAmE;AAEnE,qDAAyD;AAIzD;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAkB,EAAE;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACtC,IAAI,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,KAAK,EAAE;QAChD,OAAO,WAAW,CAAC;KACpB;I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AAC,UAAU,CAAC,CAAC;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;AACnE,CAAC,CAAC;AAbW,QAAA,qBAAqB,yBAahC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { ICredential, getCredentialId } from '../../api/types';\nimport { getUserOpenOrders } from '../../api/public-api';\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\n/**\n * Map order direction based on side and reduce-only logic\n */\nconst mapOrderDirection = (side: string): OrderDirection => {\n const normalized = side.toUpperCase();\n if (normalized === 'BID' || normalized === 'BUY') {\n return 'OPEN_LONG';\n }\n if (normalized === 'ASK' || normalized === 'SELL') {\n return 'OPEN_SHORT';\n }\n return 'OPEN_LONG';\n};\n\n/**\n * Map Hyperliquid order to Yuan IOrder format\n */\nconst mapOrder = (order: any): IOrder => {\n const volume = Number(order.sz) || 0;\n const price = Number(order.limitPx) || 0;\n\n return {\n order_id: `${order.oid}`,\n account_id: '',\n product_id: encodePath('HYPERLIQUID', 'PERPETUAL', `${order.coin?.trim()}-USD`),\n order_type: 'LIMIT', // Hyperliquid primarily uses limit orders\n order_direction: mapOrderDirection(order.side),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) && price > 0 ? price : undefined,\n submit_at: Number(order.timestamp ?? Date.now()),\n order_status: 'open', // Since these are open orders\n // Additional fields that might be useful\n comment: order.coin ? JSON.stringify({ asset_id: order.coin }) : undefined,\n };\n};\n\n/**\n * List perpetual orders\n */\nexport const listPerpOrders = async (credential: ICredential): Promise<IOrder[]> => {\n console.info(`[${formatTime(Date.now())}] Listing perpetual orders for ${credential.address}`);\n\n try {\n const orders = await getUserOpenOrders({ user: credential.address });\n if (!orders || !Array.isArray(orders)) {\n return [];\n }\n return orders.map((order) => mapOrder(order));\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error';\n console.error(`[${formatTime(Date.now())}] Failed to list perpetual orders: ${errorMessage}`);\n throw new Error(`Failed to list perpetual orders: ${errorMessage}`);\n }\n};\n\n/**\n * List orders by product_id\n */\nexport const listOrdersByProductId = async (\n credential: ICredential,\n product_id: string,\n): Promise<IOrder[]> => {\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 return [];\n }\n const orders = await listPerpOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-hyperliquid",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -19,7 +19,7 @@
19
19
  "@yuants/data-order": "0.6.6",
20
20
  "@yuants/data-series": "0.3.51",
21
21
  "@yuants/data-quote": "0.2.43",
22
- "@yuants/exchange": "0.2.1",
22
+ "@yuants/exchange": "0.3.0",
23
23
  "rxjs": "~7.5.6",
24
24
  "hyperliquid": "~1.6.2",
25
25
  "ethers": "~6.13.5",
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "apps/vendor-hyperliquid/AGENTS.md": "f0f3df594ce55fbaf78fb040f2850d1abee3449a",
3
- "apps/vendor-hyperliquid/CHANGELOG.json": "ec2efe9ec062993b6cbc0050a8b701f8303909d2",
4
- "apps/vendor-hyperliquid/CHANGELOG.md": "9c606ed67dc018912046ea87a659d65b0073f01e",
5
- "apps/vendor-hyperliquid/SESSION_NOTES.md": "a85524da3692937550f2bc64415c041bec9b94c4",
3
+ "apps/vendor-hyperliquid/CHANGELOG.json": "8ffe00dc2a68ddaeba19404adc8781617dba589b",
4
+ "apps/vendor-hyperliquid/CHANGELOG.md": "5f92d036f6586d01648ddf1f8f0c4ca432150501",
5
+ "apps/vendor-hyperliquid/SESSION_NOTES.md": "41a8a3b98f99d30fece2e510934c35e2e30ffa28",
6
6
  "apps/vendor-hyperliquid/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
7
7
  "apps/vendor-hyperliquid/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
8
8
  "apps/vendor-hyperliquid/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
9
9
  "apps/vendor-hyperliquid/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
10
10
  "apps/vendor-hyperliquid/etc/vendor-hyperliquid.api.md": "66675bd88afa1fe945f0d4023984c1c9c3e60a34",
11
- "apps/vendor-hyperliquid/package.json": "564592c97081f36c90611494219a439af6b9f08d",
11
+ "apps/vendor-hyperliquid/package.json": "c7876343a7850f15dc8a0786bec7e45a548b2520",
12
12
  "apps/vendor-hyperliquid/src/api/client.ts": "90eb3b63394c9729cc442e0ee5482bfd494aafdd",
13
13
  "apps/vendor-hyperliquid/src/api/private-api.ts": "8fd176063af8f345aeab94444850e82979cef680",
14
14
  "apps/vendor-hyperliquid/src/api/public-api.ts": "fbbb982308eea89a51b93cc21442de6ba45cfd60",
@@ -16,15 +16,15 @@
16
16
  "apps/vendor-hyperliquid/src/api/types.ts": "70347eb8b5e691770073dd043788ed5fae0c3eb4",
17
17
  "apps/vendor-hyperliquid/src/cli.ts": "9bf6b5559a6c6f33da20e74cc6c5d702c60ec891",
18
18
  "apps/vendor-hyperliquid/src/index.ts": "5626984c4caf2ccbf6f610378f719164b09f4dbe",
19
- "apps/vendor-hyperliquid/src/services/accounts/perp.ts": "6cce534903e59addcd8e7d6696f9870d115a5c26",
20
- "apps/vendor-hyperliquid/src/services/accounts/spot.ts": "426b61925d77bd26aac89f52ab5eaa063d91a867",
21
- "apps/vendor-hyperliquid/src/services/exchange.ts": "bc70307f472c37e4f8ce30ac18c247f4973142e3",
19
+ "apps/vendor-hyperliquid/src/services/accounts/perp.ts": "2be6376deabbe7f5b6416219de46400309e1c4f9",
20
+ "apps/vendor-hyperliquid/src/services/accounts/spot.ts": "cee336c2e27d97ce8386f873c0a721cce9163ea0",
21
+ "apps/vendor-hyperliquid/src/services/exchange.ts": "e36dcefff1e239e6b44c7ea1aa0632f59cbce653",
22
22
  "apps/vendor-hyperliquid/src/services/markets/interest-rate.ts": "af194dc1f2acf1cc80690fced44b1b7da4250d0e",
23
23
  "apps/vendor-hyperliquid/src/services/markets/ohlc.ts": "6cea84e64ff68ef3a760b35d2e637b66a1ca1615",
24
24
  "apps/vendor-hyperliquid/src/services/markets/product.ts": "05e6136a62c09d3756e0288c1a7c8b05b0fe0774",
25
25
  "apps/vendor-hyperliquid/src/services/markets/quote.ts": "25f8886667e36aa5e5676618a016f464c667c51b",
26
26
  "apps/vendor-hyperliquid/src/services/orders/cancelOrder.ts": "eeb8b166a712c64df45873b83b0587238c249992",
27
- "apps/vendor-hyperliquid/src/services/orders/listOrders.ts": "15c8961a28a92fa839ed6edf60f9c49a7d62742d",
27
+ "apps/vendor-hyperliquid/src/services/orders/listOrders.ts": "9ffd16181d23d98d5397e76b0a3f63f2bf7792ce",
28
28
  "apps/vendor-hyperliquid/src/services/orders/modifyOrder.ts": "01fc9d965578f216f6e5beae4e52f7640c1d4a28",
29
29
  "apps/vendor-hyperliquid/src/services/orders/submitOrder.ts": "81cdeb46c5082404fd52c6fa1afabc5c6b2d47ef",
30
30
  "apps/vendor-hyperliquid/src/services/utils.ts": "a115e2f972368033e6eb7325602092dbd448c9c3",
@@ -41,7 +41,7 @@
41
41
  "libraries/data-order/temp/package-deps.json": "2adac9fc0423f9b1b7ddaa8946ab7af374cc22e1",
42
42
  "libraries/data-series/temp/package-deps.json": "c89ebffe302757903aa54eff78f76cb855486b8c",
43
43
  "libraries/data-quote/temp/package-deps.json": "34d079eab44d2bf65e07b112ac2099c6e92a015e",
44
- "libraries/exchange/temp/package-deps.json": "f5581cbe191fec0a89636d49572d3681dc36570a",
44
+ "libraries/exchange/temp/package-deps.json": "81cd228057e0c05ac9f39d4d22b19a59e9a4792f",
45
45
  "libraries/data-ohlc/temp/package-deps.json": "c0059a14c647112486ad561d730a4427b9f6f832",
46
46
  "libraries/extension/temp/package-deps.json": "9569c553c2f9a7d50b70d8f101fc2d3825aaccb9",
47
47
  "tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"