@yuants/vendor-okx 0.28.4 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/experimental/exchange.js +3 -3
  2. package/dist/experimental/exchange.js.map +1 -1
  3. package/dist/orders/cancelOrder.js +1 -1
  4. package/dist/orders/cancelOrder.js.map +1 -1
  5. package/dist/orders/modifyOrder.js +1 -1
  6. package/dist/orders/modifyOrder.js.map +1 -1
  7. package/dist/orders/submitOrder.js +2 -1
  8. package/dist/orders/submitOrder.js.map +1 -1
  9. package/dist/services.js +2 -1
  10. package/dist/services.js.map +1 -1
  11. package/lib/experimental/exchange.js +3 -3
  12. package/lib/experimental/exchange.js.map +1 -1
  13. package/lib/orders/cancelOrder.js +1 -1
  14. package/lib/orders/cancelOrder.js.map +1 -1
  15. package/lib/orders/modifyOrder.js +1 -1
  16. package/lib/orders/modifyOrder.js.map +1 -1
  17. package/lib/orders/submitOrder.d.ts.map +1 -1
  18. package/lib/orders/submitOrder.js +2 -1
  19. package/lib/orders/submitOrder.js.map +1 -1
  20. package/lib/services.js +2 -1
  21. package/lib/services.js.map +1 -1
  22. package/package.json +1 -1
  23. package/temp/package-deps.json +8 -11
  24. package/dist/experimental/cancelOrder.js +0 -13
  25. package/dist/experimental/cancelOrder.js.map +0 -1
  26. package/dist/experimental/modifyOrder.js +0 -58
  27. package/dist/experimental/modifyOrder.js.map +0 -1
  28. package/dist/experimental/submitOrder.js +0 -109
  29. package/dist/experimental/submitOrder.js.map +0 -1
  30. package/lib/experimental/cancelOrder.d.ts +0 -4
  31. package/lib/experimental/cancelOrder.d.ts.map +0 -1
  32. package/lib/experimental/cancelOrder.js +0 -17
  33. package/lib/experimental/cancelOrder.js.map +0 -1
  34. package/lib/experimental/modifyOrder.d.ts +0 -4
  35. package/lib/experimental/modifyOrder.d.ts.map +0 -1
  36. package/lib/experimental/modifyOrder.js +0 -62
  37. package/lib/experimental/modifyOrder.js.map +0 -1
  38. package/lib/experimental/submitOrder.d.ts +0 -6
  39. package/lib/experimental/submitOrder.d.ts.map +0 -1
  40. package/lib/experimental/submitOrder.js +0 -113
  41. package/lib/experimental/submitOrder.js.map +0 -1
@@ -2,12 +2,12 @@ import { provideExchangeServices } from '@yuants/exchange';
2
2
  import { Terminal } from '@yuants/protocol';
3
3
  import { encodePath, newError } from '@yuants/utils';
4
4
  import { getAccountConfig } from '../api/private-api';
5
- import { cancelOrder } from './cancelOrder';
5
+ import { cancelOrder } from '../orders/cancelOrder';
6
+ import { modifyOrder } from '../orders/modifyOrder';
7
+ import { submitOrder } from '../orders/submitOrder';
6
8
  import { getOrders } from './getOrders';
7
9
  import { getPositions } from './getPositions';
8
- import { modifyOrder } from './modifyOrder';
9
10
  import { listProducts } from './product';
10
- import { submitOrder } from './submitOrder';
11
11
  const terminal = Terminal.fromNodeEnv();
12
12
  provideExchangeServices(terminal, {
13
13
  name: 'OKX',
@@ -1 +1 @@
1
- {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/experimental/exchange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,QAAQ,GAAG,QAAQ,CAAC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UAAU,CAAC,CAAC;IAC3D,CAAC;IACD,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,WAAW;CACzB,CAAC,CAAC","sourcesContent":["import { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath, newError } from '@yuants/utils';\nimport { getAccountConfig, ICredential } from '../api/private-api';\nimport { cancelOrder } from './cancelOrder';\nimport { getOrders } from './getOrders';\nimport { getPositions } from './getPositions';\nimport { modifyOrder } from './modifyOrder';\nimport { listProducts } from './product';\nimport { submitOrder } from './submitOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'OKX',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key', 'passphrase'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n passphrase: { type: 'string' },\n },\n },\n getCredentialId: async function (credential: ICredential): Promise<string> {\n const accountConfig = await getAccountConfig(credential);\n const uid = accountConfig.data?.[0]?.uid;\n if (!uid) throw newError('OKX_CREDENTIAL_INVALID', { credential });\n return encodePath('OKX', uid);\n },\n listProducts: listProducts,\n getPositions: getPositions,\n getOrders,\n getPositionsByProductId: async (credential, product_id) => {\n const positions = await getPositions(credential);\n return positions.filter((x) => x.product_id === product_id);\n },\n getOrdersByProductId: async (credential, product_id) => {\n const orders = await getOrders(credential);\n return orders.filter((x) => x.product_id === product_id);\n },\n submitOrder: submitOrder,\n modifyOrder: modifyOrder,\n cancelOrder: cancelOrder,\n});\n"]}
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/experimental/exchange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,gBAAg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M,YAAY,CAAC,UAAU,CAAC,CAAC;QACjD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IAC9D,CAAC;IACD,oBAAoB,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;QACrD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IAC3D,CAAC;IACD,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,WAAW;CACzB,CAAC,CAAC","sourcesContent":["import { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath, newError } from '@yuants/utils';\nimport { getAccountConfig, ICredential } from '../api/private-api';\nimport { cancelOrder } from '../orders/cancelOrder';\nimport { modifyOrder } from '../orders/modifyOrder';\nimport { submitOrder } from '../orders/submitOrder';\nimport { getOrders } from './getOrders';\nimport { getPositions } from './getPositions';\nimport { listProducts } from './product';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'OKX',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key', 'passphrase'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n passphrase: { type: 'string' },\n },\n },\n getCredentialId: async function (credential: ICredential): Promise<string> {\n const accountConfig = await getAccountConfig(credential);\n const uid = accountConfig.data?.[0]?.uid;\n if (!uid) throw newError('OKX_CREDENTIAL_INVALID', { credential });\n return encodePath('OKX', uid);\n },\n listProducts: listProducts,\n getPositions: getPositions,\n getOrders,\n getPositionsByProductId: async (credential, product_id) => {\n const positions = await getPositions(credential);\n return positions.filter((x) => x.product_id === product_id);\n },\n getOrdersByProductId: async (credential, product_id) => {\n const orders = await getOrders(credential);\n return orders.filter((x) => x.product_id === product_id);\n },\n submitOrder: submitOrder,\n modifyOrder: modifyOrder,\n cancelOrder: cancelOrder,\n});\n"]}
@@ -1,7 +1,7 @@
1
1
  import { decodePath } from '@yuants/utils';
2
2
  import { postTradeCancelOrder } from '../api/private-api';
3
3
  export const cancelOrder = async (credential, order) => {
4
- const [, instId] = decodePath(order.product_id);
4
+ const [instId] = decodePath(order.product_id).slice(-1);
5
5
  const res = await postTradeCancelOrder(credential, {
6
6
  instId,
7
7
  ordId: order.order_id,
@@ -1 +1 @@
1
- {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../src/orders/cancelOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAe,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEvE,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,UAAU,EAAE;QACjD,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,QAAS;KACvB,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { ICredential, postTradeCancelOrder } from '../api/private-api';\n\nexport const cancelOrder = async (credential: ICredential, order: IOrder) => {\n const [, instId] = decodePath(order.product_id);\n const res = await postTradeCancelOrder(credential, {\n instId,\n ordId: order.order_id!,\n });\n if (res.code !== '0') {\n throw new Error(`Cancel order failed: code=${res.code} msg=${res.msg}`);\n }\n};\n"]}
1
+ {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../src/orders/cancelOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAe,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEvE,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,UAAU,EAAE;QACjD,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,QAAS;KACvB,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { ICredential, postTradeCancelOrder } from '../api/private-api';\n\nexport const cancelOrder = async (credential: ICredential, order: IOrder) => {\n const [instId] = decodePath(order.product_id).slice(-1);\n const res = await postTradeCancelOrder(credential, {\n instId,\n ordId: order.order_id!,\n });\n if (res.code !== '0') {\n throw new Error(`Cancel order failed: code=${res.code} msg=${res.msg}`);\n }\n};\n"]}
@@ -4,7 +4,7 @@ import { postTradeAmendOrder } from '../api/private-api';
4
4
  import { productService } from '../public-data/product';
5
5
  import { spotMarketTickers$ } from '../public-data/quote';
6
6
  export const modifyOrder = async (credential, order) => {
7
- const [instType, instId] = decodePath(order.product_id);
7
+ const [instType, instId] = decodePath(order.product_id).slice(-2);
8
8
  const params = {
9
9
  instId,
10
10
  ordId: order.order_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AM;YACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;SAClD;KACF;IAED,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAEtF,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC1D,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { formatTime, decodePath, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeAmendOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nexport const modifyOrder = async (credential: ICredential, order: IOrder) => {\n const [instType, instId] = decodePath(order.product_id);\n const params: {\n instId: string;\n ordId: string;\n newPx?: string;\n newSz?: string;\n } = {\n instId,\n ordId: order.order_id!, // 使用现有订单ID\n };\n\n // 如果需要修改价格\n if (order.price !== undefined) {\n params.newPx = order.price.toString();\n }\n\n // 如果需要修改数量\n if (order.volume !== undefined) {\n // 处理数量修改,类似于 SubmitOrder 中的逻辑\n if (instType === 'SWAP') {\n params.newSz = order.volume.toString();\n } else if (instType === 'SPOT') {\n params.newSz = order.volume.toString();\n } else if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MAKER') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MARKET') {\n // 对于市价单,可能需要根据当前价格计算新的数量\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'ModifyOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n params.newSz = roundToStep(order.volume * price, theProduct.volume_step!).toString();\n }\n } else {\n throw new Error(`Unknown instType: ${instType}`);\n }\n }\n\n console.info(formatTime(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));\n\n const res = await postTradeAmendOrder(credential, params);\n if (res.code !== '0') {\n throw new Error(`ModifyOrder failed: code=${res.code}, msg=${res.msg}`);\n }\n};\n"]}
1
+ {"version":3,"file":"modifyOrder.js","sourceRoot":"","sources":["../../src/orders/modifyOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAe,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,MAAM,MAAM,GAKR;QACF,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,QAAS,EAAE,WAAW;KACpC,CAAC;IAEF,WAAW;IACX,IAAI,KAAK,CAAC,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CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;gBACpE,MAAM,UAAU,GAAG,MAAM,cAAc,CACrC,cAAc,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAChF,CAAC;gBACF,IAAI,CAAC,UAAU,EAAE;oBACf,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;iBAC1D;gBACD,MAAM,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,EAAE,UAAU,CAAC,WAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;aACtF;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;SAClD;KACF;IAED,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAEtF,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC1D,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { formatTime, decodePath, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeAmendOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nexport const modifyOrder = async (credential: ICredential, order: IOrder) => {\n const [instType, instId] = decodePath(order.product_id).slice(-2);\n const params: {\n instId: string;\n ordId: string;\n newPx?: string;\n newSz?: string;\n } = {\n instId,\n ordId: order.order_id!, // 使用现有订单ID\n };\n\n // 如果需要修改价格\n if (order.price !== undefined) {\n params.newPx = order.price.toString();\n }\n\n // 如果需要修改数量\n if (order.volume !== undefined) {\n // 处理数量修改,类似于 SubmitOrder 中的逻辑\n if (instType === 'SWAP') {\n params.newSz = order.volume.toString();\n } else if (instType === 'SPOT') {\n params.newSz = order.volume.toString();\n } else if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MAKER') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MARKET') {\n // 对于市价单,可能需要根据当前价格计算新的数量\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'ModifyOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n params.newSz = roundToStep(order.volume * price, theProduct.volume_step!).toString();\n }\n } else {\n throw new Error(`Unknown instType: ${instType}`);\n }\n }\n\n console.info(formatTime(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));\n\n const res = await postTradeAmendOrder(credential, params);\n if (res.code !== '0') {\n throw new Error(`ModifyOrder failed: code=${res.code}, msg=${res.msg}`);\n }\n};\n"]}
@@ -38,7 +38,7 @@ const mapOrderTypeToOrdType = (order_type) => {
38
38
  };
39
39
  export const submitOrder = async (credential, order) => {
40
40
  var _a, _b, _c;
41
- const [instType, instId] = decodePath(order.product_id);
41
+ const [instType, instId] = decodePath(order.product_id).slice(-2);
42
42
  // 交易数量,表示要购买或者出售的数量。
43
43
  // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。
44
44
  // 当币币杠杆以市价买入时,指计价货币的数量。
@@ -96,6 +96,7 @@ export const submitOrder = async (credential, order) => {
96
96
  : undefined,
97
97
  px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price.toString() : undefined,
98
98
  ccy: instType === 'MARGIN' ? 'USDT' : undefined,
99
+ tag: process.env.BROKER_CODE,
99
100
  };
100
101
  console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));
101
102
  const res = await postTradeOrder(credential, params);
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../src/orders/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAe,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,uBAAuB,GAAG,CAAC,SAAkB,EAAE,EAAE;IACrD,QAAQ,SAAS,EAAE;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,KAAK,CAAC;QACf,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,MAAM,CAAC;KACjB;IACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,0BAA0B,GAAG,CAAC,SAAkB,EAAE,EAAE;IACxD,QAAQ,SAAS,EAAE;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,YAAY;YACf,OAAO,MAAM,CAAC;QAChB,KAAK,aAAa,CAAC;QACnB,KA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EAAE;QAC5C,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;KACxC;IACD,MAAM,2BAA2B,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI;SAC9D,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;SAClC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nconst mapOrderDirectionToSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'buy';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'sell';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderDirectionToPosSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'long';\n case 'CLOSE_SHORT':\n case 'OPEN_SHORT':\n return 'short';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderTypeToOrdType = (order_type?: string) => {\n switch (order_type) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n case 'MAKER':\n return 'post_only';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nexport const submitOrder = async (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const [instType, instId] = decodePath(order.product_id);\n\n // 交易数量,表示要购买或者出售的数量。\n // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。\n // 当币币杠杆以市价买入时,指计价货币的数量。\n // 当币币杠杆以市价卖出时,指交易货币的数量。\n // 对于币币市价单,单位由 tgtCcy 决定\n // 当交割、永续、期权买入和卖出时,指合约张数。\n const mapOrderVolumeToSz = async (order: IOrder) => {\n if (instType === 'SWAP') {\n return order.volume;\n }\n if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n return order.volume;\n }\n if (order.order_type === 'MAKER') {\n return order.volume;\n }\n if (order.order_type === 'MARKET') {\n if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {\n return order.volume;\n }\n //\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n mapOrderDirectionToPosSide(order.order_direction) === 'long'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n return roundToStep(order.volume * price, theProduct.volume_step!);\n }\n\n return 0;\n }\n\n if (instType === 'SPOT') {\n return order.volume;\n }\n\n throw new Error(`Unknown instType: ${instType}`);\n };\n\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n instType === 'MARGIN' || instType === 'SPOT'\n ? 'net'\n : mapOrderDirectionToPosSide(order.order_direction),\n ordType: mapOrderTypeToOrdType(order.order_type),\n sz: (await mapOrderVolumeToSz(order)).toString(),\n tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,\n reduceOnly:\n instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes(order.order_direction ?? '')\n ? 'true'\n : undefined,\n px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price!.toString() : undefined,\n ccy: instType === 'MARGIN' ? 'USDT' : undefined,\n };\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const res = await postTradeOrder(credential, params);\n if (res.code === '0' && res.data?.[0]?.ordId) {\n return { order_id: res.data[0].ordId };\n }\n throw `Failed to submit order: ${res.code} ${res.msg}: ${res.data\n .map((x) => `${x.sCode} ${x.sMsg}`)\n .join('; ')}`;\n};\n"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../src/orders/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAe,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,uBAAuB,GAAG,CAAC,SAAkB,EAAE,EAAE;IACrD,QAAQ,SAAS,EAAE;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,KAAK,CAAC;QACf,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,MAAM,CAAC;KACjB;IACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,0BAA0B,GAAG,CAAC,SAAkB,EAAE,EAAE;IACxD,QAAQ,SAAS,EAAE;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,YAAY;YACf,OAAO,MAAM,CAAC;QAChB,KAAK,aAAa,CAAC;QACnB,KAAK,YAAY;YACf,OAAO,OAAO,CAAC;KAClB;IACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAAC,UAAmB,EAAE,EAAE;IACpD,QAAQ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AAC;KACxC;IACD,MAAM,2BAA2B,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI;SAC9D,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;SAClC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nconst mapOrderDirectionToSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'buy';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'sell';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderDirectionToPosSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'long';\n case 'CLOSE_SHORT':\n case 'OPEN_SHORT':\n return 'short';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderTypeToOrdType = (order_type?: string) => {\n switch (order_type) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n case 'MAKER':\n return 'post_only';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nexport const submitOrder = async (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const [instType, instId] = decodePath(order.product_id).slice(-2);\n\n // 交易数量,表示要购买或者出售的数量。\n // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。\n // 当币币杠杆以市价买入时,指计价货币的数量。\n // 当币币杠杆以市价卖出时,指交易货币的数量。\n // 对于币币市价单,单位由 tgtCcy 决定\n // 当交割、永续、期权买入和卖出时,指合约张数。\n const mapOrderVolumeToSz = async (order: IOrder) => {\n if (instType === 'SWAP') {\n return order.volume;\n }\n if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n return order.volume;\n }\n if (order.order_type === 'MAKER') {\n return order.volume;\n }\n if (order.order_type === 'MARKET') {\n if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {\n return order.volume;\n }\n //\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n mapOrderDirectionToPosSide(order.order_direction) === 'long'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n return roundToStep(order.volume * price, theProduct.volume_step!);\n }\n\n return 0;\n }\n\n if (instType === 'SPOT') {\n return order.volume;\n }\n\n throw new Error(`Unknown instType: ${instType}`);\n };\n\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n instType === 'MARGIN' || instType === 'SPOT'\n ? 'net'\n : mapOrderDirectionToPosSide(order.order_direction),\n ordType: mapOrderTypeToOrdType(order.order_type),\n sz: (await mapOrderVolumeToSz(order)).toString(),\n tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,\n reduceOnly:\n instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes(order.order_direction ?? '')\n ? 'true'\n : undefined,\n px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price!.toString() : undefined,\n ccy: instType === 'MARGIN' ? 'USDT' : undefined,\n tag: process.env.BROKER_CODE,\n };\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const res = await postTradeOrder(credential, params);\n if (res.code === '0' && res.data?.[0]?.ordId) {\n return { order_id: res.data[0].ordId };\n }\n throw `Failed to submit order: ${res.code} ${res.msg}: ${res.data\n .map((x) => `${x.sCode} ${x.sMsg}`)\n .join('; ')}`;\n};\n"]}
package/dist/services.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Terminal } from '@yuants/protocol';
2
2
  import { defer } from 'rxjs';
3
- import { getDefaultCredential, postGridAlgoOrder } from './api/private-api';
4
3
  import { getTradingAccountId } from './accountInfos/uid';
4
+ import { getDefaultCredential, postGridAlgoOrder } from './api/private-api';
5
5
  const terminal = Terminal.fromNodeEnv();
6
6
  const credential = getDefaultCredential();
7
7
  defer(async () => {
@@ -13,6 +13,7 @@ defer(async () => {
13
13
  },
14
14
  }, async (msg) => {
15
15
  if (msg.req) {
16
+ msg.req.tag = process.env.BROKER_CODE;
16
17
  const result = await postGridAlgoOrder(credential, msg.req);
17
18
  return { res: { code: 0, message: 'OK', data: result } };
18
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;AAE1C,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAE/D,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,iBAAiB,EACjB;QACE,QAAQ,EAAE,CAAC,YAAY,CAAC;QACxB,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;SACxC;KACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;QACZ,IAAI,GAAG,CAAC,GAAG,EAAE;YACX,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,GAAG,CAAC,GAAU,CAAC,CAAC;YACnE,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;SAC1D;QACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC;IACpD,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport { getDefaultCredential, postGridAlgoOrder } from './api/private-api';\nimport { getTradingAccountId } from './accountInfos/uid';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const tradingAccountId = await getTradingAccountId(credential);\n\n terminal.server.provideService(\n 'Grid/Algo-Order',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountId },\n },\n },\n async (msg) => {\n if (msg.req) {\n const result = await postGridAlgoOrder(credential, msg.req as any);\n return { res: { code: 0, message: 'OK', data: result } };\n }\n return { res: { code: 0, message: 'No Params' } };\n },\n );\n}).subscribe();\n"]}
1
+ {"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE5E,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;AAE1C,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAI/D,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,iBAAiB,EACjB;QACE,QAAQ,EAAE,CAAC,YAAY,CAAC;QACxB,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;SACxC;KACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;QACZ,IAAI,GAAG,CAAC,GAAG,EAAE;YACX,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;YACtC,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5D,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;SAC1D;QACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC;IACpD,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport { getTradingAccountId } from './accountInfos/uid';\nimport { getDefaultCredential, postGridAlgoOrder } from './api/private-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const tradingAccountId = await getTradingAccountId(credential);\n\n type Request = Parameters<typeof postGridAlgoOrder>[1];\n\n terminal.server.provideService<Request, any>(\n 'Grid/Algo-Order',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountId },\n },\n },\n async (msg) => {\n if (msg.req) {\n msg.req.tag = process.env.BROKER_CODE;\n const result = await postGridAlgoOrder(credential, msg.req);\n return { res: { code: 0, message: 'OK', data: result } };\n }\n return { res: { code: 0, message: 'No Params' } };\n },\n );\n}).subscribe();\n"]}
@@ -4,12 +4,12 @@ const exchange_1 = require("@yuants/exchange");
4
4
  const protocol_1 = require("@yuants/protocol");
5
5
  const utils_1 = require("@yuants/utils");
6
6
  const private_api_1 = require("../api/private-api");
7
- const cancelOrder_1 = require("./cancelOrder");
7
+ const cancelOrder_1 = require("../orders/cancelOrder");
8
+ const modifyOrder_1 = require("../orders/modifyOrder");
9
+ const submitOrder_1 = require("../orders/submitOrder");
8
10
  const getOrders_1 = require("./getOrders");
9
11
  const getPositions_1 = require("./getPositions");
10
- const modifyOrder_1 = require("./modifyOrder");
11
12
  const product_1 = require("./product");
12
- const submitOrder_1 = require("./submitOrder");
13
13
  const terminal = protocol_1.Terminal.fromNodeEnv();
14
14
  (0, exchange_1.provideExchangeServices)(terminal, {
15
15
  name: 'OKX',
@@ -1 +1 @@
1
- {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/experimental/exchange.ts"],"names":[],"mappings":";;AAAA,+CAA2D;AAC3D,+CAA4C;AAC5C,yCAAqD;AACrD,oDAAmE;AACnE,+CAA4C;AAC5C,2CAAwC;AACxC,iDAA8C;AAC9C,+CAA4C;AAC5C,uCAAyC;AACzC,+CAA4C;AAE5C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,kCAAuB,EAAc,QAAQ,EAAE;IAC7C,IAAI,EAAE,KAAK;IACX,gBAAgB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;QACpD,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC/B;KACF;IACD,eAAe,EAAE,KAAK,WAAW,UAAuB;;QACtD,MAAM,aAAa,GAAG,MAAM,IAAA,8BAAgB,EAAC,UAAU,CAAC,CAAC;QACzD,MAAM,GAAG,GAAG,MAAA,MAAA,aAAa,CAAC,IAAI,0CAAG,CAAC,CAAC,0CAAE,GAAG,CAAC;QACzC,IAAI,CAAC,GAAG;YAAE,MAAM,IAAA,gBAAQ,EAAC,wBAAwB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QACnE,OAAO,IAAA,kBAAU,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,YAAY,EAAE,sBAAY;IAC1B,YAAY,EAAE,2BAAY;IAC1B,SAAS,EAAT,qBAAS;IACT,uBAAuB,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;QACxD,MAAM,SAAS,GAAG,MAAM,IAAA,2BAAY,EAAC,UAAU,CAAC,CAAC;QACjD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IAC9D,CAAC;IACD,oBAAoB,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;QACrD,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAS,EAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IAC3D,CAAC;IACD,WAAW,EAAE,yBAAW;IACxB,WAAW,EAAE,yBAAW;IACxB,WAAW,EAAE,yBAAW;CACzB,CAAC,CAAC","sourcesContent":["import { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath, newError } from '@yuants/utils';\nimport { getAccountConfig, ICredential } from '../api/private-api';\nimport { cancelOrder } from './cancelOrder';\nimport { getOrders } from './getOrders';\nimport { getPositions } from './getPositions';\nimport { modifyOrder } from './modifyOrder';\nimport { listProducts } from './product';\nimport { submitOrder } from './submitOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'OKX',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key', 'passphrase'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n passphrase: { type: 'string' },\n },\n },\n getCredentialId: async function (credential: ICredential): Promise<string> {\n const accountConfig = await getAccountConfig(credential);\n const uid = accountConfig.data?.[0]?.uid;\n if (!uid) throw newError('OKX_CREDENTIAL_INVALID', { credential });\n return encodePath('OKX', uid);\n },\n listProducts: listProducts,\n getPositions: getPositions,\n getOrders,\n getPositionsByProductId: async (credential, product_id) => {\n const positions = await getPositions(credential);\n return positions.filter((x) => x.product_id === product_id);\n },\n getOrdersByProductId: async (credential, product_id) => {\n const orders = await getOrders(credential);\n return orders.filter((x) => x.product_id === product_id);\n },\n submitOrder: submitOrder,\n modifyOrder: modifyOrder,\n cancelOrder: cancelOrder,\n});\n"]}
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/experimental/exchange.ts"],"names":[],"mappings":";;AAAA,+CAA2D;AAC3D,+CAA4C;AAC5C,yCAAqD;AACrD,oDAAmE;AACnE,uDAAoD;AACpD,uDAAoD;AACpD,uDAAoD;AACpD,2CAAwC;AACxC,iDAA8C;AAC9C,uCAAyC;AAEzC,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,kCAAuB,EAAc,QAAQ,EAAE;IAC7C,IAAI,EAAE,KAAK;IACX,gBAAgB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;QACpD,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,E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ePath, newError } from '@yuants/utils';\nimport { getAccountConfig, ICredential } from '../api/private-api';\nimport { cancelOrder } from '../orders/cancelOrder';\nimport { modifyOrder } from '../orders/modifyOrder';\nimport { submitOrder } from '../orders/submitOrder';\nimport { getOrders } from './getOrders';\nimport { getPositions } from './getPositions';\nimport { listProducts } from './product';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'OKX',\n credentialSchema: {\n type: 'object',\n required: ['access_key', 'secret_key', 'passphrase'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n passphrase: { type: 'string' },\n },\n },\n getCredentialId: async function (credential: ICredential): Promise<string> {\n const accountConfig = await getAccountConfig(credential);\n const uid = accountConfig.data?.[0]?.uid;\n if (!uid) throw newError('OKX_CREDENTIAL_INVALID', { credential });\n return encodePath('OKX', uid);\n },\n listProducts: listProducts,\n getPositions: getPositions,\n getOrders,\n getPositionsByProductId: async (credential, product_id) => {\n const positions = await getPositions(credential);\n return positions.filter((x) => x.product_id === product_id);\n },\n getOrdersByProductId: async (credential, product_id) => {\n const orders = await getOrders(credential);\n return orders.filter((x) => x.product_id === product_id);\n },\n submitOrder: submitOrder,\n modifyOrder: modifyOrder,\n cancelOrder: cancelOrder,\n});\n"]}
@@ -4,7 +4,7 @@ exports.cancelOrder = void 0;
4
4
  const utils_1 = require("@yuants/utils");
5
5
  const private_api_1 = require("../api/private-api");
6
6
  const cancelOrder = async (credential, order) => {
7
- const [, instId] = (0, utils_1.decodePath)(order.product_id);
7
+ const [instId] = (0, utils_1.decodePath)(order.product_id).slice(-1);
8
8
  const res = await (0, private_api_1.postTradeCancelOrder)(credential, {
9
9
  instId,
10
10
  ordId: order.order_id,
@@ -1 +1 @@
1
- {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../src/orders/cancelOrder.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,oDAAuE;AAEhE,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,MAAM,IAAA,kCAAoB,EAAC,UAAU,EAAE;QACjD,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,QAAS;KACvB,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC;AATW,QAAA,WAAW,eAStB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { ICredential, postTradeCancelOrder } from '../api/private-api';\n\nexport const cancelOrder = async (credential: ICredential, order: IOrder) => {\n const [, instId] = decodePath(order.product_id);\n const res = await postTradeCancelOrder(credential, {\n instId,\n ordId: order.order_id!,\n });\n if (res.code !== '0') {\n throw new Error(`Cancel order failed: code=${res.code} msg=${res.msg}`);\n }\n};\n"]}
1
+ {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../src/orders/cancelOrder.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,oDAAuE;AAEhE,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,MAAM,GAAG,GAAG,MAAM,IAAA,kCAAoB,EAAC,UAAU,EAAE;QACjD,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,QAAS;KACvB,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC;AATW,QAAA,WAAW,eAStB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { ICredential, postTradeCancelOrder } from '../api/private-api';\n\nexport const cancelOrder = async (credential: ICredential, order: IOrder) => {\n const [instId] = decodePath(order.product_id).slice(-1);\n const res = await postTradeCancelOrder(credential, {\n instId,\n ordId: order.order_id!,\n });\n if (res.code !== '0') {\n throw new Error(`Cancel order failed: code=${res.code} msg=${res.msg}`);\n }\n};\n"]}
@@ -7,7 +7,7 @@ const private_api_1 = require("../api/private-api");
7
7
  const product_1 = require("../public-data/product");
8
8
  const quote_1 = require("../public-data/quote");
9
9
  const modifyOrder = async (credential, order) => {
10
- const [instType, instId] = (0, utils_1.decodePath)(order.product_id);
10
+ const [instType, instId] = (0, utils_1.decodePath)(order.product_id).slice(-2);
11
11
  const params = {
12
12
  instId,
13
13
  ordId: order.order_id, // 使用现有订单ID
@@ -1 +1 @@
1
- {"version":3,"file":"modifyOrder.js","sourceRoot":"","sources":["../../src/orders/modifyOrder.ts"],"names":[],"mappings":";;;AACA,yCAAoE;AACpE,+BAA2C;AAC3C,oDAAsE;AACtE,oDAAwD;AACxD,gDAA0D;AAEnD,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxD,MAAM,MAAM,GAKR;QACF,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,QAAS,EAAE,WAAW;KACpC,CAAC;IAEF,WAAW;IACX,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE;QAC7B,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;KACvC;IAED,WAAW;I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,UAAU,GAAG,MAAM,IAAA,qBAAc,EACrC,wBAAc,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAChF,CAAC;gBACF,IAAI,CAAC,UAAU,EAAE;oBACf,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;iBAC1D;gBACD,MAAM,CAAC,KAAK,GAAG,IAAA,mBAAW,EAAC,KAAK,CAAC,MAAM,GAAG,KAAK,EAAE,UAAU,CAAC,WAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;aACtF;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;SAClD;KACF;IAED,OAAO,CAAC,IAAI,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAEtF,MAAM,GAAG,GAAG,MAAM,IAAA,iCAAmB,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC1D,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC;AAjEW,QAAA,WAAW,eAiEtB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { formatTime, decodePath, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeAmendOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nexport const modifyOrder = async (credential: ICredential, order: IOrder) => {\n const [instType, instId] = decodePath(order.product_id);\n const params: {\n instId: string;\n ordId: string;\n newPx?: string;\n newSz?: string;\n } = {\n instId,\n ordId: order.order_id!, // 使用现有订单ID\n };\n\n // 如果需要修改价格\n if (order.price !== undefined) {\n params.newPx = order.price.toString();\n }\n\n // 如果需要修改数量\n if (order.volume !== undefined) {\n // 处理数量修改,类似于 SubmitOrder 中的逻辑\n if (instType === 'SWAP') {\n params.newSz = order.volume.toString();\n } else if (instType === 'SPOT') {\n params.newSz = order.volume.toString();\n } else if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MAKER') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MARKET') {\n // 对于市价单,可能需要根据当前价格计算新的数量\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'ModifyOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n params.newSz = roundToStep(order.volume * price, theProduct.volume_step!).toString();\n }\n } else {\n throw new Error(`Unknown instType: ${instType}`);\n }\n }\n\n console.info(formatTime(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));\n\n const res = await postTradeAmendOrder(credential, params);\n if (res.code !== '0') {\n throw new Error(`ModifyOrder failed: code=${res.code}, msg=${res.msg}`);\n }\n};\n"]}
1
+ {"version":3,"file":"modifyOrder.js","sourceRoot":"","sources":["../../src/orders/modifyOrder.ts"],"names":[],"mappings":";;;AACA,yCAAoE;AACpE,+BAA2C;AAC3C,oDAAsE;AACtE,oDAAwD;AACxD,gDAA0D;AAEnD,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,K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AM,IAAI,KAAK,CAAC,4BAA4B,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC;AAjEW,QAAA,WAAW,eAiEtB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { formatTime, decodePath, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeAmendOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nexport const modifyOrder = async (credential: ICredential, order: IOrder) => {\n const [instType, instId] = decodePath(order.product_id).slice(-2);\n const params: {\n instId: string;\n ordId: string;\n newPx?: string;\n newSz?: string;\n } = {\n instId,\n ordId: order.order_id!, // 使用现有订单ID\n };\n\n // 如果需要修改价格\n if (order.price !== undefined) {\n params.newPx = order.price.toString();\n }\n\n // 如果需要修改数量\n if (order.volume !== undefined) {\n // 处理数量修改,类似于 SubmitOrder 中的逻辑\n if (instType === 'SWAP') {\n params.newSz = order.volume.toString();\n } else if (instType === 'SPOT') {\n params.newSz = order.volume.toString();\n } else if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MAKER') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MARKET') {\n // 对于市价单,可能需要根据当前价格计算新的数量\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'ModifyOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n params.newSz = roundToStep(order.volume * price, theProduct.volume_step!).toString();\n }\n } else {\n throw new Error(`Unknown instType: ${instType}`);\n }\n }\n\n console.info(formatTime(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));\n\n const res = await postTradeAmendOrder(credential, params);\n if (res.code !== '0') {\n throw new Error(`ModifyOrder failed: code=${res.code}, msg=${res.msg}`);\n }\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../src/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAwCjE,eAAO,MAAM,WAAW,eAAsB,WAAW,SAAS,MAAM,KAAG,QAAQ;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAmFtG,CAAC"}
1
+ {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../src/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAwCjE,eAAO,MAAM,WAAW,eAAsB,WAAW,SAAS,MAAM,KAAG,QAAQ;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAoFtG,CAAC"}
@@ -41,7 +41,7 @@ const mapOrderTypeToOrdType = (order_type) => {
41
41
  };
42
42
  const submitOrder = async (credential, order) => {
43
43
  var _a, _b, _c;
44
- const [instType, instId] = (0, utils_1.decodePath)(order.product_id);
44
+ const [instType, instId] = (0, utils_1.decodePath)(order.product_id).slice(-2);
45
45
  // 交易数量,表示要购买或者出售的数量。
46
46
  // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。
47
47
  // 当币币杠杆以市价买入时,指计价货币的数量。
@@ -99,6 +99,7 @@ const submitOrder = async (credential, order) => {
99
99
  : undefined,
100
100
  px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price.toString() : undefined,
101
101
  ccy: instType === 'MARGIN' ? 'USDT' : undefined,
102
+ tag: process.env.BROKER_CODE,
102
103
  };
103
104
  console.info((0, utils_1.formatTime)(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));
104
105
  const res = await (0, private_api_1.postTradeOrder)(credential, params);
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../src/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,yCAAoE;AACpE,+BAA2C;AAC3C,oDAAiE;AACjE,oDAAwD;AACxD,gDAA0D;AAE1D,MAAM,uBAAuB,GAAG,CAAC,SAAkB,EAAE,EAAE;IACrD,QAAQ,SAAS,EAAE;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,KAAK,CAAC;QACf,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,MAAM,CAAC;KACjB;IACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,0BAA0B,GAAG,CAAC,SAAkB,EAAE,EAAE;IACxD,QAAQ,SAAS,EAAE;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,YAAY;YACf,OAAO,MAAM,CAAC;QAChB,KAAK,aAAa,CAAC;QACnB,KAAK,YAAY;YACf,OAAO,OAAO,CAAC;KAClB;IACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAAC,UAAmB,EAAE,EAAE;IACpD,QAAQ,UAAU,EAAE;QAClB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,OAAO;YACV,OAAO,WAAW,CAAC;KACtB;IACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,UAAU,EAAE,CAAC,CAAC;AACvD,CAAC,CAAC;AAEK,MAAM,WAA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AA,WAAW,eAmFtB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nconst mapOrderDirectionToSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'buy';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'sell';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderDirectionToPosSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'long';\n case 'CLOSE_SHORT':\n case 'OPEN_SHORT':\n return 'short';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderTypeToOrdType = (order_type?: string) => {\n switch (order_type) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n case 'MAKER':\n return 'post_only';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nexport const submitOrder = async (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const [instType, instId] = decodePath(order.product_id);\n\n // 交易数量,表示要购买或者出售的数量。\n // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。\n // 当币币杠杆以市价买入时,指计价货币的数量。\n // 当币币杠杆以市价卖出时,指交易货币的数量。\n // 对于币币市价单,单位由 tgtCcy 决定\n // 当交割、永续、期权买入和卖出时,指合约张数。\n const mapOrderVolumeToSz = async (order: IOrder) => {\n if (instType === 'SWAP') {\n return order.volume;\n }\n if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n return order.volume;\n }\n if (order.order_type === 'MAKER') {\n return order.volume;\n }\n if (order.order_type === 'MARKET') {\n if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {\n return order.volume;\n }\n //\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n mapOrderDirectionToPosSide(order.order_direction) === 'long'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n return roundToStep(order.volume * price, theProduct.volume_step!);\n }\n\n return 0;\n }\n\n if (instType === 'SPOT') {\n return order.volume;\n }\n\n throw new Error(`Unknown instType: ${instType}`);\n };\n\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n instType === 'MARGIN' || instType === 'SPOT'\n ? 'net'\n : mapOrderDirectionToPosSide(order.order_direction),\n ordType: mapOrderTypeToOrdType(order.order_type),\n sz: (await mapOrderVolumeToSz(order)).toString(),\n tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,\n reduceOnly:\n instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes(order.order_direction ?? '')\n ? 'true'\n : undefined,\n px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price!.toString() : undefined,\n ccy: instType === 'MARGIN' ? 'USDT' : undefined,\n };\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const res = await postTradeOrder(credential, params);\n if (res.code === '0' && res.data?.[0]?.ordId) {\n return { order_id: res.data[0].ordId };\n }\n throw `Failed to submit order: ${res.code} ${res.msg}: ${res.data\n .map((x) => `${x.sCode} ${x.sMsg}`)\n .join('; ')}`;\n};\n"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../src/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,yCAAoE;AACpE,+BAA2C;AAC3C,oDAAiE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UAAU,KAAK,OAAO,IAAI,KAAK,CAAC,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS;QACtG,GAAG,EAAE,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QAC/C,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;KAC7B,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACtF,MAAM,GAAG,GAAG,MAAM,IAAA,4BAAc,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACrD,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,KAAI,MAAA,MAAA,GAAG,CAAC,IAAI,0CAAG,CAAC,CAAC,0CAAE,KAAK,CAAA,EAAE;QAC5C,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;KACxC;IACD,MAAM,2BAA2B,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI;SAC9D,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;SAClC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC,CAAC;AApFW,QAAA,WAAW,eAoFtB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nconst mapOrderDirectionToSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'buy';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'sell';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderDirectionToPosSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'long';\n case 'CLOSE_SHORT':\n case 'OPEN_SHORT':\n return 'short';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderTypeToOrdType = (order_type?: string) => {\n switch (order_type) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n case 'MAKER':\n return 'post_only';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nexport const submitOrder = async (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const [instType, instId] = decodePath(order.product_id).slice(-2);\n\n // 交易数量,表示要购买或者出售的数量。\n // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。\n // 当币币杠杆以市价买入时,指计价货币的数量。\n // 当币币杠杆以市价卖出时,指交易货币的数量。\n // 对于币币市价单,单位由 tgtCcy 决定\n // 当交割、永续、期权买入和卖出时,指合约张数。\n const mapOrderVolumeToSz = async (order: IOrder) => {\n if (instType === 'SWAP') {\n return order.volume;\n }\n if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n return order.volume;\n }\n if (order.order_type === 'MAKER') {\n return order.volume;\n }\n if (order.order_type === 'MARKET') {\n if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {\n return order.volume;\n }\n //\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n mapOrderDirectionToPosSide(order.order_direction) === 'long'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n return roundToStep(order.volume * price, theProduct.volume_step!);\n }\n\n return 0;\n }\n\n if (instType === 'SPOT') {\n return order.volume;\n }\n\n throw new Error(`Unknown instType: ${instType}`);\n };\n\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n instType === 'MARGIN' || instType === 'SPOT'\n ? 'net'\n : mapOrderDirectionToPosSide(order.order_direction),\n ordType: mapOrderTypeToOrdType(order.order_type),\n sz: (await mapOrderVolumeToSz(order)).toString(),\n tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,\n reduceOnly:\n instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes(order.order_direction ?? '')\n ? 'true'\n : undefined,\n px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price!.toString() : undefined,\n ccy: instType === 'MARGIN' ? 'USDT' : undefined,\n tag: process.env.BROKER_CODE,\n };\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const res = await postTradeOrder(credential, params);\n if (res.code === '0' && res.data?.[0]?.ordId) {\n return { order_id: res.data[0].ordId };\n }\n throw `Failed to submit order: ${res.code} ${res.msg}: ${res.data\n .map((x) => `${x.sCode} ${x.sMsg}`)\n .join('; ')}`;\n};\n"]}
package/lib/services.js CHANGED
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const protocol_1 = require("@yuants/protocol");
4
4
  const rxjs_1 = require("rxjs");
5
- const private_api_1 = require("./api/private-api");
6
5
  const uid_1 = require("./accountInfos/uid");
6
+ const private_api_1 = require("./api/private-api");
7
7
  const terminal = protocol_1.Terminal.fromNodeEnv();
8
8
  const credential = (0, private_api_1.getDefaultCredential)();
9
9
  (0, rxjs_1.defer)(async () => {
@@ -15,6 +15,7 @@ const credential = (0, private_api_1.getDefaultCredential)();
15
15
  },
16
16
  }, async (msg) => {
17
17
  if (msg.req) {
18
+ msg.req.tag = process.env.BROKER_CODE;
18
19
  const result = await (0, private_api_1.postGridAlgoOrder)(credential, msg.req);
19
20
  return { res: { code: 0, message: 'OK', data: result } };
20
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAC5C,+BAA6B;AAC7B,mDAA4E;AAC5E,4CAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,IAAA,yBAAmB,EAAC,UAAU,CAAC,CAAC;IAE/D,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,iBAAiB,EACjB;QACE,QAAQ,EAAE,CAAC,YAAY,CAAC;QACxB,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;SACxC;KACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;QACZ,IAAI,GAAG,CAAC,GAAG,EAAE;YACX,MAAM,MAAM,GAAG,MAAM,IAAA,+BAAiB,EAAC,UAAU,EAAE,GAAG,CAAC,GAAU,CAAC,CAAC;YACnE,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;SAC1D;QACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC;IACpD,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport { getDefaultCredential, postGridAlgoOrder } from './api/private-api';\nimport { getTradingAccountId } from './accountInfos/uid';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const tradingAccountId = await getTradingAccountId(credential);\n\n terminal.server.provideService(\n 'Grid/Algo-Order',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountId },\n },\n },\n async (msg) => {\n if (msg.req) {\n const result = await postGridAlgoOrder(credential, msg.req as any);\n return { res: { code: 0, message: 'OK', data: result } };\n }\n return { res: { code: 0, message: 'No Params' } };\n },\n );\n}).subscribe();\n"]}
1
+ {"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAC5C,+BAA6B;AAC7B,4CAAyD;AACzD,mDAA4E;AAE5E,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,IAAA,yBAAmB,EAAC,UAAU,CAAC,CAAC;IAI/D,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,iBAAiB,EACjB;QACE,QAAQ,EAAE,CAAC,YAAY,CAAC;QACxB,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;SACxC;KACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;QACZ,IAAI,GAAG,CAAC,GAAG,EAAE;YACX,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;YACtC,MAAM,MAAM,GAAG,MAAM,IAAA,+BAAiB,EAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5D,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;SAC1D;QACD,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC;IACpD,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport { getTradingAccountId } from './accountInfos/uid';\nimport { getDefaultCredential, postGridAlgoOrder } from './api/private-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const tradingAccountId = await getTradingAccountId(credential);\n\n type Request = Parameters<typeof postGridAlgoOrder>[1];\n\n terminal.server.provideService<Request, any>(\n 'Grid/Algo-Order',\n {\n required: ['account_id'],\n properties: {\n account_id: { const: tradingAccountId },\n },\n },\n async (msg) => {\n if (msg.req) {\n msg.req.tag = process.env.BROKER_CODE;\n const result = await postGridAlgoOrder(credential, msg.req);\n return { res: { code: 0, message: 'OK', data: result } };\n }\n return { res: { code: 0, message: 'No Params' } };\n },\n );\n}).subscribe();\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-okx",
3
- "version": "0.28.4",
3
+ "version": "0.29.1",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -1,13 +1,13 @@
1
1
  {
2
- "apps/vendor-okx/CHANGELOG.json": "7649a74c2edbe498f313408d95212d4180583036",
3
- "apps/vendor-okx/CHANGELOG.md": "8acce719942e6fd2619a20f1e89a29d02fa9a37d",
2
+ "apps/vendor-okx/CHANGELOG.json": "96e11227a2922723344689b2a35a032617e765d5",
3
+ "apps/vendor-okx/CHANGELOG.md": "2cdf45546d6c7943fe5b8fbf6ac5760f06db8ed2",
4
4
  "apps/vendor-okx/README.md": "68caeb8e383d77ece973cd70f4b167b86abb54c3",
5
5
  "apps/vendor-okx/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
6
6
  "apps/vendor-okx/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
7
7
  "apps/vendor-okx/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
8
8
  "apps/vendor-okx/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
9
9
  "apps/vendor-okx/etc/vendor-okx.api.md": "92c54ccd547d2ad81ca6088158ca193e85c208df",
10
- "apps/vendor-okx/package.json": "3e058d461b5df4e71a7b58c8bc6659c9f0f36b92",
10
+ "apps/vendor-okx/package.json": "1d18b3e95dd1f4d1b539eaeab489dad7e04ddbd1",
11
11
  "apps/vendor-okx/src/account-actions-with-credential.ts": "1a2de787b588e98ceef60b3ffb951f298504bf12",
12
12
  "apps/vendor-okx/src/account.ts": "672014c974457b438cf026f763d6eecfe585c82b",
13
13
  "apps/vendor-okx/src/accountInfos/earning.ts": "62aaeb3b62fa9197d07ee14155625530cdb9b1cd",
@@ -21,27 +21,24 @@
21
21
  "apps/vendor-okx/src/api-service.ts": "f1d977b144b1096965c5990260d9e6c81b08cb8c",
22
22
  "apps/vendor-okx/src/api/private-api.ts": "73ab6b99249ebb73769e903cc356627eaf19b433",
23
23
  "apps/vendor-okx/src/api/public-api.ts": "05b9cddafd09b5c9f65ce4eaeab42832e7d60449",
24
- "apps/vendor-okx/src/experimental/cancelOrder.ts": "6c4b53b5ad5edad0b5ae5de8e40be87d9de0839b",
25
- "apps/vendor-okx/src/experimental/exchange.ts": "98e379e8a7615975460639666cc0e282de0dfaa0",
24
+ "apps/vendor-okx/src/experimental/exchange.ts": "df5c9dc9e4d4210be7367f1c23dc63dc4d82cb6f",
26
25
  "apps/vendor-okx/src/experimental/getOrders.ts": "f89b8334fa55163a78f91cf675cea8c7c869d4a7",
27
26
  "apps/vendor-okx/src/experimental/getPositions.ts": "1cbbe0873a4dc1358eb43e5a1f62cc132bcd58e2",
28
- "apps/vendor-okx/src/experimental/modifyOrder.ts": "5e1e31188f3cba216ba8d9eda08f4c2c2655d9d9",
29
27
  "apps/vendor-okx/src/experimental/product.ts": "808bb037c1559ead2260a6b1eb2552f246da45c6",
30
- "apps/vendor-okx/src/experimental/submitOrder.ts": "343ec45f3793ccaebc644883579d251b63549309",
31
28
  "apps/vendor-okx/src/index.ts": "9432e574a30efe43cc1ddba8a2def12c992c4430",
32
29
  "apps/vendor-okx/src/order-actions-with-credential.ts": "f58b164c57a776db0fd0ad3a9f7197603ab2f66e",
33
30
  "apps/vendor-okx/src/order-actions.ts": "18907924c81ab679bf8a58142fcbc3addd160a94",
34
31
  "apps/vendor-okx/src/order.ts": "342f08dbc4a760e5f29bdaa1fe840872219f9ab5",
35
- "apps/vendor-okx/src/orders/cancelOrder.ts": "db8741b6f4ec9caa01bc01748ff297bb1f8b58a7",
32
+ "apps/vendor-okx/src/orders/cancelOrder.ts": "9a6c6d976caddd896ce08afac1dd2e4e24879b54",
36
33
  "apps/vendor-okx/src/orders/listOrders.ts": "c4739eb4c0f54391164a7d8e6c7fde44b41cb268",
37
- "apps/vendor-okx/src/orders/modifyOrder.ts": "ab30a4b204bcf08c2762541a4bbbf01d0e0f2d1a",
38
- "apps/vendor-okx/src/orders/submitOrder.ts": "d9200e3cfb2dd2bef090cab768e61c15e5d044d7",
34
+ "apps/vendor-okx/src/orders/modifyOrder.ts": "9101b5049743f302b0f0ad84f929ed8a88040bad",
35
+ "apps/vendor-okx/src/orders/submitOrder.ts": "564c8a659091dfb9676de753f0fceef1ec8ee168",
39
36
  "apps/vendor-okx/src/public-data/interest_rate.ts": "f3171f2753955d500ae00ce7e263ea26e05e5421",
40
37
  "apps/vendor-okx/src/public-data/market-order.ts": "c7269e9fe1f339b320e8b4cd98652854446a245c",
41
38
  "apps/vendor-okx/src/public-data/ohlc.ts": "0b5a568e30b3070f74b0e64614e8c1cc9ba507fb",
42
39
  "apps/vendor-okx/src/public-data/product.ts": "9caa1b0d9fa621800870ef47086767f6f5810ad9",
43
40
  "apps/vendor-okx/src/public-data/quote.ts": "4ab43a1d668393d90ae90ec1221de51a28101b32",
44
- "apps/vendor-okx/src/services.ts": "2cbbc938f50f8348c02fd5b05cf53b3643a66d05",
41
+ "apps/vendor-okx/src/services.ts": "aeaf5f9d0a87347be6150b28961c5a7c0886b1d8",
45
42
  "apps/vendor-okx/src/strategy-account.ts": "2d8f913e19c4402eab249291aaab0b77bc4d9ff8",
46
43
  "apps/vendor-okx/src/trade.ts": "cbb88bc535b8377ecd54a18e39082923fd5a4fda",
47
44
  "apps/vendor-okx/src/transfer.ts": "381e4bf18846c8f79d3e970277d8800a2f94dacd",
@@ -1,13 +0,0 @@
1
- import { decodePath } from '@yuants/utils';
2
- import { postTradeCancelOrder } from '../api/private-api';
3
- export const cancelOrder = async (credential, order) => {
4
- const [, , instId] = decodePath(order.product_id);
5
- const res = await postTradeCancelOrder(credential, {
6
- instId,
7
- ordId: order.order_id,
8
- });
9
- if (res.code !== '0') {
10
- throw new Error(`Cancel order failed: code=${res.code} msg=${res.msg}`);
11
- }
12
- };
13
- //# sourceMappingURL=cancelOrder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../src/experimental/cancelOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAe,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEvE,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,EAAE,AAAD,EAAG,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,UAAU,EAAE;QACjD,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,QAAS;KACvB,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { ICredential, postTradeCancelOrder } from '../api/private-api';\n\nexport const cancelOrder = async (credential: ICredential, order: IOrder) => {\n const [, , instId] = decodePath(order.product_id);\n const res = await postTradeCancelOrder(credential, {\n instId,\n ordId: order.order_id!,\n });\n if (res.code !== '0') {\n throw new Error(`Cancel order failed: code=${res.code} msg=${res.msg}`);\n }\n};\n"]}
@@ -1,58 +0,0 @@
1
- import { formatTime, decodePath, roundToStep } from '@yuants/utils';
2
- import { firstValueFrom, map } from 'rxjs';
3
- import { postTradeAmendOrder } from '../api/private-api';
4
- import { productService } from '../public-data/product';
5
- import { spotMarketTickers$ } from '../public-data/quote';
6
- export const modifyOrder = async (credential, order) => {
7
- const [, instType, instId] = decodePath(order.product_id);
8
- const params = {
9
- instId,
10
- ordId: order.order_id, // 使用现有订单ID
11
- };
12
- // 如果需要修改价格
13
- if (order.price !== undefined) {
14
- params.newPx = order.price.toString();
15
- }
16
- // 如果需要修改数量
17
- if (order.volume !== undefined) {
18
- // 处理数量修改,类似于 SubmitOrder 中的逻辑
19
- if (instType === 'SWAP') {
20
- params.newSz = order.volume.toString();
21
- }
22
- else if (instType === 'SPOT') {
23
- params.newSz = order.volume.toString();
24
- }
25
- else if (instType === 'MARGIN') {
26
- if (order.order_type === 'LIMIT') {
27
- params.newSz = order.volume.toString();
28
- }
29
- if (order.order_type === 'MAKER') {
30
- params.newSz = order.volume.toString();
31
- }
32
- if (order.order_type === 'MARKET') {
33
- // 对于市价单,可能需要根据当前价格计算新的数量
34
- const price = await firstValueFrom(spotMarketTickers$.pipe(map((x) => order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'
35
- ? +x[instId].askPx
36
- : +x[instId].bidPx)));
37
- if (!price) {
38
- throw new Error(`invalid tick: ${price}`);
39
- }
40
- console.info(formatTime(Date.now()), 'ModifyOrder', 'price', price);
41
- const theProduct = await firstValueFrom(productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))));
42
- if (!theProduct) {
43
- throw new Error(`Unknown product: ${order.position_id}`);
44
- }
45
- params.newSz = roundToStep(order.volume * price, theProduct.volume_step).toString();
46
- }
47
- }
48
- else {
49
- throw new Error(`Unknown instType: ${instType}`);
50
- }
51
- }
52
- console.info(formatTime(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));
53
- const res = await postTradeAmendOrder(credential, params);
54
- if (res.code !== '0') {
55
- throw new Error(`ModifyOrder failed: code=${res.code}, msg=${res.msg}`);
56
- }
57
- };
58
- //# sourceMappingURL=modifyOrder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modifyOrder.js","sourceRoot":"","sources":["../../src/experimental/modifyOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAe,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC1D,MAAM,MAAM,GAKR;QACF,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,QAAS,EAAE,WAAW;KACpC,CAAC;IAEF,WAAW;IACX,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE;QAC7B,MAAM,CAAC,KAAK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EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;gBACpE,MAAM,UAAU,GAAG,MAAM,cAAc,CACrC,cAAc,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAChF,CAAC;gBACF,IAAI,CAAC,UAAU,EAAE;oBACf,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;iBAC1D;gBACD,MAAM,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,EAAE,UAAU,CAAC,WAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;aACtF;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;SAClD;KACF;IAED,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAEtF,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC1D,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { formatTime, decodePath, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeAmendOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nexport const modifyOrder = async (credential: ICredential, order: IOrder) => {\n const [, instType, instId] = decodePath(order.product_id);\n const params: {\n instId: string;\n ordId: string;\n newPx?: string;\n newSz?: string;\n } = {\n instId,\n ordId: order.order_id!, // 使用现有订单ID\n };\n\n // 如果需要修改价格\n if (order.price !== undefined) {\n params.newPx = order.price.toString();\n }\n\n // 如果需要修改数量\n if (order.volume !== undefined) {\n // 处理数量修改,类似于 SubmitOrder 中的逻辑\n if (instType === 'SWAP') {\n params.newSz = order.volume.toString();\n } else if (instType === 'SPOT') {\n params.newSz = order.volume.toString();\n } else if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MAKER') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MARKET') {\n // 对于市价单,可能需要根据当前价格计算新的数量\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'ModifyOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n params.newSz = roundToStep(order.volume * price, theProduct.volume_step!).toString();\n }\n } else {\n throw new Error(`Unknown instType: ${instType}`);\n }\n }\n\n console.info(formatTime(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));\n\n const res = await postTradeAmendOrder(credential, params);\n if (res.code !== '0') {\n throw new Error(`ModifyOrder failed: code=${res.code}, msg=${res.msg}`);\n }\n};\n"]}
@@ -1,109 +0,0 @@
1
- import { decodePath, formatTime, roundToStep } from '@yuants/utils';
2
- import { firstValueFrom, map } from 'rxjs';
3
- import { postTradeOrder } from '../api/private-api';
4
- import { productService } from '../public-data/product';
5
- import { spotMarketTickers$ } from '../public-data/quote';
6
- const mapOrderDirectionToSide = (direction) => {
7
- switch (direction) {
8
- case 'OPEN_LONG':
9
- case 'CLOSE_SHORT':
10
- return 'buy';
11
- case 'OPEN_SHORT':
12
- case 'CLOSE_LONG':
13
- return 'sell';
14
- }
15
- throw new Error(`Unknown direction: ${direction}`);
16
- };
17
- const mapOrderDirectionToPosSide = (direction) => {
18
- switch (direction) {
19
- case 'OPEN_LONG':
20
- case 'CLOSE_LONG':
21
- return 'long';
22
- case 'CLOSE_SHORT':
23
- case 'OPEN_SHORT':
24
- return 'short';
25
- }
26
- throw new Error(`Unknown direction: ${direction}`);
27
- };
28
- const mapOrderTypeToOrdType = (order_type) => {
29
- switch (order_type) {
30
- case 'LIMIT':
31
- return 'limit';
32
- case 'MARKET':
33
- return 'market';
34
- case 'MAKER':
35
- return 'post_only';
36
- }
37
- throw new Error(`Unknown order type: ${order_type}`);
38
- };
39
- export const submitOrder = async (credential, order) => {
40
- var _a, _b, _c;
41
- const [, instType, instId] = decodePath(order.product_id);
42
- // 交易数量,表示要购买或者出售的数量。
43
- // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。
44
- // 当币币杠杆以市价买入时,指计价货币的数量。
45
- // 当币币杠杆以市价卖出时,指交易货币的数量。
46
- // 对于币币市价单,单位由 tgtCcy 决定
47
- // 当交割、永续、期权买入和卖出时,指合约张数。
48
- const mapOrderVolumeToSz = async (order) => {
49
- if (instType === 'SWAP') {
50
- return order.volume;
51
- }
52
- if (instType === 'MARGIN') {
53
- if (order.order_type === 'LIMIT') {
54
- return order.volume;
55
- }
56
- if (order.order_type === 'MAKER') {
57
- return order.volume;
58
- }
59
- if (order.order_type === 'MARKET') {
60
- if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {
61
- return order.volume;
62
- }
63
- //
64
- const price = await firstValueFrom(spotMarketTickers$.pipe(map((x) => mapOrderDirectionToPosSide(order.order_direction) === 'long'
65
- ? +x[instId].askPx
66
- : +x[instId].bidPx)));
67
- if (!price) {
68
- throw new Error(`invalid tick: ${price}`);
69
- }
70
- console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);
71
- const theProduct = await firstValueFrom(productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))));
72
- if (!theProduct) {
73
- throw new Error(`Unknown product: ${order.position_id}`);
74
- }
75
- return roundToStep(order.volume * price, theProduct.volume_step);
76
- }
77
- return 0;
78
- }
79
- if (instType === 'SPOT') {
80
- return order.volume;
81
- }
82
- throw new Error(`Unknown instType: ${instType}`);
83
- };
84
- const params = {
85
- instId,
86
- tdMode: instType === 'SPOT' ? 'cash' : 'cross',
87
- side: mapOrderDirectionToSide(order.order_direction),
88
- posSide: instType === 'MARGIN' || instType === 'SPOT'
89
- ? 'net'
90
- : mapOrderDirectionToPosSide(order.order_direction),
91
- ordType: mapOrderTypeToOrdType(order.order_type),
92
- sz: (await mapOrderVolumeToSz(order)).toString(),
93
- tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,
94
- reduceOnly: instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes((_a = order.order_direction) !== null && _a !== void 0 ? _a : '')
95
- ? 'true'
96
- : undefined,
97
- px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price.toString() : undefined,
98
- ccy: instType === 'MARGIN' ? 'USDT' : undefined,
99
- };
100
- console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));
101
- const res = await postTradeOrder(credential, params);
102
- if (res.code === '0' && ((_c = (_b = res.data) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.ordId)) {
103
- return { order_id: res.data[0].ordId };
104
- }
105
- throw `Failed to submit order: ${res.code} ${res.msg}: ${res.data
106
- .map((x) => `${x.sCode} ${x.sMsg}`)
107
- .join('; ')}`;
108
- };
109
- //# sourceMappingURL=submitOrder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../src/experimental/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,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AI,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,MAAA,KAAK,CAAC,eAAe,mCAAI,EAAE,CAAC;YAC1F,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,SAAS;QACf,EAAE,EAAE,KAAK,CAAC,UAAU,KAAK,OAAO,IAAI,KAAK,CAAC,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS;QACtG,GAAG,EAAE,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;KAChD,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACtF,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACrD,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,KAAI,MAAA,MAAA,GAAG,CAAC,IAAI,0CAAG,CAAC,CAAC,0CAAE,KAAK,CAAA,EAAE;QAC5C,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;KACxC;IACD,MAAM,2BAA2B,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI;SAC9D,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;SAClC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nconst mapOrderDirectionToSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'buy';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'sell';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderDirectionToPosSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'long';\n case 'CLOSE_SHORT':\n case 'OPEN_SHORT':\n return 'short';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderTypeToOrdType = (order_type?: string) => {\n switch (order_type) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n case 'MAKER':\n return 'post_only';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nexport const submitOrder = async (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const [, instType, instId] = decodePath(order.product_id);\n\n // 交易数量,表示要购买或者出售的数量。\n // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。\n // 当币币杠杆以市价买入时,指计价货币的数量。\n // 当币币杠杆以市价卖出时,指交易货币的数量。\n // 对于币币市价单,单位由 tgtCcy 决定\n // 当交割、永续、期权买入和卖出时,指合约张数。\n const mapOrderVolumeToSz = async (order: IOrder) => {\n if (instType === 'SWAP') {\n return order.volume;\n }\n if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n return order.volume;\n }\n if (order.order_type === 'MAKER') {\n return order.volume;\n }\n if (order.order_type === 'MARKET') {\n if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {\n return order.volume;\n }\n //\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n mapOrderDirectionToPosSide(order.order_direction) === 'long'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n return roundToStep(order.volume * price, theProduct.volume_step!);\n }\n\n return 0;\n }\n\n if (instType === 'SPOT') {\n return order.volume;\n }\n\n throw new Error(`Unknown instType: ${instType}`);\n };\n\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n instType === 'MARGIN' || instType === 'SPOT'\n ? 'net'\n : mapOrderDirectionToPosSide(order.order_direction),\n ordType: mapOrderTypeToOrdType(order.order_type),\n sz: (await mapOrderVolumeToSz(order)).toString(),\n tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,\n reduceOnly:\n instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes(order.order_direction ?? '')\n ? 'true'\n : undefined,\n px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price!.toString() : undefined,\n ccy: instType === 'MARGIN' ? 'USDT' : undefined,\n };\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const res = await postTradeOrder(credential, params);\n if (res.code === '0' && res.data?.[0]?.ordId) {\n return { order_id: res.data[0].ordId };\n }\n throw `Failed to submit order: ${res.code} ${res.msg}: ${res.data\n .map((x) => `${x.sCode} ${x.sMsg}`)\n .join('; ')}`;\n};\n"]}
@@ -1,4 +0,0 @@
1
- import { IOrder } from '@yuants/data-order';
2
- import { ICredential } from '../api/private-api';
3
- export declare const cancelOrder: (credential: ICredential, order: IOrder) => Promise<void>;
4
- //# sourceMappingURL=cancelOrder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cancelOrder.d.ts","sourceRoot":"","sources":["../../src/experimental/cancelOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAwB,MAAM,oBAAoB,CAAC;AAEvE,eAAO,MAAM,WAAW,eAAsB,WAAW,SAAS,MAAM,kBASvE,CAAC"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cancelOrder = void 0;
4
- const utils_1 = require("@yuants/utils");
5
- const private_api_1 = require("../api/private-api");
6
- const cancelOrder = async (credential, order) => {
7
- const [, , instId] = (0, utils_1.decodePath)(order.product_id);
8
- const res = await (0, private_api_1.postTradeCancelOrder)(credential, {
9
- instId,
10
- ordId: order.order_id,
11
- });
12
- if (res.code !== '0') {
13
- throw new Error(`Cancel order failed: code=${res.code} msg=${res.msg}`);
14
- }
15
- };
16
- exports.cancelOrder = cancelOrder;
17
- //# sourceMappingURL=cancelOrder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../src/experimental/cancelOrder.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,oDAAuE;AAEhE,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,EAAE,AAAD,EAAG,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,MAAM,IAAA,kCAAoB,EAAC,UAAU,EAAE;QACjD,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,QAAS;KACvB,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;KACzE;AACH,CAAC,CAAC;AATW,QAAA,WAAW,eAStB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { ICredential, postTradeCancelOrder } from '../api/private-api';\n\nexport const cancelOrder = async (credential: ICredential, order: IOrder) => {\n const [, , instId] = decodePath(order.product_id);\n const res = await postTradeCancelOrder(credential, {\n instId,\n ordId: order.order_id!,\n });\n if (res.code !== '0') {\n throw new Error(`Cancel order failed: code=${res.code} msg=${res.msg}`);\n }\n};\n"]}
@@ -1,4 +0,0 @@
1
- import { IOrder } from '@yuants/data-order';
2
- import { ICredential } from '../api/private-api';
3
- export declare const modifyOrder: (credential: ICredential, order: IOrder) => Promise<void>;
4
- //# sourceMappingURL=modifyOrder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modifyOrder.d.ts","sourceRoot":"","sources":["../../src/experimental/modifyOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAuB,MAAM,oBAAoB,CAAC;AAItE,eAAO,MAAM,WAAW,eAAsB,WAAW,SAAS,MAAM,kBAiEvE,CAAC"}
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.modifyOrder = void 0;
4
- const utils_1 = require("@yuants/utils");
5
- const rxjs_1 = require("rxjs");
6
- const private_api_1 = require("../api/private-api");
7
- const product_1 = require("../public-data/product");
8
- const quote_1 = require("../public-data/quote");
9
- const modifyOrder = async (credential, order) => {
10
- const [, instType, instId] = (0, utils_1.decodePath)(order.product_id);
11
- const params = {
12
- instId,
13
- ordId: order.order_id, // 使用现有订单ID
14
- };
15
- // 如果需要修改价格
16
- if (order.price !== undefined) {
17
- params.newPx = order.price.toString();
18
- }
19
- // 如果需要修改数量
20
- if (order.volume !== undefined) {
21
- // 处理数量修改,类似于 SubmitOrder 中的逻辑
22
- if (instType === 'SWAP') {
23
- params.newSz = order.volume.toString();
24
- }
25
- else if (instType === 'SPOT') {
26
- params.newSz = order.volume.toString();
27
- }
28
- else if (instType === 'MARGIN') {
29
- if (order.order_type === 'LIMIT') {
30
- params.newSz = order.volume.toString();
31
- }
32
- if (order.order_type === 'MAKER') {
33
- params.newSz = order.volume.toString();
34
- }
35
- if (order.order_type === 'MARKET') {
36
- // 对于市价单,可能需要根据当前价格计算新的数量
37
- const price = await (0, rxjs_1.firstValueFrom)(quote_1.spotMarketTickers$.pipe((0, rxjs_1.map)((x) => order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'
38
- ? +x[instId].askPx
39
- : +x[instId].bidPx)));
40
- if (!price) {
41
- throw new Error(`invalid tick: ${price}`);
42
- }
43
- console.info((0, utils_1.formatTime)(Date.now()), 'ModifyOrder', 'price', price);
44
- const theProduct = await (0, rxjs_1.firstValueFrom)(product_1.productService.mapProductIdToProduct$.pipe((0, rxjs_1.map)((x) => x.get(order.product_id))));
45
- if (!theProduct) {
46
- throw new Error(`Unknown product: ${order.position_id}`);
47
- }
48
- params.newSz = (0, utils_1.roundToStep)(order.volume * price, theProduct.volume_step).toString();
49
- }
50
- }
51
- else {
52
- throw new Error(`Unknown instType: ${instType}`);
53
- }
54
- }
55
- console.info((0, utils_1.formatTime)(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));
56
- const res = await (0, private_api_1.postTradeAmendOrder)(credential, params);
57
- if (res.code !== '0') {
58
- throw new Error(`ModifyOrder failed: code=${res.code}, msg=${res.msg}`);
59
- }
60
- };
61
- exports.modifyOrder = modifyOrder;
62
- //# sourceMappingURL=modifyOrder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modifyOrder.js","sourceRoot":"","sources":["../../src/experimental/modifyOrder.ts"],"names":[],"mappings":";;;AACA,yCAAoE;AACpE,+BAA2C;AAC3C,oDAAsE;AACtE,oDAAwD;AACxD,gDAA0D;AAEnD,MAAM,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAE,EAAE;IAC1E,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,C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AW,eAiEtB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { formatTime, decodePath, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeAmendOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nexport const modifyOrder = async (credential: ICredential, order: IOrder) => {\n const [, instType, instId] = decodePath(order.product_id);\n const params: {\n instId: string;\n ordId: string;\n newPx?: string;\n newSz?: string;\n } = {\n instId,\n ordId: order.order_id!, // 使用现有订单ID\n };\n\n // 如果需要修改价格\n if (order.price !== undefined) {\n params.newPx = order.price.toString();\n }\n\n // 如果需要修改数量\n if (order.volume !== undefined) {\n // 处理数量修改,类似于 SubmitOrder 中的逻辑\n if (instType === 'SWAP') {\n params.newSz = order.volume.toString();\n } else if (instType === 'SPOT') {\n params.newSz = order.volume.toString();\n } else if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MAKER') {\n params.newSz = order.volume.toString();\n }\n if (order.order_type === 'MARKET') {\n // 对于市价单,可能需要根据当前价格计算新的数量\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_SHORT'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'ModifyOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n params.newSz = roundToStep(order.volume * price, theProduct.volume_step!).toString();\n }\n } else {\n throw new Error(`Unknown instType: ${instType}`);\n }\n }\n\n console.info(formatTime(Date.now()), 'ModifyOrder', 'params', JSON.stringify(params));\n\n const res = await postTradeAmendOrder(credential, params);\n if (res.code !== '0') {\n throw new Error(`ModifyOrder failed: code=${res.code}, msg=${res.msg}`);\n }\n};\n"]}
@@ -1,6 +0,0 @@
1
- import { IOrder } from '@yuants/data-order';
2
- import { ICredential } from '../api/private-api';
3
- export declare const submitOrder: (credential: ICredential, order: IOrder) => Promise<{
4
- order_id: string;
5
- }>;
6
- //# sourceMappingURL=submitOrder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../src/experimental/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAwCjE,eAAO,MAAM,WAAW,eAAsB,WAAW,SAAS,MAAM,KAAG,QAAQ;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAmFtG,CAAC"}
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.submitOrder = void 0;
4
- const utils_1 = require("@yuants/utils");
5
- const rxjs_1 = require("rxjs");
6
- const private_api_1 = require("../api/private-api");
7
- const product_1 = require("../public-data/product");
8
- const quote_1 = require("../public-data/quote");
9
- const mapOrderDirectionToSide = (direction) => {
10
- switch (direction) {
11
- case 'OPEN_LONG':
12
- case 'CLOSE_SHORT':
13
- return 'buy';
14
- case 'OPEN_SHORT':
15
- case 'CLOSE_LONG':
16
- return 'sell';
17
- }
18
- throw new Error(`Unknown direction: ${direction}`);
19
- };
20
- const mapOrderDirectionToPosSide = (direction) => {
21
- switch (direction) {
22
- case 'OPEN_LONG':
23
- case 'CLOSE_LONG':
24
- return 'long';
25
- case 'CLOSE_SHORT':
26
- case 'OPEN_SHORT':
27
- return 'short';
28
- }
29
- throw new Error(`Unknown direction: ${direction}`);
30
- };
31
- const mapOrderTypeToOrdType = (order_type) => {
32
- switch (order_type) {
33
- case 'LIMIT':
34
- return 'limit';
35
- case 'MARKET':
36
- return 'market';
37
- case 'MAKER':
38
- return 'post_only';
39
- }
40
- throw new Error(`Unknown order type: ${order_type}`);
41
- };
42
- const submitOrder = async (credential, order) => {
43
- var _a, _b, _c;
44
- const [, instType, instId] = (0, utils_1.decodePath)(order.product_id);
45
- // 交易数量,表示要购买或者出售的数量。
46
- // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。
47
- // 当币币杠杆以市价买入时,指计价货币的数量。
48
- // 当币币杠杆以市价卖出时,指交易货币的数量。
49
- // 对于币币市价单,单位由 tgtCcy 决定
50
- // 当交割、永续、期权买入和卖出时,指合约张数。
51
- const mapOrderVolumeToSz = async (order) => {
52
- if (instType === 'SWAP') {
53
- return order.volume;
54
- }
55
- if (instType === 'MARGIN') {
56
- if (order.order_type === 'LIMIT') {
57
- return order.volume;
58
- }
59
- if (order.order_type === 'MAKER') {
60
- return order.volume;
61
- }
62
- if (order.order_type === 'MARKET') {
63
- if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {
64
- return order.volume;
65
- }
66
- //
67
- const price = await (0, rxjs_1.firstValueFrom)(quote_1.spotMarketTickers$.pipe((0, rxjs_1.map)((x) => mapOrderDirectionToPosSide(order.order_direction) === 'long'
68
- ? +x[instId].askPx
69
- : +x[instId].bidPx)));
70
- if (!price) {
71
- throw new Error(`invalid tick: ${price}`);
72
- }
73
- console.info((0, utils_1.formatTime)(Date.now()), 'SubmitOrder', 'price', price);
74
- const theProduct = await (0, rxjs_1.firstValueFrom)(product_1.productService.mapProductIdToProduct$.pipe((0, rxjs_1.map)((x) => x.get(order.product_id))));
75
- if (!theProduct) {
76
- throw new Error(`Unknown product: ${order.position_id}`);
77
- }
78
- return (0, utils_1.roundToStep)(order.volume * price, theProduct.volume_step);
79
- }
80
- return 0;
81
- }
82
- if (instType === 'SPOT') {
83
- return order.volume;
84
- }
85
- throw new Error(`Unknown instType: ${instType}`);
86
- };
87
- const params = {
88
- instId,
89
- tdMode: instType === 'SPOT' ? 'cash' : 'cross',
90
- side: mapOrderDirectionToSide(order.order_direction),
91
- posSide: instType === 'MARGIN' || instType === 'SPOT'
92
- ? 'net'
93
- : mapOrderDirectionToPosSide(order.order_direction),
94
- ordType: mapOrderTypeToOrdType(order.order_type),
95
- sz: (await mapOrderVolumeToSz(order)).toString(),
96
- tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,
97
- reduceOnly: instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes((_a = order.order_direction) !== null && _a !== void 0 ? _a : '')
98
- ? 'true'
99
- : undefined,
100
- px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price.toString() : undefined,
101
- ccy: instType === 'MARGIN' ? 'USDT' : undefined,
102
- };
103
- console.info((0, utils_1.formatTime)(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));
104
- const res = await (0, private_api_1.postTradeOrder)(credential, params);
105
- if (res.code === '0' && ((_c = (_b = res.data) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.ordId)) {
106
- return { order_id: res.data[0].ordId };
107
- }
108
- throw `Failed to submit order: ${res.code} ${res.msg}: ${res.data
109
- .map((x) => `${x.sCode} ${x.sMsg}`)
110
- .join('; ')}`;
111
- };
112
- exports.submitOrder = submitOrder;
113
- //# sourceMappingURL=submitOrder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../src/experimental/submitOrder.ts"],"names":[],"mappings":";;;AACA,yCAAoE;AACpE,+BAA2C;AAC3C,oDAAiE;AACjE,oDAAwD;AACxD,gDAA0D;AAE1D,MAAM,uBAAuB,GAAG,CAAC,SAAkB,EAAE,EAAE;IACrD,QAAQ,SAAS,EAAE;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,KAAK,CAAC;QACf,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,MAAM,CAAC;KACjB;IACD,MAAM,IAAI,K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,GAAG,EAAE,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACtF,MAAM,GAAG,GAAG,MAAM,IAAA,4BAAc,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACrD,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,KAAI,MAAA,MAAA,GAAG,CAAC,IAAI,0CAAG,CAAC,CAAC,0CAAE,KAAK,CAAA,EAAE;QAC5C,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;KACxC;IACD,MAAM,2BAA2B,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI;SAC9D,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;SAClC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC,CAAC;AAnFW,QAAA,WAAW,eAmFtB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { decodePath, formatTime, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { ICredential, postTradeOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\n\nconst mapOrderDirectionToSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 'buy';\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return 'sell';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderDirectionToPosSide = (direction?: string) => {\n switch (direction) {\n case 'OPEN_LONG':\n case 'CLOSE_LONG':\n return 'long';\n case 'CLOSE_SHORT':\n case 'OPEN_SHORT':\n return 'short';\n }\n throw new Error(`Unknown direction: ${direction}`);\n};\n\nconst mapOrderTypeToOrdType = (order_type?: string) => {\n switch (order_type) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n case 'MAKER':\n return 'post_only';\n }\n throw new Error(`Unknown order type: ${order_type}`);\n};\n\nexport const submitOrder = async (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const [, instType, instId] = decodePath(order.product_id);\n\n // 交易数量,表示要购买或者出售的数量。\n // 当币币/币币杠杆以限价买入和卖出时,指交易货币数量。\n // 当币币杠杆以市价买入时,指计价货币的数量。\n // 当币币杠杆以市价卖出时,指交易货币的数量。\n // 对于币币市价单,单位由 tgtCcy 决定\n // 当交割、永续、期权买入和卖出时,指合约张数。\n const mapOrderVolumeToSz = async (order: IOrder) => {\n if (instType === 'SWAP') {\n return order.volume;\n }\n if (instType === 'MARGIN') {\n if (order.order_type === 'LIMIT') {\n return order.volume;\n }\n if (order.order_type === 'MAKER') {\n return order.volume;\n }\n if (order.order_type === 'MARKET') {\n if (order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_LONG') {\n return order.volume;\n }\n //\n const price = await firstValueFrom(\n spotMarketTickers$.pipe(\n map((x) =>\n mapOrderDirectionToPosSide(order.order_direction) === 'long'\n ? +x[instId].askPx\n : +x[instId].bidPx,\n ),\n ),\n );\n if (!price) {\n throw new Error(`invalid tick: ${price}`);\n }\n console.info(formatTime(Date.now()), 'SubmitOrder', 'price', price);\n const theProduct = await firstValueFrom(\n productService.mapProductIdToProduct$.pipe(map((x) => x.get(order.product_id))),\n );\n if (!theProduct) {\n throw new Error(`Unknown product: ${order.position_id}`);\n }\n return roundToStep(order.volume * price, theProduct.volume_step!);\n }\n\n return 0;\n }\n\n if (instType === 'SPOT') {\n return order.volume;\n }\n\n throw new Error(`Unknown instType: ${instType}`);\n };\n\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n instType === 'MARGIN' || instType === 'SPOT'\n ? 'net'\n : mapOrderDirectionToPosSide(order.order_direction),\n ordType: mapOrderTypeToOrdType(order.order_type),\n sz: (await mapOrderVolumeToSz(order)).toString(),\n tgtCcy: instType === 'SPOT' && order.order_type === 'MARKET' ? 'base_ccy' : undefined,\n reduceOnly:\n instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes(order.order_direction ?? '')\n ? 'true'\n : undefined,\n px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price!.toString() : undefined,\n ccy: instType === 'MARGIN' ? 'USDT' : undefined,\n };\n console.info(formatTime(Date.now()), 'SubmitOrder', 'params', JSON.stringify(params));\n const res = await postTradeOrder(credential, params);\n if (res.code === '0' && res.data?.[0]?.ordId) {\n return { order_id: res.data[0].ordId };\n }\n throw `Failed to submit order: ${res.code} ${res.msg}: ${res.data\n .map((x) => `${x.sCode} ${x.sMsg}`)\n .join('; ')}`;\n};\n"]}