@yuants/vendor-gate 0.4.17 → 0.4.19

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,23 +1,19 @@
1
- import { firstValueFrom } from 'rxjs';
2
- import { getFuturePositions, getFuturesAccounts } from '../../api/private-api';
3
- import { mapProductIdToUsdtFutureProduct$ } from '../markets/product';
4
1
  import { encodePath } from '@yuants/utils';
2
+ import { getFuturePositions, getFuturesAccounts } from '../../api/private-api';
3
+ import { productCache } from '../markets/product';
5
4
  export const loadFuturePositions = async (credential) => {
6
- const [positionsRes, productMap] = await Promise.all([
7
- getFuturePositions(credential, 'usdt'),
8
- firstValueFrom(mapProductIdToUsdtFutureProduct$),
9
- ]);
10
- const positions = Array.isArray(positionsRes) ? positionsRes : [];
11
- return positions
12
- .filter((pos) => Math.abs(pos.size) > 0)
13
- .map((position) => {
14
- var _a;
5
+ var _a;
6
+ const positions = [];
7
+ const positionsRes = await getFuturePositions(credential, 'usdt');
8
+ for (const position of Array.isArray(positionsRes) ? positionsRes : []) {
9
+ if (!(Math.abs(position.size) > 0))
10
+ continue;
15
11
  const product_id = encodePath('GATE', 'FUTURE', position.contract);
16
- const theProduct = productMap.get(product_id);
12
+ const theProduct = await productCache.query(product_id);
17
13
  const volume = Math.abs(position.size);
18
14
  const closable_price = Number(position.mark_price);
19
15
  const valuation = volume * closable_price * ((_a = theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) !== null && _a !== void 0 ? _a : 1);
20
- return {
16
+ positions.push({
21
17
  datasource_id: 'GATE',
22
18
  position_id: `${position.contract}-${position.leverage}-${position.mode}`,
23
19
  product_id,
@@ -34,8 +30,9 @@ export const loadFuturePositions = async (credential) => {
34
30
  closable_price,
35
31
  floating_profit: Number(position.unrealised_pnl),
36
32
  valuation,
37
- };
38
- });
33
+ });
34
+ }
35
+ return positions;
39
36
  };
40
37
  export const getFutureAccountInfo = async (credential) => {
41
38
  const [positions, rawAccount] = await Promise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V,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;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,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"]}
1
+ {"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;;IACzF,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAElE,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,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AAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,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 { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { productCache } from '../markets/product';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n const positionsRes = await getFuturePositions(credential, 'usdt');\n\n for (const position of Array.isArray(positionsRes) ? positionsRes : []) {\n if (!(Math.abs(position.size) > 0)) continue;\n\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = await productCache.query(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 positions.push({\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 return positions;\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"]}
@@ -1,41 +1,8 @@
1
+ import { createProductCache } from '@yuants/data-product';
1
2
  import { Terminal } from '@yuants/protocol';
2
- import { createSQLWriter } from '@yuants/sql';
3
- import { defer, from, map, mergeMap, repeat, retry, shareReplay, Subject, tap, toArray } from 'rxjs';
4
- import { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';
5
3
  import { encodePath } from '@yuants/utils';
6
- const terminal = Terminal.fromNodeEnv();
7
- const product$ = new Subject();
8
- const usdtFutureProducts$ = defer(() => getFuturesContracts('usdt', {})).pipe(mergeMap((contracts) => from(contracts).pipe(map((contract) => {
9
- const [base, quote] = contract.name.split('_');
10
- return {
11
- datasource_id: 'GATE',
12
- product_id: encodePath('GATE', 'FUTURE', contract.name),
13
- base_currency: base,
14
- quote_currency: quote,
15
- value_scale: Number(contract.quanto_multiplier),
16
- price_step: Number(contract.order_price_round),
17
- volume_step: 1,
18
- name: '',
19
- value_scale_unit: '',
20
- margin_rate: 0,
21
- value_based_cost: 0,
22
- volume_based_cost: 0,
23
- max_position: 0,
24
- max_volume: 0,
25
- allow_long: true,
26
- allow_short: true,
27
- market_id: 'GATE/USDT-FUTURE',
28
- no_interest_rate: false,
29
- };
30
- }), tap((item) => product$.next(item)), toArray())), repeat({ delay: 3600000 }), retry({ delay: 60000 }), shareReplay(1));
31
- usdtFutureProducts$.subscribe();
32
- export const mapProductIdToUsdtFutureProduct$ = usdtFutureProducts$.pipe(map((items) => new Map(items.map((item) => [item.product_id, item]))), shareReplay(1));
33
- createSQLWriter(terminal, {
34
- data$: product$,
35
- tableName: 'product',
36
- conflictKeys: ['datasource_id', 'product_id'],
37
- writeInterval: 1000,
38
- });
4
+ import { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';
5
+ export const productCache = createProductCache(Terminal.fromNodeEnv());
39
6
  export const listProducts = async () => {
40
7
  const [futureProducts, spotProducts] = await Promise.all([
41
8
  getFuturesContracts('usdt', {}),
@@ -53,7 +20,7 @@ export const listProducts = async () => {
53
20
  volume_step: 1,
54
21
  name: '',
55
22
  value_scale_unit: '',
56
- margin_rate: 0,
23
+ margin_rate: 1 / Number(contract.leverage_max),
57
24
  value_based_cost: 0,
58
25
  volume_based_cost: 0,
59
26
  max_position: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrG,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAY,CAAC;AAEzC,MAAM,mBAAmB,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC3E,QAAQ,CAAC,CAAC,SAAS,EAAE,EAAE,CACrB,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAClB,GAAG,CAAC,CAAC,QAAQ,EAAY,EAAE;IACzB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO;QACL,aAAa,EAAE,MAAM;QACrB,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC;QACvD,aAAa,EAAE,IAAI;QACnB,cAAc,EAAE,KAAK;QACrB,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC/C,UAAU,EAAE,MAAM,CAAC,QAAQ,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AC1C,WAAW,EAAE,CAAC;QACd,IAAI,EAAE,EAAE;QACR,gBAAgB,EAAE,EAAE;QACpB,WAAW,EAAE,CAAC;QACd,gBAAgB,EAAE,CAAC;QACnB,iBAAiB,EAAE,CAAC;QACpB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,KAAK;QAClB,SAAS,EAAE,gBAAgB;QAC3B,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC,CAAC;IAEJ,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AAC1B,CAAC,CAAC","sourcesContent":["import { IProduct } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { defer, from, map, mergeMap, repeat, retry, shareReplay, Subject, tap, toArray } from 'rxjs';\nimport { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';\nimport { encodePath } from '@yuants/utils';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst product$ = new Subject<IProduct>();\n\nconst usdtFutureProducts$ = defer(() => getFuturesContracts('usdt', {})).pipe(\n mergeMap((contracts) =>\n from(contracts).pipe(\n map((contract): IProduct => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n }),\n tap((item) => product$.next(item)),\n toArray(),\n ),\n ),\n repeat({ delay: 3_600_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\nusdtFutureProducts$.subscribe();\n\nexport const mapProductIdToUsdtFutureProduct$ = usdtFutureProducts$.pipe(\n map((items) => new Map(items.map((item) => [item.product_id, item]))),\n shareReplay(1),\n);\n\ncreateSQLWriter(terminal, {\n data$: product$,\n tableName: 'product',\n conflictKeys: ['datasource_id', 'product_id'],\n writeInterval: 1000,\n});\n\nexport const listProducts = async () => {\n const [futureProducts, spotProducts] = await Promise.all([\n getFuturesContracts('usdt', {}),\n getSpotCurrencyPairs(),\n ]);\n const fps = futureProducts.map((contract) => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n const sps = spotProducts.map((spot) => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', spot.id),\n base_currency: spot.base,\n quote_currency: spot.quote,\n value_scale: 1,\n price_step: Number(`1e-${spot.precision}`),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'GATE/USDT-SPOT',\n no_interest_rate: false,\n }));\n\n return [...fps, ...sps];\n};\n"]}
1
+ {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,C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QACtC,aAAa,EAAE,MAAM;QACrB,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;QAC/C,aAAa,EAAE,IAAI,CAAC,IAAI;QACxB,cAAc,EAAE,IAAI,CAAC,KAAK;QAC1B,WAAW,EAAE,CAAC;QACd,UAAU,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1C,WAAW,EAAE,CAAC;QACd,IAAI,EAAE,EAAE;QACR,gBAAgB,EAAE,EAAE;QACpB,WAAW,EAAE,CAAC;QACd,gBAAgB,EAAE,CAAC;QACnB,iBAAiB,EAAE,CAAC;QACpB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,KAAK;QAClB,SAAS,EAAE,gBAAgB;QAC3B,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC,CAAC;IAEJ,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AAC1B,CAAC,CAAC","sourcesContent":["import { createProductCache } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';\n\nexport const productCache = createProductCache(Terminal.fromNodeEnv());\n\nexport const listProducts = async () => {\n const [futureProducts, spotProducts] = await Promise.all([\n getFuturesContracts('usdt', {}),\n getSpotCurrencyPairs(),\n ]);\n const fps = futureProducts.map((contract) => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 1 / Number(contract.leverage_max),\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n const sps = spotProducts.map((spot) => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', spot.id),\n base_currency: spot.base,\n quote_currency: spot.quote,\n value_scale: 1,\n price_step: Number(`1e-${spot.precision}`),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'GATE/USDT-SPOT',\n no_interest_rate: false,\n }));\n\n return [...fps, ...sps];\n};\n"]}
@@ -33,10 +33,10 @@ export const submitOrder = async (credential, order) => {
33
33
  if (price === undefined) {
34
34
  throw new Error('Limit/Maker order requires price');
35
35
  }
36
- const [, TYPE] = decodePath(order.product_id);
36
+ const [, TYPE, contract] = decodePath(order.product_id);
37
37
  if (TYPE === 'FUTURE') {
38
38
  const res = await postFutureOrders(credential, 'usdt', {
39
- contract: order.product_id,
39
+ contract,
40
40
  size,
41
41
  price,
42
42
  tif,
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAAe,EAAE;QACvB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,CAAC,CAAC;QACX,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,CAAC,CAAC,CAAC;QACZ;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,eAAe,EAAE,CAAC,CAAC;KACtE;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,UAAmB,EAAU,EAAE;IACjD,IAAI,UAAU,KAA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E,MAAM,EAAE;YACrD,QAAQ,EAAE,KAAK,CAAC,UAAU;YAC1B,IAAI;YACJ,KAAK;YACL,GAAG;YACH,WAAW;SACZ,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,KAAK,EAAE;YACb,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClF,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;SACzB;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nconst resolveTif = (order_type?: string): string => {\n if (order_type === 'MARKET') return 'ioc';\n if (order_type === 'LIMIT' || order_type === 'MAKER') return 'gtc';\n throw new Error(`Unsupported order_type: ${order_type}`);\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = resolveTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract: order.product_id,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\n};\n"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAAe,EAAE;QACvB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,CAAC,CAAC;QACX,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,CAAC,CAAC,CAAC;QACZ;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,eAAe,EAAE,CAAC,CAAC;KACtE;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,UAAmB,EAAU,EAAE;IACjD,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1C,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACnE,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;QACrB,MAAM,IAAI,KAA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C,CAAC;YAClF,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;SACzB;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nconst resolveTif = (order_type?: string): string => {\n if (order_type === 'MARKET') return 'ioc';\n if (order_type === 'LIMIT' || order_type === 'MAKER') return 'gtc';\n throw new Error(`Unsupported order_type: ${order_type}`);\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = resolveTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE, contract] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\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,CAkCtF,CAAC;AAEF,eAAO,MAAM,oBAAoB,eAAsB,WAAW,yBAOjE,CAAC"}
1
+ {"version":3,"file":"future.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG5F,eAAO,MAAM,mBAAmB,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAkCtF,CAAC;AAEF,eAAO,MAAM,oBAAoB,eAAsB,WAAW,yBAOjE,CAAC"}
@@ -1,26 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFutureAccountInfo = exports.loadFuturePositions = void 0;
4
- const rxjs_1 = require("rxjs");
4
+ const utils_1 = require("@yuants/utils");
5
5
  const private_api_1 = require("../../api/private-api");
6
6
  const product_1 = require("../markets/product");
7
- const utils_1 = require("@yuants/utils");
8
7
  const loadFuturePositions = async (credential) => {
9
- const [positionsRes, productMap] = await Promise.all([
10
- (0, private_api_1.getFuturePositions)(credential, 'usdt'),
11
- (0, rxjs_1.firstValueFrom)(product_1.mapProductIdToUsdtFutureProduct$),
12
- ]);
13
- const positions = Array.isArray(positionsRes) ? positionsRes : [];
14
- return positions
15
- .filter((pos) => Math.abs(pos.size) > 0)
16
- .map((position) => {
17
- var _a;
8
+ var _a;
9
+ const positions = [];
10
+ const positionsRes = await (0, private_api_1.getFuturePositions)(credential, 'usdt');
11
+ for (const position of Array.isArray(positionsRes) ? positionsRes : []) {
12
+ if (!(Math.abs(position.size) > 0))
13
+ continue;
18
14
  const product_id = (0, utils_1.encodePath)('GATE', 'FUTURE', position.contract);
19
- const theProduct = productMap.get(product_id);
15
+ const theProduct = await product_1.productCache.query(product_id);
20
16
  const volume = Math.abs(position.size);
21
17
  const closable_price = Number(position.mark_price);
22
18
  const valuation = volume * closable_price * ((_a = theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) !== null && _a !== void 0 ? _a : 1);
23
- return {
19
+ positions.push({
24
20
  datasource_id: 'GATE',
25
21
  position_id: `${position.contract}-${position.leverage}-${position.mode}`,
26
22
  product_id,
@@ -37,8 +33,9 @@ const loadFuturePositions = async (credential) => {
37
33
  closable_price,
38
34
  floating_profit: Number(position.unrealised_pnl),
39
35
  valuation,
40
- };
41
- });
36
+ });
37
+ }
38
+ return positions;
42
39
  };
43
40
  exports.loadFuturePositions = loadFuturePositions;
44
41
  const getFutureAccountInfo = async (credential) => {
@@ -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,EAAC,0CAAgC,CAAC;KACjD,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAClE,OAAO,SAAS;SACb,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAA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uB,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"]}
1
+ {"version":3,"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,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,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,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 { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { productCache } from '../markets/product';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n const positionsRes = await getFuturePositions(credential, 'usdt');\n\n for (const position of Array.isArray(positionsRes) ? positionsRes : []) {\n if (!(Math.abs(position.size) > 0)) continue;\n\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = await productCache.query(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 positions.push({\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 return positions;\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"]}
@@ -1,5 +1,4 @@
1
- import { IProduct } from '@yuants/data-product';
2
- export declare const mapProductIdToUsdtFutureProduct$: import("rxjs").Observable<Map<string, IProduct>>;
1
+ export declare const productCache: import("@yuants/cache").ICache<import("@yuants/data-product").IProduct>;
3
2
  export declare const listProducts: () => Promise<{
4
3
  datasource_id: string;
5
4
  product_id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAgDhD,eAAO,MAAM,gCAAgC,kDAG5C,CAAC;AASF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;IAkDxB,CAAC"}
1
+ {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,yEAA6C,CAAC;AAEvE,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;IAkDxB,CAAC"}
@@ -1,44 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listProducts = exports.mapProductIdToUsdtFutureProduct$ = void 0;
3
+ exports.listProducts = exports.productCache = void 0;
4
+ const data_product_1 = require("@yuants/data-product");
4
5
  const protocol_1 = require("@yuants/protocol");
5
- const sql_1 = require("@yuants/sql");
6
- const rxjs_1 = require("rxjs");
7
- const public_api_1 = require("../../api/public-api");
8
6
  const utils_1 = require("@yuants/utils");
9
- const terminal = protocol_1.Terminal.fromNodeEnv();
10
- const product$ = new rxjs_1.Subject();
11
- const usdtFutureProducts$ = (0, rxjs_1.defer)(() => (0, public_api_1.getFuturesContracts)('usdt', {})).pipe((0, rxjs_1.mergeMap)((contracts) => (0, rxjs_1.from)(contracts).pipe((0, rxjs_1.map)((contract) => {
12
- const [base, quote] = contract.name.split('_');
13
- return {
14
- datasource_id: 'GATE',
15
- product_id: (0, utils_1.encodePath)('GATE', 'FUTURE', contract.name),
16
- base_currency: base,
17
- quote_currency: quote,
18
- value_scale: Number(contract.quanto_multiplier),
19
- price_step: Number(contract.order_price_round),
20
- volume_step: 1,
21
- name: '',
22
- value_scale_unit: '',
23
- margin_rate: 0,
24
- value_based_cost: 0,
25
- volume_based_cost: 0,
26
- max_position: 0,
27
- max_volume: 0,
28
- allow_long: true,
29
- allow_short: true,
30
- market_id: 'GATE/USDT-FUTURE',
31
- no_interest_rate: false,
32
- };
33
- }), (0, rxjs_1.tap)((item) => product$.next(item)), (0, rxjs_1.toArray)())), (0, rxjs_1.repeat)({ delay: 3600000 }), (0, rxjs_1.retry)({ delay: 60000 }), (0, rxjs_1.shareReplay)(1));
34
- usdtFutureProducts$.subscribe();
35
- exports.mapProductIdToUsdtFutureProduct$ = usdtFutureProducts$.pipe((0, rxjs_1.map)((items) => new Map(items.map((item) => [item.product_id, item]))), (0, rxjs_1.shareReplay)(1));
36
- (0, sql_1.createSQLWriter)(terminal, {
37
- data$: product$,
38
- tableName: 'product',
39
- conflictKeys: ['datasource_id', 'product_id'],
40
- writeInterval: 1000,
41
- });
7
+ const public_api_1 = require("../../api/public-api");
8
+ exports.productCache = (0, data_product_1.createProductCache)(protocol_1.Terminal.fromNodeEnv());
42
9
  const listProducts = async () => {
43
10
  const [futureProducts, spotProducts] = await Promise.all([
44
11
  (0, public_api_1.getFuturesContracts)('usdt', {}),
@@ -56,7 +23,7 @@ const listProducts = async () => {
56
23
  volume_step: 1,
57
24
  name: '',
58
25
  value_scale_unit: '',
59
- margin_rate: 0,
26
+ margin_rate: 1 / Number(contract.leverage_max),
60
27
  value_based_cost: 0,
61
28
  volume_based_cost: 0,
62
29
  max_position: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAC5C,qCAA8C;AAC9C,+BAAqG;AACrG,qDAAiF;AACjF,yCAA2C;AAE3C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,QAAQ,GAAG,IAAI,cAAO,EAAY,CAAC;AAEzC,MAAM,mBAAmB,GAAG,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,gCAAmB,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC3E,IAAA,eAAQ,EAAC,CAAC,SAAS,EAAE,EAAE,CACrB,IAAA,WAAI,EAAC,SAAS,CAAC,CAAC,IAAI,CAClB,IAAA,UAAG,EAAC,CAAC,QAAQ,EAAY,EAAE;IACzB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO;QACL,aAAa,EAAE,MAAM;QACrB,UAAU,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC;QACvD,aAAa,EAAE,IAAI;QACnB,cAAc,EAAE,KAAK;QACrB,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC/C,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC9C,WAAW,EAAE,CAAC;QACd,IAAI,EAAE,EAAE;QACR,gBAAgB,EAAE,EAAE;QACpB,WAAW,EAAE,CAAC;QACd,gBAAgB,E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WAAW,EAAE,CAAC;QACd,gBAAgB,EAAE,CAAC;QACnB,iBAAiB,EAAE,CAAC;QACpB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,KAAK;QAClB,SAAS,EAAE,gBAAgB;QAC3B,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC,CAAC;IAEJ,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AAC1B,CAAC,CAAC;AAlDW,QAAA,YAAY,gBAkDvB","sourcesContent":["import { IProduct } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { defer, from, map, mergeMap, repeat, retry, shareReplay, Subject, tap, toArray } from 'rxjs';\nimport { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';\nimport { encodePath } from '@yuants/utils';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst product$ = new Subject<IProduct>();\n\nconst usdtFutureProducts$ = defer(() => getFuturesContracts('usdt', {})).pipe(\n mergeMap((contracts) =>\n from(contracts).pipe(\n map((contract): IProduct => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n }),\n tap((item) => product$.next(item)),\n toArray(),\n ),\n ),\n repeat({ delay: 3_600_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\nusdtFutureProducts$.subscribe();\n\nexport const mapProductIdToUsdtFutureProduct$ = usdtFutureProducts$.pipe(\n map((items) => new Map(items.map((item) => [item.product_id, item]))),\n shareReplay(1),\n);\n\ncreateSQLWriter(terminal, {\n data$: product$,\n tableName: 'product',\n conflictKeys: ['datasource_id', 'product_id'],\n writeInterval: 1000,\n});\n\nexport const listProducts = async () => {\n const [futureProducts, spotProducts] = await Promise.all([\n getFuturesContracts('usdt', {}),\n getSpotCurrencyPairs(),\n ]);\n const fps = futureProducts.map((contract) => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n const sps = spotProducts.map((spot) => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', spot.id),\n base_currency: spot.base,\n quote_currency: spot.quote,\n value_scale: 1,\n price_step: Number(`1e-${spot.precision}`),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'GATE/USDT-SPOT',\n no_interest_rate: false,\n }));\n\n return [...fps, ...sps];\n};\n"]}
1
+ {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":";;;AAAA,uDAA0D;AAC1D,+CAA4C;AAC5C,yCAA2C;AAC3C,qDAAiF;AAEpE,QAAA,YAAY,GAAG,IAAA,iCAAkB,EAAC,mBAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AAEhE,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;IACrC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC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;QACd,UAAU,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1C,WAAW,EAAE,CAAC;QACd,IAAI,EAAE,EAAE;QACR,gBAAgB,EAAE,EAAE;QACpB,WAAW,EAAE,CAAC;QACd,gBAAgB,EAAE,CAAC;QACnB,iBAAiB,EAAE,CAAC;QACpB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,KAAK;QAClB,SAAS,EAAE,gBAAgB;QAC3B,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC,CAAC;IAEJ,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AAC1B,CAAC,CAAC;AAlDW,QAAA,YAAY,gBAkDvB","sourcesContent":["import { createProductCache } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';\n\nexport const productCache = createProductCache(Terminal.fromNodeEnv());\n\nexport const listProducts = async () => {\n const [futureProducts, spotProducts] = await Promise.all([\n getFuturesContracts('usdt', {}),\n getSpotCurrencyPairs(),\n ]);\n const fps = futureProducts.map((contract) => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 1 / Number(contract.leverage_max),\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n const sps = spotProducts.map((spot) => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', spot.id),\n base_currency: spot.base,\n quote_currency: spot.quote,\n value_scale: 1,\n price_step: Number(`1e-${spot.precision}`),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'GATE/USDT-SPOT',\n no_interest_rate: false,\n }));\n\n return [...fps, ...sps];\n};\n"]}
@@ -36,10 +36,10 @@ const submitOrder = async (credential, order) => {
36
36
  if (price === undefined) {
37
37
  throw new Error('Limit/Maker order requires price');
38
38
  }
39
- const [, TYPE] = (0, utils_1.decodePath)(order.product_id);
39
+ const [, TYPE, contract] = (0, utils_1.decodePath)(order.product_id);
40
40
  if (TYPE === 'FUTURE') {
41
41
  const res = await (0, private_api_1.postFutureOrders)(credential, 'usdt', {
42
- contract: order.product_id,
42
+ contract,
43
43
  size,
44
44
  price,
45
45
  tif,
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,uDAAsE;AACtE,yCAA2C;AAE3C,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAAe,EAAE;QACvB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,CAAC,CAAC;QACX,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,CAAC,CAAC,CAAC;QACZ;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,eAAe,EAAE,CAAC,CAAC;KACtE;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,UAAmB,EAAU,EAAE;IACjD,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1C,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACnE,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEK,MAAM,W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AAG,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClF,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;SACzB;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC;AAnCW,QAAA,WAAW,eAmCtB","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nconst resolveTif = (order_type?: string): string => {\n if (order_type === 'MARKET') return 'ioc';\n if (order_type === 'LIMIT' || order_type === 'MAKER') return 'gtc';\n throw new Error(`Unsupported order_type: ${order_type}`);\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = resolveTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract: order.product_id,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\n};\n"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,uDAAsE;AACtE,yCAA2C;AAE3C,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAAe,EAAE;QACvB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,CAAC,CAAC;QACX,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,CAAC,CAAC,CAAC;QACZ;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,eAAe,EAAE,CAAC,CAAC;KACtE;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,UAAmB,EAAU,EAAE;IACjD,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1C,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACnE,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEK,MAAM,WAAW,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;KACvC;IACD,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;KACzC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACn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ActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nconst resolveTif = (order_type?: string): string => {\n if (order_type === 'MARKET') return 'ioc';\n if (order_type === 'LIMIT' || order_type === 'MAKER') return 'gtc';\n throw new Error(`Unsupported order_type: ${order_type}`);\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = resolveTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE, contract] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-gate",
3
- "version": "0.4.17",
3
+ "version": "0.4.19",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "lib",
@@ -11,14 +11,14 @@
11
11
  "@yuants/cache": "0.3.3",
12
12
  "@yuants/protocol": "0.53.2",
13
13
  "@yuants/transfer": "0.2.39",
14
- "@yuants/data-account": "0.8.4",
14
+ "@yuants/data-account": "0.9.0",
15
15
  "@yuants/data-order": "0.6.6",
16
16
  "@yuants/sql": "0.9.30",
17
17
  "@yuants/data-product": "0.5.0",
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.3.1",
21
+ "@yuants/exchange": "0.4.0",
22
22
  "@yuants/data-quote": "0.2.43",
23
23
  "rxjs": "~7.5.6"
24
24
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "apps/vendor-gate/AGENTS.md": "59be8d734f8a91ae5f7377e7c688f1fccb8641b7",
3
- "apps/vendor-gate/CHANGELOG.json": "7b0f5a70a37440921781f4d41d58efdff697f3a2",
4
- "apps/vendor-gate/CHANGELOG.md": "0c6aa3d10f6003651958025c930c2dad7a26b23c",
3
+ "apps/vendor-gate/CHANGELOG.json": "8d8cedc678ff3418e8c2287fc08c47e0663ad5b2",
4
+ "apps/vendor-gate/CHANGELOG.md": "5fe2460d9383d2ed4c48ad2a8ddb7ffc8bd67842",
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,38 +9,38 @@
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": "f18c454a51669a7a21283d93a4c4c1f86e0f2e14",
12
+ "apps/vendor-gate/package.json": "cca4b3c5080ed4fef09bb4e43176690a0874d8c7",
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": "faaad3eeeaa9a32e2b96a38a111878011867bd1e",
16
16
  "apps/vendor-gate/src/api/rate-limiter.ts": "047c51029ffcaf98190cfd04d96816bbced5fa7c",
17
17
  "apps/vendor-gate/src/index.ts": "31888627bccab532d55bd91833d80c72a4afae9b",
18
- "apps/vendor-gate/src/services/accounts/future.ts": "840e18154f16ad4a3e265195e39eb02bd90ab237",
18
+ "apps/vendor-gate/src/services/accounts/future.ts": "4e762c193fe8ae4dbe3ae15d45b03bdf0a0fb8c8",
19
19
  "apps/vendor-gate/src/services/accounts/profile.ts": "4132c7c3d9760b9a6694d5b3eae7e8b2847fe6c1",
20
20
  "apps/vendor-gate/src/services/accounts/spot.ts": "b861a4584e73eb181d79ea28ac216747895df086",
21
21
  "apps/vendor-gate/src/services/accounts/unified.ts": "f49b87a161553fd2abcce20ec76f8df3ae98c2bc",
22
22
  "apps/vendor-gate/src/services/default-credential.ts": "b9ffa157b818148450bfaaf4851597e91901190c",
23
23
  "apps/vendor-gate/src/services/exchange.ts": "5672321dea53f8c4592d8d2163de47075ba8fef5",
24
24
  "apps/vendor-gate/src/services/markets/interest-rate.ts": "e669eb1d664448f309bb062907b273157d1c111e",
25
- "apps/vendor-gate/src/services/markets/product.ts": "38f600251ddb0a17e111ccceda9231bee98c60a3",
25
+ "apps/vendor-gate/src/services/markets/product.ts": "64b6c0758e022a0b2c42d69b35bd5d7bd1bfa9c3",
26
26
  "apps/vendor-gate/src/services/markets/quote.ts": "1624d58b9c607ae01300de292de3ed49a2f2e037",
27
27
  "apps/vendor-gate/src/services/orders/cancelOrder.ts": "7dfdd30eaac89742f1050bf0fb47d8053ccecb28",
28
28
  "apps/vendor-gate/src/services/orders/listOrders.ts": "9e4bd2c53cd768d609d1368fd37ff783f9b4d52f",
29
- "apps/vendor-gate/src/services/orders/submitOrder.ts": "830e79b7e4c3fa0ea364382c801fa5527c2d9761",
29
+ "apps/vendor-gate/src/services/orders/submitOrder.ts": "321398ad18bb4012d2a40e4f704bc827ccfaff93",
30
30
  "apps/vendor-gate/src/services/transfer.ts": "cf7d6cbcef3fe217b607f0bba7719d62ac603d66",
31
31
  "apps/vendor-gate/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
32
32
  "apps/vendor-gate/.rush/temp/shrinkwrap-deps.json": "9aa98bfacea2eaf6aa77491dda2ea7632a0ce879",
33
33
  "libraries/cache/temp/package-deps.json": "a4afa15e6462983f9d3735d31dc1ed8a683fb4dc",
34
34
  "libraries/protocol/temp/package-deps.json": "0bd43721e96039b52d7b59c834dc6df45cf75e3f",
35
35
  "libraries/transfer/temp/package-deps.json": "36c58299bd6c841c5ba7252d71881a881570d08c",
36
- "libraries/data-account/temp/package-deps.json": "ae6b0c69040d0d1989525e843717b6e303d95ef2",
36
+ "libraries/data-account/temp/package-deps.json": "711aeba1f1f5f03741475a4290e56d18b39e5305",
37
37
  "libraries/data-order/temp/package-deps.json": "2adac9fc0423f9b1b7ddaa8946ab7af374cc22e1",
38
38
  "libraries/sql/temp/package-deps.json": "4a9a7ec55f04b20459e664e81e76fa74b6c77b39",
39
39
  "libraries/data-product/temp/package-deps.json": "a03f08f30800d5fb52c5d019bda4f8e7ec04e344",
40
40
  "libraries/utils/temp/package-deps.json": "6d58e9b325e8d16de8a878c32010f626b12a01da",
41
41
  "libraries/data-series/temp/package-deps.json": "c89ebffe302757903aa54eff78f76cb855486b8c",
42
42
  "libraries/data-interest-rate/temp/package-deps.json": "cef1e1cb0116ad593c24635684e0cbf03488d67c",
43
- "libraries/exchange/temp/package-deps.json": "ee94ff641b8afcd48484829a1d6d66ffede2a69c",
43
+ "libraries/exchange/temp/package-deps.json": "d30a450879e4d67f56466262bd88a72506594d68",
44
44
  "libraries/data-quote/temp/package-deps.json": "34d079eab44d2bf65e07b112ac2099c6e92a015e",
45
45
  "libraries/extension/temp/package-deps.json": "9569c553c2f9a7d50b70d8f101fc2d3825aaccb9",
46
46
  "tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"