@yuants/vendor-okx 0.33.8 → 0.33.10

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 (43) hide show
  1. package/dist/experimental/getOrders.js +2 -1
  2. package/dist/experimental/getOrders.js.map +1 -1
  3. package/dist/order.js +2 -1
  4. package/dist/order.js.map +1 -1
  5. package/dist/orders/listOrders.js +2 -1
  6. package/dist/orders/listOrders.js.map +1 -1
  7. package/dist/orders/mapOkxOrdTypeToOrderType.js +17 -0
  8. package/dist/orders/mapOkxOrdTypeToOrderType.js.map +1 -0
  9. package/dist/orders/mapOrderTypeToOrdType.js +16 -0
  10. package/dist/orders/mapOrderTypeToOrdType.js.map +1 -0
  11. package/dist/orders/order-type-mapping.test.js +171 -0
  12. package/dist/orders/order-type-mapping.test.js.map +1 -0
  13. package/dist/orders/submitOrder.js +4 -16
  14. package/dist/orders/submitOrder.js.map +1 -1
  15. package/lib/experimental/getOrders.d.ts.map +1 -1
  16. package/lib/experimental/getOrders.js +2 -1
  17. package/lib/experimental/getOrders.js.map +1 -1
  18. package/lib/order.d.ts.map +1 -1
  19. package/lib/order.js +2 -1
  20. package/lib/order.js.map +1 -1
  21. package/lib/orders/listOrders.d.ts.map +1 -1
  22. package/lib/orders/listOrders.js +2 -1
  23. package/lib/orders/listOrders.js.map +1 -1
  24. package/lib/orders/mapOkxOrdTypeToOrderType.d.ts +2 -0
  25. package/lib/orders/mapOkxOrdTypeToOrderType.d.ts.map +1 -0
  26. package/lib/orders/mapOkxOrdTypeToOrderType.js +21 -0
  27. package/lib/orders/mapOkxOrdTypeToOrderType.js.map +1 -0
  28. package/lib/orders/mapOrderTypeToOrdType.d.ts +2 -0
  29. package/lib/orders/mapOrderTypeToOrdType.d.ts.map +1 -0
  30. package/lib/orders/mapOrderTypeToOrdType.js +20 -0
  31. package/lib/orders/mapOrderTypeToOrdType.js.map +1 -0
  32. package/lib/orders/order-type-mapping.test.d.ts +2 -0
  33. package/lib/orders/order-type-mapping.test.d.ts.map +1 -0
  34. package/lib/orders/order-type-mapping.test.js +173 -0
  35. package/lib/orders/order-type-mapping.test.js.map +1 -0
  36. package/lib/orders/submitOrder.d.ts.map +1 -1
  37. package/lib/orders/submitOrder.js +5 -17
  38. package/lib/orders/submitOrder.js.map +1 -1
  39. package/package.json +7 -7
  40. package/temp/build/typescript/ts_xKrCYDcc.json +1 -1
  41. package/temp/package-deps.json +11 -8
  42. package/temp/test/jest/haste-map-0104fb5fee08bd97aacd02300cdbf195-f3ddf881f4f21e2e5ae6006d95adf2b1-267deb988b5111321a1cf92c4d020334 +0 -0
  43. package/temp/test/jest/perf-cache-0104fb5fee08bd97aacd02300cdbf195-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
@@ -1,10 +1,11 @@
1
1
  import { encodePath } from '@yuants/utils';
2
2
  import { getTradeOrdersPending } from '../api/private-api';
3
+ import { mapOkxOrdTypeToOrderType } from '../orders/mapOkxOrdTypeToOrderType';
3
4
  export const getOrders = async function (credential) {
4
5
  const orders = [];
5
6
  const orderRes = await getTradeOrdersPending(credential, {});
6
7
  for (const x of orderRes.data || []) {
7
- const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
8
+ const order_type = mapOkxOrdTypeToOrderType(x.ordType);
8
9
  const order_direction = x.side === 'buy'
9
10
  ? x.posSide === 'long'
10
11
  ? 'OPEN_LONG'
@@ -1 +1 @@
1
- {"version":3,"file":"getOrders.js","sourceRoot":"","sources":["../../src/experimental/getOrders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAe,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAExE,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,WAAW,UAAuB;IAC9D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QAEnG,MAAM,eAAe,GACnB,CAAC,CAAC,IAAI,KAAK,KAAK;YACd,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM;gBACpB,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,aAAa;YACjB,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO;gBACvB,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,YAAY,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC;YACV,QAAQ,EAAE,CAAC,CAAC,KAAK;YACjB,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;YACnD,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK;YACnB,SAAS,EAAE,CAAC,CAAC,CAAC,QAAQ;YACtB,UAAU;YACV,eAAe;YACf,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;YACb,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS;YAC3B,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;YACZ,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK;SACvB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getTradeOrdersPending } from '../api/private-api';\n\nexport const getOrders = async function (credential: ICredential): Promise<IOrder[]> {\n const orders: IOrder[] = [];\n const orderRes = await getTradeOrdersPending(credential, {});\n\n for (const x of orderRes.data || []) {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n orders.push({\n order_id: x.ordId,\n account_id: '',\n product_id: encodePath('OKX', x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n });\n }\n\n return orders;\n};\n"]}
1
+ {"version":3,"file":"getOrders.js","sourceRoot":"","sources":["../../src/experimental/getOrders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAe,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAE9E,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,WAAW,UAAuB;IAC9D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,wBAAwB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAEvD,MAAM,eAAe,GACnB,CAAC,CAAC,IAAI,KAAK,KAAK;YACd,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM;gBACpB,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,aAAa;YACjB,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO;gBACvB,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,YAAY,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC;YACV,QAAQ,EAAE,CAAC,CAAC,KAAK;YACjB,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;YACnD,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK;YACnB,SAAS,EAAE,CAAC,CAAC,CAAC,QAAQ;YACtB,UAAU;YACV,eAAe;YACf,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;YACb,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS;YAC3B,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;YACZ,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK;SACvB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getTradeOrdersPending } from '../api/private-api';\nimport { mapOkxOrdTypeToOrderType } from '../orders/mapOkxOrdTypeToOrderType';\n\nexport const getOrders = async function (credential: ICredential): Promise<IOrder[]> {\n const orders: IOrder[] = [];\n const orderRes = await getTradeOrdersPending(credential, {});\n\n for (const x of orderRes.data || []) {\n const order_type = mapOkxOrdTypeToOrderType(x.ordType);\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n orders.push({\n order_id: x.ordId,\n account_id: '',\n product_id: encodePath('OKX', x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n });\n }\n\n return orders;\n};\n"]}
package/dist/order.js CHANGED
@@ -4,6 +4,7 @@ import { encodePath, formatTime } from '@yuants/utils';
4
4
  import { defer, from, map, merge, mergeMap, repeat, retry, shareReplay, Subject, tap } from 'rxjs';
5
5
  import { getDefaultCredential, getTradeOrdersHistory, getTradeOrdersPending } from './api/private-api';
6
6
  import { getTradingAccountId } from './accountInfos/uid';
7
+ import { mapOkxOrdTypeToOrderType } from './orders/mapOkxOrdTypeToOrderType';
7
8
  export const order$ = new Subject();
8
9
  const credential = getDefaultCredential();
9
10
  order$
@@ -38,7 +39,7 @@ writeToSQL({
38
39
  }))
39
40
  .subscribe();
40
41
  const makeOrder = (x, account_id) => {
41
- const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
42
+ const order_type = mapOkxOrdTypeToOrderType(x.ordType);
42
43
  const order_direction = x.side === 'buy'
43
44
  ? x.posSide === 'long'
44
45
  ? 'OPEN_LONG'
package/dist/order.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,OAAO,EAAU,CAAC;AAE5C,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;AAE1C,MAAM;KACH,IAAI;AACH,EAAE;AACF,sBAAsB;AACtB,UAAU,CAAC;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AEF,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,IAAI;IACpD,EAAE;IACF,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CACb,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI;IACrB,EAAE;IACF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAC7C,CACF,CACF,CAAC;IAEF,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,IAAI;IACpD,EAAE;IACF,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CACb,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI;IACrB,EAAE;IACF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAC7C,CACF,CACF,CAAC;IAEF,KAAK,CAAC,uBAAuB,EAAE,uBAAuB,CAAC;SACpD,IAAI;IACH,EAAE;IACF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACR,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CACH;SACA,SAAS,EAAE,CAAC;AACjB,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, from, map, merge, mergeMap, repeat, retry, shareReplay, Subject, tap } from 'rxjs';\nimport { getDefaultCredential, getTradeOrdersHistory, getTradeOrdersPending } from './api/private-api';\nimport { getTradingAccountId } from './accountInfos/uid';\n\nexport const order$ = new Subject<IOrder>();\n\nconst credential = getDefaultCredential();\n\norder$\n .pipe(\n //\n // mergeMap((x) => x),\n writeToSQL({\n terminal: Terminal.fromNodeEnv(),\n tableName: '\"order\"',\n writeInterval: 1000,\n columns: [\n 'order_id',\n 'account_id',\n 'product_id',\n 'position_id',\n 'order_type',\n 'order_direction',\n 'volume',\n 'submit_at',\n 'updated_at',\n 'filled_at',\n 'price',\n 'traded_volume',\n 'traded_price',\n 'order_status',\n 'comment',\n 'profit_correction',\n 'real_profit',\n 'inferred_base_currency_price',\n ],\n conflictKeys: ['account_id', 'order_id'],\n }),\n )\n .subscribe();\n\nconst makeOrder = (\n x: {\n ordType: string;\n side: string;\n posSide: string;\n instType: string;\n instId: string;\n cTime: string;\n uTime: string;\n fillTime: string;\n sz: string;\n accFillSz: string;\n px: string;\n avgPx: string;\n state: string;\n clOrdId: string;\n ordId: string;\n },\n account_id: string,\n): IOrder => {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n const order_status = ['live', 'partially_filled'].includes(x.state)\n ? 'ACCEPTED'\n : x.state === 'filled'\n ? 'TRADED'\n : 'CANCELLED';\n return {\n order_id: x.clOrdId !== '' ? x.clOrdId : x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n created_at: formatTime(+x.cTime),\n updated_at: formatTime(+x.uTime),\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n order_status,\n };\n};\n\n(async () => {\n const TRADING_ACCOUNT_ID = await getTradingAccountId(credential);\n\n const swapHistoryOrders = defer(() => getTradeOrdersHistory(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const swapPendingOrders = defer(() => getTradeOrdersPending(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const ordersFromHistoryOrder$ = swapHistoryOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n const ordersFromPendingOrder$ = swapPendingOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n merge(ordersFromHistoryOrder$, ordersFromPendingOrder$)\n .pipe(\n //\n tap((x) => {\n order$.next(x);\n }),\n )\n .subscribe();\n})();\n"]}
1
+ {"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,OAAO,EAAU,CAAC;AAE5C,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;AAE1C,MAAM;KACH,IAAI;AACH,EAAE;AACF,sBAAsB;AACtB,UAAU,CAAC;IACT,QAAQ,EAAE,QAAQ,CAAC,WAAW,EAAE;IAChC,SAAS,EAAE,SAAS;IACpB,aAAa,EAAE,IAAI;IACnB,OAAO,EAAE;QACP,UA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AAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAC7C,CACF,CACF,CAAC;IAEF,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,IAAI;IACpD,EAAE;IACF,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CACb,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI;IACrB,EAAE;IACF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAC7C,CACF,CACF,CAAC;IAEF,KAAK,CAAC,uBAAuB,EAAE,uBAAuB,CAAC;SACpD,IAAI;IACH,EAAE;IACF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACR,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CACH;SACA,SAAS,EAAE,CAAC;AACjB,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, from, map, merge, mergeMap, repeat, retry, shareReplay, Subject, tap } from 'rxjs';\nimport { getDefaultCredential, getTradeOrdersHistory, getTradeOrdersPending } from './api/private-api';\nimport { getTradingAccountId } from './accountInfos/uid';\nimport { mapOkxOrdTypeToOrderType } from './orders/mapOkxOrdTypeToOrderType';\n\nexport const order$ = new Subject<IOrder>();\n\nconst credential = getDefaultCredential();\n\norder$\n .pipe(\n //\n // mergeMap((x) => x),\n writeToSQL({\n terminal: Terminal.fromNodeEnv(),\n tableName: '\"order\"',\n writeInterval: 1000,\n columns: [\n 'order_id',\n 'account_id',\n 'product_id',\n 'position_id',\n 'order_type',\n 'order_direction',\n 'volume',\n 'submit_at',\n 'updated_at',\n 'filled_at',\n 'price',\n 'traded_volume',\n 'traded_price',\n 'order_status',\n 'comment',\n 'profit_correction',\n 'real_profit',\n 'inferred_base_currency_price',\n ],\n conflictKeys: ['account_id', 'order_id'],\n }),\n )\n .subscribe();\n\nconst makeOrder = (\n x: {\n ordType: string;\n side: string;\n posSide: string;\n instType: string;\n instId: string;\n cTime: string;\n uTime: string;\n fillTime: string;\n sz: string;\n accFillSz: string;\n px: string;\n avgPx: string;\n state: string;\n clOrdId: string;\n ordId: string;\n },\n account_id: string,\n): IOrder => {\n const order_type = mapOkxOrdTypeToOrderType(x.ordType);\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n const order_status = ['live', 'partially_filled'].includes(x.state)\n ? 'ACCEPTED'\n : x.state === 'filled'\n ? 'TRADED'\n : 'CANCELLED';\n return {\n order_id: x.clOrdId !== '' ? x.clOrdId : x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n created_at: formatTime(+x.cTime),\n updated_at: formatTime(+x.uTime),\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n order_status,\n };\n};\n\n(async () => {\n const TRADING_ACCOUNT_ID = await getTradingAccountId(credential);\n\n const swapHistoryOrders = defer(() => getTradeOrdersHistory(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const swapPendingOrders = defer(() => getTradeOrdersPending(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const ordersFromHistoryOrder$ = swapHistoryOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n const ordersFromPendingOrder$ = swapPendingOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n merge(ordersFromHistoryOrder$, ordersFromPendingOrder$)\n .pipe(\n //\n tap((x) => {\n order$.next(x);\n }),\n )\n .subscribe();\n})();\n"]}
@@ -1,12 +1,13 @@
1
1
  import { encodePath } from '@yuants/utils';
2
2
  import { getAccountIds } from '../accountInfos/uid';
3
3
  import { getTradeOrdersPending } from '../api/private-api';
4
+ import { mapOkxOrdTypeToOrderType } from './mapOkxOrdTypeToOrderType';
4
5
  export const listOrders = async (credential, account_id) => {
5
6
  const accountIds = await getAccountIds(credential);
6
7
  if ((accountIds === null || accountIds === void 0 ? void 0 : accountIds.trading) === account_id) {
7
8
  const orderRes = await getTradeOrdersPending(credential, {});
8
9
  return orderRes.data.map((x) => {
9
- const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
10
+ const order_type = mapOkxOrdTypeToOrderType(x.ordType);
10
11
  const order_direction = x.side === 'buy'
11
12
  ? x.posSide === 'long'
12
13
  ? 'OPEN_LONG'
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../src/orders/listOrders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAuB,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAe,MAAM,oBAAoB,CAAC;AAExE,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAqB,EAAE;IACjG,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;IACnD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,MAAK,UAAU,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC7B,MAAM,UAAU,GAAG,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;YAEnG,MAAM,eAAe,GACnB,CAAC,CAAC,IAAI,KAAK,KAAK;gBACd,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM;oBACpB,CAAC,CAAC,WAAW;oBACb,CAAC,CAAC,aAAa;gBACjB,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO;oBACvB,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,YAAY,CAAC;YACnB,OAAO;gBACL,QAAQ,EAAE,CAAC,CAAC,KAAK;gBACjB,UAAU;gBACV,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;gBAC5C,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK;gBACnB,SAAS,EAAE,CAAC,CAAC,CAAC,QAAQ;gBACtB,UAAU;gBACV,eAAe;gBACf,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;gBACb,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS;gBAC3B,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;gBACZ,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK;aACvB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,cAAc,UAAU,qCAAqC,CAAC,CAAC;AACjF,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { encodePath } from '@yuants/utils';\nimport { getAccountIds, getTradingAccountId } from '../accountInfos/uid';\nimport { getTradeOrdersPending, ICredential } from '../api/private-api';\n\nexport const listOrders = async (credential: ICredential, account_id: string): Promise<IOrder[]> => {\n const accountIds = await getAccountIds(credential);\n if (accountIds?.trading === account_id) {\n const orderRes = await getTradeOrdersPending(credential, {});\n return orderRes.data.map((x) => {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n return {\n order_id: x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n };\n });\n }\n throw new Error(`Account ID ${account_id} not found or not a trading account`);\n};\n"]}
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../src/orders/listOrders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAuB,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAe,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAqB,EAAE;IACjG,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;IACnD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,MAAK,UAAU,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC7B,MAAM,UAAU,GAAG,wBAAwB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAEvD,MAAM,eAAe,GACnB,CAAC,CAAC,IAAI,KAAK,KAAK;gBACd,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM;oBACpB,CAAC,CAAC,WAAW;oBACb,CAAC,CAAC,aAAa;gBACjB,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO;oBACvB,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,YAAY,CAAC;YACnB,OAAO;gBACL,QAAQ,EAAE,CAAC,CAAC,KAAK;gBACjB,UAAU;gBACV,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;gBAC5C,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK;gBACnB,SAAS,EAAE,CAAC,CAAC,CAAC,QAAQ;gBACtB,UAAU;gBACV,eAAe;gBACf,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;gBACb,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS;gBAC3B,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;gBACZ,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK;aACvB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,cAAc,UAAU,qCAAqC,CAAC,CAAC;AACjF,CAAC,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { encodePath } from '@yuants/utils';\nimport { getAccountIds, getTradingAccountId } from '../accountInfos/uid';\nimport { getTradeOrdersPending, ICredential } from '../api/private-api';\nimport { mapOkxOrdTypeToOrderType } from './mapOkxOrdTypeToOrderType';\n\nexport const listOrders = async (credential: ICredential, account_id: string): Promise<IOrder[]> => {\n const accountIds = await getAccountIds(credential);\n if (accountIds?.trading === account_id) {\n const orderRes = await getTradeOrdersPending(credential, {});\n return orderRes.data.map((x) => {\n const order_type = mapOkxOrdTypeToOrderType(x.ordType);\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n return {\n order_id: x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n };\n });\n }\n throw new Error(`Account ID ${account_id} not found or not a trading account`);\n};\n"]}
@@ -0,0 +1,17 @@
1
+ export const mapOkxOrdTypeToOrderType = (ordType) => {
2
+ switch (ordType) {
3
+ case 'market':
4
+ return 'MARKET';
5
+ case 'limit':
6
+ return 'LIMIT';
7
+ case 'post_only':
8
+ return 'MAKER';
9
+ case 'ioc':
10
+ return 'IOC';
11
+ case 'fok':
12
+ return 'FOK';
13
+ default:
14
+ return 'UNKNOWN';
15
+ }
16
+ };
17
+ //# sourceMappingURL=mapOkxOrdTypeToOrderType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOkxOrdTypeToOrderType.js","sourceRoot":"","sources":["../../src/orders/mapOkxOrdTypeToOrderType.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC3D,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,WAAW;YACd,OAAO,OAAO,CAAC;QACjB,KAAK,KAAK;YACR,OAAO,KAAK,CAAC;QACf,KAAK,KAAK;YACR,OAAO,KAAK,CAAC;QACf;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC,CAAC","sourcesContent":["export const mapOkxOrdTypeToOrderType = (ordType?: string) => {\n switch (ordType) {\n case 'market':\n return 'MARKET';\n case 'limit':\n return 'LIMIT';\n case 'post_only':\n return 'MAKER';\n case 'ioc':\n return 'IOC';\n case 'fok':\n return 'FOK';\n default:\n return 'UNKNOWN';\n }\n};\n"]}
@@ -0,0 +1,16 @@
1
+ export const mapOrderTypeToOrdType = (orderType) => {
2
+ switch (orderType) {
3
+ case 'LIMIT':
4
+ return 'limit';
5
+ case 'MARKET':
6
+ return 'market';
7
+ case 'MAKER':
8
+ return 'post_only';
9
+ case 'IOC':
10
+ return 'ioc';
11
+ case 'FOK':
12
+ return 'fok';
13
+ }
14
+ throw new Error(`Unknown order type: ${orderType}`);
15
+ };
16
+ //# sourceMappingURL=mapOrderTypeToOrdType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOrderTypeToOrdType.js","sourceRoot":"","sources":["../../src/orders/mapOrderTypeToOrdType.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,SAAkB,EAAE,EAAE;IAC1D,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,OAAO;YACV,OAAO,WAAW,CAAC;QACrB,KAAK,KAAK;YACR,OAAO,KAAK,CAAC;QACf,KAAK,KAAK;YACR,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,uBAAuB,SAAS,EAAE,CAAC,CAAC;AACtD,CAAC,CAAC","sourcesContent":["export const mapOrderTypeToOrdType = (orderType?: string) => {\n switch (orderType) {\n case 'LIMIT':\n return 'limit';\n case 'MARKET':\n return 'market';\n case 'MAKER':\n return 'post_only';\n case 'IOC':\n return 'ioc';\n case 'FOK':\n return 'fok';\n }\n\n throw new Error(`Unknown order type: ${orderType}`);\n};\n"]}
@@ -0,0 +1,171 @@
1
+ import { encodePath } from '@yuants/utils';
2
+ jest.mock('../accountInfos/uid', () => ({
3
+ accountConfigCache: {
4
+ query: jest.fn(),
5
+ },
6
+ getAccountIds: jest.fn(),
7
+ }));
8
+ jest.mock('../api/private-api', () => ({
9
+ postTradeOrder: jest.fn(),
10
+ getTradeOrdersPending: jest.fn(),
11
+ }));
12
+ jest.mock('../public-data/product', () => ({
13
+ productService: {
14
+ mapProductIdToProduct$: {
15
+ pipe: jest.fn(),
16
+ },
17
+ },
18
+ }));
19
+ jest.mock('../public-data/quote', () => ({
20
+ spotMarketTickers$: {
21
+ pipe: jest.fn(),
22
+ },
23
+ }));
24
+ import { accountConfigCache } from '../accountInfos/uid';
25
+ import { getAccountIds } from '../accountInfos/uid';
26
+ import { getTradeOrdersPending, postTradeOrder } from '../api/private-api';
27
+ import { getOrders } from '../experimental/getOrders';
28
+ import { listOrders } from './listOrders';
29
+ import { mapOkxOrdTypeToOrderType } from './mapOkxOrdTypeToOrderType';
30
+ import { mapOrderTypeToOrdType } from './mapOrderTypeToOrdType';
31
+ import { submitOrder } from './submitOrder';
32
+ const mockedAccountConfigCache = jest.mocked(accountConfigCache);
33
+ const mockedGetAccountIds = jest.mocked(getAccountIds);
34
+ const mockedGetTradeOrdersPending = jest.mocked(getTradeOrdersPending);
35
+ const mockedPostTradeOrder = jest.mocked(postTradeOrder);
36
+ describe('mapOrderTypeToOrdType', () => {
37
+ test('maps IOC and FOK to OKX ordType values', () => {
38
+ expect(mapOrderTypeToOrdType('IOC')).toBe('ioc');
39
+ expect(mapOrderTypeToOrdType('FOK')).toBe('fok');
40
+ });
41
+ });
42
+ describe('mapOkxOrdTypeToOrderType', () => {
43
+ test('maps OKX ordType values back to Yuan order types', () => {
44
+ expect(mapOkxOrdTypeToOrderType('market')).toBe('MARKET');
45
+ expect(mapOkxOrdTypeToOrderType('limit')).toBe('LIMIT');
46
+ expect(mapOkxOrdTypeToOrderType('post_only')).toBe('MAKER');
47
+ expect(mapOkxOrdTypeToOrderType('ioc')).toBe('IOC');
48
+ expect(mapOkxOrdTypeToOrderType('fok')).toBe('FOK');
49
+ });
50
+ test('returns UNKNOWN for unsupported ordType', () => {
51
+ expect(mapOkxOrdTypeToOrderType('not_a_real_okx_ord_type')).toBe('UNKNOWN');
52
+ });
53
+ });
54
+ describe('submitOrder', () => {
55
+ beforeEach(() => {
56
+ jest.resetAllMocks();
57
+ mockedAccountConfigCache.query.mockResolvedValue({
58
+ code: '0',
59
+ msg: '',
60
+ data: [{ acctLv: '1', posMode: 'net_mode' }],
61
+ });
62
+ mockedPostTradeOrder.mockResolvedValue({
63
+ code: '0',
64
+ msg: '',
65
+ data: [{ ordId: 'order-1', clOrdId: '', tag: '', sCode: '0', sMsg: '' }],
66
+ inTime: '',
67
+ outTime: '',
68
+ });
69
+ });
70
+ test.each([
71
+ ['IOC', 'ioc'],
72
+ ['FOK', 'fok'],
73
+ ])('maps %s orders to OKX ordType %s when submitting', async (orderType, ordType) => {
74
+ await expect(submitOrder({ access_key: 'ak', secret_key: 'sk', passphrase: 'pp' }, {
75
+ account_id: 'okx/test/trading',
76
+ product_id: encodePath('MARGIN', 'BTC-USDT'),
77
+ order_type: orderType,
78
+ order_direction: 'OPEN_LONG',
79
+ volume: 1,
80
+ price: 12345,
81
+ })).resolves.toEqual({ order_id: 'order-1' });
82
+ expect(mockedPostTradeOrder).toHaveBeenCalledWith({ access_key: 'ak', secret_key: 'sk', passphrase: 'pp' }, expect.objectContaining({ ordType, px: '12345', sz: '1' }));
83
+ });
84
+ });
85
+ describe('order readback mapping', () => {
86
+ beforeEach(() => {
87
+ jest.resetAllMocks();
88
+ });
89
+ test('listOrders maps IOC and FOK ordType values via shared readback mapping', async () => {
90
+ mockedGetAccountIds.mockResolvedValue({ trading: 'okx/test/trading' });
91
+ mockedGetTradeOrdersPending.mockResolvedValue({
92
+ code: '0',
93
+ msg: '',
94
+ data: [
95
+ {
96
+ ordId: 'ioc-order',
97
+ ordType: 'ioc',
98
+ side: 'buy',
99
+ posSide: 'long',
100
+ instType: 'SWAP',
101
+ instId: 'BTC-USDT-SWAP',
102
+ cTime: '1',
103
+ fillTime: '0',
104
+ sz: '2',
105
+ accFillSz: '1',
106
+ px: '100',
107
+ avgPx: '101',
108
+ },
109
+ {
110
+ ordId: 'fok-order',
111
+ ordType: 'fok',
112
+ side: 'sell',
113
+ posSide: 'short',
114
+ instType: 'SWAP',
115
+ instId: 'ETH-USDT-SWAP',
116
+ cTime: '2',
117
+ fillTime: '0',
118
+ sz: '3',
119
+ accFillSz: '0',
120
+ px: '200',
121
+ avgPx: '0',
122
+ },
123
+ ],
124
+ });
125
+ await expect(listOrders({ access_key: 'ak', secret_key: 'sk', passphrase: 'pp' }, 'okx/test/trading')).resolves.toMatchObject([
126
+ { order_id: 'ioc-order', order_type: 'IOC' },
127
+ { order_id: 'fok-order', order_type: 'FOK' },
128
+ ]);
129
+ });
130
+ test('getOrders maps IOC and FOK ordType values via shared readback mapping', async () => {
131
+ mockedGetTradeOrdersPending.mockResolvedValue({
132
+ code: '0',
133
+ msg: '',
134
+ data: [
135
+ {
136
+ ordId: 'ioc-order',
137
+ ordType: 'ioc',
138
+ side: 'buy',
139
+ posSide: 'long',
140
+ instType: 'SWAP',
141
+ instId: 'BTC-USDT-SWAP',
142
+ cTime: '1',
143
+ fillTime: '0',
144
+ sz: '2',
145
+ accFillSz: '1',
146
+ px: '100',
147
+ avgPx: '101',
148
+ },
149
+ {
150
+ ordId: 'fok-order',
151
+ ordType: 'fok',
152
+ side: 'sell',
153
+ posSide: 'short',
154
+ instType: 'SWAP',
155
+ instId: 'ETH-USDT-SWAP',
156
+ cTime: '2',
157
+ fillTime: '0',
158
+ sz: '3',
159
+ accFillSz: '0',
160
+ px: '200',
161
+ avgPx: '0',
162
+ },
163
+ ],
164
+ });
165
+ await expect(getOrders({ access_key: 'ak', secret_key: 'sk', passphrase: 'pp' })).resolves.toMatchObject([
166
+ { order_id: 'ioc-order', order_type: 'IOC' },
167
+ { order_id: 'fok-order', order_type: 'FOK' },
168
+ ]);
169
+ });
170
+ });
171
+ //# sourceMappingURL=order-type-mapping.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-type-mapping.test.js","sourceRoot":"","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AG;iBACX;aACF;SACO,CAAC,CAAC;QAEZ,MAAM,MAAM,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC;YACvG,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE;YAC5C,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE;SAC7C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { encodePath } from '@yuants/utils';\n\njest.mock('../accountInfos/uid', () => ({\n accountConfigCache: {\n query: jest.fn(),\n },\n getAccountIds: jest.fn(),\n}));\n\njest.mock('../api/private-api', () => ({\n postTradeOrder: jest.fn(),\n getTradeOrdersPending: jest.fn(),\n}));\n\njest.mock('../public-data/product', () => ({\n productService: {\n mapProductIdToProduct$: {\n pipe: jest.fn(),\n },\n },\n}));\n\njest.mock('../public-data/quote', () => ({\n spotMarketTickers$: {\n pipe: jest.fn(),\n },\n}));\n\nimport { accountConfigCache } from '../accountInfos/uid';\nimport { getAccountIds } from '../accountInfos/uid';\nimport { getTradeOrdersPending, postTradeOrder } from '../api/private-api';\nimport { getOrders } from '../experimental/getOrders';\nimport { listOrders } from './listOrders';\nimport { mapOkxOrdTypeToOrderType } from './mapOkxOrdTypeToOrderType';\nimport { mapOrderTypeToOrdType } from './mapOrderTypeToOrdType';\nimport { submitOrder } from './submitOrder';\n\nconst mockedAccountConfigCache = jest.mocked(accountConfigCache);\nconst mockedGetAccountIds = jest.mocked(getAccountIds);\nconst mockedGetTradeOrdersPending = jest.mocked(getTradeOrdersPending);\nconst mockedPostTradeOrder = jest.mocked(postTradeOrder);\n\ndescribe('mapOrderTypeToOrdType', () => {\n test('maps IOC and FOK to OKX ordType values', () => {\n expect(mapOrderTypeToOrdType('IOC')).toBe('ioc');\n expect(mapOrderTypeToOrdType('FOK')).toBe('fok');\n });\n});\n\ndescribe('mapOkxOrdTypeToOrderType', () => {\n test('maps OKX ordType values back to Yuan order types', () => {\n expect(mapOkxOrdTypeToOrderType('market')).toBe('MARKET');\n expect(mapOkxOrdTypeToOrderType('limit')).toBe('LIMIT');\n expect(mapOkxOrdTypeToOrderType('post_only')).toBe('MAKER');\n expect(mapOkxOrdTypeToOrderType('ioc')).toBe('IOC');\n expect(mapOkxOrdTypeToOrderType('fok')).toBe('FOK');\n });\n\n test('returns UNKNOWN for unsupported ordType', () => {\n expect(mapOkxOrdTypeToOrderType('not_a_real_okx_ord_type')).toBe('UNKNOWN');\n });\n});\n\ndescribe('submitOrder', () => {\n beforeEach(() => {\n jest.resetAllMocks();\n\n mockedAccountConfigCache.query.mockResolvedValue({\n code: '0',\n msg: '',\n data: [{ acctLv: '1', posMode: 'net_mode' }],\n } as never);\n\n mockedPostTradeOrder.mockResolvedValue({\n code: '0',\n msg: '',\n data: [{ ordId: 'order-1', clOrdId: '', tag: '', sCode: '0', sMsg: '' }],\n inTime: '',\n outTime: '',\n });\n });\n\n test.each([\n ['IOC', 'ioc'],\n ['FOK', 'fok'],\n ])('maps %s orders to OKX ordType %s when submitting', async (orderType, ordType) => {\n await expect(\n submitOrder(\n { access_key: 'ak', secret_key: 'sk', passphrase: 'pp' },\n {\n account_id: 'okx/test/trading',\n product_id: encodePath('MARGIN', 'BTC-USDT'),\n order_type: orderType,\n order_direction: 'OPEN_LONG',\n volume: 1,\n price: 12345,\n },\n ),\n ).resolves.toEqual({ order_id: 'order-1' });\n\n expect(mockedPostTradeOrder).toHaveBeenCalledWith(\n { access_key: 'ak', secret_key: 'sk', passphrase: 'pp' },\n expect.objectContaining({ ordType, px: '12345', sz: '1' }),\n );\n });\n});\n\ndescribe('order readback mapping', () => {\n beforeEach(() => {\n jest.resetAllMocks();\n });\n\n test('listOrders maps IOC and FOK ordType values via shared readback mapping', async () => {\n mockedGetAccountIds.mockResolvedValue({ trading: 'okx/test/trading' } as never);\n mockedGetTradeOrdersPending.mockResolvedValue({\n code: '0',\n msg: '',\n data: [\n {\n ordId: 'ioc-order',\n ordType: 'ioc',\n side: 'buy',\n posSide: 'long',\n instType: 'SWAP',\n instId: 'BTC-USDT-SWAP',\n cTime: '1',\n fillTime: '0',\n sz: '2',\n accFillSz: '1',\n px: '100',\n avgPx: '101',\n },\n {\n ordId: 'fok-order',\n ordType: 'fok',\n side: 'sell',\n posSide: 'short',\n instType: 'SWAP',\n instId: 'ETH-USDT-SWAP',\n cTime: '2',\n fillTime: '0',\n sz: '3',\n accFillSz: '0',\n px: '200',\n avgPx: '0',\n },\n ],\n } as never);\n\n await expect(\n listOrders({ access_key: 'ak', secret_key: 'sk', passphrase: 'pp' }, 'okx/test/trading'),\n ).resolves.toMatchObject([\n { order_id: 'ioc-order', order_type: 'IOC' },\n { order_id: 'fok-order', order_type: 'FOK' },\n ]);\n });\n\n test('getOrders maps IOC and FOK ordType values via shared readback mapping', async () => {\n mockedGetTradeOrdersPending.mockResolvedValue({\n code: '0',\n msg: '',\n data: [\n {\n ordId: 'ioc-order',\n ordType: 'ioc',\n side: 'buy',\n posSide: 'long',\n instType: 'SWAP',\n instId: 'BTC-USDT-SWAP',\n cTime: '1',\n fillTime: '0',\n sz: '2',\n accFillSz: '1',\n px: '100',\n avgPx: '101',\n },\n {\n ordId: 'fok-order',\n ordType: 'fok',\n side: 'sell',\n posSide: 'short',\n instType: 'SWAP',\n instId: 'ETH-USDT-SWAP',\n cTime: '2',\n fillTime: '0',\n sz: '3',\n accFillSz: '0',\n px: '200',\n avgPx: '0',\n },\n ],\n } as never);\n\n await expect(getOrders({ access_key: 'ak', secret_key: 'sk', passphrase: 'pp' })).resolves.toMatchObject([\n { order_id: 'ioc-order', order_type: 'IOC' },\n { order_id: 'fok-order', order_type: 'FOK' },\n ]);\n });\n});\n"]}
@@ -4,6 +4,7 @@ import { accountConfigCache } from '../accountInfos/uid';
4
4
  import { postTradeOrder } from '../api/private-api';
5
5
  import { productService } from '../public-data/product';
6
6
  import { spotMarketTickers$ } from '../public-data/quote';
7
+ import { mapOrderTypeToOrdType } from './mapOrderTypeToOrdType';
7
8
  const mapOrderDirectionToSide = (direction) => {
8
9
  switch (direction) {
9
10
  case 'OPEN_LONG':
@@ -15,17 +16,7 @@ const mapOrderDirectionToSide = (direction) => {
15
16
  }
16
17
  throw new Error(`Unknown direction: ${direction}`);
17
18
  };
18
- const mapOrderTypeToOrdType = (order_type) => {
19
- switch (order_type) {
20
- case 'LIMIT':
21
- return 'limit';
22
- case 'MARKET':
23
- return 'market';
24
- case 'MAKER':
25
- return 'post_only';
26
- }
27
- throw new Error(`Unknown order type: ${order_type}`);
28
- };
19
+ const isPricedOrderType = (orderType) => ['LIMIT', 'MAKER', 'IOC', 'FOK'].includes(orderType !== null && orderType !== void 0 ? orderType : '');
29
20
  export const submitOrder = async (credential, order) => {
30
21
  var _a, _b, _c, _d;
31
22
  const accountConfigRes = await accountConfigCache.query(JSON.stringify(credential));
@@ -53,10 +44,7 @@ export const submitOrder = async (credential, order) => {
53
44
  return order.volume;
54
45
  }
55
46
  if (instType === 'MARGIN') {
56
- if (order.order_type === 'LIMIT') {
57
- return order.volume;
58
- }
59
- if (order.order_type === 'MAKER') {
47
+ if (isPricedOrderType(order.order_type)) {
60
48
  return order.volume;
61
49
  }
62
50
  if (order.order_type === 'MARKET') {
@@ -110,7 +98,7 @@ export const submitOrder = async (credential, order) => {
110
98
  reduceOnly: instType === 'MARGIN' && ['CLOSE_LONG', 'CLOSE_SHORT'].includes((_b = order.order_direction) !== null && _b !== void 0 ? _b : '')
111
99
  ? 'true'
112
100
  : undefined,
113
- px: order.order_type === 'LIMIT' || order.order_type === 'MAKER' ? order.price.toString() : undefined,
101
+ px: isPricedOrderType(order.order_type) ? order.price.toString() : undefined,
114
102
  ccy: instType === 'MARGIN' ? 'USDT' : undefined,
115
103
  tag: process.env.BROKER_CODE,
116
104
  };
@@ -1 +1 @@
1
- {"version":3,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,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,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,CAAC;QAC7C,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC;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, newError, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { accountConfigCache } from '../accountInfos/uid';\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 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 accountConfigRes = await accountConfigCache.query(JSON.stringify(credential));\n if (!accountConfigRes) throw newError('ACCOUNT_CONFIG_FETCH_ERROR', { accountConfigRes });\n if (!accountConfigRes.data?.[0]) throw newError('ACCOUNT_CONFIG_FETCH_ERROR', { accountConfigRes });\n\n /**\n * 是否为组合保证金模式\n */\n const isPortfolioMarginMode = accountConfigRes.data[0].acctLv === '4';\n /**\n * 是否为单向持仓模式(买卖模式)\n */\n const isSingleSideMode = accountConfigRes.data[0].posMode === 'net_mode';\n\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 mapOrderDirectionToPosSide = (direction?: string) => {\n if (isPortfolioMarginMode) return undefined;\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\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n isSingleSideMode || instType === 'MARGIN' || instType === 'SPOT'\n ? undefined\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"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../src/orders/submitOrder.ts"],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AAC,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,CAAC;QAC7C,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC;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, newError, roundToStep } from '@yuants/utils';\nimport { firstValueFrom, map } from 'rxjs';\nimport { accountConfigCache } from '../accountInfos/uid';\nimport { ICredential, postTradeOrder } from '../api/private-api';\nimport { productService } from '../public-data/product';\nimport { spotMarketTickers$ } from '../public-data/quote';\nimport { mapOrderTypeToOrdType } from './mapOrderTypeToOrdType';\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 isPricedOrderType = (orderType?: string) => ['LIMIT', 'MAKER', 'IOC', 'FOK'].includes(orderType ?? '');\n\nexport const submitOrder = async (credential: ICredential, order: IOrder): Promise<{ order_id: string }> => {\n const accountConfigRes = await accountConfigCache.query(JSON.stringify(credential));\n if (!accountConfigRes) throw newError('ACCOUNT_CONFIG_FETCH_ERROR', { accountConfigRes });\n if (!accountConfigRes.data?.[0]) throw newError('ACCOUNT_CONFIG_FETCH_ERROR', { accountConfigRes });\n\n /**\n * 是否为组合保证金模式\n */\n const isPortfolioMarginMode = accountConfigRes.data[0].acctLv === '4';\n /**\n * 是否为单向持仓模式(买卖模式)\n */\n const isSingleSideMode = accountConfigRes.data[0].posMode === 'net_mode';\n\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 (isPricedOrderType(order.order_type)) {\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 mapOrderDirectionToPosSide = (direction?: string) => {\n if (isPortfolioMarginMode) return undefined;\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\n const params = {\n instId,\n tdMode: instType === 'SPOT' ? 'cash' : 'cross',\n side: mapOrderDirectionToSide(order.order_direction),\n posSide:\n isSingleSideMode || instType === 'MARGIN' || instType === 'SPOT'\n ? undefined\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: isPricedOrderType(order.order_type) ? 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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"getOrders.d.ts","sourceRoot":"","sources":["../../src/experimental/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAyB,MAAM,oBAAoB,CAAC;AAExE,eAAO,MAAM,SAAS,GAAmB,YAAY,WAAW,KAAG,OAAO,CAAC,MAAM,EAAE,CA+BlF,CAAC"}
1
+ {"version":3,"file":"getOrders.d.ts","sourceRoot":"","sources":["../../src/experimental/getOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAyB,MAAM,oBAAoB,CAAC;AAGxE,eAAO,MAAM,SAAS,GAAmB,YAAY,WAAW,KAAG,OAAO,CAAC,MAAM,EAAE,CA+BlF,CAAC"}
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getOrders = void 0;
4
4
  const utils_1 = require("@yuants/utils");
5
5
  const private_api_1 = require("../api/private-api");
6
+ const mapOkxOrdTypeToOrderType_1 = require("../orders/mapOkxOrdTypeToOrderType");
6
7
  const getOrders = async function (credential) {
7
8
  const orders = [];
8
9
  const orderRes = await (0, private_api_1.getTradeOrdersPending)(credential, {});
9
10
  for (const x of orderRes.data || []) {
10
- const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
11
+ const order_type = (0, mapOkxOrdTypeToOrderType_1.mapOkxOrdTypeToOrderType)(x.ordType);
11
12
  const order_direction = x.side === 'buy'
12
13
  ? x.posSide === 'long'
13
14
  ? 'OPEN_LONG'
@@ -1 +1 @@
1
- {"version":3,"file":"getOrders.js","sourceRoot":"","sources":["../../src/experimental/getOrders.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,oDAAwE;AAEjE,MAAM,SAAS,GAAG,KAAK,WAAW,UAAuB;IAC9D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QAEnG,MAAM,eAAe,GACnB,CAAC,CAAC,IAAI,KAAK,KAAK;YACd,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM;gBACpB,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,aAAa;YACjB,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO;gBACvB,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,YAAY,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC;YACV,QAAQ,EAAE,CAAC,CAAC,KAAK;YACjB,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,IAAA,kBAAU,EAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;YACnD,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK;YACnB,SAAS,EAAE,CAAC,CAAC,CAAC,QAAQ;YACtB,UAAU;YACV,eAAe;YACf,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;YACb,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS;YAC3B,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;YACZ,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK;SACvB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA/BW,QAAA,SAAS,aA+BpB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getTradeOrdersPending } from '../api/private-api';\n\nexport const getOrders = async function (credential: ICredential): Promise<IOrder[]> {\n const orders: IOrder[] = [];\n const orderRes = await getTradeOrdersPending(credential, {});\n\n for (const x of orderRes.data || []) {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n orders.push({\n order_id: x.ordId,\n account_id: '',\n product_id: encodePath('OKX', x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n });\n }\n\n return orders;\n};\n"]}
1
+ {"version":3,"file":"getOrders.js","sourceRoot":"","sources":["../../src/experimental/getOrders.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,oDAAwE;AACxE,iFAA8E;AAEvE,MAAM,SAAS,GAAG,KAAK,WAAW,UAAuB;IAC9D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,IAAA,mDAAwB,EAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAEvD,MAAM,eAAe,GACnB,CAAC,CAAC,IAAI,KAAK,KAAK;YACd,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM;gBACpB,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,aAAa;YACjB,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO;gBACvB,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,YAAY,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC;YACV,QAAQ,EAAE,CAAC,CAAC,KAAK;YACjB,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,IAAA,kBAAU,EAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;YACnD,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK;YACnB,SAAS,EAAE,CAAC,CAAC,CAAC,QAAQ;YACtB,UAAU;YACV,eAAe;YACf,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;YACb,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS;YAC3B,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;YACZ,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK;SACvB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA/BW,QAAA,SAAS,aA+BpB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getTradeOrdersPending } from '../api/private-api';\nimport { mapOkxOrdTypeToOrderType } from '../orders/mapOkxOrdTypeToOrderType';\n\nexport const getOrders = async function (credential: ICredential): Promise<IOrder[]> {\n const orders: IOrder[] = [];\n const orderRes = await getTradeOrdersPending(credential, {});\n\n for (const x of orderRes.data || []) {\n const order_type = mapOkxOrdTypeToOrderType(x.ordType);\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n orders.push({\n order_id: x.ordId,\n account_id: '',\n product_id: encodePath('OKX', x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n });\n }\n\n return orders;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,OAAO,EAAiE,OAAO,EAAO,MAAM,MAAM,CAAC;AAInG,eAAO,MAAM,MAAM,iBAAwB,CAAC"}
1
+ {"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,OAAO,EAAiE,OAAO,EAAO,MAAM,MAAM,CAAC;AAKnG,eAAO,MAAM,MAAM,iBAAwB,CAAC"}
package/lib/order.js CHANGED
@@ -7,6 +7,7 @@ const utils_1 = require("@yuants/utils");
7
7
  const rxjs_1 = require("rxjs");
8
8
  const private_api_1 = require("./api/private-api");
9
9
  const uid_1 = require("./accountInfos/uid");
10
+ const mapOkxOrdTypeToOrderType_1 = require("./orders/mapOkxOrdTypeToOrderType");
10
11
  exports.order$ = new rxjs_1.Subject();
11
12
  const credential = (0, private_api_1.getDefaultCredential)();
12
13
  exports.order$
@@ -41,7 +42,7 @@ exports.order$
41
42
  }))
42
43
  .subscribe();
43
44
  const makeOrder = (x, account_id) => {
44
- const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
45
+ const order_type = (0, mapOkxOrdTypeToOrderType_1.mapOkxOrdTypeToOrderType)(x.ordType);
45
46
  const order_direction = x.side === 'buy'
46
47
  ? x.posSide === 'long'
47
48
  ? 'OPEN_LONG'
package/lib/order.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAAmG;AACnG,mDAAuG;AACvG,4CAAyD;AAE5C,QAAA,MAAM,GAAG,IAAI,cAAO,EAAU,CAAC;AAE5C,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,cAAM;KACH,IAAI;AACH,EAAE;AACF,sBAAsB;AACtB,IAAA,gBAAU,EAAC;IACT,QAAQ,EAAE,mBAAQ,CAAC,WAAW,EAAE;IAChC,SAAS,EAAE,SAAS;IACpB,aAAa,EAAE,IAAI;IACnB,OAAO,EAAE;QACP,UAAU;QACV,YAAY;QACZ,YAAY;QACZ,aAAa;QACb,YAAY;QACZ,iBAAiB;QACjB,QAAQ;QACR,WAAW;QACX,YAAY;QACZ,WAAW;QACX,OAAO;QACP,eAAe;QACf,cAAc;QACd,cAA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ACrB,EAAE;IACF,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAC7C,CACF,CACF,CAAC;IAEF,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,IAAI;IACpD,EAAE;IACF,IAAA,eAAQ,EAAC,CAAC,CAAC,EAAE,EAAE,CACb,IAAA,WAAI,EAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI;IACrB,EAAE;IACF,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAC7C,CACF,CACF,CAAC;IAEF,IAAA,YAAK,EAAC,uBAAuB,EAAE,uBAAuB,CAAC;SACpD,IAAI;IACH,EAAE;IACF,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE;QACR,cAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CACH;SACA,SAAS,EAAE,CAAC;AACjB,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, from, map, merge, mergeMap, repeat, retry, shareReplay, Subject, tap } from 'rxjs';\nimport { getDefaultCredential, getTradeOrdersHistory, getTradeOrdersPending } from './api/private-api';\nimport { getTradingAccountId } from './accountInfos/uid';\n\nexport const order$ = new Subject<IOrder>();\n\nconst credential = getDefaultCredential();\n\norder$\n .pipe(\n //\n // mergeMap((x) => x),\n writeToSQL({\n terminal: Terminal.fromNodeEnv(),\n tableName: '\"order\"',\n writeInterval: 1000,\n columns: [\n 'order_id',\n 'account_id',\n 'product_id',\n 'position_id',\n 'order_type',\n 'order_direction',\n 'volume',\n 'submit_at',\n 'updated_at',\n 'filled_at',\n 'price',\n 'traded_volume',\n 'traded_price',\n 'order_status',\n 'comment',\n 'profit_correction',\n 'real_profit',\n 'inferred_base_currency_price',\n ],\n conflictKeys: ['account_id', 'order_id'],\n }),\n )\n .subscribe();\n\nconst makeOrder = (\n x: {\n ordType: string;\n side: string;\n posSide: string;\n instType: string;\n instId: string;\n cTime: string;\n uTime: string;\n fillTime: string;\n sz: string;\n accFillSz: string;\n px: string;\n avgPx: string;\n state: string;\n clOrdId: string;\n ordId: string;\n },\n account_id: string,\n): IOrder => {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n const order_status = ['live', 'partially_filled'].includes(x.state)\n ? 'ACCEPTED'\n : x.state === 'filled'\n ? 'TRADED'\n : 'CANCELLED';\n return {\n order_id: x.clOrdId !== '' ? x.clOrdId : x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n created_at: formatTime(+x.cTime),\n updated_at: formatTime(+x.uTime),\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n order_status,\n };\n};\n\n(async () => {\n const TRADING_ACCOUNT_ID = await getTradingAccountId(credential);\n\n const swapHistoryOrders = defer(() => getTradeOrdersHistory(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const swapPendingOrders = defer(() => getTradeOrdersPending(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const ordersFromHistoryOrder$ = swapHistoryOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n const ordersFromPendingOrder$ = swapPendingOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n merge(ordersFromHistoryOrder$, ordersFromPendingOrder$)\n .pipe(\n //\n tap((x) => {\n order$.next(x);\n }),\n )\n .subscribe();\n})();\n"]}
1
+ {"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAAmG;AACnG,mDAAuG;AACvG,4CAAyD;AACzD,gFAA6E;AAEhE,QAAA,MAAM,GAAG,IAAI,cAAO,EAAU,CAAC;AAE5C,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,cAAM;KACH,IAAI;AACH,EAAE;AACF,sBAAsB;AACtB,IAAA,gBAAU,EAAC;IACT,QAAQ,EAAE,mBAAQ,CAAC,WAAW,EAAE;IAChC,SAAS,EAAE,SAAS;IACpB,aAAa,EAAE,IAAI;IACnB,OAAO,EAAE;QACP,UAAU;QACV,YAAY;QACZ,YAAY;QACZ,aAAa;QACb,YAAY;QACZ,iBAAiB;QACjB,QAAQ;QACR,WAAW;QACX,YAAY;QACZ,WAAW;QACX,OAAO;QACP,eAAe;QACf,cAAc;QACd,cAAc;QACd,SAAS;QACT,mBAAmB;QACnB,aAAa;QACb,8BAA8B;KAC/B;IACD,YAAY,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC;CACzC,CAAC,CACH;KACA,SAAS,EAAE,CAAC;AAEf,MAAM,SAAS,GAAG,CAChB,CAgBC,EACD,UAAkB,EACV,EAAE;IACV,MAAM,UAAU,GAAG,IAAA,mDAAwB,EAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,eAAe,GACnB,CAAC,CAAC,IAAI,KAAK,KAAK;QACd,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,MAA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B,CAAC;SACpD,IAAI;IACH,EAAE;IACF,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE;QACR,cAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CACH;SACA,SAAS,EAAE,CAAC;AACjB,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { encodePath, formatTime } from '@yuants/utils';\nimport { defer, from, map, merge, mergeMap, repeat, retry, shareReplay, Subject, tap } from 'rxjs';\nimport { getDefaultCredential, getTradeOrdersHistory, getTradeOrdersPending } from './api/private-api';\nimport { getTradingAccountId } from './accountInfos/uid';\nimport { mapOkxOrdTypeToOrderType } from './orders/mapOkxOrdTypeToOrderType';\n\nexport const order$ = new Subject<IOrder>();\n\nconst credential = getDefaultCredential();\n\norder$\n .pipe(\n //\n // mergeMap((x) => x),\n writeToSQL({\n terminal: Terminal.fromNodeEnv(),\n tableName: '\"order\"',\n writeInterval: 1000,\n columns: [\n 'order_id',\n 'account_id',\n 'product_id',\n 'position_id',\n 'order_type',\n 'order_direction',\n 'volume',\n 'submit_at',\n 'updated_at',\n 'filled_at',\n 'price',\n 'traded_volume',\n 'traded_price',\n 'order_status',\n 'comment',\n 'profit_correction',\n 'real_profit',\n 'inferred_base_currency_price',\n ],\n conflictKeys: ['account_id', 'order_id'],\n }),\n )\n .subscribe();\n\nconst makeOrder = (\n x: {\n ordType: string;\n side: string;\n posSide: string;\n instType: string;\n instId: string;\n cTime: string;\n uTime: string;\n fillTime: string;\n sz: string;\n accFillSz: string;\n px: string;\n avgPx: string;\n state: string;\n clOrdId: string;\n ordId: string;\n },\n account_id: string,\n): IOrder => {\n const order_type = mapOkxOrdTypeToOrderType(x.ordType);\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n const order_status = ['live', 'partially_filled'].includes(x.state)\n ? 'ACCEPTED'\n : x.state === 'filled'\n ? 'TRADED'\n : 'CANCELLED';\n return {\n order_id: x.clOrdId !== '' ? x.clOrdId : x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n created_at: formatTime(+x.cTime),\n updated_at: formatTime(+x.uTime),\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n order_status,\n };\n};\n\n(async () => {\n const TRADING_ACCOUNT_ID = await getTradingAccountId(credential);\n\n const swapHistoryOrders = defer(() => getTradeOrdersHistory(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const swapPendingOrders = defer(() => getTradeOrdersPending(credential, { instType: 'SWAP' })).pipe(\n repeat({ delay: 1000 }),\n retry({ delay: 1000 }),\n shareReplay(1),\n );\n\n const ordersFromHistoryOrder$ = swapHistoryOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n const ordersFromPendingOrder$ = swapPendingOrders.pipe(\n //\n mergeMap((x) =>\n from(x.data || []).pipe(\n //\n map((x) => makeOrder(x, TRADING_ACCOUNT_ID)),\n ),\n ),\n );\n\n merge(ordersFromHistoryOrder$, ordersFromPendingOrder$)\n .pipe(\n //\n tap((x) => {\n order$.next(x);\n }),\n )\n .subscribe();\n})();\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../src/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAyB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAExE,eAAO,MAAM,UAAU,GAAU,YAAY,WAAW,EAAE,YAAY,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CA+B9F,CAAC"}
1
+ {"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../src/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAyB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGxE,eAAO,MAAM,UAAU,GAAU,YAAY,WAAW,EAAE,YAAY,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CA+B9F,CAAC"}
@@ -4,12 +4,13 @@ exports.listOrders = void 0;
4
4
  const utils_1 = require("@yuants/utils");
5
5
  const uid_1 = require("../accountInfos/uid");
6
6
  const private_api_1 = require("../api/private-api");
7
+ const mapOkxOrdTypeToOrderType_1 = require("./mapOkxOrdTypeToOrderType");
7
8
  const listOrders = async (credential, account_id) => {
8
9
  const accountIds = await (0, uid_1.getAccountIds)(credential);
9
10
  if ((accountIds === null || accountIds === void 0 ? void 0 : accountIds.trading) === account_id) {
10
11
  const orderRes = await (0, private_api_1.getTradeOrdersPending)(credential, {});
11
12
  return orderRes.data.map((x) => {
12
- const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
13
+ const order_type = (0, mapOkxOrdTypeToOrderType_1.mapOkxOrdTypeToOrderType)(x.ordType);
13
14
  const order_direction = x.side === 'buy'
14
15
  ? x.posSide === 'long'
15
16
  ? 'OPEN_LONG'
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../src/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,6CAAyE;AACzE,oDAAwE;AAEjE,MAAM,UAAU,GAAG,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAqB,EAAE;IACjG,MAAM,UAAU,GAAG,MAAM,IAAA,mBAAa,EAAC,UAAU,CAAC,CAAC;IACnD,IAAI,CAA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/BW,QAAA,UAAU,cA+BrB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { encodePath } from '@yuants/utils';\nimport { getAccountIds, getTradingAccountId } from '../accountInfos/uid';\nimport { getTradeOrdersPending, ICredential } from '../api/private-api';\n\nexport const listOrders = async (credential: ICredential, account_id: string): Promise<IOrder[]> => {\n const accountIds = await getAccountIds(credential);\n if (accountIds?.trading === account_id) {\n const orderRes = await getTradeOrdersPending(credential, {});\n return orderRes.data.map((x) => {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n return {\n order_id: x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n };\n });\n }\n throw new Error(`Account ID ${account_id} not found or not a trading account`);\n};\n"]}
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../src/orders/listOrders.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,6CAAyE;AACzE,oDAAwE;AACxE,yEAAsE;AAE/D,MAAM,UAAU,GAAG,KAAK,EAAE,UAAuB,EAAE,UAAkB,EAAqB,EAAE;IACjG,MAAM,UAAU,GAAG,MAAM,IAAA,mBAAa,EAAC,UAAU,CAAC,CAAC;IACnD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,MAAK,UAAU,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,MAAM,IAAA,mCAAqB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC7B,MAAM,UAAU,GAAG,IAAA,mDAAwB,EAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAEvD,MAAM,eAAe,GACnB,CAAC,CAAC,IAAI,KAAK,KAAK;gBACd,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM;oBACpB,CAAC,CAAC,WAAW;oBACb,CAAC,CAAC,aAAa;gBACjB,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO;oBACvB,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,YAAY,CAAC;YACnB,OAAO;gBACL,QAAQ,EAAE,CAAC,CAAC,KAAK;gBACjB,UAAU;gBACV,UAAU,EAAE,IAAA,kBAAU,EAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;gBAC5C,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK;gBACnB,SAAS,EAAE,CAAC,CAAC,CAAC,QAAQ;gBACtB,UAAU;gBACV,eAAe;gBACf,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;gBACb,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS;gBAC3B,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;gBACZ,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK;aACvB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,cAAc,UAAU,qCAAqC,CAAC,CAAC;AACjF,CAAC,CAAC;AA/BW,QAAA,UAAU,cA+BrB","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { encodePath } from '@yuants/utils';\nimport { getAccountIds, getTradingAccountId } from '../accountInfos/uid';\nimport { getTradeOrdersPending, ICredential } from '../api/private-api';\nimport { mapOkxOrdTypeToOrderType } from './mapOkxOrdTypeToOrderType';\n\nexport const listOrders = async (credential: ICredential, account_id: string): Promise<IOrder[]> => {\n const accountIds = await getAccountIds(credential);\n if (accountIds?.trading === account_id) {\n const orderRes = await getTradeOrdersPending(credential, {});\n return orderRes.data.map((x) => {\n const order_type = mapOkxOrdTypeToOrderType(x.ordType);\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n return {\n order_id: x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n };\n });\n }\n throw new Error(`Account ID ${account_id} not found or not a trading account`);\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const mapOkxOrdTypeToOrderType: (ordType?: string) => "MARKET" | "LIMIT" | "MAKER" | "IOC" | "FOK" | "UNKNOWN";
2
+ //# sourceMappingURL=mapOkxOrdTypeToOrderType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOkxOrdTypeToOrderType.d.ts","sourceRoot":"","sources":["../../src/orders/mapOkxOrdTypeToOrderType.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,GAAI,UAAU,MAAM,6DAexD,CAAC"}