@yuants/vendor-okx 0.28.3 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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_TAG,
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/experimental/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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AAA,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/experimental/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;IACp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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 tag: process.env.BROKER_TAG,\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"]}
@@ -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_TAG,
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,CAA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AAK,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
+ {"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;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A2B,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 tag: process.env.BROKER_TAG,\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"]}
@@ -12,24 +12,9 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
12
12
  };
13
13
  import { createSeriesProvider } from '@yuants/data-series';
14
14
  import { Terminal } from '@yuants/protocol';
15
- import { createSQLWriter } from '@yuants/sql';
16
15
  import { decodePath, formatTime } from '@yuants/utils';
17
- import { firstValueFrom, map, mergeAll, timer } from 'rxjs';
16
+ import { firstValueFrom, timer } from 'rxjs';
18
17
  import { getFundingRateHistory, getLendingRateHistory } from '../api/public-api';
19
- import { productService } from './product';
20
- createSQLWriter(Terminal.fromNodeEnv(), {
21
- data$: productService.products$.pipe(mergeAll(), map((x) => ({
22
- series_id: x.product_id,
23
- table_name: 'interest_rate',
24
- cron_pattern: '0 * * * *',
25
- cron_timezone: 'UTC',
26
- disabled: false,
27
- replay_count: 0,
28
- }))),
29
- tableName: 'series_collecting_task',
30
- writeInterval: 1000,
31
- conflictKeys: ['series_id', 'table_name'],
32
- });
33
18
  createSeriesProvider(Terminal.fromNodeEnv(), {
34
19
  tableName: 'interest_rate',
35
20
  series_id_prefix_parts: ['OKX'],
@@ -1 +1 @@
1
- {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../src/public-data/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAyB,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAc,UAAU,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EA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ollectingTask } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { firstValueFrom, map, mergeAll, timer } from 'rxjs';\nimport { getFundingRateHistory, getLendingRateHistory } from '../api/public-api';\nimport { productService } from './product';\n\ncreateSQLWriter<ISeriesCollectingTask>(Terminal.fromNodeEnv(), {\n data$: productService.products$.pipe(\n mergeAll(),\n map(\n (x): ISeriesCollectingTask => ({\n series_id: x.product_id,\n table_name: 'interest_rate',\n cron_pattern: '0 * * * *', // 每小时执行一次\n cron_timezone: 'UTC',\n disabled: false,\n replay_count: 0,\n }),\n ),\n ),\n tableName: 'series_collecting_task',\n writeInterval: 1000,\n conflictKeys: ['series_id', 'table_name'],\n});\n\ncreateSeriesProvider<IInterestRate>(Terminal.fromNodeEnv(), {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['OKX'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, started_at, ended_at }) {\n const start = started_at || 0;\n const end = ended_at || Date.now();\n const [, instType, instId] = decodePath(series_id);\n\n if (instType === 'SWAP') {\n let current_end = end;\n while (true) {\n // 接口行为备注:向前翻页,时间降序,不含 after 当前时间点\n const res = await getFundingRateHistory({\n instId: instId,\n after: `${current_end}`,\n });\n if (res.code !== '0') {\n throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;\n }\n // 如果没有数据了,就退出\n if (res.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));\n const data = res.data.map(\n (v): IInterestRate => ({\n series_id: series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.fundingTime),\n long_rate: `${-v.fundingRate}`,\n short_rate: `${v.fundingRate}`,\n settlement_price: '',\n }),\n );\n yield data;\n current_end = +res.data[res.data.length - 1].fundingTime;\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n\n if (instType === 'MARGIN') {\n // MARGIN/BTC-USDT\n const [base, quote] = instId.split('-');\n let current_end = end;\n while (true) {\n const resBase = await getLendingRateHistory({ ccy: base, after: `${current_end}` });\n const resQuote = await getLendingRateHistory({ ccy: quote, after: `${current_end}` });\n\n if (resBase.code !== '0') {\n throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;\n }\n if (resBase.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));\n\n if (resQuote.code !== '0') {\n throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;\n }\n if (resQuote.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));\n\n // 做多时,借入 quote 的资金,做空时,借入 base 的资金\n // 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate\n\n const mapTsToBaseRate = new Map<string, string>();\n resBase.data.forEach((v) => {\n mapTsToBaseRate.set(v.ts, v.rate);\n });\n\n const data: IInterestRate[] = [];\n\n resQuote.data.forEach((v) => {\n if (!mapTsToBaseRate.has(v.ts)) return;\n const long_rate = +v.rate / 365 / 24; // 转换为小时利率\n const short_rate = +mapTsToBaseRate.get(v.ts)! / 365 / 24; // 转换为小时利率\n data.push({\n series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.ts),\n long_rate: `${-long_rate}`,\n short_rate: `${-short_rate}`,\n settlement_price: '',\n });\n });\n\n yield data;\n current_end = new Date(data[data.length - 1].created_at).getTime();\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n },\n});\n"]}
1
+ {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../src/public-data/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kB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GAAG,GAAG,EAAE,CAAC,CAAC,UAAU;wBAChD,MAAM,UAAU,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,UAAU;wBACrE,IAAI,CAAC,IAAI,CAAC;4BACR,SAAS;4BACT,UAAU,EAAE,SAAS;4BACrB,aAAa,EAAE,KAAK;4BACpB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;4BAC7B,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE;4BAC1B,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE;4BAC5B,gBAAgB,EAAE,EAAE;yBACrB,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;oBAEH,oBAAM,IAAI,CAAA,CAAC;oBACX,WAAW,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;oBACnE,IAAI,WAAW,IAAI,KAAK,EAAE;wBACxB,MAAM;qBACP;oBACD,qBAAqB;oBACrB,cAAM,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC;iBACnC;aACF;QACH,CAAC;KAAA;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { createSeriesProvider } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { firstValueFrom, timer } from 'rxjs';\nimport { getFundingRateHistory, getLendingRateHistory } from '../api/public-api';\n\ncreateSeriesProvider<IInterestRate>(Terminal.fromNodeEnv(), {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['OKX'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, started_at, ended_at }) {\n const start = started_at || 0;\n const end = ended_at || Date.now();\n const [, instType, instId] = decodePath(series_id);\n\n if (instType === 'SWAP') {\n let current_end = end;\n while (true) {\n // 接口行为备注:向前翻页,时间降序,不含 after 当前时间点\n const res = await getFundingRateHistory({\n instId: instId,\n after: `${current_end}`,\n });\n if (res.code !== '0') {\n throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;\n }\n // 如果没有数据了,就退出\n if (res.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));\n const data = res.data.map(\n (v): IInterestRate => ({\n series_id: series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.fundingTime),\n long_rate: `${-v.fundingRate}`,\n short_rate: `${v.fundingRate}`,\n settlement_price: '',\n }),\n );\n yield data;\n current_end = +res.data[res.data.length - 1].fundingTime;\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n\n if (instType === 'MARGIN') {\n // MARGIN/BTC-USDT\n const [base, quote] = instId.split('-');\n let current_end = end;\n while (true) {\n const resBase = await getLendingRateHistory({ ccy: base, after: `${current_end}` });\n const resQuote = await getLendingRateHistory({ ccy: quote, after: `${current_end}` });\n\n if (resBase.code !== '0') {\n throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;\n }\n if (resBase.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));\n\n if (resQuote.code !== '0') {\n throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;\n }\n if (resQuote.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));\n\n // 做多时,借入 quote 的资金,做空时,借入 base 的资金\n // 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate\n\n const mapTsToBaseRate = new Map<string, string>();\n resBase.data.forEach((v) => {\n mapTsToBaseRate.set(v.ts, v.rate);\n });\n\n const data: IInterestRate[] = [];\n\n resQuote.data.forEach((v) => {\n if (!mapTsToBaseRate.has(v.ts)) return;\n const long_rate = +v.rate / 365 / 24; // 转换为小时利率\n const short_rate = +mapTsToBaseRate.get(v.ts)! / 365 / 24; // 转换为小时利率\n data.push({\n series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.ts),\n long_rate: `${-long_rate}`,\n short_rate: `${-short_rate}`,\n settlement_price: '',\n });\n });\n\n yield data;\n current_end = new Date(data[data.length - 1].created_at).getTime();\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n },\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_TAG;
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,UAAU,CAAC;YACrC,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_TAG;\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"]}
@@ -1 +1 @@
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
+ {"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,CAoFtG,CAAC"}
@@ -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_TAG,
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/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,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,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiC,EAAE;;IACzG,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC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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,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;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"]}
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,aAA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,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QAC/C,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;KAC5B,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);\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_TAG,\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 +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"}
@@ -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_TAG,
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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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"]}
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,WAAW,GAAG,KAAK,EAAE,UAAuB,EAAE,KAAa,EAAiC,EAAE;;IACzG,MAAM,CAAC,QAAQ,EAAE,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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 tag: process.env.BROKER_TAG,\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"]}
@@ -14,24 +14,9 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const data_series_1 = require("@yuants/data-series");
16
16
  const protocol_1 = require("@yuants/protocol");
17
- const sql_1 = require("@yuants/sql");
18
17
  const utils_1 = require("@yuants/utils");
19
18
  const rxjs_1 = require("rxjs");
20
19
  const public_api_1 = require("../api/public-api");
21
- const product_1 = require("./product");
22
- (0, sql_1.createSQLWriter)(protocol_1.Terminal.fromNodeEnv(), {
23
- data$: product_1.productService.products$.pipe((0, rxjs_1.mergeAll)(), (0, rxjs_1.map)((x) => ({
24
- series_id: x.product_id,
25
- table_name: 'interest_rate',
26
- cron_pattern: '0 * * * *',
27
- cron_timezone: 'UTC',
28
- disabled: false,
29
- replay_count: 0,
30
- }))),
31
- tableName: 'series_collecting_task',
32
- writeInterval: 1000,
33
- conflictKeys: ['series_id', 'table_name'],
34
- });
35
20
  (0, data_series_1.createSeriesProvider)(protocol_1.Terminal.fromNodeEnv(), {
36
21
  tableName: 'interest_rate',
37
22
  series_id_prefix_parts: ['OKX'],
@@ -1 +1 @@
1
- {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../src/public-data/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,qDAAkF;AAClF,+CAA4C;AAC5C,qCAA8C;AAC9C,yCAAmE;AACnE,+BAA4D;AAC5D,kDAAiF;AACjF,uCAA2C;AAE3C,IAAA,qBAAe,EAAwB,mBAAQ,CAAC,WAAW,EAAE,EAAE;IAC7D,KAAK,EAAE,wBAAc,CAAC,SAAS,CAAC,IAAI,CAClC,IAAA,eAAQ,GAAE,EACV,IAAA,UAAG,EACD,CAAC,CAAC,EAAyB,EAAE,CAAC,CAAC;QAC7B,SAAS,EAAE,CAAC,CAAC,UAAU;QACvB,UAAU,EAAE,eAAe;QAC3B,YAAY,EAAE,WAAW;QACzB,aAAa,EAAE,KAAK;QACpB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,CAAC;KAChB,CAAC,CACH,CACF;IACD,SAAS,EAAE,wBAAwB;IACnC,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,CAAC,WAAW,EAAE,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CAAC,EAAE,CAAE,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,UAAU;wBACrE,IAAI,CAAC,IAAI,CAAC;4BACR,SAAS;4BACT,UAAU,EAAE,SAAS;4BACrB,aAAa,EAAE,KAAK;4BACpB,UAAU,EAAE,IAAA,kBAAU,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;4BAC7B,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE;4BAC1B,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE;4BAC5B,gBAAgB,EAAE,EAAE;yBACrB,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;oBAEH,oBAAM,IAAI,CAAA,CAAC;oBACX,WAAW,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;oBACnE,IAAI,WAAW,IAAI,KAAK,EAAE;wBACxB,MAAM;qBACP;oBACD,qBAAqB;oBACrB,cAAM,IAAA,qBAAc,EAAC,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC,CAAA,CAAC;iBACnC;aACF;QACH,CAAC;KAAA;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { createSeriesProvider, ISeriesCollectingTask } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { firstValueFrom, map, mergeAll, timer } from 'rxjs';\nimport { getFundingRateHistory, getLendingRateHistory } from '../api/public-api';\nimport { productService } from './product';\n\ncreateSQLWriter<ISeriesCollectingTask>(Terminal.fromNodeEnv(), {\n data$: productService.products$.pipe(\n mergeAll(),\n map(\n (x): ISeriesCollectingTask => ({\n series_id: x.product_id,\n table_name: 'interest_rate',\n cron_pattern: '0 * * * *', // 每小时执行一次\n cron_timezone: 'UTC',\n disabled: false,\n replay_count: 0,\n }),\n ),\n ),\n tableName: 'series_collecting_task',\n writeInterval: 1000,\n conflictKeys: ['series_id', 'table_name'],\n});\n\ncreateSeriesProvider<IInterestRate>(Terminal.fromNodeEnv(), {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['OKX'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, started_at, ended_at }) {\n const start = started_at || 0;\n const end = ended_at || Date.now();\n const [, instType, instId] = decodePath(series_id);\n\n if (instType === 'SWAP') {\n let current_end = end;\n while (true) {\n // 接口行为备注:向前翻页,时间降序,不含 after 当前时间点\n const res = await getFundingRateHistory({\n instId: instId,\n after: `${current_end}`,\n });\n if (res.code !== '0') {\n throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;\n }\n // 如果没有数据了,就退出\n if (res.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));\n const data = res.data.map(\n (v): IInterestRate => ({\n series_id: series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.fundingTime),\n long_rate: `${-v.fundingRate}`,\n short_rate: `${v.fundingRate}`,\n settlement_price: '',\n }),\n );\n yield data;\n current_end = +res.data[res.data.length - 1].fundingTime;\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n\n if (instType === 'MARGIN') {\n // MARGIN/BTC-USDT\n const [base, quote] = instId.split('-');\n let current_end = end;\n while (true) {\n const resBase = await getLendingRateHistory({ ccy: base, after: `${current_end}` });\n const resQuote = await getLendingRateHistory({ ccy: quote, after: `${current_end}` });\n\n if (resBase.code !== '0') {\n throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;\n }\n if (resBase.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));\n\n if (resQuote.code !== '0') {\n throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;\n }\n if (resQuote.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));\n\n // 做多时,借入 quote 的资金,做空时,借入 base 的资金\n // 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate\n\n const mapTsToBaseRate = new Map<string, string>();\n resBase.data.forEach((v) => {\n mapTsToBaseRate.set(v.ts, v.rate);\n });\n\n const data: IInterestRate[] = [];\n\n resQuote.data.forEach((v) => {\n if (!mapTsToBaseRate.has(v.ts)) return;\n const long_rate = +v.rate / 365 / 24; // 转换为小时利率\n const short_rate = +mapTsToBaseRate.get(v.ts)! / 365 / 24; // 转换为小时利率\n data.push({\n series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.ts),\n long_rate: `${-long_rate}`,\n short_rate: `${-short_rate}`,\n settlement_price: '',\n });\n });\n\n yield data;\n current_end = new Date(data[data.length - 1].created_at).getTime();\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n },\n});\n"]}
1
+ {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../src/public-data/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,qDAA2D;AAC3D,+CAA4C;AAC5C,yCAAuD;AACvD,+BAA6C;AAC7C,kDAAiF;AAEjF,IAAA,kCAAoB,EAAgB,mBAAQ,CAAC,WAAW,EAAE,EAAE;IAC1D,SAAS,EAAE,eAAe;IAC1B,sBAAsB,EAAE,CAAC,KAAK,CAAC;IAC/B,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE;IACjC,OAAO,EAAE,UAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE;;YAC3D,MAAM,KAAK,GAAG,UAAU,IAAI,CAAC,CAAC;YAC9B,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACnC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,IAA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AAM,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;oBACnE,IAAI,WAAW,IAAI,KAAK,EAAE;wBACxB,MAAM;qBACP;oBACD,qBAAqB;oBACrB,cAAM,IAAA,qBAAc,EAAC,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC,CAAA,CAAC;iBACnC;aACF;QACH,CAAC;KAAA;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { createSeriesProvider } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { firstValueFrom, timer } from 'rxjs';\nimport { getFundingRateHistory, getLendingRateHistory } from '../api/public-api';\n\ncreateSeriesProvider<IInterestRate>(Terminal.fromNodeEnv(), {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['OKX'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, started_at, ended_at }) {\n const start = started_at || 0;\n const end = ended_at || Date.now();\n const [, instType, instId] = decodePath(series_id);\n\n if (instType === 'SWAP') {\n let current_end = end;\n while (true) {\n // 接口行为备注:向前翻页,时间降序,不含 after 当前时间点\n const res = await getFundingRateHistory({\n instId: instId,\n after: `${current_end}`,\n });\n if (res.code !== '0') {\n throw `getFundingRateHistory failed: ${res.code} ${res.msg}`;\n }\n // 如果没有数据了,就退出\n if (res.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getFundingRateHistory', JSON.stringify(res.data));\n const data = res.data.map(\n (v): IInterestRate => ({\n series_id: series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.fundingTime),\n long_rate: `${-v.fundingRate}`,\n short_rate: `${v.fundingRate}`,\n settlement_price: '',\n }),\n );\n yield data;\n current_end = +res.data[res.data.length - 1].fundingTime;\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n\n if (instType === 'MARGIN') {\n // MARGIN/BTC-USDT\n const [base, quote] = instId.split('-');\n let current_end = end;\n while (true) {\n const resBase = await getLendingRateHistory({ ccy: base, after: `${current_end}` });\n const resQuote = await getLendingRateHistory({ ccy: quote, after: `${current_end}` });\n\n if (resBase.code !== '0') {\n throw `getLendingRateHistory failed: ${resBase.code} ${resBase.msg}`;\n }\n if (resBase.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resBase.data));\n\n if (resQuote.code !== '0') {\n throw `getLendingRateHistory failed: ${resQuote.code} ${resQuote.msg}`;\n }\n if (resQuote.data.length === 0) {\n break;\n }\n console.info(formatTime(Date.now()), 'getLendingRateHistory', JSON.stringify(resQuote.data));\n\n // 做多时,借入 quote 的资金,做空时,借入 base 的资金\n // 用 quote 的 rate 作为 long_rate,base 的 rate 作为 short_rate\n\n const mapTsToBaseRate = new Map<string, string>();\n resBase.data.forEach((v) => {\n mapTsToBaseRate.set(v.ts, v.rate);\n });\n\n const data: IInterestRate[] = [];\n\n resQuote.data.forEach((v) => {\n if (!mapTsToBaseRate.has(v.ts)) return;\n const long_rate = +v.rate / 365 / 24; // 转换为小时利率\n const short_rate = +mapTsToBaseRate.get(v.ts)! / 365 / 24; // 转换为小时利率\n data.push({\n series_id,\n product_id: series_id,\n datasource_id: 'OKX',\n created_at: formatTime(+v.ts),\n long_rate: `${-long_rate}`,\n short_rate: `${-short_rate}`,\n settlement_price: '',\n });\n });\n\n yield data;\n current_end = new Date(data[data.length - 1].created_at).getTime();\n if (current_end <= start) {\n break;\n }\n // for API rate limit\n await firstValueFrom(timer(1000));\n }\n }\n },\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_TAG;
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,UAAU,CAAC;YACrC,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_TAG;\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.3",
3
+ "version": "0.29.0",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -1,13 +1,13 @@
1
1
  {
2
- "apps/vendor-okx/CHANGELOG.json": "1274e028ebf58bc46c9e18bfd846b975d885a4c5",
3
- "apps/vendor-okx/CHANGELOG.md": "2059225e33a0b10915c8aa0c2224bc46e635a587",
2
+ "apps/vendor-okx/CHANGELOG.json": "b372c1ad7665d3424445834c6f91fbc1565b8695",
3
+ "apps/vendor-okx/CHANGELOG.md": "2c57a21cc39e5b5d3d40a4c4dd059787e0f4a927",
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": "22fafd82ef91efaaf51cadd778cefc8fd76f5e1e",
10
+ "apps/vendor-okx/package.json": "5a652b575a9c2ef027f1bf19204d52cd67b048f0",
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",
@@ -27,7 +27,7 @@
27
27
  "apps/vendor-okx/src/experimental/getPositions.ts": "1cbbe0873a4dc1358eb43e5a1f62cc132bcd58e2",
28
28
  "apps/vendor-okx/src/experimental/modifyOrder.ts": "5e1e31188f3cba216ba8d9eda08f4c2c2655d9d9",
29
29
  "apps/vendor-okx/src/experimental/product.ts": "808bb037c1559ead2260a6b1eb2552f246da45c6",
30
- "apps/vendor-okx/src/experimental/submitOrder.ts": "343ec45f3793ccaebc644883579d251b63549309",
30
+ "apps/vendor-okx/src/experimental/submitOrder.ts": "bfeca4a4819d407ea80317e9b7e18090b44d1181",
31
31
  "apps/vendor-okx/src/index.ts": "9432e574a30efe43cc1ddba8a2def12c992c4430",
32
32
  "apps/vendor-okx/src/order-actions-with-credential.ts": "f58b164c57a776db0fd0ad3a9f7197603ab2f66e",
33
33
  "apps/vendor-okx/src/order-actions.ts": "18907924c81ab679bf8a58142fcbc3addd160a94",
@@ -35,13 +35,13 @@
35
35
  "apps/vendor-okx/src/orders/cancelOrder.ts": "db8741b6f4ec9caa01bc01748ff297bb1f8b58a7",
36
36
  "apps/vendor-okx/src/orders/listOrders.ts": "c4739eb4c0f54391164a7d8e6c7fde44b41cb268",
37
37
  "apps/vendor-okx/src/orders/modifyOrder.ts": "ab30a4b204bcf08c2762541a4bbbf01d0e0f2d1a",
38
- "apps/vendor-okx/src/orders/submitOrder.ts": "d9200e3cfb2dd2bef090cab768e61c15e5d044d7",
39
- "apps/vendor-okx/src/public-data/interest_rate.ts": "a03083ef520c0aba6e0b01e0e24147a858e164f4",
38
+ "apps/vendor-okx/src/orders/submitOrder.ts": "5a161696cda8ae6618745786e7c4f29358cd19ae",
39
+ "apps/vendor-okx/src/public-data/interest_rate.ts": "f3171f2753955d500ae00ce7e263ea26e05e5421",
40
40
  "apps/vendor-okx/src/public-data/market-order.ts": "c7269e9fe1f339b320e8b4cd98652854446a245c",
41
41
  "apps/vendor-okx/src/public-data/ohlc.ts": "0b5a568e30b3070f74b0e64614e8c1cc9ba507fb",
42
42
  "apps/vendor-okx/src/public-data/product.ts": "9caa1b0d9fa621800870ef47086767f6f5810ad9",
43
43
  "apps/vendor-okx/src/public-data/quote.ts": "4ab43a1d668393d90ae90ec1221de51a28101b32",
44
- "apps/vendor-okx/src/services.ts": "2cbbc938f50f8348c02fd5b05cf53b3643a66d05",
44
+ "apps/vendor-okx/src/services.ts": "9c8c077ad7c7e865ad466b4fd9093c2988bb08b6",
45
45
  "apps/vendor-okx/src/strategy-account.ts": "2d8f913e19c4402eab249291aaab0b77bc4d9ff8",
46
46
  "apps/vendor-okx/src/trade.ts": "cbb88bc535b8377ecd54a18e39082923fd5a4fda",
47
47
  "apps/vendor-okx/src/transfer.ts": "381e4bf18846c8f79d3e970277d8800a2f94dacd",