@yuants/vendor-gate 0.4.16 → 0.4.18

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 (34) hide show
  1. package/dist/api/public-api.js +1 -1
  2. package/dist/api/public-api.js.map +1 -1
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/services/accounts/future.js +13 -16
  6. package/dist/services/accounts/future.js.map +1 -1
  7. package/dist/services/markets/product.js +4 -37
  8. package/dist/services/markets/product.js.map +1 -1
  9. package/dist/services/markets/quote.js +70 -0
  10. package/dist/services/markets/quote.js.map +1 -0
  11. package/dist/services/orders/submitOrder.js +2 -2
  12. package/dist/services/orders/submitOrder.js.map +1 -1
  13. package/lib/api/public-api.d.ts +1 -1
  14. package/lib/api/public-api.js +1 -1
  15. package/lib/api/public-api.js.map +1 -1
  16. package/lib/index.d.ts +1 -0
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +1 -0
  19. package/lib/index.js.map +1 -1
  20. package/lib/services/accounts/future.d.ts.map +1 -1
  21. package/lib/services/accounts/future.js +12 -15
  22. package/lib/services/accounts/future.js.map +1 -1
  23. package/lib/services/markets/product.d.ts +1 -2
  24. package/lib/services/markets/product.d.ts.map +1 -1
  25. package/lib/services/markets/product.js +5 -38
  26. package/lib/services/markets/product.js.map +1 -1
  27. package/lib/services/markets/quote.d.ts +2 -0
  28. package/lib/services/markets/quote.d.ts.map +1 -0
  29. package/lib/services/markets/quote.js +72 -0
  30. package/lib/services/markets/quote.js.map +1 -0
  31. package/lib/services/orders/submitOrder.js +2 -2
  32. package/lib/services/orders/submitOrder.js.map +1 -1
  33. package/package.json +2 -1
  34. package/temp/package-deps.json +11 -9
@@ -31,7 +31,7 @@ export const getFuturesTickers = (settle, params) => requestPublic('GET', `/api/
31
31
  /**
32
32
  * 获取交易对 ticker 信息
33
33
  *
34
- * 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
34
+ * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E4%BA%A4%E6%98%93%E5%AF%B9-ticker-%E4%BF%A1%E6%81%AF
35
35
  */
36
36
  export const getSpotTickers = (params) => requestPublic('GET', `/api/v4/spot/tickers`, params);
37
37
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAc,EACd,MAA4C,EA8C5C,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,mBAAmB,MAAM,YAAY,EAAE,MAAM,CAAC,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,MAAc,EACd,MAA4C,EAM5C,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,mBAAmB,MAAM,eAAe,EAAE,MAAM,CAAC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAAc,EACd,MAKC,EAaA,EAAE,CACH,WAAW,CAAC,QAAQ,CAAC,sBAAsB,MAAM,EAAE,EAAE,GAAG,EAAE,KAAM,EAAE,GAAG,EAAE,CACrE,aAAa,CAAC,KAAK,EAAE,mBAAmB,MAAM,aAAa,EAAE,MAAM,CAAC,CACrE,CAAC;AAEJ;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,MAA8B,EAyB9B,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,mBAAmB,MAAM,UAAU,EAAE,MAAM,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAG9B,EAoBC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,sBAAsB,EAAE,MAAM,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAqBlC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC","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\n/**\n * 查询支持的所有现货交易对\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%94%AF%E6%8C%81%E7%9A%84%E6%89%80%E6%9C%89%E4%BA%A4%E6%98%93%E5%AF%B9\n */\nexport const getSpotCurrencyPairs = (): Promise<\n Array<{\n id: string;\n base: string;\n base_name: string;\n quote: string;\n quote_name: string;\n fee: string;\n min_base_amount: string;\n min_quote_amount: string;\n max_base_amount: string;\n max_quote_amount: string;\n amount_precision: Number;\n precision: Number;\n trade_status: string;\n sell_start: Number;\n buy_start: number;\n delisting_time: number;\n trade_url: string;\n st_tag: boolean;\n }>\n> => requestPublic('GET', `/spot/currency_pairs`);\n"]}
1
+ {"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAc,EACd,MAA4C,EA8C5C,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,mBAAmB,MAAM,YAAY,EAAE,MAAM,CAAC,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,MAAc,EACd,MAA4C,EAM5C,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,mBAAmB,MAAM,eAAe,EAAE,MAAM,CAAC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAAc,EACd,MAKC,EAaA,EAAE,CACH,WAAW,CAAC,QAAQ,CAAC,sBAAsB,MAAM,EAAE,EAAE,GAAG,EAAE,KAAM,EAAE,GAAG,EAAE,CACrE,aAAa,CAAC,KAAK,EAAE,mBAAmB,MAAM,aAAa,EAAE,MAAM,CAAC,CACrE,CAAC;AAEJ;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,MAA8B,EAyB9B,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,mBAAmB,MAAM,UAAU,EAAE,MAAM,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAG9B,EAoBC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,sBAAsB,EAAE,MAAM,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAqBlC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC","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.com/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E4%BA%A4%E6%98%93%E5%AF%B9-ticker-%E4%BF%A1%E6%81%AF\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\n/**\n * 查询支持的所有现货交易对\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%94%AF%E6%8C%81%E7%9A%84%E6%89%80%E6%9C%89%E4%BA%A4%E6%98%93%E5%AF%B9\n */\nexport const getSpotCurrencyPairs = (): Promise<\n Array<{\n id: string;\n base: string;\n base_name: string;\n quote: string;\n quote_name: string;\n fee: string;\n min_base_amount: string;\n min_quote_amount: string;\n max_base_amount: string;\n max_quote_amount: string;\n amount_precision: Number;\n precision: Number;\n trade_status: string;\n sell_start: Number;\n buy_start: number;\n delisting_time: number;\n trade_url: string;\n st_tag: boolean;\n }>\n> => requestPublic('GET', `/spot/currency_pairs`);\n"]}
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ import './services/markets/product';
2
2
  import './services/markets/interest-rate';
3
3
  import './services/transfer';
4
4
  import './services/exchange';
5
+ import './services/markets/quote';
5
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC;AACpC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC","sourcesContent":["import './services/markets/product';\nimport './services/markets/interest-rate';\nimport './services/transfer';\nimport './services/exchange';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC;AACpC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,0BAA0B,CAAC","sourcesContent":["import './services/markets/product';\nimport './services/markets/interest-rate';\nimport './services/transfer';\nimport './services/exchange';\nimport './services/markets/quote';\n"]}
@@ -1,23 +1,19 @@
1
- import { firstValueFrom } from 'rxjs';
2
- import { getFuturePositions, getFuturesAccounts } from '../../api/private-api';
3
- import { mapProductIdToUsdtFutureProduct$ } from '../markets/product';
4
1
  import { encodePath } from '@yuants/utils';
2
+ import { getFuturePositions, getFuturesAccounts } from '../../api/private-api';
3
+ import { productCache } from '../markets/product';
5
4
  export const loadFuturePositions = async (credential) => {
6
- const [positionsRes, productMap] = await Promise.all([
7
- getFuturePositions(credential, 'usdt'),
8
- firstValueFrom(mapProductIdToUsdtFutureProduct$),
9
- ]);
10
- const positions = Array.isArray(positionsRes) ? positionsRes : [];
11
- return positions
12
- .filter((pos) => Math.abs(pos.size) > 0)
13
- .map((position) => {
14
- var _a;
5
+ var _a;
6
+ const positions = [];
7
+ const positionsRes = await getFuturePositions(credential, 'usdt');
8
+ for (const position of Array.isArray(positionsRes) ? positionsRes : []) {
9
+ if (!(Math.abs(position.size) > 0))
10
+ continue;
15
11
  const product_id = encodePath('GATE', 'FUTURE', position.contract);
16
- const theProduct = productMap.get(product_id);
12
+ const theProduct = await productCache.query(product_id);
17
13
  const volume = Math.abs(position.size);
18
14
  const closable_price = Number(position.mark_price);
19
15
  const valuation = volume * closable_price * ((_a = theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) !== null && _a !== void 0 ? _a : 1);
20
- return {
16
+ positions.push({
21
17
  datasource_id: 'GATE',
22
18
  position_id: `${position.contract}-${position.leverage}-${position.mode}`,
23
19
  product_id,
@@ -34,8 +30,9 @@ export const loadFuturePositions = async (credential) => {
34
30
  closable_price,
35
31
  floating_profit: Number(position.unrealised_pnl),
36
32
  valuation,
37
- };
38
- });
33
+ });
34
+ }
35
+ return positions;
39
36
  };
40
37
  export const getFutureAccountInfo = async (credential) => {
41
38
  const [positions, rawAccount] = await Promise.all([
@@ -1 +1 @@
1
- {"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,M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AAQ,CAAC,IAAI,KAAK,YAAY;oBAChC,CAAC,CAAC,OAAO;oBACT,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC;wBACnB,CAAC,CAAC,MAAM;wBACR,CAAC,CAAC,OAAO;YACb,MAAM;YACN,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;YACpC,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;YAC5C,cAAc;YACd,eAAe,EAAE,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC;YAChD,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IACpE,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChD,mBAAmB,CAAC,UAAU,CAAC;QAC/B,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import type { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { mapProductIdToUsdtFutureProduct$ } from '../markets/product';\nimport { encodePath } from '@yuants/utils';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const [positionsRes, productMap] = await Promise.all([\n getFuturePositions(credential, 'usdt'),\n firstValueFrom(mapProductIdToUsdtFutureProduct$),\n ]);\n const positions = Array.isArray(positionsRes) ? positionsRes : [];\n return positions\n .filter((pos) => Math.abs(pos.size) > 0)\n .map((position): IPosition => {\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = productMap.get(product_id);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price * (theProduct?.value_scale ?? 1);\n return {\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n valuation,\n };\n });\n};\n\nexport const getFutureAccountInfo = async (credential: ICredential) => {\n const [positions, rawAccount] = await Promise.all([\n loadFuturePositions(credential),\n getFuturesAccounts(credential, 'usdt'),\n ]);\n\n return positions;\n};\n"]}
1
+ {"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAe,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;;IACzF,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAElE,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE;QACtE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAAE,SAAS;QAE7C,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnE,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;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C;AACnB,CAAC,CAAC","sourcesContent":["import type { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { productCache } from '../markets/product';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n const positionsRes = await getFuturePositions(credential, 'usdt');\n\n for (const position of Array.isArray(positionsRes) ? positionsRes : []) {\n if (!(Math.abs(position.size) > 0)) continue;\n\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = await productCache.query(product_id);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price * (theProduct?.value_scale ?? 1);\n positions.push({\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n valuation,\n });\n }\n\n return positions;\n};\n\nexport const getFutureAccountInfo = async (credential: ICredential) => {\n const [positions, rawAccount] = await Promise.all([\n loadFuturePositions(credential),\n getFuturesAccounts(credential, 'usdt'),\n ]);\n\n return positions;\n};\n"]}
@@ -1,41 +1,8 @@
1
+ import { createProductCache } from '@yuants/data-product';
1
2
  import { Terminal } from '@yuants/protocol';
2
- import { createSQLWriter } from '@yuants/sql';
3
- import { defer, from, map, mergeMap, repeat, retry, shareReplay, Subject, tap, toArray } from 'rxjs';
4
- import { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';
5
3
  import { encodePath } from '@yuants/utils';
6
- const terminal = Terminal.fromNodeEnv();
7
- const product$ = new Subject();
8
- const usdtFutureProducts$ = defer(() => getFuturesContracts('usdt', {})).pipe(mergeMap((contracts) => from(contracts).pipe(map((contract) => {
9
- const [base, quote] = contract.name.split('_');
10
- return {
11
- datasource_id: 'GATE',
12
- product_id: encodePath('GATE', 'FUTURE', contract.name),
13
- base_currency: base,
14
- quote_currency: quote,
15
- value_scale: Number(contract.quanto_multiplier),
16
- price_step: Number(contract.order_price_round),
17
- volume_step: 1,
18
- name: '',
19
- value_scale_unit: '',
20
- margin_rate: 0,
21
- value_based_cost: 0,
22
- volume_based_cost: 0,
23
- max_position: 0,
24
- max_volume: 0,
25
- allow_long: true,
26
- allow_short: true,
27
- market_id: 'GATE/USDT-FUTURE',
28
- no_interest_rate: false,
29
- };
30
- }), tap((item) => product$.next(item)), toArray())), repeat({ delay: 3600000 }), retry({ delay: 60000 }), shareReplay(1));
31
- usdtFutureProducts$.subscribe();
32
- export const mapProductIdToUsdtFutureProduct$ = usdtFutureProducts$.pipe(map((items) => new Map(items.map((item) => [item.product_id, item]))), shareReplay(1));
33
- createSQLWriter(terminal, {
34
- data$: product$,
35
- tableName: 'product',
36
- conflictKeys: ['datasource_id', 'product_id'],
37
- writeInterval: 1000,
38
- });
4
+ import { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';
5
+ export const productCache = createProductCache(Terminal.fromNodeEnv());
39
6
  export const listProducts = async () => {
40
7
  const [futureProducts, spotProducts] = await Promise.all([
41
8
  getFuturesContracts('usdt', {}),
@@ -53,7 +20,7 @@ export const listProducts = async () => {
53
20
  volume_step: 1,
54
21
  name: '',
55
22
  value_scale_unit: '',
56
- margin_rate: 0,
23
+ margin_rate: 1 / Number(contract.leverage_max),
57
24
  value_based_cost: 0,
58
25
  volume_based_cost: 0,
59
26
  max_position: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAA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,KAAK;KACxB,CAAC,CAAC,CAAC;IAEJ,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AAC1B,CAAC,CAAC","sourcesContent":["import { IProduct } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { defer, from, map, mergeMap, repeat, retry, shareReplay, Subject, tap, toArray } from 'rxjs';\nimport { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';\nimport { encodePath } from '@yuants/utils';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst product$ = new Subject<IProduct>();\n\nconst usdtFutureProducts$ = defer(() => getFuturesContracts('usdt', {})).pipe(\n mergeMap((contracts) =>\n from(contracts).pipe(\n map((contract): IProduct => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n }),\n tap((item) => product$.next(item)),\n toArray(),\n ),\n ),\n repeat({ delay: 3_600_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\nusdtFutureProducts$.subscribe();\n\nexport const mapProductIdToUsdtFutureProduct$ = usdtFutureProducts$.pipe(\n map((items) => new Map(items.map((item) => [item.product_id, item]))),\n shareReplay(1),\n);\n\ncreateSQLWriter(terminal, {\n data$: product$,\n tableName: 'product',\n conflictKeys: ['datasource_id', 'product_id'],\n writeInterval: 1000,\n});\n\nexport const listProducts = async () => {\n const [futureProducts, spotProducts] = await Promise.all([\n getFuturesContracts('usdt', {}),\n getSpotCurrencyPairs(),\n ]);\n const fps = futureProducts.map((contract) => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n const sps = spotProducts.map((spot) => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', spot.id),\n base_currency: spot.base,\n quote_currency: spot.quote,\n value_scale: 1,\n price_step: Number(`1e-${spot.precision}`),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'GATE/USDT-SPOT',\n no_interest_rate: false,\n }));\n\n return [...fps, ...sps];\n};\n"]}
1
+ {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjF,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AAEvE,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;IACrC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACvD,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC;QAC/B,oBAAoB,E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C;QACd,IAAI,EAAE,EAAE;QACR,gBAAgB,EAAE,EAAE;QACpB,WAAW,EAAE,CAAC;QACd,gBAAgB,EAAE,CAAC;QACnB,iBAAiB,EAAE,CAAC;QACpB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,KAAK;QAClB,SAAS,EAAE,gBAAgB;QAC3B,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC,CAAC;IAEJ,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AAC1B,CAAC,CAAC","sourcesContent":["import { createProductCache } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';\n\nexport const productCache = createProductCache(Terminal.fromNodeEnv());\n\nexport const listProducts = async () => {\n const [futureProducts, spotProducts] = await Promise.all([\n getFuturesContracts('usdt', {}),\n getSpotCurrencyPairs(),\n ]);\n const fps = futureProducts.map((contract) => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 1 / Number(contract.leverage_max),\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n const sps = spotProducts.map((spot) => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', spot.id),\n base_currency: spot.base,\n quote_currency: spot.quote,\n value_scale: 1,\n price_step: Number(`1e-${spot.precision}`),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'GATE/USDT-SPOT',\n no_interest_rate: false,\n }));\n\n return [...fps, ...sps];\n};\n"]}
@@ -0,0 +1,70 @@
1
+ import { Terminal } from '@yuants/protocol';
2
+ import { writeToSQL } from '@yuants/sql';
3
+ import { decodePath, encodePath } from '@yuants/utils';
4
+ import { defer, filter, map, mergeMap, repeat, retry, shareReplay, merge, catchError, EMPTY, groupBy, scan, share, } from 'rxjs';
5
+ import { getFuturesTickers, getFuturesContracts, getSpotTickers } from '../../api/public-api';
6
+ const terminal = Terminal.fromNodeEnv();
7
+ // 获取所有USDT永续合约
8
+ const usdtFutureContracts$ = defer(() => getFuturesContracts('usdt', {})).pipe(repeat({ delay: 3600000 }), retry({ delay: 60000 }), shareReplay(1));
9
+ // 从tickers获取价格和交易量数据
10
+ const quoteFromTickers$ = defer(() => getFuturesTickers('usdt', {})).pipe(mergeMap((tickers) => tickers), map((ticker) => ({
11
+ datasource_id: 'GATE',
12
+ product_id: encodePath('GATE', 'FUTURE', ticker.contract),
13
+ last_price: ticker.last,
14
+ ask_price: ticker.lowest_ask,
15
+ bid_price: ticker.highest_bid,
16
+ // GATE API doesn't provide bid/ask volumes in tickers endpoint
17
+ // We'll need to use order book for that if required
18
+ ask_volume: '0',
19
+ bid_volume: '0',
20
+ // total_size is the open interest
21
+ open_interest: ticker.total_size,
22
+ // funding_rate is the current funding rate
23
+ interest_rate_long: ticker.funding_rate ? `${-parseFloat(ticker.funding_rate)}` : undefined,
24
+ interest_rate_short: ticker.funding_rate,
25
+ })), repeat({ delay: 5000 }), retry({ delay: 1000 }));
26
+ // 从现货tickers获取价格和交易量数据
27
+ const quoteFromSpotTickers$ = defer(() => getSpotTickers({})).pipe(mergeMap((tickers) => tickers), map((ticker) => {
28
+ var _a, _b;
29
+ return ({
30
+ datasource_id: 'GATE',
31
+ product_id: encodePath('GATE', 'SPOT', ticker.currency_pair),
32
+ last_price: ticker.last,
33
+ ask_price: ticker.lowest_ask,
34
+ bid_price: ticker.highest_bid,
35
+ ask_volume: (_a = ticker.lowest_size) !== null && _a !== void 0 ? _a : '0',
36
+ bid_volume: (_b = ticker.highest_size) !== null && _b !== void 0 ? _b : '0',
37
+ // 现货没有持仓量的概念,设置为0
38
+ open_interest: '0',
39
+ });
40
+ }), repeat({ delay: 5000 }), retry({ delay: 1000 }));
41
+ const quoteSources$ = [quoteFromTickers$, quoteFromSpotTickers$];
42
+ const quote$ = defer(() => merge(...quoteSources$.map((x$) => defer(() => x$).pipe(
43
+ // 防止单个流关闭导致整体关闭
44
+ catchError(() => EMPTY))))).pipe(groupBy((x) => encodePath(x.datasource_id, x.product_id)), mergeMap((group$) => {
45
+ return group$.pipe(
46
+ //
47
+ scan((acc, cur) => Object.assign(acc, cur), {}));
48
+ }), share());
49
+ // 写入数据库
50
+ if (process.env.WRITE_QUOTE_TO_SQL === 'true') {
51
+ terminal.channel.publishChannel('quote', { pattern: `^GATE/` }, (channel_id) => {
52
+ const [datasource_id, product_id] = decodePath(channel_id);
53
+ if (!datasource_id) {
54
+ throw 'datasource_id is required';
55
+ }
56
+ if (!product_id) {
57
+ throw 'product_id is required';
58
+ }
59
+ return quote$.pipe(filter((x) => x.product_id === product_id));
60
+ });
61
+ quote$
62
+ .pipe(writeToSQL({
63
+ terminal,
64
+ writeInterval: 1000,
65
+ tableName: 'quote',
66
+ conflictKeys: ['datasource_id', 'product_id'],
67
+ }))
68
+ .subscribe();
69
+ }
70
+ //# sourceMappingURL=quote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAc,MAAM,eAAe,CAAC;AACnE,OAAO,EACL,KAAK,EACL,MAAM,EAEN,GAAG,EACH,QA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ote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport {\n defer,\n filter,\n from,\n map,\n mergeMap,\n repeat,\n retry,\n shareReplay,\n merge,\n catchError,\n EMPTY,\n groupBy,\n scan,\n share,\n tap,\n} from 'rxjs';\nimport { getFuturesTickers, getFuturesContracts, 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 writeToSQL({\n terminal,\n writeInterval: 1000,\n tableName: 'quote',\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n}\n"]}
@@ -33,10 +33,10 @@ export const submitOrder = async (credential, order) => {
33
33
  if (price === undefined) {
34
34
  throw new Error('Limit/Maker order requires price');
35
35
  }
36
- const [, TYPE] = decodePath(order.product_id);
36
+ const [, TYPE, contract] = decodePath(order.product_id);
37
37
  if (TYPE === 'FUTURE') {
38
38
  const res = await postFutureOrders(credential, 'usdt', {
39
- contract: order.product_id,
39
+ contract,
40
40
  size,
41
41
  price,
42
42
  tif,
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAA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,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACjG,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;KACrD;IACD,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,IAAI,KAAK,QAAQ,EAAE;QACrB,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE;YACrD,QAAQ,EAAE,KAAK,CAAC,UAAU;YAC1B,IAAI;YACJ,KAAK;YACL,GAAG;YACH,WAAW;SACZ,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,KAAK,EAAE;YACb,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClF,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;SACzB;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nconst resolveTif = (order_type?: string): string => {\n if (order_type === 'MARKET') return 'ioc';\n if (order_type === 'LIMIT' || order_type === 'MAKER') return 'gtc';\n throw new Error(`Unsupported order_type: ${order_type}`);\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = resolveTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract: order.product_id,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\n};\n"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAAe,EAAE;QACvB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,CAAC,CAAC;QACX,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,CAAC,CAAC,CAAC;QACZ;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,eAAe,EAAE,CAAC,CAAC;KACtE;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,UAAmB,EAAU,EAAE;IACjD,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;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AAQ;YACR,IAAI;YACJ,KAAK;YACL,GAAG;YACH,WAAW;SACZ,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,KAAK,EAAE;YACb,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClF,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;SACzB;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nconst resolveTif = (order_type?: string): string => {\n if (order_type === 'MARKET') return 'ioc';\n if (order_type === 'LIMIT' || order_type === 'MAKER') return 'gtc';\n throw new Error(`Unsupported order_type: ${order_type}`);\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = resolveTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE, contract] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\n};\n"]}
@@ -122,7 +122,7 @@ export declare const getFuturesTickers: (settle: string, params?: {
122
122
  /**
123
123
  * 获取交易对 ticker 信息
124
124
  *
125
- * 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
125
+ * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E4%BA%A4%E6%98%93%E5%AF%B9-ticker-%E4%BF%A1%E6%81%AF
126
126
  */
127
127
  export declare const getSpotTickers: (params: {
128
128
  currency_pair?: string;
@@ -38,7 +38,7 @@ exports.getFuturesTickers = getFuturesTickers;
38
38
  /**
39
39
  * 获取交易对 ticker 信息
40
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
41
+ * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E4%BA%A4%E6%98%93%E5%AF%B9-ticker-%E4%BF%A1%E6%81%AF
42
42
  */
43
43
  const getSpotTickers = (params) => (0, http_client_1.requestPublic)('GET', `/api/v4/spot/tickers`, params);
44
44
  exports.getSpotTickers = getSpotTickers;
@@ -1 +1 @@
1
- {"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAC7C,+CAA8C;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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\n/**\n * 查询支持的所有现货交易对\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%94%AF%E6%8C%81%E7%9A%84%E6%89%80%E6%9C%89%E4%BA%A4%E6%98%93%E5%AF%B9\n */\nexport const getSpotCurrencyPairs = (): Promise<\n Array<{\n id: string;\n base: string;\n base_name: string;\n quote: string;\n quote_name: string;\n fee: string;\n min_base_amount: string;\n min_quote_amount: string;\n max_base_amount: string;\n max_quote_amount: string;\n amount_precision: Number;\n precision: Number;\n trade_status: string;\n sell_start: Number;\n buy_start: number;\n delisting_time: number;\n trade_url: string;\n st_tag: boolean;\n }>\n> => requestPublic('GET', `/spot/currency_pairs`);\n"]}
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;AAE1D;;;GAGG;AACI,MAAM,oBAAoB,GAAG,GAqBlC,EAAE,CAAC,IAAA,2BAAa,EAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;AArBrC,QAAA,oBAAoB,wBAqBiB","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.com/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E4%BA%A4%E6%98%93%E5%AF%B9-ticker-%E4%BF%A1%E6%81%AF\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\n/**\n * 查询支持的所有现货交易对\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%94%AF%E6%8C%81%E7%9A%84%E6%89%80%E6%9C%89%E4%BA%A4%E6%98%93%E5%AF%B9\n */\nexport const getSpotCurrencyPairs = (): Promise<\n Array<{\n id: string;\n base: string;\n base_name: string;\n quote: string;\n quote_name: string;\n fee: string;\n min_base_amount: string;\n min_quote_amount: string;\n max_base_amount: string;\n max_quote_amount: string;\n amount_precision: Number;\n precision: Number;\n trade_status: string;\n sell_start: Number;\n buy_start: number;\n delisting_time: number;\n trade_url: string;\n st_tag: boolean;\n }>\n> => requestPublic('GET', `/spot/currency_pairs`);\n"]}
package/lib/index.d.ts CHANGED
@@ -2,4 +2,5 @@ import './services/markets/product';
2
2
  import './services/markets/interest-rate';
3
3
  import './services/transfer';
4
4
  import './services/exchange';
5
+ import './services/markets/quote';
5
6
  //# 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"}
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"}
package/lib/index.js CHANGED
@@ -4,4 +4,5 @@ require("./services/markets/product");
4
4
  require("./services/markets/interest-rate");
5
5
  require("./services/transfer");
6
6
  require("./services/exchange");
7
+ require("./services/markets/quote");
7
8
  //# 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","sourcesContent":["import './services/markets/product';\nimport './services/markets/interest-rate';\nimport './services/transfer';\nimport './services/exchange';\n"]}
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 +1 @@
1
- {"version":3,"file":"future.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI5F,eAAO,MAAM,mBAAmB,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAkCtF,CAAC;AAEF,eAAO,MAAM,oBAAoB,eAAsB,WAAW,yBAOjE,CAAC"}
1
+ {"version":3,"file":"future.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAA0C,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG5F,eAAO,MAAM,mBAAmB,eAAsB,WAAW,KAAG,QAAQ,SAAS,EAAE,CAkCtF,CAAC;AAEF,eAAO,MAAM,oBAAoB,eAAsB,WAAW,yBAOjE,CAAC"}
@@ -1,26 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFutureAccountInfo = exports.loadFuturePositions = void 0;
4
- const rxjs_1 = require("rxjs");
4
+ const utils_1 = require("@yuants/utils");
5
5
  const private_api_1 = require("../../api/private-api");
6
6
  const product_1 = require("../markets/product");
7
- const utils_1 = require("@yuants/utils");
8
7
  const loadFuturePositions = async (credential) => {
9
- const [positionsRes, productMap] = await Promise.all([
10
- (0, private_api_1.getFuturePositions)(credential, 'usdt'),
11
- (0, rxjs_1.firstValueFrom)(product_1.mapProductIdToUsdtFutureProduct$),
12
- ]);
13
- const positions = Array.isArray(positionsRes) ? positionsRes : [];
14
- return positions
15
- .filter((pos) => Math.abs(pos.size) > 0)
16
- .map((position) => {
17
- var _a;
8
+ var _a;
9
+ const positions = [];
10
+ const positionsRes = await (0, private_api_1.getFuturePositions)(credential, 'usdt');
11
+ for (const position of Array.isArray(positionsRes) ? positionsRes : []) {
12
+ if (!(Math.abs(position.size) > 0))
13
+ continue;
18
14
  const product_id = (0, utils_1.encodePath)('GATE', 'FUTURE', position.contract);
19
- const theProduct = productMap.get(product_id);
15
+ const theProduct = await product_1.productCache.query(product_id);
20
16
  const volume = Math.abs(position.size);
21
17
  const closable_price = Number(position.mark_price);
22
18
  const valuation = volume * closable_price * ((_a = theProduct === null || theProduct === void 0 ? void 0 : theProduct.value_scale) !== null && _a !== void 0 ? _a : 1);
23
- return {
19
+ positions.push({
24
20
  datasource_id: 'GATE',
25
21
  position_id: `${position.contract}-${position.leverage}-${position.mode}`,
26
22
  product_id,
@@ -37,8 +33,9 @@ const loadFuturePositions = async (credential) => {
37
33
  closable_price,
38
34
  floating_profit: Number(position.unrealised_pnl),
39
35
  valuation,
40
- };
41
- });
36
+ });
37
+ }
38
+ return positions;
42
39
  };
43
40
  exports.loadFuturePositions = loadFuturePositions;
44
41
  const getFutureAccountInfo = async (credential) => {
@@ -1 +1 @@
1
- {"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":";;;AACA,+BAAsC;AACtC,uDAA4F;AAC5F,gDAAsE;AACtE,yCAA2C;AAEpC,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;IACzF,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,IAAA,gCAAkB,EAAC,UAAU,EAAE,MAAM,CAAC;QACtC,IAAA,qBAAc,EAAC,0CAAgC,CAAC;KACjD,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAClE,OAAO,SAAS;S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,CAAC,CAAC;AACP,CAAC,CAAC;AAlCW,QAAA,mBAAmB,uBAkC9B;AAEK,MAAM,oBAAoB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IACpE,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChD,IAAA,2BAAmB,EAAC,UAAU,CAAC;QAC/B,IAAA,gCAAkB,EAAC,UAAU,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAPW,QAAA,oBAAoB,wBAO/B","sourcesContent":["import type { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { mapProductIdToUsdtFutureProduct$ } from '../markets/product';\nimport { encodePath } from '@yuants/utils';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const [positionsRes, productMap] = await Promise.all([\n getFuturePositions(credential, 'usdt'),\n firstValueFrom(mapProductIdToUsdtFutureProduct$),\n ]);\n const positions = Array.isArray(positionsRes) ? positionsRes : [];\n return positions\n .filter((pos) => Math.abs(pos.size) > 0)\n .map((position): IPosition => {\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = productMap.get(product_id);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price * (theProduct?.value_scale ?? 1);\n return {\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n valuation,\n };\n });\n};\n\nexport const getFutureAccountInfo = async (credential: ICredential) => {\n const [positions, rawAccount] = await Promise.all([\n loadFuturePositions(credential),\n getFuturesAccounts(credential, 'usdt'),\n ]);\n\n return positions;\n};\n"]}
1
+ {"version":3,"file":"future.js","sourceRoot":"","sources":["../../../src/services/accounts/future.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,uDAA4F;AAC5F,gDAAkD;AAE3C,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAwB,EAAE;;IACzF,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,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnE,MAAM,UAAU,GAAG,MAAM,sBAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACxD,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,SAAS,CAAC,IAAI,CAAC;YACb,aAAa,EAAE,MAAM;YACrB,WAAW,EAAE,GAAG,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE;YACzE,UAAU;YACV,SAAS,EACP,QAAQ,CAAC,IAAI,KAAK,WAAW;gBAC3B,CAAC,CAAC,MAAM;gBACR,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;oBAChC,CAAC,CAAC,OAAO;oBACT,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC;wBACnB,CAAC,CAAC,MAAM;wBACR,CAAC,CAAC,OAAO;YACb,MAAM;YACN,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;YACpC,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;YAC5C,cAAc;YACd,eAAe,EAAE,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC;YAChD,SAAS;SACV,CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAlCW,QAAA,mBAAmB,uBAkC9B;AAEK,MAAM,oBAAoB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IACpE,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChD,IAAA,2BAAmB,EAAC,UAAU,CAAC;QAC/B,IAAA,gCAAkB,EAAC,UAAU,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAPW,QAAA,oBAAoB,wBAO/B","sourcesContent":["import type { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturePositions, getFuturesAccounts, ICredential } from '../../api/private-api';\nimport { productCache } from '../markets/product';\n\nexport const loadFuturePositions = async (credential: ICredential): Promise<IPosition[]> => {\n const positions: IPosition[] = [];\n const positionsRes = await getFuturePositions(credential, 'usdt');\n\n for (const position of Array.isArray(positionsRes) ? positionsRes : []) {\n if (!(Math.abs(position.size) > 0)) continue;\n\n const product_id = encodePath('GATE', 'FUTURE', position.contract);\n const theProduct = await productCache.query(product_id);\n const volume = Math.abs(position.size);\n const closable_price = Number(position.mark_price);\n const valuation = volume * closable_price * (theProduct?.value_scale ?? 1);\n positions.push({\n datasource_id: 'GATE',\n position_id: `${position.contract}-${position.leverage}-${position.mode}`,\n product_id,\n direction:\n position.mode === 'dual_long'\n ? 'LONG'\n : position.mode === 'dual_short'\n ? 'SHORT'\n : position.size > 0\n ? 'LONG'\n : 'SHORT',\n volume,\n free_volume: Math.abs(position.size),\n position_price: Number(position.entry_price),\n closable_price,\n floating_profit: Number(position.unrealised_pnl),\n valuation,\n });\n }\n\n return positions;\n};\n\nexport const getFutureAccountInfo = async (credential: ICredential) => {\n const [positions, rawAccount] = await Promise.all([\n loadFuturePositions(credential),\n getFuturesAccounts(credential, 'usdt'),\n ]);\n\n return positions;\n};\n"]}
@@ -1,5 +1,4 @@
1
- import { IProduct } from '@yuants/data-product';
2
- export declare const mapProductIdToUsdtFutureProduct$: import("rxjs").Observable<Map<string, IProduct>>;
1
+ export declare const productCache: import("@yuants/cache").ICache<import("@yuants/data-product").IProduct>;
3
2
  export declare const listProducts: () => Promise<{
4
3
  datasource_id: string;
5
4
  product_id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAgDhD,eAAO,MAAM,gCAAgC,kDAG5C,CAAC;AASF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;IAkDxB,CAAC"}
1
+ {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,yEAA6C,CAAC;AAEvE,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;IAkDxB,CAAC"}
@@ -1,44 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listProducts = exports.mapProductIdToUsdtFutureProduct$ = void 0;
3
+ exports.listProducts = exports.productCache = void 0;
4
+ const data_product_1 = require("@yuants/data-product");
4
5
  const protocol_1 = require("@yuants/protocol");
5
- const sql_1 = require("@yuants/sql");
6
- const rxjs_1 = require("rxjs");
7
- const public_api_1 = require("../../api/public-api");
8
6
  const utils_1 = require("@yuants/utils");
9
- const terminal = protocol_1.Terminal.fromNodeEnv();
10
- const product$ = new rxjs_1.Subject();
11
- const usdtFutureProducts$ = (0, rxjs_1.defer)(() => (0, public_api_1.getFuturesContracts)('usdt', {})).pipe((0, rxjs_1.mergeMap)((contracts) => (0, rxjs_1.from)(contracts).pipe((0, rxjs_1.map)((contract) => {
12
- const [base, quote] = contract.name.split('_');
13
- return {
14
- datasource_id: 'GATE',
15
- product_id: (0, utils_1.encodePath)('GATE', 'FUTURE', contract.name),
16
- base_currency: base,
17
- quote_currency: quote,
18
- value_scale: Number(contract.quanto_multiplier),
19
- price_step: Number(contract.order_price_round),
20
- volume_step: 1,
21
- name: '',
22
- value_scale_unit: '',
23
- margin_rate: 0,
24
- value_based_cost: 0,
25
- volume_based_cost: 0,
26
- max_position: 0,
27
- max_volume: 0,
28
- allow_long: true,
29
- allow_short: true,
30
- market_id: 'GATE/USDT-FUTURE',
31
- no_interest_rate: false,
32
- };
33
- }), (0, rxjs_1.tap)((item) => product$.next(item)), (0, rxjs_1.toArray)())), (0, rxjs_1.repeat)({ delay: 3600000 }), (0, rxjs_1.retry)({ delay: 60000 }), (0, rxjs_1.shareReplay)(1));
34
- usdtFutureProducts$.subscribe();
35
- exports.mapProductIdToUsdtFutureProduct$ = usdtFutureProducts$.pipe((0, rxjs_1.map)((items) => new Map(items.map((item) => [item.product_id, item]))), (0, rxjs_1.shareReplay)(1));
36
- (0, sql_1.createSQLWriter)(terminal, {
37
- data$: product$,
38
- tableName: 'product',
39
- conflictKeys: ['datasource_id', 'product_id'],
40
- writeInterval: 1000,
41
- });
7
+ const public_api_1 = require("../../api/public-api");
8
+ exports.productCache = (0, data_product_1.createProductCache)(protocol_1.Terminal.fromNodeEnv());
42
9
  const listProducts = async () => {
43
10
  const [futureProducts, spotProducts] = await Promise.all([
44
11
  (0, public_api_1.getFuturesContracts)('usdt', {}),
@@ -56,7 +23,7 @@ const listProducts = async () => {
56
23
  volume_step: 1,
57
24
  name: '',
58
25
  value_scale_unit: '',
59
- margin_rate: 0,
26
+ margin_rate: 1 / Number(contract.leverage_max),
60
27
  value_based_cost: 0,
61
28
  volume_based_cost: 0,
62
29
  max_position: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAC5C,qCAA8C;AAC9C,+BAAqG;AACrG,qDAAiF;AACjF,yCAA2C;AAE3C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,QAAQ,GAAG,IAAI,cAAO,EAAY,CAAC;AAEzC,MAAM,mBAAmB,GAAG,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,gCAAmB,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC3E,IAAA,eAAQ,EAAC,CAAC,SAAS,EAAE,EAAE,CACrB,IAAA,WAAI,EAAC,SAAS,CAAC,CAAC,IAAI,CAClB,IAAA,UAAG,EAAC,CAAC,QAAQ,EAAY,EAAE;IACzB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO;QACL,aAAa,EAAE,MAAM;QACrB,UAAU,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC;QACvD,aAAa,EAAE,IAAI;QACnB,cAAc,EAAE,KAAK;QACrB,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC/C,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC9C,W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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 { IProduct } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { defer, from, map, mergeMap, repeat, retry, shareReplay, Subject, tap, toArray } from 'rxjs';\nimport { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';\nimport { encodePath } from '@yuants/utils';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst product$ = new Subject<IProduct>();\n\nconst usdtFutureProducts$ = defer(() => getFuturesContracts('usdt', {})).pipe(\n mergeMap((contracts) =>\n from(contracts).pipe(\n map((contract): IProduct => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n }),\n tap((item) => product$.next(item)),\n toArray(),\n ),\n ),\n repeat({ delay: 3_600_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\nusdtFutureProducts$.subscribe();\n\nexport const mapProductIdToUsdtFutureProduct$ = usdtFutureProducts$.pipe(\n map((items) => new Map(items.map((item) => [item.product_id, item]))),\n shareReplay(1),\n);\n\ncreateSQLWriter(terminal, {\n data$: product$,\n tableName: 'product',\n conflictKeys: ['datasource_id', 'product_id'],\n writeInterval: 1000,\n});\n\nexport const listProducts = async () => {\n const [futureProducts, spotProducts] = await Promise.all([\n getFuturesContracts('usdt', {}),\n getSpotCurrencyPairs(),\n ]);\n const fps = futureProducts.map((contract) => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n const sps = spotProducts.map((spot) => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', spot.id),\n base_currency: spot.base,\n quote_currency: spot.quote,\n value_scale: 1,\n price_step: Number(`1e-${spot.precision}`),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'GATE/USDT-SPOT',\n no_interest_rate: false,\n }));\n\n return [...fps, ...sps];\n};\n"]}
1
+ {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":";;;AAAA,uDAA0D;AAC1D,+CAA4C;AAC5C,yCAA2C;AAC3C,qDAAiF;AAEpE,QAAA,YAAY,GAAG,IAAA,iCAAkB,EAAC,mBAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AAEhE,MAAM,YAA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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 { createProductCache } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFuturesContracts, getSpotCurrencyPairs } from '../../api/public-api';\n\nexport const productCache = createProductCache(Terminal.fromNodeEnv());\n\nexport const listProducts = async () => {\n const [futureProducts, spotProducts] = await Promise.all([\n getFuturesContracts('usdt', {}),\n getSpotCurrencyPairs(),\n ]);\n const fps = futureProducts.map((contract) => {\n const [base, quote] = contract.name.split('_');\n return {\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n base_currency: base,\n quote_currency: quote,\n value_scale: Number(contract.quanto_multiplier),\n price_step: Number(contract.order_price_round),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 1 / Number(contract.leverage_max),\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: true,\n market_id: 'GATE/USDT-FUTURE',\n no_interest_rate: false,\n };\n });\n const sps = spotProducts.map((spot) => ({\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'SPOT', spot.id),\n base_currency: spot.base,\n quote_currency: spot.quote,\n value_scale: 1,\n price_step: Number(`1e-${spot.precision}`),\n volume_step: 1,\n name: '',\n value_scale_unit: '',\n margin_rate: 0,\n value_based_cost: 0,\n volume_based_cost: 0,\n max_position: 0,\n max_volume: 0,\n allow_long: true,\n allow_short: false,\n market_id: 'GATE/USDT-SPOT',\n no_interest_rate: false,\n }));\n\n return [...fps, ...sps];\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=quote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote.d.ts","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":""}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const protocol_1 = require("@yuants/protocol");
4
+ const sql_1 = require("@yuants/sql");
5
+ const utils_1 = require("@yuants/utils");
6
+ const rxjs_1 = require("rxjs");
7
+ const public_api_1 = require("../../api/public-api");
8
+ const terminal = protocol_1.Terminal.fromNodeEnv();
9
+ // 获取所有USDT永续合约
10
+ const usdtFutureContracts$ = (0, rxjs_1.defer)(() => (0, public_api_1.getFuturesContracts)('usdt', {})).pipe((0, rxjs_1.repeat)({ delay: 3600000 }), (0, rxjs_1.retry)({ delay: 60000 }), (0, rxjs_1.shareReplay)(1));
11
+ // 从tickers获取价格和交易量数据
12
+ const quoteFromTickers$ = (0, rxjs_1.defer)(() => (0, public_api_1.getFuturesTickers)('usdt', {})).pipe((0, rxjs_1.mergeMap)((tickers) => tickers), (0, rxjs_1.map)((ticker) => ({
13
+ datasource_id: 'GATE',
14
+ product_id: (0, utils_1.encodePath)('GATE', 'FUTURE', ticker.contract),
15
+ last_price: ticker.last,
16
+ ask_price: ticker.lowest_ask,
17
+ bid_price: ticker.highest_bid,
18
+ // GATE API doesn't provide bid/ask volumes in tickers endpoint
19
+ // We'll need to use order book for that if required
20
+ ask_volume: '0',
21
+ bid_volume: '0',
22
+ // total_size is the open interest
23
+ open_interest: ticker.total_size,
24
+ // funding_rate is the current funding rate
25
+ interest_rate_long: ticker.funding_rate ? `${-parseFloat(ticker.funding_rate)}` : undefined,
26
+ interest_rate_short: ticker.funding_rate,
27
+ })), (0, rxjs_1.repeat)({ delay: 5000 }), (0, rxjs_1.retry)({ delay: 1000 }));
28
+ // 从现货tickers获取价格和交易量数据
29
+ const quoteFromSpotTickers$ = (0, rxjs_1.defer)(() => (0, public_api_1.getSpotTickers)({})).pipe((0, rxjs_1.mergeMap)((tickers) => tickers), (0, rxjs_1.map)((ticker) => {
30
+ var _a, _b;
31
+ return ({
32
+ datasource_id: 'GATE',
33
+ product_id: (0, utils_1.encodePath)('GATE', 'SPOT', ticker.currency_pair),
34
+ last_price: ticker.last,
35
+ ask_price: ticker.lowest_ask,
36
+ bid_price: ticker.highest_bid,
37
+ ask_volume: (_a = ticker.lowest_size) !== null && _a !== void 0 ? _a : '0',
38
+ bid_volume: (_b = ticker.highest_size) !== null && _b !== void 0 ? _b : '0',
39
+ // 现货没有持仓量的概念,设置为0
40
+ open_interest: '0',
41
+ });
42
+ }), (0, rxjs_1.repeat)({ delay: 5000 }), (0, rxjs_1.retry)({ delay: 1000 }));
43
+ const quoteSources$ = [quoteFromTickers$, quoteFromSpotTickers$];
44
+ const quote$ = (0, rxjs_1.defer)(() => (0, rxjs_1.merge)(...quoteSources$.map((x$) => (0, rxjs_1.defer)(() => x$).pipe(
45
+ // 防止单个流关闭导致整体关闭
46
+ (0, rxjs_1.catchError)(() => rxjs_1.EMPTY))))).pipe((0, rxjs_1.groupBy)((x) => (0, utils_1.encodePath)(x.datasource_id, x.product_id)), (0, rxjs_1.mergeMap)((group$) => {
47
+ return group$.pipe(
48
+ //
49
+ (0, rxjs_1.scan)((acc, cur) => Object.assign(acc, cur), {}));
50
+ }), (0, rxjs_1.share)());
51
+ // 写入数据库
52
+ if (process.env.WRITE_QUOTE_TO_SQL === 'true') {
53
+ terminal.channel.publishChannel('quote', { pattern: `^GATE/` }, (channel_id) => {
54
+ const [datasource_id, product_id] = (0, utils_1.decodePath)(channel_id);
55
+ if (!datasource_id) {
56
+ throw 'datasource_id is required';
57
+ }
58
+ if (!product_id) {
59
+ throw 'product_id is required';
60
+ }
61
+ return quote$.pipe((0, rxjs_1.filter)((x) => x.product_id === product_id));
62
+ });
63
+ quote$
64
+ .pipe((0, sql_1.writeToSQL)({
65
+ terminal,
66
+ writeInterval: 1000,
67
+ tableName: 'quote',
68
+ conflictKeys: ['datasource_id', 'product_id'],
69
+ }))
70
+ .subscribe();
71
+ }
72
+ //# sourceMappingURL=quote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":";;AACA,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAmE;AACnE,+BAgBc;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,IAAA,kBAAW,EAAC,CAAC,CAAC,CACf,CAAC;AAEF,qBAAqB;AACrB,MAAM,iBAAiB,GAAG,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,8BAAiB,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CACvE,IAAA,eAAQ,EAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAC9B,IAAA,UAAG,EACD,CAAC,MAAM,EAAmB,EAAE,CAAC,CAAC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,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,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 } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport {\n defer,\n filter,\n from,\n map,\n mergeMap,\n repeat,\n retry,\n shareReplay,\n merge,\n catchError,\n EMPTY,\n groupBy,\n scan,\n share,\n tap,\n} from 'rxjs';\nimport { getFuturesTickers, getFuturesContracts, 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 writeToSQL({\n terminal,\n writeInterval: 1000,\n tableName: 'quote',\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n}\n"]}
@@ -36,10 +36,10 @@ const submitOrder = async (credential, order) => {
36
36
  if (price === undefined) {
37
37
  throw new Error('Limit/Maker order requires price');
38
38
  }
39
- const [, TYPE] = (0, utils_1.decodePath)(order.product_id);
39
+ const [, TYPE, contract] = (0, utils_1.decodePath)(order.product_id);
40
40
  if (TYPE === 'FUTURE') {
41
41
  const res = await (0, private_api_1.postFutureOrders)(credential, 'usdt', {
42
- contract: order.product_id,
42
+ contract,
43
43
  size,
44
44
  price,
45
45
  tif,
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,uDAAsE;AACtE,yCAA2C;AAE3C,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAAe,EAAE;QACvB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,CAAC,CAAC;QACX,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,CAAC,CAAC,CAAC;QACZ;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,eAAe,EAAE,CAAC,CAAC;KACtE;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,UAAmB,EAAU,EAAE;IACjD,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1C,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACnE,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEK,MAAM,WAAW,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;KACvC;IACD,IAAI,C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,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;SACzB;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC;AAnCW,QAAA,WAAW,eAmCtB","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nconst resolveTif = (order_type?: string): string => {\n if (order_type === 'MARKET') return 'ioc';\n if (order_type === 'LIMIT' || order_type === 'MAKER') return 'gtc';\n throw new Error(`Unsupported order_type: ${order_type}`);\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = resolveTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract: order.product_id,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\n};\n"]}
1
+ {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AAM,KAAK,GACT,KAAK,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACjG,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;KACrD;IACD,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxD,IAAI,IAAI,KAAK,QAAQ,EAAE;QACrB,MAAM,GAAG,GAAG,MAAM,IAAA,8BAAgB,EAAC,UAAU,EAAE,MAAM,EAAE;YACrD,QAAQ;YACR,IAAI;YACJ,KAAK;YACL,GAAG;YACH,WAAW;SACZ,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,KAAK,EAAE;YACb,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClF,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;SACzB;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC;AAnCW,QAAA,WAAW,eAmCtB","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nconst resolveTif = (order_type?: string): string => {\n if (order_type === 'MARKET') return 'ioc';\n if (order_type === 'LIMIT' || order_type === 'MAKER') return 'gtc';\n throw new Error(`Unsupported order_type: ${order_type}`);\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = resolveTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE, contract] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-gate",
3
- "version": "0.4.16",
3
+ "version": "0.4.18",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "lib",
@@ -19,6 +19,7 @@
19
19
  "@yuants/data-series": "0.3.51",
20
20
  "@yuants/data-interest-rate": "0.1.48",
21
21
  "@yuants/exchange": "0.3.1",
22
+ "@yuants/data-quote": "0.2.43",
22
23
  "rxjs": "~7.5.6"
23
24
  },
24
25
  "devDependencies": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "apps/vendor-gate/AGENTS.md": "59be8d734f8a91ae5f7377e7c688f1fccb8641b7",
3
- "apps/vendor-gate/CHANGELOG.json": "a25b2712345ad7f05855d41346b053356fa2a44d",
4
- "apps/vendor-gate/CHANGELOG.md": "fc34ccdf2b084f945e8fdc51a3f5df26e91a9849",
3
+ "apps/vendor-gate/CHANGELOG.json": "32fa927ca61f02b55a52aa0894bfe99856d068e5",
4
+ "apps/vendor-gate/CHANGELOG.md": "1ce1276a5e60ca24b2b1add15d57517882c33386",
5
5
  "apps/vendor-gate/README.md": "ea5ee3a61cd87d9104d729902dfaccac9b9913e0",
6
6
  "apps/vendor-gate/SESSION_NOTES.md": "768c89019ebca263968450d853c8038b0d56f619",
7
7
  "apps/vendor-gate/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
@@ -9,26 +9,27 @@
9
9
  "apps/vendor-gate/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
10
10
  "apps/vendor-gate/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
11
11
  "apps/vendor-gate/etc/vendor-gate.api.md": "970682cd589432de553cc5cee2a0abe73814a515",
12
- "apps/vendor-gate/package.json": "5d462aead67e787e044b1687e5938e844399aaa0",
12
+ "apps/vendor-gate/package.json": "c89d41b5bd3da8401aab853dc79b92096085372d",
13
13
  "apps/vendor-gate/src/api/http-client.ts": "013dcdfebaf136c83274638ceb697146a8e3f218",
14
14
  "apps/vendor-gate/src/api/private-api.ts": "644570bc10fd22b7e9d4d6a0267397af9d5510f0",
15
- "apps/vendor-gate/src/api/public-api.ts": "2371d8be290d3c6d373f704b6b10d0cc4dba8af4",
15
+ "apps/vendor-gate/src/api/public-api.ts": "faaad3eeeaa9a32e2b96a38a111878011867bd1e",
16
16
  "apps/vendor-gate/src/api/rate-limiter.ts": "047c51029ffcaf98190cfd04d96816bbced5fa7c",
17
- "apps/vendor-gate/src/index.ts": "0b87307abd7f94126f312c7a02138c158e4de07a",
18
- "apps/vendor-gate/src/services/accounts/future.ts": "840e18154f16ad4a3e265195e39eb02bd90ab237",
17
+ "apps/vendor-gate/src/index.ts": "31888627bccab532d55bd91833d80c72a4afae9b",
18
+ "apps/vendor-gate/src/services/accounts/future.ts": "4e762c193fe8ae4dbe3ae15d45b03bdf0a0fb8c8",
19
19
  "apps/vendor-gate/src/services/accounts/profile.ts": "4132c7c3d9760b9a6694d5b3eae7e8b2847fe6c1",
20
20
  "apps/vendor-gate/src/services/accounts/spot.ts": "b861a4584e73eb181d79ea28ac216747895df086",
21
21
  "apps/vendor-gate/src/services/accounts/unified.ts": "f49b87a161553fd2abcce20ec76f8df3ae98c2bc",
22
22
  "apps/vendor-gate/src/services/default-credential.ts": "b9ffa157b818148450bfaaf4851597e91901190c",
23
23
  "apps/vendor-gate/src/services/exchange.ts": "5672321dea53f8c4592d8d2163de47075ba8fef5",
24
24
  "apps/vendor-gate/src/services/markets/interest-rate.ts": "e669eb1d664448f309bb062907b273157d1c111e",
25
- "apps/vendor-gate/src/services/markets/product.ts": "38f600251ddb0a17e111ccceda9231bee98c60a3",
25
+ "apps/vendor-gate/src/services/markets/product.ts": "64b6c0758e022a0b2c42d69b35bd5d7bd1bfa9c3",
26
+ "apps/vendor-gate/src/services/markets/quote.ts": "1624d58b9c607ae01300de292de3ed49a2f2e037",
26
27
  "apps/vendor-gate/src/services/orders/cancelOrder.ts": "7dfdd30eaac89742f1050bf0fb47d8053ccecb28",
27
28
  "apps/vendor-gate/src/services/orders/listOrders.ts": "9e4bd2c53cd768d609d1368fd37ff783f9b4d52f",
28
- "apps/vendor-gate/src/services/orders/submitOrder.ts": "830e79b7e4c3fa0ea364382c801fa5527c2d9761",
29
+ "apps/vendor-gate/src/services/orders/submitOrder.ts": "321398ad18bb4012d2a40e4f704bc827ccfaff93",
29
30
  "apps/vendor-gate/src/services/transfer.ts": "cf7d6cbcef3fe217b607f0bba7719d62ac603d66",
30
31
  "apps/vendor-gate/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
31
- "apps/vendor-gate/.rush/temp/shrinkwrap-deps.json": "7c7a8a0ba2466ff6bce80aa8e8509d790b2c2d7d",
32
+ "apps/vendor-gate/.rush/temp/shrinkwrap-deps.json": "9aa98bfacea2eaf6aa77491dda2ea7632a0ce879",
32
33
  "libraries/cache/temp/package-deps.json": "a4afa15e6462983f9d3735d31dc1ed8a683fb4dc",
33
34
  "libraries/protocol/temp/package-deps.json": "0bd43721e96039b52d7b59c834dc6df45cf75e3f",
34
35
  "libraries/transfer/temp/package-deps.json": "36c58299bd6c841c5ba7252d71881a881570d08c",
@@ -40,6 +41,7 @@
40
41
  "libraries/data-series/temp/package-deps.json": "c89ebffe302757903aa54eff78f76cb855486b8c",
41
42
  "libraries/data-interest-rate/temp/package-deps.json": "cef1e1cb0116ad593c24635684e0cbf03488d67c",
42
43
  "libraries/exchange/temp/package-deps.json": "ee94ff641b8afcd48484829a1d6d66ffede2a69c",
44
+ "libraries/data-quote/temp/package-deps.json": "34d079eab44d2bf65e07b112ac2099c6e92a015e",
43
45
  "libraries/extension/temp/package-deps.json": "9569c553c2f9a7d50b70d8f101fc2d3825aaccb9",
44
46
  "tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
45
47
  }