@yuants/vendor-aster 0.5.8 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/private-api.js +69 -0
- package/dist/api/private-api.js.map +1 -0
- package/dist/api/public-api.js +44 -0
- package/dist/api/public-api.js.map +1 -0
- package/dist/index.js +6 -8
- package/dist/index.js.map +1 -1
- package/dist/services/account-actions-with-credential.js +34 -0
- package/dist/services/account-actions-with-credential.js.map +1 -0
- package/dist/{account.js → services/accounts/perp.js} +5 -9
- package/dist/services/accounts/perp.js.map +1 -0
- package/dist/{account-spot.js → services/accounts/spot.js} +8 -9
- package/dist/services/accounts/spot.js.map +1 -0
- package/dist/services/legacy.js +69 -0
- package/dist/services/legacy.js.map +1 -0
- package/dist/{interest_rate.js → services/markets/interest_rate.js} +1 -1
- package/dist/services/markets/interest_rate.js.map +1 -0
- package/dist/{product.js → services/markets/product.js} +1 -1
- package/dist/services/markets/product.js.map +1 -0
- package/dist/{quote.js → services/markets/quote.js} +1 -1
- package/dist/services/markets/quote.js.map +1 -0
- package/dist/services/order-actions-with-credential.js +19 -0
- package/dist/services/order-actions-with-credential.js.map +1 -0
- package/dist/services/orders/cancelOrder.js +40 -0
- package/dist/services/orders/cancelOrder.js.map +1 -0
- package/dist/services/orders/listOrders.js +67 -0
- package/dist/services/orders/listOrders.js.map +1 -0
- package/dist/services/orders/submitOrder.js +101 -0
- package/dist/services/orders/submitOrder.js.map +1 -0
- package/dist/utils.js +1 -20
- package/dist/utils.js.map +1 -1
- package/lib/api/private-api.d.ts +192 -0
- package/lib/api/private-api.d.ts.map +1 -0
- package/lib/api/private-api.js +72 -0
- package/lib/api/private-api.js.map +1 -0
- package/lib/api/public-api.d.ts +59 -0
- package/lib/api/public-api.d.ts.map +1 -0
- package/lib/api/public-api.js +47 -0
- package/lib/api/public-api.js.map +1 -0
- package/lib/index.d.ts +6 -8
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -8
- package/lib/index.js.map +1 -1
- package/lib/services/account-actions-with-credential.d.ts +2 -0
- package/lib/services/account-actions-with-credential.d.ts.map +1 -0
- package/lib/services/account-actions-with-credential.js +36 -0
- package/lib/services/account-actions-with-credential.js.map +1 -0
- package/lib/services/accounts/perp.d.ts +4 -0
- package/lib/services/accounts/perp.d.ts.map +1 -0
- package/lib/{account.js → services/accounts/perp.js} +7 -10
- package/lib/services/accounts/perp.js.map +1 -0
- package/lib/services/accounts/spot.d.ts +4 -0
- package/lib/services/accounts/spot.d.ts.map +1 -0
- package/lib/{account-spot.js → services/accounts/spot.js} +10 -10
- package/lib/services/accounts/spot.js.map +1 -0
- package/lib/services/legacy.d.ts +2 -0
- package/lib/services/legacy.d.ts.map +1 -0
- package/lib/services/legacy.js +71 -0
- package/lib/services/legacy.js.map +1 -0
- package/lib/services/markets/interest_rate.d.ts.map +1 -0
- package/lib/{interest_rate.js → services/markets/interest_rate.js} +2 -2
- package/lib/services/markets/interest_rate.js.map +1 -0
- package/lib/services/markets/product.d.ts.map +1 -0
- package/lib/{product.js → services/markets/product.js} +2 -2
- package/lib/services/markets/product.js.map +1 -0
- package/lib/{quote.d.ts.map → services/markets/quote.d.ts.map} +1 -1
- package/lib/{quote.js → services/markets/quote.js} +3 -3
- package/lib/services/markets/quote.js.map +1 -0
- package/lib/services/order-actions-with-credential.d.ts +2 -0
- package/lib/services/order-actions-with-credential.d.ts.map +1 -0
- package/lib/services/order-actions-with-credential.js +21 -0
- package/lib/services/order-actions-with-credential.js.map +1 -0
- package/lib/services/orders/cancelOrder.d.ts +4 -0
- package/lib/services/orders/cancelOrder.d.ts.map +1 -0
- package/lib/services/orders/cancelOrder.js +44 -0
- package/lib/services/orders/cancelOrder.js.map +1 -0
- package/lib/services/orders/listOrders.d.ts +4 -0
- package/lib/services/orders/listOrders.d.ts.map +1 -0
- package/lib/services/orders/listOrders.js +71 -0
- package/lib/services/orders/listOrders.js.map +1 -0
- package/lib/services/orders/submitOrder.d.ts +4 -0
- package/lib/services/orders/submitOrder.d.ts.map +1 -0
- package/lib/services/orders/submitOrder.js +105 -0
- package/lib/services/orders/submitOrder.js.map +1 -0
- package/lib/utils.d.ts +1 -2
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +3 -23
- package/lib/utils.js.map +1 -1
- package/package.json +3 -4
- package/temp/package-deps.json +22 -18
- package/dist/account-spot.js.map +0 -1
- package/dist/account.js.map +0 -1
- package/dist/api.js +0 -55
- package/dist/api.js.map +0 -1
- package/dist/cli.js +0 -3
- package/dist/cli.js.map +0 -1
- package/dist/interest_rate.js.map +0 -1
- package/dist/order-spot.js +0 -38
- package/dist/order-spot.js.map +0 -1
- package/dist/order.js +0 -70
- package/dist/order.js.map +0 -1
- package/dist/pending-orders.js +0 -43
- package/dist/pending-orders.js.map +0 -1
- package/dist/product.js.map +0 -1
- package/dist/quote.js.map +0 -1
- package/dist/sapi.js +0 -48
- package/dist/sapi.js.map +0 -1
- package/lib/account-spot.d.ts +0 -2
- package/lib/account-spot.d.ts.map +0 -1
- package/lib/account-spot.js.map +0 -1
- package/lib/account.d.ts +0 -2
- package/lib/account.d.ts.map +0 -1
- package/lib/account.js.map +0 -1
- package/lib/api.d.ts +0 -149
- package/lib/api.d.ts.map +0 -1
- package/lib/api.js +0 -58
- package/lib/api.js.map +0 -1
- package/lib/cli.d.ts +0 -3
- package/lib/cli.d.ts.map +0 -1
- package/lib/cli.js +0 -5
- package/lib/cli.js.map +0 -1
- package/lib/interest_rate.d.ts.map +0 -1
- package/lib/interest_rate.js.map +0 -1
- package/lib/order-spot.d.ts +0 -2
- package/lib/order-spot.d.ts.map +0 -1
- package/lib/order-spot.js +0 -40
- package/lib/order-spot.js.map +0 -1
- package/lib/order.d.ts +0 -2
- package/lib/order.d.ts.map +0 -1
- package/lib/order.js +0 -72
- package/lib/order.js.map +0 -1
- package/lib/pending-orders.d.ts +0 -2
- package/lib/pending-orders.d.ts.map +0 -1
- package/lib/pending-orders.js +0 -45
- package/lib/pending-orders.js.map +0 -1
- package/lib/product.d.ts.map +0 -1
- package/lib/product.js.map +0 -1
- package/lib/quote.js.map +0 -1
- package/lib/sapi.d.ts +0 -37
- package/lib/sapi.d.ts.map +0 -1
- package/lib/sapi.js +0 -51
- package/lib/sapi.js.map +0 -1
- /package/lib/{interest_rate.d.ts → services/markets/interest_rate.d.ts} +0 -0
- /package/lib/{product.d.ts → services/markets/product.d.ts} +0 -0
- /package/lib/{quote.d.ts → services/markets/quote.d.ts} +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const data_account_1 = require("@yuants/data-account");
|
|
4
|
+
const protocol_1 = require("@yuants/protocol");
|
|
5
|
+
const perp_1 = require("./accounts/perp");
|
|
6
|
+
const spot_1 = require("./accounts/spot");
|
|
7
|
+
(0, data_account_1.provideAccountActionsWithCredential)(protocol_1.Terminal.fromNodeEnv(), 'ASTER', {
|
|
8
|
+
type: 'object',
|
|
9
|
+
required: ['address', 'api_key', 'secret_key'],
|
|
10
|
+
properties: {
|
|
11
|
+
address: { type: 'string' },
|
|
12
|
+
api_key: { type: 'string' },
|
|
13
|
+
secret_key: { type: 'string' },
|
|
14
|
+
},
|
|
15
|
+
}, {
|
|
16
|
+
listAccounts: async (credential) => {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
account_id: `ASTER/${credential.address}/PERP`,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
account_id: `ASTER/${credential.address}/SPOT`,
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
},
|
|
26
|
+
getAccountInfo: async (credential, account_id) => {
|
|
27
|
+
if (account_id.endsWith('/PERP')) {
|
|
28
|
+
return (0, perp_1.getPerpAccountInfo)(credential, account_id);
|
|
29
|
+
}
|
|
30
|
+
if (account_id.endsWith('/SPOT')) {
|
|
31
|
+
return (0, spot_1.getSpotAccountInfo)(credential, account_id);
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`Unsupported account type for account_id: ${account_id}`);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=account-actions-with-credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-actions-with-credential.js","sourceRoot":"","sources":["../../src/services/account-actions-with-credential.ts"],"names":[],"mappings":";;AAAA,uDAA2E;AAC3E,+CAA4C;AAE5C,0CAAqD;AACrD,0CAAqD;AAErD,IAAA,kDAAmC,EACjC,mBAAQ,CAAC,WAAW,EAAE,EACtB,OAAO,EACP;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC;IAC9C,UAAU,EAAE;QACV,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC/B;CACF,EACD;IACE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;QACjC,OAAO;YACL;gBACE,UAAU,EAAE,SAAS,UAAU,CAAC,OAAO,OAAO;aAC/C;YACD;gBACE,UAAU,EAAE,SAAS,UAAU,CAAC,OAAO,OAAO;aAC/C;SACF,CAAC;IACJ,CAAC;IACD,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE;QAC/C,IAAI,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAChC,OAAO,IAAA,yBAAkB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SACnD;QACD,IAAI,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAChC,OAAO,IAAA,yBAAkB,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SACnD;QACD,MAAM,IAAI,KAAK,CAAC,4CAA4C,UAAU,EAAE,CAAC,CAAC;IAC5E,CAAC;CACF,CACF,CAAC","sourcesContent":["import { provideAccountActionsWithCredential } from '@yuants/data-account';\nimport { Terminal } from '@yuants/protocol';\nimport { ICredential } from '../api/private-api';\nimport { getPerpAccountInfo } from './accounts/perp';\nimport { getSpotAccountInfo } from './accounts/spot';\n\nprovideAccountActionsWithCredential<ICredential>(\n Terminal.fromNodeEnv(),\n 'ASTER',\n {\n type: 'object',\n required: ['address', 'api_key', 'secret_key'],\n properties: {\n address: { type: 'string' },\n api_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n {\n listAccounts: async (credential) => {\n return [\n {\n account_id: `ASTER/${credential.address}/PERP`,\n },\n {\n account_id: `ASTER/${credential.address}/SPOT`,\n },\n ];\n },\n getAccountInfo: async (credential, account_id) => {\n if (account_id.endsWith('/PERP')) {\n return getPerpAccountInfo(credential, account_id);\n }\n if (account_id.endsWith('/SPOT')) {\n return getSpotAccountInfo(credential, account_id);\n }\n throw new Error(`Unsupported account type for account_id: ${account_id}`);\n },\n },\n);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perp.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AAEjF,OAAO,EAAoB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEtE,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CA8B1E,CAAC"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const data_account_1 = require("@yuants/data-account");
|
|
5
|
-
const protocol_1 = require("@yuants/protocol");
|
|
3
|
+
exports.getPerpAccountInfo = void 0;
|
|
6
4
|
const utils_1 = require("@yuants/utils");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
(0, data_account_1.provideAccountInfoService)(protocol_1.Terminal.fromNodeEnv(), exports.ACCOUNT_ID, async () => {
|
|
11
|
-
const [a] = await Promise.all([(0, api_1.getFApiV4Account)({})]);
|
|
5
|
+
const private_api_1 = require("../../api/private-api");
|
|
6
|
+
const getPerpAccountInfo = async (credential) => {
|
|
7
|
+
const [a] = await Promise.all([(0, private_api_1.getFApiV4Account)(credential, {})]);
|
|
12
8
|
const equity = +a.totalWalletBalance + +a.totalUnrealizedProfit;
|
|
13
9
|
const free = +a.availableBalance;
|
|
14
10
|
const positions = a.positions
|
|
@@ -33,5 +29,6 @@ exports.ACCOUNT_ID = `ASTER/${ADDRESS}`;
|
|
|
33
29
|
},
|
|
34
30
|
positions,
|
|
35
31
|
};
|
|
36
|
-
}
|
|
37
|
-
|
|
32
|
+
};
|
|
33
|
+
exports.getPerpAccountInfo = getPerpAccountInfo;
|
|
34
|
+
//# sourceMappingURL=perp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perp.js","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,uDAAsE;AAE/D,MAAM,kBAAkB,GAAgD,KAAK,EAAE,UAAU,EAAE,EAAE;IAClG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAA,8BAAgB,EAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAElE,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC,qBAAqB,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAEjC,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS;SAC1B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC;SACnC,GAAG,CACF,CAAC,CAAC,EAAa,EAAE,CAAC,CAAC;QACjB,WAAW,EAAE,CAAC,CAAC,MAAM;QACrB,UAAU,EAAE,IAAA,kBAAU,EAAC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QAC7C,aAAa,EAAE,OAAO;QACtB,SAAS,EAAE,CAAC,CAAC,YAAY,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;QAC/F,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QACrC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;QAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;QACtD,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB;QACpC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;KACjC,CAAC,CACH,CAAC;IACJ,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,KAAK;YACf,MAAM;YACN,IAAI;SACL;QACD,SAAS;KACV,CAAC;AACJ,CAAC,CAAC;AA9BW,QAAA,kBAAkB,sBA8B7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFApiV4Account, ICredential } from '../../api/private-api';\n\nexport const getPerpAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (credential) => {\n const [a] = await Promise.all([getFApiV4Account(credential, {})]);\n\n const equity = +a.totalWalletBalance + +a.totalUnrealizedProfit;\n const free = +a.availableBalance;\n\n const positions = a.positions\n .filter((p) => +p.positionAmt !== 0)\n .map(\n (p): IPosition => ({\n position_id: p.symbol,\n product_id: encodePath('PERPETUAL', p.symbol),\n datasource_id: 'ASTER',\n direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,\n volume: Math.abs(+p.positionAmt),\n free_volume: Math.abs(+p.positionAmt),\n position_price: +p.entryPrice,\n closable_price: Math.abs(+p.notional / +p.positionAmt),\n floating_profit: +p.unrealizedProfit,\n valuation: Math.abs(+p.notional),\n }),\n );\n return {\n money: {\n currency: 'USD',\n equity,\n free,\n },\n positions,\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAa,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAwC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE1F,eAAO,MAAM,kBAAkB,EAAE,8BAA8B,CAAC,WAAW,CA6C1E,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const [x, prices] = await Promise.all([(0, sapi_1.getApiV1Account)({}), (0, sapi_1.getApiV1TickerPrice)({})]);
|
|
3
|
+
exports.getSpotAccountInfo = void 0;
|
|
4
|
+
const private_api_1 = require("../../api/private-api");
|
|
5
|
+
const getSpotAccountInfo = async (credential, account_id) => {
|
|
6
|
+
const [x, prices] = await Promise.all([
|
|
7
|
+
(0, private_api_1.getApiV1Account)(credential, {}),
|
|
8
|
+
(0, private_api_1.getApiV1TickerPrice)(credential, {}),
|
|
9
|
+
]);
|
|
11
10
|
const positions = x.balances.map((b) => {
|
|
12
11
|
var _a, _b;
|
|
13
12
|
const thePrice = b.asset === 'USDT' ? 1 : (_b = (_a = prices.find((p) => p.symbol === b.asset + 'USDT')) === null || _a === void 0 ? void 0 : _a.price) !== null && _b !== void 0 ? _b : 0;
|
|
@@ -40,5 +39,6 @@ exports.SPOT_ACCOUNT_ID = `ASTER/${ADDRESS}/SPOT`;
|
|
|
40
39
|
},
|
|
41
40
|
positions,
|
|
42
41
|
};
|
|
43
|
-
}
|
|
44
|
-
|
|
42
|
+
};
|
|
43
|
+
exports.getSpotAccountInfo = getSpotAccountInfo;
|
|
44
|
+
//# sourceMappingURL=spot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AACA,uDAA0F;AAEnF,MAAM,kBAAkB,GAAgD,KAAK,EAClF,UAAU,EACV,UAAU,EACV,EAAE;IACF,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACpC,IAAA,6BAAe,EAAC,UAAU,EAAE,EAAE,CAAC;QAC/B,IAAA,iCAAmB,EAAC,UAAU,EAAE,EAAE,CAAC;KACpC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAa,EAAE;;QAChD,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAA,MAAA,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,0CAAE,KAAK,mCAAI,CAAC,CAAC;QAExG,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;QAEnC,MAAM,cAAc,GAAG,CAAC,QAAQ,CAAC;QACjC,MAAM,cAAc,GAAG,CAAC,QAAQ,CAAC;QACjC,MAAM,SAAS,GAAG,MAAM,GAAG,cAAc,CAAC;QAC1C,MAAM,eAAe,GAAG,CAAC,CAAC;QAE1B,OAAO;YACL,WAAW,EAAE,CAAC,CAAC,KAAK;YACpB,aAAa,EAAE,OAAO;YACtB,UAAU,EAAE,CAAC,CAAC,KAAK;YACnB,SAAS,EAAE,MAAM;YACjB,MAAM;YACN,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;YACpB,cAAc;YACd,cAAc;YACd,eAAe;YACf,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7C,OAAO;QACL,KAAK,EAAE;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM;YACN,IAAI;SACL;QACD,SAAS;KACV,CAAC;AACJ,CAAC,CAAC;AA7CW,QAAA,kBAAkB,sBA6C7B","sourcesContent":["import { IActionHandlerOfGetAccountInfo, IPosition } from '@yuants/data-account';\nimport { getApiV1Account, getApiV1TickerPrice, ICredential } from '../../api/private-api';\n\nexport const getSpotAccountInfo: IActionHandlerOfGetAccountInfo<ICredential> = async (\n credential,\n account_id,\n) => {\n const [x, prices] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n ]);\n\n const positions = x.balances.map((b): IPosition => {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n\n const volume = +b.free + +b.locked;\n\n const position_price = +thePrice;\n const closable_price = +thePrice;\n const valuation = volume * closable_price;\n const floating_profit = 0;\n\n return {\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: b.asset,\n direction: 'LONG',\n volume,\n free_volume: +b.free,\n position_price,\n closable_price,\n floating_profit,\n valuation,\n };\n });\n\n const usdtAsset = x.balances.find((b) => b.asset === 'USDT');\n const equity = positions.reduce((a, b) => a + b.valuation, 0);\n const free = usdtAsset ? +usdtAsset.free : 0;\n\n return {\n money: {\n currency: 'USDT',\n equity,\n free,\n },\n positions,\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../src/services/legacy.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const data_account_1 = require("@yuants/data-account");
|
|
4
|
+
const data_order_1 = require("@yuants/data-order");
|
|
5
|
+
const protocol_1 = require("@yuants/protocol");
|
|
6
|
+
const perp_1 = require("../services/accounts/perp");
|
|
7
|
+
const spot_1 = require("../services/accounts/spot");
|
|
8
|
+
const cancelOrder_1 = require("../services/orders/cancelOrder");
|
|
9
|
+
const submitOrder_1 = require("../services/orders/submitOrder");
|
|
10
|
+
const listOrders_1 = require("./orders/listOrders");
|
|
11
|
+
const getDefaultCredential = () => {
|
|
12
|
+
return {
|
|
13
|
+
address: process.env.API_ADDRESS || '',
|
|
14
|
+
api_key: process.env.API_KEY || '',
|
|
15
|
+
secret_key: process.env.SECRET_KEY || '',
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const ADDRESS = process.env.ADDRESS;
|
|
19
|
+
const credential = getDefaultCredential();
|
|
20
|
+
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
21
|
+
const SPOT_ACCOUNT_ID = `ASTER/${ADDRESS}/SPOT`;
|
|
22
|
+
const PERP_ACCOUNT_ID = `ASTER/${ADDRESS}`;
|
|
23
|
+
(0, data_account_1.provideAccountInfoService)(protocol_1.Terminal.fromNodeEnv(), SPOT_ACCOUNT_ID, async () => (0, spot_1.getSpotAccountInfo)(credential, SPOT_ACCOUNT_ID), { auto_refresh_interval: 1000 });
|
|
24
|
+
(0, data_account_1.provideAccountInfoService)(protocol_1.Terminal.fromNodeEnv(), PERP_ACCOUNT_ID, async () => (0, perp_1.getPerpAccountInfo)(credential, PERP_ACCOUNT_ID), { auto_refresh_interval: 1000 });
|
|
25
|
+
(0, data_order_1.providePendingOrdersService)(terminal, SPOT_ACCOUNT_ID, async () => (0, listOrders_1.listOrders)(credential, SPOT_ACCOUNT_ID), {
|
|
26
|
+
auto_refresh_interval: 1000,
|
|
27
|
+
});
|
|
28
|
+
(0, data_order_1.providePendingOrdersService)(terminal, PERP_ACCOUNT_ID, async () => (0, listOrders_1.listOrders)(credential, PERP_ACCOUNT_ID), {
|
|
29
|
+
auto_refresh_interval: 2000,
|
|
30
|
+
});
|
|
31
|
+
protocol_1.Terminal.fromNodeEnv().server.provideService('CancelOrder', {
|
|
32
|
+
required: ['account_id', 'order_id', 'product_id'],
|
|
33
|
+
properties: {
|
|
34
|
+
account_id: { type: 'string', const: SPOT_ACCOUNT_ID },
|
|
35
|
+
order_id: { type: ['string', 'number'] },
|
|
36
|
+
product_id: { type: 'string' },
|
|
37
|
+
},
|
|
38
|
+
}, async (msg) => {
|
|
39
|
+
const order = msg.req;
|
|
40
|
+
await (0, cancelOrder_1.handleCancelOrder)(credential, order);
|
|
41
|
+
return { res: { code: 0, message: 'OK' } };
|
|
42
|
+
});
|
|
43
|
+
protocol_1.Terminal.fromNodeEnv().server.provideService('SubmitOrder', { required: ['account_id'], properties: { account_id: { type: 'string', const: SPOT_ACCOUNT_ID } } }, async (msg) => {
|
|
44
|
+
const order = msg.req;
|
|
45
|
+
const data = await (0, submitOrder_1.handleSubmitOrder)(credential, order);
|
|
46
|
+
return { res: { code: 0, message: 'OK', data } };
|
|
47
|
+
});
|
|
48
|
+
terminal.server.provideService('SubmitOrder', { required: ['account_id'], properties: { account_id: { type: 'string', const: PERP_ACCOUNT_ID } } }, async (msg) => {
|
|
49
|
+
const order = msg.req;
|
|
50
|
+
const data = await (0, submitOrder_1.handleSubmitOrder)(credential, order);
|
|
51
|
+
return {
|
|
52
|
+
res: {
|
|
53
|
+
code: 0,
|
|
54
|
+
message: 'OK',
|
|
55
|
+
data,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
terminal.server.provideService('CancelOrder', {
|
|
60
|
+
required: ['account_id', 'order_id', 'product_id'],
|
|
61
|
+
properties: {
|
|
62
|
+
account_id: { type: 'string', const: PERP_ACCOUNT_ID },
|
|
63
|
+
order_id: { type: ['string', 'number'] },
|
|
64
|
+
product_id: { type: 'string' },
|
|
65
|
+
},
|
|
66
|
+
}, async (msg) => {
|
|
67
|
+
const order = msg.req;
|
|
68
|
+
await (0, cancelOrder_1.handleCancelOrder)(credential, order);
|
|
69
|
+
return { res: { code: 0, message: 'OK' } };
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=legacy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../src/services/legacy.ts"],"names":[],"mappings":";;AAAA,uDAAiE;AACjE,mDAAyE;AACzE,+CAA4C;AAE5C,oDAA+D;AAC/D,oDAA+D;AAC/D,gEAAmE;AACnE,gEAAmE;AACnE,oDAAiD;AAEjD,MAAM,oBAAoB,GAAG,GAAgB,EAAE;IAC7C,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE;QACtC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE;QAClC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE;KACzC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,OAAO,GAA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AAC;IAExD,OAAO;QACL,GAAG,EAAE;YACH,IAAI,EAAE,CAAC;YACP,OAAO,EAAE,IAAI;YACb,IAAI;SACL;KACF,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,aAAa,EACb;IACE,QAAQ,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,YAAY,CAAC;IAClD,UAAU,EAAE;QACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE;QACtD,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE;QACxC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC/B;CACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;IACZ,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;IAEtB,MAAM,IAAA,+BAAiB,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAE3C,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;AAC7C,CAAC,CACF,CAAC","sourcesContent":["import { provideAccountInfoService } from '@yuants/data-account';\nimport { IOrder, providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { ICredential } from '../api/private-api';\nimport { getPerpAccountInfo } from '../services/accounts/perp';\nimport { getSpotAccountInfo } from '../services/accounts/spot';\nimport { handleCancelOrder } from '../services/orders/cancelOrder';\nimport { handleSubmitOrder } from '../services/orders/submitOrder';\nimport { listOrders } from './orders/listOrders';\n\nconst getDefaultCredential = (): ICredential => {\n return {\n address: process.env.API_ADDRESS || '',\n api_key: process.env.API_KEY || '',\n secret_key: process.env.SECRET_KEY || '',\n };\n};\n\nconst ADDRESS = process.env.ADDRESS!;\nconst credential = getDefaultCredential();\nconst terminal = Terminal.fromNodeEnv();\n\nconst SPOT_ACCOUNT_ID = `ASTER/${ADDRESS}/SPOT`;\nconst PERP_ACCOUNT_ID = `ASTER/${ADDRESS}`;\n\nprovideAccountInfoService(\n Terminal.fromNodeEnv(),\n SPOT_ACCOUNT_ID,\n async () => getSpotAccountInfo(credential, SPOT_ACCOUNT_ID),\n { auto_refresh_interval: 1000 },\n);\n\nprovideAccountInfoService(\n Terminal.fromNodeEnv(),\n PERP_ACCOUNT_ID,\n async () => getPerpAccountInfo(credential, PERP_ACCOUNT_ID),\n { auto_refresh_interval: 1000 },\n);\n\nprovidePendingOrdersService(terminal, SPOT_ACCOUNT_ID, async () => listOrders(credential, SPOT_ACCOUNT_ID), {\n auto_refresh_interval: 1000,\n});\n\nprovidePendingOrdersService(terminal, PERP_ACCOUNT_ID, async () => listOrders(credential, PERP_ACCOUNT_ID), {\n auto_refresh_interval: 2000,\n});\n\nTerminal.fromNodeEnv().server.provideService<IOrder>(\n 'CancelOrder',\n {\n required: ['account_id', 'order_id', 'product_id'],\n properties: {\n account_id: { type: 'string', const: SPOT_ACCOUNT_ID },\n order_id: { type: ['string', 'number'] },\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n const order = msg.req;\n\n await handleCancelOrder(credential, order);\n\n return { res: { code: 0, message: 'OK' } };\n },\n);\n\nTerminal.fromNodeEnv().server.provideService<IOrder, { order_id: string }>(\n 'SubmitOrder',\n { required: ['account_id'], properties: { account_id: { type: 'string', const: SPOT_ACCOUNT_ID } } },\n async (msg) => {\n const order = msg.req;\n\n const data = await handleSubmitOrder(credential, order);\n\n return { res: { code: 0, message: 'OK', data } };\n },\n);\n\nterminal.server.provideService<IOrder, { order_id?: string }>(\n 'SubmitOrder',\n { required: ['account_id'], properties: { account_id: { type: 'string', const: PERP_ACCOUNT_ID } } },\n async (msg) => {\n const order = msg.req;\n const data = await handleSubmitOrder(credential, order);\n\n return {\n res: {\n code: 0,\n message: 'OK',\n data,\n },\n };\n },\n);\n\nterminal.server.provideService<IOrder>(\n 'CancelOrder',\n {\n required: ['account_id', 'order_id', 'product_id'],\n properties: {\n account_id: { type: 'string', const: PERP_ACCOUNT_ID },\n order_id: { type: ['string', 'number'] },\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n const order = msg.req;\n\n await handleCancelOrder(credential, order);\n\n return { res: { code: 0, message: 'OK' } };\n },\n);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest_rate.d.ts","sourceRoot":"","sources":["../../../src/services/markets/interest_rate.ts"],"names":[],"mappings":""}
|
|
@@ -17,7 +17,7 @@ const protocol_1 = require("@yuants/protocol");
|
|
|
17
17
|
const sql_1 = require("@yuants/sql");
|
|
18
18
|
const utils_1 = require("@yuants/utils");
|
|
19
19
|
const rxjs_1 = require("rxjs");
|
|
20
|
-
const
|
|
20
|
+
const public_api_1 = require("../../api/public-api");
|
|
21
21
|
const product_1 = require("./product");
|
|
22
22
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
23
23
|
(0, sql_1.createSQLWriter)(terminal, {
|
|
@@ -49,7 +49,7 @@ const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
|
49
49
|
}
|
|
50
50
|
let currentStart = start;
|
|
51
51
|
while (currentStart <= end) {
|
|
52
|
-
const res = yield __await((0,
|
|
52
|
+
const res = yield __await((0, public_api_1.getFApiV1FundingRate)({
|
|
53
53
|
symbol: instId,
|
|
54
54
|
startTime: currentStart,
|
|
55
55
|
endTime: end,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../../src/services/markets/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,qDAAkF;AAClF,+CAA4C;AAC5C,qCAA8C;AAC9C,yCAAmE;AACnE,+BAA4D;AAC5D,qDAA4D;AAC5D,uCAA2C;AAE3C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,qBAAe,EAAwB,QAAQ,EAAE;IAC/C,KAAK,EAA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I,EAAE;wBACrB,UAAU,EAAE,GAAG,IAAI,EAAE;wBACrB,gBAAgB,EAAE,EAAE;qBACrB,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,oBAAM,IAAI,CAAA,CAAC;gBAEX,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;gBAC3D,IAAI,QAAQ,IAAI,GAAG,EAAE;oBACnB,MAAM;iBACP;gBAED,YAAY,GAAG,QAAQ,GAAG,CAAC,CAAC;gBAE5B,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE;oBACrB,MAAM;iBACP;gBAED,cAAM,IAAA,qBAAc,EAAC,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC,CAAA,CAAC;aACnC;QACH,CAAC;KAAA;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { IProduct } from '@yuants/data-product';\nimport { createSeriesProvider, ISeriesCollectingTask } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { createSQLWriter } from '@yuants/sql';\nimport { decodePath, encodePath, formatTime } from '@yuants/utils';\nimport { firstValueFrom, map, mergeAll, timer } from 'rxjs';\nimport { getFApiV1FundingRate } from '../../api/public-api';\nimport { productService } from './product';\n\nconst terminal = Terminal.fromNodeEnv();\n\ncreateSQLWriter<ISeriesCollectingTask>(terminal, {\n data$: productService.products$.pipe(\n map((products: IProduct[]) => products.filter((product) => product.no_interest_rate === false)),\n mergeAll(),\n map(\n (product: IProduct): ISeriesCollectingTask => ({\n series_id: encodePath(product.datasource_id, product.product_id),\n table_name: 'interest_rate',\n cron_pattern: '0 * * * *',\n cron_timezone: 'UTC',\n disabled: false,\n replay_count: 0,\n }),\n ),\n ),\n tableName: 'series_collecting_task',\n writeInterval: 1000,\n conflictKeys: ['series_id', 'table_name'],\n});\n\ncreateSeriesProvider<IInterestRate>(terminal, {\n tableName: 'interest_rate',\n series_id_prefix_parts: ['ASTER'],\n reversed: true,\n serviceOptions: { concurrent: 1 },\n queryFn: async function* ({ series_id, started_at, ended_at }) {\n const start = started_at ?? 0;\n const end = ended_at ?? Date.now();\n const [datasource_id, product_id] = decodePath(series_id);\n const [instType, instId] = decodePath(product_id);\n\n if (instType !== 'PERPETUAL') {\n return;\n }\n\n let currentStart = start;\n\n while (currentStart <= end) {\n const res = await getFApiV1FundingRate({\n symbol: instId,\n startTime: currentStart,\n endTime: end,\n limit: 1000,\n });\n\n if (!Array.isArray(res) || res.length === 0) {\n break;\n }\n\n const filtered = res.filter((item) => item.fundingTime >= currentStart && item.fundingTime <= end);\n\n if (filtered.length === 0) {\n const lastRecord = res[res.length - 1];\n const nextStart = lastRecord.fundingTime + 1;\n if (nextStart <= currentStart) {\n break;\n }\n currentStart = nextStart;\n await firstValueFrom(timer(1000));\n continue;\n }\n\n const data = filtered.map((item): IInterestRate => {\n const rate = Number(item.fundingRate);\n return {\n series_id,\n product_id,\n datasource_id,\n created_at: formatTime(item.fundingTime),\n long_rate: `${-rate}`,\n short_rate: `${rate}`,\n settlement_price: '',\n };\n });\n\n yield data;\n\n const lastTime = filtered[filtered.length - 1].fundingTime;\n if (lastTime >= end) {\n break;\n }\n\n currentStart = lastTime + 1;\n\n if (res.length < 1000) {\n break;\n }\n\n await firstValueFrom(timer(1000));\n }\n },\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,sDA4C1B,CAAC"}
|
|
@@ -4,12 +4,12 @@ exports.productService = void 0;
|
|
|
4
4
|
const data_product_1 = require("@yuants/data-product");
|
|
5
5
|
const protocol_1 = require("@yuants/protocol");
|
|
6
6
|
const utils_1 = require("@yuants/utils");
|
|
7
|
-
const
|
|
7
|
+
const public_api_1 = require("../../api/public-api");
|
|
8
8
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
9
9
|
// Provide QueryProducts service for ASTER
|
|
10
10
|
exports.productService = (0, data_product_1.provideQueryProductsService)(terminal, 'ASTER', async (req) => {
|
|
11
11
|
// Fetch exchange info from ASTER API
|
|
12
|
-
const exchangeInfo = await (0,
|
|
12
|
+
const exchangeInfo = await (0, public_api_1.getFApiV1ExchangeInfo)({});
|
|
13
13
|
// Convert symbols to IProduct format
|
|
14
14
|
return exchangeInfo.symbols
|
|
15
15
|
.filter((symbol) => symbol.status === 'TRADING') // Only include active trading symbols
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":";;;AAAA,uDAAoG;AACpG,+CAA4C;AAC5C,yCAA2C;AAC3C,qDAA6D;AAE7D,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,0CAA0C;AAC7B,QAAA,cAAc,GAAG,IAAA,0CAA2B,EACvD,QAAQ,EACR,OAAO,EACP,KAAK,EAAE,GAA0B,EAAuB,EAAE;IACxD,qCAAqC;IACrC,MAAM,YAAY,GAAG,MAAM,IAAA,kCAAqB,EAAC,EAAE,CAAC,CAAC;IAErD,qCAAqC;IACrC,OAAO,YAAY,CAAC,OAAO;SACxB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,sCAAsC;SACtF,GAAG,CAAC,CAAC,MAAM,EAAY,EAAE;QACxB,mCAAmC;QACnC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,KAAK,cAAc,CAAC,CAAC;QAC1F,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QAE7D,uCAAuC;QACvC,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;QACxF,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC;QAEtG,OAAO;YACL,aAAa,EAAE,OAAO;YACtB,UAAU,EAAE,IAAA,kBAAU,EAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC;YAClD,IAAI,EAAE,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,UAAU,OAAO;YACrD,cAAc,EAAE,MAAM,CAAC,UAAU;YACjC,aAAa,EAAE,MAAM,CAAC,SAAS;YAC/B,gBAAgB,EAAE,EAAE;YACpB,gBAAgB,EAAE,CAAC;YACnB,iBAAiB,EAAE,CAAC;YACpB,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,SAAS;YACrB,WAAW,EAAE,UAAU;YACvB,WAAW,EAAE,CAAC;YACd,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,IAAI;YACjB,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE,CAAC;YACf,SAAS,EAAE,iBAAiB;YAC5B,gBAAgB,EAAE,KAAK;SACxB,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC,EACD;IACE,qBAAqB,EAAE,OAAQ,EAAE,iBAAiB;CACnD,CACF,CAAC","sourcesContent":["import { IProduct, IQueryProductsRequest, provideQueryProductsService } from '@yuants/data-product';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { getFApiV1ExchangeInfo } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\n// Provide QueryProducts service for ASTER\nexport const productService = provideQueryProductsService(\n terminal,\n 'ASTER',\n async (req: IQueryProductsRequest): Promise<IProduct[]> => {\n // Fetch exchange info from ASTER API\n const exchangeInfo = await getFApiV1ExchangeInfo({});\n\n // Convert symbols to IProduct format\n return exchangeInfo.symbols\n .filter((symbol) => symbol.status === 'TRADING') // Only include active trading symbols\n .map((symbol): IProduct => {\n // Find price filter for price step\n const priceFilter = symbol.filters.find((filter) => filter.filterType === 'PRICE_FILTER');\n const priceStep = priceFilter ? +priceFilter.tickSize : 1e-2;\n\n // Find lot size filter for volume step\n const lotSizeFilter = symbol.filters.find((filter) => filter.filterType === 'LOT_SIZE');\n const volumeStep = lotSizeFilter ? +lotSizeFilter.stepSize : Number(`1e-${symbol.quantityPrecision}`);\n\n return {\n datasource_id: 'ASTER',\n product_id: encodePath('PERPETUAL', symbol.symbol),\n name: `${symbol.baseAsset}/${symbol.quoteAsset} PERP`,\n quote_currency: symbol.quoteAsset,\n base_currency: symbol.baseAsset,\n value_scale_unit: '',\n value_based_cost: 0,\n volume_based_cost: 0,\n max_volume: 0,\n price_step: priceStep,\n volume_step: volumeStep,\n value_scale: 1,\n allow_long: true,\n allow_short: true,\n margin_rate: 0.1, // Default margin rate, can be adjusted based on actual requirements\n max_position: 0,\n market_id: 'ASTER/PERPETUAL',\n no_interest_rate: false,\n };\n });\n },\n {\n auto_refresh_interval: 3600_000, // Refresh hourly\n },\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"quote.d.ts","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":""}
|
|
@@ -5,12 +5,12 @@ const protocol_1 = require("@yuants/protocol");
|
|
|
5
5
|
const sql_1 = require("@yuants/sql");
|
|
6
6
|
const utils_1 = require("@yuants/utils");
|
|
7
7
|
const rxjs_1 = require("rxjs");
|
|
8
|
-
const
|
|
8
|
+
const public_api_1 = require("../../api/public-api");
|
|
9
9
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
10
10
|
const OPEN_INTEREST_TTL = process.env.OPEN_INTEREST_TTL ? Number(process.env.OPEN_INTEREST_TTL) : 120000;
|
|
11
11
|
const openInterestCache = (0, cache_1.createCache)(async (symbol) => {
|
|
12
12
|
try {
|
|
13
|
-
const data = await (0,
|
|
13
|
+
const data = await (0, public_api_1.getFApiV1OpenInterest)({ symbol });
|
|
14
14
|
return data.openInterest;
|
|
15
15
|
}
|
|
16
16
|
catch (error) {
|
|
@@ -18,7 +18,7 @@ const openInterestCache = (0, cache_1.createCache)(async (symbol) => {
|
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
}, { expire: OPEN_INTEREST_TTL });
|
|
21
|
-
const quote$ = (0, rxjs_1.defer)(() => (0,
|
|
21
|
+
const quote$ = (0, rxjs_1.defer)(() => (0, public_api_1.getFApiV1TickerPrice)({})).pipe((0, rxjs_1.mergeMap)((tickers) => tickers || []), (0, rxjs_1.mergeMap)((ticker) => (0, rxjs_1.from)(openInterestCache.query(ticker.symbol)).pipe((0, rxjs_1.map)((openInterest) => {
|
|
22
22
|
var _a;
|
|
23
23
|
return ({
|
|
24
24
|
datasource_id: 'ASTER',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../src/services/markets/quote.ts"],"names":[],"mappings":";;AAAA,yCAA4C;AAE5C,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAAsF;AACtF,qDAAmF;AAEnF,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AACxC,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAO,CAAC;AAE1G,MAAM,iBAAiB,GAAG,IAAA,mBAAW,EACnC,KAAK,EAAE,MAAc,EAAE,EAAE;IACvB,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,IAAA,kCAAqB,EAAC,EAAE,MAAM,EAAE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IAAI,EAAE,CAAC,EACtB,IAAA,kBAAW,EAAC,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAC/C,CAAC;AAEF,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,EAAE;IAC7C,MAAM;SACH,IAAI,CACH,IAAA,gBAAU,EAAC;QACT,QAAQ;QACR,SAAS,EAAE,OAAO;QAClB,aAAa,EAAE,IAAI;QACnB,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC;KAC9C,CAAC,CACH;SACA,SAAS,EAAE,CAAC;IAEf,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,EAAE;QAC9E,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,uBAAuB,UAAU,EAAE,CAAC,CAAC;SACtD;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAA,aAAM,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;CACJ","sourcesContent":["import { createCache } from '@yuants/cache';\nimport type { IQuote } from '@yuants/data-quote';\nimport { Terminal } from '@yuants/protocol';\nimport { writeToSQL } from '@yuants/sql';\nimport { decodePath, encodePath } from '@yuants/utils';\nimport { defer, filter, from, map, mergeMap, repeat, retry, shareReplay } from 'rxjs';\nimport { getFApiV1OpenInterest, getFApiV1TickerPrice } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\nconst OPEN_INTEREST_TTL = process.env.OPEN_INTEREST_TTL ? Number(process.env.OPEN_INTEREST_TTL) : 120_000;\n\nconst openInterestCache = createCache<string>(\n async (symbol: string) => {\n try {\n const data = await getFApiV1OpenInterest({ symbol });\n return data.openInterest;\n } catch (error) {\n console.warn('getFApiV1OpenInterest failed', symbol, error);\n return undefined;\n }\n },\n { expire: OPEN_INTEREST_TTL },\n);\n\nconst quote$ = defer(() => getFApiV1TickerPrice({})).pipe(\n mergeMap((tickers) => tickers || []),\n mergeMap(\n (ticker) =>\n from(openInterestCache.query(ticker.symbol)).pipe(\n map(\n (openInterest): Partial<IQuote> => ({\n datasource_id: 'ASTER',\n product_id: encodePath('PERPETUAL', ticker.symbol),\n last_price: `${ticker.price}`,\n bid_price: `${ticker.price}`,\n ask_price: `${ticker.price}`,\n open_interest: `${openInterest ?? 0}`,\n updated_at: new Date(ticker.time ?? Date.now()).toISOString(),\n }),\n ),\n ),\n 5,\n ),\n repeat({ delay: 1000 }),\n retry({ delay: 5000 }),\n shareReplay({ bufferSize: 1, refCount: true }),\n);\n\nif (process.env.WRITE_QUOTE_TO_SQL === 'true') {\n quote$\n .pipe(\n writeToSQL({\n terminal,\n tableName: 'quote',\n writeInterval: 1000,\n conflictKeys: ['datasource_id', 'product_id'],\n }),\n )\n .subscribe();\n\n terminal.channel.publishChannel('quote', { pattern: '^ASTER/' }, (channel_id) => {\n const [datasourceId, productId] = decodePath(channel_id);\n if (!datasourceId || !productId) {\n throw new Error(`Invalid channel_id: ${channel_id}`);\n }\n return quote$.pipe(filter((quote) => quote.product_id === productId));\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-actions-with-credential.d.ts","sourceRoot":"","sources":["../../src/services/order-actions-with-credential.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const data_order_1 = require("@yuants/data-order");
|
|
4
|
+
const protocol_1 = require("@yuants/protocol");
|
|
5
|
+
const cancelOrder_1 = require("./orders/cancelOrder");
|
|
6
|
+
const submitOrder_1 = require("./orders/submitOrder");
|
|
7
|
+
const listOrders_1 = require("./orders/listOrders");
|
|
8
|
+
(0, data_order_1.provideOrderActionsWithCredential)(protocol_1.Terminal.fromNodeEnv(), 'ASTER', {
|
|
9
|
+
type: 'object',
|
|
10
|
+
required: ['address', 'api_key', 'secret_key'],
|
|
11
|
+
properties: {
|
|
12
|
+
address: { type: 'string' },
|
|
13
|
+
api_key: { type: 'string' },
|
|
14
|
+
secret_key: { type: 'string' },
|
|
15
|
+
},
|
|
16
|
+
}, {
|
|
17
|
+
submitOrder: submitOrder_1.handleSubmitOrder,
|
|
18
|
+
cancelOrder: cancelOrder_1.handleCancelOrder,
|
|
19
|
+
listOrders: listOrders_1.listOrders,
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=order-actions-with-credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-actions-with-credential.js","sourceRoot":"","sources":["../../src/services/order-actions-with-credential.ts"],"names":[],"mappings":";;AAAA,mDAAuE;AACvE,+CAA4C;AAC5C,sDAAyD;AACzD,sDAAyD;AACzD,oDAAiD;AAEjD,IAAA,8CAAiC,EAC/B,mBAAQ,CAAC,WAAW,EAAE,EACtB,OAAO,EACP;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC;IAC9C,UAAU,EAAE;QACV,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC/B;CACF,EACD;IACE,WAAW,EAAE,+BAAiB;IAC9B,WAAW,EAAE,+BAAiB;IAC9B,UAAU,EAAV,uBAAU;CACX,CACF,CAAC","sourcesContent":["import { provideOrderActionsWithCredential } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { handleCancelOrder } from './orders/cancelOrder';\nimport { handleSubmitOrder } from './orders/submitOrder';\nimport { listOrders } from './orders/listOrders';\n\nprovideOrderActionsWithCredential(\n Terminal.fromNodeEnv(),\n 'ASTER',\n {\n type: 'object',\n required: ['address', 'api_key', 'secret_key'],\n properties: {\n address: { type: 'string' },\n api_key: { type: 'string' },\n secret_key: { type: 'string' },\n },\n },\n {\n submitOrder: handleSubmitOrder,\n cancelOrder: handleCancelOrder,\n listOrders,\n },\n);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancelOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAuC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAazF,eAAO,MAAM,iBAAiB,EAAE,2BAA2B,CAAC,WAAW,CA8BtE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleCancelOrder = void 0;
|
|
4
|
+
const utils_1 = require("@yuants/utils");
|
|
5
|
+
const private_api_1 = require("../../api/private-api");
|
|
6
|
+
const parseProductId = (productId) => {
|
|
7
|
+
if (!productId) {
|
|
8
|
+
return { category: undefined, symbol: undefined };
|
|
9
|
+
}
|
|
10
|
+
const parts = (0, utils_1.decodePath)(productId);
|
|
11
|
+
if (parts.length >= 2) {
|
|
12
|
+
return { category: parts[0], symbol: parts.slice(1).join('/') };
|
|
13
|
+
}
|
|
14
|
+
return { category: undefined, symbol: parts[0] };
|
|
15
|
+
};
|
|
16
|
+
const handleCancelOrder = async (credential, order) => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
if (!order.order_id) {
|
|
19
|
+
throw new Error('order_id is required for CancelOrder');
|
|
20
|
+
}
|
|
21
|
+
const { category, symbol } = parseProductId(order.product_id);
|
|
22
|
+
if (!symbol) {
|
|
23
|
+
throw new Error('product_id is required to resolve symbol for CancelOrder');
|
|
24
|
+
}
|
|
25
|
+
const accountId = (_b = (_a = order.account_id) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : order.account_id;
|
|
26
|
+
const productType = category === null || category === void 0 ? void 0 : category.toUpperCase();
|
|
27
|
+
if ((accountId === null || accountId === void 0 ? void 0 : accountId.includes('/SPOT')) || productType === 'SPOT') {
|
|
28
|
+
await (0, private_api_1.deleteApiV1Order)(credential, {
|
|
29
|
+
symbol,
|
|
30
|
+
orderId: order.order_id,
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if ((accountId === null || accountId === void 0 ? void 0 : accountId.includes('/PERP')) || productType === 'PERPETUAL') {
|
|
35
|
+
await (0, private_api_1.deleteFApiV1Order)(credential, {
|
|
36
|
+
symbol,
|
|
37
|
+
orderId: order.order_id,
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Unsupported account_id/product for CancelOrder: ${order.account_id}`);
|
|
42
|
+
};
|
|
43
|
+
exports.handleCancelOrder = handleCancelOrder;
|
|
44
|
+
//# sourceMappingURL=cancelOrder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancelOrder.js","sourceRoot":"","sources":["../../../src/services/orders/cancelOrder.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,uDAAyF;AAEzF,MAAM,cAAc,GAAG,CAAC,SAAkB,EAAE,EAAE;IAC5C,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,EAAE,QAAQ,EAAE,SAA+B,EAAE,MAAM,EAAE,SAA+B,EAAE,CAAC;KAC/F;IACD,MAAM,KAAK,GAAG,IAAA,kBAAU,EAAC,SAAS,CAAC,CAAC;IACpC,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;QACrB,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,EA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AAI,KAAK,CAAC,mDAAmD,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;AACzF,CAAC,CAAC;AA9BW,QAAA,iBAAiB,qBA8B5B","sourcesContent":["import { IActionHandlerOfCancelOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { deleteApiV1Order, deleteFApiV1Order, ICredential } from '../../api/private-api';\n\nconst parseProductId = (productId?: string) => {\n if (!productId) {\n return { category: undefined as string | undefined, symbol: undefined as string | undefined };\n }\n const parts = decodePath(productId);\n if (parts.length >= 2) {\n return { category: parts[0], symbol: parts.slice(1).join('/') };\n }\n return { category: undefined, symbol: parts[0] };\n};\n\nexport const handleCancelOrder: IActionHandlerOfCancelOrder<ICredential> = async (credential, order) => {\n if (!order.order_id) {\n throw new Error('order_id is required for CancelOrder');\n }\n\n const { category, symbol } = parseProductId(order.product_id);\n if (!symbol) {\n throw new Error('product_id is required to resolve symbol for CancelOrder');\n }\n\n const accountId = order.account_id?.toUpperCase() ?? order.account_id;\n const productType = category?.toUpperCase();\n\n if (accountId?.includes('/SPOT') || productType === 'SPOT') {\n await deleteApiV1Order(credential, {\n symbol,\n orderId: order.order_id,\n });\n return;\n }\n\n if (accountId?.includes('/PERP') || productType === 'PERPETUAL') {\n await deleteFApiV1Order(credential, {\n symbol,\n orderId: order.order_id,\n });\n return;\n }\n\n throw new Error(`Unsupported account_id/product for CancelOrder: ${order.account_id}`);\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listOrders.d.ts","sourceRoot":"","sources":["../../../src/services/orders/listOrders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAU,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAKL,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAoE/B,eAAO,MAAM,UAAU,EAAE,0BAA0B,CAAC,WAAW,CAQ9D,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listOrders = void 0;
|
|
4
|
+
const private_api_1 = require("../../api/private-api");
|
|
5
|
+
const utils_1 = require("@yuants/utils");
|
|
6
|
+
const resolvePerpOrderDirection = (asterOrder) => {
|
|
7
|
+
const reduceOnly = asterOrder.reduceOnly || asterOrder.closePosition;
|
|
8
|
+
if (asterOrder.positionSide === 'LONG') {
|
|
9
|
+
return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';
|
|
10
|
+
}
|
|
11
|
+
if (asterOrder.positionSide === 'SHORT') {
|
|
12
|
+
return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'OPEN_SHORT';
|
|
13
|
+
}
|
|
14
|
+
if (reduceOnly) {
|
|
15
|
+
return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'CLOSE_LONG';
|
|
16
|
+
}
|
|
17
|
+
return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT';
|
|
18
|
+
};
|
|
19
|
+
const resolveSpotOrderDirection = (side) => {
|
|
20
|
+
return side === 'SELL' ? 'CLOSE_LONG' : 'OPEN_LONG';
|
|
21
|
+
};
|
|
22
|
+
const mapPerpOrder = (order, account_id) => {
|
|
23
|
+
const volume = Number(order.origQty);
|
|
24
|
+
const tradedVolume = Number(order.executedQty);
|
|
25
|
+
const price = Number(order.price);
|
|
26
|
+
const avgPrice = Number(order.avgPrice);
|
|
27
|
+
return {
|
|
28
|
+
order_id: `${order.orderId}`,
|
|
29
|
+
account_id,
|
|
30
|
+
product_id: (0, utils_1.encodePath)('PERPETUAL', order.symbol),
|
|
31
|
+
order_type: order.type,
|
|
32
|
+
order_direction: resolvePerpOrderDirection(order),
|
|
33
|
+
volume: Number.isFinite(volume) ? volume : 0,
|
|
34
|
+
price: Number.isFinite(price) ? price : undefined,
|
|
35
|
+
submit_at: order.updateTime,
|
|
36
|
+
traded_volume: Number.isFinite(tradedVolume) ? tradedVolume : undefined,
|
|
37
|
+
traded_price: Number.isFinite(avgPrice) && avgPrice > 0 ? avgPrice : undefined,
|
|
38
|
+
order_status: order.status,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const mapSpotOrder = (order, account_id) => {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const volume = Number(order.origQty);
|
|
44
|
+
const tradedVolume = Number(order.executedQty);
|
|
45
|
+
const price = Number(order.price);
|
|
46
|
+
const avgPrice = Number((_a = order.avgPrice) !== null && _a !== void 0 ? _a : order.price);
|
|
47
|
+
return {
|
|
48
|
+
order_id: `${order.orderId}`,
|
|
49
|
+
account_id,
|
|
50
|
+
product_id: (0, utils_1.encodePath)('SPOT', order.symbol),
|
|
51
|
+
order_type: order.type,
|
|
52
|
+
order_direction: resolveSpotOrderDirection(order.side),
|
|
53
|
+
volume: Number.isFinite(volume) ? volume : 0,
|
|
54
|
+
price: Number.isFinite(price) ? price : undefined,
|
|
55
|
+
submit_at: (_b = order.updateTime) !== null && _b !== void 0 ? _b : order.time,
|
|
56
|
+
traded_volume: Number.isFinite(tradedVolume) ? tradedVolume : undefined,
|
|
57
|
+
traded_price: Number.isFinite(avgPrice) && avgPrice > 0 ? avgPrice : undefined,
|
|
58
|
+
order_status: order.status,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const isSpotAccount = (account_id) => account_id.endsWith('/SPOT');
|
|
62
|
+
const listOrders = async (credential, account_id) => {
|
|
63
|
+
if (isSpotAccount(account_id)) {
|
|
64
|
+
const orders = await (0, private_api_1.getApiV1OpenOrders)(credential, {});
|
|
65
|
+
return orders.map((order) => mapSpotOrder(order, account_id));
|
|
66
|
+
}
|
|
67
|
+
const orders = await (0, private_api_1.getFApiV1OpenOrders)(credential, {});
|
|
68
|
+
return orders.map((order) => mapPerpOrder(order, account_id));
|
|
69
|
+
};
|
|
70
|
+
exports.listOrders = listOrders;
|
|
71
|
+
//# sourceMappingURL=listOrders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AAC,CAAC;IACzD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC;AARW,QAAA,UAAU,cAQrB","sourcesContent":["import { IActionHandlerOfListOrders, IOrder } from '@yuants/data-order';\nimport {\n getApiV1OpenOrders,\n getFApiV1OpenOrders,\n IAsterFutureOpenOrder,\n IAsterSpotOpenOrder,\n ICredential,\n} from '../../api/private-api';\nimport { encodePath } from '@yuants/utils';\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\nconst resolvePerpOrderDirection = (asterOrder: IAsterFutureOpenOrder): OrderDirection => {\n const reduceOnly = asterOrder.reduceOnly || asterOrder.closePosition;\n\n if (asterOrder.positionSide === 'LONG') {\n return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'CLOSE_LONG';\n }\n if (asterOrder.positionSide === 'SHORT') {\n return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'OPEN_SHORT';\n }\n if (reduceOnly) {\n return asterOrder.side === 'BUY' ? 'CLOSE_SHORT' : 'CLOSE_LONG';\n }\n return asterOrder.side === 'BUY' ? 'OPEN_LONG' : 'OPEN_SHORT';\n};\n\nconst resolveSpotOrderDirection = (side: 'BUY' | 'SELL'): OrderDirection => {\n return side === 'SELL' ? 'CLOSE_LONG' : 'OPEN_LONG';\n};\n\nconst mapPerpOrder = (order: IAsterFutureOpenOrder, account_id: string): IOrder => {\n const volume = Number(order.origQty);\n const tradedVolume = Number(order.executedQty);\n const price = Number(order.price);\n const avgPrice = Number(order.avgPrice);\n\n return {\n order_id: `${order.orderId}`,\n account_id,\n product_id: encodePath('PERPETUAL', order.symbol),\n order_type: order.type,\n order_direction: resolvePerpOrderDirection(order),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) ? price : undefined,\n submit_at: order.updateTime,\n traded_volume: Number.isFinite(tradedVolume) ? tradedVolume : undefined,\n traded_price: Number.isFinite(avgPrice) && avgPrice > 0 ? avgPrice : undefined,\n order_status: order.status,\n };\n};\n\nconst mapSpotOrder = (order: IAsterSpotOpenOrder, account_id: string): IOrder => {\n const volume = Number(order.origQty);\n const tradedVolume = Number(order.executedQty);\n const price = Number(order.price);\n const avgPrice = Number(order.avgPrice ?? order.price);\n\n return {\n order_id: `${order.orderId}`,\n account_id,\n product_id: encodePath('SPOT', order.symbol),\n order_type: order.type,\n order_direction: resolveSpotOrderDirection(order.side),\n volume: Number.isFinite(volume) ? volume : 0,\n price: Number.isFinite(price) ? price : undefined,\n submit_at: order.updateTime ?? order.time,\n traded_volume: Number.isFinite(tradedVolume) ? tradedVolume : undefined,\n traded_price: Number.isFinite(avgPrice) && avgPrice > 0 ? avgPrice : undefined,\n order_status: order.status,\n };\n};\n\nconst isSpotAccount = (account_id: string) => account_id.endsWith('/SPOT');\n\nexport const listOrders: IActionHandlerOfListOrders<ICredential> = async (credential, account_id) => {\n if (isSpotAccount(account_id)) {\n const orders = await getApiV1OpenOrders(credential, {});\n return orders.map((order) => mapSpotOrder(order, account_id));\n }\n\n const orders = await getFApiV1OpenOrders(credential, {});\n return orders.map((order) => mapPerpOrder(order, account_id));\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAuB,WAAW,EAAmC,MAAM,uBAAuB,CAAC;AA+G1G,eAAO,MAAM,iBAAiB,EAAE,2BAA2B,CAAC,WAAW,CAYtE,CAAC"}
|