@yuants/vendor-gate 0.9.11 → 0.9.13

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 (41) hide show
  1. package/dist/api/private-api.js.map +1 -1
  2. package/dist/services/markets/quote.js +3 -0
  3. package/dist/services/markets/quote.js.map +1 -1
  4. package/dist/services/orders/listOrders.js +2 -0
  5. package/dist/services/orders/listOrders.js.map +1 -1
  6. package/dist/services/orders/mapGateOrderToOrderType.js +10 -0
  7. package/dist/services/orders/mapGateOrderToOrderType.js.map +1 -0
  8. package/dist/services/orders/mapOrderTypeToTif.js +12 -0
  9. package/dist/services/orders/mapOrderTypeToTif.js.map +1 -0
  10. package/dist/services/orders/order-type-mapping.test.js +146 -0
  11. package/dist/services/orders/order-type-mapping.test.js.map +1 -0
  12. package/dist/services/orders/submitOrder.js +2 -8
  13. package/dist/services/orders/submitOrder.js.map +1 -1
  14. package/lib/api/private-api.d.ts +1 -0
  15. package/lib/api/private-api.d.ts.map +1 -1
  16. package/lib/api/private-api.js.map +1 -1
  17. package/lib/services/markets/quote.js +3 -0
  18. package/lib/services/markets/quote.js.map +1 -1
  19. package/lib/services/orders/listOrders.d.ts.map +1 -1
  20. package/lib/services/orders/listOrders.js +2 -0
  21. package/lib/services/orders/listOrders.js.map +1 -1
  22. package/lib/services/orders/mapGateOrderToOrderType.d.ts +5 -0
  23. package/lib/services/orders/mapGateOrderToOrderType.d.ts.map +1 -0
  24. package/lib/services/orders/mapGateOrderToOrderType.js +14 -0
  25. package/lib/services/orders/mapGateOrderToOrderType.js.map +1 -0
  26. package/lib/services/orders/mapOrderTypeToTif.d.ts +2 -0
  27. package/lib/services/orders/mapOrderTypeToTif.d.ts.map +1 -0
  28. package/lib/services/orders/mapOrderTypeToTif.js +16 -0
  29. package/lib/services/orders/mapOrderTypeToTif.js.map +1 -0
  30. package/lib/services/orders/order-type-mapping.test.d.ts +2 -0
  31. package/lib/services/orders/order-type-mapping.test.d.ts.map +1 -0
  32. package/lib/services/orders/order-type-mapping.test.js +148 -0
  33. package/lib/services/orders/order-type-mapping.test.js.map +1 -0
  34. package/lib/services/orders/submitOrder.d.ts.map +1 -1
  35. package/lib/services/orders/submitOrder.js +2 -8
  36. package/lib/services/orders/submitOrder.js.map +1 -1
  37. package/package.json +8 -8
  38. package/temp/build/typescript/ts_Eujh_fX2.json +1 -1
  39. package/temp/package-deps.json +11 -8
  40. package/temp/test/jest/haste-map-ac984f375ffe2771b37aa116ca7fe6f5-87fb4bb14df3d29fb61369ce8cbe1fe1-6499ab22de0ac9ce813ded0e96430273 +0 -0
  41. package/temp/test/jest/perf-cache-ac984f375ffe2771b37aa116ca7fe6f5-da39a3ee5e6b4b0d3255bfef95601890 +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":";;AAAA,mDAAkE;AAClE,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAmE;AACnE,+BAcc;AACd,qDAA8F;AAE9F,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,wBAAwB,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,MAAM,CAAC;AAEpF,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,MAAO,EAAE,CAAC,EAC1B,IAAA,YAAK,EAAC,EAAE,KAAK,EAAE,KAAM,EAAE,CAAC,EACxB,IAAA,kBAAW,EAAC,CAAC,CAAC,CACf,CAAC;AAEF,MAAM,mBAAmB,GAAG,oBAAoB,CAAC,IAAI,CACnD,IAAA,eAAQ,EAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAClC,IAAA,UAAG,EACD,CAAC,QAAQ,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AAE,CAAC,eAAe,EAAE,YAAY,CAAC;KAC9C,CAAC,CACH;SACA,SAAS,EAAE,CAAC;AACjB,CAAC","sourcesContent":["import { IQuote, setMetricsQuoteState } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport {\n catchError,\n defer,\n EMPTY,\n filter,\n groupBy,\n map,\n merge,\n mergeMap,\n repeat,\n retry,\n scan,\n share,\n shareReplay,\n} from 'rxjs';\nimport { getFuturesContracts, getFuturesTickers, getSpotTickers } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst enableQuoteFromContracts = process.env.ENABLE_QUOTE_FROM_CONTRACTS === 'true';\n\n// 获取所有USDT永续合约\nconst usdtFutureContracts$ = defer(() => getFuturesContracts('usdt', {})).pipe(\n repeat({ delay: 300_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\nconst quoteFromContracts$ = usdtFutureContracts$.pipe(\n mergeMap((contracts) => contracts),\n map(\n (contract): Partial<IQuote> => ({\n interest_rate_next_settled_at: contract.funding_next_apply\n ? formatTime(contract.funding_next_apply * 1000)\n : undefined,\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n }),\n ),\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$ = [\n quoteFromTickers$,\n quoteFromSpotTickers$,\n ...(enableQuoteFromContracts ? [quoteFromContracts$] : []),\n];\n\nconst quote$ = defer(() =>\n merge(\n ...quoteSources$.map((x$) =>\n defer(() => x$).pipe(\n // 防止单个流关闭导致整体关闭\n catchError(() => EMPTY),\n ),\n ),\n ),\n).pipe(\n groupBy((x) => encodePath(x.datasource_id, x.product_id)),\n mergeMap((group$) => {\n return group$.pipe(\n //\n scan((acc, cur) => Object.assign(acc, cur), {} as Partial<IQuote>),\n );\n }),\n share(),\n);\n\n// 写入数据库\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n terminal.channel.publishChannel('quote', { pattern: `^GATE/` }, (channel_id) => {\n const [datasource_id, product_id] = decodePath(channel_id);\n if (!datasource_id) {\n throw 'datasource_id is required';\n }\n if (!product_id) {\n throw 'product_id is required';\n }\n return quote$.pipe(filter((x) => x.product_id === product_id));\n });\n quote$\n .pipe(\n setMetricsQuoteState(terminal.terminal_id),\n writeToSQL({\n terminal,\n writeInterval: 1000,\n tableName: 'quote',\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n}\n"]}
1
+ {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"m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AC;AACJ,CAAC,CAAC,EACF,IAAA,YAAK,GAAE,CACR,CAAC;AAEF,QAAQ;AACR,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,EAAE,CAAC;IAC9C,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,UAAU,EAAE,EAAE;QAC7E,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,2BAA2B,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,wBAAwB,CAAC;QACjC,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAA,aAAM,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,MAAM;SACH,IAAI,CACH,IAAA,iCAAoB,EAAC,QAAQ,CAAC,WAAW,CAAC,EAC1C,IAAA,gBAAU,EAAC;QACT,QAAQ;QACR,aAAa,EAAE,IAAI;QACnB,SAAS,EAAE,OAAO;QAClB,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC;KAC9C,CAAC,CACH;SACA,SAAS,EAAE,CAAC;AACjB,CAAC","sourcesContent":["import { IQuote, setMetricsQuoteState } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport {\n catchError,\n defer,\n EMPTY,\n filter,\n groupBy,\n map,\n merge,\n mergeMap,\n repeat,\n retry,\n scan,\n share,\n shareReplay,\n} from 'rxjs';\nimport { getFuturesContracts, getFuturesTickers, getSpotTickers } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst enableQuoteFromContracts = process.env.ENABLE_QUOTE_FROM_CONTRACTS === 'true';\n\n// 获取所有USDT永续合约\nconst usdtFutureContracts$ = defer(() => getFuturesContracts('usdt', {})).pipe(\n repeat({ delay: 300_000 }),\n retry({ delay: 60_000 }),\n shareReplay(1),\n);\n\nconst quoteFromContracts$ = usdtFutureContracts$.pipe(\n mergeMap((contracts) => contracts),\n map(\n (contract): Partial<IQuote> => ({\n interest_rate_settlement_interval: contract.funding_interval\n ? `${contract.funding_interval * 1000}`\n : undefined,\n interest_rate_next_settled_at: contract.funding_next_apply\n ? formatTime(contract.funding_next_apply * 1000)\n : undefined,\n datasource_id: 'GATE',\n product_id: encodePath('GATE', 'FUTURE', contract.name),\n }),\n ),\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$ = [\n quoteFromTickers$,\n quoteFromSpotTickers$,\n ...(enableQuoteFromContracts ? [quoteFromContracts$] : []),\n];\n\nconst quote$ = defer(() =>\n merge(\n ...quoteSources$.map((x$) =>\n defer(() => x$).pipe(\n // 防止单个流关闭导致整体关闭\n catchError(() => EMPTY),\n ),\n ),\n ),\n).pipe(\n groupBy((x) => encodePath(x.datasource_id, x.product_id)),\n mergeMap((group$) => {\n return group$.pipe(\n //\n scan((acc, cur) => Object.assign(acc, cur), {} as Partial<IQuote>),\n );\n }),\n share(),\n);\n\n// 写入数据库\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n terminal.channel.publishChannel('quote', { pattern: `^GATE/` }, (channel_id) => {\n const [datasource_id, product_id] = decodePath(channel_id);\n if (!datasource_id) {\n throw 'datasource_id is required';\n }\n if (!product_id) {\n throw 'product_id is required';\n }\n return quote$.pipe(filter((x) => x.product_id === product_id));\n });\n quote$\n .pipe(\n setMetricsQuoteState(terminal.terminal_id),\n writeToSQL({\n terminal,\n writeInterval: 1000,\n tableName: 'quote',\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAoB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAatE,eAAO,MAAM,UAAU,GAAU,YAAY,WAAW,sBAsBvD,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,YAAY,WAAW,EACvB,YAAY,MAAM,KACjB,OAAO,CAAC,MAAM,EAAE,CAWlB,CAAC"}
1
+ {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAoB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AActE,eAAO,MAAM,UAAU,GAAU,YAAY,WAAW,sBAuBvD,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,YAAY,WAAW,EACvB,YAAY,MAAM,KACjB,OAAO,CAAC,MAAM,EAAE,CAWlB,CAAC"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getOrdersByProductId = exports.listOrders = void 0;
4
4
  const private_api_1 = require("../../api/private-api");
5
5
  const utils_1 = require("@yuants/utils");
6
+ const mapGateOrderToOrderType_1 = require("./mapGateOrderToOrderType");
6
7
  const resolveOrderDirection = (order) => {
7
8
  const isLong = order.size > 0;
8
9
  if (order.is_close) {
@@ -31,6 +32,7 @@ const listOrders = async (credential) => {
31
32
  traded_volume,
32
33
  traded_price: Number.isFinite(traded_price) ? traded_price : undefined,
33
34
  order_status: order.status,
35
+ order_type: (0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)(order),
34
36
  };
35
37
  });
36
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,uDAAsE;AACtE,yCAAqD;AAIrD,MAAM,qBAAqB,GAAG,CAAC,KAA0C,EAAkB,EAAE;IAC3F,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC;IAC/C,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;AAC7C,CAAC,CAAC;AAEK,MAAM,UAAU,GAAG,KAAK,EAAE,UAAuB,E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YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;YACtE,YAAY,EAAE,KAAK,CAAC,MAAM;SAC3B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAtBW,QAAA,UAAU,cAsBrB;AAEK,MAAM,oBAAoB,GAAG,KAAK,WACvC,UAAuB,EACvB,UAAkB;IAElB,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,sBAAsB;IACpE,6BAA6B;IAC7B,qDAAqD;IACrD,sEAAsE;IACtE,IAAI;IACJ,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,MAAM,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;QAC5C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IACnE,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;AACvD,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { getFuturesOrders, ICredential } from '../../api/private-api';\nimport { decodePath, newError } from '@yuants/utils';\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\nconst resolveOrderDirection = (order: { size: number; is_close: boolean }): OrderDirection => {\n const isLong = order.size > 0;\n if (order.is_close) {\n return isLong ? 'CLOSE_SHORT' : 'CLOSE_LONG';\n }\n return isLong ? 'OPEN_LONG' : 'OPEN_SHORT';\n};\n\nexport const listOrders = async (credential: ICredential) => {\n const orders = await getFuturesOrders(credential, 'usdt', { status: 'open' });\n if (Array.isArray(orders) === false) throw newError('InvalidResponse', { orders });\n return orders.map((order): IOrder => {\n const volume = Math.abs(order.size);\n const leftVolume = typeof order.left === 'number' ? Math.abs(order.left) : undefined;\n const traded_volume = leftVolume !== undefined ? Math.max(volume - leftVolume, 0) : undefined;\n const price = Number(order.price);\n const traded_price = Number(order.fill_price);\n return {\n order_id: `${order.id}`,\n account_id: '',\n product_id: order.contract,\n order_direction: resolveOrderDirection(order),\n volume,\n price: Number.isFinite(price) ? price : undefined,\n submit_at: order.create_time * 1000,\n traded_volume,\n traded_price: Number.isFinite(traded_price) ? traded_price : undefined,\n order_status: order.status,\n };\n });\n};\n\nexport const getOrdersByProductId = async function (\n credential: ICredential,\n product_id: string,\n): Promise<IOrder[]> {\n const [_, instType] = decodePath(product_id); // GATE/FUTURE/ADAUSDT\n // if (instType === 'SPOT') {\n // const orders = await listSpotOrders(credential);\n // return orders.filter((order) => order.product_id === product_id);\n // }\n if (instType === 'FUTURE') {\n const orders = await listOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n};\n"]}
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,uDAAsE;AACtE,yCAAqD;AACrD,uEAAoE;AAIpE,MAAM,qBAAqB,GAAG,CAAC,KAA0C,EAAkB,EAAE;IAC3F,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC;IAC/C,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;AAC7C,CAAC,CAAC;AAEK,MAAM,UAAU,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAC1D,MAAM,MAAM,GAAG,MAAM,IAAA,8BAAgB,EAAC,UAAU,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAA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uB,EAAC,KAAK,CAAC;SAC3C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAvBW,QAAA,UAAU,cAuBrB;AAEK,MAAM,oBAAoB,GAAG,KAAK,WACvC,UAAuB,EACvB,UAAkB;IAElB,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,sBAAsB;IACpE,6BAA6B;IAC7B,qDAAqD;IACrD,sEAAsE;IACtE,IAAI;IACJ,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,MAAM,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;QAC5C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IACnE,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;AACvD,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { getFuturesOrders, ICredential } from '../../api/private-api';\nimport { decodePath, newError } from '@yuants/utils';\nimport { mapGateOrderToOrderType } from './mapGateOrderToOrderType';\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\nconst resolveOrderDirection = (order: { size: number; is_close: boolean }): OrderDirection => {\n const isLong = order.size > 0;\n if (order.is_close) {\n return isLong ? 'CLOSE_SHORT' : 'CLOSE_LONG';\n }\n return isLong ? 'OPEN_LONG' : 'OPEN_SHORT';\n};\n\nexport const listOrders = async (credential: ICredential) => {\n const orders = await getFuturesOrders(credential, 'usdt', { status: 'open' });\n if (Array.isArray(orders) === false) throw newError('InvalidResponse', { orders });\n return orders.map((order): IOrder => {\n const volume = Math.abs(order.size);\n const leftVolume = typeof order.left === 'number' ? Math.abs(order.left) : undefined;\n const traded_volume = leftVolume !== undefined ? Math.max(volume - leftVolume, 0) : undefined;\n const price = Number(order.price);\n const traded_price = Number(order.fill_price);\n return {\n order_id: `${order.id}`,\n account_id: '',\n product_id: order.contract,\n order_direction: resolveOrderDirection(order),\n volume,\n price: Number.isFinite(price) ? price : undefined,\n submit_at: order.create_time * 1000,\n traded_volume,\n traded_price: Number.isFinite(traded_price) ? traded_price : undefined,\n order_status: order.status,\n order_type: mapGateOrderToOrderType(order),\n };\n });\n};\n\nexport const getOrdersByProductId = async function (\n credential: ICredential,\n product_id: string,\n): Promise<IOrder[]> {\n const [_, instType] = decodePath(product_id); // GATE/FUTURE/ADAUSDT\n // if (instType === 'SPOT') {\n // const orders = await listSpotOrders(credential);\n // return orders.filter((order) => order.product_id === product_id);\n // }\n if (instType === 'FUTURE') {\n const orders = await listOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n};\n"]}
@@ -0,0 +1,5 @@
1
+ export declare const mapGateOrderToOrderType: (order: {
2
+ tif?: string;
3
+ price?: string;
4
+ }) => "FOK" | "MARKET" | "IOC" | undefined;
5
+ //# sourceMappingURL=mapGateOrderToOrderType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapGateOrderToOrderType.d.ts","sourceRoot":"","sources":["../../../src/services/orders/mapGateOrderToOrderType.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,GAAI,OAAO;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,yCAO9E,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapGateOrderToOrderType = void 0;
4
+ const mapGateOrderToOrderType = (order) => {
5
+ if (order.tif === 'fok')
6
+ return 'FOK';
7
+ if (order.tif === 'ioc') {
8
+ return Number(order.price) === 0 ? 'MARKET' : 'IOC';
9
+ }
10
+ // Gate does not expose enough stable data here to distinguish gtc as LIMIT vs MAKER.
11
+ return undefined;
12
+ };
13
+ exports.mapGateOrderToOrderType = mapGateOrderToOrderType;
14
+ //# sourceMappingURL=mapGateOrderToOrderType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapGateOrderToOrderType.js","sourceRoot":"","sources":["../../../src/services/orders/mapGateOrderToOrderType.ts"],"names":[],"mappings":";;;AAAO,MAAM,uBAAuB,GAAG,CAAC,KAAuC,EAAE,EAAE;IACjF,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;IACtD,CAAC;IACD,qFAAqF;IACrF,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAPW,QAAA,uBAAuB,2BAOlC","sourcesContent":["export const mapGateOrderToOrderType = (order: { tif?: string; price?: string }) => {\n if (order.tif === 'fok') return 'FOK';\n if (order.tif === 'ioc') {\n return Number(order.price) === 0 ? 'MARKET' : 'IOC';\n }\n // Gate does not expose enough stable data here to distinguish gtc as LIMIT vs MAKER.\n return undefined;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const mapOrderTypeToTif: (orderType?: string) => string;
2
+ //# sourceMappingURL=mapOrderTypeToTif.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOrderTypeToTif.d.ts","sourceRoot":"","sources":["../../../src/services/orders/mapOrderTypeToTif.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,KAAG,MAMtD,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapOrderTypeToTif = void 0;
4
+ const mapOrderTypeToTif = (orderType) => {
5
+ if (orderType === 'MARKET')
6
+ return 'ioc';
7
+ if (orderType === 'LIMIT' || orderType === 'MAKER')
8
+ return 'gtc';
9
+ if (orderType === 'IOC')
10
+ return 'ioc';
11
+ if (orderType === 'FOK')
12
+ return 'fok';
13
+ throw new Error(`Unsupported order_type: ${orderType}`);
14
+ };
15
+ exports.mapOrderTypeToTif = mapOrderTypeToTif;
16
+ //# sourceMappingURL=mapOrderTypeToTif.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOrderTypeToTif.js","sourceRoot":"","sources":["../../../src/services/orders/mapOrderTypeToTif.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAAC,SAAkB,EAAU,EAAE;IAC9D,IAAI,SAAS,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,SAAS,KAAK,OAAO,IAAI,SAAS,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACjE,IAAI,SAAS,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,SAAS,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,IAAI,KAAK,CAAC,2BAA2B,SAAS,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B","sourcesContent":["export const mapOrderTypeToTif = (orderType?: string): string => {\n if (orderType === 'MARKET') return 'ioc';\n if (orderType === 'LIMIT' || orderType === 'MAKER') return 'gtc';\n if (orderType === 'IOC') return 'ioc';\n if (orderType === 'FOK') return 'fok';\n throw new Error(`Unsupported order_type: ${orderType}`);\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=order-type-mapping.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-type-mapping.test.d.ts","sourceRoot":"","sources":["../../../src/services/orders/order-type-mapping.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mapGateOrderToOrderType_1 = require("./mapGateOrderToOrderType");
4
+ const mapOrderTypeToTif_1 = require("./mapOrderTypeToTif");
5
+ jest.mock('../../api/private-api', () => ({
6
+ getFuturesOrders: jest.fn(async () => []),
7
+ postFutureOrders: jest.fn(async (_credential, _settle, payload) => (Object.assign({ id: 'mock-order-id' }, payload))),
8
+ }));
9
+ const { getFuturesOrders, postFutureOrders } = jest.requireMock('../../api/private-api');
10
+ const { listOrders } = require('./listOrders');
11
+ const { submitOrder } = require('./submitOrder');
12
+ const baseOrder = {
13
+ account_id: 'gate/test/future/USDT',
14
+ product_id: 'GATE/FUTURE/BTC_USDT',
15
+ order_direction: 'OPEN_LONG',
16
+ volume: 1,
17
+ };
18
+ describe('mapOrderTypeToTif', () => {
19
+ test('maps IOC and FOK to Gate tif values', () => {
20
+ expect((0, mapOrderTypeToTif_1.mapOrderTypeToTif)('IOC')).toBe('ioc');
21
+ expect((0, mapOrderTypeToTif_1.mapOrderTypeToTif)('FOK')).toBe('fok');
22
+ });
23
+ });
24
+ describe('mapGateOrderToOrderType', () => {
25
+ test('maps Gate tif and price to Yuan order types', () => {
26
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'ioc', price: '0' })).toBe('MARKET');
27
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'ioc', price: '12345' })).toBe('IOC');
28
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'fok', price: '12345' })).toBe('FOK');
29
+ });
30
+ test('returns undefined when Gate tif cannot be mapped reliably', () => {
31
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'gtc', price: '12345' })).toBeUndefined();
32
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'poc', price: '12345' })).toBeUndefined();
33
+ });
34
+ });
35
+ describe('submitOrder order type mapping', () => {
36
+ beforeEach(() => {
37
+ postFutureOrders.mockClear();
38
+ });
39
+ test('forwards IOC with tif=ioc and keeps the real price', async () => {
40
+ await submitOrder({}, Object.assign(Object.assign({}, baseOrder), { order_type: 'IOC', price: 12345 }));
41
+ expect(postFutureOrders).toHaveBeenCalledWith(expect.anything(), 'usdt', expect.objectContaining({
42
+ tif: 'ioc',
43
+ price: '12345',
44
+ }));
45
+ });
46
+ test('forwards FOK with tif=fok and keeps the real price', async () => {
47
+ await submitOrder({}, Object.assign(Object.assign({}, baseOrder), { order_type: 'FOK', price: 12345 }));
48
+ expect(postFutureOrders).toHaveBeenCalledWith(expect.anything(), 'usdt', expect.objectContaining({
49
+ tif: 'fok',
50
+ price: '12345',
51
+ }));
52
+ });
53
+ test('still sends market orders with price=0', async () => {
54
+ await submitOrder({}, Object.assign(Object.assign({}, baseOrder), { order_type: 'MARKET' }));
55
+ expect(postFutureOrders).toHaveBeenCalledWith(expect.anything(), 'usdt', expect.objectContaining({
56
+ tif: 'ioc',
57
+ price: '0',
58
+ }));
59
+ });
60
+ });
61
+ describe('listOrders order type mapping', () => {
62
+ beforeEach(() => {
63
+ getFuturesOrders.mockClear();
64
+ });
65
+ test('adds order_type without changing representative listOrders fields', async () => {
66
+ getFuturesOrders.mockResolvedValueOnce([
67
+ {
68
+ id: 'market-order',
69
+ contract: 'GATE/FUTURE/BTC_USDT',
70
+ size: 1,
71
+ left: 1,
72
+ price: '0',
73
+ fill_price: '0',
74
+ tif: 'ioc',
75
+ is_close: false,
76
+ create_time: 1,
77
+ status: 'open',
78
+ },
79
+ {
80
+ id: 'ioc-order',
81
+ contract: 'GATE/FUTURE/BTC_USDT',
82
+ size: -2,
83
+ left: -1,
84
+ price: '12345',
85
+ fill_price: '12340',
86
+ tif: 'ioc',
87
+ is_close: true,
88
+ create_time: 2,
89
+ status: 'open',
90
+ },
91
+ {
92
+ id: 'fok-order',
93
+ contract: 'GATE/FUTURE/BTC_USDT',
94
+ size: 3,
95
+ left: 0,
96
+ price: '12345',
97
+ fill_price: '12346',
98
+ tif: 'fok',
99
+ is_close: false,
100
+ create_time: 3,
101
+ status: 'open',
102
+ },
103
+ ]);
104
+ const orders = await listOrders({});
105
+ expect(orders).toEqual([
106
+ {
107
+ order_id: 'market-order',
108
+ account_id: '',
109
+ product_id: 'GATE/FUTURE/BTC_USDT',
110
+ order_direction: 'OPEN_LONG',
111
+ volume: 1,
112
+ price: 0,
113
+ traded_price: 0,
114
+ order_status: 'open',
115
+ traded_volume: 0,
116
+ submit_at: 1000,
117
+ order_type: 'MARKET',
118
+ },
119
+ {
120
+ order_id: 'ioc-order',
121
+ account_id: '',
122
+ product_id: 'GATE/FUTURE/BTC_USDT',
123
+ order_direction: 'CLOSE_LONG',
124
+ volume: 2,
125
+ price: 12345,
126
+ traded_price: 12340,
127
+ order_status: 'open',
128
+ traded_volume: 1,
129
+ submit_at: 2000,
130
+ order_type: 'IOC',
131
+ },
132
+ {
133
+ order_id: 'fok-order',
134
+ account_id: '',
135
+ product_id: 'GATE/FUTURE/BTC_USDT',
136
+ order_direction: 'OPEN_LONG',
137
+ volume: 3,
138
+ price: 12345,
139
+ traded_price: 12346,
140
+ order_status: 'open',
141
+ traded_volume: 3,
142
+ submit_at: 3000,
143
+ order_type: 'FOK',
144
+ },
145
+ ]);
146
+ });
147
+ });
148
+ //# sourceMappingURL=order-type-mapping.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-type-mapping.test.js","sourceRoot":"","sources":["../../../src/services/orders/order-type-mapping.test.ts"],"names":[],"mappings":";;AAAA,uEAAoE;AACpE,2DAAwD;AAExD,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,gBAAgB,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;IACzC,gBAAgB,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,iBACjE,EAAE,EAAE,eAAe,IA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,CAAC,CAAC,CAAC","sourcesContent":["import { mapGateOrderToOrderType } from './mapGateOrderToOrderType';\nimport { mapOrderTypeToTif } from './mapOrderTypeToTif';\n\njest.mock('../../api/private-api', () => ({\n getFuturesOrders: jest.fn(async () => []),\n postFutureOrders: jest.fn(async (_credential, _settle, payload) => ({\n id: 'mock-order-id',\n ...payload,\n })),\n}));\n\nconst { getFuturesOrders, postFutureOrders } = jest.requireMock('../../api/private-api') as {\n getFuturesOrders: jest.Mock;\n postFutureOrders: jest.Mock;\n};\n\nconst { listOrders } = require('./listOrders') as typeof import('./listOrders');\nconst { submitOrder } = require('./submitOrder') as typeof import('./submitOrder');\n\nconst baseOrder = {\n account_id: 'gate/test/future/USDT',\n product_id: 'GATE/FUTURE/BTC_USDT',\n order_direction: 'OPEN_LONG' as const,\n volume: 1,\n};\n\ndescribe('mapOrderTypeToTif', () => {\n test('maps IOC and FOK to Gate tif values', () => {\n expect(mapOrderTypeToTif('IOC')).toBe('ioc');\n expect(mapOrderTypeToTif('FOK')).toBe('fok');\n });\n});\n\ndescribe('mapGateOrderToOrderType', () => {\n test('maps Gate tif and price to Yuan order types', () => {\n expect(mapGateOrderToOrderType({ tif: 'ioc', price: '0' })).toBe('MARKET');\n expect(mapGateOrderToOrderType({ tif: 'ioc', price: '12345' })).toBe('IOC');\n expect(mapGateOrderToOrderType({ tif: 'fok', price: '12345' })).toBe('FOK');\n });\n\n test('returns undefined when Gate tif cannot be mapped reliably', () => {\n expect(mapGateOrderToOrderType({ tif: 'gtc', price: '12345' })).toBeUndefined();\n expect(mapGateOrderToOrderType({ tif: 'poc', price: '12345' })).toBeUndefined();\n });\n});\n\ndescribe('submitOrder order type mapping', () => {\n beforeEach(() => {\n postFutureOrders.mockClear();\n });\n\n test('forwards IOC with tif=ioc and keeps the real price', async () => {\n await submitOrder({} as never, {\n ...baseOrder,\n order_type: 'IOC',\n price: 12345,\n });\n\n expect(postFutureOrders).toHaveBeenCalledWith(\n expect.anything(),\n 'usdt',\n expect.objectContaining({\n tif: 'ioc',\n price: '12345',\n }),\n );\n });\n\n test('forwards FOK with tif=fok and keeps the real price', async () => {\n await submitOrder({} as never, {\n ...baseOrder,\n order_type: 'FOK',\n price: 12345,\n });\n\n expect(postFutureOrders).toHaveBeenCalledWith(\n expect.anything(),\n 'usdt',\n expect.objectContaining({\n tif: 'fok',\n price: '12345',\n }),\n );\n });\n\n test('still sends market orders with price=0', async () => {\n await submitOrder({} as never, {\n ...baseOrder,\n order_type: 'MARKET',\n });\n\n expect(postFutureOrders).toHaveBeenCalledWith(\n expect.anything(),\n 'usdt',\n expect.objectContaining({\n tif: 'ioc',\n price: '0',\n }),\n );\n });\n});\n\ndescribe('listOrders order type mapping', () => {\n beforeEach(() => {\n getFuturesOrders.mockClear();\n });\n\n test('adds order_type without changing representative listOrders fields', async () => {\n getFuturesOrders.mockResolvedValueOnce([\n {\n id: 'market-order',\n contract: 'GATE/FUTURE/BTC_USDT',\n size: 1,\n left: 1,\n price: '0',\n fill_price: '0',\n tif: 'ioc',\n is_close: false,\n create_time: 1,\n status: 'open',\n },\n {\n id: 'ioc-order',\n contract: 'GATE/FUTURE/BTC_USDT',\n size: -2,\n left: -1,\n price: '12345',\n fill_price: '12340',\n tif: 'ioc',\n is_close: true,\n create_time: 2,\n status: 'open',\n },\n {\n id: 'fok-order',\n contract: 'GATE/FUTURE/BTC_USDT',\n size: 3,\n left: 0,\n price: '12345',\n fill_price: '12346',\n tif: 'fok',\n is_close: false,\n create_time: 3,\n status: 'open',\n },\n ]);\n\n const orders = await listOrders({} as never);\n\n expect(orders).toEqual([\n {\n order_id: 'market-order',\n account_id: '',\n product_id: 'GATE/FUTURE/BTC_USDT',\n order_direction: 'OPEN_LONG',\n volume: 1,\n price: 0,\n traded_price: 0,\n order_status: 'open',\n traded_volume: 0,\n submit_at: 1000,\n order_type: 'MARKET',\n },\n {\n order_id: 'ioc-order',\n account_id: '',\n product_id: 'GATE/FUTURE/BTC_USDT',\n order_direction: 'CLOSE_LONG',\n volume: 2,\n price: 12345,\n traded_price: 12340,\n order_status: 'open',\n traded_volume: 1,\n submit_at: 2000,\n order_type: 'IOC',\n },\n {\n order_id: 'fok-order',\n account_id: '',\n product_id: 'GATE/FUTURE/BTC_USDT',\n order_direction: 'OPEN_LONG',\n volume: 3,\n price: 12345,\n traded_price: 12346,\n order_status: 'open',\n traded_volume: 3,\n submit_at: 3000,\n order_type: 'FOK',\n },\n ]);\n });\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAoB,MAAM,uBAAuB,CAAC;AAsBtE,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAmChE,CAAC"}
1
+ {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAoB,MAAM,uBAAuB,CAAC;AAiBtE,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAmChE,CAAC"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.submitOrder = void 0;
4
4
  const private_api_1 = require("../../api/private-api");
5
5
  const utils_1 = require("@yuants/utils");
6
+ const mapOrderTypeToTif_1 = require("./mapOrderTypeToTif");
6
7
  const resolveSizeSign = (order_direction) => {
7
8
  switch (order_direction) {
8
9
  case 'OPEN_LONG':
@@ -15,13 +16,6 @@ const resolveSizeSign = (order_direction) => {
15
16
  throw new Error(`Unsupported order_direction: ${order_direction}`);
16
17
  }
17
18
  };
18
- const resolveTif = (order_type) => {
19
- if (order_type === 'MARKET')
20
- return 'ioc';
21
- if (order_type === 'LIMIT' || order_type === 'MAKER')
22
- return 'gtc';
23
- throw new Error(`Unsupported order_type: ${order_type}`);
24
- };
25
19
  const submitOrder = async (credential, order) => {
26
20
  if (!order.product_id) {
27
21
  throw new Error('Missing product_id');
@@ -30,7 +24,7 @@ const submitOrder = async (credential, order) => {
30
24
  throw new Error('Invalid order volume');
31
25
  }
32
26
  const size = order.volume * resolveSizeSign(order.order_direction);
33
- const tif = resolveTif(order.order_type);
27
+ const tif = (0, mapOrderTypeToTif_1.mapOrderTypeToTif)(order.order_type);
34
28
  const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';
35
29
  const price = order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;
36
30
  if (price === undefined) {
@@ -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,CAAC;QACxB,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;IACvE,CAAC;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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AG,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;QAC1B,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;IACJ,CAAC;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"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,uDAAsE;AACtE,yCAA2C;AAC3C,2DAAwD;AAExD,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAAe,EAAE,CAAC;QACxB,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;IACvE,CAAC;AACH,CAAC,CAAC;AAEK,MAAM,WAAW,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC/F,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACnE,MAAM,GAAG,GAAG,IAAA,qCAAiB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,WAAW,GAAG,KAAK,CAAC,eAAe,KAAK,YAAY,IAAI,KAAK,CAAC,eAAe,KAAK,aAAa,CAAC;IACtG,MAAM,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,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,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,CAAC;YACd,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;QAC1B,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;IACJ,CAAC;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';\nimport { mapOrderTypeToTif } from './mapOrderTypeToTif';\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\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 = mapOrderTypeToTif(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.9.11",
3
+ "version": "0.9.13",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "lib",
@@ -12,18 +12,18 @@
12
12
  "@yuants/cache": "0.3.15",
13
13
  "@yuants/protocol": "0.55.0",
14
14
  "@yuants/transfer": "0.2.52",
15
- "@yuants/data-order": "0.7.13",
16
15
  "@yuants/data-account": "0.11.12",
17
- "@yuants/data-ohlc": "0.6.8",
18
- "@yuants/utils": "0.19.7",
16
+ "@yuants/data-order": "0.7.13",
19
17
  "@yuants/data-trade": "0.1.38",
20
18
  "@yuants/sql": "0.9.43",
21
- "@yuants/http-services": "0.5.3",
19
+ "@yuants/data-ohlc": "0.6.8",
22
20
  "@yuants/data-product": "0.5.13",
23
- "@yuants/data-series": "0.3.65",
21
+ "@yuants/utils": "0.19.7",
22
+ "@yuants/http-services": "0.5.3",
24
23
  "@yuants/data-interest-rate": "0.2.13",
25
- "@yuants/data-quote": "0.4.12",
26
- "@yuants/exchange": "0.8.23"
24
+ "@yuants/exchange": "0.8.23",
25
+ "@yuants/data-series": "0.3.65",
26
+ "@yuants/data-quote": "0.4.12"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@microsoft/api-extractor": "~7.55.2",