@yuants/vendor-gate 0.4.1 → 0.4.2

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 (120) hide show
  1. package/dist/api/http-client.js +89 -0
  2. package/dist/api/http-client.js.map +1 -0
  3. package/dist/api/private-api.js +108 -0
  4. package/dist/api/private-api.js.map +1 -0
  5. package/dist/api/public-api.js +37 -0
  6. package/dist/api/public-api.js.map +1 -0
  7. package/dist/api/rate-limiter.js +60 -0
  8. package/dist/api/rate-limiter.js.map +1 -0
  9. package/dist/index.js +7 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/services/account-actions-with-credential.js +37 -0
  12. package/dist/services/account-actions-with-credential.js.map +1 -0
  13. package/dist/services/accounts/future.js +56 -0
  14. package/dist/services/accounts/future.js.map +1 -0
  15. package/dist/services/accounts/profile.js +25 -0
  16. package/dist/services/accounts/profile.js.map +1 -0
  17. package/dist/services/accounts/spot.js +19 -0
  18. package/dist/services/accounts/spot.js.map +1 -0
  19. package/dist/services/accounts/unified.js +50 -0
  20. package/dist/services/accounts/unified.js.map +1 -0
  21. package/dist/services/default-credential.js +15 -0
  22. package/dist/services/default-credential.js.map +1 -0
  23. package/dist/services/legacy.js +53 -0
  24. package/dist/services/legacy.js.map +1 -0
  25. package/dist/services/markets/interest-rate.js +30 -0
  26. package/dist/services/markets/interest-rate.js.map +1 -0
  27. package/dist/services/markets/product.js +38 -0
  28. package/dist/services/markets/product.js.map +1 -0
  29. package/dist/services/order-actions-with-credential.js +18 -0
  30. package/dist/services/order-actions-with-credential.js.map +1 -0
  31. package/dist/services/orders/cancelOrder.js +8 -0
  32. package/dist/services/orders/cancelOrder.js.map +1 -0
  33. package/dist/services/orders/listOrders.js +31 -0
  34. package/dist/services/orders/listOrders.js.map +1 -0
  35. package/dist/services/orders/submitOrder.js +50 -0
  36. package/dist/services/orders/submitOrder.js.map +1 -0
  37. package/dist/services/transfer.js +107 -0
  38. package/dist/services/transfer.js.map +1 -0
  39. package/dist/vendor-gate.d.ts +1 -0
  40. package/lib/api/http-client.d.ts +9 -0
  41. package/lib/api/http-client.d.ts.map +1 -0
  42. package/lib/api/http-client.js +97 -0
  43. package/lib/api/http-client.js.map +1 -0
  44. package/lib/api/private-api.d.ts +343 -0
  45. package/lib/api/private-api.d.ts.map +1 -0
  46. package/lib/api/private-api.js +126 -0
  47. package/lib/api/private-api.js.map +1 -0
  48. package/lib/api/public-api.d.ts +149 -0
  49. package/lib/api/public-api.d.ts.map +1 -0
  50. package/lib/api/public-api.js +45 -0
  51. package/lib/api/public-api.js.map +1 -0
  52. package/lib/api/rate-limiter.d.ts +8 -0
  53. package/lib/api/rate-limiter.d.ts.map +1 -0
  54. package/lib/api/rate-limiter.js +64 -0
  55. package/lib/api/rate-limiter.js.map +1 -0
  56. package/lib/index.d.ts +7 -0
  57. package/lib/index.d.ts.map +1 -0
  58. package/lib/index.js +9 -0
  59. package/lib/index.js.map +1 -0
  60. package/lib/services/account-actions-with-credential.d.ts +2 -0
  61. package/lib/services/account-actions-with-credential.d.ts.map +1 -0
  62. package/lib/services/account-actions-with-credential.js +39 -0
  63. package/lib/services/account-actions-with-credential.js.map +1 -0
  64. package/lib/services/accounts/future.d.ts +13 -0
  65. package/lib/services/accounts/future.d.ts.map +1 -0
  66. package/lib/services/accounts/future.js +61 -0
  67. package/lib/services/accounts/future.js.map +1 -0
  68. package/lib/services/accounts/profile.d.ts +10 -0
  69. package/lib/services/accounts/profile.d.ts.map +1 -0
  70. package/lib/services/accounts/profile.js +29 -0
  71. package/lib/services/accounts/profile.js.map +1 -0
  72. package/lib/services/accounts/spot.d.ts +11 -0
  73. package/lib/services/accounts/spot.d.ts.map +1 -0
  74. package/lib/services/accounts/spot.js +23 -0
  75. package/lib/services/accounts/spot.js.map +1 -0
  76. package/lib/services/accounts/unified.d.ts +12 -0
  77. package/lib/services/accounts/unified.d.ts.map +1 -0
  78. package/lib/services/accounts/unified.js +54 -0
  79. package/lib/services/accounts/unified.js.map +1 -0
  80. package/lib/services/default-credential.d.ts +3 -0
  81. package/lib/services/default-credential.d.ts.map +1 -0
  82. package/lib/services/default-credential.js +19 -0
  83. package/lib/services/default-credential.js.map +1 -0
  84. package/lib/services/legacy.d.ts +2 -0
  85. package/lib/services/legacy.d.ts.map +1 -0
  86. package/lib/services/legacy.js +55 -0
  87. package/lib/services/legacy.js.map +1 -0
  88. package/lib/services/markets/interest-rate.d.ts +2 -0
  89. package/lib/services/markets/interest-rate.d.ts.map +1 -0
  90. package/lib/services/markets/interest-rate.js +32 -0
  91. package/lib/services/markets/interest-rate.js.map +1 -0
  92. package/lib/services/markets/product.d.ts +3 -0
  93. package/lib/services/markets/product.d.ts.map +1 -0
  94. package/lib/services/markets/product.js +41 -0
  95. package/lib/services/markets/product.js.map +1 -0
  96. package/lib/services/order-actions-with-credential.d.ts +2 -0
  97. package/lib/services/order-actions-with-credential.d.ts.map +1 -0
  98. package/lib/services/order-actions-with-credential.js +20 -0
  99. package/lib/services/order-actions-with-credential.js.map +1 -0
  100. package/lib/services/orders/cancelOrder.d.ts +4 -0
  101. package/lib/services/orders/cancelOrder.d.ts.map +1 -0
  102. package/lib/services/orders/cancelOrder.js +12 -0
  103. package/lib/services/orders/cancelOrder.js.map +1 -0
  104. package/lib/services/orders/listOrders.d.ts +4 -0
  105. package/lib/services/orders/listOrders.d.ts.map +1 -0
  106. package/lib/services/orders/listOrders.js +35 -0
  107. package/lib/services/orders/listOrders.js.map +1 -0
  108. package/lib/services/orders/submitOrder.d.ts +4 -0
  109. package/lib/services/orders/submitOrder.d.ts.map +1 -0
  110. package/lib/services/orders/submitOrder.js +54 -0
  111. package/lib/services/orders/submitOrder.js.map +1 -0
  112. package/lib/services/transfer.d.ts +2 -0
  113. package/lib/services/transfer.d.ts.map +1 -0
  114. package/lib/services/transfer.js +109 -0
  115. package/lib/services/transfer.js.map +1 -0
  116. package/lib/tsdoc-metadata.json +11 -0
  117. package/package.json +5 -9
  118. package/temp/package-deps.json +46 -0
  119. package/temp/vendor-gate.api.json +177 -0
  120. package/temp/vendor-gate.api.md +9 -0
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSpotTickers = exports.getFuturesTickers = exports.getFuturesOrderBook = exports.getFutureFundingRate = exports.getFuturesContracts = void 0;
4
+ const rate_limiter_1 = require("./rate-limiter");
5
+ const http_client_1 = require("./http-client");
6
+ /**
7
+ * 查询所有的合约信息
8
+ *
9
+ * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%89%80%E6%9C%89%E7%9A%84%E5%90%88%E7%BA%A6%E4%BF%A1%E6%81%AF
10
+ */
11
+ const getFuturesContracts = (settle, params) => (0, http_client_1.requestPublic)('GET', `/api/v4/futures/${settle}/contracts`, params);
12
+ exports.getFuturesContracts = getFuturesContracts;
13
+ /**
14
+ * 合约市场历史资金费率
15
+ *
16
+ * - Note: 该接口返回的数据是按照时间倒序排列的
17
+ * - Note: limit 参数最大值为 1000
18
+ * - Note: t 字段为秒级时间戳 (Unix Second),r 字段为资金费率 (0-1 单位)
19
+ *
20
+ * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA%E5%8E%86%E5%8F%B2%E8%B5%84%E9%87%91%E8%B4%B9%E7%8E%87
21
+ */
22
+ const getFutureFundingRate = (settle, params) => (0, http_client_1.requestPublic)('GET', `/api/v4/futures/${settle}/funding_rate`, params);
23
+ exports.getFutureFundingRate = getFutureFundingRate;
24
+ /**
25
+ * 查询合约市场深度信息
26
+ *
27
+ * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA%E6%B7%B1%E5%BA%A6%E4%BF%A1%E6%81%AF
28
+ */
29
+ const getFuturesOrderBook = async (settle, params) => rate_limiter_1.rateLimiter.schedule(`futures-order-book:${settle}`, 200, 10000, () => (0, http_client_1.requestPublic)('GET', `/api/v4/futures/${settle}/order_book`, params));
30
+ exports.getFuturesOrderBook = getFuturesOrderBook;
31
+ /**
32
+ * 获取所有合约交易行情统计
33
+ *
34
+ * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E6%89%80%E6%9C%89%E5%90%88%E7%BA%A6%E4%BA%A4%E6%98%93%E8%A1%8C%E6%83%85%E7%BB%9F%E8%AE%A1
35
+ */
36
+ const getFuturesTickers = (settle, params) => (0, http_client_1.requestPublic)('GET', `/api/v4/futures/${settle}/tickers`, params);
37
+ exports.getFuturesTickers = getFuturesTickers;
38
+ /**
39
+ * 获取交易对 ticker 信息
40
+ *
41
+ * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%8D%95%E4%B8%AA%E4%BA%A4%E6%98%93%E5%AF%B9%E8%AF%A6%E6%83%85
42
+ */
43
+ const getSpotTickers = (params) => (0, http_client_1.requestPublic)('GET', `/api/v4/spot/tickers`, params);
44
+ exports.getSpotTickers = getSpotTickers;
45
+ //# sourceMappingURL=public-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAC7C,+CAA8C;AAE9C;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CACjC,MAAc,EACd,MAA4C,EA8C5C,EAAE,CAAC,IAAA,2BAAa,EAAC,KAAK,EAAE,mBAAmB,MAAM,YAAY,EAAE,MAAM,CAAC,CAAC;AAhD5D,QAAA,mBAAmB,uBAgDyC;AAEzE;;;;;;;;GAQG;AACI,MAAM,oBAAoB,GAAG,CAClC,MAAc,EACd,MAA4C,EAM5C,EAAE,CAAC,IAAA,2BAAa,EAAC,KAAK,EAAE,mBAAmB,MAAM,eAAe,EAAE,MAAM,CAAC,CAAC;AAR/D,QAAA,oBAAoB,wBAQ2C;AAE5E;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAAc,EACd,MAKC,EAaA,EAAE,CACH,0BAAW,CAAC,QAAQ,CAAC,sBAAsB,MAAM,EAAE,EAAE,GAAG,EAAE,KAAM,EAAE,GAAG,EAAE,CACrE,IAAA,2BAAa,EAAC,KAAK,EAAE,mBAAmB,MAAM,aAAa,EAAE,MAAM,CAAC,CACrE,CAAC;AAvBS,QAAA,mBAAmB,uBAuB5B;AAEJ;;;;GAIG;AACI,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,MAA8B,EAyB9B,EAAE,CAAC,IAAA,2BAAa,EAAC,KAAK,EAAE,mBAAmB,MAAM,UAAU,EAAE,MAAM,CAAC,CAAC;AA3B1D,QAAA,iBAAiB,qBA2ByC;AAEvE;;;;GAIG;AACI,MAAM,cAAc,GAAG,CAAC,MAG9B,EAoBC,EAAE,CAAC,IAAA,2BAAa,EAAC,KAAK,EAAE,sBAAsB,EAAE,MAAM,CAAC,CAAC;AAvB7C,QAAA,cAAc,kBAuB+B","sourcesContent":["import { rateLimiter } from './rate-limiter';\nimport { requestPublic } from './http-client';\n\n/**\n * 查询所有的合约信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%89%80%E6%9C%89%E7%9A%84%E5%90%88%E7%BA%A6%E4%BF%A1%E6%81%AF\n */\nexport const getFuturesContracts = (\n settle: string,\n params?: { limit?: number; offset?: number },\n): Promise<\n {\n name: string;\n type: string;\n quanto_multiplier: string;\n ref_discount_rate: string;\n order_price_deviate: string;\n maintenance_rate: string;\n mark_type: string;\n last_price: string;\n mark_price: string;\n index_price: string;\n funding_rate_indicative: string;\n mark_price_round: string;\n funding_offset: number;\n in_delisting: boolean;\n risk_limit_base: string;\n interest_rate: string;\n order_price_round: string;\n order_size_min: number;\n ref_rebate_rate: string;\n funding_interval: number;\n risk_limit_step: string;\n leverage_min: string;\n leverage_max: string;\n risk_limit_max: string;\n maker_fee_rate: string;\n taker_fee_rate: string;\n funding_rate: string;\n order_size_max: number;\n funding_next_apply: number;\n short_users: number;\n config_change_time: number;\n trade_size: number;\n position_size: number;\n long_users: number;\n funding_impact_value: string;\n orders_limit: number;\n trade_id: number;\n orderbook_id: number;\n enable_bonus: boolean;\n enable_credit: boolean;\n create_time: number;\n funding_cap_ratio: string;\n }[]\n> => requestPublic('GET', `/api/v4/futures/${settle}/contracts`, params);\n\n/**\n * 合约市场历史资金费率\n *\n * - Note: 该接口返回的数据是按照时间倒序排列的\n * - Note: limit 参数最大值为 1000\n * - Note: t 字段为秒级时间戳 (Unix Second),r 字段为资金费率 (0-1 单位)\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA%E5%8E%86%E5%8F%B2%E8%B5%84%E9%87%91%E8%B4%B9%E7%8E%87\n */\nexport const getFutureFundingRate = (\n settle: string,\n params: { contract: string; limit?: number },\n): Promise<\n {\n t: number;\n r: string;\n }[]\n> => requestPublic('GET', `/api/v4/futures/${settle}/funding_rate`, params);\n\n/**\n * 查询合约市场深度信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA%E6%B7%B1%E5%BA%A6%E4%BF%A1%E6%81%AF\n */\nexport const getFuturesOrderBook = async (\n settle: string,\n params: {\n contract: string;\n interval?: string;\n limit?: number;\n with_id?: boolean;\n },\n): Promise<{\n id: number;\n current: number;\n update: number;\n asks: {\n p: string;\n s: string;\n }[];\n bids: {\n p: string;\n s: string;\n }[];\n}> =>\n rateLimiter.schedule(`futures-order-book:${settle}`, 200, 10_000, () =>\n requestPublic('GET', `/api/v4/futures/${settle}/order_book`, params),\n );\n\n/**\n * 获取所有合约交易行情统计\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E6%89%80%E6%9C%89%E5%90%88%E7%BA%A6%E4%BA%A4%E6%98%93%E8%A1%8C%E6%83%85%E7%BB%9F%E8%AE%A1\n */\nexport const getFuturesTickers = (\n settle: string,\n params?: { contract?: string },\n): Promise<\n {\n contract: string;\n last: string;\n change_percentage: string;\n total_size: string;\n low_24h: string;\n high_24h: string;\n volume_24h: string;\n volume_24h_btc: string;\n volume_24h_usd: string;\n volume_24h_base: string;\n volume_24h_quote: string;\n volume_24h_settle: string;\n mark_price: string;\n funding_rate: string;\n funding_rate_indicative: string;\n index_price: string;\n quanto_base_rate: string;\n basis_rate: string;\n basis_value: string;\n lowest_ask: string;\n highest_bid: string;\n }[]\n> => requestPublic('GET', `/api/v4/futures/${settle}/tickers`, params);\n\n/**\n * 获取交易对 ticker 信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%8D%95%E4%B8%AA%E4%BA%A4%E6%98%93%E5%AF%B9%E8%AF%A6%E6%83%85\n */\nexport const getSpotTickers = (params: {\n currency_pair?: string;\n timezone?: string;\n}): Promise<\n Array<{\n currency_pair: string;\n last: string;\n lowest_ask: string;\n lowest_size: string;\n highest_bid: string;\n highest_size: string;\n change_percentage: string;\n change_utc0: string;\n change_utc8: string;\n base_volume: string;\n quote_volume: string;\n high_24h: string;\n low_24h: string;\n etf_net_value: string;\n etf_pre_net_value: string;\n etf_pre_timestamp: string;\n etf_leverage: string;\n }>\n> => requestPublic('GET', `/api/v4/spot/tickers`, params);\n"]}
@@ -0,0 +1,8 @@
1
+ export declare class RateLimiter {
2
+ private channels;
3
+ schedule<T>(key: string, limit: number, periodMs: number, execute: () => Promise<T>): Promise<T>;
4
+ private ensureChannel;
5
+ private disposeChannel;
6
+ }
7
+ export declare const rateLimiter: RateLimiter;
8
+ //# sourceMappingURL=rate-limiter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limiter.d.ts","sourceRoot":"","sources":["../../src/api/rate-limiter.ts"],"names":[],"mappings":"AAiBA,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAwC;IAExD,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAehG,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,cAAc;CAQvB;AAED,eAAO,MAAM,WAAW,aAAoB,CAAC"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rateLimiter = exports.RateLimiter = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ class RateLimiter {
6
+ constructor() {
7
+ this.channels = new Map();
8
+ }
9
+ schedule(key, limit, periodMs, execute) {
10
+ if (!Number.isFinite(limit) || limit <= 0) {
11
+ return execute();
12
+ }
13
+ const channel = this.ensureChannel(key, limit, periodMs);
14
+ return new Promise((resolve, reject) => {
15
+ channel.queue.push({
16
+ execute,
17
+ resolve: (value) => resolve(value),
18
+ reject,
19
+ });
20
+ });
21
+ }
22
+ ensureChannel(key, limit, periodMs) {
23
+ if (this.channels.has(key)) {
24
+ return this.channels.get(key);
25
+ }
26
+ const subject = new rxjs_1.Subject();
27
+ const channel = {
28
+ queue: [],
29
+ limit,
30
+ subject,
31
+ queueSubscription: subject.subscribe((task) => {
32
+ channel.activeCount++;
33
+ task
34
+ .execute()
35
+ .then((value) => task.resolve(value))
36
+ .catch((error) => task.reject(error))
37
+ .finally(() => {
38
+ channel.activeCount--;
39
+ if (channel.queue.length === 0 && channel.activeCount === 0) {
40
+ this.disposeChannel(key);
41
+ }
42
+ });
43
+ }),
44
+ timerSubscription: (0, rxjs_1.timer)(0, periodMs)
45
+ .pipe((0, rxjs_1.filter)(() => channel.queue.length > 0), (0, rxjs_1.mergeMap)(() => channel.queue.splice(0, channel.limit)))
46
+ .subscribe(subject),
47
+ activeCount: 0,
48
+ };
49
+ this.channels.set(key, channel);
50
+ return channel;
51
+ }
52
+ disposeChannel(key) {
53
+ const channel = this.channels.get(key);
54
+ if (!channel)
55
+ return;
56
+ channel.queueSubscription.unsubscribe();
57
+ channel.timerSubscription.unsubscribe();
58
+ channel.subject.complete();
59
+ this.channels.delete(key);
60
+ }
61
+ }
62
+ exports.RateLimiter = RateLimiter;
63
+ exports.rateLimiter = new RateLimiter();
64
+ //# sourceMappingURL=rate-limiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/api/rate-limiter.ts"],"names":[],"mappings":"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","sourcesContent":["import { Subject, Subscription, filter, mergeMap, timer } from 'rxjs';\n\ntype QueueTask = {\n execute: () => Promise<unknown>;\n resolve: (value: unknown) => void;\n reject: (error: unknown) => void;\n};\n\ninterface IRateLimitChannel {\n queue: QueueTask[];\n limit: number;\n subject: Subject<QueueTask>;\n queueSubscription: Subscription;\n timerSubscription: Subscription;\n activeCount: number;\n}\n\nexport class RateLimiter {\n private channels = new Map<string, IRateLimitChannel>();\n\n schedule<T>(key: string, limit: number, periodMs: number, execute: () => Promise<T>): Promise<T> {\n if (!Number.isFinite(limit) || limit <= 0) {\n return execute();\n }\n const channel = this.ensureChannel(key, limit, periodMs);\n\n return new Promise<T>((resolve, reject) => {\n channel.queue.push({\n execute,\n resolve: (value) => resolve(value as T),\n reject,\n });\n });\n }\n\n private ensureChannel(key: string, limit: number, periodMs: number): IRateLimitChannel {\n if (this.channels.has(key)) {\n return this.channels.get(key)!;\n }\n const subject = new Subject<QueueTask>();\n const channel: IRateLimitChannel = {\n queue: [],\n limit,\n subject,\n queueSubscription: subject.subscribe((task) => {\n channel.activeCount++;\n task\n .execute()\n .then((value) => task.resolve(value))\n .catch((error) => task.reject(error))\n .finally(() => {\n channel.activeCount--;\n if (channel.queue.length === 0 && channel.activeCount === 0) {\n this.disposeChannel(key);\n }\n });\n }),\n timerSubscription: timer(0, periodMs)\n .pipe(\n filter(() => channel.queue.length > 0),\n mergeMap(() => channel.queue.splice(0, channel.limit)),\n )\n .subscribe(subject),\n activeCount: 0,\n };\n\n this.channels.set(key, channel);\n return channel;\n }\n\n private disposeChannel(key: string) {\n const channel = this.channels.get(key);\n if (!channel) return;\n channel.queueSubscription.unsubscribe();\n channel.timerSubscription.unsubscribe();\n channel.subject.complete();\n this.channels.delete(key);\n }\n}\n\nexport const rateLimiter = new RateLimiter();\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import './services/legacy';
2
+ import './services/account-actions-with-credential';
3
+ import './services/order-actions-with-credential';
4
+ import './services/markets/product';
5
+ import './services/markets/interest-rate';
6
+ import './services/transfer';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAC3B,OAAO,4CAA4C,CAAC;AACpD,OAAO,0CAA0C,CAAC;AAClD,OAAO,4BAA4B,CAAC;AACpC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,qBAAqB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./services/legacy");
4
+ require("./services/account-actions-with-credential");
5
+ require("./services/order-actions-with-credential");
6
+ require("./services/markets/product");
7
+ require("./services/markets/interest-rate");
8
+ require("./services/transfer");
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,6BAA2B;AAC3B,sDAAoD;AACpD,oDAAkD;AAClD,sCAAoC;AACpC,4CAA0C;AAC1C,+BAA6B","sourcesContent":["import './services/legacy';\nimport './services/account-actions-with-credential';\nimport './services/order-actions-with-credential';\nimport './services/markets/product';\nimport './services/markets/interest-rate';\nimport './services/transfer';\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=account-actions-with-credential.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-actions-with-credential.d.ts","sourceRoot":"","sources":["../../src/services/account-actions-with-credential.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const data_account_1 = require("@yuants/data-account");
4
+ const protocol_1 = require("@yuants/protocol");
5
+ const future_1 = require("./accounts/future");
6
+ const profile_1 = require("./accounts/profile");
7
+ const spot_1 = require("./accounts/spot");
8
+ const unified_1 = require("./accounts/unified");
9
+ (0, data_account_1.provideAccountActionsWithCredential)(protocol_1.Terminal.fromNodeEnv(), 'GATE', {
10
+ type: 'object',
11
+ required: ['access_key', 'secret_key'],
12
+ properties: {
13
+ access_key: { type: 'string' },
14
+ secret_key: { type: 'string' },
15
+ },
16
+ }, {
17
+ listAccounts: async (credential) => {
18
+ const accountIds = await (0, profile_1.resolveAccountProfile)(credential);
19
+ return [
20
+ { account_id: accountIds.future },
21
+ { account_id: accountIds.unified },
22
+ { account_id: accountIds.spot },
23
+ ];
24
+ },
25
+ getAccountInfo: async (credential, account_id) => {
26
+ const accountIds = await (0, profile_1.resolveAccountProfile)(credential);
27
+ if (account_id === accountIds.future) {
28
+ return (0, future_1.getFutureAccountInfo)(credential, account_id);
29
+ }
30
+ if (account_id === accountIds.unified) {
31
+ return (0, unified_1.getUnifiedAccountInfo)(credential, account_id);
32
+ }
33
+ if (account_id === accountIds.spot) {
34
+ return (0, spot_1.getSpotAccountInfo)(credential, account_id);
35
+ }
36
+ throw new Error(`Unsupported account_id: ${account_id}`);
37
+ },
38
+ });
39
+ //# sourceMappingURL=account-actions-with-credential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-actions-with-credential.js","sourceRoot":"","sources":["../../src/services/account-actions-with-credential.ts"],"names":[],"mappings":";;AAAA,uDAA2E;AAC3E,+CAA4C;AAE5C,8CAAyD;AACzD,gDAA2D;AAC3D,0CAAqD;AACrD,gDAA2D;AAE3D,IAAA,kDAAmC,EACjC,mBAAQ,CAAC,WAAW,EAAE,EACtB,MAAM,EACN;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;IACtC,UAAU,EAAE;QACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC/B;CACF,EACD;IACE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;QACjC,MAAM,UAAU,GAAG,MAAM,IAAA,+BAAqB,EAAC,UAAU,CAAC,CAAC;QAC3D,OAAO;YACL,EAAE,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE;YACjC,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,EAAE;YAClC,EAAE,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE;SAChC,CAAC;IACJ,CAAC;IACD,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;QAC/C,MAAM,UAAU,GAAG,MAAM,IAAA,+BAAqB,EAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,UAAU,KAAK,UAAU,CAAC,MAAM,EAAE;YACpC,OAAO,IAAA,6BAAoB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SACrD;QACD,IAAI,UAAU,KAAK,UAAU,CAAC,OAAO,EAAE;YACrC,OAAO,IAAA,+BAAqB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SACtD;QACD,IAAI,UAAU,KAAK,UAAU,CAAC,IAAI,EAAE;YAClC,OAAO,IAAA,yBAAkB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SACnD;QACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF,CACF,CAAC","sourcesContent":["import { provideAccountActionsWithCredential } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { ICredential } from '../api/private-api';\nimport { getFutureAccountInfo } from './accounts/future';\nimport { resolveAccountProfile } from './accounts/profile';\nimport { getSpotAccountInfo } from './accounts/spot';\nimport { getUnifiedAccountInfo } from './accounts/unified';\n\nprovideAccountActionsWithCredential<ICredential>(\n Terminal.fromNodeEnv(),\n 'GATE',\n {\n type: 'object',\n required: ['access_key', 'secret_key'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n {\n listAccounts: async (credential) => {\n const accountIds = await resolveAccountProfile(credential);\n return [\n { account_id: accountIds.future },\n { account_id: accountIds.unified },\n { account_id: accountIds.spot },\n ];\n },\n getAccountInfo: async (credential, account_id) => {\n const accountIds = await resolveAccountProfile(credential);\n if (account_id === accountIds.future) {\n return getFutureAccountInfo(credential, account_id);\n }\n if (account_id === accountIds.unified) {\n return getUnifiedAccountInfo(credential, account_id);\n }\n if (account_id === accountIds.spot) {\n return getSpotAccountInfo(credential, account_id);\n }\n throw new Error(`Unsupported account_id: ${account_id}`);\n },\n },\n);\n"]}
@@ -0,0 +1,13 @@
1
+ import type { IPosition } from '@yuants/data-account';
2
+ import { ICredential } from '../../api/private-api';
3
+ export declare const loadFuturePositions: (credential: ICredential) => Promise<IPosition[]>;
4
+ export declare const getFutureAccountInfo: (credential: ICredential, account_id: string) => Promise<{
5
+ account_id: string;
6
+ money: {
7
+ currency: string;
8
+ equity: number;
9
+ free: number;
10
+ };
11
+ positions: IPosition[];
12
+ }>;
13
+ //# sourceMappingURL=future.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"future.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG5F,eAAO,MAAM,mBAAmB,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAgCtF,CAAC;AAEF,eAAO,MAAM,oBAAoB,eAAsB,WAAW,cAAc,MAAM;;;;;;;;EAmBrF,CAAC"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFutureAccountInfo = exports.loadFuturePositions = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const private_api_1 = require("../../api/private-api");
6
+ const product_1 = require("../markets/product");
7
+ const loadFuturePositions = async (credential) => {
8
+ const [positionsRes, productMap] = await Promise.all([
9
+ (0, private_api_1.getFuturePositions)(credential, 'usdt'),
10
+ (0, rxjs_1.firstValueFrom)(product_1.mapProductIdToUsdtFutureProduct$),
11
+ ]);
12
+ const positions = Array.isArray(positionsRes) ? positionsRes : [];
13
+ return positions.map((position) => {
14
+ var _a;
15
+ const product_id = position.contract;
16
+ const theProduct = productMap.get(product_id);
17
+ const volume = Math.abs(position.size);
18
+ const closable_price = Number(position.mark_price);
19
+ const valuation = volume * closable_price * ((_a = theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) !== null && _a !== void 0 ? _a : 1);
20
+ return {
21
+ datasource_id: 'GATE-FUTURE',
22
+ position_id: `${position.contract}-${position.leverage}-${position.mode}`,
23
+ product_id,
24
+ direction: position.mode === 'dual_long'
25
+ ? 'LONG'
26
+ : position.mode === 'dual_short'
27
+ ? 'SHORT'
28
+ : position.size > 0
29
+ ? 'LONG'
30
+ : 'SHORT',
31
+ volume,
32
+ free_volume: Math.abs(position.size),
33
+ position_price: Number(position.entry_price),
34
+ closable_price,
35
+ floating_profit: Number(position.unrealised_pnl),
36
+ valuation,
37
+ };
38
+ });
39
+ };
40
+ exports.loadFuturePositions = loadFuturePositions;
41
+ const getFutureAccountInfo = async (credential, account_id) => {
42
+ var _a, _b, _c;
43
+ const [positions, rawAccount] = await Promise.all([
44
+ (0, exports.loadFuturePositions)(credential),
45
+ (0, private_api_1.getFuturesAccounts)(credential, 'usdt'),
46
+ ]);
47
+ const account = (rawAccount === null || rawAccount === void 0 ? void 0 : rawAccount.available) ? rawAccount : { available: '0', total: '0', unrealised_pnl: '0' };
48
+ const free = Number((_a = account.available) !== null && _a !== void 0 ? _a : 0);
49
+ const equity = Number((_b = account.total) !== null && _b !== void 0 ? _b : 0) + Number((_c = account.unrealised_pnl) !== null && _c !== void 0 ? _c : 0);
50
+ return {
51
+ account_id,
52
+ money: {
53
+ currency: 'USDT',
54
+ equity,
55
+ free,
56
+ },
57
+ positions,
58
+ };
59
+ };
60
+ exports.getFutureAccountInfo = getFutureAccountInfo;
61
+ //# sourceMappingURL=future.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":";;;AACA,+BAAsC;AACtC,uDAA4F;AAC5F,gDAAsE;AAE/D,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IACzF,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,IAAA,gCAAkB,EAAC,UAAU,EAAE,MAAM,CAAC;QACtC,IAAA,qBAAc,EAAC,0CAAgC,CAAC;KACjD,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAClE,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAa,EAAE;;QAC3C,MAAM,UAAU,GAAG,QAAQ,CAAC,QAAQ,CAAC;QACrC,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,MAAM,GAAG,cAAc,GAAG,CAAC,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,WAAW,mCAAI,CAAC,CAAC,CAAC;QAC3E,OAAO;YACL,aAAa,EAAE,aAAa;YAC5B,WAAW,EAAE,GAAG,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE;YACzE,UAAU;YACV,SAAS,EACP,QAAQ,CAAC,IAAI,KAAK,WAAW;gBAC3B,CAAC,CAAC,MAAM;gBACR,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;oBAChC,CAAC,CAAC,OAAO;oBACT,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC;wBACnB,CAAC,CAAC,MAAM;wBACR,CAAC,CAAC,OAAO;YACb,MAAM;YACN,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;YACpC,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;YAC5C,cAAc;YACd,eAAe,EAAE,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC;YAChD,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAhCW,QAAA,mBAAmB,uBAgC9B;AAEK,MAAM,oBAAoB,GAAG,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAE,EAAE;;IACxF,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChD,IAAA,2BAAmB,EAAC,UAAU,CAAC;QAC/B,IAAA,gCAAkB,EAAC,UAAU,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC;IACzG,MAAM,IAAI,GAAG,MAAM,CAAC,MAAA,OAAO,CAAC,SAAS,mCAAI,CAAC,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAA,OAAO,CAAC,KAAK,mCAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAA,OAAO,CAAC,cAAc,mCAAI,CAAC,CAAC,CAAC;IAEhF,OAAO;QACL,UAAU;QACV,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS;KACV,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,oBAAoB,wBAmB/B","sourcesContent":["import type { IPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { mapProductIdToUsdtFutureProduct$ } from '../markets/product';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const [positionsRes, productMap] = await Promise.all([\n getFuturePositions(credential, 'usdt'),\n firstValueFrom(mapProductIdToUsdtFutureProduct$),\n ]);\n const positions = Array.isArray(positionsRes) ? positionsRes : [];\n return positions.map((position): IPosition => {\n const product_id = position.contract;\n const theProduct = productMap.get(product_id);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price * (theProduct?.value_scale ?? 1);\n return {\n datasource_id: 'GATE-FUTURE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n valuation,\n };\n });\n};\n\nexport const getFutureAccountInfo = async (credential: ICredential, account_id: string) => {\n const [positions, rawAccount] = await Promise.all([\n loadFuturePositions(credential),\n getFuturesAccounts(credential, 'usdt'),\n ]);\n\n const account = rawAccount?.available ? rawAccount : { available: '0', total: '0', unrealised_pnl: '0' };\n const free = Number(account.available ?? 0);\n const equity = Number(account.total ?? 0) + Number(account.unrealised_pnl ?? 0);\n\n return {\n account_id,\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n};\n"]}
@@ -0,0 +1,10 @@
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
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +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;AAEtE,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"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAccountIds = exports.resolveAccountProfile = void 0;
4
+ const cache_1 = require("@yuants/cache");
5
+ const private_api_1 = require("../../api/private-api");
6
+ const PROFILE_TTL = 60000;
7
+ const serializeCredential = (credential) => JSON.stringify(credential);
8
+ const deserializeCredential = (key) => JSON.parse(key);
9
+ const accountProfileCache = (0, cache_1.createCache)(async (key) => {
10
+ const credential = deserializeCredential(key);
11
+ const detail = await (0, private_api_1.getAccountDetail)(credential);
12
+ const uid = `${detail.user_id}`;
13
+ return {
14
+ uid,
15
+ future: `gate/${uid}/future/USDT`,
16
+ spot: `gate/${uid}/spot/USDT`,
17
+ unified: `gate/${uid}/unified/USDT`,
18
+ };
19
+ }, { expire: PROFILE_TTL });
20
+ const resolveAccountProfile = async (credential) => {
21
+ const profile = await accountProfileCache.query(serializeCredential(credential));
22
+ if (!profile) {
23
+ throw new Error('Unable to resolve Gate account profile');
24
+ }
25
+ return profile;
26
+ };
27
+ exports.resolveAccountProfile = resolveAccountProfile;
28
+ exports.getAccountIds = exports.resolveAccountProfile;
29
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,uDAAsE;AAStE,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","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getAccountDetail, ICredential } from '../../api/private-api';\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"]}
@@ -0,0 +1,11 @@
1
+ import { ICredential } from '../../api/private-api';
2
+ export declare const getSpotAccountInfo: (credential: ICredential, account_id: string) => Promise<{
3
+ account_id: string;
4
+ money: {
5
+ currency: string;
6
+ equity: number;
7
+ free: number;
8
+ };
9
+ positions: never[];
10
+ }>;
11
+ //# sourceMappingURL=spot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAErE,eAAO,MAAM,kBAAkB,eAAsB,WAAW,cAAc,MAAM;;;;;;;;EAenF,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSpotAccountInfo = void 0;
4
+ const private_api_1 = require("../../api/private-api");
5
+ const getSpotAccountInfo = async (credential, account_id) => {
6
+ var _a, _b;
7
+ const res = await (0, private_api_1.getSpotAccounts)(credential);
8
+ if (!Array.isArray(res)) {
9
+ throw new Error('Failed to load spot balances');
10
+ }
11
+ const balance = Number((_b = (_a = res.find((item) => item.currency === 'USDT')) === null || _a === void 0 ? void 0 : _a.available) !== null && _b !== void 0 ? _b : '0');
12
+ return {
13
+ account_id,
14
+ money: {
15
+ currency: 'USDT',
16
+ equity: balance,
17
+ free: balance,
18
+ },
19
+ positions: [],
20
+ };
21
+ };
22
+ exports.getSpotAccountInfo = getSpotAccountInfo;
23
+ //# sourceMappingURL=spot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAqE;AAE9D,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAE,EAAE;;IACtF,MAAM,GAAG,GAAG,MAAM,IAAA,6BAAe,EAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAA,MAAA,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,0CAAE,SAAS,mCAAI,GAAG,CAAC,CAAC;IACvF,OAAO;QACL,UAAU;QACV,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,OAAO;YACf,IAAI,EAAE,OAAO;SACd;QACD,SAAS,EAAE,EAAE;KACd,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,kBAAkB,sBAe7B","sourcesContent":["import { getSpotAccounts, ICredential } from '../../api/private-api';\n\nexport const getSpotAccountInfo = async (credential: ICredential, account_id: string) => {\n const res = await getSpotAccounts(credential);\n if (!Array.isArray(res)) {\n throw new Error('Failed to load spot balances');\n }\n const balance = Number(res.find((item) => item.currency === 'USDT')?.available ?? '0');\n return {\n account_id,\n money: {\n currency: 'USDT',\n equity: balance,\n free: balance,\n },\n positions: [],\n };\n};\n"]}
@@ -0,0 +1,12 @@
1
+ import type { IPosition } from '@yuants/data-account';
2
+ import { ICredential } from '../../api/private-api';
3
+ export declare const getUnifiedAccountInfo: (credential: ICredential, account_id: string) => Promise<{
4
+ account_id: string;
5
+ money: {
6
+ currency: string;
7
+ equity: number;
8
+ free: number;
9
+ };
10
+ positions: IPosition[];
11
+ }>;
12
+ //# sourceMappingURL=unified.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAsB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGxE,eAAO,MAAM,qBAAqB,eAAsB,WAAW,cAAc,MAAM;;;;;;;;EAgDtF,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUnifiedAccountInfo = void 0;
4
+ const public_api_1 = require("../../api/public-api");
5
+ const private_api_1 = require("../../api/private-api");
6
+ const future_1 = require("./future");
7
+ const getUnifiedAccountInfo = async (credential, account_id) => {
8
+ var _a, _b;
9
+ const [futurePositions, unifiedAccount, spotTickers] = await Promise.all([
10
+ (0, future_1.loadFuturePositions)(credential),
11
+ (0, private_api_1.getUnifiedAccounts)(credential, {}),
12
+ (0, public_api_1.getSpotTickers)({}),
13
+ ]);
14
+ const balances = (_a = unifiedAccount === null || unifiedAccount === void 0 ? void 0 : unifiedAccount.balances) !== null && _a !== void 0 ? _a : {};
15
+ const spotTickerList = Array.isArray(spotTickers) ? spotTickers : [];
16
+ const spotPositions = Object.keys(balances)
17
+ .map((currency) => {
18
+ var _a, _b;
19
+ if (currency === 'USDT')
20
+ return undefined;
21
+ let currency_pair = `${currency}_USDT`;
22
+ if (currency === 'SOL2') {
23
+ currency_pair = 'SOL_USDT';
24
+ }
25
+ const closable_price = Number(((_a = spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)) === null || _a === void 0 ? void 0 : _a.last) || 0);
26
+ const volume = Number(((_b = balances[currency]) === null || _b === void 0 ? void 0 : _b.available) || 0);
27
+ return {
28
+ datasource_id: 'gate/spot',
29
+ position_id: currency,
30
+ product_id: currency,
31
+ direction: 'LONG',
32
+ volume,
33
+ free_volume: volume,
34
+ closable_price,
35
+ position_price: closable_price,
36
+ floating_profit: 0,
37
+ valuation: closable_price * volume,
38
+ };
39
+ })
40
+ .filter((item) => !!item);
41
+ const free = Number(((_b = balances['USDT']) === null || _b === void 0 ? void 0 : _b.available) || 0);
42
+ const equity = Number((unifiedAccount === null || unifiedAccount === void 0 ? void 0 : unifiedAccount.unified_account_total_equity) || 0);
43
+ return {
44
+ account_id,
45
+ money: {
46
+ currency: 'USDT',
47
+ equity,
48
+ free,
49
+ },
50
+ positions: [...futurePositions, ...spotPositions],
51
+ };
52
+ };
53
+ exports.getUnifiedAccountInfo = getUnifiedAccountInfo;
54
+ //# sourceMappingURL=unified.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unified.js","sourceRoot":"","sources":["../../../src/services/accounts/unified.ts"],"names":[],"mappings":";;;AACA,qDAAsD;AACtD,uDAAwE;AACxE,qCAA+C;AAExC,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAE,EAAE;;IACzF,MAAM,CAAC,eAAe,EAAE,cAAc,EAAE,WAAW,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACvE,IAAA,4BAAmB,EAAC,UAAU,CAAC;QAC/B,IAAA,gCAAkB,EAAC,UAAU,EAAE,EAAE,CAAC;QAClC,IAAA,2BAAc,EAAC,EAAE,CAAC;KACnB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,QAAQ,mCAAI,EAAE,CAAC;IAChD,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IAErE,MAAM,aAAa,GAAgB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;SACrD,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;;QAChB,IAAI,QAAQ,KAAK,MAAM;YAAE,OAAO,SAAS,CAAC;QAC1C,IAAI,aAAa,GAAG,GAAG,QAAQ,OAAO,CAAC;QACvC,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,aAAa,GAAG,UAAU,CAAC;SAC5B;QACD,MAAM,cAAc,GAAG,MAAM,CAC3B,CAAA,MAAA,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,KAAK,aAAa,CAAC,0CAAE,IAAI,KAAI,CAAC,CACnF,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,CAAC,CAAA,MAAA,QAAQ,CAAC,QAAQ,CAAC,0CAAE,SAAS,KAAI,CAAC,CAAC,CAAC;QAC1D,OAAO;YACL,aAAa,EAAE,WAAW;YAC1B,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,QAAQ;YACpB,SAAS,EAAE,MAAM;YACjB,MAAM;YACN,WAAW,EAAE,MAAM;YACnB,cAAc;YACd,cAAc,EAAE,cAAc;YAC9B,eAAe,EAAE,CAAC;YAClB,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,MAAM,IAAI,GAAG,MAAM,CAAC,CAAA,MAAA,QAAQ,CAAC,MAAM,CAAC,0CAAE,SAAS,KAAI,CAAC,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,4BAA4B,KAAI,CAAC,CAAC,CAAC;IAEzE,OAAO;QACL,UAAU;QACV,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS,EAAE,CAAC,GAAG,eAAe,EAAE,GAAG,aAAa,CAAC;KAClD,CAAC;AACJ,CAAC,CAAC;AAhDW,QAAA,qBAAqB,yBAgDhC","sourcesContent":["import type { IPosition } from '@yuants/data-account';\nimport { getSpotTickers } from '../../api/public-api';\nimport { getUnifiedAccounts, ICredential } from '../../api/private-api';\nimport { loadFuturePositions } from './future';\n\nexport const getUnifiedAccountInfo = async (credential: ICredential, account_id: string) => {\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\n const spotPositions: IPosition[] = Object.keys(balances)\n .map((currency) => {\n if (currency === 'USDT') return undefined;\n let currency_pair = `${currency}_USDT`;\n if (currency === 'SOL2') {\n currency_pair = 'SOL_USDT';\n }\n const closable_price = Number(\n spotTickerList.find((ticker) => ticker.currency_pair === currency_pair)?.last || 0,\n );\n const volume = Number(balances[currency]?.available || 0);\n return {\n datasource_id: 'gate/spot',\n position_id: currency,\n product_id: currency,\n direction: 'LONG',\n volume,\n free_volume: volume,\n closable_price,\n position_price: closable_price,\n floating_profit: 0,\n valuation: closable_price * volume,\n } as IPosition;\n })\n .filter((item): item is IPosition => !!item);\n\n const free = Number(balances['USDT']?.available || 0);\n const equity = Number(unifiedAccount?.unified_account_total_equity || 0);\n\n return {\n account_id,\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions: [...futurePositions, ...spotPositions],\n };\n};\n"]}
@@ -0,0 +1,3 @@
1
+ import { ICredential } from '../api/private-api';
2
+ export declare const getDefaultCredential: () => ICredential | null;
3
+ //# sourceMappingURL=default-credential.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-credential.d.ts","sourceRoot":"","sources":["../../src/services/default-credential.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIjD,eAAO,MAAM,oBAAoB,QAAO,WAAW,GAAG,IAcrD,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultCredential = void 0;
4
+ const utils_1 = require("@yuants/utils");
5
+ let warned = false;
6
+ const getDefaultCredential = () => {
7
+ const access_key = process.env.ACCESS_KEY;
8
+ const secret_key = process.env.SECRET_KEY;
9
+ if (!access_key || !secret_key) {
10
+ if (!warned) {
11
+ console.warn((0, utils_1.formatTime)(Date.now()), 'Missing ACCESS_KEY or SECRET_KEY, skip registering Gate default services');
12
+ warned = true;
13
+ }
14
+ return null;
15
+ }
16
+ return { access_key, secret_key };
17
+ };
18
+ exports.getDefaultCredential = getDefaultCredential;
19
+ //# sourceMappingURL=default-credential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-credential.js","sourceRoot":"","sources":["../../src/services/default-credential.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAG3C,IAAI,MAAM,GAAG,KAAK,CAAC;AAEZ,MAAM,oBAAoB,GAAG,GAAuB,EAAE;IAC3D,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IAC1C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IAC1C,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;QAC9B,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,CAAC,IAAI,CACV,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EACtB,0EAA0E,CAC3E,CAAC;YACF,MAAM,GAAG,IAAI,CAAC;SACf;QACD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;AACpC,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B","sourcesContent":["import { formatTime } from '@yuants/utils';\nimport { ICredential } from '../api/private-api';\n\nlet warned = false;\n\nexport const getDefaultCredential = (): ICredential | null => {\n const access_key = process.env.ACCESS_KEY;\n const secret_key = process.env.SECRET_KEY;\n if (!access_key || !secret_key) {\n if (!warned) {\n console.warn(\n formatTime(Date.now()),\n 'Missing ACCESS_KEY or SECRET_KEY, skip registering Gate default services',\n );\n warned = true;\n }\n return null;\n }\n return { access_key, secret_key };\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=legacy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../src/services/legacy.ts"],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const data_account_1 = require("@yuants/data-account");
4
+ const data_order_1 = require("@yuants/data-order");
5
+ const protocol_1 = require("@yuants/protocol");
6
+ const utils_1 = require("@yuants/utils");
7
+ const profile_1 = require("./accounts/profile");
8
+ const future_1 = require("./accounts/future");
9
+ const unified_1 = require("./accounts/unified");
10
+ const spot_1 = require("./accounts/spot");
11
+ const listOrders_1 = require("./orders/listOrders");
12
+ const submitOrder_1 = require("./orders/submitOrder");
13
+ const cancelOrder_1 = require("./orders/cancelOrder");
14
+ const default_credential_1 = require("./default-credential");
15
+ const credential = (0, default_credential_1.getDefaultCredential)();
16
+ if (credential) {
17
+ (async () => {
18
+ const terminal = protocol_1.Terminal.fromNodeEnv();
19
+ const accountIds = await (0, profile_1.resolveAccountProfile)(credential);
20
+ (0, data_account_1.provideAccountInfoService)(terminal, accountIds.future, () => (0, future_1.getFutureAccountInfo)(credential, accountIds.future), { auto_refresh_interval: 1000 });
21
+ (0, data_account_1.addAccountMarket)(terminal, { account_id: accountIds.future, market_id: 'GATE/USDT-FUTURE' });
22
+ (0, data_account_1.provideAccountInfoService)(terminal, accountIds.unified, () => (0, unified_1.getUnifiedAccountInfo)(credential, accountIds.unified), { auto_refresh_interval: 1000 });
23
+ (0, data_account_1.addAccountMarket)(terminal, { account_id: accountIds.unified, market_id: 'GATE/UNIFIED' });
24
+ (0, data_account_1.provideAccountInfoService)(terminal, accountIds.spot, () => (0, spot_1.getSpotAccountInfo)(credential, accountIds.spot), { auto_refresh_interval: 1000 });
25
+ (0, data_account_1.addAccountMarket)(terminal, { account_id: accountIds.spot, market_id: 'GATE/SPOT' });
26
+ (0, data_order_1.providePendingOrdersService)(terminal, accountIds.future, () => (0, listOrders_1.listOrders)(credential, accountIds.future), { auto_refresh_interval: 2000 });
27
+ terminal.server.provideService('SubmitOrder', {
28
+ required: ['account_id'],
29
+ properties: { account_id: { const: accountIds.future } },
30
+ }, async (msg) => {
31
+ try {
32
+ const data = await (0, submitOrder_1.submitOrder)(credential, msg.req);
33
+ return { res: { code: 0, message: 'OK', data } };
34
+ }
35
+ catch (error) {
36
+ return { res: { code: 500, message: `${error}` } };
37
+ }
38
+ });
39
+ terminal.server.provideService('CancelOrder', {
40
+ required: ['account_id'],
41
+ properties: { account_id: { const: accountIds.future } },
42
+ }, async (msg) => {
43
+ try {
44
+ await (0, cancelOrder_1.cancelOrder)(credential, msg.req);
45
+ return { res: { code: 0, message: 'OK' } };
46
+ }
47
+ catch (error) {
48
+ return { res: { code: 500, message: `${error}` } };
49
+ }
50
+ });
51
+ })().catch((error) => {
52
+ console.error((0, utils_1.formatTime)(Date.now()), 'GateLegacyInitFailed', error);
53
+ });
54
+ }
55
+ //# sourceMappingURL=legacy.js.map