@yuants/vendor-aster 0.7.7 → 0.7.8

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 (91) hide show
  1. package/dist/api/private-api.js +2 -3
  2. package/dist/api/private-api.js.map +1 -1
  3. package/dist/index.js +1 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/services/accounts/perp.js +1 -1
  6. package/dist/services/accounts/perp.js.map +1 -1
  7. package/dist/services/accounts/profile.js +10 -0
  8. package/dist/services/accounts/profile.js.map +1 -0
  9. package/dist/services/accounts/spot.js +21 -5
  10. package/dist/services/accounts/spot.js.map +1 -1
  11. package/dist/services/exchange.js +63 -0
  12. package/dist/services/exchange.js.map +1 -0
  13. package/dist/services/markets/interest_rate.js +1 -1
  14. package/dist/services/markets/interest_rate.js.map +1 -1
  15. package/dist/services/markets/product.js +5 -4
  16. package/dist/services/markets/product.js.map +1 -1
  17. package/dist/services/markets/quote.js +1 -1
  18. package/dist/services/markets/quote.js.map +1 -1
  19. package/dist/services/orders/cancelOrder.js +4 -7
  20. package/dist/services/orders/cancelOrder.js.map +1 -1
  21. package/dist/services/orders/listOrders.js +21 -12
  22. package/dist/services/orders/listOrders.js.map +1 -1
  23. package/dist/services/orders/submitOrder.js +3 -6
  24. package/dist/services/orders/submitOrder.js.map +1 -1
  25. package/lib/api/private-api.d.ts.map +1 -1
  26. package/lib/api/private-api.js +1 -2
  27. package/lib/api/private-api.js.map +1 -1
  28. package/lib/index.d.ts +1 -3
  29. package/lib/index.d.ts.map +1 -1
  30. package/lib/index.js +1 -3
  31. package/lib/index.js.map +1 -1
  32. package/lib/services/accounts/perp.d.ts +2 -2
  33. package/lib/services/accounts/perp.d.ts.map +1 -1
  34. package/lib/services/accounts/perp.js +1 -1
  35. package/lib/services/accounts/perp.js.map +1 -1
  36. package/lib/services/accounts/profile.d.ts +3 -0
  37. package/lib/services/accounts/profile.d.ts.map +1 -0
  38. package/lib/services/accounts/profile.js +14 -0
  39. package/lib/services/accounts/profile.js.map +1 -0
  40. package/lib/services/accounts/spot.d.ts +2 -2
  41. package/lib/services/accounts/spot.d.ts.map +1 -1
  42. package/lib/services/accounts/spot.js +20 -4
  43. package/lib/services/accounts/spot.js.map +1 -1
  44. package/lib/services/exchange.d.ts +2 -0
  45. package/lib/services/exchange.d.ts.map +1 -0
  46. package/lib/services/exchange.js +65 -0
  47. package/lib/services/exchange.js.map +1 -0
  48. package/lib/services/markets/interest_rate.js +1 -1
  49. package/lib/services/markets/interest_rate.js.map +1 -1
  50. package/lib/services/markets/product.d.ts +2 -0
  51. package/lib/services/markets/product.d.ts.map +1 -1
  52. package/lib/services/markets/product.js +7 -5
  53. package/lib/services/markets/product.js.map +1 -1
  54. package/lib/services/markets/quote.js +1 -1
  55. package/lib/services/markets/quote.js.map +1 -1
  56. package/lib/services/orders/cancelOrder.d.ts.map +1 -1
  57. package/lib/services/orders/cancelOrder.js +4 -7
  58. package/lib/services/orders/cancelOrder.js.map +1 -1
  59. package/lib/services/orders/listOrders.d.ts +7 -3
  60. package/lib/services/orders/listOrders.d.ts.map +1 -1
  61. package/lib/services/orders/listOrders.js +24 -11
  62. package/lib/services/orders/listOrders.js.map +1 -1
  63. package/lib/services/orders/submitOrder.d.ts.map +1 -1
  64. package/lib/services/orders/submitOrder.js +3 -6
  65. package/lib/services/orders/submitOrder.js.map +1 -1
  66. package/package.json +15 -14
  67. package/temp/package-deps.json +30 -31
  68. package/dist/services/account-actions-with-credential.js +0 -34
  69. package/dist/services/account-actions-with-credential.js.map +0 -1
  70. package/dist/services/legacy.js +0 -69
  71. package/dist/services/legacy.js.map +0 -1
  72. package/dist/services/order-actions-with-credential.js +0 -19
  73. package/dist/services/order-actions-with-credential.js.map +0 -1
  74. package/dist/utils.js +0 -9
  75. package/dist/utils.js.map +0 -1
  76. package/lib/services/account-actions-with-credential.d.ts +0 -2
  77. package/lib/services/account-actions-with-credential.d.ts.map +0 -1
  78. package/lib/services/account-actions-with-credential.js +0 -36
  79. package/lib/services/account-actions-with-credential.js.map +0 -1
  80. package/lib/services/legacy.d.ts +0 -2
  81. package/lib/services/legacy.d.ts.map +0 -1
  82. package/lib/services/legacy.js +0 -71
  83. package/lib/services/legacy.js.map +0 -1
  84. package/lib/services/order-actions-with-credential.d.ts +0 -2
  85. package/lib/services/order-actions-with-credential.d.ts.map +0 -1
  86. package/lib/services/order-actions-with-credential.js +0 -21
  87. package/lib/services/order-actions-with-credential.js.map +0 -1
  88. package/lib/utils.d.ts +0 -2
  89. package/lib/utils.d.ts.map +0 -1
  90. package/lib/utils.js +0 -13
  91. package/lib/utils.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAe,cAAc,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE1G,MAAM,cAAc,GAAG,CAAC,SAAkB,EAAE,EAAE;IAC5C,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,EAAE,QAAQ,EAAE,SAA+B,EAAE,MAAM,EAAE,SAA+B,EAAE,CAAC;KAC/F;IACD,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACpC,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;QACrB,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;KACjE;IACD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACnD,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;;IACpG,MAAM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AAH,GAAG,CAAU,IAAI,0CAAE,OAAO,mCAC3B,MAAC,GAAW,aAAX,GAAG,uBAAH,GAAG,CAAU,IAAI,0CAAE,QAAQ,CAAC;IAE/B,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAE3E,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,EAAE,CAAC;AACpC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;;IACrG,MAAM,SAAS,GAAG,MAAA,MAAA,KAAK,CAAC,UAAU,0CAAE,WAAW,EAAE,mCAAI,KAAK,CAAC,UAAU,CAAC;IACtE,MAAM,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,EAAE,CAAC;IAE5C,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,CAAC,OAAO,CAAC,KAAI,WAAW,KAAK,MAAM,EAAE;QAC1D,OAAO,uBAAuB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KACnD;IACD,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,CAAC,OAAO,CAAC,KAAI,WAAW,KAAK,WAAW,EAAE;QAC/D,OAAO,uBAAuB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KACnD;IACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;AACjF,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { decodePath, roundToStep } from '@yuants/utils';\nimport { getApiV1TickerPrice, ICredential, postApiV1Order, postFApiV1Order } from '../../api/private-api';\n\nconst parseProductId = (productId?: string) => {\n if (!productId) {\n return { category: undefined as string | undefined, symbol: undefined as string | undefined };\n }\n const parts = decodePath(productId);\n if (parts.length >= 2) {\n return { category: parts[0], symbol: parts.slice(1).join('/') };\n }\n return { category: undefined, symbol: parts[0] };\n};\n\nconst handleSubmitOrderOfSpot: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const { symbol } = parseProductId(order.product_id);\n const resolvedSymbol = symbol ?? order.product_id;\n if (!resolvedSymbol) {\n throw new Error(`Invalid product_id: unable to resolve spot symbol from \"${order.product_id}\"`);\n }\n\n const type = ({ MARKET: 'MARKET', LIMIT: 'LIMIT', MAKER: 'LIMIT' } as const)[order.order_type!];\n if (!type) throw new Error(`Unsupported order_type: ${order.order_type}`);\n\n const side = ({ OPEN_LONG: 'BUY', OPEN_SHORT: 'SELL', CLOSE_LONG: 'SELL', CLOSE_SHORT: 'BUY' } as const)[\n order.order_direction!\n ];\n if (!side) throw new Error(`Unsupported order_direction: ${order.order_direction}`);\n\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const price = order.price;\n\n let quantity: number | undefined = order.volume;\n let quoteOrderQty: number | undefined;\n\n if (type === 'MARKET' && side === 'BUY') {\n const spotPrice = await getApiV1TickerPrice(credential, {});\n const thePrice = spotPrice.find((x) => x.symbol === resolvedSymbol)?.price;\n if (!thePrice) throw new Error(`Cannot get price for symbol ${resolvedSymbol}`);\n quantity = undefined;\n quoteOrderQty = roundToStep(order.volume * +thePrice, 0.01);\n }\n\n const res = await postApiV1Order(credential, {\n symbol: resolvedSymbol,\n type,\n side,\n timeInForce,\n price,\n quantity,\n quoteOrderQty,\n });\n\n if (!res.orderId) {\n throw new Error('Failed to retrieve order ID from response');\n }\n\n return { order_id: '' + res.orderId };\n};\n\nconst handleSubmitOrderOfPerp: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const { symbol } = parseProductId(order.product_id);\n if (!symbol) {\n throw new Error(`Invalid product_id: unable to decode symbol from \"${order.product_id}\"`);\n }\n\n const side = ({ OPEN_LONG: 'BUY', OPEN_SHORT: 'SELL', CLOSE_LONG: 'SELL', CLOSE_SHORT: 'BUY' } as const)[\n order.order_direction!\n ];\n if (!side) throw new Error(`Unsupported order_direction: ${order.order_direction}`);\n\n const type = ({ MARKET: 'MARKET', LIMIT: 'LIMIT', MAKER: 'LIMIT' } as const)[order.order_type!];\n if (!type) throw new Error(`Unsupported order_type: ${order.order_type}`);\n\n const quantity = order.volume;\n const price = order.price;\n\n const positionSide =\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_LONG'\n ? 'LONG'\n : order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_SHORT'\n ? 'SHORT'\n : undefined;\n\n const reduceOnly =\n order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'true' : undefined;\n\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const res = await postFApiV1Order(credential, {\n symbol,\n side,\n type,\n quantity,\n price,\n timeInForce,\n positionSide,\n reduceOnly,\n });\n\n const orderId =\n (res as any)?.orderId ??\n (res as any)?.order_id ??\n (res as any)?.data?.orderId ??\n (res as any)?.data?.order_id;\n\n if (!orderId) throw new Error('Failed to retrieve order ID from response');\n\n return { order_id: `${orderId}` };\n};\n\nexport const handleSubmitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const accountId = order.account_id?.toUpperCase() ?? order.account_id;\n const { category } = parseProductId(order.product_id);\n const productType = category?.toUpperCase();\n\n if (accountId?.includes('/SPOT') || productType === 'SPOT') {\n return handleSubmitOrderOfSpot(credential, order);\n }\n if (accountId?.includes('/PERP') || productType === 'PERPETUAL') {\n return handleSubmitOrderOfPerp(credential, order);\n }\n throw new Error(`Unsupported account_id for SubmitOrder: ${order.account_id}`);\n};\n"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submit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ClF,IAAI,QAAQ,KAAK,MAAM,EAAE;QACvB,OAAO,uBAAuB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KACnD;IACD,IAAI,QAAQ,KAAK,MAAM,EAAE;QACvB,OAAO,uBAAuB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KACnD;IACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;AACjF,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { decodePath, roundToStep } from '@yuants/utils';\nimport { getApiV1TickerPrice, ICredential, postApiV1Order, postFApiV1Order } from '../../api/private-api';\n\nconst parseProductId = (productId?: string) => {\n if (!productId) {\n return { category: undefined as string | undefined, symbol: undefined as string | undefined };\n }\n const parts = decodePath(productId);\n if (parts.length >= 2) {\n return { category: parts[0], symbol: parts.slice(1).join('/') };\n }\n return { category: undefined, symbol: parts[0] };\n};\n\nconst handleSubmitOrderOfSpot: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const { symbol } = parseProductId(order.product_id);\n const resolvedSymbol = symbol ?? order.product_id;\n if (!resolvedSymbol) {\n throw new Error(`Invalid product_id: unable to resolve spot symbol from \"${order.product_id}\"`);\n }\n\n const type = ({ MARKET: 'MARKET', LIMIT: 'LIMIT', MAKER: 'LIMIT' } as const)[order.order_type!];\n if (!type) throw new Error(`Unsupported order_type: ${order.order_type}`);\n\n const side = ({ OPEN_LONG: 'BUY', OPEN_SHORT: 'SELL', CLOSE_LONG: 'SELL', CLOSE_SHORT: 'BUY' } as const)[\n order.order_direction!\n ];\n if (!side) throw new Error(`Unsupported order_direction: ${order.order_direction}`);\n\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const price = order.price;\n\n let quantity: number | undefined = order.volume;\n let quoteOrderQty: number | undefined;\n\n if (type === 'MARKET' && side === 'BUY') {\n const spotPrice = await getApiV1TickerPrice(credential, {});\n const thePrice = spotPrice.find((x) => x.symbol === resolvedSymbol)?.price;\n if (!thePrice) throw new Error(`Cannot get price for symbol ${resolvedSymbol}`);\n quantity = undefined;\n quoteOrderQty = roundToStep(order.volume * +thePrice, 0.01);\n }\n\n const res = await postApiV1Order(credential, {\n symbol: resolvedSymbol,\n type,\n side,\n timeInForce,\n price,\n quantity,\n quoteOrderQty,\n });\n\n if (!res.orderId) {\n throw new Error('Failed to retrieve order ID from response');\n }\n\n return { order_id: '' + res.orderId };\n};\n\nconst handleSubmitOrderOfPerp: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const { symbol } = parseProductId(order.product_id);\n if (!symbol) {\n throw new Error(`Invalid product_id: unable to decode symbol from \"${order.product_id}\"`);\n }\n\n const side = ({ OPEN_LONG: 'BUY', OPEN_SHORT: 'SELL', CLOSE_LONG: 'SELL', CLOSE_SHORT: 'BUY' } as const)[\n order.order_direction!\n ];\n if (!side) throw new Error(`Unsupported order_direction: ${order.order_direction}`);\n\n const type = ({ MARKET: 'MARKET', LIMIT: 'LIMIT', MAKER: 'LIMIT' } as const)[order.order_type!];\n if (!type) throw new Error(`Unsupported order_type: ${order.order_type}`);\n\n const quantity = order.volume;\n const price = order.price;\n\n const positionSide =\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_LONG'\n ? 'LONG'\n : order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_SHORT'\n ? 'SHORT'\n : undefined;\n\n const reduceOnly =\n order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'true' : undefined;\n\n const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const res = await postFApiV1Order(credential, {\n symbol,\n side,\n type,\n quantity,\n price,\n timeInForce,\n positionSide,\n reduceOnly,\n });\n\n const orderId =\n (res as any)?.orderId ??\n (res as any)?.order_id ??\n (res as any)?.data?.orderId ??\n (res as any)?.data?.order_id;\n\n if (!orderId) throw new Error('Failed to retrieve order ID from response');\n\n return { order_id: `${orderId}` };\n};\n\nexport const handleSubmitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const [_, instType] = decodePath(order.product_id); // BITGET/USDT-FUTURES/BTCUSDT\n if (instType === 'SPOT') {\n return handleSubmitOrderOfSpot(credential, order);\n }\n if (instType === 'PERP') {\n return handleSubmitOrderOfPerp(credential, order);\n }\n throw new Error(`Unsupported account_id for SubmitOrder: ${order.account_id}`);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"private-api.d.ts","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM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B,eA9Hf,WAAW;YAgId,MAAM;;;iBAKW,CAAC;AAE9B;;;;GAIG;AACH,eAAO,MAAM,eAAe,eA5Ib,WAAW;aA+Ib,MAAM;cACL,OAAO;gBACL,OAAO;iBACN,OAAO;kBACN,OAAO;gBACT,MAAM;cACR;QACR,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KAChB,EAAE;EAEoB,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,mBAAmB,eAjKjB,WAAW;YAoKd,MAAM;WACP,MAAM;UACP,MAAM;IAEgB,CAAC;AAEjC,eAAO,MAAM,cAAc,eA1KZ,WAAW;YA4Kd,MAAM;UACR,KAAK,GAAG,MAAM;UACd,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,GAAG,aAAa,GAAG,oBAAoB;;;;;;aAO/E,MAAM;EAEO,CAAC;AAE3B;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,eA9Ld,WAAW;YAgMd,MAAM;;;iBAKU,CAAC"}
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deleteApiV1Order = exports.postApiV1Order = exports.getApiV1TickerPrice = exports.getApiV1Account = exports.deleteFApiV1Order = exports.getApiV1OpenOrders = exports.getFApiV1OpenOrders = exports.postFApiV1Order = exports.getFApiV2Balance = exports.getFApiV4Account = void 0;
4
4
  const utils_1 = require("@yuants/utils");
5
- const utils_2 = require("../utils");
6
5
  const request = async (credential, method, baseURL, endpoint, params = {}) => {
7
6
  const url = new URL(baseURL);
8
7
  url.pathname = endpoint;
@@ -13,7 +12,7 @@ const request = async (credential, method, baseURL, endpoint, params = {}) => {
13
12
  }
14
13
  url.searchParams.set('timestamp', `${Date.now()}`);
15
14
  const msg = url.search.slice(1); // 去掉开头的 '?'
16
- const signature = (0, utils_2.uint8ArrayToHex)(await (0, utils_1.HmacSHA256)(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)));
15
+ const signature = (0, utils_1.encodeHex)(await (0, utils_1.HmacSHA256)(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)));
17
16
  url.searchParams.set('signature', signature);
18
17
  console.info(url.toString());
19
18
  const response = await fetch(url.toString(), {
@@ -1 +1 @@
1
- {"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAC3C,oCAA2C;AAkD3C,MAAM,OAAO,GAAG,KAAK,EACnB,UAAuB,EACvB,MAAc,EACd,OAAe,EACf,QAAgB,EAChB,SAAc,EAAE,EACJ,EAAE;IACd,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;KACvC;IAED,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;IAC7C,MAAM,SAAS,GAAG,IAAA,uBAAe,EAC/B,MAAM,IAAA,kBAAU,EAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CACjG,CAAC;IACF,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAE7C,OAAO,CAAC,IAAI,CAAC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AAK,EAAE,qBAAqB,CAAC,CAAC;AAEhC;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,aAAa,CAK7C,KAAK,EAAE,oBAAoB,CAAC,CAAC;AAElB,QAAA,iBAAiB,GAAG,eAAe,CAO9C,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AAE9B;;;;GAIG;AACU,QAAA,eAAe,GAAG,aAAa,CAe1C,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAE5B;;;GAGG;AACU,QAAA,mBAAmB,GAAG,aAAa,CAO9C,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAEpB,QAAA,cAAc,GAAG,aAAa,CAazC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3B;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,aAAa,CAO3C,QAAQ,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { HmacSHA256 } from '@yuants/utils';\nimport { uint8ArrayToHex } from '../utils';\n\nexport interface ICredential {\n address: string;\n api_key: string;\n secret_key: string;\n}\n\nexport interface IAsterFutureOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n updateTime: number;\n avgPrice: string;\n reduceOnly?: boolean;\n closePosition?: boolean;\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n workingType?: string;\n priceProtect?: boolean;\n origType?: string;\n stopPrice?: string;\n symbol: string;\n}\n\nexport interface IAsterSpotOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n cummulativeQuoteQty?: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n stopPrice?: string;\n icebergQty?: string;\n time: number;\n updateTime: number;\n isWorking?: boolean;\n avgPrice?: string;\n symbol: string;\n}\n\nconst request = async <T>(\n credential: ICredential,\n method: string,\n baseURL: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const url = new URL(baseURL);\n url.pathname = endpoint;\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined) continue;\n url.searchParams.set(key, `${value}`);\n }\n\n url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = uint8ArrayToHex(\n await HmacSHA256(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)),\n );\n url.searchParams.set('signature', signature);\n\n console.info(url.toString());\n const response = await fetch(url.toString(), {\n method,\n headers: {\n 'X-MBX-APIKEY': credential.api_key,\n },\n });\n\n const resText = await response.text();\n\n try {\n const res = JSON.parse(resText);\n\n if (res.code && res.code !== 0) {\n throw resText;\n }\n return res;\n } catch (e) {\n throw `APIError: ${response.status} ${response.statusText} ${resText}`;\n }\n};\n\nconst createApi =\n (baseURL: string) =>\n <TReq, TRes>(method: string, endpoint: string) =>\n (credential: ICredential, params: TReq) =>\n request<TRes>(credential, method, baseURL, endpoint, params);\n\nconst createFutureApi = createApi('https://fapi.asterdex.com');\nconst createSpotApi = createApi('https://sapi.asterdex.com');\n\n/**\n * 获取账户信息\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data\n */\nexport const getFApiV4Account = createFutureApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n updateTime: number;\n totalInitialMargin: string;\n totalMaintMargin: string;\n totalWalletBalance: string;\n totalUnrealizedProfit: string;\n totalMarginBalance: string;\n totalPositionInitialMargin: string;\n totalOpenOrderInitialMargin: string;\n totalCrossWalletBalance: string;\n totalCrossUnPnl: string;\n availableBalance: string;\n maxWithdrawAmount: string;\n assets: {\n asset: string;\n walletBalance: string;\n unrealizedProfit: string;\n marginBalance: string;\n maintMargin: string;\n initialMargin: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n maxWithdrawAmount: string;\n crossWalletBalance: string;\n crossUnPnl: string;\n availableBalance: string;\n marginAvailable: boolean;\n updateTime: number;\n }[];\n positions: {\n symbol: string;\n initialMargin: string;\n maintMargin: string;\n unrealizedProfit: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n leverage: string;\n isolated: boolean;\n entryPrice: string;\n maxNotional: string;\n positionSide: 'BOTH' | 'LONG' | 'SHORT';\n positionAmt: string;\n notional: string;\n isolatedWallet: string;\n updateTime: number;\n }[];\n }\n>('GET', '/fapi/v4/account');\n\nexport const getFApiV2Balance = createFutureApi<\n {},\n {\n accountAlias: string; // 账户唯一识别码\n asset: string; // 资产\n balance: string; // 总余额\n crossWalletBalance: string; // 全仓余额\n crossUnPnl: string; // 全仓持仓未实现盈亏\n availableBalance: string; // 下单可用余额\n maxWithdrawAmount: string; // 最大可转出余额\n marginAvailable: boolean; // 是否可用作联合保证金\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/balance');\n\nexport const postFApiV1Order = createFutureApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n type:\n | 'MARKET'\n | 'LIMIT'\n | 'STOP'\n | 'STOP_MARKET'\n | 'TAKE_PROFIT'\n | 'TAKE_PROFIT_MARKET'\n | 'TRAILING_STOP_MARKET';\n reduceOnly?: 'true' | 'false';\n quantity?: number;\n price?: number;\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX' | 'HIDDEN';\n },\n {}\n>('POST', '/fapi/v1/order');\n\n/**\n * 查询当前挂单 (永续)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766\n */\nexport const getFApiV1OpenOrders = createFutureApi<\n {\n symbol?: string;\n },\n IAsterFutureOpenOrder[]\n>('GET', '/fapi/v1/openOrders');\n\n/**\n * 查询当前挂单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234\n */\nexport const getApiV1OpenOrders = createSpotApi<\n {\n symbol?: string;\n },\n IAsterSpotOpenOrder[]\n>('GET', '/api/v1/openOrders');\n\nexport const deleteFApiV1Order = createFutureApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/fapi/v1/order');\n\n/**\n * 获取账户信息 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data\n */\nexport const getApiV1Account = createSpotApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n canBurnAsset: boolean;\n updateTime: number;\n balances: {\n asset: string;\n free: string;\n locked: string;\n }[];\n }\n>('GET', '/api/v1/account');\n\n/**\n * 获取最新价格\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC\n */\nexport const getApiV1TickerPrice = createSpotApi<\n {},\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n>('GET', '/api/v1/ticker/price');\n\nexport const postApiV1Order = createSpotApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX';\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n },\n {\n orderId: number; // 系统的订单ID\n }\n>('POST', '/api/v1/order');\n\n/**\n * 取消有效订单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074\n */\nexport const deleteApiV1Order = createSpotApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/api/v1/order');\n"]}
1
+ {"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":";;;AAAA,yCAAsD;AAkDtD,MAAM,OAAO,GAAG,KAAK,EACn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C,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAEpB,QAAA,cAAc,GAAG,aAAa,CAazC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3B;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,aAAa,CAO3C,QAAQ,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { encodeHex, HmacSHA256 } from '@yuants/utils';\n\nexport interface ICredential {\n address: string;\n api_key: string;\n secret_key: string;\n}\n\nexport interface IAsterFutureOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n updateTime: number;\n avgPrice: string;\n reduceOnly?: boolean;\n closePosition?: boolean;\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n workingType?: string;\n priceProtect?: boolean;\n origType?: string;\n stopPrice?: string;\n symbol: string;\n}\n\nexport interface IAsterSpotOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n cummulativeQuoteQty?: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n stopPrice?: string;\n icebergQty?: string;\n time: number;\n updateTime: number;\n isWorking?: boolean;\n avgPrice?: string;\n symbol: string;\n}\n\nconst request = async <T>(\n credential: ICredential,\n method: string,\n baseURL: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const url = new URL(baseURL);\n url.pathname = endpoint;\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined) continue;\n url.searchParams.set(key, `${value}`);\n }\n\n url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = encodeHex(\n await HmacSHA256(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)),\n );\n url.searchParams.set('signature', signature);\n\n console.info(url.toString());\n const response = await fetch(url.toString(), {\n method,\n headers: {\n 'X-MBX-APIKEY': credential.api_key,\n },\n });\n\n const resText = await response.text();\n\n try {\n const res = JSON.parse(resText);\n\n if (res.code && res.code !== 0) {\n throw resText;\n }\n return res;\n } catch (e) {\n throw `APIError: ${response.status} ${response.statusText} ${resText}`;\n }\n};\n\nconst createApi =\n (baseURL: string) =>\n <TReq, TRes>(method: string, endpoint: string) =>\n (credential: ICredential, params: TReq) =>\n request<TRes>(credential, method, baseURL, endpoint, params);\n\nconst createFutureApi = createApi('https://fapi.asterdex.com');\nconst createSpotApi = createApi('https://sapi.asterdex.com');\n\n/**\n * 获取账户信息\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data\n */\nexport const getFApiV4Account = createFutureApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n updateTime: number;\n totalInitialMargin: string;\n totalMaintMargin: string;\n totalWalletBalance: string;\n totalUnrealizedProfit: string;\n totalMarginBalance: string;\n totalPositionInitialMargin: string;\n totalOpenOrderInitialMargin: string;\n totalCrossWalletBalance: string;\n totalCrossUnPnl: string;\n availableBalance: string;\n maxWithdrawAmount: string;\n assets: {\n asset: string;\n walletBalance: string;\n unrealizedProfit: string;\n marginBalance: string;\n maintMargin: string;\n initialMargin: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n maxWithdrawAmount: string;\n crossWalletBalance: string;\n crossUnPnl: string;\n availableBalance: string;\n marginAvailable: boolean;\n updateTime: number;\n }[];\n positions: {\n symbol: string;\n initialMargin: string;\n maintMargin: string;\n unrealizedProfit: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n leverage: string;\n isolated: boolean;\n entryPrice: string;\n maxNotional: string;\n positionSide: 'BOTH' | 'LONG' | 'SHORT';\n positionAmt: string;\n notional: string;\n isolatedWallet: string;\n updateTime: number;\n }[];\n }\n>('GET', '/fapi/v4/account');\n\nexport const getFApiV2Balance = createFutureApi<\n {},\n {\n accountAlias: string; // 账户唯一识别码\n asset: string; // 资产\n balance: string; // 总余额\n crossWalletBalance: string; // 全仓余额\n crossUnPnl: string; // 全仓持仓未实现盈亏\n availableBalance: string; // 下单可用余额\n maxWithdrawAmount: string; // 最大可转出余额\n marginAvailable: boolean; // 是否可用作联合保证金\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/balance');\n\nexport const postFApiV1Order = createFutureApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n type:\n | 'MARKET'\n | 'LIMIT'\n | 'STOP'\n | 'STOP_MARKET'\n | 'TAKE_PROFIT'\n | 'TAKE_PROFIT_MARKET'\n | 'TRAILING_STOP_MARKET';\n reduceOnly?: 'true' | 'false';\n quantity?: number;\n price?: number;\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX' | 'HIDDEN';\n },\n {}\n>('POST', '/fapi/v1/order');\n\n/**\n * 查询当前挂单 (永续)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766\n */\nexport const getFApiV1OpenOrders = createFutureApi<\n {\n symbol?: string;\n },\n IAsterFutureOpenOrder[]\n>('GET', '/fapi/v1/openOrders');\n\n/**\n * 查询当前挂单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234\n */\nexport const getApiV1OpenOrders = createSpotApi<\n {\n symbol?: string;\n },\n IAsterSpotOpenOrder[]\n>('GET', '/api/v1/openOrders');\n\nexport const deleteFApiV1Order = createFutureApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/fapi/v1/order');\n\n/**\n * 获取账户信息 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data\n */\nexport const getApiV1Account = createSpotApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n canBurnAsset: boolean;\n updateTime: number;\n balances: {\n asset: string;\n free: string;\n locked: string;\n }[];\n }\n>('GET', '/api/v1/account');\n\n/**\n * 获取最新价格\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC\n */\nexport const getApiV1TickerPrice = createSpotApi<\n {},\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n>('GET', '/api/v1/ticker/price');\n\nexport const postApiV1Order = createSpotApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX';\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n },\n {\n orderId: number; // 系统的订单ID\n }\n>('POST', '/api/v1/order');\n\n/**\n * 取消有效订单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074\n */\nexport const deleteApiV1Order = createSpotApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/api/v1/order');\n"]}
package/lib/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import './services/markets/interest_rate';
2
2
  import './services/markets/product';
3
3
  import './services/markets/quote';
4
- import './services/account-actions-with-credential';
5
- import './services/legacy';
6
- import './services/order-actions-with-credential';
4
+ import './services/exchange';
7
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,4CAA4C,CAAC;AACpD,OAAO,mBAAmB,CAAC;AAC3B,OAAO,0CAA0C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,qBAAqB,CAAC"}
package/lib/index.js CHANGED
@@ -3,7 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("./services/markets/interest_rate");
4
4
  require("./services/markets/product");
5
5
  require("./services/markets/quote");
6
- require("./services/account-actions-with-credential");
7
- require("./services/legacy");
8
- require("./services/order-actions-with-credential");
6
+ require("./services/exchange");
9
7
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,4CAA0C;AAC1C,sCAAoC;AACpC,oCAAkC;AAClC,sDAAoD;AACpD,6BAA2B;AAC3B,oDAAkD","sourcesContent":["import './services/markets/interest_rate';\nimport './services/markets/product';\nimport './services/markets/quote';\nimport './services/account-actions-with-credential';\nimport './services/legacy';\nimport './services/order-actions-with-credential';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,4CAA0C;AAC1C,sCAAoC;AACpC,oCAAkC;AAClC,+BAA6B","sourcesContent":["import './services/markets/interest_rate';\nimport './services/markets/product';\nimport './services/markets/quote';\nimport './services/exchange';\n"]}
@@ -1,4 +1,4 @@
1
- import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
1
+ import { IPosition } from '@yuants/data-account';
2
2
  import { ICredential } from '../../api/private-api';
3
- export declare const getPerpAccountInfo: IActionHandlerOfGetAccountInfo<ICredential>;
3
+ export declare const getPerpAccountInfo: (credential: ICredential) => Promise<IPosition[]>;
4
4
  //# sourceMappingURL=perp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"perp.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAoB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEtE,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAuB1E,CAAC"}
1
+ {"version":3,"file":"perp.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAoB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEtE,eAAO,MAAM,kBAAkB,eAAsB,WAAW,yBAuB/D,CAAC"}
@@ -11,7 +11,7 @@ const getPerpAccountInfo = async (credential) => {
11
11
  .filter((p) => +p.positionAmt !== 0)
12
12
  .map((p) => ({
13
13
  position_id: p.symbol,
14
- product_id: (0, utils_1.encodePath)('PERPETUAL', p.symbol),
14
+ product_id: (0, utils_1.encodePath)('ASTER', 'PERP', p.symbol),
15
15
  datasource_id: 'ASTER',
16
16
  direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,
17
17
  volume: Math.abs(+p.positionAmt),
@@ -1 +1 @@
1
- {"version":3,"file":"perp.js","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,uDAAsE;AAE/D,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAA,8BAAgB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAElE,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC,qBAAqB,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAEjC,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS;SAC1B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC;SACnC,GAAG,CACF,CAAC,CAAC,EAAa,EAAE,CAAC,CAAC;QACjB,WAAW,EAAE,CAAC,CAAC,MAAM;QACrB,UAAU,EAAE,IAAA,kBAAU,EAAC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QAC7C,aAAa,EAAE,OAAO;QACtB,SAAS,EAAE,CAAC,CAAC,YAAY,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;QAC/F,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QACrC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;QAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;QACtD,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB;QACpC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;KACjC,CAAC,CACH,CAAC;IACJ,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAvBW,QAAA,kBAAkB,sBAuB7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFApiV4Account, ICredential } from '../../api/private-api';\n\nexport const getPerpAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const [a] = await Promise.all([getFApiV4Account(credential, {})]);\n\n const equity = +a.totalWalletBalance + +a.totalUnrealizedProfit;\n const free = +a.availableBalance;\n\n const positions = a.positions\n .filter((p) => +p.positionAmt !== 0)\n .map(\n (p): IPosition => ({\n position_id: p.symbol,\n product_id: encodePath('PERPETUAL', p.symbol),\n datasource_id: 'ASTER',\n direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,\n volume: Math.abs(+p.positionAmt),\n free_volume: Math.abs(+p.positionAmt),\n position_price: +p.entryPrice,\n closable_price: Math.abs(+p.notional / +p.positionAmt),\n floating_profit: +p.unrealizedProfit,\n valuation: Math.abs(+p.notional),\n }),\n );\n return positions;\n};\n"]}
1
+ {"version":3,"file":"perp.js","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,uDAAsE;AAE/D,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAA,8BAAgB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAElE,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC,qBAAqB,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAEjC,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS;SAC1B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC;SACnC,GAAG,CACF,CAAC,CAAC,EAAa,EAAE,CAAC,CAAC;QACjB,WAAW,EAAE,CAAC,CAAC,MAAM;QACrB,UAAU,EAAE,IAAA,kBAAU,EAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACjD,aAAa,EAAE,OAAO;QACtB,SAAS,EAAE,CAAC,CAAC,YAAY,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;QAC/F,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QACrC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;QAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;QACtD,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB;QACpC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;KACjC,CAAC,CACH,CAAC;IACJ,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAvBW,QAAA,kBAAkB,sBAuB7B","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFApiV4Account, ICredential } from '../../api/private-api';\n\nexport const getPerpAccountInfo = async (credential: ICredential) => {\n const [a] = await Promise.all([getFApiV4Account(credential, {})]);\n\n const equity = +a.totalWalletBalance + +a.totalUnrealizedProfit;\n const free = +a.availableBalance;\n\n const positions = a.positions\n .filter((p) => +p.positionAmt !== 0)\n .map(\n (p): IPosition => ({\n position_id: p.symbol,\n product_id: encodePath('ASTER', 'PERP', p.symbol),\n datasource_id: 'ASTER',\n direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,\n volume: Math.abs(+p.positionAmt),\n free_volume: Math.abs(+p.positionAmt),\n position_price: +p.entryPrice,\n closable_price: Math.abs(+p.notional / +p.positionAmt),\n floating_profit: +p.unrealizedProfit,\n valuation: Math.abs(+p.notional),\n }),\n );\n return positions;\n};\n"]}
@@ -0,0 +1,3 @@
1
+ import { ICredential } from '../../api/private-api';
2
+ export declare const getCredentialId: (credential: ICredential) => Promise<string>;
3
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEtE,eAAO,MAAM,eAAe,eAAsB,WAAW,KAAG,QAAQ,MAAM,CAM7E,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCredentialId = void 0;
4
+ const utils_1 = require("@yuants/utils");
5
+ const private_api_1 = require("../../api/private-api");
6
+ const getCredentialId = async (credential) => {
7
+ const accountBalance = await (0, private_api_1.getFApiV2Balance)(credential, {});
8
+ if (!(accountBalance === null || accountBalance === void 0 ? void 0 : accountBalance[0])) {
9
+ throw new Error('No Account Balance');
10
+ }
11
+ return (0, utils_1.encodePath)('ASTER', accountBalance[0].accountAlias);
12
+ };
13
+ exports.getCredentialId = getCredentialId;
14
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAC3C,uDAAsE;AAE/D,MAAM,eAAe,GAAG,KAAK,EAAE,UAAuB,EAAmB,EAAE;IAChF,MAAM,cAAc,GAAG,MAAM,IAAA,8BAAgB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC9D,IAAI,CAAC,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,CAAC,CAAC,CAAA,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;KACvC;IACD,OAAO,IAAA,kBAAU,EAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;AAC7D,CAAC,CAAC;AANW,QAAA,eAAe,mBAM1B","sourcesContent":["import { encodePath } from '@yuants/utils';\nimport { getFApiV2Balance, ICredential } from '../../api/private-api';\n\nexport const getCredentialId = async (credential: ICredential): Promise<string> => {\n const accountBalance = await getFApiV2Balance(credential, {});\n if (!accountBalance?.[0]) {\n throw new Error('No Account Balance');\n }\n return encodePath('ASTER', accountBalance[0].accountAlias);\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
1
+ import { IPosition } from '@yuants/data-account';
2
2
  import { ICredential } from '../../api/private-api';
3
- export declare const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential>;
3
+ export declare const getSpotAccountInfo: (credential: ICredential) => Promise<IPosition[]>;
4
4
  //# sourceMappingURL=spot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAA+B,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAwC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE1F,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAuB1E,CAAC"}
1
+ {"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAA0D,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG5G,eAAO,MAAM,kBAAkB,eAAsB,WAAW,yBAiC/D,CAAC"}
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSpotAccountInfo = void 0;
4
4
  const data_account_1 = require("@yuants/data-account");
5
5
  const private_api_1 = require("../../api/private-api");
6
- const getSpotAccountInfo = async (credential, account_id) => {
7
- const [x, prices] = await Promise.all([
6
+ const utils_1 = require("@yuants/utils");
7
+ const getSpotAccountInfo = async (credential) => {
8
+ const [x, prices, prep] = await Promise.all([
8
9
  (0, private_api_1.getApiV1Account)(credential, {}),
9
10
  (0, private_api_1.getApiV1TickerPrice)(credential, {}),
11
+ (0, private_api_1.getFApiV4Account)(credential, {}),
10
12
  ]);
11
13
  const positions = x.balances.map((b) => {
12
14
  var _a, _b;
@@ -14,13 +16,27 @@ const getSpotAccountInfo = async (credential, account_id) => {
14
16
  return (0, data_account_1.makeSpotPosition)({
15
17
  position_id: b.asset,
16
18
  datasource_id: 'ASTER',
17
- product_id: b.asset,
19
+ product_id: (0, utils_1.encodePath)('ASTER', 'SPOT', b.asset),
18
20
  volume: +b.free + +b.locked,
19
21
  free_volume: +b.free,
20
22
  closable_price: +thePrice,
21
23
  });
22
24
  });
23
- return positions;
25
+ const walletAssets = prep.assets
26
+ .filter((xx) => +xx.walletBalance > 0)
27
+ .map((b) => {
28
+ var _a, _b;
29
+ const thePrice = b.asset === 'USDT' ? 1 : (_b = (_a = prices.find((p) => p.symbol === b.asset + 'USDT')) === null || _a === void 0 ? void 0 : _a.price) !== null && _b !== void 0 ? _b : 0;
30
+ return (0, data_account_1.makeSpotPosition)({
31
+ position_id: (0, utils_1.encodePath)(b.asset, 'ASSET'),
32
+ datasource_id: 'ASTER',
33
+ product_id: (0, utils_1.encodePath)('ASTER', 'PERP-ASSET', b.asset),
34
+ volume: +b.walletBalance,
35
+ free_volume: +b.walletBalance,
36
+ closable_price: +thePrice,
37
+ });
38
+ });
39
+ return [...positions, ...walletAssets];
24
40
  };
25
41
  exports.getSpotAccountInfo = getSpotAccountInfo;
26
42
  //# sourceMappingURL=spot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAmG;AACnG,uDAA0F;AAEnF,MAAM,kBAAkB,GAAgD,KAAK,EAClF,UAAU,EACV,UAAU,EACV,EAAE;IACF,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACpC,IAAA,6BAAe,EAAC,UAAU,EAAE,EAAE,CAAC;QAC/B,IAAA,iCAAmB,EAAC,UAAU,EAAE,EAAE,CAAC;KACpC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAa,EAAE;;QAChD,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAA,MAAA,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,0CAAE,KAAK,mCAAI,CAAC,CAAC;QAExG,OAAO,IAAA,+BAAgB,EAAC;YACtB,WAAW,EAAE,CAAC,CAAC,KAAK;YACpB,aAAa,EAAE,OAAO;YACtB,UAAU,EAAE,CAAC,CAAC,KAAK;YACnB,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM;YAC3B,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;YACpB,cAAc,EAAE,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAvBW,QAAA,kBAAkB,sBAuB7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { getApiV1Account, getApiV1TickerPrice, ICredential } from '../../api/private-api';\n\nexport const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (\n credential,\n account_id,\n) => {\n const [x, prices] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n ]);\n\n const positions = x.balances.map((b): IPosition => {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n\n return makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: b.asset,\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n });\n });\n\n return positions;\n};\n"]}
1
+ {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AACnE,uDAA4G;AAC5G,yCAA2C;AAEpC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC1C,IAAA,6BAAe,EAAC,UAAU,EAAE,EAAE,CAAC;QAC/B,IAAA,iCAAmB,EAAC,UAAU,EAAE,EAAE,CAAC;QACnC,IAAA,8BAAgB,EAAC,UAAU,EAAE,EAAE,CAAC;KACjC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAa,EAAE;;QAChD,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAA,MAAA,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,0CAAE,KAAK,mCAAI,CAAC,CAAC;QACxG,OAAO,IAAA,+BAAgB,EAAC;YACtB,WAAW,EAAE,CAAC,CAAC,KAAK;YACpB,aAAa,EAAE,OAAO;YACtB,UAAU,EAAE,IAAA,kBAAU,EAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC;YAChD,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM;YAC3B,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;YACpB,cAAc,EAAE,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM;SAC7B,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,aAAa,GAAG,CAAC,CAAC;SACrC,GAAG,CAAC,CAAC,CAAC,EAAa,EAAE;;QACpB,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAA,MAAA,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,0CAAE,KAAK,mCAAI,CAAC,CAAC;QACxG,OAAO,IAAA,+BAAgB,EAAC;YACtB,WAAW,EAAE,IAAA,kBAAU,EAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC;YACzC,aAAa,EAAE,OAAO;YACtB,UAAU,EAAE,IAAA,kBAAU,EAAC,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC;YACtD,MAAM,EAAE,CAAC,CAAC,CAAC,aAAa;YACxB,WAAW,EAAE,CAAC,CAAC,CAAC,aAAa;YAC7B,cAAc,EAAE,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,OAAO,CAAC,GAAG,SAAS,EAAE,GAAG,YAAY,CAAC,CAAC;AACzC,CAAC,CAAC;AAjCW,QAAA,kBAAkB,sBAiC7B","sourcesContent":["import { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { getApiV1Account, getApiV1TickerPrice, getFApiV4Account, ICredential } from '../../api/private-api';\nimport { encodePath } from '@yuants/utils';\n\nexport const getSpotAccountInfo = async (credential: ICredential) => {\n const [x, prices, prep] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n getFApiV4Account(credential, {}),\n ]);\n\n const positions = x.balances.map((b): IPosition => {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n return makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'SPOT', b.asset),\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n });\n });\n const walletAssets = prep.assets\n .filter((xx) => +xx.walletBalance > 0)\n .map((b): IPosition => {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n return makeSpotPosition({\n position_id: encodePath(b.asset, 'ASSET'),\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),\n volume: +b.walletBalance,\n free_volume: +b.walletBalance,\n closable_price: +thePrice,\n });\n });\n\n return [...positions, ...walletAssets];\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=exchange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.d.ts","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":""}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const exchange_1 = require("@yuants/exchange");
4
+ const protocol_1 = require("@yuants/protocol");
5
+ const utils_1 = require("@yuants/utils");
6
+ const product_1 = require("./markets/product");
7
+ const profile_1 = require("./accounts/profile");
8
+ const spot_1 = require("./accounts/spot");
9
+ const listOrders_1 = require("./orders/listOrders");
10
+ const submitOrder_1 = require("./orders/submitOrder");
11
+ const perp_1 = require("./accounts/perp");
12
+ const cancelOrder_1 = require("./orders/cancelOrder");
13
+ const terminal = protocol_1.Terminal.fromNodeEnv();
14
+ (0, exchange_1.provideExchangeServices)(terminal, {
15
+ name: 'ASTER',
16
+ credentialSchema: {
17
+ type: 'object',
18
+ required: ['address', 'secret_key', 'api_key'],
19
+ properties: {
20
+ address: { type: 'string' },
21
+ secret_key: { type: 'string' },
22
+ api_key: { type: 'string' },
23
+ },
24
+ },
25
+ getCredentialId: profile_1.getCredentialId,
26
+ listProducts: product_1.listProducts,
27
+ getPositions: async function (credential) {
28
+ const [perpPositions, spotPositions] = await Promise.all([
29
+ (0, perp_1.getPerpAccountInfo)(credential),
30
+ (0, spot_1.getSpotAccountInfo)(credential),
31
+ ]);
32
+ return [...perpPositions, ...spotPositions];
33
+ },
34
+ getOrders: listOrders_1.listOrders,
35
+ getPositionsByProductId: async function (credential, product_id) {
36
+ const [_, instType] = (0, utils_1.decodePath)(product_id); // ASTER/PERP/ADAUSDT
37
+ if (instType === 'SPOT') {
38
+ const positions = await (0, spot_1.getSpotAccountInfo)(credential);
39
+ return positions.filter((position) => position.product_id === product_id);
40
+ }
41
+ if (instType === 'PERP') {
42
+ const positions = await (0, perp_1.getPerpAccountInfo)(credential);
43
+ return positions.filter((position) => position.product_id === product_id);
44
+ }
45
+ throw new Error(`Unsupported instType: ${instType}`);
46
+ },
47
+ getOrdersByProductId: async function (credential, product_id) {
48
+ const [_, instType] = (0, utils_1.decodePath)(product_id); // BITGET/USDT-FUTURES/BTCUSDT
49
+ if (instType === 'SPOT') {
50
+ const orders = await (0, listOrders_1.listSpotOrders)(credential);
51
+ return orders.filter((order) => order.product_id === product_id);
52
+ }
53
+ if (instType === 'PERP') {
54
+ const orders = await (0, listOrders_1.listPrepOrders)(credential);
55
+ return orders.filter((order) => order.product_id === product_id);
56
+ }
57
+ throw new Error(`Unsupported instType: ${instType}`);
58
+ },
59
+ submitOrder: submitOrder_1.handleSubmitOrder,
60
+ modifyOrder: () => {
61
+ throw new Error('Not implemented');
62
+ },
63
+ cancelOrder: cancelOrder_1.handleCancelOrder,
64
+ });
65
+ //# sourceMappingURL=exchange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AAEA,+CAA2D;AAC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import { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath } from '@yuants/utils';\nimport { listProducts } from './markets/product';\nimport { getCredentialId } from './accounts/profile';\nimport { getSpotAccountInfo } from './accounts/spot';\nimport { listOrders, listPrepOrders, listSpotOrders } from './orders/listOrders';\nimport { handleSubmitOrder } from './orders/submitOrder';\nimport { ICredential } from '../api/private-api';\nimport { getPerpAccountInfo } from './accounts/perp';\nimport { handleCancelOrder } from './orders/cancelOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'ASTER',\n credentialSchema: {\n type: 'object',\n required: ['address', 'secret_key', 'api_key'],\n properties: {\n address: { type: 'string' },\n secret_key: { type: 'string' },\n api_key: { type: 'string' },\n },\n },\n getCredentialId,\n listProducts,\n getPositions: async function (credential: ICredential): Promise<IPosition[]> {\n const [perpPositions, spotPositions] = await Promise.all([\n getPerpAccountInfo(credential),\n getSpotAccountInfo(credential),\n ]);\n return [...perpPositions, ...spotPositions];\n },\n getOrders: listOrders,\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const [_, instType] = decodePath(product_id); // ASTER/PERP/ADAUSDT\n if (instType === 'SPOT') {\n const positions = await getSpotAccountInfo(credential);\n return positions.filter((position) => position.product_id === product_id);\n }\n if (instType === 'PERP') {\n const positions = await getPerpAccountInfo(credential);\n return positions.filter((position) => position.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n },\n getOrdersByProductId: async function (credential: ICredential, product_id: string): Promise<IOrder[]> {\n const [_, instType] = decodePath(product_id); // BITGET/USDT-FUTURES/BTCUSDT\n if (instType === 'SPOT') {\n const orders = await listSpotOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n if (instType === 'PERP') {\n const orders = await listPrepOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n },\n submitOrder: handleSubmitOrder,\n modifyOrder: () => {\n throw new Error('Not implemented');\n },\n cancelOrder: handleCancelOrder,\n});\n"]}
@@ -44,7 +44,7 @@ const terminal = protocol_1.Terminal.fromNodeEnv();
44
44
  const end = ended_at !== null && ended_at !== void 0 ? ended_at : Date.now();
45
45
  const [datasource_id, product_id] = (0, utils_1.decodePath)(series_id);
46
46
  const [instType, instId] = (0, utils_1.decodePath)(product_id);
47
- if (instType !== 'PERPETUAL') {
47
+ if (instType !== 'PERP') {
48
48
  return yield __await(void 0);
49
49
  }
50
50
  let currentStart = start;
@@ -1 +1 @@
1
- {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../../src/services/markets/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,qDAAkF;AAClF,+CAA4C;AAC5C,qCAA8C;AAC9C,yCAAmE;AACnE,+BAA4D;AAC5D,qDAA4D;AAC5D,uCAA2C;AAE3C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,qBAAe,EAAwB,QAAQ,EAAE;IAC/C,KAAK,EAAE,wBAAc,CAAC,SAAS,CAAC,IAAI,CAClC,IAAA,UAAG,EAAC,CAAC,QAAoB,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC,EAC/F,IAAA,eAAQ,GAAE,EACV,IAAA,UAAG,EACD,CAAC,OAAiB,EAAyB,EAAE,CAAC,CAAC;QAC7C,SAAS,EAAE,IAAA,kBAAU,EAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC;QAChE,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;I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uants/data-interest-rate';\nimport { IProduct } from '@yuants/data-product';\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 { getFApiV1FundingRate } from '../../api/public-api';\nimport { productService } from './product';\n\nconst terminal = Terminal.fromNodeEnv();\n\ncreateSQLWriter<ISeriesCollectingTask>(terminal, {\n data$: productService.products$.pipe(\n map((products: IProduct[]) => products.filter((product) => product.no_interest_rate === false)),\n mergeAll(),\n map(\n (product: IProduct): ISeriesCollectingTask => ({\n series_id: encodePath(product.datasource_id, product.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, {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['ASTER'],\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 [datasource_id, product_id] = decodePath(series_id);\n const [instType, instId] = decodePath(product_id);\n\n if (instType !== 'PERPETUAL') {\n return;\n }\n\n let currentStart = start;\n\n while (currentStart <= end) {\n const res = await getFApiV1FundingRate({\n symbol: instId,\n startTime: currentStart,\n endTime: end,\n limit: 1000,\n });\n\n if (!Array.isArray(res) || res.length === 0) {\n break;\n }\n\n const filtered = res.filter((item) => item.fundingTime >= currentStart && item.fundingTime <= end);\n\n if (filtered.length === 0) {\n const lastRecord = res[res.length - 1];\n const nextStart = lastRecord.fundingTime + 1;\n if (nextStart <= currentStart) {\n break;\n }\n currentStart = nextStart;\n await firstValueFrom(timer(1000));\n continue;\n }\n\n const data = filtered.map((item): IInterestRate => {\n const rate = Number(item.fundingRate);\n return {\n series_id,\n product_id,\n datasource_id,\n created_at: formatTime(item.fundingTime),\n long_rate: `${-rate}`,\n short_rate: `${rate}`,\n settlement_price: '',\n };\n });\n\n yield data;\n\n const lastTime = filtered[filtered.length - 1].fundingTime;\n if (lastTime >= end) {\n break;\n }\n\n currentStart = lastTime + 1;\n\n if (res.length < 1000) {\n break;\n }\n\n await firstValueFrom(timer(1000));\n }\n },\n});\n"]}
1
+ {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../../src/services/markets/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,qDAAkF;AAClF,+CAA4C;AAC5C,qCAA8C;AAC9C,yCAAmE;AACnE,+BAA4D;AAC5D,qDAA4D;AAC5D,uCAA2C;AAE3C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,qBAAe,EAAwB,QAAQ,EAAE;IAC/C,KAAK,EAAE,wBAAc,CAAC,SAAS,CAAC,IAAI,CAClC,IAAA,UAAG,EAAC,CAAC,QAAoB,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC,EAC/F,IAAA,eAAQ,GAAE,EACV,IAAA,UAAG,EACD,CAAC,OAAiB,EAAyB,EAAE,CAAC,CAAC;QAC7C,SAAS,EAAE,IAAA,kBAAU,EAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC;QAChE,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,YAAY,CAAC;CAC1C,CAAC,CAAC;AA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M,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;oBACvC,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,GAAG,CAAC,CAAC;oBAC7C,IAAI,SAAS,IAAI,YAAY,EAAE;wBAC7B,MAAM;qBACP;oBACD,YAAY,GAAG,SAAS,CAAC;oBACzB,cAAM,IAAA,qBAAc,EAAC,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC,CAAA,CAAC;oBAClC,SAAS;iBACV;gBAED,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAiB,EAAE;oBAChD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;oBACtC,OAAO;wBACL,SAAS;wBACT,UAAU;wBACV,aAAa;wBACb,UAAU,EAAE,IAAA,kBAAU,EAAC,IAAI,CAAC,WAAW,CAAC;wBACxC,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE;wBACrB,UAAU,EAAE,GAAG,IAAI,EAAE;wBACrB,gBAAgB,EAAE,EAAE;qBACrB,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,oBAAM,IAAI,CAAA,CAAC;gBAEX,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;gBAC3D,IAAI,QAAQ,IAAI,GAAG,EAAE;oBACnB,MAAM;iBACP;gBAED,YAAY,GAAG,QAAQ,GAAG,CAAC,CAAC;gBAE5B,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE;oBACrB,MAAM;iBACP;gBAED,cAAM,IAAA,qBAAc,EAAC,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC,CAAA,CAAC;aACnC;QACH,CAAC;KAAA;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { IProduct } from '@yuants/data-product';\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 { getFApiV1FundingRate } from '../../api/public-api';\nimport { productService } from './product';\n\nconst terminal = Terminal.fromNodeEnv();\n\ncreateSQLWriter<ISeriesCollectingTask>(terminal, {\n data$: productService.products$.pipe(\n map((products: IProduct[]) => products.filter((product) => product.no_interest_rate === false)),\n mergeAll(),\n map(\n (product: IProduct): ISeriesCollectingTask => ({\n series_id: encodePath(product.datasource_id, product.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, {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['ASTER'],\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 [datasource_id, product_id] = decodePath(series_id);\n const [instType, instId] = decodePath(product_id);\n\n if (instType !== 'PERP') {\n return;\n }\n\n let currentStart = start;\n\n while (currentStart <= end) {\n const res = await getFApiV1FundingRate({\n symbol: instId,\n startTime: currentStart,\n endTime: end,\n limit: 1000,\n });\n\n if (!Array.isArray(res) || res.length === 0) {\n break;\n }\n\n const filtered = res.filter((item) => item.fundingTime >= currentStart && item.fundingTime <= end);\n\n if (filtered.length === 0) {\n const lastRecord = res[res.length - 1];\n const nextStart = lastRecord.fundingTime + 1;\n if (nextStart <= currentStart) {\n break;\n }\n currentStart = nextStart;\n await firstValueFrom(timer(1000));\n continue;\n }\n\n const data = filtered.map((item): IInterestRate => {\n const rate = Number(item.fundingRate);\n return {\n series_id,\n product_id,\n datasource_id,\n created_at: formatTime(item.fundingTime),\n long_rate: `${-rate}`,\n short_rate: `${rate}`,\n settlement_price: '',\n };\n });\n\n yield data;\n\n const lastTime = filtered[filtered.length - 1].fundingTime;\n if (lastTime >= end) {\n break;\n }\n\n currentStart = lastTime + 1;\n\n if (res.length < 1000) {\n break;\n }\n\n await firstValueFrom(timer(1000));\n }\n },\n});\n"]}
@@ -1,2 +1,4 @@
1
+ import { IProduct } from '@yuants/data-product';
2
+ export declare const listProducts: () => Promise<IProduct[]>;
1
3
  export declare const productService: import("@yuants/data-product").IQueryProductsService;
2
4
  //# sourceMappingURL=product.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,sDA4C1B,CAAC"}
1
+ {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsD,MAAM,sBAAsB,CAAC;AAOpG,eAAO,MAAM,YAAY,QAAa,QAAQ,QAAQ,EAAE,CAoCvD,CAAC;AAGF,eAAO,MAAM,cAAc,sDAEzB,CAAC"}
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.productService = void 0;
3
+ exports.productService = exports.listProducts = void 0;
4
4
  const data_product_1 = require("@yuants/data-product");
5
5
  const protocol_1 = require("@yuants/protocol");
6
6
  const utils_1 = require("@yuants/utils");
7
7
  const public_api_1 = require("../../api/public-api");
8
8
  const terminal = protocol_1.Terminal.fromNodeEnv();
9
- // Provide QueryProducts service for ASTER
10
- exports.productService = (0, data_product_1.provideQueryProductsService)(terminal, 'ASTER', async (req) => {
9
+ const listProducts = async () => {
11
10
  // Fetch exchange info from ASTER API
12
11
  const exchangeInfo = await (0, public_api_1.getFApiV1ExchangeInfo)({});
13
12
  // Convert symbols to IProduct format
@@ -22,7 +21,7 @@ exports.productService = (0, data_product_1.provideQueryProductsService)(termina
22
21
  const volumeStep = lotSizeFilter ? +lotSizeFilter.stepSize : Number(`1e-${symbol.quantityPrecision}`);
23
22
  return {
24
23
  datasource_id: 'ASTER',
25
- product_id: (0, utils_1.encodePath)('PERPETUAL', symbol.symbol),
24
+ product_id: (0, utils_1.encodePath)('ASTER', 'PERP', symbol.symbol),
26
25
  name: `${symbol.baseAsset}/${symbol.quoteAsset} PERP`,
27
26
  quote_currency: symbol.quoteAsset,
28
27
  base_currency: symbol.baseAsset,
@@ -41,7 +40,10 @@ exports.productService = (0, data_product_1.provideQueryProductsService)(termina
41
40
  no_interest_rate: false,
42
41
  };
43
42
  });
44
- }, {
43
+ };
44
+ exports.listProducts = listProducts;
45
+ // Provide QueryProducts service for ASTER
46
+ exports.productService = (0, data_product_1.provideQueryProductsService)(terminal, 'ASTER', exports.listProducts, {
45
47
  auto_refresh_interval: 3600000, // Refresh hourly
46
48
  });
47
49
  //# sourceMappingURL=product.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":";;;AAAA,uDAAoG;AACpG,+CAA4C;AAC5C,yCAA2C;AAC3C,qDAA6D;AAE7D,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,0CAA0C;AAC7B,QAAA,cAAc,GAAG,IAAA,0CAA2B,EACvD,QAAQ,EACR,OAAO,EACP,KAAK,EAAE,GAA0B,EAAuB,EAAE;IACxD,qCAAqC;IACrC,MAAM,YAAY,GAAG,MAAM,IAAA,kCAAqB,EAAC,EAAE,CAAC,CAAC;IAErD,qCAAqC;IACrC,OAAO,YAAY,CAAC,OAAO;SACxB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,sCAAsC;SACtF,GAAG,CAAC,CAAC,MAAM,EAAY,EAAE;QACxB,mCAAmC;QACnC,MAAM,WAAW,GAAG,MAAM,C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from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFApiV1ExchangeInfo } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\n// Provide QueryProducts service for ASTER\nexport const productService = provideQueryProductsService(\n terminal,\n 'ASTER',\n async (req: IQueryProductsRequest): Promise<IProduct[]> => {\n // Fetch exchange info from ASTER API\n const exchangeInfo = await getFApiV1ExchangeInfo({});\n\n // Convert symbols to IProduct format\n return exchangeInfo.symbols\n .filter((symbol) => symbol.status === 'TRADING') // Only include active trading symbols\n .map((symbol): IProduct => {\n // Find price filter for price step\n const priceFilter = symbol.filters.find((filter) => filter.filterType === 'PRICE_FILTER');\n const priceStep = priceFilter ? +priceFilter.tickSize : 1e-2;\n\n // Find lot size filter for volume step\n const lotSizeFilter = symbol.filters.find((filter) => filter.filterType === 'LOT_SIZE');\n const volumeStep = lotSizeFilter ? +lotSizeFilter.stepSize : Number(`1e-${symbol.quantityPrecision}`);\n\n return {\n datasource_id: 'ASTER',\n product_id: encodePath('PERPETUAL', symbol.symbol),\n name: `${symbol.baseAsset}/${symbol.quoteAsset} PERP`,\n quote_currency: symbol.quoteAsset,\n base_currency: symbol.baseAsset,\n value_scale_unit: '',\n value_based_cost: 0,\n volume_based_cost: 0,\n max_volume: 0,\n price_step: priceStep,\n volume_step: volumeStep,\n value_scale: 1,\n allow_long: true,\n allow_short: true,\n margin_rate: 0.1, // Default margin rate, can be adjusted based on actual requirements\n max_position: 0,\n market_id: 'ASTER/PERPETUAL',\n no_interest_rate: false,\n };\n });\n },\n {\n auto_refresh_interval: 3600_000, // Refresh hourly\n },\n);\n"]}
1
+ {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":";;;AAAA,uDAAoG;AACpG,+CAA4C;AAC5C,yCAA2C;AAC3C,qDAA6D;AAE7D,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAEjC,MA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,EAAE,SAAS;YACrB,WAAW,EAAE,UAAU;YACvB,WAAW,EAAE,CAAC;YACd,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,IAAI;YACjB,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE,CAAC;YACf,SAAS,EAAE,iBAAiB;YAC5B,gBAAgB,EAAE,KAAK;SACxB,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AApCW,QAAA,YAAY,gBAoCvB;AAEF,0CAA0C;AAC7B,QAAA,cAAc,GAAG,IAAA,0CAA2B,EAAC,QAAQ,EAAE,OAAO,EAAE,oBAAY,EAAE;IACzF,qBAAqB,EAAE,OAAQ,EAAE,iBAAiB;CACnD,CAAC,CAAC","sourcesContent":["import { IProduct, IQueryProductsRequest, provideQueryProductsService } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFApiV1ExchangeInfo } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nexport const listProducts = async (): Promise<IProduct[]> => {\n // Fetch exchange info from ASTER API\n const exchangeInfo = await getFApiV1ExchangeInfo({});\n // Convert symbols to IProduct format\n return exchangeInfo.symbols\n .filter((symbol) => symbol.status === 'TRADING') // Only include active trading symbols\n .map((symbol): IProduct => {\n // Find price filter for price step\n const priceFilter = symbol.filters.find((filter) => filter.filterType === 'PRICE_FILTER');\n const priceStep = priceFilter ? +priceFilter.tickSize : 1e-2;\n\n // Find lot size filter for volume step\n const lotSizeFilter = symbol.filters.find((filter) => filter.filterType === 'LOT_SIZE');\n const volumeStep = lotSizeFilter ? +lotSizeFilter.stepSize : Number(`1e-${symbol.quantityPrecision}`);\n\n return {\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP', symbol.symbol),\n name: `${symbol.baseAsset}/${symbol.quoteAsset} PERP`,\n quote_currency: symbol.quoteAsset,\n base_currency: symbol.baseAsset,\n value_scale_unit: '',\n value_based_cost: 0,\n volume_based_cost: 0,\n max_volume: 0,\n price_step: priceStep,\n volume_step: volumeStep,\n value_scale: 1,\n allow_long: true,\n allow_short: true,\n margin_rate: 0.1, // Default margin rate, can be adjusted based on actual requirements\n max_position: 0,\n market_id: 'ASTER/PERPETUAL',\n no_interest_rate: false,\n };\n });\n};\n\n// Provide QueryProducts service for ASTER\nexport const productService = provideQueryProductsService(terminal, 'ASTER', listProducts, {\n auto_refresh_interval: 3600_000, // Refresh hourly\n});\n"]}
@@ -22,7 +22,7 @@ const quote$ = (0, rxjs_1.defer)(() => (0, public_api_1.getFApiV1TickerPrice)({}
22
22
  var _a;
23
23
  return ({
24
24
  datasource_id: 'ASTER',
25
- product_id: (0, utils_1.encodePath)('PERPETUAL', ticker.symbol),
25
+ product_id: (0, utils_1.encodePath)('PERP', ticker.symbol),
26
26
  last_price: `${ticker.price}`,
27
27
  bid_price: `${ticker.price}`,
28
28
  ask_price: `${ticker.price}`,
@@ -1 +1 @@
1
- {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":";;AAAA,yCAA4C;AAE5C,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAAsF;AACtF,qDAAmF;AAEnF,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAO,CAAC;AAE1G,MAAM,iBAAiB,GAAG,IAAA,mBAAW,EACnC,KAAK,EAAE,MAAc,EAAE,EAAE;IACvB,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,IAAA,kCAAqB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,YAAY,CAAC;KAC1B;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,IAAI,CAAC,8BAA8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C;AAEF,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,EAAE;IAC7C,MAAM;SACH,IAAI,CACH,IAAA,gBAAU,EAAC;QACT,QAAQ;QACR,SAAS,EAAE,OAAO;QAClB,aAAa,EAAE,IAAI;QACnB,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC;KAC9C,CAAC,CACH;SACA,SAAS,EAAE,CAAC;IAEf,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,EAAE;QAC9E,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,uBAAuB,UAAU,EAAE,CAAC,CAAC;SACtD;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAA,aAAM,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;CACJ","sourcesContent":["import { createCache } from '@yuants/cache';\nimport type { IQuote } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath } from '@yuants/utils';\nimport { defer, filter, from, map, mergeMap, repeat, retry, shareReplay } from 'rxjs';\nimport { getFApiV1OpenInterest, getFApiV1TickerPrice } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst OPEN_INTEREST_TTL = process.env.OPEN_INTEREST_TTL ? Number(process.env.OPEN_INTEREST_TTL) : 120_000;\n\nconst openInterestCache = createCache<string>(\n async (symbol: string) => {\n try {\n const data = await getFApiV1OpenInterest({ symbol });\n return data.openInterest;\n } catch (error) {\n console.warn('getFApiV1OpenInterest failed', symbol, error);\n return undefined;\n }\n },\n { expire: OPEN_INTEREST_TTL },\n);\n\nconst quote$ = defer(() => getFApiV1TickerPrice({})).pipe(\n mergeMap((tickers) => tickers || []),\n mergeMap(\n (ticker) =>\n from(openInterestCache.query(ticker.symbol)).pipe(\n map(\n (openInterest): Partial<IQuote> => ({\n datasource_id: 'ASTER',\n product_id: encodePath('PERPETUAL', ticker.symbol),\n last_price: `${ticker.price}`,\n bid_price: `${ticker.price}`,\n ask_price: `${ticker.price}`,\n open_interest: `${openInterest ?? 0}`,\n updated_at: new Date(ticker.time ?? Date.now()).toISOString(),\n }),\n ),\n ),\n 5,\n ),\n repeat({ delay: 1000 }),\n retry({ delay: 5000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n quote$\n .pipe(\n writeToSQL({\n terminal,\n tableName: 'quote',\n writeInterval: 1000,\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n\n terminal.channel.publishChannel('quote', { pattern: '^ASTER/' }, (channel_id) => {\n const [datasourceId, productId] = decodePath(channel_id);\n if (!datasourceId || !productId) {\n throw new Error(`Invalid channel_id: ${channel_id}`);\n }\n return quote$.pipe(filter((quote) => quote.product_id === productId));\n });\n}\n"]}
1
+ {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":";;AAAA,yCAA4C;AAE5C,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAAsF;AACtF,qDAAmF;AAEnF,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAO,CAAC;AAE1G,MAAM,iBAAiB,GAAG,IAAA,mBAAW,EACnC,KAAK,EAAE,MAAc,EAAE,EAAE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C,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACvB,IAAA,YAAK,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACtB,IAAA,kBAAW,EAAC,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAC/C,CAAC;AAEF,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,EAAE;IAC7C,MAAM;SACH,IAAI,CACH,IAAA,gBAAU,EAAC;QACT,QAAQ;QACR,SAAS,EAAE,OAAO;QAClB,aAAa,EAAE,IAAI;QACnB,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC;KAC9C,CAAC,CACH;SACA,SAAS,EAAE,CAAC;IAEf,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,EAAE;QAC9E,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,uBAAuB,UAAU,EAAE,CAAC,CAAC;SACtD;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAA,aAAM,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;CACJ","sourcesContent":["import { createCache } from '@yuants/cache';\nimport type { IQuote } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath } from '@yuants/utils';\nimport { defer, filter, from, map, mergeMap, repeat, retry, shareReplay } from 'rxjs';\nimport { getFApiV1OpenInterest, getFApiV1TickerPrice } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst OPEN_INTEREST_TTL = process.env.OPEN_INTEREST_TTL ? Number(process.env.OPEN_INTEREST_TTL) : 120_000;\n\nconst openInterestCache = createCache<string>(\n async (symbol: string) => {\n try {\n const data = await getFApiV1OpenInterest({ symbol });\n return data.openInterest;\n } catch (error) {\n console.warn('getFApiV1OpenInterest failed', symbol, error);\n return undefined;\n }\n },\n { expire: OPEN_INTEREST_TTL },\n);\n\nconst quote$ = defer(() => getFApiV1TickerPrice({})).pipe(\n mergeMap((tickers) => tickers || []),\n mergeMap(\n (ticker) =>\n from(openInterestCache.query(ticker.symbol)).pipe(\n map(\n (openInterest): Partial<IQuote> => ({\n datasource_id: 'ASTER',\n product_id: encodePath('PERP', ticker.symbol),\n last_price: `${ticker.price}`,\n bid_price: `${ticker.price}`,\n ask_price: `${ticker.price}`,\n open_interest: `${openInterest ?? 0}`,\n updated_at: new Date(ticker.time ?? Date.now()).toISOString(),\n }),\n ),\n ),\n 5,\n ),\n repeat({ delay: 1000 }),\n retry({ delay: 5000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n quote$\n .pipe(\n writeToSQL({\n terminal,\n tableName: 'quote',\n writeInterval: 1000,\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n\n terminal.channel.publishChannel('quote', { pattern: '^ASTER/' }, (channel_id) => {\n const [datasourceId, productId] = decodePath(channel_id);\n if (!datasourceId || !productId) {\n throw new Error(`Invalid channel_id: ${channel_id}`);\n }\n return quote$.pipe(filter((quote) => quote.product_id === productId));\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"cancelOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAuC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAazF,eAAO,MAAM,iBAAiB,EAAE,2BAA2B,CAAC,WAAW,CA8BtE,CAAC"}
1
+ {"version":3,"file":"cancelOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAuC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAazF,eAAO,MAAM,iBAAiB,EAAE,2BAA2B,CAAC,WAAW,CAwBtE,CAAC"}