@yuants/vendor-aster 0.7.23 → 0.7.24

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.
@@ -9,7 +9,7 @@ const asBNBPrice = createCache(() => fetch('https://api.coingecko.com/api/v3/sim
9
9
  .then((data) => data['astherus-staked-bnb'].usd), {
10
10
  expire: 60000, // 1 minute
11
11
  });
12
- const buildSpotProductMap = async () => {
12
+ const spotProductMapCache = createCache(async () => {
13
13
  const products = await listProducts();
14
14
  const map = new Map();
15
15
  for (const product of products) {
@@ -19,7 +19,7 @@ const buildSpotProductMap = async () => {
19
19
  }
20
20
  }
21
21
  return map;
22
- };
22
+ }, { expire: 86400000 });
23
23
  export const getPositions = async (credential) => {
24
24
  var _a, _b, _c, _d, _e;
25
25
  const positions = [];
@@ -27,14 +27,15 @@ export const getPositions = async (credential) => {
27
27
  getApiV1Account(credential, {}),
28
28
  getApiV1TickerPrice(credential, {}),
29
29
  getFApiV4Account(credential, {}),
30
- buildSpotProductMap(),
30
+ spotProductMapCache.query(''),
31
31
  ]);
32
+ const resolvedSpotProductMap = spotProductMap !== null && spotProductMap !== void 0 ? spotProductMap : new Map();
32
33
  for (const b of x.balances) {
33
34
  const thePrice = b.asset === 'USDT' ? 1 : (_b = (_a = prices.find((p) => p.symbol === b.asset + 'USDT')) === null || _a === void 0 ? void 0 : _a.price) !== null && _b !== void 0 ? _b : 0;
34
35
  positions.push(makeSpotPosition({
35
36
  position_id: b.asset,
36
37
  datasource_id: 'ASTER',
37
- product_id: (_c = spotProductMap.get(b.asset)) !== null && _c !== void 0 ? _c : encodePath('ASTER', 'SPOT', b.asset),
38
+ product_id: (_c = resolvedSpotProductMap.get(b.asset)) !== null && _c !== void 0 ? _c : encodePath('ASTER', 'SPOT', b.asset),
38
39
  volume: +b.free + +b.locked,
39
40
  free_volume: +b.free,
40
41
  closable_price: +thePrice,
@@ -1 +1 @@
1
- {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../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CAAC,CAAC,CAAC,YAAY;YAC/F,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YACrC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;YAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;YACtD,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB;YACpC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;SACjC,CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getApiV1Account, getApiV1TickerPrice, getFApiV4Account, ICredential } from '../../api/private-api';\nimport { listProducts } from '../markets/product';\n\n// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko\nconst asBNBPrice = createCache(\n () =>\n fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')\n .then((res) => res.json())\n .then((data) => data['astherus-staked-bnb'].usd as number),\n {\n expire: 60_000, // 1 minute\n },\n);\n\nconst buildSpotProductMap = async () => {\n const products = await listProducts();\n const map = new Map<string, string>();\n for (const product of products) {\n const [, instType] = product.product_id.split('/');\n if (instType === 'SPOT') {\n map.set(product.base_currency, product.product_id);\n }\n }\n return map;\n};\n\nexport const getPositions = async (credential: ICredential) => {\n const positions: IPosition[] = [];\n const [x, prices, prep, spotProductMap] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n getFApiV4Account(credential, {}),\n buildSpotProductMap(),\n ]);\n\n for (const b of x.balances) {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n positions.push(\n makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: spotProductMap.get(b.asset) ?? encodePath('ASTER', 'SPOT', b.asset),\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n }),\n );\n }\n\n for (const b of prep.assets) {\n if (+b.walletBalance === 0) continue;\n let thePrice = 0;\n if (b.asset === 'USDT') {\n thePrice = 1;\n } else if (b.asset === 'ASBNB') {\n const _p = await asBNBPrice.query('').catch(() => 0);\n if (_p) {\n thePrice = _p;\n }\n } else {\n thePrice = +(prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0);\n }\n\n positions.push(\n makeSpotPosition({\n position_id: encodePath(b.asset, 'ASSET'),\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),\n volume: +b.walletBalance,\n free_volume: +b.walletBalance,\n closable_price: thePrice,\n }),\n );\n }\n\n for (const p of prep.positions) {\n if (+p.positionAmt === 0) continue;\n positions.push({\n position_id: p.symbol,\n product_id: encodePath('ASTER', 'PERP', p.symbol),\n datasource_id: 'ASTER',\n direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,\n volume: Math.abs(+p.positionAmt),\n free_volume: Math.abs(+p.positionAmt),\n position_price: +p.entryPrice,\n closable_price: Math.abs(+p.notional / +p.positionAmt),\n floating_profit: +p.unrealizedProfit,\n valuation: Math.abs(+p.notional),\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,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,mB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,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YACrC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;YAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;YACtD,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB;YACpC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;SACjC,CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getApiV1Account, getApiV1TickerPrice, getFApiV4Account, ICredential } from '../../api/private-api';\nimport { listProducts } from '../markets/product';\n\n// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko\nconst asBNBPrice = createCache(\n () =>\n fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')\n .then((res) => res.json())\n .then((data) => data['astherus-staked-bnb'].usd as number),\n {\n expire: 60_000, // 1 minute\n },\n);\n\nconst spotProductMapCache = createCache(\n async () => {\n const products = await listProducts();\n const map = new Map<string, string>();\n for (const product of products) {\n const [, instType] = product.product_id.split('/');\n if (instType === 'SPOT') {\n map.set(product.base_currency, product.product_id);\n }\n }\n return map;\n },\n { expire: 86_400_000 },\n);\n\nexport const getPositions = async (credential: ICredential) => {\n const positions: IPosition[] = [];\n const [x, prices, prep, spotProductMap] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n getFApiV4Account(credential, {}),\n spotProductMapCache.query(''),\n ]);\n\n const resolvedSpotProductMap = spotProductMap ?? new Map<string, string>();\n\n for (const b of x.balances) {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n positions.push(\n makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: resolvedSpotProductMap.get(b.asset) ?? encodePath('ASTER', 'SPOT', b.asset),\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n }),\n );\n }\n\n for (const b of prep.assets) {\n if (+b.walletBalance === 0) continue;\n let thePrice = 0;\n if (b.asset === 'USDT') {\n thePrice = 1;\n } else if (b.asset === 'ASBNB') {\n const _p = await asBNBPrice.query('').catch(() => 0);\n if (_p) {\n thePrice = _p;\n }\n } else {\n thePrice = +(prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0);\n }\n\n positions.push(\n makeSpotPosition({\n position_id: encodePath(b.asset, 'ASSET'),\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),\n volume: +b.walletBalance,\n free_volume: +b.walletBalance,\n closable_price: thePrice,\n }),\n );\n }\n\n for (const p of prep.positions) {\n if (+p.positionAmt === 0) continue;\n positions.push({\n position_id: p.symbol,\n product_id: encodePath('ASTER', 'PERP', p.symbol),\n datasource_id: 'ASTER',\n direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,\n volume: Math.abs(+p.positionAmt),\n free_volume: Math.abs(+p.positionAmt),\n position_price: +p.entryPrice,\n closable_price: Math.abs(+p.notional / +p.positionAmt),\n floating_profit: +p.unrealizedProfit,\n valuation: Math.abs(+p.notional),\n });\n }\n\n return positions;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAA0D,WAAW,EAAE,MAAM,uBAAuB,CAAC;AA0B5G,eAAO,MAAM,YAAY,eAAsB,WAAW,yBAkEzD,CAAC"}
1
+ {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAA0D,WAAW,EAAE,MAAM,uBAAuB,CAAC;AA6B5G,eAAO,MAAM,YAAY,eAAsB,WAAW,yBAoEzD,CAAC"}
@@ -12,7 +12,7 @@ const asBNBPrice = (0, cache_1.createCache)(() => fetch('https://api.coingecko.c
12
12
  .then((data) => data['astherus-staked-bnb'].usd), {
13
13
  expire: 60000, // 1 minute
14
14
  });
15
- const buildSpotProductMap = async () => {
15
+ const spotProductMapCache = (0, cache_1.createCache)(async () => {
16
16
  const products = await (0, product_1.listProducts)();
17
17
  const map = new Map();
18
18
  for (const product of products) {
@@ -22,7 +22,7 @@ const buildSpotProductMap = async () => {
22
22
  }
23
23
  }
24
24
  return map;
25
- };
25
+ }, { expire: 86400000 });
26
26
  const getPositions = async (credential) => {
27
27
  var _a, _b, _c, _d, _e;
28
28
  const positions = [];
@@ -30,14 +30,15 @@ const getPositions = async (credential) => {
30
30
  (0, private_api_1.getApiV1Account)(credential, {}),
31
31
  (0, private_api_1.getApiV1TickerPrice)(credential, {}),
32
32
  (0, private_api_1.getFApiV4Account)(credential, {}),
33
- buildSpotProductMap(),
33
+ spotProductMapCache.query(''),
34
34
  ]);
35
+ const resolvedSpotProductMap = spotProductMap !== null && spotProductMap !== void 0 ? spotProductMap : new Map();
35
36
  for (const b of x.balances) {
36
37
  const thePrice = b.asset === 'USDT' ? 1 : (_b = (_a = prices.find((p) => p.symbol === b.asset + 'USDT')) === null || _a === void 0 ? void 0 : _a.price) !== null && _b !== void 0 ? _b : 0;
37
38
  positions.push((0, data_account_1.makeSpotPosition)({
38
39
  position_id: b.asset,
39
40
  datasource_id: 'ASTER',
40
- product_id: (_c = spotProductMap.get(b.asset)) !== null && _c !== void 0 ? _c : (0, utils_1.encodePath)('ASTER', 'SPOT', b.asset),
41
+ product_id: (_c = resolvedSpotProductMap.get(b.asset)) !== null && _c !== void 0 ? _c : (0, utils_1.encodePath)('ASTER', 'SPOT', b.asset),
41
42
  volume: +b.free + +b.locked,
42
43
  free_volume: +b.free,
43
44
  closable_price: +thePrice,
@@ -1 +1 @@
1
- {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,uDAAmE;AACnE,yCAA2C;AAC3C,uDAA4G;AAC5G,gDAAkD;AAElD,qFAAqF;AACrF,MAAM,UAAU,GAAG,IAAA,mBAAW,EAC5B,GAAG,EAAE,CACH,KAAK,CAAC,yFAAyF,CAAC;KAC7F,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;KACzB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,GAAa,CAAC,EAC9D;IACE,MAAM,EAAE,KAAM,EAAE,WAAW;CAC5B,CACF,CAAC;AAEF,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAY,GAAE,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnD,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;SACpD;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEK,MAAM,YAAY,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;;IAC5D,MAAM,SAAS,GAAgB,EAAE,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C,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;YAC/F,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YACrC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;YAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;YACtD,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB;YACpC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;SACjC,CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAlEW,QAAA,YAAY,gBAkEvB","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getApiV1Account, getApiV1TickerPrice, getFApiV4Account, ICredential } from '../../api/private-api';\nimport { listProducts } from '../markets/product';\n\n// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko\nconst asBNBPrice = createCache(\n () =>\n fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')\n .then((res) => res.json())\n .then((data) => data['astherus-staked-bnb'].usd as number),\n {\n expire: 60_000, // 1 minute\n },\n);\n\nconst buildSpotProductMap = async () => {\n const products = await listProducts();\n const map = new Map<string, string>();\n for (const product of products) {\n const [, instType] = product.product_id.split('/');\n if (instType === 'SPOT') {\n map.set(product.base_currency, product.product_id);\n }\n }\n return map;\n};\n\nexport const getPositions = async (credential: ICredential) => {\n const positions: IPosition[] = [];\n const [x, prices, prep, spotProductMap] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n getFApiV4Account(credential, {}),\n buildSpotProductMap(),\n ]);\n\n for (const b of x.balances) {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n positions.push(\n makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: spotProductMap.get(b.asset) ?? encodePath('ASTER', 'SPOT', b.asset),\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n }),\n );\n }\n\n for (const b of prep.assets) {\n if (+b.walletBalance === 0) continue;\n let thePrice = 0;\n if (b.asset === 'USDT') {\n thePrice = 1;\n } else if (b.asset === 'ASBNB') {\n const _p = await asBNBPrice.query('').catch(() => 0);\n if (_p) {\n thePrice = _p;\n }\n } else {\n thePrice = +(prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0);\n }\n\n positions.push(\n makeSpotPosition({\n position_id: encodePath(b.asset, 'ASSET'),\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),\n volume: +b.walletBalance,\n free_volume: +b.walletBalance,\n closable_price: thePrice,\n }),\n );\n }\n\n for (const p of prep.positions) {\n if (+p.positionAmt === 0) continue;\n positions.push({\n position_id: p.symbol,\n product_id: encodePath('ASTER', 'PERP', p.symbol),\n datasource_id: 'ASTER',\n direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,\n volume: Math.abs(+p.positionAmt),\n free_volume: Math.abs(+p.positionAmt),\n position_price: +p.entryPrice,\n closable_price: Math.abs(+p.notional / +p.positionAmt),\n floating_profit: +p.unrealizedProfit,\n valuation: Math.abs(+p.notional),\n });\n }\n\n return positions;\n};\n"]}
1
+ {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,uDAAmE;AACnE,yCAA2C;AAC3C,uDAA4G;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CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YACrC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;YAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;YACtD,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB;YACpC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;SACjC,CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AApEW,QAAA,YAAY,gBAoEvB","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getApiV1Account, getApiV1TickerPrice, getFApiV4Account, ICredential } from '../../api/private-api';\nimport { listProducts } from '../markets/product';\n\n// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko\nconst asBNBPrice = createCache(\n () =>\n fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')\n .then((res) => res.json())\n .then((data) => data['astherus-staked-bnb'].usd as number),\n {\n expire: 60_000, // 1 minute\n },\n);\n\nconst spotProductMapCache = createCache(\n async () => {\n const products = await listProducts();\n const map = new Map<string, string>();\n for (const product of products) {\n const [, instType] = product.product_id.split('/');\n if (instType === 'SPOT') {\n map.set(product.base_currency, product.product_id);\n }\n }\n return map;\n },\n { expire: 86_400_000 },\n);\n\nexport const getPositions = async (credential: ICredential) => {\n const positions: IPosition[] = [];\n const [x, prices, prep, spotProductMap] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n getFApiV4Account(credential, {}),\n spotProductMapCache.query(''),\n ]);\n\n const resolvedSpotProductMap = spotProductMap ?? new Map<string, string>();\n\n for (const b of x.balances) {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n positions.push(\n makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: resolvedSpotProductMap.get(b.asset) ?? encodePath('ASTER', 'SPOT', b.asset),\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n }),\n );\n }\n\n for (const b of prep.assets) {\n if (+b.walletBalance === 0) continue;\n let thePrice = 0;\n if (b.asset === 'USDT') {\n thePrice = 1;\n } else if (b.asset === 'ASBNB') {\n const _p = await asBNBPrice.query('').catch(() => 0);\n if (_p) {\n thePrice = _p;\n }\n } else {\n thePrice = +(prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0);\n }\n\n positions.push(\n makeSpotPosition({\n position_id: encodePath(b.asset, 'ASSET'),\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),\n volume: +b.walletBalance,\n free_volume: +b.walletBalance,\n closable_price: thePrice,\n }),\n );\n }\n\n for (const p of prep.positions) {\n if (+p.positionAmt === 0) continue;\n positions.push({\n position_id: p.symbol,\n product_id: encodePath('ASTER', 'PERP', p.symbol),\n datasource_id: 'ASTER',\n direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,\n volume: Math.abs(+p.positionAmt),\n free_volume: Math.abs(+p.positionAmt),\n position_price: +p.entryPrice,\n closable_price: Math.abs(+p.notional / +p.positionAmt),\n floating_profit: +p.unrealizedProfit,\n valuation: Math.abs(+p.notional),\n });\n }\n\n return positions;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-aster",
3
- "version": "0.7.23",
3
+ "version": "0.7.24",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "apps/vendor-aster/AGENTS.md": "dcd006d19a5c3b73081525d7c0afea68cd6d058b",
3
- "apps/vendor-aster/CHANGELOG.json": "7841bcca263f924f344b41d7d754a76d2e3242d2",
4
- "apps/vendor-aster/CHANGELOG.md": "30fed97c26f4c5c48a70f3ab4caf3274aca86f49",
5
- "apps/vendor-aster/SESSION_NOTES.md": "9734c99b07dd143cd0a36274f582f746d549fe12",
3
+ "apps/vendor-aster/CHANGELOG.json": "f8ada593c16deebfae2d57a86d1443a753c55c44",
4
+ "apps/vendor-aster/CHANGELOG.md": "fe5f652f06ddbf87443d9be63b38cca91cd10a9d",
5
+ "apps/vendor-aster/SESSION_NOTES.md": "d91f7a251d148fab1715b6da62395455edcb3b93",
6
6
  "apps/vendor-aster/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
7
7
  "apps/vendor-aster/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
8
8
  "apps/vendor-aster/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
9
- "apps/vendor-aster/package.json": "3896d935a2f2a242be339b5b210b397342c1b714",
9
+ "apps/vendor-aster/package.json": "7e99097181be249413aa31f00c08376e99e4e65f",
10
10
  "apps/vendor-aster/src/api/private-api.ts": "71f2f794377a45c64f688a663111318e36463bdb",
11
11
  "apps/vendor-aster/src/api/public-api.ts": "ced2ae976ee7a74a5c1fe704b2c5fb2e25f13ab7",
12
12
  "apps/vendor-aster/src/index.ts": "509ef4c18ec2deb8a6e11ed5682334433cb2bcb2",
13
13
  "apps/vendor-aster/src/services/accounts/profile.ts": "fc57e7d2c865790dd257c043c8dd5cf5c641b7fd",
14
- "apps/vendor-aster/src/services/accounts/spot.ts": "34ec7b03862ab53702ea957942b8217086ee5bb0",
14
+ "apps/vendor-aster/src/services/accounts/spot.ts": "785a165bef3797d5a4e8482d5cc798f2d3eec748",
15
15
  "apps/vendor-aster/src/services/exchange.ts": "71a555ceec0d84b6f12a9c2002834676f1370d51",
16
16
  "apps/vendor-aster/src/services/markets/interest_rate.ts": "8512bb506f3d66b16aceb9d153d1b3a4671de5ef",
17
17
  "apps/vendor-aster/src/services/markets/product.ts": "cae86f69c6f019747ebad07569ed2bc862a78ac6",