@yuants/vendor-binance 0.10.15 → 0.10.16

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.
@@ -27,10 +27,10 @@ export const getUnifiedAccountInfo = async (credential) => {
27
27
  : position.positionSide === 'BOTH'
28
28
  ? 'BOTH'
29
29
  : 'UNKNOWN',
30
- volume: +position.positionAmt,
31
- free_volume: +position.positionAmt,
30
+ volume: Math.abs(+position.positionAmt),
31
+ free_volume: Math.abs(+position.positionAmt),
32
32
  position_price: +position.entryPrice,
33
- closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,
33
+ closable_price: +position.entryPrice + +position.unrealizedProfit / Math.abs(+position.positionAmt),
34
34
  floating_profit: +position.unrealizedProfit,
35
35
  valuation: +position.positionAmt *
36
36
  (+position.entryPrice +
@@ -1 +1 @@
1
- {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAe,MAAM,uBAAuB,CAAC;AACnG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAC3F,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,wBAAwB,CAAC,UAAU,CAAC;QACpC,mBAAmB,CAAC,UAAU,CAAC;KAChC,CAAC,CAAC;IACH,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;KACjC;IACD,IAA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K,GAAG,QAAQ,CAAC,KAAK,MAAM,CAAC,0CAAE,KAAK,mCAAI,CAAC,CAAC;oBAC/E,CAAC,CAAC,CAAC;SACR,CAAC,CAAA;KAAA,CACH,CAAC;IACF,OAAO,CAAC,GAAG,gBAAgB,EAAE,GAAG,SAAS,CAAC,CAAC;AAC7C,CAAC,CAAC","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\nimport { getSpotTickerPrice } from '../../api/public-api';\n\nexport const getUnifiedAccountInfo = async (credential: ICredential): Promise<IPosition[]> => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: +position.positionAmt,\n free_volume: +position.positionAmt,\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n const prices = await getSpotTickerPrice({\n symbols: JSON.stringify([\n ...new Set([\n ...balanceRes\n .map((balance) => {\n const match = balance.asset.match(/^LD(\\w+)$/);\n let symbol = balance.asset;\n if (match) {\n symbol = match[1];\n }\n if (symbol === 'USDT') return '';\n return `${symbol}USDT`;\n })\n .filter(Boolean),\n ]),\n ]),\n });\n const balancePositions: IPosition[] = balanceRes.map((position) =>\n makeSpotPosition({\n position_id: `UNIFIED-SPOT/${position.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'UNIFIED-SPOT', position.asset),\n volume: +position.totalWalletBalance + +position.umUnrealizedPNL,\n free_volume: +position.crossMarginFree,\n closable_price:\n position.asset === 'USDT'\n ? 1\n : Array.isArray(prices)\n ? +(prices.find((item) => item.symbol === `${position.asset}USDT`)?.price ?? 0)\n : 0,\n }),\n );\n return [...balancePositions, ...positions];\n};\n"]}
1
+ {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAe,MAAM,uBAAuB,CAAC;AACnG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAC3F,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,wBAAwB,CAAC,UAAU,CAAC;QACpC,mBAAmB,CAAC,UAAU,CAAC;KAChC,CAAC,CAAC;IACH,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;KACjC;IACD,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;KACnC;IAED,MAA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AC,KAAK,MAAM,CAAC,0CAAE,KAAK,mCAAI,CAAC,CAAC;oBAC/E,CAAC,CAAC,CAAC;SACR,CAAC,CAAA;KAAA,CACH,CAAC;IACF,OAAO,CAAC,GAAG,gBAAgB,EAAE,GAAG,SAAS,CAAC,CAAC;AAC7C,CAAC,CAAC","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\nimport { getSpotTickerPrice } from '../../api/public-api';\n\nexport const getUnifiedAccountInfo = async (credential: ICredential): Promise<IPosition[]> => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: Math.abs(+position.positionAmt),\n free_volume: Math.abs(+position.positionAmt),\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / Math.abs(+position.positionAmt),\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n const prices = await getSpotTickerPrice({\n symbols: JSON.stringify([\n ...new Set([\n ...balanceRes\n .map((balance) => {\n const match = balance.asset.match(/^LD(\\w+)$/);\n let symbol = balance.asset;\n if (match) {\n symbol = match[1];\n }\n if (symbol === 'USDT') return '';\n return `${symbol}USDT`;\n })\n .filter(Boolean),\n ]),\n ]),\n });\n const balancePositions: IPosition[] = balanceRes.map((position) =>\n makeSpotPosition({\n position_id: `UNIFIED-SPOT/${position.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'UNIFIED-SPOT', position.asset),\n volume: +position.totalWalletBalance + +position.umUnrealizedPNL,\n free_volume: +position.crossMarginFree,\n closable_price:\n position.asset === 'USDT'\n ? 1\n : Array.isArray(prices)\n ? +(prices.find((item) => item.symbol === `${position.asset}USDT`)?.price ?? 0)\n : 0,\n }),\n );\n return [...balancePositions, ...positions];\n};\n"]}
@@ -30,10 +30,10 @@ const getUnifiedAccountInfo = async (credential) => {
30
30
  : position.positionSide === 'BOTH'
31
31
  ? 'BOTH'
32
32
  : 'UNKNOWN',
33
- volume: +position.positionAmt,
34
- free_volume: +position.positionAmt,
33
+ volume: Math.abs(+position.positionAmt),
34
+ free_volume: Math.abs(+position.positionAmt),
35
35
  position_price: +position.entryPrice,
36
- closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,
36
+ closable_price: +position.entryPrice + +position.unrealizedProfit / Math.abs(+position.positionAmt),
37
37
  floating_profit: +position.unrealizedProfit,
38
38
  valuation: +position.positionAmt *
39
39
  (+position.entryPrice +
@@ -1 +1 @@
1
- {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AACnE,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAmG;AACnG,qDAA0D;AAEnD,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAC3F,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,IAAA,sCAAwB,EAAC,UAAU,CAAC;QACpC,IAAA,iCAAmB,EAAC,UAAU,CAAC;KAChC,CAAC,CAAC;I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,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;oBACvB,CAAC,CAAC,CAAC,CAAC,MAAA,MAAA,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,MAAM,CAAC,0CAAE,KAAK,mCAAI,CAAC,CAAC;oBAC/E,CAAC,CAAC,CAAC;SACR,CAAC,CAAA;KAAA,CACH,CAAC;IACF,OAAO,CAAC,GAAG,gBAAgB,EAAE,GAAG,SAAS,CAAC,CAAC;AAC7C,CAAC,CAAC;AAtEW,QAAA,qBAAqB,yBAsEhC","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\nimport { getSpotTickerPrice } from '../../api/public-api';\n\nexport const getUnifiedAccountInfo = async (credential: ICredential): Promise<IPosition[]> => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: +position.positionAmt,\n free_volume: +position.positionAmt,\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / +position.positionAmt,\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n const prices = await getSpotTickerPrice({\n symbols: JSON.stringify([\n ...new Set([\n ...balanceRes\n .map((balance) => {\n const match = balance.asset.match(/^LD(\\w+)$/);\n let symbol = balance.asset;\n if (match) {\n symbol = match[1];\n }\n if (symbol === 'USDT') return '';\n return `${symbol}USDT`;\n })\n .filter(Boolean),\n ]),\n ]),\n });\n const balancePositions: IPosition[] = balanceRes.map((position) =>\n makeSpotPosition({\n position_id: `UNIFIED-SPOT/${position.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'UNIFIED-SPOT', position.asset),\n volume: +position.totalWalletBalance + +position.umUnrealizedPNL,\n free_volume: +position.crossMarginFree,\n closable_price:\n position.asset === 'USDT'\n ? 1\n : Array.isArray(prices)\n ? +(prices.find((item) => item.symbol === `${position.asset}USDT`)?.price ?? 0)\n : 0,\n }),\n );\n return [...balancePositions, ...positions];\n};\n"]}
1
+ {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AACnE,yCAA2C;AAC3C,6CAA8C;AAC9C,uDAAmG;AACnG,qDAA0D;AAEnD,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAC3F,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,IAAA,sCAAwB,EAAC,UAAU,CAAC;QACpC,IAAA,iCAAmB,EAAC,UAAU,CAAC;KAChC,CAAC,CAAC;IACH,IAAI,IAAA,mBAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;KACjC;IACD,IAAI,IAAA,mBAAU,EAAC,YAAY,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;KACnC;IAED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AC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,MAAM,CAAC,0CAAE,KAAK,mCAAI,CAAC,CAAC;oBAC/E,CAAC,CAAC,CAAC;SACR,CAAC,CAAA;KAAA,CACH,CAAC;IACF,OAAO,CAAC,GAAG,gBAAgB,EAAE,GAAG,SAAS,CAAC,CAAC;AAC7C,CAAC,CAAC;AAtEW,QAAA,qBAAqB,yBAsEhC","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { isApiError } from '../../api/client';\nimport { getUnifiedAccountBalance, getUnifiedUmAccount, ICredential } from '../../api/private-api';\nimport { getSpotTickerPrice } from '../../api/public-api';\n\nexport const getUnifiedAccountInfo = async (credential: ICredential): Promise<IPosition[]> => {\n const [balanceRes, umAccountRes] = await Promise.all([\n getUnifiedAccountBalance(credential),\n getUnifiedUmAccount(credential),\n ]);\n if (isApiError(balanceRes)) {\n throw new Error(balanceRes.msg);\n }\n if (isApiError(umAccountRes)) {\n throw new Error(umAccountRes.msg);\n }\n\n const positions: IPosition[] = umAccountRes.positions\n .filter((position) => +position.positionAmt !== 0)\n .map((position) => ({\n position_id: `${position.symbol}/${position.positionSide}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'USDT-FUTURE', position.symbol),\n direction:\n position.positionSide === 'LONG'\n ? 'LONG'\n : position.positionSide === 'SHORT'\n ? 'SHORT'\n : position.positionSide === 'BOTH'\n ? 'BOTH'\n : 'UNKNOWN',\n volume: Math.abs(+position.positionAmt),\n free_volume: Math.abs(+position.positionAmt),\n position_price: +position.entryPrice,\n closable_price: +position.entryPrice + +position.unrealizedProfit / Math.abs(+position.positionAmt),\n floating_profit: +position.unrealizedProfit,\n valuation:\n +position.positionAmt *\n (+position.entryPrice +\n (+position.positionAmt === 0 ? 0 : +position.unrealizedProfit / +position.positionAmt)),\n }));\n\n const prices = await getSpotTickerPrice({\n symbols: JSON.stringify([\n ...new Set([\n ...balanceRes\n .map((balance) => {\n const match = balance.asset.match(/^LD(\\w+)$/);\n let symbol = balance.asset;\n if (match) {\n symbol = match[1];\n }\n if (symbol === 'USDT') return '';\n return `${symbol}USDT`;\n })\n .filter(Boolean),\n ]),\n ]),\n });\n const balancePositions: IPosition[] = balanceRes.map((position) =>\n makeSpotPosition({\n position_id: `UNIFIED-SPOT/${position.asset}`,\n datasource_id: 'BINANCE',\n product_id: encodePath('BINANCE', 'UNIFIED-SPOT', position.asset),\n volume: +position.totalWalletBalance + +position.umUnrealizedPNL,\n free_volume: +position.crossMarginFree,\n closable_price:\n position.asset === 'USDT'\n ? 1\n : Array.isArray(prices)\n ? +(prices.find((item) => item.symbol === `${position.asset}USDT`)?.price ?? 0)\n : 0,\n }),\n );\n return [...balancePositions, ...positions];\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-binance",
3
- "version": "0.10.15",
3
+ "version": "0.10.16",
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.53.2",
12
- "@yuants/data-account": "0.9.0",
12
+ "@yuants/data-account": "0.10.0",
13
13
  "@yuants/cache": "0.3.3",
14
14
  "@yuants/data-quote": "0.2.43",
15
15
  "@yuants/utils": "0.14.0",
@@ -20,7 +20,7 @@
20
20
  "@yuants/data-order": "0.6.6",
21
21
  "@yuants/data-interest-rate": "0.1.48",
22
22
  "@yuants/transfer": "0.2.39",
23
- "@yuants/exchange": "0.4.0",
23
+ "@yuants/exchange": "0.5.0",
24
24
  "rxjs": "~7.5.6"
25
25
  },
26
26
  "devDependencies": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "apps/vendor-binance/AGENTS.md": "378369925bffa237cd5e8ef459fe2bc2a141337c",
3
- "apps/vendor-binance/CHANGELOG.json": "6c966397053498e83d27e4c49255db16a6cdb0a6",
4
- "apps/vendor-binance/CHANGELOG.md": "3e6d3e53bc3a10ace7e96e0a5c1086539e3c3ac5",
3
+ "apps/vendor-binance/CHANGELOG.json": "1880833645a9b7178d28d8fa24c92ff20fc0f615",
4
+ "apps/vendor-binance/CHANGELOG.md": "63eadc6d786733ca7e8b19c389c8059683d53984",
5
5
  "apps/vendor-binance/README.md": "4ab94c08b3d07398aee74c3264a4f87d554d20fa",
6
6
  "apps/vendor-binance/SESSION_NOTES.md": "dd49b3364394c502fdcaf687ed5942811d89abe9",
7
7
  "apps/vendor-binance/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
@@ -9,7 +9,7 @@
9
9
  "apps/vendor-binance/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
10
10
  "apps/vendor-binance/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
11
11
  "apps/vendor-binance/etc/vendor-binance.api.md": "2094b84e9b5e7503f5c42b31fffee8d7db47fe7b",
12
- "apps/vendor-binance/package.json": "0970b460fe9abed8d0e2811a9d180ca08075209d",
12
+ "apps/vendor-binance/package.json": "c927a693e1f2c6da1943f151428ed4e78bccd6f6",
13
13
  "apps/vendor-binance/src/api/client.ts": "fab85d85d10577f0b6430a551dab46d7c1d2258a",
14
14
  "apps/vendor-binance/src/api/private-api.ts": "982c1902b8417aba1f75df5fa63db76dfc416dac",
15
15
  "apps/vendor-binance/src/api/public-api.ts": "70dc33214e05ec3ead45271bfae70abdb0623c1e",
@@ -21,7 +21,7 @@
21
21
  "apps/vendor-binance/src/public-data/quote.ts": "0445513ea3b36e1ba9bd05d577ac7050503168f0",
22
22
  "apps/vendor-binance/src/services/accounts/profile.ts": "1d23b04d19c078e8c21f41efd6ca3db37b0bd206",
23
23
  "apps/vendor-binance/src/services/accounts/spot.ts": "7561d3054c967b48711a4dcedf96946eeab9fab4",
24
- "apps/vendor-binance/src/services/accounts/unified.ts": "4bb4de2908b3dfb4a9ea78610c77a06fb4a46739",
24
+ "apps/vendor-binance/src/services/accounts/unified.ts": "feb19cb0e3dc67669ff5da60a0e859ff5412d3f3",
25
25
  "apps/vendor-binance/src/services/exchange.ts": "c989e025b771f5d5c49efcc779ca388dfb1d488d",
26
26
  "apps/vendor-binance/src/services/orders/cancelOrder.ts": "7177ca56fd09b11651edbb38e1962363ac67d4ff",
27
27
  "apps/vendor-binance/src/services/orders/listOrders.ts": "baa21b8e858c1ec593415145cc63fb38a6841d3f",
@@ -31,7 +31,7 @@
31
31
  "apps/vendor-binance/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
32
32
  "apps/vendor-binance/.rush/temp/shrinkwrap-deps.json": "0408a4d9b00c1701e07aa22f8350e585241c4581",
33
33
  "libraries/protocol/temp/package-deps.json": "0bd43721e96039b52d7b59c834dc6df45cf75e3f",
34
- "libraries/data-account/temp/package-deps.json": "711aeba1f1f5f03741475a4290e56d18b39e5305",
34
+ "libraries/data-account/temp/package-deps.json": "3ee766acef866410612b60dfc1012082c9c24556",
35
35
  "libraries/cache/temp/package-deps.json": "a4afa15e6462983f9d3735d31dc1ed8a683fb4dc",
36
36
  "libraries/data-quote/temp/package-deps.json": "34d079eab44d2bf65e07b112ac2099c6e92a015e",
37
37
  "libraries/utils/temp/package-deps.json": "6d58e9b325e8d16de8a878c32010f626b12a01da",
@@ -42,7 +42,7 @@
42
42
  "libraries/data-order/temp/package-deps.json": "2adac9fc0423f9b1b7ddaa8946ab7af374cc22e1",
43
43
  "libraries/data-interest-rate/temp/package-deps.json": "cef1e1cb0116ad593c24635684e0cbf03488d67c",
44
44
  "libraries/transfer/temp/package-deps.json": "36c58299bd6c841c5ba7252d71881a881570d08c",
45
- "libraries/exchange/temp/package-deps.json": "d30a450879e4d67f56466262bd88a72506594d68",
45
+ "libraries/exchange/temp/package-deps.json": "d40288d0530bc7e63246f234bdffa10a497776b1",
46
46
  "libraries/extension/temp/package-deps.json": "9569c553c2f9a7d50b70d8f101fc2d3825aaccb9",
47
47
  "tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
48
48
  }