@yuants/vendor-okx 0.27.3 → 0.27.5

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 (50) hide show
  1. package/dist/account-actions-with-credential.js +6 -6
  2. package/dist/account-actions-with-credential.js.map +1 -1
  3. package/dist/account.js +4 -4
  4. package/dist/account.js.map +1 -1
  5. package/dist/accountInfos/earning.js +12 -10
  6. package/dist/accountInfos/earning.js.map +1 -1
  7. package/dist/accountInfos/funding.js +11 -41
  8. package/dist/accountInfos/funding.js.map +1 -1
  9. package/dist/accountInfos/loan.js +16 -23
  10. package/dist/accountInfos/loan.js.map +1 -1
  11. package/dist/accountInfos/strategy.js +1 -8
  12. package/dist/accountInfos/strategy.js.map +1 -1
  13. package/dist/accountInfos/trading.js +26 -26
  14. package/dist/accountInfos/trading.js.map +1 -1
  15. package/dist/accountInfos/uid.js +2 -0
  16. package/dist/accountInfos/uid.js.map +1 -1
  17. package/dist/strategy-account.js +2 -2
  18. package/dist/strategy-account.js.map +1 -1
  19. package/lib/account-actions-with-credential.js +6 -6
  20. package/lib/account-actions-with-credential.js.map +1 -1
  21. package/lib/account.d.ts.map +1 -1
  22. package/lib/account.js +4 -4
  23. package/lib/account.js.map +1 -1
  24. package/lib/accountInfos/earning.d.ts +2 -2
  25. package/lib/accountInfos/earning.d.ts.map +1 -1
  26. package/lib/accountInfos/earning.js +12 -10
  27. package/lib/accountInfos/earning.js.map +1 -1
  28. package/lib/accountInfos/funding.d.ts +2 -2
  29. package/lib/accountInfos/funding.d.ts.map +1 -1
  30. package/lib/accountInfos/funding.js +10 -40
  31. package/lib/accountInfos/funding.js.map +1 -1
  32. package/lib/accountInfos/loan.d.ts +2 -2
  33. package/lib/accountInfos/loan.d.ts.map +1 -1
  34. package/lib/accountInfos/loan.js +16 -23
  35. package/lib/accountInfos/loan.js.map +1 -1
  36. package/lib/accountInfos/strategy.d.ts +2 -2
  37. package/lib/accountInfos/strategy.d.ts.map +1 -1
  38. package/lib/accountInfos/strategy.js +1 -8
  39. package/lib/accountInfos/strategy.js.map +1 -1
  40. package/lib/accountInfos/trading.d.ts +3 -2
  41. package/lib/accountInfos/trading.d.ts.map +1 -1
  42. package/lib/accountInfos/trading.js +28 -27
  43. package/lib/accountInfos/trading.js.map +1 -1
  44. package/lib/accountInfos/uid.d.ts.map +1 -1
  45. package/lib/accountInfos/uid.js +2 -0
  46. package/lib/accountInfos/uid.js.map +1 -1
  47. package/lib/strategy-account.js +2 -2
  48. package/lib/strategy-account.js.map +1 -1
  49. package/package.json +2 -2
  50. package/temp/package-deps.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAqDxB,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAyExB,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
package/lib/account.js CHANGED
@@ -21,25 +21,25 @@ const credential = (0, private_api_1.getDefaultCredential)();
21
21
  (0, rxjs_1.defer)(async () => {
22
22
  const tradingAccountId = await (0, uid_1.getTradingAccountId)(credential);
23
23
  (0, data_account_1.addAccountMarket)(terminal, { account_id: tradingAccountId, market_id: 'OKX' });
24
- (0, data_account_1.provideAccountInfoService)(terminal, tradingAccountId, () => (0, accountInfos_1.getTradingAccountInfo)(credential), {
24
+ (0, data_account_1.provideAccountInfoService)(terminal, tradingAccountId, () => (0, accountInfos_1.getTradingAccountInfo)(credential, tradingAccountId), {
25
25
  auto_refresh_interval: 1000,
26
26
  });
27
27
  }).subscribe();
28
28
  (0, rxjs_1.defer)(async () => {
29
29
  const fundingAccountId = await (0, uid_1.getFundingAccountId)(credential);
30
- (0, data_account_1.provideAccountInfoService)(terminal, fundingAccountId, () => (0, accountInfos_1.getFundingAccountInfo)(credential), {
30
+ (0, data_account_1.provideAccountInfoService)(terminal, fundingAccountId, () => (0, accountInfos_1.getFundingAccountInfo)(credential, fundingAccountId), {
31
31
  auto_refresh_interval: 1000,
32
32
  });
33
33
  }).subscribe();
34
34
  (0, rxjs_1.defer)(async () => {
35
35
  const earningAccountId = await (0, uid_1.getEarningAccountId)(credential);
36
- (0, data_account_1.provideAccountInfoService)(terminal, earningAccountId, () => (0, accountInfos_1.getEarningAccountInfo)(credential), {
36
+ (0, data_account_1.provideAccountInfoService)(terminal, earningAccountId, () => (0, accountInfos_1.getEarningAccountInfo)(credential, earningAccountId), {
37
37
  auto_refresh_interval: 5000,
38
38
  });
39
39
  }).subscribe();
40
40
  (0, rxjs_1.defer)(async () => {
41
41
  const loanAccountId = await (0, uid_1.getLoanAccountId)(credential);
42
- (0, data_account_1.provideAccountInfoService)(protocol_1.Terminal.fromNodeEnv(), loanAccountId, () => (0, accountInfos_1.getLoanAccountInfo)(credential), {
42
+ (0, data_account_1.provideAccountInfoService)(protocol_1.Terminal.fromNodeEnv(), loanAccountId, () => (0, accountInfos_1.getLoanAccountInfo)(credential, loanAccountId), {
43
43
  auto_refresh_interval: 1000,
44
44
  });
45
45
  }).subscribe();
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;AAAA,uDAAmF;AACnF,mDAAiE;AACjE,+CAA4C;AAC5C,+BAA6B;AAC7B,iDAMwB;AAqDf,uGAtDP,qCAAsB,OAsDO;AApD/B,4CAK4B;AAC5B,mDAAyD;AACzD,oDAAiD;AAEjD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,UAAU,GAAG,MAAM,IAAA,yBAAmB,EAAC,UAA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L,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,aAAa,GAAG,MAAM,IAAA,sBAAgB,EAAC,UAAU,CAAC,CAAC;IACzD,IAAA,wCAAyB,EAAC,mBAAQ,CAAC,WAAW,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,IAAA,iCAAkB,EAAC,UAAU,CAAC,EAAE;QACrG,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';\nimport { providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport {\n getEarningAccountInfo,\n getFundingAccountInfo,\n getLoanAccountInfo,\n getTradingAccountInfo,\n marketIndexTickerUSDT$,\n} from './accountInfos';\nimport {\n getEarningAccountId,\n getFundingAccountId,\n getLoanAccountId,\n getTradingAccountId,\n} from './accountInfos/uid';\nimport { getDefaultCredential } from './api/private-api';\nimport { listOrders } from './orders/listOrders';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const account_id = await getTradingAccountId(credential);\n providePendingOrdersService(terminal, account_id, async () => listOrders(credential, account_id), {\n auto_refresh_interval: 5000,\n });\n}).subscribe();\n\ndefer(async () => {\n const tradingAccountId = await getTradingAccountId(credential);\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 fundingAccountId = await getFundingAccountId(credential);\n\n provideAccountInfoService(terminal, fundingAccountId, () => getFundingAccountInfo(credential), {\n auto_refresh_interval: 1000,\n });\n}).subscribe();\n\ndefer(async () => {\n const earningAccountId = await getEarningAccountId(credential);\n provideAccountInfoService(terminal, earningAccountId, () => getEarningAccountInfo(credential), {\n auto_refresh_interval: 5000,\n });\n}).subscribe();\n\ndefer(async () => {\n const loanAccountId = await getLoanAccountId(credential);\n provideAccountInfoService(Terminal.fromNodeEnv(), loanAccountId, () => getLoanAccountInfo(credential), {\n auto_refresh_interval: 1000,\n });\n}).subscribe();\n\n// 导出 marketIndexTickerUSDT$ 供其他模块使用\nexport { marketIndexTickerUSDT$ };\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;AAAA,uDAAmF;AACnF,mDAAiE;AACjE,+CAA4C;AAC5C,+BAA6B;AAC7B,iDAMwB;AAyEf,uGA1EP,qCAAsB,OA0EO;AAxE/B,4CAK4B;AAC5B,mDAAyD;AACzD,oDAAiD;AAEjD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,IAAA,kCAAoB,GAAE,CAAC;AAE1C,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,UAAU,GAAG,MAAM,IAAA,yBAAmB,EAAC,UAAU,CAAC,CAAC;IACzD,IAAA,wCAA2B,EAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,IAAA,uBAAU,EAAC,UAAU,EAAE,UAAU,CAAC,EAAE;QAChG,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,IAAA,yBAAmB,EAAC,UAAU,CAAC,CAAC;IAC/D,IAAA,+BAAgB,EAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAE/E,IAAA,wCAAyB,EACvB,QAAQ,EACR,gBAAgB,EAChB,GAAG,EAAE,CAAC,IAAA,oCAAqB,EAAC,UAAU,EAAE,gBAAgB,CAAC,EACzD;QACE,qBAAqB,EAAE,IAAI;KAC5B,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,IAAA,yBAAmB,EAAC,UAAU,CAAC,CAAC;IAE/D,IAAA,wCAAyB,EACvB,QAAQ,EACR,gBAAgB,EAChB,GAAG,EAAE,CAAC,IAAA,oCAAqB,EAAC,UAAU,EAAE,gBAAgB,CAAC,EACzD;QACE,qBAAqB,EAAE,IAAI;KAC5B,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,IAAA,yBAAmB,EAAC,UAAU,CAAC,CAAC;IAC/D,IAAA,wCAAyB,EACvB,QAAQ,EACR,gBAAgB,EAChB,GAAG,EAAE,CAAC,IAAA,oCAAqB,EAAC,UAAU,EAAE,gBAAgB,CAAC,EACzD;QACE,qBAAqB,EAAE,IAAI;KAC5B,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,IAAA,YAAK,EAAC,KAAK,IAAI,EAAE;IACf,MAAM,aAAa,GAAG,MAAM,IAAA,sBAAgB,EAAC,UAAU,CAAC,CAAC;IACzD,IAAA,wCAAyB,EACvB,mBAAQ,CAAC,WAAW,EAAE,EACtB,aAAa,EACb,GAAG,EAAE,CAAC,IAAA,iCAAkB,EAAC,UAAU,EAAE,aAAa,CAAC,EACnD;QACE,qBAAqB,EAAE,IAAI;KAC5B,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';\nimport { providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport {\n getEarningAccountInfo,\n getFundingAccountInfo,\n getLoanAccountInfo,\n getTradingAccountInfo,\n marketIndexTickerUSDT$,\n} from './accountInfos';\nimport {\n getEarningAccountId,\n getFundingAccountId,\n getLoanAccountId,\n getTradingAccountId,\n} from './accountInfos/uid';\nimport { getDefaultCredential } from './api/private-api';\nimport { listOrders } from './orders/listOrders';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const account_id = await getTradingAccountId(credential);\n providePendingOrdersService(terminal, account_id, async () => listOrders(credential, account_id), {\n auto_refresh_interval: 5000,\n });\n}).subscribe();\n\ndefer(async () => {\n const tradingAccountId = await getTradingAccountId(credential);\n addAccountMarket(terminal, { account_id: tradingAccountId, market_id: 'OKX' });\n\n provideAccountInfoService(\n terminal,\n tradingAccountId,\n () => getTradingAccountInfo(credential, tradingAccountId),\n {\n auto_refresh_interval: 1000,\n },\n );\n}).subscribe();\n\ndefer(async () => {\n const fundingAccountId = await getFundingAccountId(credential);\n\n provideAccountInfoService(\n terminal,\n fundingAccountId,\n () => getFundingAccountInfo(credential, fundingAccountId),\n {\n auto_refresh_interval: 1000,\n },\n );\n}).subscribe();\n\ndefer(async () => {\n const earningAccountId = await getEarningAccountId(credential);\n provideAccountInfoService(\n terminal,\n earningAccountId,\n () => getEarningAccountInfo(credential, earningAccountId),\n {\n auto_refresh_interval: 5000,\n },\n );\n}).subscribe();\n\ndefer(async () => {\n const loanAccountId = await getLoanAccountId(credential);\n provideAccountInfoService(\n Terminal.fromNodeEnv(),\n loanAccountId,\n () => getLoanAccountInfo(credential, loanAccountId),\n {\n auto_refresh_interval: 1000,\n },\n );\n}).subscribe();\n\n// 导出 marketIndexTickerUSDT$ 供其他模块使用\nexport { marketIndexTickerUSDT$ };\n"]}
@@ -1,4 +1,4 @@
1
+ import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
1
2
  import { ICredential } from '../api/private-api';
2
- import { IAccountInfoCore } from './types';
3
- export declare const getEarningAccountInfo: (credential: ICredential) => Promise<IAccountInfoCore>;
3
+ export declare const getEarningAccountInfo: IActionHandlerOfGetAccountInfo<ICredential>;
4
4
  //# sourceMappingURL=earning.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"earning.d.ts","sourceRoot":"","sources":["../../src/accountInfos/earning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA4B,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,qBAAqB,eAAsB,WAAW,KAAG,QAAQ,gBAAgB,CAa7F,CAAC"}
1
+ {"version":3,"file":"earning.d.ts","sourceRoot":"","sources":["../../src/accountInfos/earning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAoB,MAAM,sBAAsB,CAAC;AAExF,OAAO,EAAE,WAAW,EAA4B,MAAM,oBAAoB,CAAC;AAG3E,eAAO,MAAM,qBAAqB,EAAE,8BAA8B,CAAC,WAAW,CAa7E,CAAC"}
@@ -1,19 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEarningAccountInfo = void 0;
4
+ const data_account_1 = require("@yuants/data-account");
4
5
  const private_api_1 = require("../api/private-api");
6
+ const trading_1 = require("./trading");
5
7
  const getEarningAccountInfo = async (credential) => {
6
8
  const offers = await (0, private_api_1.getFinanceSavingsBalance)(credential, {});
7
- const equity = offers.data.filter((x) => x.ccy === 'USDT').reduce((acc, x) => acc + +x.amt, 0);
8
- const free = equity;
9
- return {
10
- money: {
11
- currency: 'USDT',
12
- equity,
13
- free,
14
- },
15
- positions: [],
16
- };
9
+ return offers.data.map((offer) => {
10
+ return (0, data_account_1.makeSpotPosition)({
11
+ position_id: `earning/${offer.ccy}`,
12
+ datasource_id: 'OKX',
13
+ product_id: `earning/${offer.ccy}`,
14
+ volume: +offer.amt,
15
+ free_volume: +offer.amt,
16
+ closable_price: (0, trading_1.getSpotPrice)(offer.ccy),
17
+ });
18
+ });
17
19
  };
18
20
  exports.getEarningAccountInfo = getEarningAccountInfo;
19
21
  //# sourceMappingURL=earning.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"earning.js","sourceRoot":"","sources":["../../src/accountInfos/earning.ts"],"names":[],"mappings":";;;AAAA,oDAA2E;AAGpE,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAA6B,EAAE;IAChG,MAAM,MAAM,GAAG,MAAM,IAAA,sCAAwB,EAAC,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;AAbW,QAAA,qBAAqB,yBAahC","sourcesContent":["import { ICredential, getFinanceSavingsBalance } from '../api/private-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"]}
1
+ {"version":3,"file":"earning.js","sourceRoot":"","sources":["../../src/accountInfos/earning.ts"],"names":[],"mappings":";;;AAAA,uDAAwF;AAExF,oDAA2E;AAC3E,uCAAiE;AAE1D,MAAM,qBAAqB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IACrG,MAAM,MAAM,GAAG,MAAM,IAAA,sCAAwB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAE9D,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC/B,OAAO,IAAA,+BAAgB,EAAC;YACtB,WAAW,EAAE,WAAW,KAAK,CAAC,GAAG,EAAE;YACnC,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,WAAW,KAAK,CAAC,GAAG,EAAE;YAClC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG;YAClB,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG;YACvB,cAAc,EAAE,IAAA,sBAAY,EAAC,KAAK,CAAC,GAAG,CAAC;SACxC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAbW,QAAA,qBAAqB,yBAahC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, makeSpotPosition } from '@yuants/data-account';\nimport { firstValueFrom } from 'rxjs';\nimport { ICredential, getFinanceSavingsBalance } from '../api/private-api';\nimport { getSpotPrice, marketIndexTickerUSDT$ } from './trading';\n\nexport const getEarningAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const offers = await getFinanceSavingsBalance(credential, {});\n\n return offers.data.map((offer) => {\n return makeSpotPosition({\n position_id: `earning/${offer.ccy}`,\n datasource_id: 'OKX',\n product_id: `earning/${offer.ccy}`,\n volume: +offer.amt,\n free_volume: +offer.amt,\n closable_price: getSpotPrice(offer.ccy),\n });\n });\n};\n"]}
@@ -1,4 +1,4 @@
1
+ import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
1
2
  import { ICredential } from '../api/private-api';
2
- import { IAccountInfoCore } from './types';
3
- export declare const getFundingAccountInfo: (credential: ICredential) => Promise<IAccountInfoCore>;
3
+ export declare const getFundingAccountInfo: IActionHandlerOfGetAccountInfo<ICredential>;
4
4
  //# sourceMappingURL=funding.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"funding.d.ts","sourceRoot":"","sources":["../../src/accountInfos/funding.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAoB,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,qBAAqB,eAAsB,WAAW,KAAG,QAAQ,gBAAgB,CA8C7F,CAAC"}
1
+ {"version":3,"file":"funding.d.ts","sourceRoot":"","sources":["../../src/accountInfos/funding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAoB,MAAM,sBAAsB,CAAC;AAExF,OAAO,EAAE,WAAW,EAAoB,MAAM,oBAAoB,CAAC;AAGnE,eAAO,MAAM,qBAAqB,EAAE,8BAA8B,CAAC,WAAW,CAa7E,CAAC"}
@@ -1,50 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFundingAccountInfo = void 0;
4
+ const data_account_1 = require("@yuants/data-account");
4
5
  const utils_1 = require("@yuants/utils");
5
- const rxjs_1 = require("rxjs");
6
6
  const private_api_1 = require("../api/private-api");
7
7
  const trading_1 = require("./trading");
8
8
  const getFundingAccountInfo = async (credential) => {
9
- const [assetBalances, marketIndexTickerUSDT] = await Promise.all([
10
- (0, private_api_1.getAssetBalances)(credential, {}),
11
- (0, rxjs_1.firstValueFrom)(trading_1.marketIndexTickerUSDT$),
12
- ]);
13
- const positions = [];
14
- let equity = 0;
15
- let free = 0;
16
- assetBalances.data.forEach((x) => {
17
- if (x.ccy === 'USDT') {
18
- const balance = +x.bal;
19
- equity += balance;
20
- free += balance;
21
- return;
22
- }
23
- const price = marketIndexTickerUSDT.get(`${x.ccy}-USDT`) || 0;
24
- const valuation = price * +x.bal || 0;
25
- const productId = (0, utils_1.encodePath)('SPOT', `${x.ccy}-USDT`);
26
- positions.push({
27
- datasource_id: 'OKX',
28
- position_id: productId,
29
- product_id: productId,
30
- direction: 'LONG',
31
- volume: +x.bal,
32
- free_volume: +x.bal,
33
- position_price: price,
34
- floating_profit: 0,
35
- closable_price: price,
36
- valuation,
37
- });
38
- equity += valuation;
39
- });
40
- return {
41
- money: {
42
- currency: 'USDT',
43
- equity,
44
- free,
45
- },
46
- positions,
47
- };
9
+ const assetBalances = await (0, private_api_1.getAssetBalances)(credential, {});
10
+ return assetBalances.data.map((x) => (0, data_account_1.makeSpotPosition)({
11
+ datasource_id: 'OKX',
12
+ position_id: (0, utils_1.encodePath)('SPOT', `${x.ccy}-USDT`),
13
+ product_id: (0, utils_1.encodePath)('SPOT', `${x.ccy}-USDT`),
14
+ volume: +x.bal,
15
+ free_volume: +x.bal,
16
+ closable_price: (0, trading_1.getSpotPrice)(x.ccy),
17
+ }));
48
18
  };
49
19
  exports.getFundingAccountInfo = getFundingAccountInfo;
50
20
  //# sourceMappingURL=funding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"funding.js","sourceRoot":"","sources":["../../src/accountInfos/funding.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,+BAAsC;AACtC,oDAAmE;AACnE,uCAAmD;AAG5C,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAA6B,EAAE;IAChG,MAAM,CAAC,aAAa,EAAE,qBAAqB,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC/D,IAAA,8BAAgB,EAAC,UAAU,EAAE,EAAE,CAAC;QAChC,IAAA,qBAAc,EAAC,gCAAsB,CAAC;KACvC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,IAAI,GAAG,CAAC,CAAC;IAEb,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC/B,IAAI,CAAC,CAAC,GAAG,KAAK,MAAM,EAAE;YACpB,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YACvB,MAAM,IAAI,OAAO,CAAC;YAClB,IAAI,IAAI,OAAO,CAAC;YAChB,OAAO;SACR;QAED,MAAM,KAAK,GAAG,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9D,MAAM,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACtC,MAAM,SAAS,GAAG,IAAA,kBAAU,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;QAEtD,SAAS,CAAC,IAAI,CAAC;YACb,aAAa,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;AA9CW,QAAA,qBAAqB,yBA8ChC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { firstValueFrom } from 'rxjs';\nimport { ICredential, getAssetBalances } from '../api/private-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"]}
1
+ {"version":3,"file":"funding.js","sourceRoot":"","sources":["../../src/accountInfos/funding.ts"],"names":[],"mappings":";;;AAAA,uDAAwF;AACxF,yCAA2C;AAC3C,oDAAmE;AACnE,uCAAyC;AAElC,MAAM,qBAAqB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IACrG,MAAM,aAAa,GAAG,MAAM,IAAA,8BAAgB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAE7D,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAClC,IAAA,+BAAgB,EAAC;QACf,aAAa,EAAE,KAAK;QACpB,WAAW,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;QAChD,UAAU,EAAE,IAAA,kBAAU,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;QAC/C,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG;QACd,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG;QACnB,cAAc,EAAE,IAAA,sBAAY,EAAC,CAAC,CAAC,GAAG,CAAC;KACpC,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,qBAAqB,yBAahC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getAssetBalances } from '../api/private-api';\nimport { getSpotPrice } from './trading';\n\nexport const getFundingAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const assetBalances = await getAssetBalances(credential, {});\n\n return assetBalances.data.map((x) =>\n makeSpotPosition({\n datasource_id: 'OKX',\n position_id: encodePath('SPOT', `${x.ccy}-USDT`),\n product_id: encodePath('SPOT', `${x.ccy}-USDT`),\n volume: +x.bal,\n free_volume: +x.bal,\n closable_price: getSpotPrice(x.ccy),\n }),\n );\n};\n"]}
@@ -1,4 +1,4 @@
1
+ import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
1
2
  import { ICredential } from '../api/private-api';
2
- import { IAccountInfoCore } from './types';
3
- export declare const getLoanAccountInfo: (credential: ICredential) => Promise<IAccountInfoCore>;
3
+ export declare const getLoanAccountInfo: IActionHandlerOfGetAccountInfo<ICredential>;
4
4
  //# sourceMappingURL=loan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loan.d.ts","sourceRoot":"","sources":["../../src/accountInfos/loan.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAuB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,kBAAkB,eAAsB,WAAW,KAAG,QAAQ,gBAAgB,CA4C1F,CAAC"}
1
+ {"version":3,"file":"loan.d.ts","sourceRoot":"","sources":["../../src/accountInfos/loan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAA+B,MAAM,sBAAsB,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAuB,MAAM,oBAAoB,CAAC;AAGtE,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CAqC1E,CAAC"}
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLoanAccountInfo = void 0;
4
+ const data_account_1 = require("@yuants/data-account");
4
5
  const utils_1 = require("@yuants/utils");
5
6
  const private_api_1 = require("../api/private-api");
7
+ const trading_1 = require("./trading");
6
8
  const getLoanAccountInfo = async (credential) => {
7
9
  const res = await (0, private_api_1.getFlexibleLoanInfo)(credential);
8
10
  const data = res.data[0];
11
+ if (!data)
12
+ return [];
9
13
  const positions = [];
10
- for (const loan of data.loanData) {
14
+ const loanData = data.loanData || [];
15
+ for (const loan of loanData) {
11
16
  positions.push({
12
17
  datasource_id: 'OKX',
13
18
  product_id: `SPOT/${loan.ccy}-USDT`,
@@ -16,35 +21,23 @@ const getLoanAccountInfo = async (credential) => {
16
21
  position_id: (0, utils_1.encodePath)('loan', loan.ccy),
17
22
  direction: 'SHORT',
18
23
  position_price: 0,
19
- closable_price: 0,
20
- floating_profit: 0,
21
- valuation: 0,
24
+ closable_price: (0, trading_1.getSpotPrice)(loan.ccy),
25
+ floating_profit: -(0, trading_1.getSpotPrice)(loan.ccy) * +loan.amt,
26
+ valuation: (0, trading_1.getSpotPrice)(loan.ccy) * +loan.amt,
22
27
  });
23
28
  }
24
- for (const collateral of data.collateralData) {
25
- positions.push({
29
+ const collateralData = data.collateralData || [];
30
+ for (const collateral of collateralData) {
31
+ positions.push((0, data_account_1.makeSpotPosition)({
32
+ position_id: (0, utils_1.encodePath)('collateral', collateral.ccy),
26
33
  datasource_id: 'OKX',
27
34
  product_id: `SPOT/${collateral.ccy}-USDT`,
28
35
  volume: +collateral.amt,
29
36
  free_volume: +collateral.amt,
30
- position_id: (0, utils_1.encodePath)('collateral', collateral.ccy),
31
- direction: 'LONG',
32
- position_price: 0,
33
- closable_price: 0,
34
- floating_profit: 0,
35
- valuation: 0,
36
- });
37
+ closable_price: (0, trading_1.getSpotPrice)(collateral.ccy),
38
+ }));
37
39
  }
38
- const equity = +data.collateralNotionalUsd - +data.loanNotionalUsd;
39
- const free = equity - +data.collateralNotionalUsd;
40
- return {
41
- money: {
42
- currency: 'USDT',
43
- equity,
44
- free,
45
- },
46
- positions,
47
- };
40
+ return positions;
48
41
  };
49
42
  exports.getLoanAccountInfo = getLoanAccountInfo;
50
43
  //# sourceMappingURL=loan.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loan.js","sourceRoot":"","sources":["../../src/accountInfos/loan.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,oDAAsE;AAG/D,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAA6B,EAAE;IAC7F,MAAM,GAAG,GAAG,MAAM,IAAA,iCAAmB,EAAC,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,IAAA,kBAAU,EAAC,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,IAAA,kBAAU,EAAC,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;AA5CW,QAAA,kBAAkB,sBA4C7B","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getFlexibleLoanInfo } from '../api/private-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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AI,CACZ,IAAA,+BAAgB,EAAC;YACf,WAAW,EAAE,IAAA,kBAAU,EAAC,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC;YACrD,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,cAAc,EAAE,IAAA,sBAAY,EAAC,UAAU,CAAC,GAAG,CAAC;SAC7C,CAAC,CACH,CAAC;KACH;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AArCW,QAAA,kBAAkB,sBAqC7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getFlexibleLoanInfo } from '../api/private-api';\nimport { getSpotPrice } from './trading';\n\nexport const getLoanAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const res = await getFlexibleLoanInfo(credential);\n const data = res.data[0];\n if (!data) return [];\n\n const positions: IPosition[] = [];\n\n const loanData = data.loanData || [];\n for (const loan of 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: getSpotPrice(loan.ccy),\n floating_profit: -getSpotPrice(loan.ccy) * +loan.amt,\n valuation: getSpotPrice(loan.ccy) * +loan.amt,\n });\n }\n const collateralData = data.collateralData || [];\n for (const collateral of collateralData) {\n positions.push(\n makeSpotPosition({\n position_id: encodePath('collateral', collateral.ccy),\n datasource_id: 'OKX',\n product_id: `SPOT/${collateral.ccy}-USDT`,\n volume: +collateral.amt,\n free_volume: +collateral.amt,\n closable_price: getSpotPrice(collateral.ccy),\n }),\n );\n }\n\n return positions;\n};\n"]}
@@ -1,4 +1,4 @@
1
+ import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
1
2
  import { ICredential } from '../api/private-api';
2
- import { IAccountInfoCore } from './types';
3
- export declare const getStrategyAccountInfo: (credential: ICredential) => Promise<IAccountInfoCore>;
3
+ export declare const getStrategyAccountInfo: IActionHandlerOfGetAccountInfo<ICredential>;
4
4
  //# sourceMappingURL=strategy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../src/accountInfos/strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAA8C,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,sBAAsB,eAAsB,WAAW,KAAG,QAAQ,gBAAgB,CAyD9F,CAAC"}
1
+ {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../src/accountInfos/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAE,WAAW,EAA8C,MAAM,oBAAoB,CAAC;AAE7F,eAAO,MAAM,sBAAsB,EAAE,8BAA8B,CAAC,WAAW,CAkD9E,CAAC"}
@@ -47,14 +47,7 @@ const getStrategyAccountInfo = async (credential) => {
47
47
  totalEquity += positionValuation / leverage;
48
48
  }
49
49
  });
50
- return {
51
- money: {
52
- currency: 'USDT',
53
- equity: totalEquity,
54
- free: 0, // TODO: 累计策略的可提取资金作为 free
55
- },
56
- positions,
57
- };
50
+ return positions;
58
51
  };
59
52
  exports.getStrategyAccountInfo = getStrategyAccountInfo;
60
53
  //# sourceMappingURL=strategy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/accountInfos/strategy.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,oDAA6F;AAGtF,MAAM,sBAAsB,GAAG,KAAK,EAAE,UAAuB,EAA6B,EAAE;IACjG,iCA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A,kBAAU,EAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;oBAC1D,SAAS;oBACT,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;oBAC/B,WAAW,EAAE,CAAC,QAAQ,CAAC,GAAG;oBAC1B,cAAc,EAAE,CAAC,QAAQ,CAAC,KAAK;oBAC/B,eAAe,EAAE,CAAC,QAAQ,CAAC,GAAG;oBAC9B,cAAc,EAAE,CAAC,QAAQ,CAAC,IAAI;oBAC9B,SAAS,EAAE,CAAC,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;AAzDW,QAAA,sBAAsB,0BAyDjC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getGridOrdersAlgoPending, getGridPositions } from '../api/private-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"]}
1
+ {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/accountInfos/strategy.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,oDAA6F;AAEtF,MAAM,sBAAsB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IACtG,iCAAiC;IACjC,MAAM,CAAC,cAAc,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACzC,IAAA,sCAAwB,EAAC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AE,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;oBAC/B,WAAW,EAAE,CAAC,QAAQ,CAAC,GAAG;oBAC1B,cAAc,EAAE,CAAC,QAAQ,CAAC,KAAK;oBAC/B,eAAe,EAAE,CAAC,QAAQ,CAAC,GAAG;oBAC9B,cAAc,EAAE,CAAC,QAAQ,CAAC,IAAI;oBAC9B,SAAS,EAAE,CAAC,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,SAAS,CAAC;AACnB,CAAC,CAAC;AAlDW,QAAA,sBAAsB,0BAkDjC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { ICredential, getGridOrdersAlgoPending, getGridPositions } from '../api/private-api';\n\nexport const getStrategyAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\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 positions;\n};\n"]}
@@ -1,5 +1,6 @@
1
+ import { IActionHandlerOfGetAccountInfo } from '@yuants/data-account';
1
2
  import { ICredential } from '../api/private-api';
2
- import { IAccountInfoCore } from './types';
3
3
  export declare const marketIndexTickerUSDT$: import("rxjs").Observable<Map<string, number>>;
4
- export declare const getTradingAccountInfo: (credential: ICredential) => Promise<IAccountInfoCore>;
4
+ export declare const getSpotPrice: (ccy: string) => number;
5
+ export declare const getTradingAccountInfo: IActionHandlerOfGetAccountInfo<ICredential>;
5
6
  //# sourceMappingURL=trading.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trading.d.ts","sourceRoot":"","sources":["../../src/accountInfos/trading.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAA0C,MAAM,oBAAoB,CAAC;AAGzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,sBAAsB,gDASlC,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAsB,WAAW,KAAG,QAAQ,gBAAgB,CA+E7F,CAAC"}
1
+ {"version":3,"file":"trading.d.ts","sourceRoot":"","sources":["../../src/accountInfos/trading.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAA+B,MAAM,sBAAsB,CAAC;AAGnG,OAAO,EAAE,WAAW,EAA0C,MAAM,oBAAoB,CAAC;AAMzF,eAAO,MAAM,sBAAsB,gDAYlC,CAAC;AAIF,eAAO,MAAM,YAAY,QAAS,MAAM,WAGvC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,8BAA8B,CAAC,WAAW,CAuE7E,CAAC"}
@@ -1,27 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTradingAccountInfo = exports.marketIndexTickerUSDT$ = void 0;
3
+ exports.getTradingAccountInfo = exports.getSpotPrice = exports.marketIndexTickerUSDT$ = void 0;
4
+ const data_account_1 = require("@yuants/data-account");
4
5
  const utils_1 = require("@yuants/utils");
5
6
  const rxjs_1 = require("rxjs");
6
7
  const private_api_1 = require("../api/private-api");
7
8
  const public_api_1 = require("../api/public-api");
8
9
  const product_1 = require("../public-data/product");
10
+ const priceCache = new Map();
9
11
  exports.marketIndexTickerUSDT$ = (0, rxjs_1.defer)(() => (0, public_api_1.getMarketIndexTicker)({ quoteCcy: 'USDT' })).pipe((0, rxjs_1.map)((x) => {
10
12
  const mapInstIdToPrice = new Map();
11
- x.data.forEach((inst) => mapInstIdToPrice.set(inst.instId, Number(inst.idxPx)));
13
+ x.data.forEach((inst) => {
14
+ mapInstIdToPrice.set(inst.instId, Number(inst.idxPx));
15
+ priceCache.set(inst.instId, Number(inst.idxPx));
16
+ });
12
17
  return mapInstIdToPrice;
13
18
  }), (0, rxjs_1.repeat)({ delay: 1000 }), (0, rxjs_1.retry)({ delay: 5000 }), (0, rxjs_1.shareReplay)(1));
19
+ exports.marketIndexTickerUSDT$.subscribe();
20
+ const getSpotPrice = (ccy) => {
21
+ if (ccy === 'USDT')
22
+ return 1;
23
+ return priceCache.get(`${ccy}-USDT`) || 0;
24
+ };
25
+ exports.getSpotPrice = getSpotPrice;
14
26
  const getTradingAccountInfo = async (credential) => {
15
27
  var _a;
16
- const [positionsApi, balanceApi, mapProductIdToProduct, marketIndexTickerUSDT] = await Promise.all([
28
+ const [positionsApi, balanceApi, mapProductIdToProduct] = await Promise.all([
17
29
  (0, private_api_1.getAccountPositions)(credential, {}),
18
30
  (0, private_api_1.getAccountBalance)(credential, {}),
19
31
  (0, rxjs_1.firstValueFrom)(product_1.productService.mapProductIdToProduct$),
20
- (0, rxjs_1.firstValueFrom)(exports.marketIndexTickerUSDT$),
21
32
  ]);
22
- let totalEquity = 0;
23
- let totalFree = 0;
24
33
  const positions = [];
34
+ // 现货头寸
25
35
  (_a = balanceApi.data[0]) === null || _a === void 0 ? void 0 : _a.details.forEach((detail) => {
26
36
  var _a, _b, _c, _d, _e, _f;
27
37
  if (detail.ccy === 'USDT') {
@@ -29,30 +39,28 @@ const getTradingAccountInfo = async (credential) => {
29
39
  const free = Math.min(balance, // free should no more than balance if there is much profits
30
40
  +((_b = detail.availEq) !== null && _b !== void 0 ? _b : 0));
31
41
  const equity = +((_c = detail.eq) !== null && _c !== void 0 ? _c : 0) - +((_d = detail.stgyEq) !== null && _d !== void 0 ? _d : 0);
32
- totalEquity += equity;
33
- totalFree += free;
42
+ positions.push((0, data_account_1.makeSpotPosition)({
43
+ position_id: (0, utils_1.encodePath)('SPOT', 'USDT'),
44
+ datasource_id: 'OKX',
45
+ product_id: (0, utils_1.encodePath)('SPOT', 'USDT'),
46
+ volume: equity,
47
+ free_volume: free,
48
+ closable_price: 1,
49
+ }));
34
50
  }
35
51
  else {
36
52
  const volume = +((_e = detail.cashBal) !== null && _e !== void 0 ? _e : 0);
37
53
  const free_volume = Math.min(volume, // free should no more than balance if there is much profits
38
54
  +((_f = detail.availEq) !== null && _f !== void 0 ? _f : 0));
39
- const closable_price = marketIndexTickerUSDT.get(detail.ccy + '-USDT') || 0;
40
- const delta_equity = volume * closable_price || 0;
41
- const delta_profit = +detail.totalPnl || 0;
42
55
  const product_id = (0, utils_1.encodePath)('SPOT', `${detail.ccy}-USDT`);
43
- positions.push({
56
+ positions.push((0, data_account_1.makeSpotPosition)({
44
57
  position_id: product_id,
45
58
  datasource_id: 'OKX',
46
59
  product_id: product_id,
47
- direction: 'LONG',
48
60
  volume: volume,
49
61
  free_volume: free_volume,
50
- position_price: +detail.accAvgPx,
51
- floating_profit: delta_profit,
52
- closable_price: closable_price,
53
- valuation: delta_equity,
54
- });
55
- totalEquity += delta_equity;
62
+ closable_price: (0, exports.getSpotPrice)(detail.ccy),
63
+ }));
56
64
  }
57
65
  });
58
66
  positionsApi.data.forEach((x) => {
@@ -75,14 +83,7 @@ const getTradingAccountInfo = async (credential) => {
75
83
  valuation,
76
84
  });
77
85
  });
78
- return {
79
- money: {
80
- currency: 'USDT',
81
- equity: totalEquity,
82
- free: totalFree,
83
- },
84
- positions: positions,
85
- };
86
+ return positions;
86
87
  };
87
88
  exports.getTradingAccountInfo = getTradingAccountInfo;
88
89
  //# sourceMappingURL=trading.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"trading.js","sourceRoot":"","sources":["../../src/accountInfos/trading.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,+BAA8E;AAC9E,oDAAyF;AACzF,kDAAyD;AACzD,oDAAwD;AAG3C,QAAA,sBAAsB,GAAG,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,iCAAoB,EAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAChG,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE;IACR,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnD,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,gBAA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C,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QAClG,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,UAAU,GAAG,IAAA,kBAAU,EAAC,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;AA/EW,QAAA,qBAAqB,yBA+EhC","sourcesContent":["import { 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/private-api';\nimport { getMarketIndexTicker } from '../api/public-api';\nimport { productService } from '../public-data/product';\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"]}
1
+ {"version":3,"file":"trading.js","sourceRoot":"","sources":["../../src/accountInfos/trading.ts"],"names":[],"mappings":";;;AAAA,uDAAmG;AACnG,yCAA2C;AAC3C,+BAA8E;AAC9E,oDAAyF;AACzF,kDAAyD;AACzD,oDAAwD;AAExD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEhC,QAAA,sBAAsB,GAAG,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,iCAAoB,EAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAChG,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,EAAE;IACR,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnD,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE;QAC3B,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACtD,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IACH,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC,EACF,IAAA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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QAClG,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,UAAU,GAAG,IAAA,kBAAU,EAAC,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,SAAS,CAAC;AACnB,CAAC,CAAC;AAvEW,QAAA,qBAAqB,yBAuEhC","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { defer, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';\nimport { ICredential, getAccountBalance, getAccountPositions } from '../api/private-api';\nimport { getMarketIndexTicker } from '../api/public-api';\nimport { productService } from '../public-data/product';\n\nconst priceCache = new Map<string, number>();\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) => {\n mapInstIdToPrice.set(inst.instId, Number(inst.idxPx));\n priceCache.set(inst.instId, Number(inst.idxPx));\n });\n return mapInstIdToPrice;\n }),\n repeat({ delay: 1000 }),\n retry({ delay: 5000 }),\n shareReplay(1),\n);\n\nmarketIndexTickerUSDT$.subscribe();\n\nexport const getSpotPrice = (ccy: string) => {\n if (ccy === 'USDT') return 1;\n return priceCache.get(`${ccy}-USDT`) || 0;\n};\n\nexport const getTradingAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const [positionsApi, balanceApi, mapProductIdToProduct] = await Promise.all([\n getAccountPositions(credential, {}),\n getAccountBalance(credential, {}),\n firstValueFrom(productService.mapProductIdToProduct$),\n ]);\n\n const positions: IPosition[] = [];\n\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 positions.push(\n makeSpotPosition({\n position_id: encodePath('SPOT', 'USDT'),\n datasource_id: 'OKX',\n product_id: encodePath('SPOT', 'USDT'),\n volume: equity,\n free_volume: free,\n closable_price: 1,\n }),\n );\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\n const product_id = encodePath('SPOT', `${detail.ccy}-USDT`);\n positions.push(\n makeSpotPosition({\n position_id: product_id,\n datasource_id: 'OKX',\n product_id: product_id,\n volume: volume,\n free_volume: free_volume,\n closable_price: getSpotPrice(detail.ccy),\n }),\n );\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 positions;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"uid.d.ts","sourceRoot":"","sources":["../../src/accountInfos/uid.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAuBnE,eAAO,MAAM,MAAM,eAAsB,WAAW,gCAEnD,CAAC;AAEF,eAAO,MAAM,aAAa,eAAsB,WAAW;;;;;;cAE1D,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAAsB,WAAW,oBACd,CAAC;AAEpD,eAAO,MAAM,oBAAoB,eAAsB,WAAW,oBACd,CAAC;AAErD,eAAO,MAAM,gBAAgB,eAAsB,WAAW,oBACd,CAAC;AAEjD,eAAO,MAAM,mBAAmB,eAAsB,WAAW,oBACd,CAAC;AAEpD,eAAO,MAAM,mBAAmB,eAAsB,WAAW,oBACd,CAAC"}
1
+ {"version":3,"file":"uid.d.ts","sourceRoot":"","sources":["../../src/accountInfos/uid.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAwBnE,eAAO,MAAM,MAAM,eAAsB,WAAW,gCAEnD,CAAC;AAEF,eAAO,MAAM,aAAa,eAAsB,WAAW;;;;;;cAE1D,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAAsB,WAAW,oBACd,CAAC;AAEpD,eAAO,MAAM,oBAAoB,eAAsB,WAAW,oBACd,CAAC;AAErD,eAAO,MAAM,gBAAgB,eAAsB,WAAW,oBACd,CAAC;AAEjD,eAAO,MAAM,mBAAmB,eAAsB,WAAW,oBACd,CAAC;AAEpD,eAAO,MAAM,mBAAmB,eAAsB,WAAW,oBACd,CAAC"}
@@ -13,6 +13,8 @@ const accountUidCache = (0, cache_1.createCache)(async (key) => {
13
13
  });
14
14
  const accountIdCache = (0, cache_1.createCache)(async (key) => {
15
15
  const uid = await accountUidCache.query(key);
16
+ if (!uid)
17
+ throw new Error('Failed to get UID');
16
18
  return {
17
19
  trading: `okx/${uid}/trading`,
18
20
  strategy: `okx/${uid}/strategy`,
@@ -1 +1 @@
1
- {"version":3,"file":"uid.js","sourceRoot":"","sources":["../../src/accountInfos/uid.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,oDAAmE;AAEnE,MAAM,kBAAkB,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,8BAAgB,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE;IACjF,MAAM,EAAE,MAAO;IACf,QAAQ,EAAE,KAAM;CACjB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,IAAA,mBAAW,EAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAChD,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnD,OAAO,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;AAC7B,CAAC,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,IAAA,mBAAW,EAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAC/C,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO;QACL,OAAO,EAAE,OAAO,GAAG,UAAU;QAC7B,QAAQ,EAAE,OAAO,GAAG,WAAW;QAC/B,IAAI,EAAE,OAAO,GAAG,YAAY;QAC5B,OAAO,EAAE,OAAO,GAAG,eAAe;QAClC,OAAO,EAAE,OAAO,GAAG,eAAe;KACnC,CAAC;AACJ,CAAC,CAAC,CAAC;AA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E,CACnE,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC;AADvC,QAAA,mBAAmB,uBACoB","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getAccountConfig, ICredential } from '../api/private-api';\n\nconst accountConfigCache = createCache((key) => getAccountConfig(JSON.parse(key)), {\n expire: 100_000,\n swrAfter: 10_000,\n});\n\nconst accountUidCache = createCache(async (key) => {\n const config = await accountConfigCache.query(key);\n return config?.data[0].uid;\n});\n\nconst accountIdCache = createCache(async (key) => {\n const uid = await accountUidCache.query(key);\n return {\n trading: `okx/${uid}/trading`,\n strategy: `okx/${uid}/strategy`,\n loan: `okx/${uid}/loan/USDT`,\n earning: `okx/${uid}/earning/USDT`,\n funding: `okx/${uid}/funding/USDT`,\n };\n});\n\nexport const getUid = async (credential: ICredential) => {\n return accountUidCache.query(JSON.stringify(credential));\n};\n\nexport const getAccountIds = async (credential: ICredential) => {\n return accountIdCache.query(JSON.stringify(credential));\n};\n\nexport const getTradingAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.trading);\n\nexport const getStrategyAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.strategy);\n\nexport const getLoanAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.loan);\n\nexport const getEarningAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.earning);\n\nexport const getFundingAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.funding);\n"]}
1
+ {"version":3,"file":"uid.js","sourceRoot":"","sources":["../../src/accountInfos/uid.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,oDAAmE;AAEnE,MAAM,kBAAkB,GAAG,IAAA,mBAAW,EAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,8BAAgB,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE;IAC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AAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC;AADvC,QAAA,mBAAmB,uBACoB;AAE7C,MAAM,oBAAoB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE,CACpE,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,QAAQ,CAAC,CAAC;AADxC,QAAA,oBAAoB,wBACoB;AAE9C,MAAM,gBAAgB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE,CAChE,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,IAAI,CAAC,CAAC;AADpC,QAAA,gBAAgB,oBACoB;AAE1C,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE,CACnE,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC;AADvC,QAAA,mBAAmB,uBACoB;AAE7C,MAAM,mBAAmB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE,CACnE,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC;AADvC,QAAA,mBAAmB,uBACoB","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getAccountConfig, ICredential } from '../api/private-api';\n\nconst accountConfigCache = createCache((key) => getAccountConfig(JSON.parse(key)), {\n expire: 100_000,\n swrAfter: 10_000,\n});\n\nconst accountUidCache = createCache(async (key) => {\n const config = await accountConfigCache.query(key);\n return config?.data[0].uid;\n});\n\nconst accountIdCache = createCache(async (key) => {\n const uid = await accountUidCache.query(key);\n if (!uid) throw new Error('Failed to get UID');\n return {\n trading: `okx/${uid}/trading`,\n strategy: `okx/${uid}/strategy`,\n loan: `okx/${uid}/loan/USDT`,\n earning: `okx/${uid}/earning/USDT`,\n funding: `okx/${uid}/funding/USDT`,\n };\n});\n\nexport const getUid = async (credential: ICredential) => {\n return accountUidCache.query(JSON.stringify(credential));\n};\n\nexport const getAccountIds = async (credential: ICredential) => {\n return accountIdCache.query(JSON.stringify(credential));\n};\n\nexport const getTradingAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.trading);\n\nexport const getStrategyAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.strategy);\n\nexport const getLoanAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.loan);\n\nexport const getEarningAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.earning);\n\nexport const getFundingAccountId = async (credential: ICredential) =>\n getAccountIds(credential).then((x) => x!.funding);\n"]}
@@ -4,8 +4,8 @@ const data_account_1 = require("@yuants/data-account");
4
4
  const protocol_1 = require("@yuants/protocol");
5
5
  const rxjs_1 = require("rxjs");
6
6
  const accountInfos_1 = require("./accountInfos");
7
- const private_api_1 = require("./api/private-api");
8
7
  const uid_1 = require("./accountInfos/uid");
8
+ const private_api_1 = require("./api/private-api");
9
9
  const terminal = protocol_1.Terminal.fromNodeEnv();
10
10
  const credential = (0, private_api_1.getDefaultCredential)();
11
11
  (0, rxjs_1.defer)(async () => {
@@ -30,7 +30,7 @@ const credential = (0, private_api_1.getDefaultCredential)();
30
30
  egress_token_capacity: 20,
31
31
  egress_token_refill_interval: 4000, // 每 4 秒恢复 20 个令牌 (双倍冗余限流)
32
32
  });
33
- (0, data_account_1.provideAccountInfoService)(terminal, strategyAccountId, () => (0, accountInfos_1.getStrategyAccountInfo)(credential), {
33
+ (0, data_account_1.provideAccountInfoService)(terminal, strategyAccountId, () => (0, accountInfos_1.getStrategyAccountInfo)(credential, strategyAccountId), {
34
34
  auto_refresh_interval: 5000,
35
35
  });
36
36
  }).subscribe();