@yuants/vendor-gate 0.4.27 → 0.5.1

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.
Files changed (39) hide show
  1. package/dist/index.js +4 -3
  2. package/dist/index.js.map +1 -1
  3. package/dist/services/accounts/profile.js +5 -26
  4. package/dist/services/accounts/profile.js.map +1 -1
  5. package/dist/services/accounts/unified.js +8 -25
  6. package/dist/services/accounts/unified.js.map +1 -1
  7. package/dist/services/markets/product.js +0 -3
  8. package/dist/services/markets/product.js.map +1 -1
  9. package/dist/services/markets/quote.js.map +1 -1
  10. package/dist/services/quotes.js +51 -0
  11. package/dist/services/quotes.js.map +1 -0
  12. package/dist/services/transfer.js +132 -106
  13. package/dist/services/transfer.js.map +1 -1
  14. package/lib/index.d.ts +4 -3
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +4 -3
  17. package/lib/index.js.map +1 -1
  18. package/lib/services/accounts/profile.d.ts +0 -8
  19. package/lib/services/accounts/profile.d.ts.map +1 -1
  20. package/lib/services/accounts/profile.js +6 -28
  21. package/lib/services/accounts/profile.js.map +1 -1
  22. package/lib/services/accounts/unified.d.ts +1 -1
  23. package/lib/services/accounts/unified.d.ts.map +1 -1
  24. package/lib/services/accounts/unified.js +8 -25
  25. package/lib/services/accounts/unified.js.map +1 -1
  26. package/lib/services/markets/product.d.ts +0 -1
  27. package/lib/services/markets/product.d.ts.map +1 -1
  28. package/lib/services/markets/product.js +1 -4
  29. package/lib/services/markets/product.js.map +1 -1
  30. package/lib/services/markets/quote.js.map +1 -1
  31. package/lib/services/quotes.d.ts +2 -0
  32. package/lib/services/quotes.d.ts.map +1 -0
  33. package/lib/services/quotes.js +53 -0
  34. package/lib/services/quotes.js.map +1 -0
  35. package/lib/services/transfer.d.ts +0 -1
  36. package/lib/services/transfer.js +131 -107
  37. package/lib/services/transfer.js.map +1 -1
  38. package/package.json +14 -14
  39. package/temp/package-deps.json +23 -22
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import './services/markets/product';
2
- import './services/markets/interest-rate';
3
- import './services/transfer';
4
1
  import './services/exchange';
2
+ import './services/markets/interest-rate';
3
+ import './services/markets/product';
5
4
  import './services/markets/quote';
5
+ import './services/quotes';
6
+ import './services/transfer';
6
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC;AACpC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,0BAA0B,CAAC","sourcesContent":["import './services/markets/product';\nimport './services/markets/interest-rate';\nimport './services/transfer';\nimport './services/exchange';\nimport './services/markets/quote';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,kCAAkC,CAAC;AAC1C,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,qBAAqB,CAAC","sourcesContent":["import './services/exchange';\nimport './services/markets/interest-rate';\nimport './services/markets/product';\nimport './services/markets/quote';\nimport './services/quotes';\nimport './services/transfer';\n"]}
@@ -1,30 +1,9 @@
1
- import { createCache } from '@yuants/cache';
1
+ import { encodePath, newError } from '@yuants/utils';
2
2
  import { getAccountDetail } from '../../api/private-api';
3
- import { encodePath } from '@yuants/utils';
4
- const PROFILE_TTL = 60000;
5
- const serializeCredential = (credential) => JSON.stringify(credential);
6
- const deserializeCredential = (key) => JSON.parse(key);
7
- const accountProfileCache = createCache(async (key) => {
8
- const credential = deserializeCredential(key);
9
- const detail = await getAccountDetail(credential);
10
- const uid = `${detail.user_id}`;
11
- return {
12
- uid,
13
- future: `gate/${uid}/future/USDT`,
14
- spot: `gate/${uid}/spot/USDT`,
15
- unified: `gate/${uid}/unified/USDT`,
16
- };
17
- }, { expire: PROFILE_TTL });
18
- export const resolveAccountProfile = async (credential) => {
19
- const profile = await accountProfileCache.query(serializeCredential(credential));
20
- if (!profile) {
21
- throw new Error('Unable to resolve Gate account profile');
22
- }
23
- return profile;
24
- };
25
- export const getAccountIds = resolveAccountProfile;
26
3
  export const getCredentialId = async (credential) => {
27
- const spotAccountInfo = await resolveAccountProfile(credential);
28
- return encodePath('GATE', spotAccountInfo.uid);
4
+ const res = await getAccountDetail(credential);
5
+ if (!res.user_id)
6
+ throw newError('GATE_GET_UID_FAILED', { res });
7
+ return encodePath('GATE', res.user_id);
29
8
  };
30
9
  //# sourceMappingURL=profile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAS3C,MAAM,WAAW,GAAG,KAAM,CAAC;AAE3B,MAAM,mBAAmB,GAAG,CAAC,UAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AACpF,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAe,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAgB,CAAC;AAE3F,MAAM,mBAAmB,GAAG,WAAW,CACrC,KAAK,EAAE,GAAW,EAAE,EAAE;IACpB,MAAM,UAAU,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAChC,OAAO;QACL,GAAG;QACH,MAAM,EAAE,QAAQ,GAAG,cAAc;QACjC,IAAI,EAAE,QAAQ,GAAG,YAAY;QAC7B,OAAO,EAAE,QAAQ,GAAG,eAAe;KACpC,CAAC;AACJ,CAAC,EACD,EAAE,MAAM,EAAE,WAAW,EAAE,CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAA4B,EAAE;IAC/F,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,KAAK,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC;IACjF,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAEnD,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,UAAuB,EAAmB,EAAE;IAChF,MAAM,eAAe,GAAG,MAAM,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAChE,OAAO,UAAU,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC;AACjD,CAAC,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getAccountDetail, ICredential } from '../../api/private-api';\nimport { encodePath } from '@yuants/utils';\n\nexport interface IAccountProfile {\n uid: string;\n future: string;\n spot: string;\n unified: string;\n}\n\nconst PROFILE_TTL = 60_000;\n\nconst serializeCredential = (credential: ICredential) => JSON.stringify(credential);\nconst deserializeCredential = (key: string): ICredential => JSON.parse(key) as ICredential;\n\nconst accountProfileCache = createCache<IAccountProfile>(\n async (key: string) => {\n const credential = deserializeCredential(key);\n const detail = await getAccountDetail(credential);\n const uid = `${detail.user_id}`;\n return {\n uid,\n future: `gate/${uid}/future/USDT`,\n spot: `gate/${uid}/spot/USDT`,\n unified: `gate/${uid}/unified/USDT`,\n };\n },\n { expire: PROFILE_TTL },\n);\n\nexport const resolveAccountProfile = async (credential: ICredential): Promise<IAccountProfile> => {\n const profile = await accountProfileCache.query(serializeCredential(credential));\n if (!profile) {\n throw new Error('Unable to resolve Gate account profile');\n }\n return profile;\n};\n\nexport const getAccountIds = resolveAccountProfile;\n\nexport const getCredentialId = async (credential: ICredential): Promise<string> => {\n const spotAccountInfo = await resolveAccountProfile(credential);\n return encodePath('GATE', spotAccountInfo.uid);\n};\n"]}
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAC;AAEtE,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,UAAuB,EAAmB,EAAE;IAChF,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,CAAC,GAAG,CAAC,OAAO;QAAE,MAAM,QAAQ,CAAC,qBAAqB,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACjE,OAAO,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC,CAAC","sourcesContent":["import { encodePath, newError } from '@yuants/utils';\nimport { getAccountDetail, ICredential } from '../../api/private-api';\n\nexport const getCredentialId = async (credential: ICredential): Promise<string> => {\n const res = await getAccountDetail(credential);\n if (!res.user_id) throw newError('GATE_GET_UID_FAILED', { res });\n return encodePath('GATE', res.user_id);\n};\n"]}
@@ -1,19 +1,7 @@
1
- import { createCache } from '@yuants/cache';
1
+ import { makeSpotPosition } from '@yuants/data-account';
2
2
  import { encodePath } from '@yuants/utils';
3
3
  import { getFuturePositions, getUnifiedAccounts } from '../../api/private-api';
4
4
  import { getSpotTickers } from '../../api/public-api';
5
- import { listProducts } from '../markets/product';
6
- const spotProductMapCache = createCache(async () => {
7
- const products = await listProducts();
8
- const map = new Map();
9
- for (const product of products !== null && products !== void 0 ? products : []) {
10
- const [, instType] = product.product_id.split('/');
11
- if (instType === 'SPOT') {
12
- map.set(product.base_currency, product.product_id);
13
- }
14
- }
15
- return map;
16
- }, { expire: 86400000 });
17
5
  const loadFuturePositions = async (credential) => {
18
6
  const positions = [];
19
7
  const positionsRes = await getFuturePositions(credential, 'usdt');
@@ -48,18 +36,16 @@ const loadFuturePositions = async (credential) => {
48
36
  };
49
37
  export const getUnifiedAccountInfo = async (credential) => {
50
38
  var _a;
51
- const [futurePositions, unifiedAccount, spotTickers, spotProductMap] = await Promise.all([
39
+ const [futurePositions, unifiedAccount, spotTickers] = await Promise.all([
52
40
  loadFuturePositions(credential),
53
41
  getUnifiedAccounts(credential, {}),
54
42
  getSpotTickers({}),
55
- spotProductMapCache.query('').catch(() => undefined),
56
43
  ]);
57
- const resolvedSpotProductMap = spotProductMap !== null && spotProductMap !== void 0 ? spotProductMap : new Map();
58
44
  const balances = (_a = unifiedAccount === null || unifiedAccount === void 0 ? void 0 : unifiedAccount.balances) !== null && _a !== void 0 ? _a : {};
59
45
  const spotTickerList = Array.isArray(spotTickers) ? spotTickers : [];
60
46
  const spotPositions = Object.keys(balances)
61
47
  .map((currency) => {
62
- var _a, _b, _c, _d;
48
+ var _a, _b, _c;
63
49
  let currency_pair = `${currency}_USDT`;
64
50
  if (currency === 'SOL2') {
65
51
  currency_pair = 'SOL_USDT';
@@ -70,22 +56,19 @@ export const getUnifiedAccountInfo = async (credential) => {
70
56
  const closable_price = currency === 'USDT'
71
57
  ? 1
72
58
  : Number(((_a = spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)) === null || _a === void 0 ? void 0 : _a.last) || 0);
73
- const volume = Number(((_b = balances[currency]) === null || _b === void 0 ? void 0 : _b.cross_balance) || 0);
59
+ // TODO: 根据账户模式调整 volume 计算方式
60
+ const volume = Number(((_b = balances[currency]) === null || _b === void 0 ? void 0 : _b.available) || 0);
74
61
  const free_volume = Number(((_c = balances[currency]) === null || _c === void 0 ? void 0 : _c.available) || 0);
75
62
  if (Math.abs(volume) === 0)
76
63
  return undefined;
77
- return {
64
+ return makeSpotPosition({
78
65
  datasource_id: 'GATE',
79
66
  position_id: currency,
80
- product_id: (_d = resolvedSpotProductMap.get(currency)) !== null && _d !== void 0 ? _d : encodePath('GATE', 'SPOT', currency),
81
- direction: 'LONG',
67
+ product_id: encodePath('GATE', 'SPOT', currency + '_USDT'),
82
68
  volume,
83
69
  free_volume,
84
70
  closable_price,
85
- position_price: closable_price,
86
- floating_profit: closable_price * volume,
87
- valuation: closable_price * volume,
88
- };
71
+ });
89
72
  })
90
73
  .filter((item) => !!item);
91
74
  return [...futurePositions, ...spotPositions];
@@ -1 +1 @@
1
- {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,mBAAmB,GAAG,WAAW,CACrC,KAAK,IAAI,EAAE;IACT,MAAM,QAAQ,GAAG,MAAM,YAAY,EAAE,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,KAAK,MAAM,OAAO,IAAI,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,EAAE;QACpC,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnD,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;SACpD;KACF;IACD,OAAO,GAAG,CAAC;AAC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B;QACD,MAAM,cAAc,GAClB,QAAQ,KAAK,MAAM;YACjB,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,aAAa,KAAI,CAAC,CAAC,CAAC;QAC9D,MAAM,WAAW,GAAG,MAAM,CAAC,CAAA,MAAA,QAAQ,CAAC,QAAQ,CAAC,0CAAE,SAAS,KAAI,CAAC,CAAC,CAAC;QAC/D,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC7C,OAAO;YACL,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,MAAA,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,mCAAI,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;YACxF,SAAS,EAAE,MAAM;YACjB,MAAM;YACN,WAAW;YACX,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 { createCache } from '@yuants/cache';\nimport type { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturePositions, getUnifiedAccounts, ICredential } from '../../api/private-api';\nimport { getSpotTickers } from '../../api/public-api';\nimport { listProducts } from '../markets/product';\n\nconst spotProductMapCache = createCache(\n async () => {\n const products = await listProducts();\n const map = new Map<string, string>();\n for (const product of products ?? []) {\n const [, instType] = product.product_id.split('/');\n if (instType === 'SPOT') {\n map.set(product.base_currency, product.product_id);\n }\n }\n return map;\n },\n { expire: 86_400_000 },\n);\n\nconst 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 volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price;\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 liquidation_price: position.liq_price,\n valuation,\n });\n }\n\n return positions;\n};\n\nexport const getUnifiedAccountInfo = async (credential: ICredential) => {\n const [futurePositions, unifiedAccount, spotTickers, spotProductMap] = await Promise.all([\n loadFuturePositions(credential),\n getUnifiedAccounts(credential, {}),\n getSpotTickers({}),\n spotProductMapCache.query('').catch(() => undefined),\n ]);\n\n const resolvedSpotProductMap = spotProductMap ?? new Map<string, string>();\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]?.cross_balance || 0);\n const free_volume = Number(balances[currency]?.available || 0);\n if (Math.abs(volume) === 0) return undefined;\n return {\n datasource_id: 'GATE',\n position_id: currency,\n product_id: resolvedSpotProductMap.get(currency) ?? encodePath('GATE', 'SPOT', currency),\n direction: 'LONG',\n volume,\n free_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"]}
1
+ {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAClF,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,CAAC,EAAE,EAAE;QACtE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAAE,SAAS;QAE7C,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnE,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CA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,EAAqB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,eAAe,EAAE,GAAG,aAAa,CAAC,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import { makeSpotPosition, type IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturePositions, getUnifiedAccounts, ICredential } from '../../api/private-api';\nimport { getSpotTickers } from '../../api/public-api';\n\nconst 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 volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price;\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 liquidation_price: position.liq_price,\n valuation,\n });\n }\n\n return positions;\n};\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 // TODO: 根据账户模式调整 volume 计算方式\n const volume = Number(balances[currency]?.available || 0);\n const free_volume = Number(balances[currency]?.available || 0);\n if (Math.abs(volume) === 0) return undefined;\n return makeSpotPosition({\n datasource_id: 'GATE',\n position_id: currency,\n product_id: encodePath('GATE', 'SPOT', currency + '_USDT'),\n volume,\n free_volume,\n closable_price,\n });\n })\n .filter((item): item is IPosition => !!item);\n\n return [...futurePositions, ...spotPositions];\n};\n"]}
@@ -1,8 +1,5 @@
1
- import { createClientProductCache } from '@yuants/data-product';
2
- import { Terminal } from '@yuants/protocol';
3
1
  import { encodePath } from '@yuants/utils';
4
2
  import { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';
5
- export const productCache = createClientProductCache(Terminal.fromNodeEnv());
6
3
  export const listProducts = async () => {
7
4
  const [futureProducts, spotProducts] = await Promise.all([
8
5
  getFuturesContracts('usdt', {}),
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjF,MAAM,CAAC,MAAM,YAAY,GAAG,wBAAwB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;IACrC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACvD,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC;QAC/B,oBAAoB,EAAE;KACvB,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,cAAc,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ACpB,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 { createClientProductCache } 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 = createClientProductCache(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"]}
1
+ {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;IACrC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACvD,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC;QAC/B,oBAAoB,EAAE;KACvB,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC1C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/C,OAAO;YACL,aAAa,EAAE,MAAM;YACrB,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC;YACvD,aAAa,EAAE,IAAI;YACnB,cAAc,EAAE,KAAK;YACrB,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YAC/C,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YAC9C,WAAW,EAAE,CAAC;YACd,IAAI,EAAE,EAAE;YACR,gBAAgB,EAAE,EAAE;YACpB,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC;YAC9C,gBAAgB,EAAE,CAAC;YACnB,iBAAiB,EAAE,CAAC;YACpB,YAAY,EAAE,CAAC;YACf,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,IAAI;YACjB,SAAS,EAAE,kBAAkB;YAC7B,gBAAgB,EAAE,KAAK;SACxB,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;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 { encodePath } from '@yuants/utils';\nimport { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAA4B,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,UAAU,EACV,KAAK,EACL,KAAK,EACL,MAAM,EACN,OAAO,EACP,GAAG,EACH,KAAK,EACL,QAAQ,EACR,MAAM,EACN,KAAK,EACL,IAAI,EACJ,KAAK,EACL,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE9F,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,eAAe;AACf,MAAM,oBAAoB,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC5E,MAAM,CAAC,EAAE,KAAK,EAAE,OAAQ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CAAC,EACF,KAAK,EAAE,CACR,CAAC;AAEF,QAAQ;AACR,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,EAAE;IAC7C,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,UAAU,EAAE,EAAE;QAC7E,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,aAAa,EAAE;YAClB,MAAM,2BAA2B,CAAC;SACnC;QACD,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,wBAAwB,CAAC;SAChC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,MAAM;SACH,IAAI,CACH,oBAAoB,CAAC,QAAQ,CAAC,WAAW,CAAC,EAC1C,UAAU,CAAC;QACT,QAAQ;QACR,aAAa,EAAE,IAAI;QACnB,SAAS,EAAE,OAAO;QAClB,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC;KAC9C,CAAC,CACH;SACA,SAAS,EAAE,CAAC;CAChB","sourcesContent":["import { IQuote, setMetricsQuoteState } from '@yuants/data-quote';\nimport { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath } from '@yuants/utils';\nimport {\n catchError,\n defer,\n EMPTY,\n filter,\n groupBy,\n map,\n merge,\n mergeMap,\n repeat,\n retry,\n scan,\n share,\n shareReplay,\n} from 'rxjs';\nimport { getFuturesContracts, getFuturesTickers, getSpotTickers } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\n// 获取所有USDT永续合约\nconst usdtFutureContracts$ = defer(() => getFuturesContracts('usdt', {})).pipe(\n repeat({ delay: 3600_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\n// 从tickers获取价格和交易量数据\nconst quoteFromTickers$ = defer(() => getFuturesTickers('usdt', {})).pipe(\n mergeMap((tickers) => tickers),\n map(\n (ticker): Partial<IQuote> => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', ticker.contract),\n last_price: ticker.last,\n ask_price: ticker.lowest_ask,\n bid_price: ticker.highest_bid,\n // GATE API doesn't provide bid/ask volumes in tickers endpoint\n // We'll need to use order book for that if required\n ask_volume: '0',\n bid_volume: '0',\n // total_size is the open interest\n open_interest: ticker.total_size,\n // funding_rate is the current funding rate\n interest_rate_long: ticker.funding_rate ? `${-parseFloat(ticker.funding_rate)}` : undefined,\n interest_rate_short: ticker.funding_rate,\n }),\n ),\n repeat({ delay: 5000 }),\n retry({ delay: 1000 }),\n);\n\n// 从现货tickers获取价格和交易量数据\nconst quoteFromSpotTickers$ = defer(() => getSpotTickers({})).pipe(\n mergeMap((tickers) => tickers),\n map(\n (ticker): Partial<IQuote> => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', ticker.currency_pair),\n last_price: ticker.last,\n ask_price: ticker.lowest_ask,\n bid_price: ticker.highest_bid,\n ask_volume: ticker.lowest_size ?? '0',\n bid_volume: ticker.highest_size ?? '0',\n // 现货没有持仓量的概念,设置为0\n open_interest: '0',\n }),\n ),\n repeat({ delay: 5000 }),\n retry({ delay: 1000 }),\n);\n\nconst quoteSources$ = [quoteFromTickers$, quoteFromSpotTickers$];\n\nconst quote$ = defer(() =>\n merge(\n ...quoteSources$.map((x$) =>\n defer(() => x$).pipe(\n // 防止单个流关闭导致整体关闭\n catchError(() => EMPTY),\n ),\n ),\n ),\n).pipe(\n groupBy((x) => encodePath(x.datasource_id, x.product_id)),\n mergeMap((group$) => {\n return group$.pipe(\n //\n scan((acc, cur) => Object.assign(acc, cur), {} as Partial<IQuote>),\n );\n }),\n share(),\n);\n\n// 写入数据库\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n terminal.channel.publishChannel('quote', { pattern: `^GATE/` }, (channel_id) => {\n const [datasource_id, product_id] = decodePath(channel_id);\n if (!datasource_id) {\n throw 'datasource_id is required';\n }\n if (!product_id) {\n throw 'product_id is required';\n }\n return quote$.pipe(filter((x) => x.product_id === product_id));\n });\n quote$\n .pipe(\n setMetricsQuoteState(terminal.terminal_id),\n writeToSQL({\n terminal,\n writeInterval: 1000,\n tableName: 'quote',\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n}\n"]}
1
+ {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,UAAU,EACV,KAAK,EACL,KAAK,EACL,MAAM,EACN,OAAO,EACP,GAAG,EACH,KAAK,EACL,QAAQ,EACR,MAAM,EACN,KAAK,EACL,IAAI,EACJ,KAAK,EACL,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE9F,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,eAAe;AACf,MAAM,oBAAoB,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC5E,MAAM,CAAC,EAAE,KAAK,EAAE,OAAQ,EAAE,CAAC,EAC3B,KAAK,CAAC,EAAE,KAAK,EAAE,KAAM,EAAE,CAAC,EACxB,WAAW,CAAC,CAAC,CAAC,CACf,CAAC;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AC7C,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,UAAU,EAAE,EAAE;QAC7E,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,aAAa,EAAE;YAClB,MAAM,2BAA2B,CAAC;SACnC;QACD,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,wBAAwB,CAAC;SAChC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,MAAM;SACH,IAAI,CACH,oBAAoB,CAAC,QAAQ,CAAC,WAAW,CAAC,EAC1C,UAAU,CAAC;QACT,QAAQ;QACR,aAAa,EAAE,IAAI;QACnB,SAAS,EAAE,OAAO;QAClB,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC;KAC9C,CAAC,CACH;SACA,SAAS,EAAE,CAAC;CAChB","sourcesContent":["import { IQuote, setMetricsQuoteState } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath } from '@yuants/utils';\nimport {\n catchError,\n defer,\n EMPTY,\n filter,\n groupBy,\n map,\n merge,\n mergeMap,\n repeat,\n retry,\n scan,\n share,\n shareReplay,\n} from 'rxjs';\nimport { getFuturesContracts, getFuturesTickers, getSpotTickers } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\n// 获取所有USDT永续合约\nconst usdtFutureContracts$ = defer(() => getFuturesContracts('usdt', {})).pipe(\n repeat({ delay: 3600_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\n// 从tickers获取价格和交易量数据\nconst quoteFromTickers$ = defer(() => getFuturesTickers('usdt', {})).pipe(\n mergeMap((tickers) => tickers),\n map(\n (ticker): Partial<IQuote> => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', ticker.contract),\n last_price: ticker.last,\n ask_price: ticker.lowest_ask,\n bid_price: ticker.highest_bid,\n // GATE API doesn't provide bid/ask volumes in tickers endpoint\n // We'll need to use order book for that if required\n ask_volume: '0',\n bid_volume: '0',\n // total_size is the open interest\n open_interest: ticker.total_size,\n // funding_rate is the current funding rate\n interest_rate_long: ticker.funding_rate ? `${-parseFloat(ticker.funding_rate)}` : undefined,\n interest_rate_short: ticker.funding_rate,\n }),\n ),\n repeat({ delay: 5000 }),\n retry({ delay: 1000 }),\n);\n\n// 从现货tickers获取价格和交易量数据\nconst quoteFromSpotTickers$ = defer(() => getSpotTickers({})).pipe(\n mergeMap((tickers) => tickers),\n map(\n (ticker): Partial<IQuote> => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', ticker.currency_pair),\n last_price: ticker.last,\n ask_price: ticker.lowest_ask,\n bid_price: ticker.highest_bid,\n ask_volume: ticker.lowest_size ?? '0',\n bid_volume: ticker.highest_size ?? '0',\n // 现货没有持仓量的概念,设置为0\n open_interest: '0',\n }),\n ),\n repeat({ delay: 5000 }),\n retry({ delay: 1000 }),\n);\n\nconst quoteSources$ = [quoteFromTickers$, quoteFromSpotTickers$];\n\nconst quote$ = defer(() =>\n merge(\n ...quoteSources$.map((x$) =>\n defer(() => x$).pipe(\n // 防止单个流关闭导致整体关闭\n catchError(() => EMPTY),\n ),\n ),\n ),\n).pipe(\n groupBy((x) => encodePath(x.datasource_id, x.product_id)),\n mergeMap((group$) => {\n return group$.pipe(\n //\n scan((acc, cur) => Object.assign(acc, cur), {} as Partial<IQuote>),\n );\n }),\n share(),\n);\n\n// 写入数据库\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n terminal.channel.publishChannel('quote', { pattern: `^GATE/` }, (channel_id) => {\n const [datasource_id, product_id] = decodePath(channel_id);\n if (!datasource_id) {\n throw 'datasource_id is required';\n }\n if (!product_id) {\n throw 'product_id is required';\n }\n return quote$.pipe(filter((x) => x.product_id === product_id));\n });\n quote$\n .pipe(\n setMetricsQuoteState(terminal.terminal_id),\n writeToSQL({\n terminal,\n writeInterval: 1000,\n tableName: 'quote',\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n}\n"]}
@@ -0,0 +1,51 @@
1
+ import { provideQuoteService } from '@yuants/exchange';
2
+ import { Terminal } from '@yuants/protocol';
3
+ import { encodePath } from '@yuants/utils';
4
+ import { getFuturesTickers, getSpotTickers } from '../api/public-api';
5
+ const terminal = Terminal.fromNodeEnv();
6
+ provideQuoteService(terminal, {
7
+ product_id_prefix: 'GATE/FUTURE/',
8
+ fields: [
9
+ 'last_price',
10
+ 'ask_price',
11
+ 'bid_price',
12
+ 'open_interest',
13
+ 'interest_rate_long',
14
+ 'interest_rate_short',
15
+ ],
16
+ }, async () => {
17
+ const res = await getFuturesTickers('usdt', {});
18
+ return res.map((ticker) => ({
19
+ product_id: encodePath('GATE', 'FUTURE', ticker.contract),
20
+ updated_at: Date.now(),
21
+ last_price: ticker.last,
22
+ ask_price: ticker.lowest_ask,
23
+ bid_price: ticker.highest_bid,
24
+ // total_size is the open interest
25
+ open_interest: ticker.total_size,
26
+ // funding_rate is the current funding rate
27
+ interest_rate_long: `${-Number(ticker.funding_rate)}`,
28
+ interest_rate_short: ticker.funding_rate,
29
+ }));
30
+ });
31
+ provideQuoteService(terminal, {
32
+ product_id_prefix: 'GATE/SPOT/',
33
+ fields: ['last_price', 'ask_price', 'ask_volume', 'bid_price', 'bid_volume', 'open_interest'],
34
+ }, async () => {
35
+ const res = await getSpotTickers({});
36
+ return res.map((ticker) => {
37
+ var _a, _b;
38
+ return ({
39
+ product_id: encodePath('GATE', 'SPOT', ticker.currency_pair),
40
+ updated_at: Date.now(),
41
+ last_price: ticker.last,
42
+ ask_price: ticker.lowest_ask,
43
+ bid_price: ticker.highest_bid,
44
+ ask_volume: (_a = ticker.lowest_size) !== null && _a !== void 0 ? _a : '0',
45
+ bid_volume: (_b = ticker.highest_size) !== null && _b !== void 0 ? _b : '0',
46
+ // 现货没有持仓量的概念,设置为0
47
+ open_interest: '0',
48
+ });
49
+ });
50
+ });
51
+ //# sourceMappingURL=quotes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quotes.js","sourceRoot":"","sources":["../../src/services/quotes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEtE,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,mBAAmB,CACjB,QAAQ,EACR;IACE,iBAAiB,EAAE,cAAc;IACjC,MAAM,EAAE;QACN,YAAY;QACZ,WAAW;QACX,WAAW;QACX,eAAe;QACf,oBAAoB;QACpB,qBAAqB;KACtB;CACF,EACD,KAAK,IAAI,EAAE;IACT,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC1B,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;QACzD,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;QACtB,UAAU,EAAE,MAAM,CAAC,IAAI;QACvB,SAAS,EAAE,MAAM,CAAC,UAAU;QAC5B,SAAS,EAAE,MAAM,CAAC,WAAW;QAC7B,kCAAkC;QAClC,aAAa,EAAE,MAAM,CAAC,UAAU;QAChC,2CAA2C;QAC3C,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE;QACrD,mBAAmB,EAAE,MAAM,CAAC,YAAY;KACzC,CAAC,CAAC,CAAC;AACN,CAAC,CACF,CAAC;AAEF,mBAAmB,CACjB,QAAQ,EACR;IACE,iBAAiB,EAAE,YAAY;IAC/B,MAAM,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,CAAC;CAC9F,EACD,KAAK,IAAI,EAAE;IACT,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;IACrC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;;QAAC,OAAA,CAAC;YAC1B,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,aAAa,CAAC;YAC5D,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;YACtB,UAAU,EAAE,MAAM,CAAC,IAAI;YACvB,SAAS,EAAE,MAAM,CAAC,UAAU;YAC5B,SAAS,EAAE,MAAM,CAAC,WAAW;YAC7B,UAAU,EAAE,MAAA,MAAM,CAAC,WAAW,mCAAI,GAAG;YACrC,UAAU,EAAE,MAAA,MAAM,CAAC,YAAY,mCAAI,GAAG;YACtC,kBAAkB;YAClB,aAAa,EAAE,GAAG;SACnB,CAAC,CAAA;KAAA,CAAC,CAAC;AACN,CAAC,CACF,CAAC","sourcesContent":["import { provideQuoteService } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturesTickers, getSpotTickers } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideQuoteService(\n terminal,\n {\n product_id_prefix: 'GATE/FUTURE/',\n fields: [\n 'last_price',\n 'ask_price',\n 'bid_price',\n 'open_interest',\n 'interest_rate_long',\n 'interest_rate_short',\n ],\n },\n async () => {\n const res = await getFuturesTickers('usdt', {});\n return res.map((ticker) => ({\n product_id: encodePath('GATE', 'FUTURE', ticker.contract),\n updated_at: Date.now(), // ISSUE: API 未返回服务器时间\n last_price: ticker.last,\n ask_price: ticker.lowest_ask,\n bid_price: ticker.highest_bid,\n // total_size is the open interest\n open_interest: ticker.total_size,\n // funding_rate is the current funding rate\n interest_rate_long: `${-Number(ticker.funding_rate)}`,\n interest_rate_short: ticker.funding_rate,\n }));\n },\n);\n\nprovideQuoteService(\n terminal,\n {\n product_id_prefix: 'GATE/SPOT/',\n fields: ['last_price', 'ask_price', 'ask_volume', 'bid_price', 'bid_volume', 'open_interest'],\n },\n async () => {\n const res = await getSpotTickers({});\n return res.map((ticker) => ({\n product_id: encodePath('GATE', 'SPOT', ticker.currency_pair),\n updated_at: Date.now(),\n last_price: ticker.last,\n ask_price: ticker.lowest_ask,\n bid_price: ticker.highest_bid,\n ask_volume: ticker.lowest_size ?? '0',\n bid_volume: ticker.highest_size ?? '0',\n // 现货没有持仓量的概念,设置为0\n open_interest: '0',\n }));\n },\n);\n"]}
@@ -1,107 +1,133 @@
1
- import { Terminal } from '@yuants/protocol';
2
- import { addAccountTransferAddress } from '@yuants/transfer';
3
- import { formatTime } from '@yuants/utils';
4
- import { getDepositAddress, getDepositHistory, getSubAccountList, getWithdrawalHistory, postWalletTransfer, postWithdrawals, } from '../api/private-api';
5
- import { resolveAccountProfile } from './accounts/profile';
6
- import { getDefaultCredential } from './default-credential';
7
- const credential = getDefaultCredential();
8
- const registerInternalTransfer = (terminal, credential, accountId, direction, network_id) => {
9
- const params = direction === 'spot_to_future'
10
- ? {
11
- account_id: accountId,
12
- from: 'spot',
13
- to: 'futures',
14
- address: 'SPOT',
15
- }
16
- : {
17
- account_id: accountId,
18
- from: 'futures',
19
- to: 'spot',
20
- address: 'USDT_FUTURE',
21
- };
22
- addAccountTransferAddress({
23
- terminal,
24
- account_id: params.account_id,
25
- network_id,
26
- currency: 'USDT',
27
- address: params.address,
28
- onApply: {
29
- INIT: async (order) => {
30
- const transferResult = await postWalletTransfer(credential, {
31
- currency: 'USDT',
32
- from: params.from,
33
- to: params.to,
34
- amount: `${order.current_amount}`,
35
- settle: 'usdt',
36
- });
37
- if (transferResult.tx_id !== undefined) {
38
- return { state: 'COMPLETE', transaction_id: transferResult.tx_id };
39
- }
40
- return { state: 'INIT', message: JSON.stringify(transferResult) };
41
- },
42
- },
43
- onEval: async (transferOrder) => ({
44
- state: 'COMPLETE',
45
- received_amount: transferOrder.current_amount,
46
- }),
47
- });
48
- };
49
- if (credential) {
50
- (async () => {
51
- const terminal = Terminal.fromNodeEnv();
52
- const accountIds = await resolveAccountProfile(credential);
53
- const ACCOUNT_INTERNAL_NETWORK_ID = `Gate/${accountIds.uid}/ACCOUNT_INTERNAL`;
54
- registerInternalTransfer(terminal, credential, accountIds.future, 'future_to_spot', ACCOUNT_INTERNAL_NETWORK_ID);
55
- const subAccountsResult = await getSubAccountList(credential, { type: '0' });
56
- const isMainAccount = Array.isArray(subAccountsResult);
57
- if (isMainAccount) {
58
- const depositAddressRes = await getDepositAddress(credential, { currency: 'USDT' });
59
- console.info(formatTime(Date.now()), 'DepositAddress', JSON.stringify(depositAddressRes));
60
- const addresses = depositAddressRes.multichain_addresses.filter((item) => item.chain === 'TRX');
61
- for (const address of addresses) {
62
- addAccountTransferAddress({
63
- terminal,
64
- account_id: accountIds.spot,
65
- network_id: 'TRC20',
66
- currency: 'USDT',
67
- address: address.address,
68
- onApply: {
69
- INIT: async (transferOrder) => {
70
- const transferResult = await postWithdrawals(credential, {
71
- amount: `${transferOrder.current_amount}`,
72
- currency: 'USDT',
73
- address: transferOrder.current_rx_address,
74
- chain: 'TRX',
75
- });
76
- const { txid, withdraw_order_id } = transferResult;
77
- if (txid && txid.length > 0) {
78
- return { state: 'COMPLETE', transaction_id: txid };
79
- }
80
- return { state: 'PENDING', context: withdraw_order_id };
81
- },
82
- PENDING: async (transferOrder) => {
83
- const wdId = transferOrder.current_tx_context;
84
- const withdrawalRecordsResult = await getWithdrawalHistory(credential, {});
85
- const withdrawalRecord = withdrawalRecordsResult.find((item) => item.withdraw_order_id === wdId);
86
- if (withdrawalRecord && withdrawalRecord.txid && withdrawalRecord.txid.length > 0) {
87
- return { state: 'COMPLETE', transaction_id: withdrawalRecord.txid };
88
- }
89
- return { state: 'PENDING', context: wdId };
90
- },
91
- },
92
- onEval: async (transferOrder) => {
93
- const checkResult = await getDepositHistory(credential, { currency: 'USDT' });
94
- const depositRecord = checkResult.find((item) => item.txid === transferOrder.current_transaction_id);
95
- if (depositRecord && depositRecord.status === 'DONE') {
96
- return { state: 'COMPLETE', received_amount: Number(depositRecord.amount) };
97
- }
98
- return { state: 'PENDING' };
99
- },
100
- });
101
- }
102
- }
103
- })().catch((error) => {
104
- console.error(formatTime(Date.now()), 'GateTransferInitFailed', error);
105
- });
106
- }
1
+ "use strict";
2
+ // import { Terminal } from '@yuants/protocol';
3
+ // import { addAccountTransferAddress } from '@yuants/transfer';
4
+ // import { formatTime } from '@yuants/utils';
5
+ // import {
6
+ // getDepositAddress,
7
+ // getDepositHistory,
8
+ // getSubAccountList,
9
+ // getWithdrawalHistory,
10
+ // ICredential,
11
+ // postWalletTransfer,
12
+ // postWithdrawals,
13
+ // } from '../api/private-api';
14
+ // import { resolveAccountProfile } from './accounts/profile';
15
+ // import { getDefaultCredential } from './default-credential';
16
+ // const credential = getDefaultCredential();
17
+ // const registerInternalTransfer = (
18
+ // terminal: Terminal,
19
+ // credential: ICredential,
20
+ // accountId: string,
21
+ // direction: 'spot_to_future' | 'future_to_spot',
22
+ // network_id: string,
23
+ // ) => {
24
+ // const params =
25
+ // direction === 'spot_to_future'
26
+ // ? {
27
+ // account_id: accountId,
28
+ // from: 'spot',
29
+ // to: 'futures',
30
+ // address: 'SPOT',
31
+ // }
32
+ // : {
33
+ // account_id: accountId,
34
+ // from: 'futures',
35
+ // to: 'spot',
36
+ // address: 'USDT_FUTURE',
37
+ // };
38
+ // addAccountTransferAddress({
39
+ // terminal,
40
+ // account_id: params.account_id,
41
+ // network_id,
42
+ // currency: 'USDT',
43
+ // address: params.address,
44
+ // onApply: {
45
+ // INIT: async (order) => {
46
+ // const transferResult = await postWalletTransfer(credential, {
47
+ // currency: 'USDT',
48
+ // from: params.from,
49
+ // to: params.to,
50
+ // amount: `${order.current_amount}`,
51
+ // settle: 'usdt',
52
+ // });
53
+ // if (transferResult.tx_id !== undefined) {
54
+ // return { state: 'COMPLETE', transaction_id: transferResult.tx_id };
55
+ // }
56
+ // return { state: 'INIT', message: JSON.stringify(transferResult) };
57
+ // },
58
+ // },
59
+ // onEval: async (transferOrder) => ({
60
+ // state: 'COMPLETE',
61
+ // received_amount: transferOrder.current_amount,
62
+ // }),
63
+ // });
64
+ // };
65
+ // if (credential) {
66
+ // (async () => {
67
+ // const terminal = Terminal.fromNodeEnv();
68
+ // const accountIds = await resolveAccountProfile(credential);
69
+ // const ACCOUNT_INTERNAL_NETWORK_ID = `Gate/${accountIds.uid}/ACCOUNT_INTERNAL`;
70
+ // registerInternalTransfer(
71
+ // terminal,
72
+ // credential,
73
+ // accountIds.future,
74
+ // 'future_to_spot',
75
+ // ACCOUNT_INTERNAL_NETWORK_ID,
76
+ // );
77
+ // const subAccountsResult = await getSubAccountList(credential, { type: '0' });
78
+ // const isMainAccount = Array.isArray(subAccountsResult);
79
+ // if (isMainAccount) {
80
+ // const depositAddressRes = await getDepositAddress(credential, { currency: 'USDT' });
81
+ // console.info(formatTime(Date.now()), 'DepositAddress', JSON.stringify(depositAddressRes));
82
+ // const addresses = depositAddressRes.multichain_addresses.filter((item) => item.chain === 'TRX');
83
+ // for (const address of addresses) {
84
+ // addAccountTransferAddress({
85
+ // terminal,
86
+ // account_id: accountIds.spot,
87
+ // network_id: 'TRC20',
88
+ // currency: 'USDT',
89
+ // address: address.address,
90
+ // onApply: {
91
+ // INIT: async (transferOrder) => {
92
+ // const transferResult = await postWithdrawals(credential, {
93
+ // amount: `${transferOrder.current_amount}`,
94
+ // currency: 'USDT',
95
+ // address: transferOrder.current_rx_address!,
96
+ // chain: 'TRX',
97
+ // });
98
+ // const { txid, withdraw_order_id } = transferResult;
99
+ // if (txid && txid.length > 0) {
100
+ // return { state: 'COMPLETE', transaction_id: txid };
101
+ // }
102
+ // return { state: 'PENDING', context: withdraw_order_id };
103
+ // },
104
+ // PENDING: async (transferOrder) => {
105
+ // const wdId = transferOrder.current_tx_context;
106
+ // const withdrawalRecordsResult = await getWithdrawalHistory(credential, {});
107
+ // const withdrawalRecord = withdrawalRecordsResult.find(
108
+ // (item) => item.withdraw_order_id === wdId,
109
+ // );
110
+ // if (withdrawalRecord && withdrawalRecord.txid && withdrawalRecord.txid.length > 0) {
111
+ // return { state: 'COMPLETE', transaction_id: withdrawalRecord.txid };
112
+ // }
113
+ // return { state: 'PENDING', context: wdId };
114
+ // },
115
+ // },
116
+ // onEval: async (transferOrder) => {
117
+ // const checkResult = await getDepositHistory(credential, { currency: 'USDT' });
118
+ // const depositRecord = checkResult.find(
119
+ // (item) => item.txid === transferOrder.current_transaction_id,
120
+ // );
121
+ // if (depositRecord && depositRecord.status === 'DONE') {
122
+ // return { state: 'COMPLETE', received_amount: Number(depositRecord.amount) };
123
+ // }
124
+ // return { state: 'PENDING' };
125
+ // },
126
+ // });
127
+ // }
128
+ // }
129
+ // })().catch((error) => {
130
+ // console.error(formatTime(Date.now()), 'GateTransferInitFailed', error);
131
+ // });
132
+ // }
107
133
  //# sourceMappingURL=transfer.js.map