@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.
- package/dist/account-actions-with-credential.js +6 -6
- package/dist/account-actions-with-credential.js.map +1 -1
- package/dist/account.js +4 -4
- package/dist/account.js.map +1 -1
- package/dist/accountInfos/earning.js +12 -10
- package/dist/accountInfos/earning.js.map +1 -1
- package/dist/accountInfos/funding.js +11 -41
- package/dist/accountInfos/funding.js.map +1 -1
- package/dist/accountInfos/loan.js +14 -23
- package/dist/accountInfos/loan.js.map +1 -1
- package/dist/accountInfos/strategy.js +1 -8
- package/dist/accountInfos/strategy.js.map +1 -1
- package/dist/accountInfos/trading.js +26 -26
- package/dist/accountInfos/trading.js.map +1 -1
- package/dist/strategy-account.js +2 -2
- package/dist/strategy-account.js.map +1 -1
- package/lib/account-actions-with-credential.js +6 -6
- package/lib/account-actions-with-credential.js.map +1 -1
- package/lib/account.d.ts.map +1 -1
- package/lib/account.js +4 -4
- package/lib/account.js.map +1 -1
- package/lib/accountInfos/earning.d.ts +2 -2
- package/lib/accountInfos/earning.d.ts.map +1 -1
- package/lib/accountInfos/earning.js +12 -10
- package/lib/accountInfos/earning.js.map +1 -1
- package/lib/accountInfos/funding.d.ts +2 -2
- package/lib/accountInfos/funding.d.ts.map +1 -1
- package/lib/accountInfos/funding.js +10 -40
- package/lib/accountInfos/funding.js.map +1 -1
- package/lib/accountInfos/loan.d.ts +2 -2
- package/lib/accountInfos/loan.d.ts.map +1 -1
- package/lib/accountInfos/loan.js +14 -23
- package/lib/accountInfos/loan.js.map +1 -1
- package/lib/accountInfos/strategy.d.ts +2 -2
- package/lib/accountInfos/strategy.d.ts.map +1 -1
- package/lib/accountInfos/strategy.js +1 -8
- package/lib/accountInfos/strategy.js.map +1 -1
- package/lib/accountInfos/trading.d.ts +3 -2
- package/lib/accountInfos/trading.d.ts.map +1 -1
- package/lib/accountInfos/trading.js +28 -27
- package/lib/accountInfos/trading.js.map +1 -1
- package/lib/strategy-account.js +2 -2
- package/lib/strategy-account.js.map +1 -1
- package/package.json +16 -16
- package/temp/package-deps.json +26 -26
package/lib/account.js.map
CHANGED
|
@@ -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;
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
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
|
-
|
|
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":"
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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":";;;
|
|
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
|
-
|
|
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":"
|
|
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"}
|
package/lib/accountInfos/loan.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
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
|
-
const loanData =
|
|
14
|
+
const loanData = data.loanData || [];
|
|
11
15
|
for (const loan of loanData) {
|
|
12
16
|
positions.push({
|
|
13
17
|
datasource_id: 'OKX',
|
|
@@ -17,36 +21,23 @@ const getLoanAccountInfo = async (credential) => {
|
|
|
17
21
|
position_id: (0, utils_1.encodePath)('loan', loan.ccy),
|
|
18
22
|
direction: 'SHORT',
|
|
19
23
|
position_price: 0,
|
|
20
|
-
closable_price: 0,
|
|
21
|
-
floating_profit: 0,
|
|
22
|
-
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,
|
|
23
27
|
});
|
|
24
28
|
}
|
|
25
|
-
const collateralData =
|
|
29
|
+
const collateralData = data.collateralData || [];
|
|
26
30
|
for (const collateral of collateralData) {
|
|
27
|
-
positions.push({
|
|
31
|
+
positions.push((0, data_account_1.makeSpotPosition)({
|
|
32
|
+
position_id: (0, utils_1.encodePath)('collateral', collateral.ccy),
|
|
28
33
|
datasource_id: 'OKX',
|
|
29
34
|
product_id: `SPOT/${collateral.ccy}-USDT`,
|
|
30
35
|
volume: +collateral.amt,
|
|
31
36
|
free_volume: +collateral.amt,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
position_price: 0,
|
|
35
|
-
closable_price: 0,
|
|
36
|
-
floating_profit: 0,
|
|
37
|
-
valuation: 0,
|
|
38
|
-
});
|
|
37
|
+
closable_price: (0, trading_1.getSpotPrice)(collateral.ccy),
|
|
38
|
+
}));
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
const free = equity - +data.collateralNotionalUsd;
|
|
42
|
-
return {
|
|
43
|
-
money: {
|
|
44
|
-
currency: 'USDT',
|
|
45
|
-
equity,
|
|
46
|
-
free,
|
|
47
|
-
},
|
|
48
|
-
positions,
|
|
49
|
-
};
|
|
40
|
+
return positions;
|
|
50
41
|
};
|
|
51
42
|
exports.getLoanAccountInfo = getLoanAccountInfo;
|
|
52
43
|
//# sourceMappingURL=loan.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loan.js","sourceRoot":"","sources":["../../src/accountInfos/loan.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"loan.js","sourceRoot":"","sources":["../../src/accountInfos/loan.ts"],"names":[],"mappings":";;;AAAA,uDAAmG;AACnG,yCAA2C;AAC3C,oDAAsE;AACtE,uCAAyC;AAElC,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,MAAM,GAAG,GAAG,MAAM,IAAA,iCAAmB,EAAC,UAAU,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,MAAM,SAAS,GAAgB,EAAE,CAAC;IAElC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;IACrC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE;QAC3B,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,IAAA,sBAAY,EAAC,IAAI,CAAC,GAAG,CAAC;YACtC,eAAe,EAAE,CAAC,IAAA,sBAAY,EAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG;YACpD,SAAS,EAAE,IAAA,sBAAY,EAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG;SAC9C,CAAC,CAAC;KACJ;IACD,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,EAAE,CAAC;IACjD,KAAK,MAAM,UAAU,IAAI,cAAc,EAAE;QACvC,SAAS,CAAC,IAAI,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
|
-
|
|
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":"
|
|
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,yCAA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AAE,CAAC,CAAC,CAAC,MAAM,CAAC;gBACrE,SAAS,CAAC,IAAI,CAAC;oBACb,WAAW,EAAE,IAAA,kBAAU,EAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;oBACzD,aAAa,EAAE,KAAK;oBACpB,UAAU,EAAE,IAAA,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,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
|
|
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":"
|
|
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) =>
|
|
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
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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":";;;
|
|
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,aAAM,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACvB,IAAA,YAAK,EAAC,EAAE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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"]}
|
package/lib/strategy-account.js
CHANGED
|
@@ -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();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy-account.js","sourceRoot":"","sources":["../src/strategy-account.ts"],"names":[],"mappings":";;AAAA,uDAAmF;AACnF,+CAA4C;AAC5C,+BAA6B;AAC7B,iDAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"strategy-account.js","sourceRoot":"","sources":["../src/strategy-account.ts"],"names":[],"mappings":";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AAC;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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-okx",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.6",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -8,20 +8,20 @@
|
|
|
8
8
|
"temp"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@yuants/protocol": "0.52.
|
|
12
|
-
"@yuants/transfer": "0.2.
|
|
13
|
-
"@yuants/data-account": "0.
|
|
14
|
-
"@yuants/data-order": "0.6.
|
|
15
|
-
"@yuants/utils": "0.
|
|
16
|
-
"@yuants/cache": "0.3.
|
|
17
|
-
"@yuants/sql": "0.9.
|
|
18
|
-
"@yuants/secret": "0.3.
|
|
19
|
-
"@yuants/data-series": "0.3.
|
|
20
|
-
"@yuants/data-product": "0.4.
|
|
21
|
-
"@yuants/data-ohlc": "0.4.
|
|
22
|
-
"@yuants/data-interest-rate": "0.1.
|
|
23
|
-
"@yuants/data-quote": "0.2.
|
|
24
|
-
"@yuants/data-trade": "0.1.
|
|
11
|
+
"@yuants/protocol": "0.52.1",
|
|
12
|
+
"@yuants/transfer": "0.2.36",
|
|
13
|
+
"@yuants/data-account": "0.8.1",
|
|
14
|
+
"@yuants/data-order": "0.6.3",
|
|
15
|
+
"@yuants/utils": "0.12.0",
|
|
16
|
+
"@yuants/cache": "0.3.1",
|
|
17
|
+
"@yuants/sql": "0.9.27",
|
|
18
|
+
"@yuants/secret": "0.3.10",
|
|
19
|
+
"@yuants/data-series": "0.3.48",
|
|
20
|
+
"@yuants/data-product": "0.4.18",
|
|
21
|
+
"@yuants/data-ohlc": "0.4.19",
|
|
22
|
+
"@yuants/data-interest-rate": "0.1.45",
|
|
23
|
+
"@yuants/data-quote": "0.2.40",
|
|
24
|
+
"@yuants/data-trade": "0.1.18",
|
|
25
25
|
"rxjs": "~7.5.6",
|
|
26
26
|
"crypto-js": "^4.2.0",
|
|
27
27
|
"ws": "~8.8.1"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@rushstack/heft-node-rig": "~1.10.7",
|
|
34
34
|
"@types/heft-jest": "1.0.3",
|
|
35
35
|
"@types/node": "22",
|
|
36
|
-
"@yuants/extension": "0.2.
|
|
36
|
+
"@yuants/extension": "0.2.29",
|
|
37
37
|
"@yuants/tool-kit": "0.2.1",
|
|
38
38
|
"typescript": "~4.7.4",
|
|
39
39
|
"ts-node": "~10.9.2",
|