@yuants/vendor-huobi 0.14.3 → 0.14.4

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,20 +1,21 @@
1
+ import { makeSpotPosition } from '@yuants/data-account';
1
2
  import { getSpotAccountBalance } from '../api/private-api';
2
3
  import { spotAccountUidCache } from '../uid';
3
4
  export const getSpotAccountInfo = async (credential) => {
4
- var _a, _b;
5
5
  const spotAccountUid = await spotAccountUidCache.query(JSON.stringify(credential));
6
6
  if (!spotAccountUid)
7
7
  throw new Error('Failed to get Spot Account UID');
8
8
  const spotBalance = await getSpotAccountBalance(credential, spotAccountUid);
9
- const equity = +((_b = (_a = spotBalance.data.list.find((v) => v.currency === 'usdt')) === null || _a === void 0 ? void 0 : _a.balance) !== null && _b !== void 0 ? _b : 0);
10
- const free = equity;
11
- return {
12
- money: {
13
- currency: 'USDT',
14
- equity,
15
- free,
16
- },
17
- positions: [],
18
- };
9
+ return spotBalance.data.list.map((v) => {
10
+ var _a, _b;
11
+ return makeSpotPosition({
12
+ position_id: `${v.currency}`,
13
+ datasource_id: 'HTX',
14
+ product_id: `SPOT/${v.currency}-USDT`,
15
+ volume: +((_a = v.balance) !== null && _a !== void 0 ? _a : 0),
16
+ free_volume: +((_b = v.balance) !== null && _b !== void 0 ? _b : 0),
17
+ closable_price: 1, // TODO: 获取现货币对价格
18
+ });
19
+ });
19
20
  };
20
21
  //# sourceMappingURL=spot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../src/accounts/spot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAe,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,CAAC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;;IAClG,MAAM,cAAc,GAAG,MAAM,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACnF,IAAI,CAAC,cAAc;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAE5E,MAAM,MAAM,GAAG,CAAC,CAAC,MAAA,MAAA,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,0CAAE,OAAO,mCAAI,CAAC,CAAC,CAAC;IACzF,MAAM,IAAI,GAAG,MAAM,CAAC;IACpB,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS,EAAE,EAAE;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { spotAccountUidCache } from '../uid';\n\nexport const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const spotAccountUid = await spotAccountUidCache.query(JSON.stringify(credential));\n if (!spotAccountUid) throw new Error('Failed to get Spot Account UID');\n const spotBalance = await getSpotAccountBalance(credential, spotAccountUid);\n\n const equity = +(spotBalance.data.list.find((v) => v.currency === 'usdt')?.balance ?? 0);\n const free = equity;\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions: [],\n };\n};\n"]}
1
+ {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../src/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAe,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,CAAC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,MAAM,cAAc,GAAG,MAAM,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACnF,IAAI,CAAC,cAAc;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAE5E,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;;QACrC,OAAO,gBAAgB,CAAC;YACtB,WAAW,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE;YAC5B,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,OAAO;YACrC,MAAM,EAAE,CAAC,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC;YACzB,WAAW,EAAE,CAAC,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC;YAC9B,cAAc,EAAE,CAAC,EAAE,iBAAiB;SACrC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, makeSpotPosition } from '@yuants/data-account';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { spotAccountUidCache } from '../uid';\n\nexport const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const spotAccountUid = await spotAccountUidCache.query(JSON.stringify(credential));\n if (!spotAccountUid) throw new Error('Failed to get Spot Account UID');\n const spotBalance = await getSpotAccountBalance(credential, spotAccountUid);\n\n return spotBalance.data.list.map((v) => {\n return makeSpotPosition({\n position_id: `${v.currency}`,\n datasource_id: 'HTX',\n product_id: `SPOT/${v.currency}-USDT`,\n volume: +(v.balance ?? 0),\n free_volume: +(v.balance ?? 0),\n closable_price: 1, // TODO: 获取现货币对价格\n });\n });\n};\n"]}
@@ -18,10 +18,6 @@ export const getSuperMarginAccountInfo = async (credential) => {
18
18
  throw new Error('Failed to get Super Margin Account UID');
19
19
  const accountBalance = await getSpotAccountBalance(credential, superMarginAccountUid);
20
20
  const balanceList = ((_a = accountBalance.data) === null || _a === void 0 ? void 0 : _a.list) || [];
21
- // calculate usdt balance
22
- const usdtBalance = balanceList
23
- .filter((v) => v.currency === 'usdt')
24
- .reduce((acc, cur) => acc + +cur.balance, 0);
25
21
  // get positions (non-usdt currencies)
26
22
  const positions = [];
27
23
  const nonUsdtCurrencies = balanceList
@@ -60,15 +56,6 @@ export const getSuperMarginAccountInfo = async (credential) => {
60
56
  }
61
57
  }
62
58
  }
63
- // calculate equity
64
- const equity = positions.reduce((acc, cur) => acc + cur.closable_price * cur.volume, 0) + usdtBalance;
65
- return {
66
- money: {
67
- currency: 'USDT',
68
- equity,
69
- free: equity,
70
- },
71
- positions,
72
- };
59
+ return positions;
73
60
  };
74
61
  //# sourceMappingURL=super-margin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"super-margin.js","sourceRoot":"","sources":["../../src/accounts/super-margin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAe,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAC;AAEpD,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,QAAQ,MAAM,EAAE,CAAC,EAAE;IAC1F,MAAM,EAAE,MAAO;IACf,QAAQ,EAAE,KAAM,EAAE,aAAa;CAChC,CAAC,CAAC;AAEH;;GAEG;AACH,MA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YAChB,MAAM;YACN,IAAI,EAAE,MAAM;SACb;QACD,SAAS;KACV,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { formatTime } from '@yuants/utils';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { getSpotTick } from '../api/public-api';\nimport { superMarginAccountUidCache } from '../uid';\n\nconst spotTickCache = createCache((currency) => getSpotTick({ symbol: `${currency}usdt` }), {\n expire: 300_000, // 5 minutes\n swrAfter: 10_000, // 10 seconds\n});\n\n/**\n * 全仓杠杆账户 (Super Margin Account)\n */\nexport const getSuperMarginAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n // get account balance\n const superMarginAccountUid = await superMarginAccountUidCache.query(JSON.stringify(credential));\n if (!superMarginAccountUid) throw new Error('Failed to get Super Margin Account UID');\n const accountBalance = await getSpotAccountBalance(credential, superMarginAccountUid);\n const balanceList = accountBalance.data?.list || [];\n\n // calculate usdt balance\n const usdtBalance = balanceList\n .filter((v) => v.currency === 'usdt')\n .reduce((acc, cur) => acc + +cur.balance, 0);\n\n // get positions (non-usdt currencies)\n const positions: IPosition[] = [];\n const nonUsdtCurrencies = balanceList\n .filter((v) => v.currency !== 'usdt')\n .reduce((acc, cur) => {\n const existing = acc.find((item) => item.currency === cur.currency);\n if (existing) {\n existing.balance += +cur.balance;\n } else {\n acc.push({ currency: cur.currency, balance: +cur.balance });\n }\n return acc;\n }, [] as { currency: string; balance: number }[]);\n\n // get prices and create positions\n for (const currencyData of nonUsdtCurrencies) {\n if (currencyData.balance > 0) {\n const tickerRes = await spotTickCache.query(currencyData.currency);\n const price = tickerRes?.tick.close || 0;\n try {\n // get current price from websocket or fallback to REST API\n\n positions.push({\n position_id: `${currencyData.currency}/usdt/spot`,\n product_id: `${currencyData.currency}usdt`,\n direction: 'LONG',\n volume: currencyData.balance,\n free_volume: currencyData.balance,\n position_price: price,\n closable_price: price,\n floating_profit: 0,\n valuation: currencyData.balance * price,\n });\n } catch (error) {\n console.warn(formatTime(Date.now()), `Failed to get price for ${currencyData.currency}:`, error);\n }\n }\n }\n\n // calculate equity\n const equity = positions.reduce((acc, cur) => acc + cur.closable_price * cur.volume, 0) + usdtBalance;\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free: equity,\n },\n positions,\n };\n};\n"]}
1
+ {"version":3,"file":"super-margin.js","sourceRoot":"","sources":["../../src/accounts/super-margin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAe,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAC;AAEpD,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,QAAQ,MAAM,EAAE,CAAC,EAAE;IAC1F,MAAM,EAAE,MAAO;IACf,QAAQ,EAAE,KAAM,EAAE,aAAa;CAChC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;;IACzG,sBAAsB;IACtB,MAAM,qBAAqB,GAAG,MAAM,0BAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACjG,IAAI,CAAC,qBAAqB;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACtF,MAAM,cAAc,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC;IACtF,MAAM,WAAW,GAAG,CAAA,MAAA,cAAc,CAAC,IAAI,0CAAE,IAAI,KAAI,EAAE,C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EAAE,KAAK;oBACrB,cAAc,EAAE,KAAK;oBACrB,eAAe,EAAE,CAAC;oBAClB,SAAS,EAAE,YAAY,CAAC,OAAO,GAAG,KAAK;iBACxC,CAAC,CAAC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,2BAA2B,YAAY,CAAC,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;aAClG;SACF;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { formatTime } from '@yuants/utils';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { getSpotTick } from '../api/public-api';\nimport { superMarginAccountUidCache } from '../uid';\n\nconst spotTickCache = createCache((currency) => getSpotTick({ symbol: `${currency}usdt` }), {\n expire: 300_000, // 5 minutes\n swrAfter: 10_000, // 10 seconds\n});\n\n/**\n * 全仓杠杆账户 (Super Margin Account)\n */\nexport const getSuperMarginAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n // get account balance\n const superMarginAccountUid = await superMarginAccountUidCache.query(JSON.stringify(credential));\n if (!superMarginAccountUid) throw new Error('Failed to get Super Margin Account UID');\n const accountBalance = await getSpotAccountBalance(credential, superMarginAccountUid);\n const balanceList = accountBalance.data?.list || [];\n\n // get positions (non-usdt currencies)\n const positions: IPosition[] = [];\n const nonUsdtCurrencies = balanceList\n .filter((v) => v.currency !== 'usdt')\n .reduce((acc, cur) => {\n const existing = acc.find((item) => item.currency === cur.currency);\n if (existing) {\n existing.balance += +cur.balance;\n } else {\n acc.push({ currency: cur.currency, balance: +cur.balance });\n }\n return acc;\n }, [] as { currency: string; balance: number }[]);\n\n // get prices and create positions\n for (const currencyData of nonUsdtCurrencies) {\n if (currencyData.balance > 0) {\n const tickerRes = await spotTickCache.query(currencyData.currency);\n const price = tickerRes?.tick.close || 0;\n try {\n // get current price from websocket or fallback to REST API\n\n positions.push({\n position_id: `${currencyData.currency}/usdt/spot`,\n product_id: `${currencyData.currency}usdt`,\n direction: 'LONG',\n volume: currencyData.balance,\n free_volume: currencyData.balance,\n position_price: price,\n closable_price: price,\n floating_profit: 0,\n valuation: currencyData.balance * price,\n });\n } catch (error) {\n console.warn(formatTime(Date.now()), `Failed to get price for ${currencyData.currency}:`, error);\n }\n }\n }\n\n return positions;\n};\n"]}
@@ -75,13 +75,6 @@ export const getSwapAccountInfo = async (credential) => {
75
75
  // orders.push(...pageOrders);
76
76
  // page_index++;
77
77
  // }
78
- return {
79
- money: {
80
- currency: 'USDT',
81
- equity,
82
- free,
83
- },
84
- positions,
85
- };
78
+ return positions;
86
79
  };
87
80
  //# sourceMappingURL=swap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"swap.js","sourceRoot":"","sources":["../../src/accounts/swap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAe,MAAM,oBAAoB,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,CAAC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,UAAU;IACV,MAAM,OAAO,GAAG,MAAM,qBAAqB,CAAC,UAAU,CAAC,CAAC;IACxD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;KACvD;IACD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,MAAM,CAAC,CAAC;IACxE,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC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;IACjB,iFAAiF;IACjF,yEAAyE;IACzE,aAAa;IACb,MAAM;IAEN,4EAA4E;IAC5E,eAAe;IACf,kCAAkC;IAClC,qCAAqC;IACrC,qCAAqC;IACrC,+DAA+D;IAC/D,qBAAqB;IACrB,kGAAkG;IAClG,kCAAkC;IAClC,cAAc;IACd,oBAAoB;IACpB,iDAAiD;IACjD,kBAAkB;IAClB,+CAA+C;IAC/C,kBAAkB;IAClB,wCAAwC;IACxC,yBAAyB;IACzB,iCAAiC;IACjC,iCAAiC;IACjC,4BAA4B;IAC5B,6BAA6B;IAC7B,iCAAiC;IACjC,4BAA4B;IAC5B,4BAA4B;IAC5B,0BAA0B;IAC1B,iCAAiC;IACjC,wBAAwB;IACxB,uCAAuC;IACvC,SAAS;IACT,QAAQ;IAER,gCAAgC;IAChC,kBAAkB;IAClB,IAAI;IAEJ,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS;KACV,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { getSwapCrossPositionInfo, getUnifiedAccountInfo, ICredential } from '../api/private-api';\nimport { swapProductService } from '../product';\n\nexport const getSwapAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n // balance\n const balance = await getUnifiedAccountInfo(credential);\n if (!balance.data) {\n throw new Error('Failed to get unified account info');\n }\n const balanceData = balance.data.find((v) => v.margin_asset === 'USDT');\n if (!balanceData) {\n throw new Error('No USDT balance found in unified account');\n }\n const equity = balanceData.margin_balance;\n const free = balanceData.withdraw_available;\n\n // positions\n const positionsRes = await getSwapCrossPositionInfo(credential);\n const mapProductIdToPerpetualProduct = await firstValueFrom(swapProductService.mapProductIdToProduct$);\n const positions: IPosition[] = (positionsRes.data || []).map((v): IPosition => {\n const product_id = v.contract_code;\n const theProduct = mapProductIdToPerpetualProduct?.get(product_id);\n const valuation = v.volume * v.last_price * (theProduct?.value_scale || 1);\n return {\n position_id: `${v.contract_code}/${v.contract_type}/${v.direction}/${v.margin_mode}`,\n datasource_id: 'HUOBI-SWAP',\n product_id,\n direction: v.direction === 'buy' ? 'LONG' : 'SHORT',\n volume: v.volume,\n free_volume: v.available,\n position_price: v.cost_hold,\n closable_price: v.last_price,\n floating_profit: v.profit_unreal,\n valuation,\n };\n });\n\n // orders\n // const orders: IOrder[] = [];\n // let page_index = 1;\n // const page_size = 50;\n\n // while (true) {\n // const ordersRes = await client.getSwapOpenOrders({ page_index, page_size });\n // if (!ordersRes.data?.orders || ordersRes.data.orders.length === 0) {\n // break;\n // }\n\n // const pageOrders: IOrder[] = ordersRes.data.orders.map((v): IOrder => {\n // return {\n // order_id: v.order_id_str,\n // account_id: SWAP_ACCOUNT_ID,\n // product_id: v.contract_code,\n // order_type: ['lightning'].includes(v.order_price_type)\n // ? 'MARKET'\n // : ['limit', 'opponent', 'post_only', 'optimal_5', 'optimal_10', 'optimal_20'].includes(\n // v.order_price_type,\n // )\n // ? 'LIMIT'\n // : ['fok'].includes(v.order_price_type)\n // ? 'FOK'\n // : v.order_price_type.includes('ioc')\n // ? 'IOC'\n // : 'STOP', // unreachable code\n // order_direction:\n // v.direction === 'open'\n // ? v.offset === 'buy'\n // ? 'OPEN_LONG'\n // : 'OPEN_SHORT'\n // : v.offset === 'buy'\n // ? 'CLOSE_SHORT'\n // : 'CLOSE_LONG',\n // volume: v.volume,\n // submit_at: v.created_at,\n // price: v.price,\n // traded_volume: v.trade_volume,\n // };\n // });\n\n // orders.push(...pageOrders);\n // page_index++;\n // }\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n};\n"]}
1
+ {"version":3,"file":"swap.js","sourceRoot":"","sources":["../../src/accounts/swap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,qBA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,EAAE,GAAG,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,WAAW,EAAE;YACpF,aAAa,EAAE,YAAY;YAC3B,UAAU;YACV,SAAS,EAAE,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;YACnD,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,WAAW,EAAE,CAAC,CAAC,SAAS;YACxB,cAAc,EAAE,CAAC,CAAC,SAAS;YAC3B,cAAc,EAAE,CAAC,CAAC,UAAU;YAC5B,eAAe,EAAE,CAAC,CAAC,aAAa;YAChC,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,SAAS;IACT,+BAA+B;IAC/B,sBAAsB;IACtB,wBAAwB;IAExB,iBAAiB;IACjB,iFAAiF;IACjF,yEAAyE;IACzE,aAAa;IACb,MAAM;IAEN,4EAA4E;IAC5E,eAAe;IACf,kCAAkC;IAClC,qCAAqC;IACrC,qCAAqC;IACrC,+DAA+D;IAC/D,qBAAqB;IACrB,kGAAkG;IAClG,kCAAkC;IAClC,cAAc;IACd,oBAAoB;IACpB,iDAAiD;IACjD,kBAAkB;IAClB,+CAA+C;IAC/C,kBAAkB;IAClB,wCAAwC;IACxC,yBAAyB;IACzB,iCAAiC;IACjC,iCAAiC;IACjC,4BAA4B;IAC5B,6BAA6B;IAC7B,iCAAiC;IACjC,4BAA4B;IAC5B,4BAA4B;IAC5B,0BAA0B;IAC1B,iCAAiC;IACjC,wBAAwB;IACxB,uCAAuC;IACvC,SAAS;IACT,QAAQ;IAER,gCAAgC;IAChC,kBAAkB;IAClB,IAAI;IAEJ,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { getSwapCrossPositionInfo, getUnifiedAccountInfo, ICredential } from '../api/private-api';\nimport { swapProductService } from '../product';\n\nexport const getSwapAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n // balance\n const balance = await getUnifiedAccountInfo(credential);\n if (!balance.data) {\n throw new Error('Failed to get unified account info');\n }\n const balanceData = balance.data.find((v) => v.margin_asset === 'USDT');\n if (!balanceData) {\n throw new Error('No USDT balance found in unified account');\n }\n const equity = balanceData.margin_balance;\n const free = balanceData.withdraw_available;\n\n // positions\n const positionsRes = await getSwapCrossPositionInfo(credential);\n const mapProductIdToPerpetualProduct = await firstValueFrom(swapProductService.mapProductIdToProduct$);\n const positions: IPosition[] = (positionsRes.data || []).map((v): IPosition => {\n const product_id = v.contract_code;\n const theProduct = mapProductIdToPerpetualProduct?.get(product_id);\n const valuation = v.volume * v.last_price * (theProduct?.value_scale || 1);\n return {\n position_id: `${v.contract_code}/${v.contract_type}/${v.direction}/${v.margin_mode}`,\n datasource_id: 'HUOBI-SWAP',\n product_id,\n direction: v.direction === 'buy' ? 'LONG' : 'SHORT',\n volume: v.volume,\n free_volume: v.available,\n position_price: v.cost_hold,\n closable_price: v.last_price,\n floating_profit: v.profit_unreal,\n valuation,\n };\n });\n\n // orders\n // const orders: IOrder[] = [];\n // let page_index = 1;\n // const page_size = 50;\n\n // while (true) {\n // const ordersRes = await client.getSwapOpenOrders({ page_index, page_size });\n // if (!ordersRes.data?.orders || ordersRes.data.orders.length === 0) {\n // break;\n // }\n\n // const pageOrders: IOrder[] = ordersRes.data.orders.map((v): IOrder => {\n // return {\n // order_id: v.order_id_str,\n // account_id: SWAP_ACCOUNT_ID,\n // product_id: v.contract_code,\n // order_type: ['lightning'].includes(v.order_price_type)\n // ? 'MARKET'\n // : ['limit', 'opponent', 'post_only', 'optimal_5', 'optimal_10', 'optimal_20'].includes(\n // v.order_price_type,\n // )\n // ? 'LIMIT'\n // : ['fok'].includes(v.order_price_type)\n // ? 'FOK'\n // : v.order_price_type.includes('ioc')\n // ? 'IOC'\n // : 'STOP', // unreachable code\n // order_direction:\n // v.direction === 'open'\n // ? v.offset === 'buy'\n // ? 'OPEN_LONG'\n // : 'OPEN_SHORT'\n // : v.offset === 'buy'\n // ? 'CLOSE_SHORT'\n // : 'CLOSE_LONG',\n // volume: v.volume,\n // submit_at: v.created_at,\n // price: v.price,\n // traded_volume: v.trade_volume,\n // };\n // });\n\n // orders.push(...pageOrders);\n // page_index++;\n // }\n\n return positions;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../src/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAyB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGxE,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAe1E,CAAC"}
1
+ {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../src/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAoB,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAyB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGxE,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAe1E,CAAC"}
@@ -1,24 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSpotAccountInfo = void 0;
4
+ const data_account_1 = require("@yuants/data-account");
4
5
  const private_api_1 = require("../api/private-api");
5
6
  const uid_1 = require("../uid");
6
7
  const getSpotAccountInfo = async (credential) => {
7
- var _a, _b;
8
8
  const spotAccountUid = await uid_1.spotAccountUidCache.query(JSON.stringify(credential));
9
9
  if (!spotAccountUid)
10
10
  throw new Error('Failed to get Spot Account UID');
11
11
  const spotBalance = await (0, private_api_1.getSpotAccountBalance)(credential, spotAccountUid);
12
- const equity = +((_b = (_a = spotBalance.data.list.find((v) => v.currency === 'usdt')) === null || _a === void 0 ? void 0 : _a.balance) !== null && _b !== void 0 ? _b : 0);
13
- const free = equity;
14
- return {
15
- money: {
16
- currency: 'USDT',
17
- equity,
18
- free,
19
- },
20
- positions: [],
21
- };
12
+ return spotBalance.data.list.map((v) => {
13
+ var _a, _b;
14
+ return (0, data_account_1.makeSpotPosition)({
15
+ position_id: `${v.currency}`,
16
+ datasource_id: 'HTX',
17
+ product_id: `SPOT/${v.currency}-USDT`,
18
+ volume: +((_a = v.balance) !== null && _a !== void 0 ? _a : 0),
19
+ free_volume: +((_b = v.balance) !== null && _b !== void 0 ? _b : 0),
20
+ closable_price: 1, // TODO: 获取现货币对价格
21
+ });
22
+ });
22
23
  };
23
24
  exports.getSpotAccountInfo = getSpotAccountInfo;
24
25
  //# sourceMappingURL=spot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../src/accounts/spot.ts"],"names":[],"mappings":";;;AACA,oDAAwE;AACxE,gCAA6C;AAEtC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;;IAClG,MAAM,cAAc,GAAG,MAAM,yBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACnF,IAAI,CAAC,cAAc;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAE5E,MAAM,MAAM,GAAG,CAAC,CAAC,MAAA,MAAA,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,0CAAE,OAAO,mCAAI,CAAC,CAAC,CAAC;IACzF,MAAM,IAAI,GAAG,MAAM,CAAC;IACpB,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS,EAAE,EAAE;KACd,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,kBAAkB,sBAe7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { spotAccountUidCache } from '../uid';\n\nexport const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const spotAccountUid = await spotAccountUidCache.query(JSON.stringify(credential));\n if (!spotAccountUid) throw new Error('Failed to get Spot Account UID');\n const spotBalance = await getSpotAccountBalance(credential, spotAccountUid);\n\n const equity = +(spotBalance.data.list.find((v) => v.currency === 'usdt')?.balance ?? 0);\n const free = equity;\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions: [],\n };\n};\n"]}
1
+ {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../src/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAwF;AACxF,oDAAwE;AACxE,gCAA6C;AAEtC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,MAAM,cAAc,GAAG,MAAM,yBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACnF,IAAI,CAAC,cAAc;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAE5E,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;;QACrC,OAAO,IAAA,+BAAgB,EAAC;YACtB,WAAW,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE;YAC5B,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,OAAO;YACrC,MAAM,EAAE,CAAC,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC;YACzB,WAAW,EAAE,CAAC,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC;YAC9B,cAAc,EAAE,CAAC,EAAE,iBAAiB;SACrC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAfW,QAAA,kBAAkB,sBAe7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, makeSpotPosition } from '@yuants/data-account';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { spotAccountUidCache } from '../uid';\n\nexport const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const spotAccountUid = await spotAccountUidCache.query(JSON.stringify(credential));\n if (!spotAccountUid) throw new Error('Failed to get Spot Account UID');\n const spotBalance = await getSpotAccountBalance(credential, spotAccountUid);\n\n return spotBalance.data.list.map((v) => {\n return makeSpotPosition({\n position_id: `${v.currency}`,\n datasource_id: 'HTX',\n product_id: `SPOT/${v.currency}-USDT`,\n volume: +(v.balance ?? 0),\n free_volume: +(v.balance ?? 0),\n closable_price: 1, // TODO: 获取现货币对价格\n });\n });\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"super-margin.d.ts","sourceRoot":"","sources":["../../src/accounts/super-margin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAyB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AASxE;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,8BAA8B,CAAC,WAAW,CA8DjF,CAAC"}
1
+ {"version":3,"file":"super-margin.d.ts","sourceRoot":"","sources":["../../src/accounts/super-margin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAyB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AASxE;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,8BAA8B,CAAC,WAAW,CA+CjF,CAAC"}
@@ -21,10 +21,6 @@ const getSuperMarginAccountInfo = async (credential) => {
21
21
  throw new Error('Failed to get Super Margin Account UID');
22
22
  const accountBalance = await (0, private_api_1.getSpotAccountBalance)(credential, superMarginAccountUid);
23
23
  const balanceList = ((_a = accountBalance.data) === null || _a === void 0 ? void 0 : _a.list) || [];
24
- // calculate usdt balance
25
- const usdtBalance = balanceList
26
- .filter((v) => v.currency === 'usdt')
27
- .reduce((acc, cur) => acc + +cur.balance, 0);
28
24
  // get positions (non-usdt currencies)
29
25
  const positions = [];
30
26
  const nonUsdtCurrencies = balanceList
@@ -63,16 +59,7 @@ const getSuperMarginAccountInfo = async (credential) => {
63
59
  }
64
60
  }
65
61
  }
66
- // calculate equity
67
- const equity = positions.reduce((acc, cur) => acc + cur.closable_price * cur.volume, 0) + usdtBalance;
68
- return {
69
- money: {
70
- currency: 'USDT',
71
- equity,
72
- free: equity,
73
- },
74
- positions,
75
- };
62
+ return positions;
76
63
  };
77
64
  exports.getSuperMarginAccountInfo = getSuperMarginAccountInfo;
78
65
  //# sourceMappingURL=super-margin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"super-margin.js","sourceRoot":"","sources":["../../src/accounts/super-margin.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,yCAA2C;AAC3C,oDAAwE;AACxE,kDAAgD;AAChD,gCAAoD;AAEpD,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,wBAAW,EAAC,EAAE,MAAM,EAAE,GAAG,QAAQ,MAAM,EAAE,CAAC,EAAE;IAC1F,MAAM,EAAE,MAAO;IACf,QAAQ,EAAE,KAAM,EAAE,aAAa;CAChC,CAAC,CAAC;AAEH;;GAEG;AACI,MAAM,yBAAyB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;;IACzG,sBAAsB;IACtB,MAAM,qBAAqB,GAAG,MAAM,gCAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,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nimport { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { formatTime } from '@yuants/utils';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { getSpotTick } from '../api/public-api';\nimport { superMarginAccountUidCache } from '../uid';\n\nconst spotTickCache = createCache((currency) => getSpotTick({ symbol: `${currency}usdt` }), {\n expire: 300_000, // 5 minutes\n swrAfter: 10_000, // 10 seconds\n});\n\n/**\n * 全仓杠杆账户 (Super Margin Account)\n */\nexport const getSuperMarginAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n // get account balance\n const superMarginAccountUid = await superMarginAccountUidCache.query(JSON.stringify(credential));\n if (!superMarginAccountUid) throw new Error('Failed to get Super Margin Account UID');\n const accountBalance = await getSpotAccountBalance(credential, superMarginAccountUid);\n const balanceList = accountBalance.data?.list || [];\n\n // calculate usdt balance\n const usdtBalance = balanceList\n .filter((v) => v.currency === 'usdt')\n .reduce((acc, cur) => acc + +cur.balance, 0);\n\n // get positions (non-usdt currencies)\n const positions: IPosition[] = [];\n const nonUsdtCurrencies = balanceList\n .filter((v) => v.currency !== 'usdt')\n .reduce((acc, cur) => {\n const existing = acc.find((item) => item.currency === cur.currency);\n if (existing) {\n existing.balance += +cur.balance;\n } else {\n acc.push({ currency: cur.currency, balance: +cur.balance });\n }\n return acc;\n }, [] as { currency: string; balance: number }[]);\n\n // get prices and create positions\n for (const currencyData of nonUsdtCurrencies) {\n if (currencyData.balance > 0) {\n const tickerRes = await spotTickCache.query(currencyData.currency);\n const price = tickerRes?.tick.close || 0;\n try {\n // get current price from websocket or fallback to REST API\n\n positions.push({\n position_id: `${currencyData.currency}/usdt/spot`,\n product_id: `${currencyData.currency}usdt`,\n direction: 'LONG',\n volume: currencyData.balance,\n free_volume: currencyData.balance,\n position_price: price,\n closable_price: price,\n floating_profit: 0,\n valuation: currencyData.balance * price,\n });\n } catch (error) {\n console.warn(formatTime(Date.now()), `Failed to get price for ${currencyData.currency}:`, error);\n }\n }\n }\n\n // calculate equity\n const equity = positions.reduce((acc, cur) => acc + cur.closable_price * cur.volume, 0) + usdtBalance;\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free: equity,\n },\n positions,\n };\n};\n"]}
1
+ {"version":3,"file":"super-margin.js","sourceRoot":"","sources":["../../src/accounts/super-margin.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,yCAA2C;AAC3C,oDAAwE;AACxE,kDAAgD;AAChD,gCAAoD;AAEpD,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,wBAAW,EAAC,EAAE,MAAM,EAAE,GAAG,QAAQ,MAAM,EAAE,CAAC,EAAE;IAC1F,MAAM,EAAE,MAAO;IACf,QAAQ,EAAE,KAAM,EAAE,aAAa;CAChC,CAAC,CAAC;AAEH;;GAEG;AACI,MAAM,yBAAyB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;;IACzG,sBAAsB;IACtB,MAAM,qBAAqB,GAAG,MAAM,gCAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACjG,IAAI,CAAC,qBAAqB;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACtF,MAAM,cAAc,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC;IACtF,MAAM,WAAW,GAAG,CAAA,MAAA,cAAc,CAAC,IAAI,0CAAE,IAAI,KAAI,EAAE,CAAC;IAEpD,sCAAsC;IACtC,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,MAAM,iBAAiB,GAAG,WAAW;SAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;SACpC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAC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G,EAAE,KAAK,CAAC,CAAC;aAClG;SACF;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AA/CW,QAAA,yBAAyB,6BA+CpC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { formatTime } from '@yuants/utils';\nimport { getSpotAccountBalance, ICredential } from '../api/private-api';\nimport { getSpotTick } from '../api/public-api';\nimport { superMarginAccountUidCache } from '../uid';\n\nconst spotTickCache = createCache((currency) => getSpotTick({ symbol: `${currency}usdt` }), {\n expire: 300_000, // 5 minutes\n swrAfter: 10_000, // 10 seconds\n});\n\n/**\n * 全仓杠杆账户 (Super Margin Account)\n */\nexport const getSuperMarginAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n // get account balance\n const superMarginAccountUid = await superMarginAccountUidCache.query(JSON.stringify(credential));\n if (!superMarginAccountUid) throw new Error('Failed to get Super Margin Account UID');\n const accountBalance = await getSpotAccountBalance(credential, superMarginAccountUid);\n const balanceList = accountBalance.data?.list || [];\n\n // get positions (non-usdt currencies)\n const positions: IPosition[] = [];\n const nonUsdtCurrencies = balanceList\n .filter((v) => v.currency !== 'usdt')\n .reduce((acc, cur) => {\n const existing = acc.find((item) => item.currency === cur.currency);\n if (existing) {\n existing.balance += +cur.balance;\n } else {\n acc.push({ currency: cur.currency, balance: +cur.balance });\n }\n return acc;\n }, [] as { currency: string; balance: number }[]);\n\n // get prices and create positions\n for (const currencyData of nonUsdtCurrencies) {\n if (currencyData.balance > 0) {\n const tickerRes = await spotTickCache.query(currencyData.currency);\n const price = tickerRes?.tick.close || 0;\n try {\n // get current price from websocket or fallback to REST API\n\n positions.push({\n position_id: `${currencyData.currency}/usdt/spot`,\n product_id: `${currencyData.currency}usdt`,\n direction: 'LONG',\n volume: currencyData.balance,\n free_volume: currencyData.balance,\n position_price: price,\n closable_price: price,\n floating_profit: 0,\n valuation: currencyData.balance * price,\n });\n } catch (error) {\n console.warn(formatTime(Date.now()), `Failed to get price for ${currencyData.currency}:`, error);\n }\n }\n }\n\n return positions;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../../src/accounts/swap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAmD,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGlG,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAwF1E,CAAC"}
1
+ {"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../../src/accounts/swap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAmD,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGlG,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAiF1E,CAAC"}
@@ -78,14 +78,7 @@ const getSwapAccountInfo = async (credential) => {
78
78
  // orders.push(...pageOrders);
79
79
  // page_index++;
80
80
  // }
81
- return {
82
- money: {
83
- currency: 'USDT',
84
- equity,
85
- free,
86
- },
87
- positions,
88
- };
81
+ return positions;
89
82
  };
90
83
  exports.getSwapAccountInfo = getSwapAccountInfo;
91
84
  //# sourceMappingURL=swap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"swap.js","sourceRoot":"","sources":["../../src/accounts/swap.ts"],"names":[],"mappings":";;;AACA,+BAAsC;AACtC,oDAAkG;AAClG,wCAAgD;AAEzC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,UAAU;IACV,MAAM,OAAO,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,CAAC,CAAC;IACxD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;KACvD;IACD,MAAM,WAAW,GAAG,OAAO,CA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,SAAS;YAC3B,cAAc,EAAE,CAAC,CAAC,UAAU;YAC5B,eAAe,EAAE,CAAC,CAAC,aAAa;YAChC,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,SAAS;IACT,+BAA+B;IAC/B,sBAAsB;IACtB,wBAAwB;IAExB,iBAAiB;IACjB,iFAAiF;IACjF,yEAAyE;IACzE,aAAa;IACb,MAAM;IAEN,4EAA4E;IAC5E,eAAe;IACf,kCAAkC;IAClC,qCAAqC;IACrC,qCAAqC;IACrC,+DAA+D;IAC/D,qBAAqB;IACrB,kGAAkG;IAClG,kCAAkC;IAClC,cAAc;IACd,oBAAoB;IACpB,iDAAiD;IACjD,kBAAkB;IAClB,+CAA+C;IAC/C,kBAAkB;IAClB,wCAAwC;IACxC,yBAAyB;IACzB,iCAAiC;IACjC,iCAAiC;IACjC,4BAA4B;IAC5B,6BAA6B;IAC7B,iCAAiC;IACjC,4BAA4B;IAC5B,4BAA4B;IAC5B,0BAA0B;IAC1B,iCAAiC;IACjC,wBAAwB;IACxB,uCAAuC;IACvC,SAAS;IACT,QAAQ;IAER,gCAAgC;IAChC,kBAAkB;IAClB,IAAI;IAEJ,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS;KACV,CAAC;AACJ,CAAC,CAAC;AAxFW,QAAA,kBAAkB,sBAwF7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { getSwapCrossPositionInfo, getUnifiedAccountInfo, ICredential } from '../api/private-api';\nimport { swapProductService } from '../product';\n\nexport const getSwapAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n // balance\n const balance = await getUnifiedAccountInfo(credential);\n if (!balance.data) {\n throw new Error('Failed to get unified account info');\n }\n const balanceData = balance.data.find((v) => v.margin_asset === 'USDT');\n if (!balanceData) {\n throw new Error('No USDT balance found in unified account');\n }\n const equity = balanceData.margin_balance;\n const free = balanceData.withdraw_available;\n\n // positions\n const positionsRes = await getSwapCrossPositionInfo(credential);\n const mapProductIdToPerpetualProduct = await firstValueFrom(swapProductService.mapProductIdToProduct$);\n const positions: IPosition[] = (positionsRes.data || []).map((v): IPosition => {\n const product_id = v.contract_code;\n const theProduct = mapProductIdToPerpetualProduct?.get(product_id);\n const valuation = v.volume * v.last_price * (theProduct?.value_scale || 1);\n return {\n position_id: `${v.contract_code}/${v.contract_type}/${v.direction}/${v.margin_mode}`,\n datasource_id: 'HUOBI-SWAP',\n product_id,\n direction: v.direction === 'buy' ? 'LONG' : 'SHORT',\n volume: v.volume,\n free_volume: v.available,\n position_price: v.cost_hold,\n closable_price: v.last_price,\n floating_profit: v.profit_unreal,\n valuation,\n };\n });\n\n // orders\n // const orders: IOrder[] = [];\n // let page_index = 1;\n // const page_size = 50;\n\n // while (true) {\n // const ordersRes = await client.getSwapOpenOrders({ page_index, page_size });\n // if (!ordersRes.data?.orders || ordersRes.data.orders.length === 0) {\n // break;\n // }\n\n // const pageOrders: IOrder[] = ordersRes.data.orders.map((v): IOrder => {\n // return {\n // order_id: v.order_id_str,\n // account_id: SWAP_ACCOUNT_ID,\n // product_id: v.contract_code,\n // order_type: ['lightning'].includes(v.order_price_type)\n // ? 'MARKET'\n // : ['limit', 'opponent', 'post_only', 'optimal_5', 'optimal_10', 'optimal_20'].includes(\n // v.order_price_type,\n // )\n // ? 'LIMIT'\n // : ['fok'].includes(v.order_price_type)\n // ? 'FOK'\n // : v.order_price_type.includes('ioc')\n // ? 'IOC'\n // : 'STOP', // unreachable code\n // order_direction:\n // v.direction === 'open'\n // ? v.offset === 'buy'\n // ? 'OPEN_LONG'\n // : 'OPEN_SHORT'\n // : v.offset === 'buy'\n // ? 'CLOSE_SHORT'\n // : 'CLOSE_LONG',\n // volume: v.volume,\n // submit_at: v.created_at,\n // price: v.price,\n // traded_volume: v.trade_volume,\n // };\n // });\n\n // orders.push(...pageOrders);\n // page_index++;\n // }\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n};\n"]}
1
+ {"version":3,"file":"swap.js","sourceRoot":"","sources":["../../src/accounts/swap.ts"],"names":[],"mappings":";;;AACA,+BAAsC;AACtC,oDAAkG;AAClG,wCAAgD;AAEzC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,UAAU;IACV,MAAM,OAAO,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,CAAC,CAAC;IACxD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;KACvD;IACD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,MAAM,CAAC,CAAC;IACxE,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC7D;IACD,MAAM,MAAM,GAAG,WAAW,CAAC,cAAc,CAAC;IAC1C,MAAM,IAAI,GAAG,WAAW,CAAC,kBAAkB,CAAC;IAE5C,YAAY;IACZ,MAAM,YAAY,GAAG,MAAM,IAAA,sCAAwB,EAAC,UAAU,CAAC,CAAC;IAChE,MAAM,8BAA8B,GAAG,MAAM,IAAA,qBAAc,EAAC,4BAAkB,CAAC,sBAAsB,CAAC,CAAC;IACvG,MAAM,SAAS,GAAgB,CAAC,YAAY,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAa,EAAE;QAC5E,MAAM,UAAU,GAAG,CAAC,CAAC,aAAa,CAAC;QACnC,MAAM,UAAU,GAAG,8BAA8B,aAA9B,8BAA8B,uBAA9B,8BAA8B,CAAE,GAAG,CAAC,UAAU,CAAC,CAAC;QACnE,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC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AA,kBAAkB,sBAiF7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { getSwapCrossPositionInfo, getUnifiedAccountInfo, ICredential } from '../api/private-api';\nimport { swapProductService } from '../product';\n\nexport const getSwapAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n // balance\n const balance = await getUnifiedAccountInfo(credential);\n if (!balance.data) {\n throw new Error('Failed to get unified account info');\n }\n const balanceData = balance.data.find((v) => v.margin_asset === 'USDT');\n if (!balanceData) {\n throw new Error('No USDT balance found in unified account');\n }\n const equity = balanceData.margin_balance;\n const free = balanceData.withdraw_available;\n\n // positions\n const positionsRes = await getSwapCrossPositionInfo(credential);\n const mapProductIdToPerpetualProduct = await firstValueFrom(swapProductService.mapProductIdToProduct$);\n const positions: IPosition[] = (positionsRes.data || []).map((v): IPosition => {\n const product_id = v.contract_code;\n const theProduct = mapProductIdToPerpetualProduct?.get(product_id);\n const valuation = v.volume * v.last_price * (theProduct?.value_scale || 1);\n return {\n position_id: `${v.contract_code}/${v.contract_type}/${v.direction}/${v.margin_mode}`,\n datasource_id: 'HUOBI-SWAP',\n product_id,\n direction: v.direction === 'buy' ? 'LONG' : 'SHORT',\n volume: v.volume,\n free_volume: v.available,\n position_price: v.cost_hold,\n closable_price: v.last_price,\n floating_profit: v.profit_unreal,\n valuation,\n };\n });\n\n // orders\n // const orders: IOrder[] = [];\n // let page_index = 1;\n // const page_size = 50;\n\n // while (true) {\n // const ordersRes = await client.getSwapOpenOrders({ page_index, page_size });\n // if (!ordersRes.data?.orders || ordersRes.data.orders.length === 0) {\n // break;\n // }\n\n // const pageOrders: IOrder[] = ordersRes.data.orders.map((v): IOrder => {\n // return {\n // order_id: v.order_id_str,\n // account_id: SWAP_ACCOUNT_ID,\n // product_id: v.contract_code,\n // order_type: ['lightning'].includes(v.order_price_type)\n // ? 'MARKET'\n // : ['limit', 'opponent', 'post_only', 'optimal_5', 'optimal_10', 'optimal_20'].includes(\n // v.order_price_type,\n // )\n // ? 'LIMIT'\n // : ['fok'].includes(v.order_price_type)\n // ? 'FOK'\n // : v.order_price_type.includes('ioc')\n // ? 'IOC'\n // : 'STOP', // unreachable code\n // order_direction:\n // v.direction === 'open'\n // ? v.offset === 'buy'\n // ? 'OPEN_LONG'\n // : 'OPEN_SHORT'\n // : v.offset === 'buy'\n // ? 'CLOSE_SHORT'\n // : 'CLOSE_LONG',\n // volume: v.volume,\n // submit_at: v.created_at,\n // price: v.price,\n // traded_volume: v.trade_volume,\n // };\n // });\n\n // orders.push(...pageOrders);\n // page_index++;\n // }\n\n return positions;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-huobi",
3
- "version": "0.14.3",
3
+ "version": "0.14.4",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "dependencies": {
11
11
  "@yuants/protocol": "0.52.0",
12
- "@yuants/data-account": "0.7.3",
12
+ "@yuants/data-account": "0.8.0",
13
13
  "@yuants/data-order": "0.6.2",
14
14
  "@yuants/transfer": "0.2.35",
15
15
  "@yuants/utils": "0.11.0",
@@ -1,19 +1,19 @@
1
1
  {
2
- "apps/vendor-huobi/CHANGELOG.json": "376b28a6354881af9144994849a34311dac21b48",
3
- "apps/vendor-huobi/CHANGELOG.md": "d5bd81906d49fa787b660b3095ba07df522a0360",
2
+ "apps/vendor-huobi/CHANGELOG.json": "aaa097ab604efe11c92c78beeeb8b91d331f9564",
3
+ "apps/vendor-huobi/CHANGELOG.md": "fad2711c1d510d891ea4a9aa37405f55a3b75e99",
4
4
  "apps/vendor-huobi/README.md": "d7bf0149513114eab5500a6b5c9e7cba10565572",
5
5
  "apps/vendor-huobi/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
6
6
  "apps/vendor-huobi/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
7
7
  "apps/vendor-huobi/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
8
8
  "apps/vendor-huobi/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
9
9
  "apps/vendor-huobi/etc/vendor-huobi.api.md": "dc8cbf2a044a227b30a4ee9701b0c97328244724",
10
- "apps/vendor-huobi/package.json": "6a6170fc8aa3376356b40e4e943d2813a8f08d21",
10
+ "apps/vendor-huobi/package.json": "29377935191ed467436fde5b1e1c1472c83e269f",
11
11
  "apps/vendor-huobi/src/account-actions-with-credentials.ts": "406799578e60a57d78b90dfb67e3360a53640571",
12
12
  "apps/vendor-huobi/src/account-info.ts": "fc2189e31000dd05855e659c2f0cf14fc12ffbdd",
13
13
  "apps/vendor-huobi/src/accounts/list.ts": "25e82ca0e49850afba3a1c7c23d67528b20e6ee1",
14
- "apps/vendor-huobi/src/accounts/spot.ts": "d1fdefe960eca370a0c8ec9b244a6357c046545a",
15
- "apps/vendor-huobi/src/accounts/super-margin.ts": "c6f3593929ad7b7e87eb66599e2d034875186423",
16
- "apps/vendor-huobi/src/accounts/swap.ts": "84537c6cfd1be5d1964d7e6c58ab9625502cc43f",
14
+ "apps/vendor-huobi/src/accounts/spot.ts": "8615b7b36c0d5c529f8183f41d1ef2fe6fc22562",
15
+ "apps/vendor-huobi/src/accounts/super-margin.ts": "1d3ea2cdd39fa0d75ae7cda7cd0e5690fecc9a0d",
16
+ "apps/vendor-huobi/src/accounts/swap.ts": "dd9e364f26684ecb08d439ee3ff12ed969bc0a81",
17
17
  "apps/vendor-huobi/src/api.ts": "061c8644a01c6e0b4964e4be6f4588e16abd8869",
18
18
  "apps/vendor-huobi/src/api/private-api.ts": "644260e6709841ade74d43b6df6dd3eda42d36d9",
19
19
  "apps/vendor-huobi/src/api/public-api.ts": "03a1468bea318d5fcb8c0c9d45666ffbee4346f0",
@@ -30,7 +30,7 @@
30
30
  "apps/vendor-huobi/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
31
31
  "apps/vendor-huobi/.rush/temp/shrinkwrap-deps.json": "9cfeff02d2b4838478ed6afd825f89806d4c2b57",
32
32
  "libraries/protocol/temp/package-deps.json": "52d2a645608a17915da897e48a70b415312a94fb",
33
- "libraries/data-account/temp/package-deps.json": "36ce528a841782d724392412ec002a155733a5d0",
33
+ "libraries/data-account/temp/package-deps.json": "459a552a5ff4304fff00dfd369bb0746bd33cf5f",
34
34
  "libraries/data-order/temp/package-deps.json": "0e063d2c14a4c5cfb23756143c3f399f545b496d",
35
35
  "libraries/transfer/temp/package-deps.json": "43e6dc024979295961767cdfbbdbdf5aff2831b3",
36
36
  "libraries/utils/temp/package-deps.json": "c58f1ca8f498315d9a0219ca8c498299a41d297b",