@yuants/vendor-okx 0.27.4 → 0.27.6

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 (45) 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 +14 -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/strategy-account.js +2 -2
  16. package/dist/strategy-account.js.map +1 -1
  17. package/lib/account-actions-with-credential.js +6 -6
  18. package/lib/account-actions-with-credential.js.map +1 -1
  19. package/lib/account.d.ts.map +1 -1
  20. package/lib/account.js +4 -4
  21. package/lib/account.js.map +1 -1
  22. package/lib/accountInfos/earning.d.ts +2 -2
  23. package/lib/accountInfos/earning.d.ts.map +1 -1
  24. package/lib/accountInfos/earning.js +12 -10
  25. package/lib/accountInfos/earning.js.map +1 -1
  26. package/lib/accountInfos/funding.d.ts +2 -2
  27. package/lib/accountInfos/funding.d.ts.map +1 -1
  28. package/lib/accountInfos/funding.js +10 -40
  29. package/lib/accountInfos/funding.js.map +1 -1
  30. package/lib/accountInfos/loan.d.ts +2 -2
  31. package/lib/accountInfos/loan.d.ts.map +1 -1
  32. package/lib/accountInfos/loan.js +14 -23
  33. package/lib/accountInfos/loan.js.map +1 -1
  34. package/lib/accountInfos/strategy.d.ts +2 -2
  35. package/lib/accountInfos/strategy.d.ts.map +1 -1
  36. package/lib/accountInfos/strategy.js +1 -8
  37. package/lib/accountInfos/strategy.js.map +1 -1
  38. package/lib/accountInfos/trading.d.ts +3 -2
  39. package/lib/accountInfos/trading.d.ts.map +1 -1
  40. package/lib/accountInfos/trading.js +28 -27
  41. package/lib/accountInfos/trading.js.map +1 -1
  42. package/lib/strategy-account.js +2 -2
  43. package/lib/strategy-account.js.map +1 -1
  44. package/package.json +16 -16
  45. package/temp/package-deps.json +26 -26
@@ -1,7 +1,7 @@
1
1
  import { provideAccountActionsWithCredential } from '@yuants/data-account';
2
2
  import { Terminal } from '@yuants/protocol';
3
- import { getAccountIds } from './accountInfos/uid';
4
3
  import { getEarningAccountInfo, getFundingAccountInfo, getLoanAccountInfo, getStrategyAccountInfo, getTradingAccountInfo, } from './accountInfos';
4
+ import { getAccountIds } from './accountInfos/uid';
5
5
  provideAccountActionsWithCredential(Terminal.fromNodeEnv(), 'OKX', {
6
6
  type: 'object',
7
7
  required: ['access_key', 'secret_key', 'passphrase'],
@@ -23,15 +23,15 @@ provideAccountActionsWithCredential(Terminal.fromNodeEnv(), 'OKX', {
23
23
  throw new Error('Failed to get account IDs');
24
24
  switch (account_id) {
25
25
  case accountIds.trading:
26
- return getTradingAccountInfo(credential);
26
+ return getTradingAccountInfo(credential, account_id);
27
27
  case accountIds.funding:
28
- return getFundingAccountInfo(credential);
28
+ return getFundingAccountInfo(credential, account_id);
29
29
  case accountIds.earning:
30
- return getEarningAccountInfo(credential);
30
+ return getEarningAccountInfo(credential, account_id);
31
31
  case accountIds.loan:
32
- return getLoanAccountInfo(credential);
32
+ return getLoanAccountInfo(credential, account_id);
33
33
  case accountIds.strategy:
34
- return getStrategyAccountInfo(credential);
34
+ return getStrategyAccountInfo(credential, account_id);
35
35
  }
36
36
  throw new Error(`Unsupported account_id: ${account_id}`);
37
37
  },
@@ -1 +1 @@
1
- {"version":3,"file":"account-actions-with-credential.js","sourceRoot":"","sources":["../src/account-actions-with-credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO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C,CAAC;YAC3C,KAAK,UAAU,CAAC,OAAO;gBACrB,OAAO,qBAAqB,CAAC,UAAU,CAAC,CAAC;YAC3C,KAAK,UAAU,CAAC,IAAI;gBAClB,OAAO,kBAAkB,CAAC,UAAU,CAAC,CAAC;YACxC,KAAK,UAAU,CAAC,QAAQ;gBACtB,OAAO,sBAAsB,CAAC,UAAU,CAAC,CAAC;SAC7C;QACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF,CACF,CAAC","sourcesContent":["import { provideAccountActionsWithCredential } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { ICredential } from './api/private-api';\nimport { getAccountIds } from './accountInfos/uid';\nimport {\n getEarningAccountInfo,\n getFundingAccountInfo,\n getLoanAccountInfo,\n getStrategyAccountInfo,\n getTradingAccountInfo,\n} from './accountInfos';\n\nprovideAccountActionsWithCredential<ICredential>(\n Terminal.fromNodeEnv(),\n 'OKX',\n {\n type: 'object',\n required: ['access_key', 'secret_key', 'passphrase'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n passphrase: { type: 'string' },\n },\n },\n {\n listAccounts: async (credential) => {\n const accountIds = await getAccountIds(credential);\n if (!accountIds) throw new Error('Failed to get account IDs');\n return Object.values(accountIds).map((account_id) => ({ account_id }));\n },\n getAccountInfo: async (credential, account_id) => {\n const accountIds = await getAccountIds(credential);\n if (!accountIds) throw new Error('Failed to get account IDs');\n switch (account_id) {\n case accountIds.trading:\n return getTradingAccountInfo(credential);\n case accountIds.funding:\n return getFundingAccountInfo(credential);\n case accountIds.earning:\n return getEarningAccountInfo(credential);\n case accountIds.loan:\n return getLoanAccountInfo(credential);\n case accountIds.strategy:\n return getStrategyAccountInfo(credential);\n }\n throw new Error(`Unsupported account_id: ${account_id}`);\n },\n },\n);\n"]}
1
+ {"version":3,"file":"account-actions-with-credential.js","sourceRoot":"","sources":["../src/account-actions-with-credential.ts"],"names":[],"mappings":"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AC,CAAC;YACvD,KAAK,UAAU,CAAC,OAAO;gBACrB,OAAO,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YACvD,KAAK,UAAU,CAAC,OAAO;gBACrB,OAAO,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YACvD,KAAK,UAAU,CAAC,IAAI;gBAClB,OAAO,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YACpD,KAAK,UAAU,CAAC,QAAQ;gBACtB,OAAO,sBAAsB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SACzD;QACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF,CACF,CAAC","sourcesContent":["import { provideAccountActionsWithCredential } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport {\n getEarningAccountInfo,\n getFundingAccountInfo,\n getLoanAccountInfo,\n getStrategyAccountInfo,\n getTradingAccountInfo,\n} from './accountInfos';\nimport { getAccountIds } from './accountInfos/uid';\nimport { ICredential } from './api/private-api';\n\nprovideAccountActionsWithCredential<ICredential>(\n Terminal.fromNodeEnv(),\n 'OKX',\n {\n type: 'object',\n required: ['access_key', 'secret_key', 'passphrase'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n passphrase: { type: 'string' },\n },\n },\n {\n listAccounts: async (credential) => {\n const accountIds = await getAccountIds(credential);\n if (!accountIds) throw new Error('Failed to get account IDs');\n return Object.values(accountIds).map((account_id) => ({ account_id }));\n },\n getAccountInfo: async (credential, account_id) => {\n const accountIds = await getAccountIds(credential);\n if (!accountIds) throw new Error('Failed to get account IDs');\n switch (account_id) {\n case accountIds.trading:\n return getTradingAccountInfo(credential, account_id);\n case accountIds.funding:\n return getFundingAccountInfo(credential, account_id);\n case accountIds.earning:\n return getEarningAccountInfo(credential, account_id);\n case accountIds.loan:\n return getLoanAccountInfo(credential, account_id);\n case accountIds.strategy:\n return getStrategyAccountInfo(credential, account_id);\n }\n throw new Error(`Unsupported account_id: ${account_id}`);\n },\n },\n);\n"]}
package/dist/account.js CHANGED
@@ -17,25 +17,25 @@ defer(async () => {
17
17
  defer(async () => {
18
18
  const tradingAccountId = await getTradingAccountId(credential);
19
19
  addAccountMarket(terminal, { account_id: tradingAccountId, market_id: 'OKX' });
20
- provideAccountInfoService(terminal, tradingAccountId, () => getTradingAccountInfo(credential), {
20
+ provideAccountInfoService(terminal, tradingAccountId, () => getTradingAccountInfo(credential, tradingAccountId), {
21
21
  auto_refresh_interval: 1000,
22
22
  });
23
23
  }).subscribe();
24
24
  defer(async () => {
25
25
  const fundingAccountId = await getFundingAccountId(credential);
26
- provideAccountInfoService(terminal, fundingAccountId, () => getFundingAccountInfo(credential), {
26
+ provideAccountInfoService(terminal, fundingAccountId, () => getFundingAccountInfo(credential, fundingAccountId), {
27
27
  auto_refresh_interval: 1000,
28
28
  });
29
29
  }).subscribe();
30
30
  defer(async () => {
31
31
  const earningAccountId = await getEarningAccountId(credential);
32
- provideAccountInfoService(terminal, earningAccountId, () => getEarningAccountInfo(credential), {
32
+ provideAccountInfoService(terminal, earningAccountId, () => getEarningAccountInfo(credential, earningAccountId), {
33
33
  auto_refresh_interval: 5000,
34
34
  });
35
35
  }).subscribe();
36
36
  defer(async () => {
37
37
  const loanAccountId = await getLoanAccountId(credential);
38
- provideAccountInfoService(Terminal.fromNodeEnv(), loanAccountId, () => getLoanAccountInfo(credential), {
38
+ provideAccountInfoService(Terminal.fromNodeEnv(), loanAccountId, () => getLoanAccountInfo(credential, loanAccountId), {
39
39
  auto_refresh_interval: 1000,
40
40
  });
41
41
  }).subscribe();
@@ -1 +1 @@
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,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AAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAE/D,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,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC/D,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,aAAa,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACzD,yBAAyB,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE;QACrG,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 { 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,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,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,mBAAm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CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC/D,yBAAyB,CACvB,QAAQ,EACR,gBAAgB,EAChB,GAAG,EAAE,CAAC,qBAAqB,CAAC,UAAU,EAAE,gBAAgB,CAAC,EACzD;QACE,qBAAqB,EAAE,IAAI;KAC5B,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAEf,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACzD,yBAAyB,CACvB,QAAQ,CAAC,WAAW,EAAE,EACtB,aAAa,EACb,GAAG,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,aAAa,CAAC,EACnD;QACE,qBAAqB,EAAE,IAAI;KAC5B,CACF,CAAC;AACJ,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 { 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,15 +1,17 @@
1
+ import { makeSpotPosition } from '@yuants/data-account';
1
2
  import { getFinanceSavingsBalance } from '../api/private-api';
3
+ import { getSpotPrice } from './trading';
2
4
  export const getEarningAccountInfo = async (credential) => {
3
5
  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
- };
6
+ return offers.data.map((offer) => {
7
+ return makeSpotPosition({
8
+ position_id: `earning/${offer.ccy}`,
9
+ datasource_id: 'OKX',
10
+ product_id: `earning/${offer.ccy}`,
11
+ volume: +offer.amt,
12
+ free_volume: +offer.amt,
13
+ closable_price: getSpotPrice(offer.ccy),
14
+ });
15
+ });
14
16
  };
15
17
  //# sourceMappingURL=earning.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"earning.js","sourceRoot":"","sources":["../../src/accountInfos/earning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAG3E,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/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,OAAO,EAAkC,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExF,OAAO,EAAe,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAA0B,MAAM,WAAW,CAAC;AAEjE,MAAM,CAAC,MAAM,qBAAqB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IACrG,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAE9D,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC/B,OAAO,gBAAgB,CAAC;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,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC;SACxC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","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,46 +1,16 @@
1
+ import { makeSpotPosition } from '@yuants/data-account';
1
2
  import { encodePath } from '@yuants/utils';
2
- import { firstValueFrom } from 'rxjs';
3
3
  import { getAssetBalances } from '../api/private-api';
4
- import { marketIndexTickerUSDT$ } from './trading';
4
+ import { getSpotPrice } from './trading';
5
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
- };
6
+ const assetBalances = await getAssetBalances(credential, {});
7
+ return assetBalances.data.map((x) => makeSpotPosition({
8
+ datasource_id: 'OKX',
9
+ position_id: encodePath('SPOT', `${x.ccy}-USDT`),
10
+ product_id: encodePath('SPOT', `${x.ccy}-USDT`),
11
+ volume: +x.bal,
12
+ free_volume: +x.bal,
13
+ closable_price: getSpotPrice(x.ccy),
14
+ }));
45
15
  };
46
16
  //# sourceMappingURL=funding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"funding.js","sourceRoot":"","sources":["../../src/accountInfos/funding.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAe,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAGnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EAAE,UAAuB,EAA6B,EAAE;IAChG,MAAM,CA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ACL;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/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,OAAO,EAAkC,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAe,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,CAAC,MAAM,qBAAqB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IACrG,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAE7D,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAClC,gBAAgB,CAAC;QACf,aAAa,EAAE,KAAK;QACpB,WAAW,EAAE,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;QAChD,UAAU,EAAE,UAAU,CAAC,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,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC;KACpC,CAAC,CACH,CAAC;AACJ,CAAC,CAAC","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,10 +1,14 @@
1
+ import { makeSpotPosition } from '@yuants/data-account';
1
2
  import { encodePath } from '@yuants/utils';
2
3
  import { getFlexibleLoanInfo } from '../api/private-api';
4
+ import { getSpotPrice } from './trading';
3
5
  export const getLoanAccountInfo = async (credential) => {
4
6
  const res = await getFlexibleLoanInfo(credential);
5
7
  const data = res.data[0];
8
+ if (!data)
9
+ return [];
6
10
  const positions = [];
7
- const loanData = (data === null || data === void 0 ? void 0 : data.loanData) || [];
11
+ const loanData = data.loanData || [];
8
12
  for (const loan of loanData) {
9
13
  positions.push({
10
14
  datasource_id: 'OKX',
@@ -14,35 +18,22 @@ export const getLoanAccountInfo = async (credential) => {
14
18
  position_id: encodePath('loan', loan.ccy),
15
19
  direction: 'SHORT',
16
20
  position_price: 0,
17
- closable_price: 0,
18
- floating_profit: 0,
19
- valuation: 0,
21
+ closable_price: getSpotPrice(loan.ccy),
22
+ floating_profit: -getSpotPrice(loan.ccy) * +loan.amt,
23
+ valuation: getSpotPrice(loan.ccy) * +loan.amt,
20
24
  });
21
25
  }
22
- const collateralData = (data === null || data === void 0 ? void 0 : data.collateralData) || [];
26
+ const collateralData = data.collateralData || [];
23
27
  for (const collateral of collateralData) {
24
- positions.push({
28
+ positions.push(makeSpotPosition({
29
+ position_id: encodePath('collateral', collateral.ccy),
25
30
  datasource_id: 'OKX',
26
31
  product_id: `SPOT/${collateral.ccy}-USDT`,
27
32
  volume: +collateral.amt,
28
33
  free_volume: +collateral.amt,
29
- position_id: encodePath('collateral', collateral.ccy),
30
- direction: 'LONG',
31
- position_price: 0,
32
- closable_price: 0,
33
- floating_profit: 0,
34
- valuation: 0,
35
- });
34
+ closable_price: getSpotPrice(collateral.ccy),
35
+ }));
36
36
  }
37
- const equity = +data.collateralNotionalUsd - +data.loanNotionalUsd;
38
- const free = equity - +data.collateralNotionalUsd;
39
- return {
40
- money: {
41
- currency: 'USDT',
42
- equity,
43
- free,
44
- },
45
- positions,
46
- };
37
+ return positions;
47
38
  };
48
39
  //# sourceMappingURL=loan.js.map
@@ -1 +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,oBAAoB,CAAC;AAGtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAA6B,EAAE;IAC7F,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,IAAI,G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,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/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\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: 0,\n floating_profit: 0,\n valuation: 0,\n });\n }\n const collateralData = data?.collateralData || [];\n for (const collateral of 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"]}
1
+ {"version":3,"file":"loan.js","sourceRoot":"","sources":["../../src/accountInfos/loan.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAe,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtE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AAU,EAAE,QAAQ,UAAU,CAAC,GAAG,OAAO;YACzC,MAAM,EAAE,CAAC,UAAU,CAAC,GAAG;YACvB,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG;YAC5B,cAAc,EAAE,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC;SAC7C,CAAC,CACH,CAAC;KACH;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","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"]}
@@ -44,13 +44,6 @@ export const getStrategyAccountInfo = async (credential) => {
44
44
  totalEquity += positionValuation / leverage;
45
45
  }
46
46
  });
47
- return {
48
- money: {
49
- currency: 'USDT',
50
- equity: totalEquity,
51
- free: 0, // TODO: 累计策略的可提取资金作为 free
52
- },
53
- positions,
54
- };
47
+ return positions;
55
48
  };
56
49
  //# sourceMappingURL=strategy.js.map
@@ -1 +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,oBAAoB,CAAC;AAG7F,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,EAAE,EAAE,CAC/B,gBAAgB,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CACpF,CACF,CAAC;IAEF,gBAAgB,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,KAAK,EAAE,EAAE;;QAChD,IAAI,iBAAiB,GAAG,CAAC,CAAC;QAC1B,MAAM,QAAQ,GAAG,CAAC,CAAA,MAAA,cAAc,CAAC,IAAI,0CAAG,KAAK,EAAE,WAAW,CAAA,CAAC;QAC3D,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,0CAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;;YACxC,IAAI,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,EAAE;gBACvB,MAAM,YAAY,GAAG,MAAA,MAAA,MAAA,cAAc,CAAC,IAAI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,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/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};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E,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;gBACrE,SAAS,CAAC,IAAI,CAAC;oBACb,WAAW,EAAE,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;oBACzD,aAAa,EAAE,KAAK;oBACpB,UAAU,EAAE,UAAU,CAAC,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,SAAS,CAAC;AACnB,CAAC,CAAC","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,24 +1,33 @@
1
+ import { makeSpotPosition } from '@yuants/data-account';
1
2
  import { encodePath } from '@yuants/utils';
2
3
  import { defer, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';
3
4
  import { getAccountBalance, getAccountPositions } from '../api/private-api';
4
5
  import { getMarketIndexTicker } from '../api/public-api';
5
6
  import { productService } from '../public-data/product';
7
+ const priceCache = new Map();
6
8
  export const marketIndexTickerUSDT$ = defer(() => getMarketIndexTicker({ quoteCcy: 'USDT' })).pipe(map((x) => {
7
9
  const mapInstIdToPrice = new Map();
8
- x.data.forEach((inst) => mapInstIdToPrice.set(inst.instId, Number(inst.idxPx)));
10
+ x.data.forEach((inst) => {
11
+ mapInstIdToPrice.set(inst.instId, Number(inst.idxPx));
12
+ priceCache.set(inst.instId, Number(inst.idxPx));
13
+ });
9
14
  return mapInstIdToPrice;
10
15
  }), repeat({ delay: 1000 }), retry({ delay: 5000 }), shareReplay(1));
16
+ marketIndexTickerUSDT$.subscribe();
17
+ export const getSpotPrice = (ccy) => {
18
+ if (ccy === 'USDT')
19
+ return 1;
20
+ return priceCache.get(`${ccy}-USDT`) || 0;
21
+ };
11
22
  export const getTradingAccountInfo = async (credential) => {
12
23
  var _a;
13
- const [positionsApi, balanceApi, mapProductIdToProduct, marketIndexTickerUSDT] = await Promise.all([
24
+ const [positionsApi, balanceApi, mapProductIdToProduct] = await Promise.all([
14
25
  getAccountPositions(credential, {}),
15
26
  getAccountBalance(credential, {}),
16
27
  firstValueFrom(productService.mapProductIdToProduct$),
17
- firstValueFrom(marketIndexTickerUSDT$),
18
28
  ]);
19
- let totalEquity = 0;
20
- let totalFree = 0;
21
29
  const positions = [];
30
+ // 现货头寸
22
31
  (_a = balanceApi.data[0]) === null || _a === void 0 ? void 0 : _a.details.forEach((detail) => {
23
32
  var _a, _b, _c, _d, _e, _f;
24
33
  if (detail.ccy === 'USDT') {
@@ -26,30 +35,28 @@ export const getTradingAccountInfo = async (credential) => {
26
35
  const free = Math.min(balance, // free should no more than balance if there is much profits
27
36
  +((_b = detail.availEq) !== null && _b !== void 0 ? _b : 0));
28
37
  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;
38
+ positions.push(makeSpotPosition({
39
+ position_id: encodePath('SPOT', 'USDT'),
40
+ datasource_id: 'OKX',
41
+ product_id: encodePath('SPOT', 'USDT'),
42
+ volume: equity,
43
+ free_volume: free,
44
+ closable_price: 1,
45
+ }));
31
46
  }
32
47
  else {
33
48
  const volume = +((_e = detail.cashBal) !== null && _e !== void 0 ? _e : 0);
34
49
  const free_volume = Math.min(volume, // free should no more than balance if there is much profits
35
50
  +((_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
51
  const product_id = encodePath('SPOT', `${detail.ccy}-USDT`);
40
- positions.push({
52
+ positions.push(makeSpotPosition({
41
53
  position_id: product_id,
42
54
  datasource_id: 'OKX',
43
55
  product_id: product_id,
44
- direction: 'LONG',
45
56
  volume: volume,
46
57
  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;
58
+ closable_price: getSpotPrice(detail.ccy),
59
+ }));
53
60
  }
54
61
  });
55
62
  positionsApi.data.forEach((x) => {
@@ -72,13 +79,6 @@ export const getTradingAccountInfo = async (credential) => {
72
79
  valuation,
73
80
  });
74
81
  });
75
- return {
76
- money: {
77
- currency: 'USDT',
78
- equity: totalEquity,
79
- free: totalFree,
80
- },
81
- positions: positions,
82
- };
82
+ return positions;
83
83
  };
84
84
  //# sourceMappingURL=trading.js.map
@@ -1 +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,oB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AC,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 { 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,OAAO,EAA6C,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,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,oBAAoB,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAEx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ACd,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","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"]}
@@ -2,8 +2,8 @@ import { addAccountMarket, provideAccountInfoService } from '@yuants/data-accoun
2
2
  import { Terminal } from '@yuants/protocol';
3
3
  import { defer } from 'rxjs';
4
4
  import { getStrategyAccountInfo } from './accountInfos';
5
- import { getDefaultCredential, getGridPositions } from './api/private-api';
6
5
  import { getStrategyAccountId } from './accountInfos/uid';
6
+ import { getDefaultCredential, getGridPositions } from './api/private-api';
7
7
  const terminal = Terminal.fromNodeEnv();
8
8
  const credential = getDefaultCredential();
9
9
  defer(async () => {
@@ -28,7 +28,7 @@ defer(async () => {
28
28
  egress_token_capacity: 20,
29
29
  egress_token_refill_interval: 4000, // 每 4 秒恢复 20 个令牌 (双倍冗余限流)
30
30
  });
31
- provideAccountInfoService(terminal, strategyAccountId, () => getStrategyAccountInfo(credential), {
31
+ provideAccountInfoService(terminal, strategyAccountId, () => getStrategyAccountInfo(credential, strategyAccountId), {
32
32
  auto_refresh_interval: 5000,
33
33
  });
34
34
  }).subscribe();
@@ -1 +1 @@
1
- {"version":3,"file":"strategy-account.js","sourceRoot":"","sources":["../src/strategy-account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;AAE1C,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,iBAAiB,GAAG,MAAM,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAEjE,gBAAgB,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAEhF,QAAQ,CAAC,MAAM,CAAC,cAAc,CAI5B,wBAAwB,EACxB;QACE,QAAQ,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC;QAClC,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,iBAAiB,EAAE;YACxD,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC3B;KACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;QACZ,EAAE;QACF,OAAO;YACL,GAAG,EAAE;gBACH,IAAI,EAAE,CAAC;gBACP,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,MAAM,gBAAgB,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;aACnG;SACF,CAAC;IACJ,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,4BAA4B,EAAE,IAAI,EAAE,0BAA0B;KAC/D,CACF,CAAC;IAEF,yBAAyB,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC,sBAAsB,CAAC,UAAU,CAAC,EAAE;QAC/F,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport { getStrategyAccountInfo } from './accountInfos';\nimport { getDefaultCredential, getGridPositions } from './api/private-api';\nimport { getStrategyAccountId } from './accountInfos/uid';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const strategyAccountId = await getStrategyAccountId(credential);\n\n addAccountMarket(terminal, { account_id: strategyAccountId, market_id: 'OKX' });\n\n terminal.server.provideService<\n { account_id: string; algoId: string },\n Awaited<ReturnType<typeof getGridPositions>>\n >(\n `OKX/QueryGridPositions`,\n {\n required: ['account_id', 'algoId'],\n properties: {\n account_id: { type: 'string', const: strategyAccountId },\n algoId: { type: 'string' },\n },\n },\n async (msg) => {\n //\n return {\n res: {\n code: 0,\n message: 'OK',\n data: await getGridPositions(credential, { algoOrdType: 'contract_grid', algoId: msg.req.algoId }),\n },\n };\n },\n {\n egress_token_capacity: 20,\n egress_token_refill_interval: 4000, // 每 4 秒恢复 20 个令牌 (双倍冗余限流)\n },\n );\n\n provideAccountInfoService(terminal, strategyAccountId, () => getStrategyAccountInfo(credential), {\n auto_refresh_interval: 5000,\n });\n}).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CAAC,MAAM,EAAE,CAAC;aACnG;SACF,CAAC;IACJ,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,4BAA4B,EAAE,IAAI,EAAE,0BAA0B;KAC/D,CACF,CAAC;IAEF,yBAAyB,CACvB,QAAQ,EACR,iBAAiB,EACjB,GAAG,EAAE,CAAC,sBAAsB,CAAC,UAAU,EAAE,iBAAiB,CAAC,EAC3D;QACE,qBAAqB,EAAE,IAAI;KAC5B,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC","sourcesContent":["import { addAccountMarket, provideAccountInfoService } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { defer } from 'rxjs';\nimport { getStrategyAccountInfo } from './accountInfos';\nimport { getStrategyAccountId } from './accountInfos/uid';\nimport { getDefaultCredential, getGridPositions } from './api/private-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst credential = getDefaultCredential();\n\ndefer(async () => {\n const strategyAccountId = await getStrategyAccountId(credential);\n\n addAccountMarket(terminal, { account_id: strategyAccountId, market_id: 'OKX' });\n\n terminal.server.provideService<\n { account_id: string; algoId: string },\n Awaited<ReturnType<typeof getGridPositions>>\n >(\n `OKX/QueryGridPositions`,\n {\n required: ['account_id', 'algoId'],\n properties: {\n account_id: { type: 'string', const: strategyAccountId },\n algoId: { type: 'string' },\n },\n },\n async (msg) => {\n //\n return {\n res: {\n code: 0,\n message: 'OK',\n data: await getGridPositions(credential, { algoOrdType: 'contract_grid', algoId: msg.req.algoId }),\n },\n };\n },\n {\n egress_token_capacity: 20,\n egress_token_refill_interval: 4000, // 每 4 秒恢复 20 个令牌 (双倍冗余限流)\n },\n );\n\n provideAccountInfoService(\n terminal,\n strategyAccountId,\n () => getStrategyAccountInfo(credential, strategyAccountId),\n {\n auto_refresh_interval: 5000,\n },\n );\n}).subscribe();\n"]}
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const data_account_1 = require("@yuants/data-account");
4
4
  const protocol_1 = require("@yuants/protocol");
5
- const uid_1 = require("./accountInfos/uid");
6
5
  const accountInfos_1 = require("./accountInfos");
6
+ const uid_1 = require("./accountInfos/uid");
7
7
  (0, data_account_1.provideAccountActionsWithCredential)(protocol_1.Terminal.fromNodeEnv(), 'OKX', {
8
8
  type: 'object',
9
9
  required: ['access_key', 'secret_key', 'passphrase'],
@@ -25,15 +25,15 @@ const accountInfos_1 = require("./accountInfos");
25
25
  throw new Error('Failed to get account IDs');
26
26
  switch (account_id) {
27
27
  case accountIds.trading:
28
- return (0, accountInfos_1.getTradingAccountInfo)(credential);
28
+ return (0, accountInfos_1.getTradingAccountInfo)(credential, account_id);
29
29
  case accountIds.funding:
30
- return (0, accountInfos_1.getFundingAccountInfo)(credential);
30
+ return (0, accountInfos_1.getFundingAccountInfo)(credential, account_id);
31
31
  case accountIds.earning:
32
- return (0, accountInfos_1.getEarningAccountInfo)(credential);
32
+ return (0, accountInfos_1.getEarningAccountInfo)(credential, account_id);
33
33
  case accountIds.loan:
34
- return (0, accountInfos_1.getLoanAccountInfo)(credential);
34
+ return (0, accountInfos_1.getLoanAccountInfo)(credential, account_id);
35
35
  case accountIds.strategy:
36
- return (0, accountInfos_1.getStrategyAccountInfo)(credential);
36
+ return (0, accountInfos_1.getStrategyAccountInfo)(credential, account_id);
37
37
  }
38
38
  throw new Error(`Unsupported account_id: ${account_id}`);
39
39
  },
@@ -1 +1 @@
1
- {"version":3,"file":"account-actions-with-credential.js","sourceRoot":"","sources":["../src/account-actions-with-credential.ts"],"names":[],"mappings":";;AAAA,uDAA2E;AAC3E,+CAA4C;AAE5C,4CAAmD;AACnD,iDAMwB;AAExB,IAAA,kDAAmC,EACjC,mBAAQ,CAAC,WAAW,EAAE,EACtB,KAAK,EACL;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;IACpD,UAAU,EAAE;QACV,UAAU,EAAE,EAAE,IAAI,E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ccountActionsWithCredential } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { ICredential } from './api/private-api';\nimport { getAccountIds } from './accountInfos/uid';\nimport {\n getEarningAccountInfo,\n getFundingAccountInfo,\n getLoanAccountInfo,\n getStrategyAccountInfo,\n getTradingAccountInfo,\n} from './accountInfos';\n\nprovideAccountActionsWithCredential<ICredential>(\n Terminal.fromNodeEnv(),\n 'OKX',\n {\n type: 'object',\n required: ['access_key', 'secret_key', 'passphrase'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n passphrase: { type: 'string' },\n },\n },\n {\n listAccounts: async (credential) => {\n const accountIds = await getAccountIds(credential);\n if (!accountIds) throw new Error('Failed to get account IDs');\n return Object.values(accountIds).map((account_id) => ({ account_id }));\n },\n getAccountInfo: async (credential, account_id) => {\n const accountIds = await getAccountIds(credential);\n if (!accountIds) throw new Error('Failed to get account IDs');\n switch (account_id) {\n case accountIds.trading:\n return getTradingAccountInfo(credential);\n case accountIds.funding:\n return getFundingAccountInfo(credential);\n case accountIds.earning:\n return getEarningAccountInfo(credential);\n case accountIds.loan:\n return getLoanAccountInfo(credential);\n case accountIds.strategy:\n return getStrategyAccountInfo(credential);\n }\n throw new Error(`Unsupported account_id: ${account_id}`);\n },\n },\n);\n"]}
1
+ {"version":3,"file":"account-actions-with-credential.js","sourceRoot":"","sources":["../src/account-actions-with-credential.ts"],"names":[],"mappings":";;AAAA,uDAA2E;AAC3E,+CAA4C;AAC5C,iDAMwB;AACxB,4CAAmD;AAGnD,IAAA,kDAAmC,EACjC,mBAAQ,CAAC,WAAW,EAAE,EACtB,KAAK,EACL;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;IACpD,UAAU,EAAE;QACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,UAAU,EAAE,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Terminal } from '@yuants/protocol';\nimport {\n getEarningAccountInfo,\n getFundingAccountInfo,\n getLoanAccountInfo,\n getStrategyAccountInfo,\n getTradingAccountInfo,\n} from './accountInfos';\nimport { getAccountIds } from './accountInfos/uid';\nimport { ICredential } from './api/private-api';\n\nprovideAccountActionsWithCredential<ICredential>(\n Terminal.fromNodeEnv(),\n 'OKX',\n {\n type: 'object',\n required: ['access_key', 'secret_key', 'passphrase'],\n properties: {\n access_key: { type: 'string' },\n secret_key: { type: 'string' },\n passphrase: { type: 'string' },\n },\n },\n {\n listAccounts: async (credential) => {\n const accountIds = await getAccountIds(credential);\n if (!accountIds) throw new Error('Failed to get account IDs');\n return Object.values(accountIds).map((account_id) => ({ account_id }));\n },\n getAccountInfo: async (credential, account_id) => {\n const accountIds = await getAccountIds(credential);\n if (!accountIds) throw new Error('Failed to get account IDs');\n switch (account_id) {\n case accountIds.trading:\n return getTradingAccountInfo(credential, account_id);\n case accountIds.funding:\n return getFundingAccountInfo(credential, account_id);\n case accountIds.earning:\n return getEarningAccountInfo(credential, account_id);\n case accountIds.loan:\n return getLoanAccountInfo(credential, account_id);\n case accountIds.strategy:\n return getStrategyAccountInfo(credential, account_id);\n }\n throw new Error(`Unsupported account_id: ${account_id}`);\n },\n },\n);\n"]}
@@ -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();