@yuants/vendor-okx 0.23.24 → 0.23.26

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 (139) hide show
  1. package/dist/account.js +16 -138
  2. package/dist/account.js.map +1 -1
  3. package/dist/accountInfos/earning.js +15 -0
  4. package/dist/accountInfos/earning.js.map +1 -0
  5. package/dist/accountInfos/funding.js +46 -0
  6. package/dist/accountInfos/funding.js.map +1 -0
  7. package/dist/accountInfos/index.js +7 -0
  8. package/dist/accountInfos/index.js.map +1 -0
  9. package/dist/accountInfos/loan.js +46 -0
  10. package/dist/accountInfos/loan.js.map +1 -0
  11. package/dist/accountInfos/strategy.js +56 -0
  12. package/dist/accountInfos/strategy.js.map +1 -0
  13. package/dist/accountInfos/trading.js +84 -0
  14. package/dist/accountInfos/trading.js.map +1 -0
  15. package/dist/accountInfos/types.js +2 -0
  16. package/dist/accountInfos/types.js.map +1 -0
  17. package/dist/api.js +444 -402
  18. package/dist/api.js.map +1 -1
  19. package/dist/index.js +5 -4
  20. package/dist/index.js.map +1 -1
  21. package/dist/loan-account.js +4 -45
  22. package/dist/loan-account.js.map +1 -1
  23. package/dist/market-order.js +1 -1
  24. package/dist/market-order.js.map +1 -1
  25. package/dist/order-actions.js +39 -0
  26. package/dist/order-actions.js.map +1 -0
  27. package/dist/order.js +3 -3
  28. package/dist/order.js.map +1 -1
  29. package/dist/orders/cancelOrder.js +13 -0
  30. package/dist/orders/cancelOrder.js.map +1 -0
  31. package/dist/orders/modifyOrder.js +58 -0
  32. package/dist/orders/modifyOrder.js.map +1 -0
  33. package/dist/orders/submitOrder.js +107 -0
  34. package/dist/orders/submitOrder.js.map +1 -0
  35. package/dist/public-api.js.map +1 -1
  36. package/dist/quote.js.map +1 -1
  37. package/dist/services.js +3 -2
  38. package/dist/services.js.map +1 -1
  39. package/dist/strategy-account.js +8 -61
  40. package/dist/strategy-account.js.map +1 -1
  41. package/dist/trade.js +6 -5
  42. package/dist/trade.js.map +1 -1
  43. package/dist/transfer.js +279 -0
  44. package/dist/transfer.js.map +1 -0
  45. package/dist/websocket.js.map +1 -1
  46. package/lib/account.d.ts +4 -2
  47. package/lib/account.d.ts.map +1 -1
  48. package/lib/account.js +15 -138
  49. package/lib/account.js.map +1 -1
  50. package/lib/accountInfos/earning.d.ts +4 -0
  51. package/lib/accountInfos/earning.d.ts.map +1 -0
  52. package/lib/accountInfos/earning.js +19 -0
  53. package/lib/accountInfos/earning.js.map +1 -0
  54. package/lib/accountInfos/funding.d.ts +4 -0
  55. package/lib/accountInfos/funding.d.ts.map +1 -0
  56. package/lib/accountInfos/funding.js +50 -0
  57. package/lib/accountInfos/funding.js.map +1 -0
  58. package/lib/accountInfos/index.d.ts +8 -0
  59. package/lib/accountInfos/index.d.ts.map +1 -0
  60. package/lib/accountInfos/index.js +16 -0
  61. package/lib/accountInfos/index.js.map +1 -0
  62. package/lib/accountInfos/loan.d.ts +4 -0
  63. package/lib/accountInfos/loan.d.ts.map +1 -0
  64. package/lib/accountInfos/loan.js +50 -0
  65. package/lib/accountInfos/loan.js.map +1 -0
  66. package/lib/accountInfos/strategy.d.ts +4 -0
  67. package/lib/accountInfos/strategy.d.ts.map +1 -0
  68. package/lib/accountInfos/strategy.js +60 -0
  69. package/lib/accountInfos/strategy.js.map +1 -0
  70. package/lib/accountInfos/trading.d.ts +5 -0
  71. package/lib/accountInfos/trading.d.ts.map +1 -0
  72. package/lib/accountInfos/trading.js +88 -0
  73. package/lib/accountInfos/trading.js.map +1 -0
  74. package/lib/accountInfos/types.d.ts +6 -0
  75. package/lib/accountInfos/types.d.ts.map +1 -0
  76. package/lib/accountInfos/types.js +3 -0
  77. package/lib/accountInfos/types.js.map +1 -0
  78. package/lib/api.d.ts +1252 -1264
  79. package/lib/api.d.ts.map +1 -1
  80. package/lib/api.js +477 -404
  81. package/lib/api.js.map +1 -1
  82. package/lib/index.d.ts +5 -4
  83. package/lib/index.d.ts.map +1 -1
  84. package/lib/index.js +5 -4
  85. package/lib/index.js.map +1 -1
  86. package/lib/loan-account.js +3 -44
  87. package/lib/loan-account.js.map +1 -1
  88. package/lib/market-order.d.ts.map +1 -1
  89. package/lib/market-order.js +1 -1
  90. package/lib/market-order.js.map +1 -1
  91. package/lib/order-actions.d.ts +2 -0
  92. package/lib/order-actions.d.ts.map +1 -0
  93. package/lib/order-actions.js +41 -0
  94. package/lib/order-actions.js.map +1 -0
  95. package/lib/order.js +2 -2
  96. package/lib/order.js.map +1 -1
  97. package/lib/orders/cancelOrder.d.ts +4 -0
  98. package/lib/orders/cancelOrder.d.ts.map +1 -0
  99. package/lib/orders/cancelOrder.js +17 -0
  100. package/lib/orders/cancelOrder.js.map +1 -0
  101. package/lib/orders/modifyOrder.d.ts +4 -0
  102. package/lib/orders/modifyOrder.d.ts.map +1 -0
  103. package/lib/orders/modifyOrder.js +62 -0
  104. package/lib/orders/modifyOrder.js.map +1 -0
  105. package/lib/orders/submitOrder.d.ts +4 -0
  106. package/lib/orders/submitOrder.d.ts.map +1 -0
  107. package/lib/orders/submitOrder.js +111 -0
  108. package/lib/orders/submitOrder.js.map +1 -0
  109. package/lib/public-api.js.map +1 -1
  110. package/lib/quote.d.ts +1 -1
  111. package/lib/quote.d.ts.map +1 -1
  112. package/lib/quote.js.map +1 -1
  113. package/lib/services.js +2 -1
  114. package/lib/services.js.map +1 -1
  115. package/lib/strategy-account.d.ts +2 -2
  116. package/lib/strategy-account.d.ts.map +1 -1
  117. package/lib/strategy-account.js +7 -60
  118. package/lib/strategy-account.js.map +1 -1
  119. package/lib/trade.js +6 -5
  120. package/lib/trade.js.map +1 -1
  121. package/lib/transfer.d.ts +2 -0
  122. package/lib/transfer.d.ts.map +1 -0
  123. package/lib/transfer.js +281 -0
  124. package/lib/transfer.js.map +1 -0
  125. package/lib/websocket.js.map +1 -1
  126. package/package.json +13 -12
  127. package/temp/package-deps.json +40 -29
  128. package/dist/legacy_index.js +0 -563
  129. package/dist/legacy_index.js.map +0 -1
  130. package/dist/logger.js +0 -91
  131. package/dist/logger.js.map +0 -1
  132. package/lib/legacy_index.d.ts +0 -2
  133. package/lib/legacy_index.d.ts.map +0 -1
  134. package/lib/legacy_index.js +0 -565
  135. package/lib/legacy_index.js.map +0 -1
  136. package/lib/logger.d.ts +0 -21
  137. package/lib/logger.d.ts.map +0 -1
  138. package/lib/logger.js +0 -98
  139. package/lib/logger.js.map +0 -1
package/dist/account.js CHANGED
@@ -3,18 +3,17 @@ import { providePendingOrdersService } from '@yuants/data-order';
3
3
  import { Terminal } from '@yuants/protocol';
4
4
  import { encodePath } from '@yuants/utils';
5
5
  import { defer, filter, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';
6
- import { client } from './api';
7
- import { productService } from './product';
8
- import { getMarketIndexTicker } from './public-api';
6
+ import { getAccountConfig, getDefaultCredential, getTradeOrdersPending } from './api';
7
+ import { getTradingAccountInfo, getFundingAccountInfo, getEarningAccountInfo, marketIndexTickerUSDT$, } from './accountInfos';
9
8
  const terminal = Terminal.fromNodeEnv();
10
- export const accountConfig$ = defer(() => client.getAccountConfig()).pipe(repeat({ delay: 10000 }), retry({ delay: 10000 }), shareReplay(1));
11
- const subAccountUids$ = defer(() => client.getSubAccountList()).pipe(repeat({ delay: 10000 }), retry({ delay: 10000 }), shareReplay(1));
9
+ const credential = getDefaultCredential();
10
+ export const accountConfig$ = defer(() => getAccountConfig(credential)).pipe(repeat({ delay: 10000 }), retry({ delay: 10000 }), shareReplay(1));
12
11
  export const accountUid$ = accountConfig$.pipe(map((x) => x.data[0].uid), filter((x) => !!x), shareReplay(1));
13
12
  defer(async () => {
14
13
  const uid = await firstValueFrom(accountUid$);
15
14
  const account_id = `okx/${uid}/trading`;
16
15
  providePendingOrdersService(terminal, account_id, async () => {
17
- const orders = await client.getTradeOrdersPending({});
16
+ const orders = await getTradeOrdersPending(credential, {});
18
17
  return orders.data.map((x) => {
19
18
  const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';
20
19
  const order_direction = x.side === 'buy'
@@ -40,149 +39,28 @@ defer(async () => {
40
39
  });
41
40
  }, { auto_refresh_interval: 5000 });
42
41
  }).subscribe();
43
- const marketIndexTickerUSDT$ = defer(() => getMarketIndexTicker({ quoteCcy: 'USDT' })).pipe(map((x) => {
44
- const mapInstIdToPrice = new Map();
45
- x.data.forEach((inst) => mapInstIdToPrice.set(inst.instId, Number(inst.idxPx)));
46
- return mapInstIdToPrice;
47
- }), repeat({ delay: 1000 }), retry({ delay: 5000 }), shareReplay(1));
48
42
  export const tradingAccountId$ = accountUid$.pipe(map((uid) => `okx/${uid}/trading`), shareReplay(1));
49
43
  defer(async () => {
50
44
  const tradingAccountId = await firstValueFrom(tradingAccountId$);
51
45
  addAccountMarket(terminal, { account_id: tradingAccountId, market_id: 'OKX' });
52
- provideAccountInfoService(terminal, tradingAccountId, async () => {
53
- var _a;
54
- const [positionsApi, balanceApi, mapProductIdToProduct, marketIndexTickerUSDT] = await Promise.all([
55
- client.getAccountPositions({}),
56
- client.getAccountBalance({}),
57
- firstValueFrom(productService.mapProductIdToProduct$),
58
- firstValueFrom(marketIndexTickerUSDT$),
59
- ]);
60
- let totalEquity = 0;
61
- let totalFree = 0;
62
- const positions = [];
63
- (_a = balanceApi.data[0]) === null || _a === void 0 ? void 0 : _a.details.forEach((detail) => {
64
- var _a, _b, _c, _d, _e, _f;
65
- if (detail.ccy === 'USDT') {
66
- const balance = +((_a = detail.cashBal) !== null && _a !== void 0 ? _a : 0);
67
- const free = Math.min(balance, // free should no more than balance if there is much profits
68
- +((_b = detail.availEq) !== null && _b !== void 0 ? _b : 0));
69
- const equity = +((_c = detail.eq) !== null && _c !== void 0 ? _c : 0) - +((_d = detail.stgyEq) !== null && _d !== void 0 ? _d : 0);
70
- totalEquity += equity;
71
- totalFree += free;
72
- }
73
- else {
74
- const volume = +((_e = detail.cashBal) !== null && _e !== void 0 ? _e : 0);
75
- const free_volume = Math.min(volume, // free should no more than balance if there is much profits
76
- +((_f = detail.availEq) !== null && _f !== void 0 ? _f : 0));
77
- const closable_price = marketIndexTickerUSDT.get(detail.ccy + '-USDT') || 0;
78
- const delta_equity = volume * closable_price || 0;
79
- const delta_profit = +detail.totalPnl || 0;
80
- const product_id = encodePath('SPOT', `${detail.ccy}-USDT`);
81
- positions.push({
82
- position_id: product_id,
83
- datasource_id: 'OKX',
84
- product_id: product_id,
85
- direction: 'LONG',
86
- volume: volume,
87
- free_volume: free_volume,
88
- position_price: +detail.accAvgPx,
89
- floating_profit: delta_profit,
90
- closable_price: closable_price,
91
- valuation: delta_equity,
92
- });
93
- totalEquity += delta_equity;
94
- }
95
- });
96
- positionsApi.data.forEach((x) => {
97
- var _a, _b;
98
- const direction = x.posSide === 'long' ? 'LONG' : x.posSide === 'short' ? 'SHORT' : +x.pos > 0 ? 'LONG' : 'SHORT';
99
- const volume = Math.abs(+x.pos);
100
- const product_id = encodePath(x.instType, x.instId);
101
- const closable_price = +x.last;
102
- const valuation = ((_b = (_a = mapProductIdToProduct.get(product_id)) === null || _a === void 0 ? void 0 : _a.value_scale) !== null && _b !== void 0 ? _b : 1) * volume * closable_price || 0;
103
- positions.push({
104
- position_id: x.posId,
105
- datasource_id: 'OKX',
106
- product_id,
107
- direction,
108
- volume: volume,
109
- free_volume: +x.availPos,
110
- closable_price,
111
- position_price: +x.avgPx,
112
- floating_profit: +x.upl,
113
- valuation,
114
- });
115
- });
116
- return {
117
- money: {
118
- currency: 'USDT',
119
- equity: totalEquity,
120
- free: totalFree,
121
- },
122
- positions: positions,
123
- };
124
- }, { auto_refresh_interval: 1000 });
46
+ provideAccountInfoService(terminal, tradingAccountId, () => getTradingAccountInfo(credential), {
47
+ auto_refresh_interval: 1000,
48
+ });
125
49
  }).subscribe();
126
50
  defer(async () => {
127
51
  const uid = await firstValueFrom(accountUid$);
128
52
  const fundingAccountId = `okx/${uid}/funding/USDT`;
129
- provideAccountInfoService(terminal, fundingAccountId, async () => {
130
- const [assetBalances, marketIndexTickerUSDT] = await Promise.all([
131
- client.getAssetBalances({}),
132
- firstValueFrom(marketIndexTickerUSDT$),
133
- ]);
134
- const positions = [];
135
- let equity = 0;
136
- let free = 0;
137
- assetBalances.data.forEach((x) => {
138
- if (x.ccy === 'USDT') {
139
- const balance = +x.bal;
140
- equity += balance;
141
- free += balance;
142
- return;
143
- }
144
- const price = marketIndexTickerUSDT.get(`${x.ccy}-USDT`) || 0;
145
- const valuation = price * +x.bal || 0;
146
- const productId = encodePath('SPOT', `${x.ccy}-USDT`);
147
- positions.push({
148
- datasource_id: 'OKX',
149
- position_id: productId,
150
- product_id: productId,
151
- direction: 'LONG',
152
- volume: +x.bal,
153
- free_volume: +x.bal,
154
- position_price: price,
155
- floating_profit: 0,
156
- closable_price: price,
157
- valuation,
158
- });
159
- equity += valuation;
160
- });
161
- return {
162
- money: {
163
- currency: 'USDT',
164
- equity,
165
- free,
166
- },
167
- positions,
168
- };
169
- }, { auto_refresh_interval: 1000 });
53
+ provideAccountInfoService(terminal, fundingAccountId, () => getFundingAccountInfo(credential), {
54
+ auto_refresh_interval: 1000,
55
+ });
170
56
  }).subscribe();
171
57
  defer(async () => {
172
58
  const uid = await firstValueFrom(accountUid$);
173
59
  const earningAccountId = `okx/${uid}/earning/USDT`;
174
- provideAccountInfoService(terminal, earningAccountId, async () => {
175
- const offers = await client.getFinanceSavingsBalance({});
176
- const equity = offers.data.filter((x) => x.ccy === 'USDT').reduce((acc, x) => acc + +x.amt, 0);
177
- const free = equity;
178
- return {
179
- money: {
180
- currency: 'USDT',
181
- equity,
182
- free,
183
- },
184
- positions: [],
185
- };
186
- }, { auto_refresh_interval: 5000 });
60
+ provideAccountInfoService(terminal, earningAccountId, () => getEarningAccountInfo(credential), {
61
+ auto_refresh_interval: 5000,
62
+ });
187
63
  }).subscribe();
64
+ // 导出 marketIndexTickerUSDT$ 供其他模块使用
65
+ export { marketIndexTickerUSDT$ };
188
66
  //# sourceMappingURL=account.js.map
@@ -1 +1 @@
1
- {"version":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AC;AAEf,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,gBAAgB,GAAG,OAAO,GAAG,eAAe,CAAC;IACnD,yBAAyB,CACvB,QAAQ,EACR,gBAAgB,EAChB,KAAK,IAAI,EAAE;QACT,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,EAAE,CAAC,CAAC;QACzD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAC/F,MAAM,IAAI,GAAG,MAAM,CAAC;QACpB,OAAO;YACL,KAAK,EAAE;gBACL,QAAQ,EAAE,MAAM;gBAChB,MAAM;gBACN,IAAI;aACL;YACD,SAAS,EAAE,EAAE;SACd,CAAC;IACJ,CAAC,EACD,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAChC,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { addAccountMarket, IPosition, provideAccountInfoService } from '@yuants/data-account';\nimport { providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { defer, filter, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';\nimport { client } from './api';\nimport { productService } from './product';\nimport { getMarketIndexTicker } from './public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nexport const accountConfig$ = defer(() => client.getAccountConfig()).pipe(\n repeat({ delay: 10_000 }),\n retry({ delay: 10_000 }),\n shareReplay(1),\n);\n\nconst subAccountUids$ = defer(() => client.getSubAccountList()).pipe(\n repeat({ delay: 10_000 }),\n retry({ delay: 10_000 }),\n shareReplay(1),\n);\n\nexport const accountUid$ = accountConfig$.pipe(\n map((x) => x.data[0].uid),\n filter((x) => !!x),\n shareReplay(1),\n);\n\ndefer(async () => {\n const uid = await firstValueFrom(accountUid$);\n const account_id = `okx/${uid}/trading`;\n providePendingOrdersService(\n terminal,\n account_id,\n async () => {\n const orders = await client.getTradeOrdersPending({});\n return orders.data.map((x) => {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n return {\n order_id: x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n };\n });\n },\n { auto_refresh_interval: 5000 },\n );\n}).subscribe();\n\nconst marketIndexTickerUSDT$ = defer(() => getMarketIndexTicker({ quoteCcy: 'USDT' })).pipe(\n map((x) => {\n const mapInstIdToPrice = new Map<string, number>();\n x.data.forEach((inst) => mapInstIdToPrice.set(inst.instId, Number(inst.idxPx)));\n return mapInstIdToPrice;\n }),\n repeat({ delay: 1000 }),\n retry({ delay: 5000 }),\n shareReplay(1),\n);\n\nexport const tradingAccountId$ = accountUid$.pipe(\n map((uid) => `okx/${uid}/trading`),\n shareReplay(1),\n);\n\ndefer(async () => {\n const tradingAccountId = await firstValueFrom(tradingAccountId$);\n addAccountMarket(terminal, { account_id: tradingAccountId, market_id: 'OKX' });\n\n provideAccountInfoService(\n terminal,\n tradingAccountId,\n async () => {\n const [positionsApi, balanceApi, mapProductIdToProduct, marketIndexTickerUSDT] = await Promise.all([\n client.getAccountPositions({}),\n client.getAccountBalance({}),\n firstValueFrom(productService.mapProductIdToProduct$),\n firstValueFrom(marketIndexTickerUSDT$),\n ]);\n\n let totalEquity = 0;\n let totalFree = 0;\n const positions: IPosition[] = [];\n\n balanceApi.data[0]?.details.forEach((detail) => {\n if (detail.ccy === 'USDT') {\n const balance = +(detail.cashBal ?? 0);\n const free = Math.min(\n balance, // free should no more than balance if there is much profits\n +(detail.availEq ?? 0),\n );\n const equity = +(detail.eq ?? 0) - +(detail.stgyEq ?? 0);\n totalEquity += equity;\n totalFree += free;\n } else {\n const volume = +(detail.cashBal ?? 0);\n const free_volume = Math.min(\n volume, // free should no more than balance if there is much profits\n +(detail.availEq ?? 0),\n );\n const closable_price = marketIndexTickerUSDT.get(detail.ccy + '-USDT') || 0;\n const delta_equity = volume * closable_price || 0;\n const delta_profit = +detail.totalPnl || 0;\n\n const product_id = encodePath('SPOT', `${detail.ccy}-USDT`);\n positions.push({\n position_id: product_id,\n datasource_id: 'OKX',\n product_id: product_id,\n direction: 'LONG',\n volume: volume,\n free_volume: free_volume,\n position_price: +detail.accAvgPx,\n floating_profit: delta_profit,\n closable_price: closable_price,\n valuation: delta_equity,\n });\n\n totalEquity += delta_equity;\n }\n });\n positionsApi.data.forEach((x) => {\n const direction =\n x.posSide === 'long' ? 'LONG' : x.posSide === 'short' ? 'SHORT' : +x.pos > 0 ? 'LONG' : 'SHORT';\n const volume = Math.abs(+x.pos);\n const product_id = encodePath(x.instType, x.instId);\n const closable_price = +x.last;\n const valuation =\n (mapProductIdToProduct.get(product_id)?.value_scale ?? 1) * volume * closable_price || 0;\n\n positions.push({\n position_id: x.posId,\n datasource_id: 'OKX',\n product_id,\n direction,\n volume: volume,\n free_volume: +x.availPos,\n closable_price,\n position_price: +x.avgPx,\n floating_profit: +x.upl,\n valuation,\n });\n });\n return {\n money: {\n currency: 'USDT',\n equity: totalEquity,\n free: totalFree,\n },\n positions: positions,\n };\n },\n { auto_refresh_interval: 1000 },\n );\n}).subscribe();\n\ndefer(async () => {\n const uid = await firstValueFrom(accountUid$);\n\n const fundingAccountId = `okx/${uid}/funding/USDT`;\n\n provideAccountInfoService(\n terminal,\n fundingAccountId,\n async () => {\n const [assetBalances, marketIndexTickerUSDT] = await Promise.all([\n client.getAssetBalances({}),\n firstValueFrom(marketIndexTickerUSDT$),\n ]);\n\n const positions: IPosition[] = [];\n let equity = 0;\n let free = 0;\n\n assetBalances.data.forEach((x) => {\n if (x.ccy === 'USDT') {\n const balance = +x.bal;\n equity += balance;\n free += balance;\n return;\n }\n\n const price = marketIndexTickerUSDT.get(`${x.ccy}-USDT`) || 0;\n const valuation = price * +x.bal || 0;\n const productId = encodePath('SPOT', `${x.ccy}-USDT`);\n\n positions.push({\n datasource_id: 'OKX',\n position_id: productId,\n product_id: productId,\n direction: 'LONG',\n volume: +x.bal,\n free_volume: +x.bal,\n position_price: price,\n floating_profit: 0,\n closable_price: price,\n valuation,\n });\n\n equity += valuation;\n });\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n },\n { auto_refresh_interval: 1000 },\n );\n}).subscribe();\n\ndefer(async () => {\n const uid = await firstValueFrom(accountUid$);\n const earningAccountId = `okx/${uid}/earning/USDT`;\n provideAccountInfoService(\n terminal,\n earningAccountId,\n async () => {\n const offers = await client.getFinanceSavingsBalance({});\n const equity = offers.data.filter((x) => x.ccy === 'USDT').reduce((acc, x) => acc + +x.amt, 0);\n const free = equity;\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions: [],\n };\n },\n { auto_refresh_interval: 5000 },\n );\n}).subscribe();\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EA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KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACjE,gBAAgB,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAE/E,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,UAAU,CAAC,EAAE;QAC7F,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,CAAC;IAE9C,MAAM,gBAAgB,GAAG,OAAO,GAAG,eAAe,CAAC;IAEnD,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,UAAU,CAAC,EAAE;QAC7F,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,MAAM,gBAAgB,GAAG,OAAO,GAAG,eAAe,CAAC;IACnD,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,UAAU,CAAC,EAAE;QAC7F,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,oCAAoC;AACpC,OAAO,EAAE,sBAAsB,EAAE,CAAC","sourcesContent":["import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';\nimport { providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { defer, filter, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';\nimport { getAccountConfig, getDefaultCredential, getTradeOrdersPending } from './api';\nimport {\n getTradingAccountInfo,\n getFundingAccountInfo,\n getEarningAccountInfo,\n marketIndexTickerUSDT$,\n} from './accountInfos';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst credential = getDefaultCredential();\n\nexport const accountConfig$ = defer(() => getAccountConfig(credential)).pipe(\n repeat({ delay: 10_000 }),\n retry({ delay: 10_000 }),\n shareReplay(1),\n);\n\nexport const accountUid$ = accountConfig$.pipe(\n map((x) => x.data[0].uid),\n filter((x) => !!x),\n shareReplay(1),\n);\n\ndefer(async () => {\n const uid = await firstValueFrom(accountUid$);\n const account_id = `okx/${uid}/trading`;\n providePendingOrdersService(\n terminal,\n account_id,\n async () => {\n const orders = await getTradeOrdersPending(credential, {});\n return orders.data.map((x) => {\n const order_type = x.ordType === 'market' ? 'MARKET' : x.ordType === 'limit' ? 'LIMIT' : 'UNKNOWN';\n\n const order_direction =\n x.side === 'buy'\n ? x.posSide === 'long'\n ? 'OPEN_LONG'\n : 'CLOSE_SHORT'\n : x.posSide === 'short'\n ? 'OPEN_SHORT'\n : 'CLOSE_LONG';\n return {\n order_id: x.ordId,\n account_id,\n product_id: encodePath(x.instType, x.instId),\n submit_at: +x.cTime,\n filled_at: +x.fillTime,\n order_type,\n order_direction,\n volume: +x.sz,\n traded_volume: +x.accFillSz,\n price: +x.px,\n traded_price: +x.avgPx,\n };\n });\n },\n { auto_refresh_interval: 5000 },\n );\n}).subscribe();\n\nexport const tradingAccountId$ = accountUid$.pipe(\n map((uid) => `okx/${uid}/trading`),\n shareReplay(1),\n);\n\ndefer(async () => {\n const tradingAccountId = await firstValueFrom(tradingAccountId$);\n addAccountMarket(terminal, { account_id: tradingAccountId, market_id: 'OKX' });\n\n provideAccountInfoService(terminal, tradingAccountId, () => getTradingAccountInfo(credential), {\n auto_refresh_interval: 1000,\n });\n}).subscribe();\n\ndefer(async () => {\n const uid = await firstValueFrom(accountUid$);\n\n const fundingAccountId = `okx/${uid}/funding/USDT`;\n\n provideAccountInfoService(terminal, fundingAccountId, () => getFundingAccountInfo(credential), {\n auto_refresh_interval: 1000,\n });\n}).subscribe();\n\ndefer(async () => {\n const uid = await firstValueFrom(accountUid$);\n const earningAccountId = `okx/${uid}/earning/USDT`;\n provideAccountInfoService(terminal, earningAccountId, () => getEarningAccountInfo(credential), {\n auto_refresh_interval: 5000,\n });\n}).subscribe();\n\n// 导出 marketIndexTickerUSDT$ 供其他模块使用\nexport { marketIndexTickerUSDT$ };\n"]}
@@ -0,0 +1,15 @@
1
+ import { getFinanceSavingsBalance } from '../api';
2
+ export const getEarningAccountInfo = async (credential) => {
3
+ const offers = await getFinanceSavingsBalance(credential, {});
4
+ const equity = offers.data.filter((x) => x.ccy === 'USDT').reduce((acc, x) => acc + +x.amt, 0);
5
+ const free = equity;
6
+ return {
7
+ money: {
8
+ currency: 'USDT',
9
+ equity,
10
+ free,
11
+ },
12
+ positions: [],
13
+ };
14
+ };
15
+ //# sourceMappingURL=earning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"earning.js","sourceRoot":"","sources":["../../src/accountInfos/earning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAG/D,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAA6B,EAAE;IAChG,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC/F,MAAM,IAAI,GAAG,MAAM,CAAC;IAEpB,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS,EAAE,EAAE;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { ICredential, getFinanceSavingsBalance } from '../api';\nimport { IAccountInfoCore } from './types';\n\nexport const getEarningAccountInfo = async (credential: ICredential): Promise<IAccountInfoCore> => {\n const offers = await getFinanceSavingsBalance(credential, {});\n const equity = offers.data.filter((x) => x.ccy === 'USDT').reduce((acc, x) => acc + +x.amt, 0);\n const free = equity;\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions: [],\n };\n};\n"]}
@@ -0,0 +1,46 @@
1
+ import { encodePath } from '@yuants/utils';
2
+ import { firstValueFrom } from 'rxjs';
3
+ import { getAssetBalances } from '../api';
4
+ import { marketIndexTickerUSDT$ } from './trading';
5
+ export const getFundingAccountInfo = async (credential) => {
6
+ const [assetBalances, marketIndexTickerUSDT] = await Promise.all([
7
+ getAssetBalances(credential, {}),
8
+ firstValueFrom(marketIndexTickerUSDT$),
9
+ ]);
10
+ const positions = [];
11
+ let equity = 0;
12
+ let free = 0;
13
+ assetBalances.data.forEach((x) => {
14
+ if (x.ccy === 'USDT') {
15
+ const balance = +x.bal;
16
+ equity += balance;
17
+ free += balance;
18
+ return;
19
+ }
20
+ const price = marketIndexTickerUSDT.get(`${x.ccy}-USDT`) || 0;
21
+ const valuation = price * +x.bal || 0;
22
+ const productId = encodePath('SPOT', `${x.ccy}-USDT`);
23
+ positions.push({
24
+ datasource_id: 'OKX',
25
+ position_id: productId,
26
+ product_id: productId,
27
+ direction: 'LONG',
28
+ volume: +x.bal,
29
+ free_volume: +x.bal,
30
+ position_price: price,
31
+ floating_profit: 0,
32
+ closable_price: price,
33
+ valuation,
34
+ });
35
+ equity += valuation;
36
+ });
37
+ return {
38
+ money: {
39
+ currency: 'USDT',
40
+ equity,
41
+ free,
42
+ },
43
+ positions,
44
+ };
45
+ };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a,EAAE,KAAK;YACpB,WAAW,EAAE,SAAS;YACtB,UAAU,EAAE,SAAS;YACrB,SAAS,EAAE,MAAM;YACjB,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG;YACd,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG;YACnB,cAAc,EAAE,KAAK;YACrB,eAAe,EAAE,CAAC;YAClB,cAAc,EAAE,KAAK;YACrB,SAAS;SACV,CAAC,CAAC;QAEH,MAAM,IAAI,SAAS,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS;KACV,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { firstValueFrom } from 'rxjs';\nimport { ICredential, getAssetBalances } from '../api';\nimport { marketIndexTickerUSDT$ } from './trading';\nimport { IAccountInfoCore } from './types';\n\nexport const getFundingAccountInfo = async (credential: ICredential): Promise<IAccountInfoCore> => {\n const [assetBalances, marketIndexTickerUSDT] = await Promise.all([\n getAssetBalances(credential, {}),\n firstValueFrom(marketIndexTickerUSDT$),\n ]);\n\n const positions: IPosition[] = [];\n let equity = 0;\n let free = 0;\n\n assetBalances.data.forEach((x) => {\n if (x.ccy === 'USDT') {\n const balance = +x.bal;\n equity += balance;\n free += balance;\n return;\n }\n\n const price = marketIndexTickerUSDT.get(`${x.ccy}-USDT`) || 0;\n const valuation = price * +x.bal || 0;\n const productId = encodePath('SPOT', `${x.ccy}-USDT`);\n\n positions.push({\n datasource_id: 'OKX',\n position_id: productId,\n product_id: productId,\n direction: 'LONG',\n volume: +x.bal,\n free_volume: +x.bal,\n position_price: price,\n floating_profit: 0,\n closable_price: price,\n valuation,\n });\n\n equity += valuation;\n });\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n};\n"]}
@@ -0,0 +1,7 @@
1
+ export { getTradingAccountInfo } from './trading';
2
+ export { getFundingAccountInfo } from './funding';
3
+ export { getLoanAccountInfo } from './loan';
4
+ export { getEarningAccountInfo } from './earning';
5
+ export { getStrategyAccountInfo } from './strategy';
6
+ export { marketIndexTickerUSDT$ } from './trading';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/accountInfos/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { getTradingAccountInfo } from './trading';\nexport { getFundingAccountInfo } from './funding';\nexport { getLoanAccountInfo } from './loan';\nexport { getEarningAccountInfo } from './earning';\nexport { getStrategyAccountInfo } from './strategy';\nexport { marketIndexTickerUSDT$ } from './trading';\nexport { IAccountInfoCore } from './types';\n"]}
@@ -0,0 +1,46 @@
1
+ import { encodePath } from '@yuants/utils';
2
+ import { getFlexibleLoanInfo } from '../api';
3
+ export const getLoanAccountInfo = async (credential) => {
4
+ const res = await getFlexibleLoanInfo(credential);
5
+ const data = res.data[0];
6
+ const positions = [];
7
+ for (const loan of data.loanData) {
8
+ positions.push({
9
+ datasource_id: 'OKX',
10
+ product_id: `SPOT/${loan.ccy}-USDT`,
11
+ volume: +loan.amt,
12
+ free_volume: +loan.amt,
13
+ position_id: encodePath('loan', loan.ccy),
14
+ direction: 'SHORT',
15
+ position_price: 0,
16
+ closable_price: 0,
17
+ floating_profit: 0,
18
+ valuation: 0,
19
+ });
20
+ }
21
+ for (const collateral of data.collateralData) {
22
+ positions.push({
23
+ datasource_id: 'OKX',
24
+ product_id: `SPOT/${collateral.ccy}-USDT`,
25
+ volume: +collateral.amt,
26
+ free_volume: +collateral.amt,
27
+ position_id: encodePath('collateral', collateral.ccy),
28
+ direction: 'LONG',
29
+ position_price: 0,
30
+ closable_price: 0,
31
+ floating_profit: 0,
32
+ valuation: 0,
33
+ });
34
+ }
35
+ const equity = +data.collateralNotionalUsd - +data.loanNotionalUsd;
36
+ const free = equity - +data.collateralNotionalUsd;
37
+ return {
38
+ money: {
39
+ currency: 'USDT',
40
+ equity,
41
+ free,
42
+ },
43
+ positions,
44
+ };
45
+ };
46
+ //# sourceMappingURL=loan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loan.js","sourceRoot":"","sources":["../../src/accountInfos/loan.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAe,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAG1D,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAA6B,EAAE;IAC7F,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEzB,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;QAChC,SAAS,CAAC,IAAI,CAAC;YACb,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ,IAAI,CAAC,GAAG,OAAO;YACnC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG;YACjB,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG;YACtB,WAAW,EAAE,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC;YACzC,SAAS,EAAE,OAAO;YAClB,cAAc,EAAE,CAAC;YACjB,cAAc,EAAE,CAAC;YACjB,eAAe,EAAE,CAAC;YAClB,SAAS,EAAE,CAAC;SACb,CAAC,CAAC;KACJ;IACD,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,cAAc,EAAE;QAC5C,SAAS,CAAC,IAAI,CAAC;YACb,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,QAAQ,UAAU,CAAC,GAAG,OAAO;YACzC,MAAM,EAAE,CAAC,UAAU,CAAC,GAAG;YACvB,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG;YAC5B,WAAW,EAAE,UAAU,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC;YACrD,SAAS,EAAE,MAAM;YACjB,cAAc,EAAE,CAAC;YACjB,cAAc,EAAE,CAAC;YACjB,eAAe,EAAE,CAAC;YAClB,SAAS,EAAE,CAAC;SACb,CAAC,CAAC;KACJ;IACD,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,qBAAqB,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC;IACnE,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,qBAAqB,CAAC;IAElD,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS;KACV,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getFlexibleLoanInfo } from '../api';\nimport { IAccountInfoCore } from './types';\n\nexport const getLoanAccountInfo = async (credential: ICredential): Promise<IAccountInfoCore> => {\n const res = await getFlexibleLoanInfo(credential);\n const data = res.data[0];\n\n const positions: IPosition[] = [];\n for (const loan of data.loanData) {\n positions.push({\n datasource_id: 'OKX',\n product_id: `SPOT/${loan.ccy}-USDT`,\n volume: +loan.amt,\n free_volume: +loan.amt,\n position_id: encodePath('loan', loan.ccy),\n direction: 'SHORT',\n position_price: 0,\n closable_price: 0,\n floating_profit: 0,\n valuation: 0,\n });\n }\n for (const collateral of data.collateralData) {\n positions.push({\n datasource_id: 'OKX',\n product_id: `SPOT/${collateral.ccy}-USDT`,\n volume: +collateral.amt,\n free_volume: +collateral.amt,\n position_id: encodePath('collateral', collateral.ccy),\n direction: 'LONG',\n position_price: 0,\n closable_price: 0,\n floating_profit: 0,\n valuation: 0,\n });\n }\n const equity = +data.collateralNotionalUsd - +data.loanNotionalUsd;\n const free = equity - +data.collateralNotionalUsd;\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n};\n"]}
@@ -0,0 +1,56 @@
1
+ import { encodePath } from '@yuants/utils';
2
+ import { getGridOrdersAlgoPending, getGridPositions } from '../api';
3
+ export const getStrategyAccountInfo = async (credential) => {
4
+ // TODO: 需要分页获取所有的网格订单 (每页 100 条)
5
+ const [gridAlgoOrders] = await Promise.all([
6
+ getGridOrdersAlgoPending(credential, {
7
+ algoOrdType: 'contract_grid',
8
+ }),
9
+ ]);
10
+ let totalEquity = 0;
11
+ const positions = [];
12
+ const gridPositionsRes = await Promise.all(gridAlgoOrders.data.map((item) => getGridPositions(credential, { algoOrdType: 'contract_grid', algoId: item.algoId })));
13
+ gridPositionsRes.forEach((gridPositions, index) => {
14
+ var _a, _b, _c, _d;
15
+ let positionValuation = 0;
16
+ const leverage = +((_a = gridAlgoOrders.data) === null || _a === void 0 ? void 0 : _a[index].actualLever);
17
+ (_b = gridPositions === null || gridPositions === void 0 ? void 0 : gridPositions.data) === null || _b === void 0 ? void 0 : _b.forEach((position) => {
18
+ var _a, _b, _c;
19
+ if (+position.pos !== 0) {
20
+ const directionRaw = (_c = (_b = (_a = gridAlgoOrders.data) === null || _a === void 0 ? void 0 : _a[index]) === null || _b === void 0 ? void 0 : _b.direction) !== null && _c !== void 0 ? _c : '';
21
+ const direction = directionRaw ? directionRaw.toUpperCase() : 'LONG';
22
+ positions.push({
23
+ position_id: encodePath(position.algoId, position.instId),
24
+ datasource_id: 'OKX',
25
+ product_id: encodePath(position.instType, position.instId),
26
+ direction,
27
+ volume: Math.abs(+position.pos),
28
+ free_volume: +position.pos,
29
+ position_price: +position.avgPx,
30
+ floating_profit: +position.upl,
31
+ closable_price: +position.last,
32
+ valuation: +position.notionalUsd,
33
+ });
34
+ positionValuation += +position.notionalUsd;
35
+ }
36
+ });
37
+ if (leverage === 0) {
38
+ // 实际杠杆为 0,说明没有持仓,直接把投资金额和累计盈亏算到净值里
39
+ totalEquity += +((_c = gridAlgoOrders.data) === null || _c === void 0 ? void 0 : _c[index].investment) + +((_d = gridAlgoOrders.data) === null || _d === void 0 ? void 0 : _d[index].totalPnl);
40
+ }
41
+ else {
42
+ // 历史提取金额不会从 investment, totalPnl 扣减
43
+ // 计算净值需要通过仓位的名义价值和实际杠杆计算
44
+ totalEquity += positionValuation / leverage;
45
+ }
46
+ });
47
+ return {
48
+ money: {
49
+ currency: 'USDT',
50
+ equity: totalEquity,
51
+ free: 0, // TODO: 累计策略的可提取资金作为 free
52
+ },
53
+ positions,
54
+ };
55
+ };
56
+ //# sourceMappingURL=strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/accountInfos/strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAe,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAGjF,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,UAAuB,EAA6B,EAAE;IACjG,iCAAiC;IACjC,MAAM,CAAC,cAAc,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACzC,wBAAwB,CAAC,UAAU,EAAE;YACnC,WAAW,EAAE,eAAe;SAC7B,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,MAAM,SAAS,GAAgB,EAAE,CAAC;IAElC,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,GAAG,CACxC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI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AC,QAAQ,CAAC,WAAW;iBACjC,CAAC,CAAC;gBACH,iBAAiB,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;aAC5C;QACH,CAAC,CAAC,CAAC;QACH,IAAI,QAAQ,KAAK,CAAC,EAAE;YAClB,mCAAmC;YACnC,WAAW,IAAI,CAAC,CAAA,MAAA,cAAc,CAAC,IAAI,0CAAG,KAAK,EAAE,UAAU,CAAA,GAAG,CAAC,CAAA,MAAA,cAAc,CAAC,IAAI,0CAAG,KAAK,EAAE,QAAQ,CAAA,CAAC;SAClG;aAAM;YACL,oCAAoC;YACpC,yBAAyB;YACzB,WAAW,IAAI,iBAAiB,GAAG,QAAQ,CAAC;SAC7C;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,WAAW;YACnB,IAAI,EAAE,CAAC,EAAE,0BAA0B;SACpC;QACD,SAAS;KACV,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getGridOrdersAlgoPending, getGridPositions } from '../api';\nimport { IAccountInfoCore } from './types';\n\nexport const getStrategyAccountInfo = async (credential: ICredential): Promise<IAccountInfoCore> => {\n // TODO: 需要分页获取所有的网格订单 (每页 100 条)\n const [gridAlgoOrders] = await Promise.all([\n getGridOrdersAlgoPending(credential, {\n algoOrdType: 'contract_grid',\n }),\n ]);\n\n let totalEquity = 0;\n const positions: IPosition[] = [];\n\n const gridPositionsRes = await Promise.all(\n gridAlgoOrders.data.map((item) =>\n getGridPositions(credential, { algoOrdType: 'contract_grid', algoId: item.algoId }),\n ),\n );\n\n gridPositionsRes.forEach((gridPositions, index) => {\n let positionValuation = 0;\n const leverage = +gridAlgoOrders.data?.[index].actualLever;\n gridPositions?.data?.forEach((position) => {\n if (+position.pos !== 0) {\n const directionRaw = gridAlgoOrders.data?.[index]?.direction ?? '';\n const direction = directionRaw ? directionRaw.toUpperCase() : 'LONG';\n positions.push({\n position_id: encodePath(position.algoId, position.instId),\n datasource_id: 'OKX',\n product_id: encodePath(position.instType, position.instId),\n direction,\n volume: Math.abs(+position.pos),\n free_volume: +position.pos,\n position_price: +position.avgPx,\n floating_profit: +position.upl,\n closable_price: +position.last,\n valuation: +position.notionalUsd,\n });\n positionValuation += +position.notionalUsd;\n }\n });\n if (leverage === 0) {\n // 实际杠杆为 0,说明没有持仓,直接把投资金额和累计盈亏算到净值里\n totalEquity += +gridAlgoOrders.data?.[index].investment + +gridAlgoOrders.data?.[index].totalPnl;\n } else {\n // 历史提取金额不会从 investment, totalPnl 扣减\n // 计算净值需要通过仓位的名义价值和实际杠杆计算\n totalEquity += positionValuation / leverage;\n }\n });\n\n return {\n money: {\n currency: 'USDT',\n equity: totalEquity,\n free: 0, // TODO: 累计策略的可提取资金作为 free\n },\n positions,\n };\n};\n"]}
@@ -0,0 +1,84 @@
1
+ import { encodePath } from '@yuants/utils';
2
+ import { defer, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';
3
+ import { getAccountBalance, getAccountPositions } from '../api';
4
+ import { productService } from '../product';
5
+ import { getMarketIndexTicker } from '../public-api';
6
+ export const marketIndexTickerUSDT$ = defer(() => getMarketIndexTicker({ quoteCcy: 'USDT' })).pipe(map((x) => {
7
+ const mapInstIdToPrice = new Map();
8
+ x.data.forEach((inst) => mapInstIdToPrice.set(inst.instId, Number(inst.idxPx)));
9
+ return mapInstIdToPrice;
10
+ }), repeat({ delay: 1000 }), retry({ delay: 5000 }), shareReplay(1));
11
+ export const getTradingAccountInfo = async (credential) => {
12
+ var _a;
13
+ const [positionsApi, balanceApi, mapProductIdToProduct, marketIndexTickerUSDT] = await Promise.all([
14
+ getAccountPositions(credential, {}),
15
+ getAccountBalance(credential, {}),
16
+ firstValueFrom(productService.mapProductIdToProduct$),
17
+ firstValueFrom(marketIndexTickerUSDT$),
18
+ ]);
19
+ let totalEquity = 0;
20
+ let totalFree = 0;
21
+ const positions = [];
22
+ (_a = balanceApi.data[0]) === null || _a === void 0 ? void 0 : _a.details.forEach((detail) => {
23
+ var _a, _b, _c, _d, _e, _f;
24
+ if (detail.ccy === 'USDT') {
25
+ const balance = +((_a = detail.cashBal) !== null && _a !== void 0 ? _a : 0);
26
+ const free = Math.min(balance, // free should no more than balance if there is much profits
27
+ +((_b = detail.availEq) !== null && _b !== void 0 ? _b : 0));
28
+ const equity = +((_c = detail.eq) !== null && _c !== void 0 ? _c : 0) - +((_d = detail.stgyEq) !== null && _d !== void 0 ? _d : 0);
29
+ totalEquity += equity;
30
+ totalFree += free;
31
+ }
32
+ else {
33
+ const volume = +((_e = detail.cashBal) !== null && _e !== void 0 ? _e : 0);
34
+ const free_volume = Math.min(volume, // free should no more than balance if there is much profits
35
+ +((_f = detail.availEq) !== null && _f !== void 0 ? _f : 0));
36
+ const closable_price = marketIndexTickerUSDT.get(detail.ccy + '-USDT') || 0;
37
+ const delta_equity = volume * closable_price || 0;
38
+ const delta_profit = +detail.totalPnl || 0;
39
+ const product_id = encodePath('SPOT', `${detail.ccy}-USDT`);
40
+ positions.push({
41
+ position_id: product_id,
42
+ datasource_id: 'OKX',
43
+ product_id: product_id,
44
+ direction: 'LONG',
45
+ volume: volume,
46
+ free_volume: free_volume,
47
+ position_price: +detail.accAvgPx,
48
+ floating_profit: delta_profit,
49
+ closable_price: closable_price,
50
+ valuation: delta_equity,
51
+ });
52
+ totalEquity += delta_equity;
53
+ }
54
+ });
55
+ positionsApi.data.forEach((x) => {
56
+ var _a, _b;
57
+ const direction = x.posSide === 'long' ? 'LONG' : x.posSide === 'short' ? 'SHORT' : +x.pos > 0 ? 'LONG' : 'SHORT';
58
+ const volume = Math.abs(+x.pos);
59
+ const product_id = encodePath(x.instType, x.instId);
60
+ const closable_price = +x.last;
61
+ const valuation = ((_b = (_a = mapProductIdToProduct.get(product_id)) === null || _a === void 0 ? void 0 : _a.value_scale) !== null && _b !== void 0 ? _b : 1) * volume * closable_price || 0;
62
+ positions.push({
63
+ position_id: x.posId,
64
+ datasource_id: 'OKX',
65
+ product_id,
66
+ direction,
67
+ volume: volume,
68
+ free_volume: +x.availPos,
69
+ closable_price,
70
+ position_price: +x.avgPx,
71
+ floating_profit: +x.upl,
72
+ valuation,
73
+ });
74
+ });
75
+ return {
76
+ money: {
77
+ currency: 'USDT',
78
+ equity: totalEquity,
79
+ free: totalFree,
80
+ },
81
+ positions: positions,
82
+ };
83
+ };
84
+ //# sourceMappingURL=trading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trading.js","sourceRoot":"","sources":["../../src/accountInfos/trading.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC9E,OAAO,EAAe,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAChG,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;IACR,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnD,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrF,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC,EACF,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,E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,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;QACpD,MAAM,cAAc,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/B,MAAM,SAAS,GACb,CAAC,MAAA,MAAA,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAC,0CAAE,WAAW,mCAAI,CAAC,CAAC,GAAG,MAAM,GAAG,cAAc,IAAI,CAAC,CAAC;QAE3F,SAAS,CAAC,IAAI,CAAC;YACb,WAAW,EAAE,CAAC,CAAC,KAAK;YACpB,aAAa,EAAE,KAAK;YACpB,UAAU;YACV,SAAS;YACT,MAAM,EAAE,MAAM;YACd,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ;YACxB,cAAc;YACd,cAAc,EAAE,CAAC,CAAC,CAAC,KAAK;YACxB,eAAe,EAAE,CAAC,CAAC,CAAC,GAAG;YACvB,SAAS;SACV,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,WAAW;YACnB,IAAI,EAAE,SAAS;SAChB;QACD,SAAS,EAAE,SAAS;KACrB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { IAccountMoney, IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { defer, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';\nimport { ICredential, getAccountBalance, getAccountPositions } from '../api';\nimport { productService } from '../product';\nimport { getMarketIndexTicker } from '../public-api';\nimport { IAccountInfoCore } from './types';\n\nexport const marketIndexTickerUSDT$ = defer(() => getMarketIndexTicker({ quoteCcy: 'USDT' })).pipe(\n map((x) => {\n const mapInstIdToPrice = new Map<string, number>();\n x.data.forEach((inst: any) => mapInstIdToPrice.set(inst.instId, Number(inst.idxPx)));\n return mapInstIdToPrice;\n }),\n repeat({ delay: 1000 }),\n retry({ delay: 5000 }),\n shareReplay(1),\n);\n\nexport const getTradingAccountInfo = async (credential: ICredential): Promise<IAccountInfoCore> => {\n const [positionsApi, balanceApi, mapProductIdToProduct, marketIndexTickerUSDT] = await Promise.all([\n getAccountPositions(credential, {}),\n getAccountBalance(credential, {}),\n firstValueFrom(productService.mapProductIdToProduct$),\n firstValueFrom(marketIndexTickerUSDT$),\n ]);\n\n let totalEquity = 0;\n let totalFree = 0;\n const positions: IPosition[] = [];\n\n balanceApi.data[0]?.details.forEach((detail) => {\n if (detail.ccy === 'USDT') {\n const balance = +(detail.cashBal ?? 0);\n const free = Math.min(\n balance, // free should no more than balance if there is much profits\n +(detail.availEq ?? 0),\n );\n const equity = +(detail.eq ?? 0) - +(detail.stgyEq ?? 0);\n totalEquity += equity;\n totalFree += free;\n } else {\n const volume = +(detail.cashBal ?? 0);\n const free_volume = Math.min(\n volume, // free should no more than balance if there is much profits\n +(detail.availEq ?? 0),\n );\n const closable_price = marketIndexTickerUSDT.get(detail.ccy + '-USDT') || 0;\n const delta_equity = volume * closable_price || 0;\n const delta_profit = +detail.totalPnl || 0;\n\n const product_id = encodePath('SPOT', `${detail.ccy}-USDT`);\n positions.push({\n position_id: product_id,\n datasource_id: 'OKX',\n product_id: product_id,\n direction: 'LONG',\n volume: volume,\n free_volume: free_volume,\n position_price: +detail.accAvgPx,\n floating_profit: delta_profit,\n closable_price: closable_price,\n valuation: delta_equity,\n });\n\n totalEquity += delta_equity;\n }\n });\n positionsApi.data.forEach((x) => {\n const direction =\n x.posSide === 'long' ? 'LONG' : x.posSide === 'short' ? 'SHORT' : +x.pos > 0 ? 'LONG' : 'SHORT';\n const volume = Math.abs(+x.pos);\n const product_id = encodePath(x.instType, x.instId);\n const closable_price = +x.last;\n const valuation =\n (mapProductIdToProduct.get(product_id)?.value_scale ?? 1) * volume * closable_price || 0;\n\n positions.push({\n position_id: x.posId,\n datasource_id: 'OKX',\n product_id,\n direction,\n volume: volume,\n free_volume: +x.availPos,\n closable_price,\n position_price: +x.avgPx,\n floating_profit: +x.upl,\n valuation,\n });\n });\n return {\n money: {\n currency: 'USDT',\n equity: totalEquity,\n free: totalFree,\n },\n positions: positions,\n };\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/accountInfos/types.ts"],"names":[],"mappings":"","sourcesContent":["import { IAccountMoney, IPosition } from '@yuants/data-account';\n\nexport interface IAccountInfoCore {\n money: Pick<IAccountMoney, 'currency' | 'equity' | 'free'>;\n positions: IPosition[];\n}\n"]}