@yuants/vendor-aster 0.5.8 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/api/private-api.js +69 -0
  2. package/dist/api/private-api.js.map +1 -0
  3. package/dist/api/public-api.js +44 -0
  4. package/dist/api/public-api.js.map +1 -0
  5. package/dist/index.js +6 -8
  6. package/dist/index.js.map +1 -1
  7. package/dist/services/account-actions-with-credential.js +34 -0
  8. package/dist/services/account-actions-with-credential.js.map +1 -0
  9. package/dist/{account.js → services/accounts/perp.js} +5 -9
  10. package/dist/services/accounts/perp.js.map +1 -0
  11. package/dist/{account-spot.js → services/accounts/spot.js} +8 -9
  12. package/dist/services/accounts/spot.js.map +1 -0
  13. package/dist/services/legacy.js +69 -0
  14. package/dist/services/legacy.js.map +1 -0
  15. package/dist/{interest_rate.js → services/markets/interest_rate.js} +1 -1
  16. package/dist/services/markets/interest_rate.js.map +1 -0
  17. package/dist/{product.js → services/markets/product.js} +1 -1
  18. package/dist/services/markets/product.js.map +1 -0
  19. package/dist/{quote.js → services/markets/quote.js} +1 -1
  20. package/dist/services/markets/quote.js.map +1 -0
  21. package/dist/services/order-actions-with-credential.js +19 -0
  22. package/dist/services/order-actions-with-credential.js.map +1 -0
  23. package/dist/services/orders/cancelOrder.js +40 -0
  24. package/dist/services/orders/cancelOrder.js.map +1 -0
  25. package/dist/services/orders/listOrders.js +67 -0
  26. package/dist/services/orders/listOrders.js.map +1 -0
  27. package/dist/services/orders/submitOrder.js +101 -0
  28. package/dist/services/orders/submitOrder.js.map +1 -0
  29. package/dist/utils.js +1 -20
  30. package/dist/utils.js.map +1 -1
  31. package/lib/api/private-api.d.ts +192 -0
  32. package/lib/api/private-api.d.ts.map +1 -0
  33. package/lib/api/private-api.js +72 -0
  34. package/lib/api/private-api.js.map +1 -0
  35. package/lib/api/public-api.d.ts +59 -0
  36. package/lib/api/public-api.d.ts.map +1 -0
  37. package/lib/api/public-api.js +47 -0
  38. package/lib/api/public-api.js.map +1 -0
  39. package/lib/index.d.ts +6 -8
  40. package/lib/index.d.ts.map +1 -1
  41. package/lib/index.js +6 -8
  42. package/lib/index.js.map +1 -1
  43. package/lib/services/account-actions-with-credential.d.ts +2 -0
  44. package/lib/services/account-actions-with-credential.d.ts.map +1 -0
  45. package/lib/services/account-actions-with-credential.js +36 -0
  46. package/lib/services/account-actions-with-credential.js.map +1 -0
  47. package/lib/services/accounts/perp.d.ts +4 -0
  48. package/lib/services/accounts/perp.d.ts.map +1 -0
  49. package/lib/{account.js → services/accounts/perp.js} +7 -10
  50. package/lib/services/accounts/perp.js.map +1 -0
  51. package/lib/services/accounts/spot.d.ts +4 -0
  52. package/lib/services/accounts/spot.d.ts.map +1 -0
  53. package/lib/{account-spot.js → services/accounts/spot.js} +10 -10
  54. package/lib/services/accounts/spot.js.map +1 -0
  55. package/lib/services/legacy.d.ts +2 -0
  56. package/lib/services/legacy.d.ts.map +1 -0
  57. package/lib/services/legacy.js +71 -0
  58. package/lib/services/legacy.js.map +1 -0
  59. package/lib/services/markets/interest_rate.d.ts.map +1 -0
  60. package/lib/{interest_rate.js → services/markets/interest_rate.js} +2 -2
  61. package/lib/services/markets/interest_rate.js.map +1 -0
  62. package/lib/services/markets/product.d.ts.map +1 -0
  63. package/lib/{product.js → services/markets/product.js} +2 -2
  64. package/lib/services/markets/product.js.map +1 -0
  65. package/lib/{quote.d.ts.map → services/markets/quote.d.ts.map} +1 -1
  66. package/lib/{quote.js → services/markets/quote.js} +3 -3
  67. package/lib/services/markets/quote.js.map +1 -0
  68. package/lib/services/order-actions-with-credential.d.ts +2 -0
  69. package/lib/services/order-actions-with-credential.d.ts.map +1 -0
  70. package/lib/services/order-actions-with-credential.js +21 -0
  71. package/lib/services/order-actions-with-credential.js.map +1 -0
  72. package/lib/services/orders/cancelOrder.d.ts +4 -0
  73. package/lib/services/orders/cancelOrder.d.ts.map +1 -0
  74. package/lib/services/orders/cancelOrder.js +44 -0
  75. package/lib/services/orders/cancelOrder.js.map +1 -0
  76. package/lib/services/orders/listOrders.d.ts +4 -0
  77. package/lib/services/orders/listOrders.d.ts.map +1 -0
  78. package/lib/services/orders/listOrders.js +71 -0
  79. package/lib/services/orders/listOrders.js.map +1 -0
  80. package/lib/services/orders/submitOrder.d.ts +4 -0
  81. package/lib/services/orders/submitOrder.d.ts.map +1 -0
  82. package/lib/services/orders/submitOrder.js +105 -0
  83. package/lib/services/orders/submitOrder.js.map +1 -0
  84. package/lib/utils.d.ts +1 -2
  85. package/lib/utils.d.ts.map +1 -1
  86. package/lib/utils.js +3 -23
  87. package/lib/utils.js.map +1 -1
  88. package/package.json +3 -4
  89. package/temp/package-deps.json +22 -18
  90. package/dist/account-spot.js.map +0 -1
  91. package/dist/account.js.map +0 -1
  92. package/dist/api.js +0 -55
  93. package/dist/api.js.map +0 -1
  94. package/dist/cli.js +0 -3
  95. package/dist/cli.js.map +0 -1
  96. package/dist/interest_rate.js.map +0 -1
  97. package/dist/order-spot.js +0 -38
  98. package/dist/order-spot.js.map +0 -1
  99. package/dist/order.js +0 -70
  100. package/dist/order.js.map +0 -1
  101. package/dist/pending-orders.js +0 -43
  102. package/dist/pending-orders.js.map +0 -1
  103. package/dist/product.js.map +0 -1
  104. package/dist/quote.js.map +0 -1
  105. package/dist/sapi.js +0 -48
  106. package/dist/sapi.js.map +0 -1
  107. package/lib/account-spot.d.ts +0 -2
  108. package/lib/account-spot.d.ts.map +0 -1
  109. package/lib/account-spot.js.map +0 -1
  110. package/lib/account.d.ts +0 -2
  111. package/lib/account.d.ts.map +0 -1
  112. package/lib/account.js.map +0 -1
  113. package/lib/api.d.ts +0 -149
  114. package/lib/api.d.ts.map +0 -1
  115. package/lib/api.js +0 -58
  116. package/lib/api.js.map +0 -1
  117. package/lib/cli.d.ts +0 -3
  118. package/lib/cli.d.ts.map +0 -1
  119. package/lib/cli.js +0 -5
  120. package/lib/cli.js.map +0 -1
  121. package/lib/interest_rate.d.ts.map +0 -1
  122. package/lib/interest_rate.js.map +0 -1
  123. package/lib/order-spot.d.ts +0 -2
  124. package/lib/order-spot.d.ts.map +0 -1
  125. package/lib/order-spot.js +0 -40
  126. package/lib/order-spot.js.map +0 -1
  127. package/lib/order.d.ts +0 -2
  128. package/lib/order.d.ts.map +0 -1
  129. package/lib/order.js +0 -72
  130. package/lib/order.js.map +0 -1
  131. package/lib/pending-orders.d.ts +0 -2
  132. package/lib/pending-orders.d.ts.map +0 -1
  133. package/lib/pending-orders.js +0 -45
  134. package/lib/pending-orders.js.map +0 -1
  135. package/lib/product.d.ts.map +0 -1
  136. package/lib/product.js.map +0 -1
  137. package/lib/quote.js.map +0 -1
  138. package/lib/sapi.d.ts +0 -37
  139. package/lib/sapi.d.ts.map +0 -1
  140. package/lib/sapi.js +0 -51
  141. package/lib/sapi.js.map +0 -1
  142. /package/lib/{interest_rate.d.ts → services/markets/interest_rate.d.ts} +0 -0
  143. /package/lib/{product.d.ts → services/markets/product.d.ts} +0 -0
  144. /package/lib/{quote.d.ts → services/markets/quote.d.ts} +0 -0
package/dist/quote.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"quote.js","sourceRoot":"","sources":["../src/quote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,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;AAEtF,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEpE,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;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,EAAE,IAAI,IAAI,CAAC,MAAA,MAAM,CAAC,IAAI,mCAAI,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;KAC9D,CAAC,CAAA;CAAA,CACH,CACF,EACH,CAAC,CACF,EACD,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACvB,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACtB,WAAW,CAAC,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,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 { 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 type { IQuote } from '../../../libraries/data-quote/lib';\nimport { getFApiV1OpenInterest, getFApiV1TickerPrice } from './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"]}
package/dist/sapi.js DELETED
@@ -1,48 +0,0 @@
1
- import { opensslEquivalentHMAC } from './utils';
2
- const API_KEY = process.env.API_KEY;
3
- const SECRET_KEY = process.env.SECRET_KEY;
4
- const BASE_URL = 'https://sapi.asterdex.com';
5
- const request = async (type, method, endpoint, params = {}) => {
6
- const needApiKey = type !== 'NONE';
7
- const needSign = type === 'TRADE' || type === 'USER_DATA';
8
- const url = new URL(BASE_URL);
9
- url.pathname = endpoint;
10
- for (const [key, value] of Object.entries(params)) {
11
- if (value === undefined)
12
- continue;
13
- url.searchParams.set(key, `${value}`);
14
- }
15
- if (needSign) {
16
- url.searchParams.set('timestamp', `${Date.now()}`);
17
- const msg = url.search.slice(1); // 去掉开头的 '?'
18
- const signature = await opensslEquivalentHMAC(msg, SECRET_KEY);
19
- url.searchParams.set('signature', signature);
20
- }
21
- console.info(url.toString());
22
- const response = await fetch(url.toString(), {
23
- method,
24
- headers: needApiKey
25
- ? {
26
- 'X-MBX-APIKEY': API_KEY,
27
- }
28
- : {},
29
- }).then((response) => response.json());
30
- if (response.code && response.code !== 0) {
31
- throw JSON.stringify(response);
32
- }
33
- return response;
34
- };
35
- const createApi = (type, method, endpoint) => (params) => request(type, method, endpoint, params);
36
- /**
37
- * 获取账户信息 (现货)
38
- *
39
- * 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
40
- */
41
- export const getApiV1Account = createApi('USER_DATA', 'GET', '/api/v1/account');
42
- /**
43
- * 获取最新价格
44
- * 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
45
- */
46
- export const getApiV1TickerPrice = createApi('MARKET_DATA', 'GET', '/api/v1/ticker/price');
47
- export const postApiV1Order = createApi('TRADE', 'POST', '/api/v1/order');
48
- //# sourceMappingURL=sapi.js.map
package/dist/sapi.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"sapi.js","sourceRoot":"","sources":["../src/sapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEhD,MAAM,O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;QACN,OAAO,EAAE,UAAU;YACjB,CAAC,CAAC;gBACE,cAAc,EAAE,OAAO;aACxB;YACH,CAAC,CAAC,EAAE;KACP,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAS,CAAC,CAAC;IAE9C,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE;QACxC,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;KAChC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,SAAS,GACb,CACE,IAAoE,EACpE,MAAc,EACd,QAAgB,EAChB,EAAE,CACJ,CAAC,MAAY,EAAE,EAAE,CACf,OAAO,CAAO,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAetC,WAAW,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAO1C,aAAa,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAEhD,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAWrC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { opensslEquivalentHMAC } from './utils';\n\nconst API_KEY = process.env.API_KEY!;\nconst SECRET_KEY = process.env.SECRET_KEY!;\n\nconst BASE_URL = 'https://sapi.asterdex.com';\n\nconst request = async <T>(\n type: 'NONE' | 'TRADE' | 'USER_DATA' | 'USER_STREAM' | 'MARKET_DATA',\n method: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const needApiKey = type !== 'NONE';\n const needSign = type === 'TRADE' || type === 'USER_DATA';\n\n const url = new URL(BASE_URL);\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 if (needSign) {\n url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = await opensslEquivalentHMAC(msg, SECRET_KEY);\n url.searchParams.set('signature', signature);\n }\n\n console.info(url.toString());\n\n const response = await fetch(url.toString(), {\n method,\n headers: needApiKey\n ? {\n 'X-MBX-APIKEY': API_KEY,\n }\n : {},\n }).then((response) => response.json() as any);\n\n if (response.code && response.code !== 0) {\n throw JSON.stringify(response);\n }\n\n return response;\n};\n\nconst createApi =\n <TReq, TRes>(\n type: 'NONE' | 'TRADE' | 'USER_DATA' | 'USER_STREAM' | 'MARKET_DATA',\n method: string,\n endpoint: string,\n ) =>\n (params: TReq) =>\n request<TRes>(type, method, endpoint, params);\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 = createApi<\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>('USER_DATA', '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 = createApi<\n {},\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n>('MARKET_DATA', 'GET', '/api/v1/ticker/price');\n\nexport const postApiV1Order = createApi<\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>('TRADE', 'POST', '/api/v1/order');\n"]}
@@ -1,2 +0,0 @@
1
- export declare const SPOT_ACCOUNT_ID: string;
2
- //# sourceMappingURL=account-spot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account-spot.d.ts","sourceRoot":"","sources":["../src/account-spot.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,eAAe,QAA0B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"account-spot.js","sourceRoot":"","sources":["../src/account-spot.ts"],"names":[],"mappings":";;;AAAA,uDAA4E;AAC5E,+CAA4C;AAC5C,iCAA8D;AAE9D,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAQ,CAAC;AACxB,QAAA,eAAe,GAAG,SAAS,OAAO,OAAO,CAAC;AAEvD,IAAA,wCAAyB,EACvB,mBAAQ,CAAC,WAAW,EAAE,EACtB,uBAAe,EACf,KAAK,IAAI,EAAE;IACT,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAA,sBAAe,EAAC,EAAE,CAAC,EAAE,IAAA,0BAAmB,EAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEtF,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,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;QAEnC,MAAM,cAAc,GAAG,CAAC,QAAQ,CAAC;QACjC,MAAM,cAAc,GAAG,CAAC,QAAQ,CAAC;QACjC,MAAM,SAAS,GAAG,MAAM,GAAG,cAAc,CAAC;QAC1C,MAAM,eAAe,GAAG,CAAC,CAAC;QAE1B,OAAO;YACL,WAAW,EAAE,CAAC,CAAC,KAAK;YACpB,aAAa,EAAE,OAAO;YACtB,UAAU,EAAE,CAAC,CAAC,KAAK;YACnB,SAAS,EAAE,MAAM;YACjB,MAAM;YACN,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;YACpB,cAAc;YACd,cAAc;YACd,eAAe;YACf,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7C,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS;KACV,CAAC;AACJ,CAAC,EACD,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAChC,CAAC","sourcesContent":["import { IPosition, provideAccountInfoService } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { getApiV1Account, getApiV1TickerPrice } from './sapi';\n\nconst ADDRESS = process.env.ADDRESS!;\nexport const SPOT_ACCOUNT_ID = `ASTER/${ADDRESS}/SPOT`;\n\nprovideAccountInfoService(\n Terminal.fromNodeEnv(),\n SPOT_ACCOUNT_ID,\n async () => {\n const [x, prices] = await Promise.all([getApiV1Account({}), getApiV1TickerPrice({})]);\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 const volume = +b.free + +b.locked;\n\n const position_price = +thePrice;\n const closable_price = +thePrice;\n const valuation = volume * closable_price;\n const floating_profit = 0;\n\n return {\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: b.asset,\n direction: 'LONG',\n volume,\n free_volume: +b.free,\n position_price,\n closable_price,\n floating_profit,\n valuation,\n };\n });\n\n const usdtAsset = x.balances.find((b) => b.asset === 'USDT');\n const equity = positions.reduce((a, b) => a + b.valuation, 0);\n const free = usdtAsset ? +usdtAsset.free : 0;\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n },\n { auto_refresh_interval: 1000 },\n);\n"]}
package/lib/account.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const ACCOUNT_ID: string;
2
- //# sourceMappingURL=account.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU,QAAqB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;AAAA,uDAA4E;AAC5E,+CAA4C;AAC5C,yCAA2C;AAC3C,+BAAyC;AAEzC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAQ,CAAC;AACxB,QAAA,UAAU,GAAG,SAAS,OAAO,EAAE,CAAC;AAE7C,IAAA,wCAAyB,EACvB,mBAAQ,CAAC,WAAW,EAAE,EACtB,kBAAU,EACV,KAAK,IAAI,EAAE;IACT,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAA,sBAAgB,EAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEtD,MAAM,MAAM,GAAG,CAAC,CAAC,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ent":["import { IPosition, provideAccountInfoService } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFApiV4Account } from './api';\n\nconst ADDRESS = process.env.ADDRESS!;\nexport const ACCOUNT_ID = `ASTER/${ADDRESS}`;\n\nprovideAccountInfoService(\n Terminal.fromNodeEnv(),\n ACCOUNT_ID,\n async () => {\n const [a] = await Promise.all([getFApiV4Account({})]);\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 {\n money: {\n currency: 'USD',\n equity,\n free,\n },\n positions,\n };\n },\n { auto_refresh_interval: 1000 },\n);\n"]}
package/lib/api.d.ts DELETED
@@ -1,149 +0,0 @@
1
- /**
2
- * 获取账户信息
3
- *
4
- * 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
5
- */
6
- export declare const getFApiV4Account: (params: {}) => Promise<{
7
- feeTier: number;
8
- canTrade: boolean;
9
- canDeposit: boolean;
10
- canWithdraw: boolean;
11
- updateTime: number;
12
- totalInitialMargin: string;
13
- totalMaintMargin: string;
14
- totalWalletBalance: string;
15
- totalUnrealizedProfit: string;
16
- totalMarginBalance: string;
17
- totalPositionInitialMargin: string;
18
- totalOpenOrderInitialMargin: string;
19
- totalCrossWalletBalance: string;
20
- totalCrossUnPnl: string;
21
- availableBalance: string;
22
- maxWithdrawAmount: string;
23
- assets: {
24
- asset: string;
25
- walletBalance: string;
26
- unrealizedProfit: string;
27
- marginBalance: string;
28
- maintMargin: string;
29
- initialMargin: string;
30
- positionInitialMargin: string;
31
- openOrderInitialMargin: string;
32
- maxWithdrawAmount: string;
33
- crossWalletBalance: string;
34
- crossUnPnl: string;
35
- availableBalance: string;
36
- marginAvailable: boolean;
37
- updateTime: number;
38
- }[];
39
- positions: {
40
- symbol: string;
41
- initialMargin: string;
42
- maintMargin: string;
43
- unrealizedProfit: string;
44
- positionInitialMargin: string;
45
- openOrderInitialMargin: string;
46
- leverage: string;
47
- isolated: boolean;
48
- entryPrice: string;
49
- maxNotional: string;
50
- positionSide: 'BOTH' | 'LONG' | 'SHORT';
51
- positionAmt: string;
52
- notional: string;
53
- isolatedWallet: string;
54
- updateTime: number;
55
- }[];
56
- }>;
57
- export declare const getFApiV2Balance: (params: {}) => Promise<{
58
- accountAlias: string;
59
- asset: string;
60
- balance: string;
61
- crossWalletBalance: string;
62
- crossUnPnl: string;
63
- availableBalance: string;
64
- maxWithdrawAmount: string;
65
- marginAvailable: boolean;
66
- updateTime: number;
67
- }[]>;
68
- export declare const getFApiV1TickerPrice: (params: {}) => Promise<{
69
- symbol: string;
70
- price: string;
71
- time?: number | undefined;
72
- }[]>;
73
- export declare const getFApiV1OpenInterest: (params: {
74
- symbol: string;
75
- }) => Promise<{
76
- symbol: string;
77
- openInterest: string;
78
- time: number;
79
- }>;
80
- export declare const getFApiV1FundingRate: (params: {
81
- symbol?: string | undefined;
82
- startTime?: number | undefined;
83
- endTime?: number | undefined;
84
- limit?: number | undefined;
85
- }) => Promise<{
86
- symbol: string;
87
- fundingRate: string;
88
- fundingTime: number;
89
- }[]>;
90
- export declare const postFApiV1Order: (params: {
91
- symbol: string;
92
- side: 'BUY' | 'SELL';
93
- positionSide?: "LONG" | "BOTH" | "SHORT" | undefined;
94
- type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET' | 'TRAILING_STOP_MARKET';
95
- reduceOnly?: "true" | "false" | undefined;
96
- quantity?: number | undefined;
97
- price?: number | undefined;
98
- timeInForce?: "GTC" | "IOC" | "FOK" | "GTX" | "HIDDEN" | undefined;
99
- }) => Promise<{}>;
100
- export declare const getFApiV1OpenOrders: (params: {
101
- symbol?: string | undefined;
102
- }) => Promise<{
103
- orderId: number;
104
- clientOrderId: string;
105
- price: string;
106
- origQty: string;
107
- executedQty: string;
108
- status: string;
109
- timeInForce: string;
110
- type: string;
111
- side: 'BUY' | 'SELL';
112
- updateTime: number;
113
- avgPrice: string;
114
- reduceOnly?: boolean | undefined;
115
- closePosition?: boolean | undefined;
116
- positionSide?: "LONG" | "BOTH" | "SHORT" | undefined;
117
- workingType?: string | undefined;
118
- priceProtect?: boolean | undefined;
119
- origType?: string | undefined;
120
- stopPrice?: string | undefined;
121
- symbol: string;
122
- }[]>;
123
- export declare const deleteFApiV1Order: (params: {
124
- symbol: string;
125
- orderId?: string | number | undefined;
126
- origClientOrderId?: string | undefined;
127
- }) => Promise<{}>;
128
- /**
129
- * 获取交易对信息
130
- *
131
- * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E4%BA%A4%E6%98%93%E5%AF%B9%E4%BF%A1%E6%81%AF
132
- */
133
- export declare const getFApiV1ExchangeInfo: (params: {}) => Promise<{
134
- symbols: {
135
- symbol: string;
136
- status: 'TRADING' | 'BREAK' | 'HALT';
137
- baseAsset: string;
138
- quoteAsset: string;
139
- pricePrecision: number;
140
- quantityPrecision: number;
141
- baseAssetPrecision: number;
142
- quotePrecision: number;
143
- filters: {
144
- [key: string]: any;
145
- filterType: string;
146
- }[];
147
- }[];
148
- }>;
149
- //# sourceMappingURL=api.d.ts.map
package/lib/api.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAsDA;;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GX,MAAM;WACb,MAAM;aACJ,MAAM;wBACK,MAAM;gBACd,MAAM;sBACA,MAAM;uBACL,MAAM;qBACR,OAAO;gBACZ,MAAM;IAEmB,CAAC;AAE1C,eAAO,MAAM,oBAAoB;YAGrB,MAAM;WACP,MAAM;;IAG+B,CAAC;AAEjD,eAAO,MAAM,qBAAqB;YAEtB,MAAM;;YAGN,MAAM;kBACA,MAAM;UACd,MAAM;EAEgC,CAAC;AAEjD,eAAO,MAAM,oBAAoB;;;;;;YAQrB,MAAM;iBACD,MAAM;iBACN,MAAM;IAEiB,CAAC;AAEzC,eAAO,MAAM,eAAe;YAEhB,MAAM;UACR,KAAK,GAAG,MAAM;;UAGhB,QAAQ,GACR,OAAO,GACP,MAAM,GACN,aAAa,GACb,aAAa,GACb,oBAAoB,GACpB,sBAAsB;;;;;iBAOM,CAAC;AAErC,eAAO,MAAM,mBAAmB;;;aAKnB,MAAM;mBACA,MAAM;WACd,MAAM;aACJ,MAAM;iBACF,MAAM;YACX,MAAM;iBACD,MAAM;UACb,MAAM;UACN,KAAK,GAAG,MAAM;gBACR,MAAM;cACR,MAAM;;;;;;;;YAQR,MAAM;IAE0B,CAAC;AAE7C,eAAO,MAAM,iBAAiB;YAElB,MAAM;;;iBAKoB,CAAC;AAEvC;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;gBAIpB,MAAM;gBACN,SAAS,GAAG,OAAO,GAAG,MAAM;mBACzB,MAAM;oBACL,MAAM;wBACF,MAAM;2BACH,MAAM;4BACL,MAAM;wBACV,MAAM;;;wBAER,MAAM;;;EAKe,CAAC"}
package/lib/api.js DELETED
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFApiV1ExchangeInfo = exports.deleteFApiV1Order = exports.getFApiV1OpenOrders = exports.postFApiV1Order = exports.getFApiV1FundingRate = exports.getFApiV1OpenInterest = exports.getFApiV1TickerPrice = exports.getFApiV2Balance = exports.getFApiV4Account = void 0;
4
- const utils_1 = require("./utils");
5
- const API_KEY = process.env.API_KEY;
6
- const SECRET_KEY = process.env.SECRET_KEY;
7
- const BASE_URL = 'https://fapi.asterdex.com';
8
- const request = async (type, method, endpoint, params = {}) => {
9
- const needApiKey = type !== 'NONE';
10
- const needSign = type === 'TRADE' || type === 'USER_DATA';
11
- const url = new URL(BASE_URL);
12
- url.pathname = endpoint;
13
- for (const [key, value] of Object.entries(params)) {
14
- if (value === undefined)
15
- continue;
16
- url.searchParams.set(key, `${value}`);
17
- }
18
- if (needSign) {
19
- url.searchParams.set('timestamp', `${Date.now()}`);
20
- const msg = url.search.slice(1); // 去掉开头的 '?'
21
- const signature = await (0, utils_1.opensslEquivalentHMAC)(msg, SECRET_KEY);
22
- url.searchParams.set('signature', signature);
23
- }
24
- console.info(url.toString());
25
- const res = await fetch(url.toString(), {
26
- method,
27
- headers: needApiKey
28
- ? {
29
- 'X-MBX-APIKEY': API_KEY,
30
- }
31
- : {},
32
- }).then((response) => response.json());
33
- if (res.code && res.code !== 0) {
34
- throw JSON.stringify(res);
35
- }
36
- return res;
37
- };
38
- const createApi = (type, method, endpoint) => (params) => request(type, method, endpoint, params);
39
- /**
40
- * 获取账户信息
41
- *
42
- * 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
43
- */
44
- exports.getFApiV4Account = createApi('USER_DATA', 'GET', '/fapi/v4/account');
45
- exports.getFApiV2Balance = createApi('USER_DATA', 'GET', '/fapi/v2/balance');
46
- exports.getFApiV1TickerPrice = createApi('MARKET_DATA', 'GET', '/fapi/v1/ticker/price');
47
- exports.getFApiV1OpenInterest = createApi('MARKET_DATA', 'GET', '/fapi/v1/openInterest');
48
- exports.getFApiV1FundingRate = createApi('NONE', 'GET', '/fapi/v1/fundingRate');
49
- exports.postFApiV1Order = createApi('TRADE', 'POST', '/fapi/v1/order');
50
- exports.getFApiV1OpenOrders = createApi('USER_DATA', 'GET', '/fapi/v1/openOrders');
51
- exports.deleteFApiV1Order = createApi('TRADE', 'DELETE', '/fapi/v1/order');
52
- /**
53
- * 获取交易对信息
54
- *
55
- * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E4%BA%A4%E6%98%93%E5%AF%B9%E4%BF%A1%E6%81%AF
56
- */
57
- exports.getFApiV1ExchangeInfo = createApi('NONE', 'GET', '/fapi/v1/exchangeInfo');
58
- //# sourceMappingURL=api.js.map
package/lib/api.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AAAA,mCAAgD;AAEhD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAQ,CAAC;AACrC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAW,CAAC;AAE3C,MAAM,QAAQ,GAAG,2BAA2B,CAAC;AAE7C,MAAM,OAAO,GAAG,KAAK,EACnB,IAAoE,EACpE,MAAc,EACd,QAAgB,EAChB,SAAc,EAAE,EACJ,EAAE;IACd,MAAM,UAAU,GAAG,IAAI,KAAK,MAAM,CAAC;IACnC,MAAM,QAAQ,GAAG,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,WAAW,CAAC;IAE1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,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,IAAI,QAAQ,EAAE;QACZ,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,GAAG,EAA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C;AAEpC,QAAA,qBAAqB,GAAG,SAAS,CAS5C,aAAa,EAAE,KAAK,EAAE,uBAAuB,CAAC,CAAC;AAEpC,QAAA,oBAAoB,GAAG,SAAS,CAY3C,MAAM,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAE5B,QAAA,eAAe,GAAG,SAAS,CAmBtC,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAExB,QAAA,mBAAmB,GAAG,SAAS,CAyB1C,WAAW,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC;AAEhC,QAAA,iBAAiB,GAAG,SAAS,CAOxC,OAAO,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AAEvC;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,SAAS,CAkB5C,MAAM,EAAE,KAAK,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import { opensslEquivalentHMAC } from './utils';\n\nconst API_KEY = process.env.API_KEY!;\nconst SECRET_KEY = process.env.SECRET_KEY!;\n\nconst BASE_URL = 'https://fapi.asterdex.com';\n\nconst request = async <T>(\n type: 'NONE' | 'TRADE' | 'USER_DATA' | 'USER_STREAM' | 'MARKET_DATA',\n method: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const needApiKey = type !== 'NONE';\n const needSign = type === 'TRADE' || type === 'USER_DATA';\n\n const url = new URL(BASE_URL);\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 if (needSign) {\n url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = await opensslEquivalentHMAC(msg, SECRET_KEY);\n url.searchParams.set('signature', signature);\n }\n\n console.info(url.toString());\n const res = await fetch(url.toString(), {\n method,\n headers: needApiKey\n ? {\n 'X-MBX-APIKEY': API_KEY,\n }\n : {},\n }).then((response) => response.json());\n if (res.code && res.code !== 0) {\n throw JSON.stringify(res);\n }\n return res;\n};\n\nconst createApi =\n <TReq, TRes>(\n type: 'NONE' | 'TRADE' | 'USER_DATA' | 'USER_STREAM' | 'MARKET_DATA',\n method: string,\n endpoint: string,\n ) =>\n (params: TReq) =>\n request<TRes>(type, method, endpoint, params);\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 = createApi<\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>('USER_DATA', 'GET', '/fapi/v4/account');\n\nexport const getFApiV2Balance = createApi<\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>('USER_DATA', 'GET', '/fapi/v2/balance');\n\nexport const getFApiV1TickerPrice = createApi<\n {},\n {\n symbol: string;\n price: string;\n time?: number;\n }[]\n>('MARKET_DATA', 'GET', '/fapi/v1/ticker/price');\n\nexport const getFApiV1OpenInterest = createApi<\n {\n symbol: string;\n },\n {\n symbol: string;\n openInterest: string;\n time: number;\n }\n>('MARKET_DATA', 'GET', '/fapi/v1/openInterest');\n\nexport const getFApiV1FundingRate = createApi<\n {\n symbol?: string;\n startTime?: number;\n endTime?: number;\n limit?: number;\n },\n {\n symbol: string;\n fundingRate: string;\n fundingTime: number;\n }[]\n>('NONE', 'GET', '/fapi/v1/fundingRate');\n\nexport const postFApiV1Order = createApi<\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>('TRADE', 'POST', '/fapi/v1/order');\n\nexport const getFApiV1OpenOrders = createApi<\n {\n symbol?: string;\n },\n {\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>('USER_DATA', 'GET', '/fapi/v1/openOrders');\n\nexport const deleteFApiV1Order = createApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('TRADE', 'DELETE', '/fapi/v1/order');\n\n/**\n * 获取交易对信息\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E4%BA%A4%E6%98%93%E5%AF%B9%E4%BF%A1%E6%81%AF\n */\nexport const getFApiV1ExchangeInfo = createApi<\n {},\n {\n symbols: {\n symbol: string;\n status: 'TRADING' | 'BREAK' | 'HALT';\n baseAsset: string;\n quoteAsset: string;\n pricePrecision: number;\n quantityPrecision: number;\n baseAssetPrecision: number;\n quotePrecision: number;\n filters: {\n filterType: string;\n [key: string]: any;\n }[];\n }[];\n }\n>('NONE', 'GET', '/fapi/v1/exchangeInfo');\n"]}
package/lib/cli.d.ts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import './index';
3
- //# sourceMappingURL=cli.d.ts.map
package/lib/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,SAAS,CAAC"}
package/lib/cli.js DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- require("./index");
5
- //# sourceMappingURL=cli.js.map
package/lib/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AACA,mBAAiB","sourcesContent":["#!/usr/bin/env node\nimport './index';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interest_rate.d.ts","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,qDAAkF;AAClF,+CAA4C;AAC5C,qCAA8C;AAC9C,yCAAmE;AACnE,+BAA4D;AAC5D,+BAA6C;AAC7C,uCAA2C;AAE3C,MA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ACV,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';\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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=order-spot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"order-spot.d.ts","sourceRoot":"","sources":["../src/order-spot.ts"],"names":[],"mappings":""}
package/lib/order-spot.js DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const protocol_1 = require("@yuants/protocol");
4
- const utils_1 = require("@yuants/utils");
5
- const account_spot_1 = require("./account-spot");
6
- const sapi_1 = require("./sapi");
7
- protocol_1.Terminal.fromNodeEnv().server.provideService('SubmitOrder', { required: ['account_id'], properties: { account_id: { type: 'string', const: account_spot_1.SPOT_ACCOUNT_ID } } }, async (msg) => {
8
- var _a;
9
- const order = msg.req;
10
- const symbol = order.product_id;
11
- const type = { MARKET: 'MARKET', LIMIT: 'LIMIT', MAKER: 'LIMIT' }[order.order_type];
12
- if (!type)
13
- throw new Error(`Unsupported order_type: ${order.order_type}`);
14
- const side = { OPEN_LONG: 'BUY', OPEN_SHORT: 'SELL', CLOSE_LONG: 'SELL', CLOSE_SHORT: 'BUY' }[order.order_direction];
15
- if (!side)
16
- throw new Error(`Unsupported order_direction: ${order.order_direction}`);
17
- const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;
18
- const price = order.price;
19
- let quantity = order.volume;
20
- let quoteOrderQty;
21
- if (type === 'MARKET' && side === 'BUY') {
22
- const spotPrice = await (0, sapi_1.getApiV1TickerPrice)({});
23
- const thePrice = (_a = spotPrice.find((x) => x.symbol === symbol)) === null || _a === void 0 ? void 0 : _a.price;
24
- if (!thePrice)
25
- throw new Error(`Cannot get price for symbol ${symbol}`);
26
- quantity = undefined;
27
- quoteOrderQty = (0, utils_1.roundToStep)(order.volume * +thePrice, 0.01);
28
- }
29
- await (0, sapi_1.postApiV1Order)({
30
- symbol,
31
- type,
32
- side,
33
- timeInForce,
34
- price,
35
- quantity,
36
- quoteOrderQty,
37
- });
38
- return { res: { code: 0, message: 'OK' } };
39
- });
40
- //# sourceMappingURL=order-spot.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"order-spot.js","sourceRoot":"","sources":["../src/order-spot.ts"],"names":[],"mappings":";;AACA,+CAA4C;AAC5C,yCAA4C;AAC5C,iDAAiD;AACjD,iCAA6D;AAE7D,mBAAQ,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,cAAc,CAC1C,aAAa,EACb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Q,GAAG,MAAA,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,0CAAE,KAAK,CAAC;QACnE,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,MAAM,EAAE,CAAC,CAAC;QACxE,QAAQ,GAAG,SAAS,CAAC;QACrB,aAAa,GAAG,IAAA,mBAAW,EAAC,KAAK,CAAC,MAAM,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;KAC7D;IAED,MAAM,IAAA,qBAAc,EAAC;QACnB,MAAM;QACN,IAAI;QACJ,IAAI;QACJ,WAAW;QACX,KAAK;QACL,QAAQ;QACR,aAAa;KACd,CAAC,CAAC;IAEH,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;AAC7C,CAAC,CACF,CAAC","sourcesContent":["import { IOrder } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { roundToStep } from '@yuants/utils';\nimport { SPOT_ACCOUNT_ID } from './account-spot';\nimport { getApiV1TickerPrice, postApiV1Order } from './sapi';\n\nTerminal.fromNodeEnv().server.provideService<IOrder>(\n 'SubmitOrder',\n { required: ['account_id'], properties: { account_id: { type: 'string', const: SPOT_ACCOUNT_ID } } },\n async (msg) => {\n const order = msg.req;\n const symbol = order.product_id;\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 =\n 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({});\n const thePrice = spotPrice.find((x) => x.symbol === symbol)?.price;\n if (!thePrice) throw new Error(`Cannot get price for symbol ${symbol}`);\n quantity = undefined;\n quoteOrderQty = roundToStep(order.volume * +thePrice, 0.01);\n }\n\n await postApiV1Order({\n symbol,\n type,\n side,\n timeInForce,\n price,\n quantity,\n quoteOrderQty,\n });\n\n return { res: { code: 0, message: 'OK' } };\n },\n);\n"]}
package/lib/order.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=order.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":""}
package/lib/order.js DELETED
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const protocol_1 = require("@yuants/protocol");
4
- const utils_1 = require("@yuants/utils");
5
- const account_1 = require("./account");
6
- const api_1 = require("./api");
7
- const terminal = protocol_1.Terminal.fromNodeEnv();
8
- terminal.server.provideService('SubmitOrder', { required: ['account_id'], properties: { account_id: { type: 'string', const: account_1.ACCOUNT_ID } } }, async (msg) => {
9
- var _a, _b, _c, _d, _e;
10
- const order = msg.req;
11
- const [, decodedSymbol] = (0, utils_1.decodePath)(order.product_id);
12
- if (!decodedSymbol) {
13
- throw new Error(`Invalid product_id: unable to decode symbol from "${order.product_id}"`);
14
- }
15
- const symbol = decodedSymbol;
16
- const side = { OPEN_LONG: 'BUY', OPEN_SHORT: 'SELL', CLOSE_LONG: 'SELL', CLOSE_SHORT: 'BUY' }[order.order_direction];
17
- if (!side)
18
- throw new Error(`Unsupported order_direction: ${order.order_direction}`);
19
- const type = { MARKET: 'MARKET', LIMIT: 'LIMIT', MAKER: 'LIMIT' }[order.order_type];
20
- if (!type)
21
- throw new Error(`Unsupported order_type: ${order.order_type}`);
22
- const quantity = order.volume;
23
- const price = order.price;
24
- const positionSide = order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_LONG'
25
- ? 'LONG'
26
- : order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_SHORT'
27
- ? 'SHORT'
28
- : undefined;
29
- const reduceOnly = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'true' : undefined;
30
- const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;
31
- const res = await (0, api_1.postFApiV1Order)({
32
- symbol,
33
- side,
34
- type,
35
- quantity,
36
- price,
37
- timeInForce,
38
- positionSide,
39
- reduceOnly,
40
- });
41
- const orderId = (_d = (_b = (_a = res === null || res === void 0 ? void 0 : res.orderId) !== null && _a !== void 0 ? _a : res === null || res === void 0 ? void 0 : res.order_id) !== null && _b !== void 0 ? _b : (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.orderId) !== null && _d !== void 0 ? _d : (_e = res === null || res === void 0 ? void 0 : res.data) === null || _e === void 0 ? void 0 : _e.order_id;
42
- return {
43
- res: {
44
- code: 0,
45
- message: 'OK',
46
- data: orderId ? { order_id: `${orderId}` } : undefined,
47
- },
48
- };
49
- });
50
- terminal.server.provideService('CancelOrder', {
51
- required: ['account_id', 'order_id', 'product_id'],
52
- properties: {
53
- account_id: { type: 'string', const: account_1.ACCOUNT_ID },
54
- order_id: { type: ['string', 'number'] },
55
- product_id: { type: 'string' },
56
- },
57
- }, async (msg) => {
58
- const order = msg.req;
59
- const [, decodedSymbol] = (0, utils_1.decodePath)(order.product_id);
60
- if (!decodedSymbol) {
61
- throw new Error(`Invalid product_id: unable to decode symbol from "${order.product_id}"`);
62
- }
63
- if (!order.order_id) {
64
- throw new Error('order_id is required for CancelOrder');
65
- }
66
- await (0, api_1.deleteFApiV1Order)({
67
- symbol: decodedSymbol,
68
- orderId: order.order_id,
69
- });
70
- return { res: { code: 0, message: 'OK' } };
71
- });
72
- //# sourceMappingURL=order.js.map
package/lib/order.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAE5C,yCAA2C;AAC3C,uCAAuC;AACvC,+BAA2D;AAE3D,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,aAAa,EACb,EAAE,QAAQ,EAAE,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,oBAAU,EAAE,EAAE,EAAE,EAC/F,KAAK,EAAE,GAAG,EAAE,EAAE;;IACZ,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;IAEtB,MAAM,CAAC,EAAE,aAAa,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACvD,IAAI,CAAC,aAAa,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,qDAAqD,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC;KAC3F;IACD,MAAM,MAAM,GAAG,aAAa,CAAC;IAE7B,MAAM,IAAI,GAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAY,CACtG,KAAK,CAAC,eAAgB,CACvB,CAAC;IACF,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;IAEpF,MAAM,IAAI,GAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAY,CAAC,KAAK,CAAC,UAAW,CAAC,CAAC;IAChG,IAAI,CAAC,IAAI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import { ACCOUNT_ID } from './account';\nimport { deleteFApiV1Order, postFApiV1Order } from './api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nterminal.server.provideService<IOrder, { order_id?: string }>(\n 'SubmitOrder',\n { required: ['account_id'], properties: { account_id: { type: 'string', const: ACCOUNT_ID } } },\n async (msg) => {\n const order = msg.req;\n\n const [, decodedSymbol] = decodePath(order.product_id);\n if (!decodedSymbol) {\n throw new Error(`Invalid product_id: unable to decode symbol from \"${order.product_id}\"`);\n }\n const symbol = decodedSymbol;\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 =\n order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const res = await postFApiV1Order({\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 return {\n res: {\n code: 0,\n message: 'OK',\n data: orderId ? { order_id: `${orderId}` } : undefined,\n },\n };\n },\n);\n\nterminal.server.provideService<IOrder>(\n 'CancelOrder',\n {\n required: ['account_id', 'order_id', 'product_id'],\n properties: {\n account_id: { type: 'string', const: ACCOUNT_ID },\n order_id: { type: ['string', 'number'] },\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n const order = msg.req;\n const [, decodedSymbol] = decodePath(order.product_id);\n if (!decodedSymbol) {\n throw new Error(`Invalid product_id: unable to decode symbol from \"${order.product_id}\"`);\n }\n if (!order.order_id) {\n throw new Error('order_id is required for CancelOrder');\n }\n\n await deleteFApiV1Order({\n symbol: decodedSymbol,\n orderId: order.order_id,\n });\n\n return { res: { code: 0, message: 'OK' } };\n },\n);\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=pending-orders.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pending-orders.d.ts","sourceRoot":"","sources":["../src/pending-orders.ts"],"names":[],"mappings":""}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const data_order_1 = require("@yuants/data-order");
4
- const protocol_1 = require("@yuants/protocol");
5
- const utils_1 = require("@yuants/utils");
6
- const account_1 = require("./account");
7
- const api_1 = require("./api");
8
- const terminal = protocol_1.Terminal.fromNodeEnv();
9
- const resolveOrderDirection = (asterOrder) => {
10
- const reduceOnly = asterOrder.reduceOnly || asterOrder.closePosition;
11
- if (asterOrder.positionSide === 'LONG') {
12
- return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';
13
- }
14
- if (asterOrder.positionSide === 'SHORT') {
15
- return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'OPEN_SHORT';
16
- }
17
- if (reduceOnly) {
18
- return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'CLOSE_LONG';
19
- }
20
- return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT';
21
- };
22
- (0, data_order_1.providePendingOrdersService)(terminal, account_1.ACCOUNT_ID, async () => {
23
- const orders = (await (0, api_1.getFApiV1OpenOrders)({}));
24
- return orders.map((order) => {
25
- const volume = Number(order.origQty);
26
- const tradedVolume = Number(order.executedQty);
27
- const price = Number(order.price);
28
- const avgPrice = Number(order.avgPrice);
29
- const mapped = {
30
- order_id: `${order.orderId}`,
31
- account_id: account_1.ACCOUNT_ID,
32
- product_id: (0, utils_1.encodePath)('PERPETUAL', order.symbol),
33
- order_type: order.type,
34
- order_direction: resolveOrderDirection(order),
35
- volume: Number.isFinite(volume) ? volume : 0,
36
- price: Number.isFinite(price) ? price : undefined,
37
- submit_at: order.updateTime,
38
- traded_volume: Number.isFinite(tradedVolume) ? tradedVolume : undefined,
39
- traded_price: Number.isFinite(avgPrice) && avgPrice > 0 ? avgPrice : undefined,
40
- order_status: order.status,
41
- };
42
- return mapped;
43
- });
44
- }, { auto_refresh_interval: 2000 });
45
- //# sourceMappingURL=pending-orders.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pending-orders.js","sourceRoot":"","sources":["../src/pending-orders.ts"],"names":[],"mappings":";;AAAA,mDAAyE;AACzE,+CAA4C;AAC5C,yCAA2C;AAC3C,uCAAuC;AACvC,+BAA4C;AAE5C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAoBxC,MAAM,qBAAqB,GAAG,CAAC,UAA2B,EAAkB,EAAE;IAC5E,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,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YACvE,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YAC9E,YAAY,EAAE,KAAK,CAAC,MAAM;SAC3B,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAChC,CAAC","sourcesContent":["import { IOrder, providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { ACCOUNT_ID } from './account';\nimport { getFApiV1OpenOrders } from './api';\n\nconst terminal = Terminal.fromNodeEnv();\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\ninterface IAsterOpenOrder {\n orderId: number;\n symbol: string;\n side: 'BUY' | 'SELL';\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n reduceOnly?: boolean;\n closePosition?: boolean;\n type: string;\n origQty: string;\n executedQty: string;\n price: string;\n avgPrice: string;\n status: string;\n updateTime: number;\n}\n\nconst resolveOrderDirection = (asterOrder: IAsterOpenOrder): 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\nprovidePendingOrdersService(\n terminal,\n ACCOUNT_ID,\n async () => {\n const orders = (await getFApiV1OpenOrders({})) as IAsterOpenOrder[];\n return orders.map((order) => {\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 const mapped: IOrder = {\n order_id: `${order.orderId}`,\n account_id: ACCOUNT_ID,\n product_id: encodePath('PERPETUAL', order.symbol),\n order_type: order.type,\n order_direction: resolveOrderDirection(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 return mapped;\n });\n },\n { auto_refresh_interval: 2000 },\n);\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../src/product.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,sDA4C1B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../src/product.ts"],"names":[],"mappings":";;;AAAA,uDAAoG;AACpG,+CAA4C;AAC5C,yCAA2C;AAC3C,+BAA8C;AAE9C,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,2BAAqB,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,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,IAAA,kBAAU,EAAC,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';\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"]}