@yuants/vendor-gate 0.4.27 → 0.5.0

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 +2 -2
  39. package/temp/package-deps.json +11 -10
@@ -1 +1 @@
1
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,CAAC,IAAI,CACnD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,KAAK,IAAI,CAC1C,CAAC;4BACF,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,IAAI,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;gCACjF,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC;6BACrE;4BACD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wBAC7C,CAAC;qBACF;oBACD,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE;wBAC9B,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;wBAC9E,MAAM,aAAa,GAAG,WAAW,CAAC,IAAI,CACpC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,sBAAsB,CAC7D,CAAC;wBACF,IAAI,aAAa,IAAI,aAAa,CAAC,MAAM,KAAK,MAAM,EAAE;4BACpD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;yBAC7E;wBACD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;oBAC9B,CAAC;iBACF,CAAC,CAAC;aACJ;SACF;IACH,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,wBAAwB,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;CACJ","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { addAccountTransferAddress } from '@yuants/transfer';\nimport { formatTime } from '@yuants/utils';\nimport {\n getDepositAddress,\n getDepositHistory,\n getSubAccountList,\n getWithdrawalHistory,\n ICredential,\n postWalletTransfer,\n postWithdrawals,\n} from '../api/private-api';\nimport { resolveAccountProfile } from './accounts/profile';\nimport { getDefaultCredential } from './default-credential';\n\nconst credential = getDefaultCredential();\n\nconst registerInternalTransfer = (\n terminal: Terminal,\n credential: ICredential,\n accountId: string,\n direction: 'spot_to_future' | 'future_to_spot',\n network_id: string,\n) => {\n const params =\n direction === 'spot_to_future'\n ? {\n account_id: accountId,\n from: 'spot',\n to: 'futures',\n address: 'SPOT',\n }\n : {\n account_id: accountId,\n from: 'futures',\n to: 'spot',\n address: 'USDT_FUTURE',\n };\n\n addAccountTransferAddress({\n terminal,\n account_id: params.account_id,\n network_id,\n currency: 'USDT',\n address: params.address,\n onApply: {\n INIT: async (order) => {\n const transferResult = await postWalletTransfer(credential, {\n currency: 'USDT',\n from: params.from,\n to: params.to,\n amount: `${order.current_amount}`,\n settle: 'usdt',\n });\n if (transferResult.tx_id !== undefined) {\n return { state: 'COMPLETE', transaction_id: transferResult.tx_id };\n }\n return { state: 'INIT', message: JSON.stringify(transferResult) };\n },\n },\n onEval: async (transferOrder) => ({\n state: 'COMPLETE',\n received_amount: transferOrder.current_amount,\n }),\n });\n};\n\nif (credential) {\n (async () => {\n const terminal = Terminal.fromNodeEnv();\n const accountIds = await resolveAccountProfile(credential);\n const ACCOUNT_INTERNAL_NETWORK_ID = `Gate/${accountIds.uid}/ACCOUNT_INTERNAL`;\n\n registerInternalTransfer(\n terminal,\n credential,\n accountIds.future,\n 'future_to_spot',\n ACCOUNT_INTERNAL_NETWORK_ID,\n );\n\n const subAccountsResult = await getSubAccountList(credential, { type: '0' });\n const isMainAccount = Array.isArray(subAccountsResult);\n if (isMainAccount) {\n const depositAddressRes = await getDepositAddress(credential, { currency: 'USDT' });\n console.info(formatTime(Date.now()), 'DepositAddress', JSON.stringify(depositAddressRes));\n const addresses = depositAddressRes.multichain_addresses.filter((item) => item.chain === 'TRX');\n for (const address of addresses) {\n addAccountTransferAddress({\n terminal,\n account_id: accountIds.spot,\n network_id: 'TRC20',\n currency: 'USDT',\n address: address.address,\n onApply: {\n INIT: async (transferOrder) => {\n const transferResult = await postWithdrawals(credential, {\n amount: `${transferOrder.current_amount}`,\n currency: 'USDT',\n address: transferOrder.current_rx_address!,\n chain: 'TRX',\n });\n const { txid, withdraw_order_id } = transferResult;\n if (txid && txid.length > 0) {\n return { state: 'COMPLETE', transaction_id: txid };\n }\n return { state: 'PENDING', context: withdraw_order_id };\n },\n PENDING: async (transferOrder) => {\n const wdId = transferOrder.current_tx_context;\n const withdrawalRecordsResult = await getWithdrawalHistory(credential, {});\n const withdrawalRecord = withdrawalRecordsResult.find(\n (item) => item.withdraw_order_id === wdId,\n );\n if (withdrawalRecord && withdrawalRecord.txid && withdrawalRecord.txid.length > 0) {\n return { state: 'COMPLETE', transaction_id: withdrawalRecord.txid };\n }\n return { state: 'PENDING', context: wdId };\n },\n },\n onEval: async (transferOrder) => {\n const checkResult = await getDepositHistory(credential, { currency: 'USDT' });\n const depositRecord = checkResult.find(\n (item) => item.txid === transferOrder.current_transaction_id,\n );\n if (depositRecord && depositRecord.status === 'DONE') {\n return { state: 'COMPLETE', received_amount: Number(depositRecord.amount) };\n }\n return { state: 'PENDING' };\n },\n });\n }\n }\n })().catch((error) => {\n console.error(formatTime(Date.now()), 'GateTransferInitFailed', error);\n });\n}\n"]}
1
+ {"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../src/services/transfer.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,gEAAgE;AAChE,8CAA8C;AAC9C,WAAW;AACX,uBAAuB;AACvB,uBAAuB;AACvB,uBAAuB;AACvB,0BAA0B;AAC1B,iBAAiB;AACjB,wBAAwB;AACxB,qBAAqB;AACrB,+BAA+B;AAC/B,8DAA8D;AAC9D,+DAA+D;AAE/D,6CAA6C;AAE7C,qCAAqC;AACrC,wBAAwB;AACxB,6BAA6B;AAC7B,uB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,4FAA4F;AAC5F,uEAAuE;AACvE,6DAA6D;AAC7D,mBAAmB;AACnB,qGAAqG;AACrG,uFAAuF;AACvF,kBAAkB;AAClB,4DAA4D;AAC5D,iBAAiB;AACjB,eAAe;AACf,+CAA+C;AAC/C,6FAA6F;AAC7F,sDAAsD;AACtD,8EAA8E;AAC9E,iBAAiB;AACjB,sEAAsE;AACtE,6FAA6F;AAC7F,gBAAgB;AAChB,2CAA2C;AAC3C,eAAe;AACf,cAAc;AACd,UAAU;AACV,QAAQ;AACR,4BAA4B;AAC5B,8EAA8E;AAC9E,QAAQ;AACR,IAAI","sourcesContent":["// import { Terminal } from '@yuants/protocol';\n// import { addAccountTransferAddress } from '@yuants/transfer';\n// import { formatTime } from '@yuants/utils';\n// import {\n// getDepositAddress,\n// getDepositHistory,\n// getSubAccountList,\n// getWithdrawalHistory,\n// ICredential,\n// postWalletTransfer,\n// postWithdrawals,\n// } from '../api/private-api';\n// import { resolveAccountProfile } from './accounts/profile';\n// import { getDefaultCredential } from './default-credential';\n\n// const credential = getDefaultCredential();\n\n// const registerInternalTransfer = (\n// terminal: Terminal,\n// credential: ICredential,\n// accountId: string,\n// direction: 'spot_to_future' | 'future_to_spot',\n// network_id: string,\n// ) => {\n// const params =\n// direction === 'spot_to_future'\n// ? {\n// account_id: accountId,\n// from: 'spot',\n// to: 'futures',\n// address: 'SPOT',\n// }\n// : {\n// account_id: accountId,\n// from: 'futures',\n// to: 'spot',\n// address: 'USDT_FUTURE',\n// };\n\n// addAccountTransferAddress({\n// terminal,\n// account_id: params.account_id,\n// network_id,\n// currency: 'USDT',\n// address: params.address,\n// onApply: {\n// INIT: async (order) => {\n// const transferResult = await postWalletTransfer(credential, {\n// currency: 'USDT',\n// from: params.from,\n// to: params.to,\n// amount: `${order.current_amount}`,\n// settle: 'usdt',\n// });\n// if (transferResult.tx_id !== undefined) {\n// return { state: 'COMPLETE', transaction_id: transferResult.tx_id };\n// }\n// return { state: 'INIT', message: JSON.stringify(transferResult) };\n// },\n// },\n// onEval: async (transferOrder) => ({\n// state: 'COMPLETE',\n// received_amount: transferOrder.current_amount,\n// }),\n// });\n// };\n\n// if (credential) {\n// (async () => {\n// const terminal = Terminal.fromNodeEnv();\n// const accountIds = await resolveAccountProfile(credential);\n// const ACCOUNT_INTERNAL_NETWORK_ID = `Gate/${accountIds.uid}/ACCOUNT_INTERNAL`;\n\n// registerInternalTransfer(\n// terminal,\n// credential,\n// accountIds.future,\n// 'future_to_spot',\n// ACCOUNT_INTERNAL_NETWORK_ID,\n// );\n\n// const subAccountsResult = await getSubAccountList(credential, { type: '0' });\n// const isMainAccount = Array.isArray(subAccountsResult);\n// if (isMainAccount) {\n// const depositAddressRes = await getDepositAddress(credential, { currency: 'USDT' });\n// console.info(formatTime(Date.now()), 'DepositAddress', JSON.stringify(depositAddressRes));\n// const addresses = depositAddressRes.multichain_addresses.filter((item) => item.chain === 'TRX');\n// for (const address of addresses) {\n// addAccountTransferAddress({\n// terminal,\n// account_id: accountIds.spot,\n// network_id: 'TRC20',\n// currency: 'USDT',\n// address: address.address,\n// onApply: {\n// INIT: async (transferOrder) => {\n// const transferResult = await postWithdrawals(credential, {\n// amount: `${transferOrder.current_amount}`,\n// currency: 'USDT',\n// address: transferOrder.current_rx_address!,\n// chain: 'TRX',\n// });\n// const { txid, withdraw_order_id } = transferResult;\n// if (txid && txid.length > 0) {\n// return { state: 'COMPLETE', transaction_id: txid };\n// }\n// return { state: 'PENDING', context: withdraw_order_id };\n// },\n// PENDING: async (transferOrder) => {\n// const wdId = transferOrder.current_tx_context;\n// const withdrawalRecordsResult = await getWithdrawalHistory(credential, {});\n// const withdrawalRecord = withdrawalRecordsResult.find(\n// (item) => item.withdraw_order_id === wdId,\n// );\n// if (withdrawalRecord && withdrawalRecord.txid && withdrawalRecord.txid.length > 0) {\n// return { state: 'COMPLETE', transaction_id: withdrawalRecord.txid };\n// }\n// return { state: 'PENDING', context: wdId };\n// },\n// },\n// onEval: async (transferOrder) => {\n// const checkResult = await getDepositHistory(credential, { currency: 'USDT' });\n// const depositRecord = checkResult.find(\n// (item) => item.txid === transferOrder.current_transaction_id,\n// );\n// if (depositRecord && depositRecord.status === 'DONE') {\n// return { state: 'COMPLETE', received_amount: Number(depositRecord.amount) };\n// }\n// return { state: 'PENDING' };\n// },\n// });\n// }\n// }\n// })().catch((error) => {\n// console.error(formatTime(Date.now()), 'GateTransferInitFailed', error);\n// });\n// }\n"]}
package/lib/index.d.ts 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.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","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"}
1
+ {"version":3,"file":"index.d.ts","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"}
package/lib/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- require("./services/markets/product");
4
- require("./services/markets/interest-rate");
5
- require("./services/transfer");
6
3
  require("./services/exchange");
4
+ require("./services/markets/interest-rate");
5
+ require("./services/markets/product");
7
6
  require("./services/markets/quote");
7
+ require("./services/quotes");
8
+ require("./services/transfer");
8
9
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,sCAAoC;AACpC,4CAA0C;AAC1C,+BAA6B;AAC7B,+BAA6B;AAC7B,oCAAkC","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,+BAA6B;AAC7B,4CAA0C;AAC1C,sCAAoC;AACpC,oCAAkC;AAClC,6BAA2B;AAC3B,+BAA6B","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,11 +1,3 @@
1
1
  import { ICredential } from '../../api/private-api';
2
- export interface IAccountProfile {
3
- uid: string;
4
- future: string;
5
- spot: string;
6
- unified: string;
7
- }
8
- export declare const resolveAccountProfile: (credential: ICredential) => Promise<IAccountProfile>;
9
- export declare const getAccountIds: (credential: ICredential) => Promise<IAccountProfile>;
10
2
  export declare const getCredentialId: (credential: ICredential) => Promise<string>;
11
3
  //# sourceMappingURL=profile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGtE,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAsBD,eAAO,MAAM,qBAAqB,eAAsB,WAAW,KAAG,QAAQ,eAAe,CAM5F,CAAC;AAEF,eAAO,MAAM,aAAa,eAR8B,WAAW,KAAG,QAAQ,eAAe,CAQ3C,CAAC;AAEnD,eAAO,MAAM,eAAe,eAAsB,WAAW,KAAG,QAAQ,MAAM,CAG7E,CAAC"}
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEtE,eAAO,MAAM,eAAe,eAAsB,WAAW,KAAG,QAAQ,MAAM,CAI7E,CAAC"}
@@ -1,35 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCredentialId = exports.getAccountIds = exports.resolveAccountProfile = void 0;
4
- const cache_1 = require("@yuants/cache");
5
- const private_api_1 = require("../../api/private-api");
3
+ exports.getCredentialId = void 0;
6
4
  const utils_1 = require("@yuants/utils");
7
- const PROFILE_TTL = 60000;
8
- const serializeCredential = (credential) => JSON.stringify(credential);
9
- const deserializeCredential = (key) => JSON.parse(key);
10
- const accountProfileCache = (0, cache_1.createCache)(async (key) => {
11
- const credential = deserializeCredential(key);
12
- const detail = await (0, private_api_1.getAccountDetail)(credential);
13
- const uid = `${detail.user_id}`;
14
- return {
15
- uid,
16
- future: `gate/${uid}/future/USDT`,
17
- spot: `gate/${uid}/spot/USDT`,
18
- unified: `gate/${uid}/unified/USDT`,
19
- };
20
- }, { expire: PROFILE_TTL });
21
- const resolveAccountProfile = async (credential) => {
22
- const profile = await accountProfileCache.query(serializeCredential(credential));
23
- if (!profile) {
24
- throw new Error('Unable to resolve Gate account profile');
25
- }
26
- return profile;
27
- };
28
- exports.resolveAccountProfile = resolveAccountProfile;
29
- exports.getAccountIds = exports.resolveAccountProfile;
5
+ const private_api_1 = require("../../api/private-api");
30
6
  const getCredentialId = async (credential) => {
31
- const spotAccountInfo = await (0, exports.resolveAccountProfile)(credential);
32
- return (0, utils_1.encodePath)('GATE', spotAccountInfo.uid);
7
+ const res = await (0, private_api_1.getAccountDetail)(credential);
8
+ if (!res.user_id)
9
+ throw (0, utils_1.newError)('GATE_GET_UID_FAILED', { res });
10
+ return (0, utils_1.encodePath)('GATE', res.user_id);
33
11
  };
34
12
  exports.getCredentialId = getCredentialId;
35
13
  //# sourceMappingURL=profile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,uDAAsE;AACtE,yCAA2C;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,IAAA,mBAAW,EACrC,KAAK,EAAE,GAAW,EAAE,EAAE;IACpB,MAAM,UAAU,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,IAAA,8BAAgB,EAAC,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;AAEK,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;AANW,QAAA,qBAAqB,yBAMhC;AAEW,QAAA,aAAa,GAAG,6BAAqB,CAAC;AAE5C,MAAM,eAAe,GAAG,KAAK,EAAE,UAAuB,EAAmB,EAAE;IAChF,MAAM,eAAe,GAAG,MAAM,IAAA,6BAAqB,EAAC,UAAU,CAAC,CAAC;IAChE,OAAO,IAAA,kBAAU,EAAC,MAAM,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC;AACjD,CAAC,CAAC;AAHW,QAAA,eAAe,mBAG1B","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,yCAAqD;AACrD,uDAAsE;AAE/D,MAAM,eAAe,GAAG,KAAK,EAAE,UAAuB,EAAmB,EAAE;IAChF,MAAM,GAAG,GAAG,MAAM,IAAA,8BAAgB,EAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,CAAC,GAAG,CAAC,OAAO;QAAE,MAAM,IAAA,gBAAQ,EAAC,qBAAqB,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACjE,OAAO,IAAA,kBAAU,EAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B","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,4 +1,4 @@
1
- import type { IPosition } from '@yuants/data-account';
1
+ import { type IPosition } from '@yuants/data-account';
2
2
  import { ICredential } from '../../api/private-api';
3
3
  export declare const getUnifiedAccountInfo: (credential: ICredential) => Promise<IPosition[]>;
4
4
  //# sourceMappingURL=unified.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAuD5F,eAAO,MAAM,qBAAqB,eAAsB,WAAW,yBA2ClE,CAAC"}
1
+ {"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAExE,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAuC5F,eAAO,MAAM,qBAAqB,eAAsB,WAAW,yBAsClE,CAAC"}
@@ -1,22 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getUnifiedAccountInfo = void 0;
4
- const cache_1 = require("@yuants/cache");
4
+ const data_account_1 = require("@yuants/data-account");
5
5
  const utils_1 = require("@yuants/utils");
6
6
  const private_api_1 = require("../../api/private-api");
7
7
  const public_api_1 = require("../../api/public-api");
8
- const product_1 = require("../markets/product");
9
- const spotProductMapCache = (0, cache_1.createCache)(async () => {
10
- const products = await (0, product_1.listProducts)();
11
- const map = new Map();
12
- for (const product of products !== null && products !== void 0 ? products : []) {
13
- const [, instType] = product.product_id.split('/');
14
- if (instType === 'SPOT') {
15
- map.set(product.base_currency, product.product_id);
16
- }
17
- }
18
- return map;
19
- }, { expire: 86400000 });
20
8
  const loadFuturePositions = async (credential) => {
21
9
  const positions = [];
22
10
  const positionsRes = await (0, private_api_1.getFuturePositions)(credential, 'usdt');
@@ -51,18 +39,16 @@ const loadFuturePositions = async (credential) => {
51
39
  };
52
40
  const getUnifiedAccountInfo = async (credential) => {
53
41
  var _a;
54
- const [futurePositions, unifiedAccount, spotTickers, spotProductMap] = await Promise.all([
42
+ const [futurePositions, unifiedAccount, spotTickers] = await Promise.all([
55
43
  loadFuturePositions(credential),
56
44
  (0, private_api_1.getUnifiedAccounts)(credential, {}),
57
45
  (0, public_api_1.getSpotTickers)({}),
58
- spotProductMapCache.query('').catch(() => undefined),
59
46
  ]);
60
- const resolvedSpotProductMap = spotProductMap !== null && spotProductMap !== void 0 ? spotProductMap : new Map();
61
47
  const balances = (_a = unifiedAccount === null || unifiedAccount === void 0 ? void 0 : unifiedAccount.balances) !== null && _a !== void 0 ? _a : {};
62
48
  const spotTickerList = Array.isArray(spotTickers) ? spotTickers : [];
63
49
  const spotPositions = Object.keys(balances)
64
50
  .map((currency) => {
65
- var _a, _b, _c, _d;
51
+ var _a, _b, _c;
66
52
  let currency_pair = `${currency}_USDT`;
67
53
  if (currency === 'SOL2') {
68
54
  currency_pair = 'SOL_USDT';
@@ -73,22 +59,19 @@ const getUnifiedAccountInfo = async (credential) => {
73
59
  const closable_price = currency === 'USDT'
74
60
  ? 1
75
61
  : Number(((_a = spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)) === null || _a === void 0 ? void 0 : _a.last) || 0);
76
- const volume = Number(((_b = balances[currency]) === null || _b === void 0 ? void 0 : _b.cross_balance) || 0);
62
+ // TODO: 根据账户模式调整 volume 计算方式
63
+ const volume = Number(((_b = balances[currency]) === null || _b === void 0 ? void 0 : _b.available) || 0);
77
64
  const free_volume = Number(((_c = balances[currency]) === null || _c === void 0 ? void 0 : _c.available) || 0);
78
65
  if (Math.abs(volume) === 0)
79
66
  return undefined;
80
- return {
67
+ return (0, data_account_1.makeSpotPosition)({
81
68
  datasource_id: 'GATE',
82
69
  position_id: currency,
83
- product_id: (_d = resolvedSpotProductMap.get(currency)) !== null && _d !== void 0 ? _d : (0, utils_1.encodePath)('GATE', 'SPOT', currency),
84
- direction: 'LONG',
70
+ product_id: (0, utils_1.encodePath)('GATE', 'SPOT', currency + '_USDT'),
85
71
  volume,
86
72
  free_volume,
87
73
  closable_price,
88
- position_price: closable_price,
89
- floating_profit: closable_price * volume,
90
- valuation: closable_price * volume,
91
- };
74
+ });
92
75
  })
93
76
  .filter((item) => !!item);
94
77
  return [...futurePositions, ...spotPositions];
@@ -1 +1 @@
1
- {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,yCAA2C;AAC3C,uDAA4F;AAC5F,qDAAsD;AACtD,gDAAkD;AAElD,MAAM,mBAAmB,GAAG,IAAA,mBAAW,EACrC,KAAK,IAAI,EAAE;IACT,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAY,GAAE,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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CAAC;IAE/C,OAAO,CAAC,GAAG,eAAe,EAAE,GAAG,aAAa,CAAC,CAAC;AAChD,CAAC,CAAC;AA3CW,QAAA,qBAAqB,yBA2ChC","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,uDAAwE;AACxE,yCAA2C;AAC3C,uDAA4F;AAC5F,qDAAsD;AAEtD,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IAClF,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,MAAM,YAAY,GAAG,MAAM,IAAA,gCAAkB,EAAC,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,IAAA,kBAAU,EAAC,MA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MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC;YAC1D,MAAM;YACN,WAAW;YACX,cAAc;SACf,CAAC,CAAC;IACL,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;AAtCW,QAAA,qBAAqB,yBAsChC","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,4 +1,3 @@
1
- export declare const productCache: import("@yuants/cache").ICache<import("@yuants/data-product").IProduct>;
2
1
  export declare const listProducts: () => Promise<{
3
2
  datasource_id: string;
4
3
  product_id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,yEAAmD,CAAC;AAE7E,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;IAkDxB,CAAC"}
1
+ {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;IAkDxB,CAAC"}
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listProducts = exports.productCache = void 0;
4
- const data_product_1 = require("@yuants/data-product");
5
- const protocol_1 = require("@yuants/protocol");
3
+ exports.listProducts = void 0;
6
4
  const utils_1 = require("@yuants/utils");
7
5
  const public_api_1 = require("../../api/public-api");
8
- exports.productCache = (0, data_product_1.createClientProductCache)(protocol_1.Terminal.fromNodeEnv());
9
6
  const listProducts = async () => {
10
7
  const [futureProducts, spotProducts] = await Promise.all([
11
8
  (0, public_api_1.getFuturesContracts)('usdt', {}),
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":";;;AAAA,uDAAgE;AAChE,+CAA4C;AAC5C,yCAA2C;AAC3C,qDAAiF;AAEpE,QAAA,YAAY,GAAG,IAAA,uCAAwB,EAAC,mBAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AAEtE,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;IACrC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACvD,IAAA,gCAAmB,EAAC,MAAM,EAAE,EAAE,CAAC;QAC/B,IAAA,iCAAoB,GAAE;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,IAAA,kBAAU,EAAC,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,IAAA,kBAAU,EAAC,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;AAlDW,QAAA,YAAY,gBAkDvB","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,yCAA2C;AAC3C,qDAAiF;AAE1E,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;IACrC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACvD,IAAA,gCAAmB,EAAC,MAAM,EAAE,EAAE,CAAC;QAC/B,IAAA,iCAAoB,GAAE;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,IAAA,kBAA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3B,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 { 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,mDAAkE;AAClE,+CAAsE;AACtE,qCAAyC;AACzC,yCAAuD;AACvD,+BAcc;AACd,qDAA8F;AAE9F,MAAM,QAAQ,GAAG,mBAAQ,CA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sQuoteState } 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,mDAAkE;AAClE,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAcc;AACd,qDAA8F;AAE9F,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,eAAe;AACf,MAAM,oBAAoB,GAAG,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,gCAAmB,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC5E,IAAA,aAAM,EAAC,EAAE,KAAK,EAAE,OAAQ,EAAE,CAAC,EAC3B,IAAA,YAAK,EAAC,EAAE,KAAK,EAAE,KAAM,EAAE,CAAC,EACxB,IAA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GAAG,EAAE,GAAG,CAAC,EAAE,EAAqB,CAAC,CACnE,CAAC;AACJ,CAAC,CAAC,EACF,IAAA,YAAK,GAAE,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,IAAA,kBAAU,EAAC,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,IAAA,aAAM,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,MAAM;SACH,IAAI,CACH,IAAA,iCAAoB,EAAC,QAAQ,CAAC,WAAW,CAAC,EAC1C,IAAA,gBAAU,EAAC;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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=quotes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quotes.d.ts","sourceRoot":"","sources":["../../src/services/quotes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const exchange_1 = require("@yuants/exchange");
4
+ const protocol_1 = require("@yuants/protocol");
5
+ const utils_1 = require("@yuants/utils");
6
+ const public_api_1 = require("../api/public-api");
7
+ const terminal = protocol_1.Terminal.fromNodeEnv();
8
+ (0, exchange_1.provideQuoteService)(terminal, {
9
+ product_id_prefix: 'GATE/FUTURE/',
10
+ fields: [
11
+ 'last_price',
12
+ 'ask_price',
13
+ 'bid_price',
14
+ 'open_interest',
15
+ 'interest_rate_long',
16
+ 'interest_rate_short',
17
+ ],
18
+ }, async () => {
19
+ const res = await (0, public_api_1.getFuturesTickers)('usdt', {});
20
+ return res.map((ticker) => ({
21
+ product_id: (0, utils_1.encodePath)('GATE', 'FUTURE', ticker.contract),
22
+ updated_at: Date.now(),
23
+ last_price: ticker.last,
24
+ ask_price: ticker.lowest_ask,
25
+ bid_price: ticker.highest_bid,
26
+ // total_size is the open interest
27
+ open_interest: ticker.total_size,
28
+ // funding_rate is the current funding rate
29
+ interest_rate_long: `${-Number(ticker.funding_rate)}`,
30
+ interest_rate_short: ticker.funding_rate,
31
+ }));
32
+ });
33
+ (0, exchange_1.provideQuoteService)(terminal, {
34
+ product_id_prefix: 'GATE/SPOT/',
35
+ fields: ['last_price', 'ask_price', 'ask_volume', 'bid_price', 'bid_volume', 'open_interest'],
36
+ }, async () => {
37
+ const res = await (0, public_api_1.getSpotTickers)({});
38
+ return res.map((ticker) => {
39
+ var _a, _b;
40
+ return ({
41
+ product_id: (0, utils_1.encodePath)('GATE', 'SPOT', ticker.currency_pair),
42
+ updated_at: Date.now(),
43
+ last_price: ticker.last,
44
+ ask_price: ticker.lowest_ask,
45
+ bid_price: ticker.highest_bid,
46
+ ask_volume: (_a = ticker.lowest_size) !== null && _a !== void 0 ? _a : '0',
47
+ bid_volume: (_b = ticker.highest_size) !== null && _b !== void 0 ? _b : '0',
48
+ // 现货没有持仓量的概念,设置为0
49
+ open_interest: '0',
50
+ });
51
+ });
52
+ });
53
+ //# sourceMappingURL=quotes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quotes.js","sourceRoot":"","sources":["../../src/services/quotes.ts"],"names":[],"mappings":";;AAAA,+CAAuD;AACvD,+CAA4C;AAC5C,yCAA2C;AAC3C,kDAAsE;AAEtE,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,8BAAmB,EACjB,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,IAAA,8BAAiB,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC1B,UAAU,EAAE,IAAA,kBAA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{ 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,2 +1 @@
1
- export {};
2
1
  //# sourceMappingURL=transfer.d.ts.map