@yuants/vendor-hyperliquid 0.3.13 → 0.3.14

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/index.js CHANGED
@@ -1,19 +1,15 @@
1
- import { addAccountMarket, publishAccountInfo, } from '@yuants/data-account';
2
- import { encodePath, formatTime } from '@yuants/utils';
3
- import { defer, repeat, retry, shareReplay, tap } from 'rxjs';
1
+ import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';
2
+ import { encodePath } from '@yuants/utils';
4
3
  import { client } from './api';
4
+ import './interest_rate';
5
5
  import './order';
6
6
  import './product';
7
7
  import { terminal } from './terminal';
8
- import './interest_rate';
9
- const memoizeMap = (fn) => {
10
- const cache = {};
11
- return ((...params) => { var _a; var _b; return ((_a = cache[_b = encodePath(params)]) !== null && _a !== void 0 ? _a : (cache[_b] = fn(...params))); });
12
- };
13
8
  (async () => {
14
9
  // swap account info
15
10
  {
16
- const swapAccountInfo$ = defer(async () => {
11
+ const account_id = `Hyperliquid/${client.public_key}`;
12
+ provideAccountInfoService(terminal, account_id, async () => {
17
13
  const accountRes = await client.getUserPerpetualsAccountSummary({
18
14
  user: client.public_key,
19
15
  });
@@ -29,7 +25,6 @@ const memoizeMap = (fn) => {
29
25
  balance: +accountRes.crossMarginSummary.accountValue - profit,
30
26
  };
31
27
  return {
32
- account_id: `Hyperliquid/${client.public_key}`,
33
28
  money: money,
34
29
  positions: accountRes.assetPositions.map((position) => ({
35
30
  position_id: `${position.position.coin}-USD`,
@@ -44,16 +39,8 @@ const memoizeMap = (fn) => {
44
39
  valuation: +position.position.positionValue,
45
40
  margin: +position.position.marginUsed,
46
41
  })),
47
- updated_at: Date.now(),
48
42
  };
49
- }).pipe(
50
- //
51
- tap({
52
- error: (e) => {
53
- console.error(formatTime(Date.now()), 'PerpetualAccountInfo', e);
54
- },
55
- }), retry({ delay: 5000 }), repeat({ delay: 1000 }), shareReplay(1));
56
- publishAccountInfo(terminal, `Hyperliquid/${client.public_key}`, swapAccountInfo$);
43
+ }, { auto_refresh_interval: 1000 });
57
44
  addAccountMarket(terminal, { account_id: `Hyperliquid/${client.public_key}`, market_id: 'Hyperliquid' });
58
45
  }
59
46
  // TODO: spot account info
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAIhB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,SAAS,CAAC;AACjB,OAAO,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,iBAAiB,CAAC;AAEzB,MAAM,UAAU,GAAG,CAAsC,EAAK,EAAK,EAAE;IACnE,MAAM,KAAK,GAAwB,EAAE,CAAC;IACtC,OAAO,CAAC,CAAC,GAAG,MAAa,EAAE,EAAE,mBAAC,OAAA,OAAC,KAAK,MAAC,UAAU,CAAC,MAAM,CAAC,qCAAxB,KAAK,OAAyB,EAAE,CAAC,GAAG,MAAM,CAAC,EAAC,CAAA,EAAA,CAAM,CAAC;AACpF,CAAC,CAAC;AAEF,CAAC,KAAK,IAAI,EAAE;IACV,oBAAoB;IACpB;QACE,MAAM,gBAAgB,GAAG,KAAK,CAAC,KAAK,IAA2B,EAAE;YAC/D,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,+BAA+B,CAAC;gBAC9D,IAAI,EAAE,MAAM,CAAC,UAAW;aACzB,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,UAAU,CAAC,cAAc;iBACrC,GAAG,CAAC,CAAC,GAAG,EA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oBAC1C,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;oBACnF,eAAe,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa;oBACjD,SAAS,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa;oBAC3C,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU;iBACtC,CAAC,CACH;gBACD,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;aACvB,CAAC;QACJ,CAAC,CAAC,CAAC,IAAI;QACL,EAAE;QACF,GAAG,CAAC;YACF,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;gBACX,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,sBAAsB,EAAE,CAAC,CAAC,CAAC;YACnE,CAAC;SACF,CAAC,EACF,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACtB,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACvB,WAAW,CAAC,CAAC,CAAC,CACf,CAAC;QACF,kBAAkB,CAAC,QAAQ,EAAE,eAAe,MAAM,CAAC,UAAU,EAAE,EAAE,gBAAgB,CAAC,CAAC;QACnF,gBAAgB,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,eAAe,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;KAC1G;IAED,0BAA0B;IAE1B,qBAAqB;IAErB,iBAAiB;AACnB,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import {\n addAccountMarket,\n IAccountInfo,\n IAccountMoney,\n IPosition,\n publishAccountInfo,\n} from '@yuants/data-account';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, repeat, retry, shareReplay, tap } from 'rxjs';\nimport { client } from './api';\nimport './order';\nimport './product';\nimport { terminal } from './terminal';\nimport './interest_rate';\n\nconst memoizeMap = <T extends (...params: any[]) => any>(fn: T): T => {\n const cache: Record<string, any> = {};\n return ((...params: any[]) => (cache[encodePath(params)] ??= fn(...params))) as T;\n};\n\n(async () => {\n // swap account info\n {\n const swapAccountInfo$ = defer(async (): Promise<IAccountInfo> => {\n const accountRes = await client.getUserPerpetualsAccountSummary({\n user: client.public_key!,\n });\n\n const profit = accountRes.assetPositions\n .map((pos) => +pos.position.unrealizedPnl)\n .reduce((a, b) => a + b, 0);\n\n const money: IAccountMoney = {\n currency: 'USDC',\n equity: +accountRes.crossMarginSummary.accountValue,\n profit: profit,\n free: +accountRes.withdrawable,\n used: +accountRes.crossMarginSummary.accountValue - +accountRes.withdrawable,\n balance: +accountRes.crossMarginSummary.accountValue - profit,\n };\n\n return {\n account_id: `Hyperliquid/${client.public_key}`,\n money: money,\n positions: accountRes.assetPositions.map(\n (position): IPosition => ({\n position_id: `${position.position.coin}-USD`,\n datasource_id: 'HYPERLIQUID',\n product_id: encodePath('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),\n floating_profit: +position.position.unrealizedPnl,\n valuation: +position.position.positionValue,\n margin: +position.position.marginUsed,\n }),\n ),\n updated_at: Date.now(),\n };\n }).pipe(\n //\n tap({\n error: (e) => {\n console.error(formatTime(Date.now()), 'PerpetualAccountInfo', e);\n },\n }),\n retry({ delay: 5000 }),\n repeat({ delay: 1000 }),\n shareReplay(1),\n );\n publishAccountInfo(terminal, `Hyperliquid/${client.public_key}`, swapAccountInfo$);\n addAccountMarket(terminal, { account_id: `Hyperliquid/${client.public_key}`, market_id: 'Hyperliquid' });\n }\n\n // TODO: spot account info\n\n // TODO: funding rate\n\n // TODO: transfer\n})();\n"]}
1
+ {"version":3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AAC,CAAC,EAAE,CAAC","sourcesContent":["import { addAccountMarket, IAccountMoney, IPosition, provideAccountInfoService } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { client } from './api';\nimport './interest_rate';\nimport './order';\nimport './product';\nimport { terminal } from './terminal';\n\n(async () => {\n // swap account info\n {\n const account_id = `Hyperliquid/${client.public_key}`;\n\n provideAccountInfoService(\n terminal,\n account_id,\n async () => {\n const accountRes = await client.getUserPerpetualsAccountSummary({\n user: client.public_key!,\n });\n\n const profit = accountRes.assetPositions\n .map((pos) => +pos.position.unrealizedPnl)\n .reduce((a, b) => a + b, 0);\n\n const money: IAccountMoney = {\n currency: 'USDC',\n equity: +accountRes.crossMarginSummary.accountValue,\n profit: profit,\n free: +accountRes.withdrawable,\n used: +accountRes.crossMarginSummary.accountValue - +accountRes.withdrawable,\n balance: +accountRes.crossMarginSummary.accountValue - profit,\n };\n\n return {\n money: money,\n positions: accountRes.assetPositions.map(\n (position): IPosition => ({\n position_id: `${position.position.coin}-USD`,\n datasource_id: 'HYPERLIQUID',\n product_id: encodePath('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),\n floating_profit: +position.position.unrealizedPnl,\n valuation: +position.position.positionValue,\n margin: +position.position.marginUsed,\n }),\n ),\n };\n },\n { auto_refresh_interval: 1000 },\n );\n\n addAccountMarket(terminal, { account_id: `Hyperliquid/${client.public_key}`, market_id: 'Hyperliquid' });\n }\n\n // TODO: spot account info\n\n // TODO: funding rate\n\n // TODO: transfer\n})();\n"]}
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
+ import './interest_rate';
1
2
  import './order';
2
3
  import './product';
3
- import './interest_rate';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,SAAS,CAAC;AACjB,OAAO,WAAW,CAAC;AAEnB,OAAO,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,CAAC;AACzB,OAAO,SAAS,CAAC;AACjB,OAAO,WAAW,CAAC"}
package/lib/index.js CHANGED
@@ -2,20 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const data_account_1 = require("@yuants/data-account");
4
4
  const utils_1 = require("@yuants/utils");
5
- const rxjs_1 = require("rxjs");
6
5
  const api_1 = require("./api");
6
+ require("./interest_rate");
7
7
  require("./order");
8
8
  require("./product");
9
9
  const terminal_1 = require("./terminal");
10
- require("./interest_rate");
11
- const memoizeMap = (fn) => {
12
- const cache = {};
13
- return ((...params) => { var _a; var _b; return ((_a = cache[_b = (0, utils_1.encodePath)(params)]) !== null && _a !== void 0 ? _a : (cache[_b] = fn(...params))); });
14
- };
15
10
  (async () => {
16
11
  // swap account info
17
12
  {
18
- const swapAccountInfo$ = (0, rxjs_1.defer)(async () => {
13
+ const account_id = `Hyperliquid/${api_1.client.public_key}`;
14
+ (0, data_account_1.provideAccountInfoService)(terminal_1.terminal, account_id, async () => {
19
15
  const accountRes = await api_1.client.getUserPerpetualsAccountSummary({
20
16
  user: api_1.client.public_key,
21
17
  });
@@ -31,7 +27,6 @@ const memoizeMap = (fn) => {
31
27
  balance: +accountRes.crossMarginSummary.accountValue - profit,
32
28
  };
33
29
  return {
34
- account_id: `Hyperliquid/${api_1.client.public_key}`,
35
30
  money: money,
36
31
  positions: accountRes.assetPositions.map((position) => ({
37
32
  position_id: `${position.position.coin}-USD`,
@@ -46,16 +41,8 @@ const memoizeMap = (fn) => {
46
41
  valuation: +position.position.positionValue,
47
42
  margin: +position.position.marginUsed,
48
43
  })),
49
- updated_at: Date.now(),
50
44
  };
51
- }).pipe(
52
- //
53
- (0, rxjs_1.tap)({
54
- error: (e) => {
55
- console.error((0, utils_1.formatTime)(Date.now()), 'PerpetualAccountInfo', e);
56
- },
57
- }), (0, rxjs_1.retry)({ delay: 5000 }), (0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.shareReplay)(1));
58
- (0, data_account_1.publishAccountInfo)(terminal_1.terminal, `Hyperliquid/${api_1.client.public_key}`, swapAccountInfo$);
45
+ }, { auto_refresh_interval: 1000 });
59
46
  (0, data_account_1.addAccountMarket)(terminal_1.terminal, { account_id: `Hyperliquid/${api_1.client.public_key}`, market_id: 'Hyperliquid' });
60
47
  }
61
48
  // TODO: spot account info
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,uDAM8B;AAC9B,yCAAuD;AACvD,+BAA8D;AAC9D,+BAA+B;AAC/B,mBAAiB;AACjB,qBAAmB;AACnB,yCAAsC;AACtC,2BAAyB;AAEzB,MAAM,UAAU,GAAG,CAAsC,EAAK,EAAK,EAAE;IACnE,MAAM,KAAK,GAAwB,EAAE,CAAC;IACtC,OAAO,CAAC,CAAC,GAAG,MAAa,EAAE,EAAE,mBAAC,OAAA,OAAC,KAAK,MAAC,IAAA,kBAAU,EAAC,MAAM,CAAC,qCAAxB,KAAK,OAAyB,EAAE,CAAC,GAAG,MAAM,CAAC,EAAC,CAAA,EAAA,CAAM,CAAC;AACpF,CAAC,CAAC;AAEF,CAAC,KAAK,IAAI,EAAE;IACV,oBAAoB;IACpB;QACE,MAAM,gBAAgB,GAAG,IAAA,YAAK,EAAC,KAAK,IAA2B,EAAE;YAC/D,MAAM,UAAU,GAAG,MAAM,YAAM,CAAC,+BAA+B,CAAC;gBAC9D,IAAI,EAAE,YAAM,CAAC,UAAW;aACzB,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,UAAU,CAAC,cAAc;iBACrC,GAAG,CAAC,CAAC,GAAG,EAAE,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AO;oBAC1C,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;oBACnF,eAAe,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa;oBACjD,SAAS,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa;oBAC3C,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU;iBACtC,CAAC,CACH;gBACD,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;aACvB,CAAC;QACJ,CAAC,CAAC,CAAC,IAAI;QACL,EAAE;QACF,IAAA,UAAG,EAAC;YACF,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;gBACX,OAAO,CAAC,KAAK,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,sBAAsB,EAAE,CAAC,CAAC,CAAC;YACnE,CAAC;SACF,CAAC,EACF,IAAA,YAAK,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACtB,IAAA,aAAM,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACvB,IAAA,kBAAW,EAAC,CAAC,CAAC,CACf,CAAC;QACF,IAAA,iCAAkB,EAAC,mBAAQ,EAAE,eAAe,YAAM,CAAC,UAAU,EAAE,EAAE,gBAAgB,CAAC,CAAC;QACnF,IAAA,+BAAgB,EAAC,mBAAQ,EAAE,EAAE,UAAU,EAAE,eAAe,YAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;KAC1G;IAED,0BAA0B;IAE1B,qBAAqB;IAErB,iBAAiB;AACnB,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import {\n addAccountMarket,\n IAccountInfo,\n IAccountMoney,\n IPosition,\n publishAccountInfo,\n} from '@yuants/data-account';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, repeat, retry, shareReplay, tap } from 'rxjs';\nimport { client } from './api';\nimport './order';\nimport './product';\nimport { terminal } from './terminal';\nimport './interest_rate';\n\nconst memoizeMap = <T extends (...params: any[]) => any>(fn: T): T => {\n const cache: Record<string, any> = {};\n return ((...params: any[]) => (cache[encodePath(params)] ??= fn(...params))) as T;\n};\n\n(async () => {\n // swap account info\n {\n const swapAccountInfo$ = defer(async (): Promise<IAccountInfo> => {\n const accountRes = await client.getUserPerpetualsAccountSummary({\n user: client.public_key!,\n });\n\n const profit = accountRes.assetPositions\n .map((pos) => +pos.position.unrealizedPnl)\n .reduce((a, b) => a + b, 0);\n\n const money: IAccountMoney = {\n currency: 'USDC',\n equity: +accountRes.crossMarginSummary.accountValue,\n profit: profit,\n free: +accountRes.withdrawable,\n used: +accountRes.crossMarginSummary.accountValue - +accountRes.withdrawable,\n balance: +accountRes.crossMarginSummary.accountValue - profit,\n };\n\n return {\n account_id: `Hyperliquid/${client.public_key}`,\n money: money,\n positions: accountRes.assetPositions.map(\n (position): IPosition => ({\n position_id: `${position.position.coin}-USD`,\n datasource_id: 'HYPERLIQUID',\n product_id: encodePath('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),\n floating_profit: +position.position.unrealizedPnl,\n valuation: +position.position.positionValue,\n margin: +position.position.marginUsed,\n }),\n ),\n updated_at: Date.now(),\n };\n }).pipe(\n //\n tap({\n error: (e) => {\n console.error(formatTime(Date.now()), 'PerpetualAccountInfo', e);\n },\n }),\n retry({ delay: 5000 }),\n repeat({ delay: 1000 }),\n shareReplay(1),\n );\n publishAccountInfo(terminal, `Hyperliquid/${client.public_key}`, swapAccountInfo$);\n addAccountMarket(terminal, { account_id: `Hyperliquid/${client.public_key}`, market_id: 'Hyperliquid' });\n }\n\n // TODO: spot account info\n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{ client } from './api';\nimport './interest_rate';\nimport './order';\nimport './product';\nimport { terminal } from './terminal';\n\n(async () => {\n // swap account info\n {\n const account_id = `Hyperliquid/${client.public_key}`;\n\n provideAccountInfoService(\n terminal,\n account_id,\n async () => {\n const accountRes = await client.getUserPerpetualsAccountSummary({\n user: client.public_key!,\n });\n\n const profit = accountRes.assetPositions\n .map((pos) => +pos.position.unrealizedPnl)\n .reduce((a, b) => a + b, 0);\n\n const money: IAccountMoney = {\n currency: 'USDC',\n equity: +accountRes.crossMarginSummary.accountValue,\n profit: profit,\n free: +accountRes.withdrawable,\n used: +accountRes.crossMarginSummary.accountValue - +accountRes.withdrawable,\n balance: +accountRes.crossMarginSummary.accountValue - profit,\n };\n\n return {\n money: money,\n positions: accountRes.assetPositions.map(\n (position): IPosition => ({\n position_id: `${position.position.coin}-USD`,\n datasource_id: 'HYPERLIQUID',\n product_id: encodePath('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),\n floating_profit: +position.position.unrealizedPnl,\n valuation: +position.position.positionValue,\n margin: +position.position.marginUsed,\n }),\n ),\n };\n },\n { auto_refresh_interval: 1000 },\n );\n\n addAccountMarket(terminal, { account_id: `Hyperliquid/${client.public_key}`, market_id: 'Hyperliquid' });\n }\n\n // TODO: spot account info\n\n // TODO: funding rate\n\n // TODO: transfer\n})();\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-hyperliquid",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "bin": "lib/cli.js",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@yuants/protocol": "0.43.0",
13
13
  "@yuants/transfer": "0.2.15",
14
- "@yuants/data-account": "0.4.3",
14
+ "@yuants/data-account": "0.4.4",
15
15
  "@yuants/utils": "0.8.0",
16
16
  "@yuants/sql": "0.9.6",
17
17
  "@yuants/data-product": "0.2.16",
@@ -1,15 +1,15 @@
1
1
  {
2
- "apps/vendor-hyperliquid/CHANGELOG.json": "067e3ba32631bfcabf3c4415bb4c8efc96a6d566",
3
- "apps/vendor-hyperliquid/CHANGELOG.md": "aab56ac807c6cd20bfcd296fde204cb90e1cf52c",
2
+ "apps/vendor-hyperliquid/CHANGELOG.json": "6aac12208527f4859b7a0359e09b35ee48673321",
3
+ "apps/vendor-hyperliquid/CHANGELOG.md": "cb9bd4e18be941a2af91c1954bbbc9ce699b42b2",
4
4
  "apps/vendor-hyperliquid/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
5
5
  "apps/vendor-hyperliquid/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
6
6
  "apps/vendor-hyperliquid/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
7
7
  "apps/vendor-hyperliquid/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
8
8
  "apps/vendor-hyperliquid/etc/vendor-hyperliquid.api.md": "66675bd88afa1fe945f0d4023984c1c9c3e60a34",
9
- "apps/vendor-hyperliquid/package.json": "6ef4aa169a98878bb365d93507a144ab20f1e22a",
9
+ "apps/vendor-hyperliquid/package.json": "3155117f8d11a35d9832bcbf106909058c7a6cad",
10
10
  "apps/vendor-hyperliquid/src/api.ts": "041aa6e0e322b7c6ea5c822119c695b05d32295a",
11
11
  "apps/vendor-hyperliquid/src/cli.ts": "9bf6b5559a6c6f33da20e74cc6c5d702c60ec891",
12
- "apps/vendor-hyperliquid/src/index.ts": "0b84c433e1cb0c6b718e54f88c213c9d1b632691",
12
+ "apps/vendor-hyperliquid/src/index.ts": "b62e4650a10ea26db3b08caea8f580c7d0c5ee91",
13
13
  "apps/vendor-hyperliquid/src/interest_rate.ts": "5b46f8a4904734d9801e3ddd1146813918e36835",
14
14
  "apps/vendor-hyperliquid/src/ohlc.ts": "b1272944f0ffe8dd77ef9e7e39429efb7d2e5006",
15
15
  "apps/vendor-hyperliquid/src/order.ts": "6f7cce32c4d23ba5defd07b5427672082c1319cd",
@@ -20,7 +20,7 @@
20
20
  "apps/vendor-hyperliquid/.rush/temp/shrinkwrap-deps.json": "d8a15e8163d8abdb142a2024a5b5b13ab444f87b",
21
21
  "libraries/protocol/temp/package-deps.json": "3b8c7d38aeee5cc1b2858530c0bff8904d8326e4",
22
22
  "libraries/transfer/temp/package-deps.json": "55b5e0be5042b445bf9cf2be5b4087baf93de46b",
23
- "libraries/data-account/temp/package-deps.json": "ba272e58df3a56f0f897dc18a1fa7ed1c91699e9",
23
+ "libraries/data-account/temp/package-deps.json": "5eb844c54c6c70d8cdde8bceb2e3ce337ebbe061",
24
24
  "libraries/utils/temp/package-deps.json": "c0ccd6946461153e7eb1b04a3061e075788fad2a",
25
25
  "libraries/sql/temp/package-deps.json": "58c2368f516d411e6849e82620f1969f34db381e",
26
26
  "libraries/data-product/temp/package-deps.json": "54454b1f541b962b2e87f66459d3a2f0cd524d4d",