@yuants/vendor-aster 0.7.7 → 0.7.9

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,5 +1,4 @@
1
- import { HmacSHA256 } from '@yuants/utils';
2
- import { uint8ArrayToHex } from '../utils';
1
+ import { encodeHex, HmacSHA256 } from '@yuants/utils';
3
2
  const request = async (credential, method, baseURL, endpoint, params = {}) => {
4
3
  const url = new URL(baseURL);
5
4
  url.pathname = endpoint;
@@ -10,7 +9,7 @@ const request = async (credential, method, baseURL, endpoint, params = {}) => {
10
9
  }
11
10
  url.searchParams.set('timestamp', `${Date.now()}`);
12
11
  const msg = url.search.slice(1); // 去掉开头的 '?'
13
- const signature = uint8ArrayToHex(await HmacSHA256(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)));
12
+ const signature = encodeHex(await HmacSHA256(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)));
14
13
  url.searchParams.set('signature', signature);
15
14
  console.info(url.toString());
16
15
  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,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAkD3C,MAAM,OAAO,GAAG,KAAK,EACnB,UAAuB,EACvB,MAAc,EACd,OAAe,EACf,QAAgB,EAChB,SAAc,EAAE,EACJ,EAAE;IACd,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CAO9C,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAEjC,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAazC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,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,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAkDtD,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,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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/dist/index.js 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.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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","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,OAAO,kCAAkC,CAAC;AAC1C,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,qBAAqB,CAAC","sourcesContent":["import './services/markets/interest_rate';\nimport './services/markets/product';\nimport './services/markets/quote';\nimport './services/exchange';\n"]}
@@ -8,7 +8,7 @@ export const getPerpAccountInfo = async (credential) => {
8
8
  .filter((p) => +p.positionAmt !== 0)
9
9
  .map((p) => ({
10
10
  position_id: p.symbol,
11
- product_id: encodePath('PERPETUAL', p.symbol),
11
+ product_id: encodePath('ASTER', 'PERP', p.symbol),
12
12
  datasource_id: 'ASTER',
13
13
  direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,
14
14
  volume: Math.abs(+p.positionAmt),
@@ -1 +1 @@
1
- {"version":3,"file":"perp.js","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAC;AAEtE,MAAM,CAAC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,gBAAgB,CAAC,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,UAAU,CAAC,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","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,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAC;AAEtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,gBAAgB,CAAC,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,UAAU,CAAC,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","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,10 @@
1
+ import { encodePath } from '@yuants/utils';
2
+ import { getFApiV2Balance } from '../../api/private-api';
3
+ export const getCredentialId = async (credential) => {
4
+ const accountBalance = await getFApiV2Balance(credential, {});
5
+ if (!(accountBalance === null || accountBalance === void 0 ? void 0 : accountBalance[0])) {
6
+ throw new Error('No Account Balance');
7
+ }
8
+ return encodePath('ASTER', accountBalance[0].accountAlias);
9
+ };
10
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/services/accounts/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAC;AAEtE,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,UAAuB,EAAmB,EAAE;IAChF,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC,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,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;AAC7D,CAAC,CAAC","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,9 +1,11 @@
1
1
  import { makeSpotPosition } from '@yuants/data-account';
2
- import { getApiV1Account, getApiV1TickerPrice } from '../../api/private-api';
3
- export const getSpotAccountInfo = async (credential, account_id) => {
4
- const [x, prices] = await Promise.all([
2
+ import { getApiV1Account, getApiV1TickerPrice, getFApiV4Account } from '../../api/private-api';
3
+ import { encodePath } from '@yuants/utils';
4
+ export const getSpotAccountInfo = async (credential) => {
5
+ const [x, prices, prep] = await Promise.all([
5
6
  getApiV1Account(credential, {}),
6
7
  getApiV1TickerPrice(credential, {}),
8
+ getFApiV4Account(credential, {}),
7
9
  ]);
8
10
  const positions = x.balances.map((b) => {
9
11
  var _a, _b;
@@ -11,12 +13,26 @@ export const getSpotAccountInfo = async (credential, account_id) => {
11
13
  return makeSpotPosition({
12
14
  position_id: b.asset,
13
15
  datasource_id: 'ASTER',
14
- product_id: b.asset,
16
+ product_id: encodePath('ASTER', 'SPOT', b.asset),
15
17
  volume: +b.free + +b.locked,
16
18
  free_volume: +b.free,
17
19
  closable_price: +thePrice,
18
20
  });
19
21
  });
20
- return positions;
22
+ const walletAssets = prep.assets
23
+ .filter((xx) => +xx.walletBalance > 0)
24
+ .map((b) => {
25
+ var _a, _b;
26
+ 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;
27
+ return makeSpotPosition({
28
+ position_id: encodePath(b.asset, 'ASSET'),
29
+ datasource_id: 'ASTER',
30
+ product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),
31
+ volume: +b.walletBalance,
32
+ free_volume: +b.walletBalance,
33
+ closable_price: +thePrice,
34
+ });
35
+ });
36
+ return [...positions, ...walletAssets];
21
37
  };
22
38
  //# sourceMappingURL=spot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAe,MAAM,uBAAuB,CAAC;AAE1F,MAAM,CAAC,MAAM,kBAAkB,GAAgD,KAAK,EAClF,UAAU,EACV,UAAU,EACV,EAAE;IACF,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACpC,eAAe,CAAC,UAAU,EAAE,EAAE,CAAC;QAC/B,mBAAmB,CAAC,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,gBAAgB,CAAC;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","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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AQ;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,gBAAgB,CAAC;YACtB,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC;YACzC,aAAa,EAAE,OAAO;YACtB,UAAU,EAAE,UAAU,CAAC,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","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,63 @@
1
+ import { provideExchangeServices } from '@yuants/exchange';
2
+ import { Terminal } from '@yuants/protocol';
3
+ import { decodePath } from '@yuants/utils';
4
+ import { listProducts } from './markets/product';
5
+ import { getCredentialId } from './accounts/profile';
6
+ import { getSpotAccountInfo } from './accounts/spot';
7
+ import { listOrders, listPrepOrders, listSpotOrders } from './orders/listOrders';
8
+ import { handleSubmitOrder } from './orders/submitOrder';
9
+ import { getPerpAccountInfo } from './accounts/perp';
10
+ import { handleCancelOrder } from './orders/cancelOrder';
11
+ const terminal = Terminal.fromNodeEnv();
12
+ provideExchangeServices(terminal, {
13
+ name: 'ASTER',
14
+ credentialSchema: {
15
+ type: 'object',
16
+ required: ['address', 'secret_key', 'api_key'],
17
+ properties: {
18
+ address: { type: 'string' },
19
+ secret_key: { type: 'string' },
20
+ api_key: { type: 'string' },
21
+ },
22
+ },
23
+ getCredentialId,
24
+ listProducts,
25
+ getPositions: async function (credential) {
26
+ const [perpPositions, spotPositions] = await Promise.all([
27
+ getPerpAccountInfo(credential),
28
+ getSpotAccountInfo(credential),
29
+ ]);
30
+ return [...perpPositions, ...spotPositions];
31
+ },
32
+ getOrders: listOrders,
33
+ getPositionsByProductId: async function (credential, product_id) {
34
+ const [_, instType] = decodePath(product_id); // ASTER/PERP/ADAUSDT
35
+ if (instType === 'SPOT') {
36
+ const positions = await getSpotAccountInfo(credential);
37
+ return positions.filter((position) => position.product_id === product_id);
38
+ }
39
+ if (instType === 'PERP') {
40
+ const positions = await getPerpAccountInfo(credential);
41
+ return positions.filter((position) => position.product_id === product_id);
42
+ }
43
+ throw new Error(`Unsupported instType: ${instType}`);
44
+ },
45
+ getOrdersByProductId: async function (credential, product_id) {
46
+ const [_, instType] = decodePath(product_id); // BITGET/USDT-FUTURES/BTCUSDT
47
+ if (instType === 'SPOT') {
48
+ const orders = await listSpotOrders(credential);
49
+ return orders.filter((order) => order.product_id === product_id);
50
+ }
51
+ if (instType === 'PERP') {
52
+ const orders = await listPrepOrders(credential);
53
+ return orders.filter((order) => order.product_id === product_id);
54
+ }
55
+ throw new Error(`Unsupported instType: ${instType}`);
56
+ },
57
+ submitOrder: handleSubmitOrder,
58
+ modifyOrder: () => {
59
+ throw new Error('Not implemented');
60
+ },
61
+ cancelOrder: handleCancelOrder,
62
+ });
63
+ //# sourceMappingURL=exchange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC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vB,MAAM,SAAS,GAAG,MAAM,kBAAkB,CAAC,UAAU,CAAC,CAAC;YACvD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAC3E;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,oBAAoB,EAAE,KAAK,WAAW,UAAuB,EAAE,UAAkB;QAC/E,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,8BAA8B;QAC5E,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,CAAC;YAChD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAClE;QACD,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,CAAC;YAChD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAClE;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,WAAW,EAAE,iBAAiB;CAC/B,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { 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"]}
@@ -42,7 +42,7 @@ createSeriesProvider(terminal, {
42
42
  const end = ended_at !== null && ended_at !== void 0 ? ended_at : Date.now();
43
43
  const [datasource_id, product_id] = decodePath(series_id);
44
44
  const [instType, instId] = decodePath(product_id);
45
- if (instType !== 'PERPETUAL') {
45
+ if (instType !== 'PERP') {
46
46
  return yield __await(void 0);
47
47
  }
48
48
  let currentStart = start;
@@ -1 +1 @@
1
- {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../../src/services/markets/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,oBAAoB,EAAyB,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,eAAe,CAAwB,QAAQ,EAAE;IAC/C,KAAK,EAAE,cAAc,CAAC,SAAS,CAAC,IAAI,CAClC,GAAG,CAAC,CAAC,QAAoB,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC,EAC/F,QAAQ,EAAE,EACV,GAAG,CACD,CAAC,OAAiB,EAAyB,EAAE,CAAC,CAAC;QAC7C,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC;QAChE,UAAU,EAAE,eAAe;QAC3B,YAAY,EAAE,WAAW;QACzB,aAAa,EAAE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C;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 !== '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,OAAO,EAAE,oBAAoB,EAAyB,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,eAAe,CAAwB,QAAQ,EAAE;IAC/C,KAAK,EAAE,cAAc,CAAC,SAAS,CAAC,IAAI,CAClC,GAAG,CAAC,CAAC,QAAoB,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC,EAC/F,QAAQ,EAAE,EACV,GAAG,CACD,CAAC,OAAiB,EAAyB,EAAE,CAAC,CAAC;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AAC,CAAC;gBAE5B,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE;oBACrB,MAAM;iBACP;gBAED,cAAM,cAAc,CAAC,KAAK,CAAC,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"]}
@@ -3,8 +3,7 @@ import { Terminal } from '@yuants/protocol';
3
3
  import { encodePath } from '@yuants/utils';
4
4
  import { getFApiV1ExchangeInfo } from '../../api/public-api';
5
5
  const terminal = Terminal.fromNodeEnv();
6
- // Provide QueryProducts service for ASTER
7
- export const productService = provideQueryProductsService(terminal, 'ASTER', async (req) => {
6
+ export const listProducts = async () => {
8
7
  // Fetch exchange info from ASTER API
9
8
  const exchangeInfo = await getFApiV1ExchangeInfo({});
10
9
  // Convert symbols to IProduct format
@@ -19,7 +18,7 @@ export const productService = provideQueryProductsService(terminal, 'ASTER', asy
19
18
  const volumeStep = lotSizeFilter ? +lotSizeFilter.stepSize : Number(`1e-${symbol.quantityPrecision}`);
20
19
  return {
21
20
  datasource_id: 'ASTER',
22
- product_id: encodePath('PERPETUAL', symbol.symbol),
21
+ product_id: encodePath('ASTER', 'PERP', symbol.symbol),
23
22
  name: `${symbol.baseAsset}/${symbol.quoteAsset} PERP`,
24
23
  quote_currency: symbol.quoteAsset,
25
24
  base_currency: symbol.baseAsset,
@@ -38,7 +37,9 @@ export const productService = provideQueryProductsService(terminal, 'ASTER', asy
38
37
  no_interest_rate: false,
39
38
  };
40
39
  });
41
- }, {
40
+ };
41
+ // Provide QueryProducts service for ASTER
42
+ export const productService = provideQueryProductsService(terminal, 'ASTER', listProducts, {
42
43
  auto_refresh_interval: 3600000, // Refresh hourly
43
44
  });
44
45
  //# sourceMappingURL=product.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,0CAA0C;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,CACvD,QAAQ,EACR,OAAO,EACP,KAAK,EAAE,GAA0B,EAAuB,EAAE;IACxD,qCAAqC;IACrC,MAAM,YAAY,GAAG,MAAM,qBAAqB,CAAC,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,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,KAAK,cAAc,CAAC,CAAC;QAC1F,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QAE7D,uCAAuC;QACvC,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;QACxF,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC;QAEtG,OAAO;YACL,aAAa,EAAE,OAAO;YACtB,UAAU,EAAE,UAAU,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC;YAClD,IAAI,EAAE,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,UAAU,OAAO;YACrD,cAAc,EAAE,MAAM,CAAC,UAAU;YACjC,aAAa,EAAE,MAAM,CAAC,SAAS;YAC/B,gBAAgB,EAAE,EAAE;YACpB,gBAAgB,EAAE,CAAC;YACnB,iBAAiB,EAAE,CAAC;YACpB,UAAU,EAAE,CAAC;YACb,UAAU,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,EACD;IACE,qBAAqB,EAAE,OAAQ,EAAE,iBAAiB;CACnD,CACF,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\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,OAAO,EAAmC,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,IAAyB,EAAE;IAC1D,qCAAqC;IACrC,MAAM,YAAY,GAAG,MAAM,qBAAqB,CAAC,EAAE,CAAC,CAAC;IACrD,qCAAqC;IACrC,OAAO,YAAY,C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,SAAS,EAAE,iBAAiB;YAC5B,gBAAgB,EAAE,KAAK;SACxB,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,0CAA0C;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,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"]}
@@ -20,7 +20,7 @@ const quote$ = defer(() => getFApiV1TickerPrice({})).pipe(mergeMap((tickers) =>
20
20
  var _a;
21
21
  return ({
22
22
  datasource_id: 'ASTER',
23
- product_id: encodePath('PERPETUAL', ticker.symbol),
23
+ product_id: encodePath('PERP', ticker.symbol),
24
24
  last_price: `${ticker.price}`,
25
25
  bid_price: `${ticker.price}`,
26
26
  ask_price: `${ticker.price}`,
@@ -1 +1 @@
1
- {"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,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,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACtF,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEnF,MAAM,QAAQ,GAAG,QAAQ,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,WAAW,CACnC,KAAK,EAAE,MAAc,EAAE,EAAE;IACvB,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACrD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EAAE,IAAI,EAAE,CAAC,CAC/C,CAAC;AAEF,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,EAAE;IAC7C,MAAM;SACH,IAAI,CACH,UAAU,CAAC;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,UAAU,CAAC,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,MAAM,CAAC,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,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,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,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACtF,OAAO,EAAE,qBAAq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';\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"]}
@@ -11,26 +11,23 @@ const parseProductId = (productId) => {
11
11
  return { category: undefined, symbol: parts[0] };
12
12
  };
13
13
  export const handleCancelOrder = async (credential, order) => {
14
- var _a, _b;
15
14
  if (!order.order_id) {
16
15
  throw new Error('order_id is required for CancelOrder');
17
16
  }
18
- const { category, symbol } = parseProductId(order.product_id);
17
+ const [_, instType, symbol] = decodePath(order.product_id); // BITGET/USDT-FUTURES/BTCUSDT
19
18
  if (!symbol) {
20
19
  throw new Error('product_id is required to resolve symbol for CancelOrder');
21
20
  }
22
- const accountId = (_b = (_a = order.account_id) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : order.account_id;
23
- const productType = category === null || category === void 0 ? void 0 : category.toUpperCase();
24
- if ((accountId === null || accountId === void 0 ? void 0 : accountId.includes('/SPOT')) || productType === 'SPOT') {
21
+ if (instType === 'SPOT') {
25
22
  await deleteApiV1Order(credential, {
26
23
  symbol,
27
24
  orderId: order.order_id,
28
25
  });
29
26
  return;
30
27
  }
31
- if ((accountId === null || accountId === void 0 ? void 0 : accountId.includes('/PERP')) || productType === 'PERPETUAL') {
28
+ if (instType === 'PERP') {
32
29
  await deleteFApiV1Order(credential, {
33
- symbol,
30
+ symbol: decodePath(order.product_id).slice(2).join('/'),
34
31
  orderId: order.order_id,
35
32
  });
36
33
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAe,MAAM,uBAAuB,CAAC;AAEzF,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;IAC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AU,EAAE;YAClC,MAAM;YACN,OAAO,EAAE,KAAK,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,OAAO;KACR;IAED,MAAM,IAAI,KAAK,CAAC,mDAAmD,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;AACzF,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfCancelOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { deleteApiV1Order, deleteFApiV1Order, ICredential } 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\nexport const handleCancelOrder: IActionHandlerOfCancelOrder<ICredential> = async (credential, order) => {\n if (!order.order_id) {\n throw new Error('order_id is required for CancelOrder');\n }\n\n const { category, symbol } = parseProductId(order.product_id);\n if (!symbol) {\n throw new Error('product_id is required to resolve symbol for CancelOrder');\n }\n\n const accountId = order.account_id?.toUpperCase() ?? order.account_id;\n const productType = category?.toUpperCase();\n\n if (accountId?.includes('/SPOT') || productType === 'SPOT') {\n await deleteApiV1Order(credential, {\n symbol,\n orderId: order.order_id,\n });\n return;\n }\n\n if (accountId?.includes('/PERP') || productType === 'PERPETUAL') {\n await deleteFApiV1Order(credential, {\n symbol,\n orderId: order.order_id,\n });\n return;\n }\n\n throw new Error(`Unsupported account_id/product for CancelOrder: ${order.account_id}`);\n};\n"]}
1
+ {"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAe,MAAM,uBAAuB,CAAC;AAEzF,MAAM,cAAc,GAAG,CAAC,SAAkB,EAAE,EAAE;IAC5C,IAAI,CAAC,SAAS,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AC,CAAC;QACH,OAAO;KACR;IAED,MAAM,IAAI,KAAK,CAAC,mDAAmD,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;AACzF,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfCancelOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { deleteApiV1Order, deleteFApiV1Order, ICredential } 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\nexport const handleCancelOrder: IActionHandlerOfCancelOrder<ICredential> = async (credential, order) => {\n if (!order.order_id) {\n throw new Error('order_id is required for CancelOrder');\n }\n const [_, instType, symbol] = decodePath(order.product_id); // BITGET/USDT-FUTURES/BTCUSDT\n if (!symbol) {\n throw new Error('product_id is required to resolve symbol for CancelOrder');\n }\n if (instType === 'SPOT') {\n await deleteApiV1Order(credential, {\n symbol,\n orderId: order.order_id,\n });\n return;\n }\n if (instType === 'PERP') {\n await deleteFApiV1Order(credential, {\n symbol: decodePath(order.product_id).slice(2).join('/'),\n orderId: order.order_id,\n });\n return;\n }\n\n throw new Error(`Unsupported account_id/product for CancelOrder: ${order.account_id}`);\n};\n"]}
@@ -16,7 +16,7 @@ const resolvePerpOrderDirection = (asterOrder) => {
16
16
  const resolveSpotOrderDirection = (side) => {
17
17
  return side === 'SELL' ? 'CLOSE_LONG' : 'OPEN_LONG';
18
18
  };
19
- const mapPerpOrder = (order, account_id) => {
19
+ export const mapPerpOrder = (order, account_id) => {
20
20
  const volume = Number(order.origQty);
21
21
  const tradedVolume = Number(order.executedQty);
22
22
  const price = Number(order.price);
@@ -24,7 +24,7 @@ const mapPerpOrder = (order, account_id) => {
24
24
  return {
25
25
  order_id: `${order.orderId}`,
26
26
  account_id,
27
- product_id: encodePath('PERPETUAL', order.symbol),
27
+ product_id: encodePath('ASTER', 'PERP', order.symbol),
28
28
  order_type: order.type,
29
29
  order_direction: resolvePerpOrderDirection(order),
30
30
  volume: Number.isFinite(volume) ? volume : 0,
@@ -35,7 +35,7 @@ const mapPerpOrder = (order, account_id) => {
35
35
  order_status: order.status,
36
36
  };
37
37
  };
38
- const mapSpotOrder = (order, account_id) => {
38
+ export const mapSpotOrder = (order, account_id) => {
39
39
  var _a, _b;
40
40
  const volume = Number(order.origQty);
41
41
  const tradedVolume = Number(order.executedQty);
@@ -44,7 +44,7 @@ const mapSpotOrder = (order, account_id) => {
44
44
  return {
45
45
  order_id: `${order.orderId}`,
46
46
  account_id,
47
- product_id: encodePath('SPOT', order.symbol),
47
+ product_id: encodePath('ASTER', 'SPOT', order.symbol),
48
48
  order_type: order.type,
49
49
  order_direction: resolveSpotOrderDirection(order.side),
50
50
  volume: Number.isFinite(volume) ? volume : 0,
@@ -55,13 +55,22 @@ const mapSpotOrder = (order, account_id) => {
55
55
  order_status: order.status,
56
56
  };
57
57
  };
58
- const isSpotAccount = (account_id) => account_id.endsWith('/SPOT');
59
- export const listOrders = async (credential, account_id) => {
60
- if (isSpotAccount(account_id)) {
61
- const orders = await getApiV1OpenOrders(credential, {});
62
- return orders.map((order) => mapSpotOrder(order, account_id));
63
- }
64
- const orders = await getFApiV1OpenOrders(credential, {});
65
- return orders.map((order) => mapPerpOrder(order, account_id));
58
+ export const listOrders = async (credential) => {
59
+ const [prepOrders, spotOrders] = await Promise.all([
60
+ getFApiV1OpenOrders(credential, {}),
61
+ getApiV1OpenOrders(credential, {}),
62
+ ]);
63
+ return [
64
+ ...prepOrders.map((order) => mapPerpOrder(order, '')),
65
+ ...spotOrders.map((order) => mapSpotOrder(order, '')),
66
+ ];
67
+ };
68
+ export const listSpotOrders = async (credential) => {
69
+ const [spotOrders] = await Promise.all([getApiV1OpenOrders(credential, {})]);
70
+ return [...spotOrders.map((order) => mapSpotOrder(order, ''))];
71
+ };
72
+ export const listPrepOrders = async (credential) => {
73
+ const [prepOrders] = await Promise.all([getFApiV1OpenOrders(credential, {})]);
74
+ return [...prepOrders.map((order) => mapPerpOrder(order, ''))];
66
75
  };
67
76
  //# sourceMappingURL=listOrders.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,GAIpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,MAAM,yBAAyB,GAAG,CAAC,UAAiC,EAAkB,EAAE;IACtF,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,IAAI,UAAU,CAAC,aAAa,CAAC;IAErE,IAAI,UAAU,CAAC,YAAY,KAAK,MAAM,EAAE;QACtC,OAAO,UAAU,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;KAC/D;IACD,IAAI,UAAU,CAAC,YAAY,KAAK,OAAO,EAAE;QACvC,OAAO,UAAU,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC;KACjE;IACD,IAAI,UAAU,EAAE;QACd,OAAO,UAAU,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC;KACjE;IACD,OAAO,UAAU,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;AAChE,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAC,IAAoB,EAAkB,EAAE;IACzE,OAAO,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC;AACtD,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,KAA4B,EAAE,UAAkB,EAAU,EAAE;IAChF,MAAM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AAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;KAC/D;IAED,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfListOrders, IOrder } from '@yuants/data-order';\nimport {\n getApiV1OpenOrders,\n getFApiV1OpenOrders,\n IAsterFutureOpenOrder,\n IAsterSpotOpenOrder,\n ICredential,\n} from '../../api/private-api';\nimport { encodePath } from '@yuants/utils';\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\nconst resolvePerpOrderDirection = (asterOrder: IAsterFutureOpenOrder): OrderDirection => {\n const reduceOnly = asterOrder.reduceOnly || asterOrder.closePosition;\n\n if (asterOrder.positionSide === 'LONG') {\n return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';\n }\n if (asterOrder.positionSide === 'SHORT') {\n return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'OPEN_SHORT';\n }\n if (reduceOnly) {\n return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'CLOSE_LONG';\n }\n return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT';\n};\n\nconst resolveSpotOrderDirection = (side: 'BUY' | 'SELL'): OrderDirection => {\n return side === 'SELL' ? 'CLOSE_LONG' : 'OPEN_LONG';\n};\n\nconst mapPerpOrder = (order: IAsterFutureOpenOrder, account_id: string): IOrder => {\n const volume = Number(order.origQty);\n const tradedVolume = Number(order.executedQty);\n const price = Number(order.price);\n const avgPrice = Number(order.avgPrice);\n\n return {\n order_id: `${order.orderId}`,\n account_id,\n product_id: encodePath('PERPETUAL', order.symbol),\n order_type: order.type,\n order_direction: resolvePerpOrderDirection(order),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) ? price : undefined,\n submit_at: order.updateTime,\n traded_volume: Number.isFinite(tradedVolume) ? tradedVolume : undefined,\n traded_price: Number.isFinite(avgPrice) && avgPrice > 0 ? avgPrice : undefined,\n order_status: order.status,\n };\n};\n\nconst mapSpotOrder = (order: IAsterSpotOpenOrder, account_id: string): IOrder => {\n const volume = Number(order.origQty);\n const tradedVolume = Number(order.executedQty);\n const price = Number(order.price);\n const avgPrice = Number(order.avgPrice ?? order.price);\n\n return {\n order_id: `${order.orderId}`,\n account_id,\n product_id: encodePath('SPOT', order.symbol),\n order_type: order.type,\n order_direction: resolveSpotOrderDirection(order.side),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) ? price : undefined,\n submit_at: order.updateTime ?? order.time,\n traded_volume: Number.isFinite(tradedVolume) ? tradedVolume : undefined,\n traded_price: Number.isFinite(avgPrice) && avgPrice > 0 ? avgPrice : undefined,\n order_status: order.status,\n };\n};\n\nconst isSpotAccount = (account_id: string) => account_id.endsWith('/SPOT');\n\nexport const listOrders: IActionHandlerOfListOrders<ICredential> = async (credential, account_id) => {\n if (isSpotAccount(account_id)) {\n const orders = await getApiV1OpenOrders(credential, {});\n return orders.map((order) => mapSpotOrder(order, account_id));\n }\n\n const orders = await getFApiV1OpenOrders(credential, {});\n return orders.map((order) => mapPerpOrder(order, account_id));\n};\n"]}
1
+ {"version":3,"file":"listOrders.js","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,GAIpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,MAAM,yBAAyB,GAAG,CAAC,UAAiC,EAAk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,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7E,OAAO,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAC9D,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,mBAAmB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC9E,OAAO,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfListOrders, IOrder } from '@yuants/data-order';\nimport {\n getApiV1OpenOrders,\n getFApiV1OpenOrders,\n IAsterFutureOpenOrder,\n IAsterSpotOpenOrder,\n ICredential,\n} from '../../api/private-api';\nimport { encodePath } from '@yuants/utils';\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\nconst resolvePerpOrderDirection = (asterOrder: IAsterFutureOpenOrder): OrderDirection => {\n const reduceOnly = asterOrder.reduceOnly || asterOrder.closePosition;\n\n if (asterOrder.positionSide === 'LONG') {\n return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';\n }\n if (asterOrder.positionSide === 'SHORT') {\n return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'OPEN_SHORT';\n }\n if (reduceOnly) {\n return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'CLOSE_LONG';\n }\n return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT';\n};\n\nconst resolveSpotOrderDirection = (side: 'BUY' | 'SELL'): OrderDirection => {\n return side === 'SELL' ? 'CLOSE_LONG' : 'OPEN_LONG';\n};\n\nexport const mapPerpOrder = (order: IAsterFutureOpenOrder, account_id: string): IOrder => {\n const volume = Number(order.origQty);\n const tradedVolume = Number(order.executedQty);\n const price = Number(order.price);\n const avgPrice = Number(order.avgPrice);\n\n return {\n order_id: `${order.orderId}`,\n account_id,\n product_id: encodePath('ASTER', 'PERP', order.symbol),\n order_type: order.type,\n order_direction: resolvePerpOrderDirection(order),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) ? price : undefined,\n submit_at: order.updateTime,\n traded_volume: Number.isFinite(tradedVolume) ? tradedVolume : undefined,\n traded_price: Number.isFinite(avgPrice) && avgPrice > 0 ? avgPrice : undefined,\n order_status: order.status,\n };\n};\n\nexport const mapSpotOrder = (order: IAsterSpotOpenOrder, account_id: string): IOrder => {\n const volume = Number(order.origQty);\n const tradedVolume = Number(order.executedQty);\n const price = Number(order.price);\n const avgPrice = Number(order.avgPrice ?? order.price);\n\n return {\n order_id: `${order.orderId}`,\n account_id,\n product_id: encodePath('ASTER', 'SPOT', order.symbol),\n order_type: order.type,\n order_direction: resolveSpotOrderDirection(order.side),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) ? price : undefined,\n submit_at: order.updateTime ?? order.time,\n traded_volume: Number.isFinite(tradedVolume) ? tradedVolume : undefined,\n traded_price: Number.isFinite(avgPrice) && avgPrice > 0 ? avgPrice : undefined,\n order_status: order.status,\n };\n};\n\nexport const listOrders = async (credential: ICredential) => {\n const [prepOrders, spotOrders] = await Promise.all([\n getFApiV1OpenOrders(credential, {}),\n getApiV1OpenOrders(credential, {}),\n ]);\n return [\n ...prepOrders.map((order) => mapPerpOrder(order, '')),\n ...spotOrders.map((order) => mapSpotOrder(order, '')),\n ];\n};\n\nexport const listSpotOrders = async (credential: ICredential) => {\n const [spotOrders] = await Promise.all([getApiV1OpenOrders(credential, {})]);\n return [...spotOrders.map((order) => mapSpotOrder(order, ''))];\n};\n\nexport const listPrepOrders = async (credential: ICredential) => {\n const [prepOrders] = await Promise.all([getFApiV1OpenOrders(credential, {})]);\n return [...prepOrders.map((order) => mapPerpOrder(order, ''))];\n};\n"]}
@@ -86,14 +86,11 @@ const handleSubmitOrderOfPerp = async (credential, order) => {
86
86
  return { order_id: `${orderId}` };
87
87
  };
88
88
  export const handleSubmitOrder = async (credential, order) => {
89
- var _a, _b;
90
- const accountId = (_b = (_a = order.account_id) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : order.account_id;
91
- const { category } = parseProductId(order.product_id);
92
- const productType = category === null || category === void 0 ? void 0 : category.toUpperCase();
93
- if ((accountId === null || accountId === void 0 ? void 0 : accountId.includes('/SPOT')) || productType === 'SPOT') {
89
+ const [_, instType] = decodePath(order.product_id); // BITGET/USDT-FUTURES/BTCUSDT
90
+ if (instType === 'SPOT') {
94
91
  return handleSubmitOrderOfSpot(credential, order);
95
92
  }
96
- if ((accountId === null || accountId === void 0 ? void 0 : accountId.includes('/PERP')) || productType === 'PERPETUAL') {
93
+ if (instType === 'PERP') {
97
94
  return handleSubmitOrderOfPerp(credential, order);
98
95
  }
99
96
  throw new Error(`Unsupported account_id for SubmitOrder: ${order.account_id}`);