@yuants/vendor-gate 0.4.13 → 0.4.15
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/services/accounts/future.js +3 -1
- package/dist/services/accounts/future.js.map +1 -1
- package/dist/services/accounts/spot.js +1 -1
- package/dist/services/accounts/spot.js.map +1 -1
- package/dist/services/accounts/unified.js +11 -5
- package/dist/services/accounts/unified.js.map +1 -1
- package/dist/services/exchange.js +3 -5
- package/dist/services/exchange.js.map +1 -1
- package/lib/services/accounts/future.d.ts.map +1 -1
- package/lib/services/accounts/future.js +3 -1
- package/lib/services/accounts/future.js.map +1 -1
- package/lib/services/accounts/spot.js +1 -1
- package/lib/services/accounts/spot.js.map +1 -1
- package/lib/services/accounts/unified.d.ts.map +1 -1
- package/lib/services/accounts/unified.js +11 -5
- package/lib/services/accounts/unified.js.map +1 -1
- package/lib/services/exchange.js +3 -5
- package/lib/services/exchange.js.map +1 -1
- package/package.json +2 -2
- package/temp/package-deps.json +8 -8
|
@@ -8,7 +8,9 @@ export const loadFuturePositions = async (credential) => {
|
|
|
8
8
|
firstValueFrom(mapProductIdToUsdtFutureProduct$),
|
|
9
9
|
]);
|
|
10
10
|
const positions = Array.isArray(positionsRes) ? positionsRes : [];
|
|
11
|
-
return positions
|
|
11
|
+
return positions
|
|
12
|
+
.filter((pos) => Math.abs(pos.size) > 0)
|
|
13
|
+
.map((position) => {
|
|
12
14
|
var _a;
|
|
13
15
|
const product_id = encodePath('GATE', 'FUTURE', position.contract);
|
|
14
16
|
const theProduct = productMap.get(product_id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,gCAAgC,EAAE,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AAE,UAAuB,EAAE,EAAE;IACpE,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChD,mBAAmB,CAAC,UAAU,CAAC;QAC/B,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import type { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { mapProductIdToUsdtFutureProduct$ } from '../markets/product';\nimport { encodePath } from '@yuants/utils';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const [positionsRes, productMap] = await Promise.all([\n getFuturePositions(credential, 'usdt'),\n firstValueFrom(mapProductIdToUsdtFutureProduct$),\n ]);\n const positions = Array.isArray(positionsRes) ? positionsRes : [];\n return positions\n .filter((pos) => Math.abs(pos.size) > 0)\n .map((position): IPosition => {\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = productMap.get(product_id);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price * (theProduct?.value_scale ?? 1);\n return {\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n valuation,\n };\n });\n};\n\nexport const getFutureAccountInfo = async (credential: ICredential) => {\n const [positions, rawAccount] = await Promise.all([\n loadFuturePositions(credential),\n getFuturesAccounts(credential, 'usdt'),\n ]);\n\n return positions;\n};\n"]}
|
|
@@ -10,7 +10,7 @@ export const getSpotAccountInfo = async (credential) => {
|
|
|
10
10
|
return makeSpotPosition({
|
|
11
11
|
datasource_id: 'GATE',
|
|
12
12
|
position_id: item.currency,
|
|
13
|
-
product_id: encodePath('GATE', 'SPOT', `${item.currency}
|
|
13
|
+
product_id: encodePath('GATE', 'SPOT', `${item.currency}`),
|
|
14
14
|
volume: Number(item.available),
|
|
15
15
|
free_volume: Number(item.available),
|
|
16
16
|
closable_price: 1, // TODO: use real price
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAe,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtB,OAAO,gBAAgB,CAAC;YACtB,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,IAAI,CAAC,QAAQ;YAC1B,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAe,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtB,OAAO,gBAAgB,CAAC;YACtB,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,IAAI,CAAC,QAAQ;YAC1B,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1D,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YACnC,cAAc,EAAE,CAAC,EAAE,uBAAuB;SAC3C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { makeSpotPosition } from '@yuants/data-account';\nimport { getSpotAccounts, ICredential } from '../../api/private-api';\nimport { encodePath } from '@yuants/utils';\n\nexport const getSpotAccountInfo = async (credential: ICredential) => {\n const res = await getSpotAccounts(credential);\n if (!Array.isArray(res)) {\n throw new Error('Failed to load spot balances');\n }\n return res.map((item) => {\n return makeSpotPosition({\n datasource_id: 'GATE',\n position_id: item.currency,\n product_id: encodePath('GATE', 'SPOT', `${item.currency}`),\n volume: Number(item.available),\n free_volume: Number(item.available),\n closable_price: 1, // TODO: use real price\n });\n });\n};\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getUnifiedAccounts } from '../../api/private-api';
|
|
2
2
|
import { getSpotTickers } from '../../api/public-api';
|
|
3
3
|
import { loadFuturePositions } from './future';
|
|
4
|
+
import { encodePath } from '@yuants/utils';
|
|
4
5
|
export const getUnifiedAccountInfo = async (credential) => {
|
|
5
6
|
var _a;
|
|
6
7
|
const [futurePositions, unifiedAccount, spotTickers] = await Promise.all([
|
|
@@ -13,24 +14,29 @@ export const getUnifiedAccountInfo = async (credential) => {
|
|
|
13
14
|
const spotPositions = Object.keys(balances)
|
|
14
15
|
.map((currency) => {
|
|
15
16
|
var _a, _b;
|
|
16
|
-
if (currency === 'USDT')
|
|
17
|
-
return undefined;
|
|
18
17
|
let currency_pair = `${currency}_USDT`;
|
|
19
18
|
if (currency === 'SOL2') {
|
|
20
19
|
currency_pair = 'SOL_USDT';
|
|
21
20
|
}
|
|
22
|
-
|
|
21
|
+
if (currency === 'GTSOL') {
|
|
22
|
+
currency_pair = 'SOL_USDT';
|
|
23
|
+
}
|
|
24
|
+
const closable_price = currency === 'USDT'
|
|
25
|
+
? 1
|
|
26
|
+
: Number(((_a = spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)) === null || _a === void 0 ? void 0 : _a.last) || 0);
|
|
23
27
|
const volume = Number(((_b = balances[currency]) === null || _b === void 0 ? void 0 : _b.available) || 0);
|
|
28
|
+
if (Math.abs(volume) === 0)
|
|
29
|
+
return undefined;
|
|
24
30
|
return {
|
|
25
31
|
datasource_id: 'gate/spot',
|
|
26
32
|
position_id: currency,
|
|
27
|
-
product_id: currency,
|
|
33
|
+
product_id: encodePath('GATE', 'SPOT', currency),
|
|
28
34
|
direction: 'LONG',
|
|
29
35
|
volume,
|
|
30
36
|
free_volume: volume,
|
|
31
37
|
closable_price,
|
|
32
38
|
position_price: closable_price,
|
|
33
|
-
floating_profit:
|
|
39
|
+
floating_profit: closable_price * volume,
|
|
34
40
|
valuation: closable_price * volume,
|
|
35
41
|
};
|
|
36
42
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAC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,CAAC,CAAC,CAAC;YACH,CAAC,CAAC,MAAM,CAAC,CAAA,MAAA,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,KAAK,aAAa,CAAC,0CAAE,IAAI,KAAI,CAAC,CAAC,CAAC;QACjG,MAAM,MAAM,GAAG,MAAM,CAAC,CAAA,MAAA,QAAQ,CAAC,QAAQ,CAAC,0CAAE,SAAS,KAAI,CAAC,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC7C,OAAO;YACL,aAAa,EAAE,WAAW;YAC1B,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;YAChD,SAAS,EAAE,MAAM;YACjB,MAAM;YACN,WAAW,EAAE,MAAM;YACnB,cAAc;YACd,cAAc,EAAE,cAAc;YAC9B,eAAe,EAAE,cAAc,GAAG,MAAM;YACxC,SAAS,EAAE,cAAc,GAAG,MAAM;SACtB,CAAC;IACjB,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,IAAI,EAAqB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,eAAe,EAAE,GAAG,aAAa,CAAC,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import type { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { getUnifiedAccounts, ICredential } from '../../api/private-api';\nimport { getSpotTickers } from '../../api/public-api';\nimport { loadFuturePositions } from './future';\nimport { encodePath } from '@yuants/utils';\n\nexport const getUnifiedAccountInfo = async (credential: ICredential) => {\n const [futurePositions, unifiedAccount, spotTickers] = await Promise.all([\n loadFuturePositions(credential),\n getUnifiedAccounts(credential, {}),\n getSpotTickers({}),\n ]);\n\n const balances = unifiedAccount?.balances ?? {};\n const spotTickerList = Array.isArray(spotTickers) ? spotTickers : [];\n const spotPositions: IPosition[] = Object.keys(balances)\n .map((currency) => {\n let currency_pair = `${currency}_USDT`;\n if (currency === 'SOL2') {\n currency_pair = 'SOL_USDT';\n }\n if (currency === 'GTSOL') {\n currency_pair = 'SOL_USDT';\n }\n const closable_price =\n currency === 'USDT'\n ? 1\n : Number(spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)?.last || 0);\n const volume = Number(balances[currency]?.available || 0);\n if (Math.abs(volume) === 0) return undefined;\n return {\n datasource_id: 'gate/spot',\n position_id: currency,\n product_id: encodePath('GATE', 'SPOT', currency),\n direction: 'LONG',\n volume,\n free_volume: volume,\n closable_price,\n position_price: closable_price,\n floating_profit: closable_price * volume,\n valuation: closable_price * volume,\n } as IPosition;\n })\n .filter((item): item is IPosition => !!item);\n\n return [...futurePositions, ...spotPositions];\n};\n"]}
|
|
@@ -2,7 +2,6 @@ import { provideExchangeServices } from '@yuants/exchange';
|
|
|
2
2
|
import { Terminal } from '@yuants/protocol';
|
|
3
3
|
import { decodePath } from '@yuants/utils';
|
|
4
4
|
import { getCredentialId } from './accounts/profile';
|
|
5
|
-
import { getSpotAccountInfo } from './accounts/spot';
|
|
6
5
|
import { getUnifiedAccountInfo } from './accounts/unified';
|
|
7
6
|
import { cancelOrder } from './orders/cancelOrder';
|
|
8
7
|
import { submitOrder } from './orders/submitOrder';
|
|
@@ -23,12 +22,11 @@ provideExchangeServices(terminal, {
|
|
|
23
22
|
getCredentialId,
|
|
24
23
|
listProducts,
|
|
25
24
|
getPositions: async function (credential) {
|
|
26
|
-
const [
|
|
27
|
-
getFutureAccountInfo(credential),
|
|
28
|
-
getSpotAccountInfo(credential),
|
|
25
|
+
const [unifiedPositions] = await Promise.all([
|
|
26
|
+
// getFutureAccountInfo(credential),
|
|
29
27
|
getUnifiedAccountInfo(credential),
|
|
30
28
|
]);
|
|
31
|
-
return [...
|
|
29
|
+
return [...unifiedPositions];
|
|
32
30
|
},
|
|
33
31
|
getOrders: async function (credential) {
|
|
34
32
|
const [umOrders] = await Promise.all([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,uBAAuB,CAAc,QAAQ,EAAE;IAC7C,IAAI,EAAE,MAAM;IACZ,gBAAgB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;QACtC,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,E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ants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath } from '@yuants/utils';\nimport { getCredentialId } from './accounts/profile';\nimport { getUnifiedAccountInfo } from './accounts/unified';\nimport { cancelOrder } from './orders/cancelOrder';\nimport { submitOrder } from './orders/submitOrder';\nimport { getFutureAccountInfo } from './accounts/future';\nimport { ICredential } from '../api/private-api';\nimport { listOrders, getOrdersByProductId } from './orders/listOrders';\nimport { listProducts } from './markets/product';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'GATE',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n getCredentialId,\n listProducts,\n getPositions: async function (credential: ICredential): Promise<IPosition[]> {\n const [unifiedPositions] = await Promise.all([\n // getFutureAccountInfo(credential),\n getUnifiedAccountInfo(credential),\n ]);\n return [...unifiedPositions];\n },\n getOrders: async function (credential: ICredential): Promise<IOrder[]> {\n const [umOrders] = await Promise.all([\n listOrders(credential),\n // listSpotOrders(credential),\n ]);\n return [...umOrders];\n },\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const [_, instType] = decodePath(product_id); // BINANCE/USDT-FUTURE/ADAUSDT\n // if (instType === 'SPOT') {\n // const positions = await getSpotAccountInfoSnapshot(credential);\n // return positions.filter((position) => position.product_id === product_id);\n // }\n if (instType === 'FUTURE') {\n const positions = await getFutureAccountInfo(credential);\n return positions.filter((position) => position.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n },\n getOrdersByProductId,\n submitOrder,\n modifyOrder: () => {\n throw new Error('Not implemented');\n },\n cancelOrder,\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"future.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI5F,eAAO,MAAM,mBAAmB,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"future.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI5F,eAAO,MAAM,mBAAmB,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAkCtF,CAAC;AAEF,eAAO,MAAM,oBAAoB,eAAsB,WAAW,yBAOjE,CAAC"}
|
|
@@ -11,7 +11,9 @@ const loadFuturePositions = async (credential) => {
|
|
|
11
11
|
(0, rxjs_1.firstValueFrom)(product_1.mapProductIdToUsdtFutureProduct$),
|
|
12
12
|
]);
|
|
13
13
|
const positions = Array.isArray(positionsRes) ? positionsRes : [];
|
|
14
|
-
return positions
|
|
14
|
+
return positions
|
|
15
|
+
.filter((pos) => Math.abs(pos.size) > 0)
|
|
16
|
+
.map((position) => {
|
|
15
17
|
var _a;
|
|
16
18
|
const product_id = (0, utils_1.encodePath)('GATE', 'FUTURE', position.contract);
|
|
17
19
|
const theProduct = productMap.get(product_id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":";;;AACA,+BAAsC;AACtC,uDAA4F;AAC5F,gDAAsE;AACtE,yCAA2C;AAEpC,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IACzF,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,IAAA,gCAAkB,EAAC,UAAU,EAAE,MAAM,CAAC;QACtC,IAAA,qBAAc,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AM,GAAG,cAAc,GAAG,CAAC,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,WAAW,mCAAI,CAAC,CAAC,CAAC;QAC3E,OAAO;YACL,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,GAAG,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE;YACzE,UAAU;YACV,SAAS,EACP,QAAQ,CAAC,IAAI,KAAK,WAAW;gBAC3B,CAAC,CAAC,MAAM;gBACR,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;oBAChC,CAAC,CAAC,OAAO;oBACT,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC;wBACnB,CAAC,CAAC,MAAM;wBACR,CAAC,CAAC,OAAO;YACb,MAAM;YACN,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;YACpC,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;YAC5C,cAAc;YACd,eAAe,EAAE,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC;YAChD,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAlCW,QAAA,mBAAmB,uBAkC9B;AAEK,MAAM,oBAAoB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IACpE,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChD,IAAA,2BAAmB,EAAC,UAAU,CAAC;QAC/B,IAAA,gCAAkB,EAAC,UAAU,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAPW,QAAA,oBAAoB,wBAO/B","sourcesContent":["import type { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { mapProductIdToUsdtFutureProduct$ } from '../markets/product';\nimport { encodePath } from '@yuants/utils';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const [positionsRes, productMap] = await Promise.all([\n getFuturePositions(credential, 'usdt'),\n firstValueFrom(mapProductIdToUsdtFutureProduct$),\n ]);\n const positions = Array.isArray(positionsRes) ? positionsRes : [];\n return positions\n .filter((pos) => Math.abs(pos.size) > 0)\n .map((position): IPosition => {\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = productMap.get(product_id);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price * (theProduct?.value_scale ?? 1);\n return {\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n valuation,\n };\n });\n};\n\nexport const getFutureAccountInfo = async (credential: ICredential) => {\n const [positions, rawAccount] = await Promise.all([\n loadFuturePositions(credential),\n getFuturesAccounts(credential, 'usdt'),\n ]);\n\n return positions;\n};\n"]}
|
|
@@ -13,7 +13,7 @@ const getSpotAccountInfo = async (credential) => {
|
|
|
13
13
|
return (0, data_account_1.makeSpotPosition)({
|
|
14
14
|
datasource_id: 'GATE',
|
|
15
15
|
position_id: item.currency,
|
|
16
|
-
product_id: (0, utils_1.encodePath)('GATE', 'SPOT', `${item.currency}
|
|
16
|
+
product_id: (0, utils_1.encodePath)('GATE', 'SPOT', `${item.currency}`),
|
|
17
17
|
volume: Number(item.available),
|
|
18
18
|
free_volume: Number(item.available),
|
|
19
19
|
closable_price: 1, // TODO: use real price
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAwD;AACxD,uDAAqE;AACrE,yCAA2C;AAEpC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,GAAG,GAAG,MAAM,IAAA,6BAAe,EAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtB,OAAO,IAAA,+BAAgB,EAAC;YACtB,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,IAAI,CAAC,QAAQ;YAC1B,UAAU,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAwD;AACxD,uDAAqE;AACrE,yCAA2C;AAEpC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,GAAG,GAAG,MAAM,IAAA,6BAAe,EAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtB,OAAO,IAAA,+BAAgB,EAAC;YACtB,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,IAAI,CAAC,QAAQ;YAC1B,UAAU,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1D,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YACnC,cAAc,EAAE,CAAC,EAAE,uBAAuB;SAC3C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAfW,QAAA,kBAAkB,sBAe7B","sourcesContent":["import { makeSpotPosition } from '@yuants/data-account';\nimport { getSpotAccounts, ICredential } from '../../api/private-api';\nimport { encodePath } from '@yuants/utils';\n\nexport const getSpotAccountInfo = async (credential: ICredential) => {\n const res = await getSpotAccounts(credential);\n if (!Array.isArray(res)) {\n throw new Error('Failed to load spot balances');\n }\n return res.map((item) => {\n return makeSpotPosition({\n datasource_id: 'GATE',\n position_id: item.currency,\n product_id: encodePath('GATE', 'SPOT', `${item.currency}`),\n volume: Number(item.available),\n free_volume: Number(item.available),\n closable_price: 1, // TODO: use real price\n });\n });\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAsB,WAAW,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAsB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKxE,eAAO,MAAM,qBAAqB,eAAsB,WAAW,yBAwClE,CAAC"}
|
|
@@ -4,6 +4,7 @@ exports.getUnifiedAccountInfo = void 0;
|
|
|
4
4
|
const private_api_1 = require("../../api/private-api");
|
|
5
5
|
const public_api_1 = require("../../api/public-api");
|
|
6
6
|
const future_1 = require("./future");
|
|
7
|
+
const utils_1 = require("@yuants/utils");
|
|
7
8
|
const getUnifiedAccountInfo = async (credential) => {
|
|
8
9
|
var _a;
|
|
9
10
|
const [futurePositions, unifiedAccount, spotTickers] = await Promise.all([
|
|
@@ -16,24 +17,29 @@ const getUnifiedAccountInfo = async (credential) => {
|
|
|
16
17
|
const spotPositions = Object.keys(balances)
|
|
17
18
|
.map((currency) => {
|
|
18
19
|
var _a, _b;
|
|
19
|
-
if (currency === 'USDT')
|
|
20
|
-
return undefined;
|
|
21
20
|
let currency_pair = `${currency}_USDT`;
|
|
22
21
|
if (currency === 'SOL2') {
|
|
23
22
|
currency_pair = 'SOL_USDT';
|
|
24
23
|
}
|
|
25
|
-
|
|
24
|
+
if (currency === 'GTSOL') {
|
|
25
|
+
currency_pair = 'SOL_USDT';
|
|
26
|
+
}
|
|
27
|
+
const closable_price = currency === 'USDT'
|
|
28
|
+
? 1
|
|
29
|
+
: Number(((_a = spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)) === null || _a === void 0 ? void 0 : _a.last) || 0);
|
|
26
30
|
const volume = Number(((_b = balances[currency]) === null || _b === void 0 ? void 0 : _b.available) || 0);
|
|
31
|
+
if (Math.abs(volume) === 0)
|
|
32
|
+
return undefined;
|
|
27
33
|
return {
|
|
28
34
|
datasource_id: 'gate/spot',
|
|
29
35
|
position_id: currency,
|
|
30
|
-
product_id: currency,
|
|
36
|
+
product_id: (0, utils_1.encodePath)('GATE', 'SPOT', currency),
|
|
31
37
|
direction: 'LONG',
|
|
32
38
|
volume,
|
|
33
39
|
free_volume: volume,
|
|
34
40
|
closable_price,
|
|
35
41
|
position_price: closable_price,
|
|
36
|
-
floating_profit:
|
|
42
|
+
floating_profit: closable_price * volume,
|
|
37
43
|
valuation: closable_price * volume,
|
|
38
44
|
};
|
|
39
45
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AACA,uDAAwE;AACxE,qDAAsD;AACtD,qCAA+C;
|
|
1
|
+
{"version":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AQ,CAAC,0CAAE,SAAS,KAAI,CAAC,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC7C,OAAO;YACL,aAAa,EAAE,WAAW;YAC1B,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;YAChD,SAAS,EAAE,MAAM;YACjB,MAAM;YACN,WAAW,EAAE,MAAM;YACnB,cAAc;YACd,cAAc,EAAE,cAAc;YAC9B,eAAe,EAAE,cAAc,GAAG,MAAM;YACxC,SAAS,EAAE,cAAc,GAAG,MAAM;SACtB,CAAC;IACjB,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,IAAI,EAAqB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,eAAe,EAAE,GAAG,aAAa,CAAC,CAAC;AAChD,CAAC,CAAC;AAxCW,QAAA,qBAAqB,yBAwChC","sourcesContent":["import type { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { getUnifiedAccounts, ICredential } from '../../api/private-api';\nimport { getSpotTickers } from '../../api/public-api';\nimport { loadFuturePositions } from './future';\nimport { encodePath } from '@yuants/utils';\n\nexport const getUnifiedAccountInfo = async (credential: ICredential) => {\n const [futurePositions, unifiedAccount, spotTickers] = await Promise.all([\n loadFuturePositions(credential),\n getUnifiedAccounts(credential, {}),\n getSpotTickers({}),\n ]);\n\n const balances = unifiedAccount?.balances ?? {};\n const spotTickerList = Array.isArray(spotTickers) ? spotTickers : [];\n const spotPositions: IPosition[] = Object.keys(balances)\n .map((currency) => {\n let currency_pair = `${currency}_USDT`;\n if (currency === 'SOL2') {\n currency_pair = 'SOL_USDT';\n }\n if (currency === 'GTSOL') {\n currency_pair = 'SOL_USDT';\n }\n const closable_price =\n currency === 'USDT'\n ? 1\n : Number(spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)?.last || 0);\n const volume = Number(balances[currency]?.available || 0);\n if (Math.abs(volume) === 0) return undefined;\n return {\n datasource_id: 'gate/spot',\n position_id: currency,\n product_id: encodePath('GATE', 'SPOT', currency),\n direction: 'LONG',\n volume,\n free_volume: volume,\n closable_price,\n position_price: closable_price,\n floating_profit: closable_price * volume,\n valuation: closable_price * volume,\n } as IPosition;\n })\n .filter((item): item is IPosition => !!item);\n\n return [...futurePositions, ...spotPositions];\n};\n"]}
|
package/lib/services/exchange.js
CHANGED
|
@@ -4,7 +4,6 @@ const exchange_1 = require("@yuants/exchange");
|
|
|
4
4
|
const protocol_1 = require("@yuants/protocol");
|
|
5
5
|
const utils_1 = require("@yuants/utils");
|
|
6
6
|
const profile_1 = require("./accounts/profile");
|
|
7
|
-
const spot_1 = require("./accounts/spot");
|
|
8
7
|
const unified_1 = require("./accounts/unified");
|
|
9
8
|
const cancelOrder_1 = require("./orders/cancelOrder");
|
|
10
9
|
const submitOrder_1 = require("./orders/submitOrder");
|
|
@@ -25,12 +24,11 @@ const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
|
25
24
|
getCredentialId: profile_1.getCredentialId,
|
|
26
25
|
listProducts: product_1.listProducts,
|
|
27
26
|
getPositions: async function (credential) {
|
|
28
|
-
const [
|
|
29
|
-
|
|
30
|
-
(0, spot_1.getSpotAccountInfo)(credential),
|
|
27
|
+
const [unifiedPositions] = await Promise.all([
|
|
28
|
+
// getFutureAccountInfo(credential),
|
|
31
29
|
(0, unified_1.getUnifiedAccountInfo)(credential),
|
|
32
30
|
]);
|
|
33
|
-
return [...
|
|
31
|
+
return [...unifiedPositions];
|
|
34
32
|
},
|
|
35
33
|
getOrders: async function (credential) {
|
|
36
34
|
const [umOrders] = await Promise.all([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AAEA,+CAA2D;AAC3D,+CAA4C;AAC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AAU,EAAC,UAAU,CAAC,CAAC,CAAC,8BAA8B;QAC5E,6BAA6B;QAC7B,oEAAoE;QACpE,+EAA+E;QAC/E,IAAI;QACJ,IAAI,QAAQ,KAAK,QAAQ,EAAE;YACzB,MAAM,SAAS,GAAG,MAAM,IAAA,6BAAoB,EAAC,UAAU,CAAC,CAAC;YACzD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAC3E;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,oBAAoB,EAApB,iCAAoB;IACpB,WAAW,EAAX,yBAAW;IACX,WAAW,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,WAAW,EAAX,yBAAW;CACZ,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath } from '@yuants/utils';\nimport { getCredentialId } from './accounts/profile';\nimport { getUnifiedAccountInfo } from './accounts/unified';\nimport { cancelOrder } from './orders/cancelOrder';\nimport { submitOrder } from './orders/submitOrder';\nimport { getFutureAccountInfo } from './accounts/future';\nimport { ICredential } from '../api/private-api';\nimport { listOrders, getOrdersByProductId } from './orders/listOrders';\nimport { listProducts } from './markets/product';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'GATE',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n getCredentialId,\n listProducts,\n getPositions: async function (credential: ICredential): Promise<IPosition[]> {\n const [unifiedPositions] = await Promise.all([\n // getFutureAccountInfo(credential),\n getUnifiedAccountInfo(credential),\n ]);\n return [...unifiedPositions];\n },\n getOrders: async function (credential: ICredential): Promise<IOrder[]> {\n const [umOrders] = await Promise.all([\n listOrders(credential),\n // listSpotOrders(credential),\n ]);\n return [...umOrders];\n },\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const [_, instType] = decodePath(product_id); // BINANCE/USDT-FUTURE/ADAUSDT\n // if (instType === 'SPOT') {\n // const positions = await getSpotAccountInfoSnapshot(credential);\n // return positions.filter((position) => position.product_id === product_id);\n // }\n if (instType === 'FUTURE') {\n const positions = await getFutureAccountInfo(credential);\n return positions.filter((position) => position.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n },\n getOrdersByProductId,\n submitOrder,\n modifyOrder: () => {\n throw new Error('Not implemented');\n },\n cancelOrder,\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-gate",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.15",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@yuants/utils": "0.14.0",
|
|
19
19
|
"@yuants/data-series": "0.3.51",
|
|
20
20
|
"@yuants/data-interest-rate": "0.1.48",
|
|
21
|
-
"@yuants/exchange": "0.
|
|
21
|
+
"@yuants/exchange": "0.3.0",
|
|
22
22
|
"rxjs": "~7.5.6"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
package/temp/package-deps.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"apps/vendor-gate/AGENTS.md": "59be8d734f8a91ae5f7377e7c688f1fccb8641b7",
|
|
3
|
-
"apps/vendor-gate/CHANGELOG.json": "
|
|
4
|
-
"apps/vendor-gate/CHANGELOG.md": "
|
|
3
|
+
"apps/vendor-gate/CHANGELOG.json": "9d56067ef8a980ef3ed454c2d00d8561ae379483",
|
|
4
|
+
"apps/vendor-gate/CHANGELOG.md": "3198f602c83611df5c4f9ef6e49d770e57675ed2",
|
|
5
5
|
"apps/vendor-gate/README.md": "ea5ee3a61cd87d9104d729902dfaccac9b9913e0",
|
|
6
6
|
"apps/vendor-gate/SESSION_NOTES.md": "768c89019ebca263968450d853c8038b0d56f619",
|
|
7
7
|
"apps/vendor-gate/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
@@ -9,18 +9,18 @@
|
|
|
9
9
|
"apps/vendor-gate/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
10
10
|
"apps/vendor-gate/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
11
11
|
"apps/vendor-gate/etc/vendor-gate.api.md": "970682cd589432de553cc5cee2a0abe73814a515",
|
|
12
|
-
"apps/vendor-gate/package.json": "
|
|
12
|
+
"apps/vendor-gate/package.json": "f55c40cbf0cb8436298edd8f5d80be67cab1915c",
|
|
13
13
|
"apps/vendor-gate/src/api/http-client.ts": "013dcdfebaf136c83274638ceb697146a8e3f218",
|
|
14
14
|
"apps/vendor-gate/src/api/private-api.ts": "644570bc10fd22b7e9d4d6a0267397af9d5510f0",
|
|
15
15
|
"apps/vendor-gate/src/api/public-api.ts": "2371d8be290d3c6d373f704b6b10d0cc4dba8af4",
|
|
16
16
|
"apps/vendor-gate/src/api/rate-limiter.ts": "047c51029ffcaf98190cfd04d96816bbced5fa7c",
|
|
17
17
|
"apps/vendor-gate/src/index.ts": "0b87307abd7f94126f312c7a02138c158e4de07a",
|
|
18
|
-
"apps/vendor-gate/src/services/accounts/future.ts": "
|
|
18
|
+
"apps/vendor-gate/src/services/accounts/future.ts": "840e18154f16ad4a3e265195e39eb02bd90ab237",
|
|
19
19
|
"apps/vendor-gate/src/services/accounts/profile.ts": "4132c7c3d9760b9a6694d5b3eae7e8b2847fe6c1",
|
|
20
|
-
"apps/vendor-gate/src/services/accounts/spot.ts": "
|
|
21
|
-
"apps/vendor-gate/src/services/accounts/unified.ts": "
|
|
20
|
+
"apps/vendor-gate/src/services/accounts/spot.ts": "b861a4584e73eb181d79ea28ac216747895df086",
|
|
21
|
+
"apps/vendor-gate/src/services/accounts/unified.ts": "f49b87a161553fd2abcce20ec76f8df3ae98c2bc",
|
|
22
22
|
"apps/vendor-gate/src/services/default-credential.ts": "b9ffa157b818148450bfaaf4851597e91901190c",
|
|
23
|
-
"apps/vendor-gate/src/services/exchange.ts": "
|
|
23
|
+
"apps/vendor-gate/src/services/exchange.ts": "5672321dea53f8c4592d8d2163de47075ba8fef5",
|
|
24
24
|
"apps/vendor-gate/src/services/markets/interest-rate.ts": "e669eb1d664448f309bb062907b273157d1c111e",
|
|
25
25
|
"apps/vendor-gate/src/services/markets/product.ts": "38f600251ddb0a17e111ccceda9231bee98c60a3",
|
|
26
26
|
"apps/vendor-gate/src/services/orders/cancelOrder.ts": "7dfdd30eaac89742f1050bf0fb47d8053ccecb28",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"libraries/utils/temp/package-deps.json": "6d58e9b325e8d16de8a878c32010f626b12a01da",
|
|
40
40
|
"libraries/data-series/temp/package-deps.json": "c89ebffe302757903aa54eff78f76cb855486b8c",
|
|
41
41
|
"libraries/data-interest-rate/temp/package-deps.json": "cef1e1cb0116ad593c24635684e0cbf03488d67c",
|
|
42
|
-
"libraries/exchange/temp/package-deps.json": "
|
|
42
|
+
"libraries/exchange/temp/package-deps.json": "81cd228057e0c05ac9f39d4d22b19a59e9a4792f",
|
|
43
43
|
"libraries/extension/temp/package-deps.json": "9569c553c2f9a7d50b70d8f101fc2d3825aaccb9",
|
|
44
44
|
"tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
|
|
45
45
|
}
|