@yuants/vendor-aster 0.7.14 → 0.7.16
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/services/accounts/spot.js +51 -16
- package/dist/services/accounts/spot.js.map +1 -1
- package/dist/services/exchange.js +4 -18
- package/dist/services/exchange.js.map +1 -1
- package/dist/services/markets/interest_rate.js +1 -16
- package/dist/services/markets/interest_rate.js.map +1 -1
- package/dist/services/markets/product.js +0 -5
- package/dist/services/markets/product.js.map +1 -1
- package/lib/services/accounts/spot.d.ts +1 -1
- package/lib/services/accounts/spot.d.ts.map +1 -1
- package/lib/services/accounts/spot.js +53 -18
- package/lib/services/accounts/spot.js.map +1 -1
- package/lib/services/exchange.js +3 -17
- package/lib/services/exchange.js.map +1 -1
- package/lib/services/markets/interest_rate.js +0 -15
- package/lib/services/markets/interest_rate.js.map +1 -1
- package/lib/services/markets/product.d.ts +0 -1
- package/lib/services/markets/product.d.ts.map +1 -1
- package/lib/services/markets/product.js +1 -6
- package/lib/services/markets/product.js.map +1 -1
- package/package.json +2 -2
- package/temp/package-deps.json +8 -9
- package/dist/services/accounts/perp.js +0 -23
- package/dist/services/accounts/perp.js.map +0 -1
- package/lib/services/accounts/perp.d.ts +0 -4
- package/lib/services/accounts/perp.d.ts.map +0 -1
- package/lib/services/accounts/perp.js +0 -27
- package/lib/services/accounts/perp.js.map +0 -1
|
@@ -1,38 +1,73 @@
|
|
|
1
|
+
import { createCache } from '@yuants/cache';
|
|
1
2
|
import { makeSpotPosition } from '@yuants/data-account';
|
|
2
|
-
import { getApiV1Account, getApiV1TickerPrice, getFApiV4Account } from '../../api/private-api';
|
|
3
3
|
import { encodePath } from '@yuants/utils';
|
|
4
|
-
|
|
4
|
+
import { getApiV1Account, getApiV1TickerPrice, getFApiV4Account } from '../../api/private-api';
|
|
5
|
+
// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko
|
|
6
|
+
const asBNBPrice = createCache(() => fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')
|
|
7
|
+
.then((res) => res.json())
|
|
8
|
+
.then((data) => data['astherus-staked-bnb'].usd), {
|
|
9
|
+
expire: 60000, // 1 minute
|
|
10
|
+
});
|
|
11
|
+
export const getPositions = async (credential) => {
|
|
12
|
+
var _a, _b, _c, _d;
|
|
13
|
+
const positions = [];
|
|
5
14
|
const [x, prices, prep] = await Promise.all([
|
|
6
15
|
getApiV1Account(credential, {}),
|
|
7
16
|
getApiV1TickerPrice(credential, {}),
|
|
8
17
|
getFApiV4Account(credential, {}),
|
|
9
18
|
]);
|
|
10
|
-
const
|
|
11
|
-
var _a, _b;
|
|
19
|
+
for (const b of x.balances) {
|
|
12
20
|
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;
|
|
13
|
-
|
|
21
|
+
positions.push(makeSpotPosition({
|
|
14
22
|
position_id: b.asset,
|
|
15
23
|
datasource_id: 'ASTER',
|
|
16
24
|
product_id: encodePath('ASTER', 'SPOT', b.asset),
|
|
17
25
|
volume: +b.free + +b.locked,
|
|
18
26
|
free_volume: +b.free,
|
|
19
27
|
closable_price: +thePrice,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
for (const b of prep.assets) {
|
|
31
|
+
if (+b.walletBalance === 0)
|
|
32
|
+
continue;
|
|
33
|
+
let thePrice = 0;
|
|
34
|
+
if (b.asset === 'USDT') {
|
|
35
|
+
thePrice = 1;
|
|
36
|
+
}
|
|
37
|
+
else if (b.asset === 'ASBNB') {
|
|
38
|
+
const _p = await asBNBPrice.query('').catch(() => 0);
|
|
39
|
+
if (_p) {
|
|
40
|
+
thePrice = _p;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
thePrice = +((_d = (_c = prices.find((p) => p.symbol === b.asset + 'USDT')) === null || _c === void 0 ? void 0 : _c.price) !== null && _d !== void 0 ? _d : 0);
|
|
45
|
+
}
|
|
46
|
+
positions.push(makeSpotPosition({
|
|
28
47
|
position_id: encodePath(b.asset, 'ASSET'),
|
|
29
48
|
datasource_id: 'ASTER',
|
|
30
49
|
product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),
|
|
31
50
|
volume: +b.walletBalance,
|
|
32
51
|
free_volume: +b.walletBalance,
|
|
33
|
-
closable_price:
|
|
52
|
+
closable_price: thePrice,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
for (const p of prep.positions) {
|
|
56
|
+
if (+p.positionAmt === 0)
|
|
57
|
+
continue;
|
|
58
|
+
positions.push({
|
|
59
|
+
position_id: p.symbol,
|
|
60
|
+
product_id: encodePath('ASTER', 'PERP', p.symbol),
|
|
61
|
+
datasource_id: 'ASTER',
|
|
62
|
+
direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,
|
|
63
|
+
volume: Math.abs(+p.positionAmt),
|
|
64
|
+
free_volume: Math.abs(+p.positionAmt),
|
|
65
|
+
position_price: +p.entryPrice,
|
|
66
|
+
closable_price: Math.abs(+p.notional / +p.positionAmt),
|
|
67
|
+
floating_profit: +p.unrealizedProfit,
|
|
68
|
+
valuation: Math.abs(+p.notional),
|
|
34
69
|
});
|
|
35
|
-
}
|
|
36
|
-
return
|
|
70
|
+
}
|
|
71
|
+
return positions;
|
|
37
72
|
};
|
|
38
73
|
//# sourceMappingURL=spot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,eAAe,EAA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ourcesContent":["import { createCache } from '@yuants/cache';\nimport { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getApiV1Account, getApiV1TickerPrice, getFApiV4Account, ICredential } from '../../api/private-api';\n\n// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko\nconst asBNBPrice = createCache(\n () =>\n fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')\n .then((res) => res.json())\n .then((data) => data['astherus-staked-bnb'].usd as number),\n {\n expire: 60_000, // 1 minute\n },\n);\n\nexport const getPositions = async (credential: ICredential) => {\n const positions: IPosition[] = [];\n const [x, prices, prep] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n getFApiV4Account(credential, {}),\n ]);\n\n for (const b of x.balances) {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n positions.push(\n makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'SPOT', b.asset),\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n }),\n );\n }\n\n for (const b of prep.assets) {\n if (+b.walletBalance === 0) continue;\n let thePrice = 0;\n if (b.asset === 'USDT') {\n thePrice = 1;\n } else if (b.asset === 'ASBNB') {\n const _p = await asBNBPrice.query('').catch(() => 0);\n if (_p) {\n thePrice = _p;\n }\n } else {\n thePrice = +(prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0);\n }\n\n positions.push(\n makeSpotPosition({\n position_id: encodePath(b.asset, 'ASSET'),\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),\n volume: +b.walletBalance,\n free_volume: +b.walletBalance,\n closable_price: thePrice,\n }),\n );\n }\n\n for (const p of prep.positions) {\n if (+p.positionAmt === 0) continue;\n positions.push({\n position_id: p.symbol,\n product_id: encodePath('ASTER', 'PERP', 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\n return positions;\n};\n"]}
|
|
@@ -3,10 +3,9 @@ import { Terminal } from '@yuants/protocol';
|
|
|
3
3
|
import { decodePath } from '@yuants/utils';
|
|
4
4
|
import { listProducts } from './markets/product';
|
|
5
5
|
import { getCredentialId } from './accounts/profile';
|
|
6
|
-
import {
|
|
6
|
+
import { getPositions } from './accounts/spot';
|
|
7
7
|
import { listOrders, listPrepOrders, listSpotOrders } from './orders/listOrders';
|
|
8
8
|
import { handleSubmitOrder } from './orders/submitOrder';
|
|
9
|
-
import { getPerpAccountInfo } from './accounts/perp';
|
|
10
9
|
import { handleCancelOrder } from './orders/cancelOrder';
|
|
11
10
|
const terminal = Terminal.fromNodeEnv();
|
|
12
11
|
provideExchangeServices(terminal, {
|
|
@@ -22,25 +21,12 @@ provideExchangeServices(terminal, {
|
|
|
22
21
|
},
|
|
23
22
|
getCredentialId,
|
|
24
23
|
listProducts,
|
|
25
|
-
getPositions:
|
|
26
|
-
const [perpPositions, spotPositions] = await Promise.all([
|
|
27
|
-
getPerpAccountInfo(credential),
|
|
28
|
-
getSpotAccountInfo(credential),
|
|
29
|
-
]);
|
|
30
|
-
return [...perpPositions, ...spotPositions];
|
|
31
|
-
},
|
|
24
|
+
getPositions: getPositions,
|
|
32
25
|
getOrders: listOrders,
|
|
33
26
|
getPositionsByProductId: async function (credential, product_id) {
|
|
34
27
|
const [_, instType] = decodePath(product_id); // ASTER/PERP/ADAUSDT
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return positions.filter((position) => position.product_id === product_id);
|
|
38
|
-
}
|
|
39
|
-
if (instType === 'PERP') {
|
|
40
|
-
const positions = await getPerpAccountInfo(credential);
|
|
41
|
-
return positions.filter((position) => position.product_id === product_id);
|
|
42
|
-
}
|
|
43
|
-
throw new Error(`Unsupported instType: ${instType}`);
|
|
28
|
+
const positions = await getPositions(credential);
|
|
29
|
+
return positions.filter((position) => position.product_id === product_id);
|
|
44
30
|
},
|
|
45
31
|
getOrdersByProductId: async function (credential, product_id) {
|
|
46
32
|
const [_, instType] = decodePath(product_id); // BITGET/USDT-FUTURES/BTCUSDT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,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,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,CAAC;YAChD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAClE;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,WAAW,EAAE,iBAAiB;CAC/B,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath } from '@yuants/utils';\nimport { listProducts } from './markets/product';\nimport { getCredentialId } from './accounts/profile';\nimport { getPositions } from './accounts/spot';\nimport { listOrders, listPrepOrders, listSpotOrders } from './orders/listOrders';\nimport { handleSubmitOrder } from './orders/submitOrder';\nimport { ICredential } from '../api/private-api';\nimport { handleCancelOrder } from './orders/cancelOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'ASTER',\n credentialSchema: {\n type: 'object',\n required: ['address', 'secret_key', 'api_key'],\n properties: {\n address: { type: 'string' },\n secret_key: { type: 'string' },\n api_key: { type: 'string' },\n },\n },\n getCredentialId,\n listProducts,\n getPositions: getPositions,\n getOrders: listOrders,\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const [_, instType] = decodePath(product_id); // ASTER/PERP/ADAUSDT\n const positions = await getPositions(credential);\n return positions.filter((position) => position.product_id === product_id);\n },\n getOrdersByProductId: async function (credential: ICredential, product_id: string): Promise<IOrder[]> {\n const [_, instType] = decodePath(product_id); // BITGET/USDT-FUTURES/BTCUSDT\n if (instType === 'SPOT') {\n const orders = await listSpotOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n if (instType === 'PERP') {\n const orders = await listPrepOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n },\n submitOrder: handleSubmitOrder,\n modifyOrder: () => {\n throw new Error('Not implemented');\n },\n cancelOrder: handleCancelOrder,\n});\n"]}
|
|
@@ -12,25 +12,10 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
12
12
|
};
|
|
13
13
|
import { createSeriesProvider } from '@yuants/data-series';
|
|
14
14
|
import { Terminal } from '@yuants/protocol';
|
|
15
|
-
import { createSQLWriter } from '@yuants/sql';
|
|
16
15
|
import { decodePath, formatTime } from '@yuants/utils';
|
|
17
|
-
import { firstValueFrom,
|
|
16
|
+
import { firstValueFrom, timer } from 'rxjs';
|
|
18
17
|
import { getFApiV1FundingRate } from '../../api/public-api';
|
|
19
|
-
import { productService } from './product';
|
|
20
18
|
const terminal = Terminal.fromNodeEnv();
|
|
21
|
-
createSQLWriter(terminal, {
|
|
22
|
-
data$: productService.products$.pipe(map((products) => products.filter((product) => product.no_interest_rate === false)), mergeAll(), map((product) => ({
|
|
23
|
-
series_id: product.product_id,
|
|
24
|
-
table_name: 'interest_rate',
|
|
25
|
-
cron_pattern: '0 * * * *',
|
|
26
|
-
cron_timezone: 'UTC',
|
|
27
|
-
disabled: false,
|
|
28
|
-
replay_count: 0,
|
|
29
|
-
}))),
|
|
30
|
-
tableName: 'series_collecting_task',
|
|
31
|
-
writeInterval: 1000,
|
|
32
|
-
conflictKeys: ['series_id', 'table_name'],
|
|
33
|
-
});
|
|
34
19
|
createSeriesProvider(terminal, {
|
|
35
20
|
tableName: 'interest_rate',
|
|
36
21
|
series_id_prefix_parts: ['ASTER'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../../src/services/markets/interest_rate.ts"],"names":[],"mappings":";;;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,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,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC;aACnC;QACH,CAAC;KAAA;CACF,CAAC,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { createSeriesProvider } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { firstValueFrom, timer } from 'rxjs';\nimport { getFApiV1FundingRate } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\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 [, instType, instId] = decodePath(series_id);\n\n if (instType !== 'PERP') {\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: series_id,\n datasource_id: 'ASTER',\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"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { provideQueryProductsService } from '@yuants/data-product';
|
|
2
1
|
import { Terminal } from '@yuants/protocol';
|
|
3
2
|
import { encodePath } from '@yuants/utils';
|
|
4
3
|
import { getFApiV1ExchangeInfo } from '../../api/public-api';
|
|
@@ -38,8 +37,4 @@ export const listProducts = async () => {
|
|
|
38
37
|
};
|
|
39
38
|
});
|
|
40
39
|
};
|
|
41
|
-
// Provide QueryProducts service for ASTER
|
|
42
|
-
export const productService = provideQueryProductsService(terminal, 'ASTER', listProducts, {
|
|
43
|
-
auto_refresh_interval: 3600000, // Refresh hourly
|
|
44
|
-
});
|
|
45
40
|
//# sourceMappingURL=product.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,IAAyB,EAAE;IAC1D,qCAAqC;IACrC,MAAM,YAAY,GAAG,MAAM,qBAAqB,CAAC,EAAE,CAAC,CAAC;IACrD,qCAAqC;IACrC,OAAO,YAAY,CAAC,OAAO;SACxB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,sCAAsC;SACtF,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Product } 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\nexport const listProducts = async (): Promise<IProduct[]> => {\n // Fetch exchange info from ASTER API\n const exchangeInfo = await getFApiV1ExchangeInfo({});\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('ASTER', 'PERP', 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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IPosition } from '@yuants/data-account';
|
|
2
2
|
import { ICredential } from '../../api/private-api';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const getPositions: (credential: ICredential) => Promise<IPosition[]>;
|
|
4
4
|
//# sourceMappingURL=spot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spot.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAA0D,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAa5G,eAAO,MAAM,YAAY,eAAsB,WAAW,yBAiEzD,CAAC"}
|
|
@@ -1,42 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getPositions = void 0;
|
|
4
|
+
const cache_1 = require("@yuants/cache");
|
|
4
5
|
const data_account_1 = require("@yuants/data-account");
|
|
5
|
-
const private_api_1 = require("../../api/private-api");
|
|
6
6
|
const utils_1 = require("@yuants/utils");
|
|
7
|
-
const
|
|
7
|
+
const private_api_1 = require("../../api/private-api");
|
|
8
|
+
// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko
|
|
9
|
+
const asBNBPrice = (0, cache_1.createCache)(() => fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')
|
|
10
|
+
.then((res) => res.json())
|
|
11
|
+
.then((data) => data['astherus-staked-bnb'].usd), {
|
|
12
|
+
expire: 60000, // 1 minute
|
|
13
|
+
});
|
|
14
|
+
const getPositions = async (credential) => {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
const positions = [];
|
|
8
17
|
const [x, prices, prep] = await Promise.all([
|
|
9
18
|
(0, private_api_1.getApiV1Account)(credential, {}),
|
|
10
19
|
(0, private_api_1.getApiV1TickerPrice)(credential, {}),
|
|
11
20
|
(0, private_api_1.getFApiV4Account)(credential, {}),
|
|
12
21
|
]);
|
|
13
|
-
const
|
|
14
|
-
var _a, _b;
|
|
22
|
+
for (const b of x.balances) {
|
|
15
23
|
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;
|
|
16
|
-
|
|
24
|
+
positions.push((0, data_account_1.makeSpotPosition)({
|
|
17
25
|
position_id: b.asset,
|
|
18
26
|
datasource_id: 'ASTER',
|
|
19
27
|
product_id: (0, utils_1.encodePath)('ASTER', 'SPOT', b.asset),
|
|
20
28
|
volume: +b.free + +b.locked,
|
|
21
29
|
free_volume: +b.free,
|
|
22
30
|
closable_price: +thePrice,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
for (const b of prep.assets) {
|
|
34
|
+
if (+b.walletBalance === 0)
|
|
35
|
+
continue;
|
|
36
|
+
let thePrice = 0;
|
|
37
|
+
if (b.asset === 'USDT') {
|
|
38
|
+
thePrice = 1;
|
|
39
|
+
}
|
|
40
|
+
else if (b.asset === 'ASBNB') {
|
|
41
|
+
const _p = await asBNBPrice.query('').catch(() => 0);
|
|
42
|
+
if (_p) {
|
|
43
|
+
thePrice = _p;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
thePrice = +((_d = (_c = prices.find((p) => p.symbol === b.asset + 'USDT')) === null || _c === void 0 ? void 0 : _c.price) !== null && _d !== void 0 ? _d : 0);
|
|
48
|
+
}
|
|
49
|
+
positions.push((0, data_account_1.makeSpotPosition)({
|
|
31
50
|
position_id: (0, utils_1.encodePath)(b.asset, 'ASSET'),
|
|
32
51
|
datasource_id: 'ASTER',
|
|
33
52
|
product_id: (0, utils_1.encodePath)('ASTER', 'PERP-ASSET', b.asset),
|
|
34
53
|
volume: +b.walletBalance,
|
|
35
54
|
free_volume: +b.walletBalance,
|
|
36
|
-
closable_price:
|
|
55
|
+
closable_price: thePrice,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
for (const p of prep.positions) {
|
|
59
|
+
if (+p.positionAmt === 0)
|
|
60
|
+
continue;
|
|
61
|
+
positions.push({
|
|
62
|
+
position_id: p.symbol,
|
|
63
|
+
product_id: (0, utils_1.encodePath)('ASTER', 'PERP', p.symbol),
|
|
64
|
+
datasource_id: 'ASTER',
|
|
65
|
+
direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,
|
|
66
|
+
volume: Math.abs(+p.positionAmt),
|
|
67
|
+
free_volume: Math.abs(+p.positionAmt),
|
|
68
|
+
position_price: +p.entryPrice,
|
|
69
|
+
closable_price: Math.abs(+p.notional / +p.positionAmt),
|
|
70
|
+
floating_profit: +p.unrealizedProfit,
|
|
71
|
+
valuation: Math.abs(+p.notional),
|
|
37
72
|
});
|
|
38
|
-
}
|
|
39
|
-
return
|
|
73
|
+
}
|
|
74
|
+
return positions;
|
|
40
75
|
};
|
|
41
|
-
exports.
|
|
76
|
+
exports.getPositions = getPositions;
|
|
42
77
|
//# sourceMappingURL=spot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,uDAAmE;AACnE,uDAA4G;
|
|
1
|
+
{"version":3,"file":"spot.js","sourceRoot":"","sources":["../../../src/services/accounts/spot.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,uDAAmE;AACnE,yCAA2C;AAC3C,uDAA4G;AAE5G,qFAAqF;AACrF,MAAM,UAAU,GAAG,IAAA,mBAAW,EAC5B,GAAG,EAAE,CACH,KAAK,CAAC,yFAAyF,CAAC;KAC7F,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;KACzB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,GAAa,CAAC,EAC9D;IACE,MAAM,EAAE,KAAM,EAAE,WAAW;CA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CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;YAC/F,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YACrC,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU;YAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC;YACtD,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB;YACpC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;SACjC,CAAC,CAAC;KACJ;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAjEW,QAAA,YAAY,gBAiEvB","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { IPosition, makeSpotPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getApiV1Account, getApiV1TickerPrice, getFApiV4Account, ICredential } from '../../api/private-api';\n\n// ISSUE: ASBNB price is not available in the price API, need to fetch from coingecko\nconst asBNBPrice = createCache(\n () =>\n fetch('https://api.coingecko.com/api/v3/simple/price?ids=astherus-staked-bnb&vs_currencies=usd')\n .then((res) => res.json())\n .then((data) => data['astherus-staked-bnb'].usd as number),\n {\n expire: 60_000, // 1 minute\n },\n);\n\nexport const getPositions = async (credential: ICredential) => {\n const positions: IPosition[] = [];\n const [x, prices, prep] = await Promise.all([\n getApiV1Account(credential, {}),\n getApiV1TickerPrice(credential, {}),\n getFApiV4Account(credential, {}),\n ]);\n\n for (const b of x.balances) {\n const thePrice = b.asset === 'USDT' ? 1 : prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0;\n positions.push(\n makeSpotPosition({\n position_id: b.asset,\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'SPOT', b.asset),\n volume: +b.free + +b.locked,\n free_volume: +b.free,\n closable_price: +thePrice,\n }),\n );\n }\n\n for (const b of prep.assets) {\n if (+b.walletBalance === 0) continue;\n let thePrice = 0;\n if (b.asset === 'USDT') {\n thePrice = 1;\n } else if (b.asset === 'ASBNB') {\n const _p = await asBNBPrice.query('').catch(() => 0);\n if (_p) {\n thePrice = _p;\n }\n } else {\n thePrice = +(prices.find((p) => p.symbol === b.asset + 'USDT')?.price ?? 0);\n }\n\n positions.push(\n makeSpotPosition({\n position_id: encodePath(b.asset, 'ASSET'),\n datasource_id: 'ASTER',\n product_id: encodePath('ASTER', 'PERP-ASSET', b.asset),\n volume: +b.walletBalance,\n free_volume: +b.walletBalance,\n closable_price: thePrice,\n }),\n );\n }\n\n for (const p of prep.positions) {\n if (+p.positionAmt === 0) continue;\n positions.push({\n position_id: p.symbol,\n product_id: encodePath('ASTER', 'PERP', 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\n return positions;\n};\n"]}
|
package/lib/services/exchange.js
CHANGED
|
@@ -8,7 +8,6 @@ const profile_1 = require("./accounts/profile");
|
|
|
8
8
|
const spot_1 = require("./accounts/spot");
|
|
9
9
|
const listOrders_1 = require("./orders/listOrders");
|
|
10
10
|
const submitOrder_1 = require("./orders/submitOrder");
|
|
11
|
-
const perp_1 = require("./accounts/perp");
|
|
12
11
|
const cancelOrder_1 = require("./orders/cancelOrder");
|
|
13
12
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
14
13
|
(0, exchange_1.provideExchangeServices)(terminal, {
|
|
@@ -24,25 +23,12 @@ const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
|
24
23
|
},
|
|
25
24
|
getCredentialId: profile_1.getCredentialId,
|
|
26
25
|
listProducts: product_1.listProducts,
|
|
27
|
-
getPositions:
|
|
28
|
-
const [perpPositions, spotPositions] = await Promise.all([
|
|
29
|
-
(0, perp_1.getPerpAccountInfo)(credential),
|
|
30
|
-
(0, spot_1.getSpotAccountInfo)(credential),
|
|
31
|
-
]);
|
|
32
|
-
return [...perpPositions, ...spotPositions];
|
|
33
|
-
},
|
|
26
|
+
getPositions: spot_1.getPositions,
|
|
34
27
|
getOrders: listOrders_1.listOrders,
|
|
35
28
|
getPositionsByProductId: async function (credential, product_id) {
|
|
36
29
|
const [_, instType] = (0, utils_1.decodePath)(product_id); // ASTER/PERP/ADAUSDT
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return positions.filter((position) => position.product_id === product_id);
|
|
40
|
-
}
|
|
41
|
-
if (instType === 'PERP') {
|
|
42
|
-
const positions = await (0, perp_1.getPerpAccountInfo)(credential);
|
|
43
|
-
return positions.filter((position) => position.product_id === product_id);
|
|
44
|
-
}
|
|
45
|
-
throw new Error(`Unsupported instType: ${instType}`);
|
|
30
|
+
const positions = await (0, spot_1.getPositions)(credential);
|
|
31
|
+
return positions.filter((position) => position.product_id === product_id);
|
|
46
32
|
},
|
|
47
33
|
getOrdersByProductId: async function (credential, product_id) {
|
|
48
34
|
const [_, instType] = (0, utils_1.decodePath)(product_id); // BITGET/USDT-FUTURES/BTCUSDT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AAEA,+CAA2D;AAC3D,+CAA4C;AAC5C,yCAA2C;AAC3C,+CAAiD;AACjD,gDAAqD;AACrD,
|
|
1
|
+
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/services/exchange.ts"],"names":[],"mappings":";;AAEA,+CAA2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C,CAAC;YAChD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAClE;QACD,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAc,EAAC,UAAU,CAAC,CAAC;YAChD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;SAClE;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,WAAW,EAAE,+BAAiB;IAC9B,WAAW,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,WAAW,EAAE,+BAAiB;CAC/B,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { provideExchangeServices } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath } from '@yuants/utils';\nimport { listProducts } from './markets/product';\nimport { getCredentialId } from './accounts/profile';\nimport { getPositions } from './accounts/spot';\nimport { listOrders, listPrepOrders, listSpotOrders } from './orders/listOrders';\nimport { handleSubmitOrder } from './orders/submitOrder';\nimport { ICredential } from '../api/private-api';\nimport { handleCancelOrder } from './orders/cancelOrder';\n\nconst terminal = Terminal.fromNodeEnv();\n\nprovideExchangeServices<ICredential>(terminal, {\n name: 'ASTER',\n credentialSchema: {\n type: 'object',\n required: ['address', 'secret_key', 'api_key'],\n properties: {\n address: { type: 'string' },\n secret_key: { type: 'string' },\n api_key: { type: 'string' },\n },\n },\n getCredentialId,\n listProducts,\n getPositions: getPositions,\n getOrders: listOrders,\n getPositionsByProductId: async function (\n credential: ICredential,\n product_id: string,\n ): Promise<IPosition[]> {\n const [_, instType] = decodePath(product_id); // ASTER/PERP/ADAUSDT\n const positions = await getPositions(credential);\n return positions.filter((position) => position.product_id === product_id);\n },\n getOrdersByProductId: async function (credential: ICredential, product_id: string): Promise<IOrder[]> {\n const [_, instType] = decodePath(product_id); // BITGET/USDT-FUTURES/BTCUSDT\n if (instType === 'SPOT') {\n const orders = await listSpotOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n if (instType === 'PERP') {\n const orders = await listPrepOrders(credential);\n return orders.filter((order) => order.product_id === product_id);\n }\n throw new Error(`Unsupported instType: ${instType}`);\n },\n submitOrder: handleSubmitOrder,\n modifyOrder: () => {\n throw new Error('Not implemented');\n },\n cancelOrder: handleCancelOrder,\n});\n"]}
|
|
@@ -14,25 +14,10 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const data_series_1 = require("@yuants/data-series");
|
|
16
16
|
const protocol_1 = require("@yuants/protocol");
|
|
17
|
-
const sql_1 = require("@yuants/sql");
|
|
18
17
|
const utils_1 = require("@yuants/utils");
|
|
19
18
|
const rxjs_1 = require("rxjs");
|
|
20
19
|
const public_api_1 = require("../../api/public-api");
|
|
21
|
-
const product_1 = require("./product");
|
|
22
20
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
23
|
-
(0, sql_1.createSQLWriter)(terminal, {
|
|
24
|
-
data$: product_1.productService.products$.pipe((0, rxjs_1.map)((products) => products.filter((product) => product.no_interest_rate === false)), (0, rxjs_1.mergeAll)(), (0, rxjs_1.map)((product) => ({
|
|
25
|
-
series_id: product.product_id,
|
|
26
|
-
table_name: 'interest_rate',
|
|
27
|
-
cron_pattern: '0 * * * *',
|
|
28
|
-
cron_timezone: 'UTC',
|
|
29
|
-
disabled: false,
|
|
30
|
-
replay_count: 0,
|
|
31
|
-
}))),
|
|
32
|
-
tableName: 'series_collecting_task',
|
|
33
|
-
writeInterval: 1000,
|
|
34
|
-
conflictKeys: ['series_id', 'table_name'],
|
|
35
|
-
});
|
|
36
21
|
(0, data_series_1.createSeriesProvider)(terminal, {
|
|
37
22
|
tableName: 'interest_rate',
|
|
38
23
|
series_id_prefix_parts: ['ASTER'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../../src/services/markets/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../../../src/services/markets/interest_rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,qDAA2D;AAC3D,+CAA4C;AAC5C,yCAAuD;AACvD,+BAA6C;AAC7C,qDAA4D;AAE5D,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,IAAA,kCAAoB,EAAgB,QAAQ,EAAE;IAC5C,SAAS,EAAE,eAAe;IAC1B,sBAAsB,EAAE,CAAC,OAAO,CAAC;IACjC,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE;IACjC,OAAO,EAAE,UAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE;;YAC3D,MAAM,KAAK,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,CAAC,CAAC;YAC9B,MAAM,GAAG,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACnC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,SAAS,CAAC,CAAC;YAEnD,IAAI,QAAQ,KAAK,MAAM,EAAE;gBACvB,6BAAO;aACR;YAED,IAAI,YAAY,GAAG,KAAK,CAAC;YAEzB,OAAO,YAAY,IAAI,GAAG,EAAE;gBAC1B,MAAM,GAAG,GAAG,cAAM,IAAA,iCAAoB,EAAC;oBACrC,MAAM,EAAE,MAAM;oBACd,SAAS,EAAE,YAAY;oBACvB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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 { createSeriesProvider } from '@yuants/data-series';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { firstValueFrom, timer } from 'rxjs';\nimport { getFApiV1FundingRate } from '../../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\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 [, instType, instId] = decodePath(series_id);\n\n if (instType !== 'PERP') {\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: series_id,\n datasource_id: 'ASTER',\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAOhD,eAAO,MAAM,YAAY,QAAa,QAAQ,QAAQ,EAAE,CAoCvD,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const data_product_1 = require("@yuants/data-product");
|
|
3
|
+
exports.listProducts = void 0;
|
|
5
4
|
const protocol_1 = require("@yuants/protocol");
|
|
6
5
|
const utils_1 = require("@yuants/utils");
|
|
7
6
|
const public_api_1 = require("../../api/public-api");
|
|
@@ -42,8 +41,4 @@ const listProducts = async () => {
|
|
|
42
41
|
});
|
|
43
42
|
};
|
|
44
43
|
exports.listProducts = listProducts;
|
|
45
|
-
// Provide QueryProducts service for ASTER
|
|
46
|
-
exports.productService = (0, data_product_1.provideQueryProductsService)(terminal, 'ASTER', exports.listProducts, {
|
|
47
|
-
auto_refresh_interval: 3600000, // Refresh hourly
|
|
48
|
-
});
|
|
49
44
|
//# sourceMappingURL=product.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/services/markets/product.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"product.js","sour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AAC,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,CAAC;AApCW,QAAA,YAAY,gBAoCvB","sourcesContent":["import { IProduct } 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\nexport const listProducts = async (): Promise<IProduct[]> => {\n // Fetch exchange info from ASTER API\n const exchangeInfo = await getFApiV1ExchangeInfo({});\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('ASTER', 'PERP', 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-aster",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.16",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@yuants/data-interest-rate": "0.1.48",
|
|
21
21
|
"@yuants/transfer": "0.2.39",
|
|
22
22
|
"@yuants/data-quote": "0.2.43",
|
|
23
|
-
"@yuants/exchange": "0.
|
|
23
|
+
"@yuants/exchange": "0.3.0",
|
|
24
24
|
"rxjs": "~7.5.6"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
package/temp/package-deps.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"apps/vendor-aster/AGENTS.md": "dcd006d19a5c3b73081525d7c0afea68cd6d058b",
|
|
3
|
-
"apps/vendor-aster/CHANGELOG.json": "
|
|
4
|
-
"apps/vendor-aster/CHANGELOG.md": "
|
|
3
|
+
"apps/vendor-aster/CHANGELOG.json": "a51bcb9b60e673c4d4c58f9edf0522bfb12a27bf",
|
|
4
|
+
"apps/vendor-aster/CHANGELOG.md": "b13d9c3b8d3df6d80695ab133c5b9e9cdd5ae30e",
|
|
5
5
|
"apps/vendor-aster/SESSION_NOTES.md": "f54c13cf4182d8a5e720f6db5d3acc323655ea49",
|
|
6
6
|
"apps/vendor-aster/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
|
|
7
7
|
"apps/vendor-aster/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
8
8
|
"apps/vendor-aster/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
9
|
-
"apps/vendor-aster/package.json": "
|
|
9
|
+
"apps/vendor-aster/package.json": "fd8dee6b7936829d9113605298a4a52e33f436eb",
|
|
10
10
|
"apps/vendor-aster/src/api/private-api.ts": "71f2f794377a45c64f688a663111318e36463bdb",
|
|
11
11
|
"apps/vendor-aster/src/api/public-api.ts": "052be628aec3a1bec00fa7da102c4932d74249a4",
|
|
12
12
|
"apps/vendor-aster/src/index.ts": "509ef4c18ec2deb8a6e11ed5682334433cb2bcb2",
|
|
13
|
-
"apps/vendor-aster/src/services/accounts/perp.ts": "4bdb41564394f1ddc9a1516a66a66c56d00d4581",
|
|
14
13
|
"apps/vendor-aster/src/services/accounts/profile.ts": "fc57e7d2c865790dd257c043c8dd5cf5c641b7fd",
|
|
15
|
-
"apps/vendor-aster/src/services/accounts/spot.ts": "
|
|
16
|
-
"apps/vendor-aster/src/services/exchange.ts": "
|
|
17
|
-
"apps/vendor-aster/src/services/markets/interest_rate.ts": "
|
|
18
|
-
"apps/vendor-aster/src/services/markets/product.ts": "
|
|
14
|
+
"apps/vendor-aster/src/services/accounts/spot.ts": "d04bf81c9025cae2b49b1ae0099c9525d888e7af",
|
|
15
|
+
"apps/vendor-aster/src/services/exchange.ts": "71a555ceec0d84b6f12a9c2002834676f1370d51",
|
|
16
|
+
"apps/vendor-aster/src/services/markets/interest_rate.ts": "8512bb506f3d66b16aceb9d153d1b3a4671de5ef",
|
|
17
|
+
"apps/vendor-aster/src/services/markets/product.ts": "027646b5af638bacc0f943cefc14e32e71bbb6ce",
|
|
19
18
|
"apps/vendor-aster/src/services/markets/quote.ts": "68bcc4255583a58529914742eaa39badef8993b5",
|
|
20
19
|
"apps/vendor-aster/src/services/orders/cancelOrder.ts": "09a6d3b10a218ad226346dd68d0ff0207083a7f1",
|
|
21
20
|
"apps/vendor-aster/src/services/orders/listOrders.ts": "579e83c45f6c4435ad3f5a2d3fe163a036bb9fd1",
|
|
@@ -34,7 +33,7 @@
|
|
|
34
33
|
"libraries/data-interest-rate/temp/package-deps.json": "cef1e1cb0116ad593c24635684e0cbf03488d67c",
|
|
35
34
|
"libraries/transfer/temp/package-deps.json": "36c58299bd6c841c5ba7252d71881a881570d08c",
|
|
36
35
|
"libraries/data-quote/temp/package-deps.json": "34d079eab44d2bf65e07b112ac2099c6e92a015e",
|
|
37
|
-
"libraries/exchange/temp/package-deps.json": "
|
|
36
|
+
"libraries/exchange/temp/package-deps.json": "81cd228057e0c05ac9f39d4d22b19a59e9a4792f",
|
|
38
37
|
"libraries/extension/temp/package-deps.json": "9569c553c2f9a7d50b70d8f101fc2d3825aaccb9",
|
|
39
38
|
"tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
|
|
40
39
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { encodePath } from '@yuants/utils';
|
|
2
|
-
import { getFApiV4Account } from '../../api/private-api';
|
|
3
|
-
export const getPerpAccountInfo = async (credential) => {
|
|
4
|
-
const [a] = await Promise.all([getFApiV4Account(credential, {})]);
|
|
5
|
-
const equity = +a.totalWalletBalance + +a.totalUnrealizedProfit;
|
|
6
|
-
const free = +a.availableBalance;
|
|
7
|
-
const positions = a.positions
|
|
8
|
-
.filter((p) => +p.positionAmt !== 0)
|
|
9
|
-
.map((p) => ({
|
|
10
|
-
position_id: p.symbol,
|
|
11
|
-
product_id: encodePath('ASTER', 'PERP', p.symbol),
|
|
12
|
-
datasource_id: 'ASTER',
|
|
13
|
-
direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,
|
|
14
|
-
volume: Math.abs(+p.positionAmt),
|
|
15
|
-
free_volume: Math.abs(+p.positionAmt),
|
|
16
|
-
position_price: +p.entryPrice,
|
|
17
|
-
closable_price: Math.abs(+p.notional / +p.positionAmt),
|
|
18
|
-
floating_profit: +p.unrealizedProfit,
|
|
19
|
-
valuation: Math.abs(+p.notional),
|
|
20
|
-
}));
|
|
21
|
-
return positions;
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=perp.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"perp.js","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAC;AAEtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,gBAAgB,CAAC,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,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACjD,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,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFApiV4Account, ICredential } from '../../api/private-api';\n\nexport const getPerpAccountInfo = async (credential: ICredential) => {\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('ASTER', 'PERP', 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 positions;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"perp.d.ts","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAoB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEtE,eAAO,MAAM,kBAAkB,eAAsB,WAAW,yBAuB/D,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPerpAccountInfo = void 0;
|
|
4
|
-
const utils_1 = require("@yuants/utils");
|
|
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, {})]);
|
|
8
|
-
const equity = +a.totalWalletBalance + +a.totalUnrealizedProfit;
|
|
9
|
-
const free = +a.availableBalance;
|
|
10
|
-
const positions = a.positions
|
|
11
|
-
.filter((p) => +p.positionAmt !== 0)
|
|
12
|
-
.map((p) => ({
|
|
13
|
-
position_id: p.symbol,
|
|
14
|
-
product_id: (0, utils_1.encodePath)('ASTER', 'PERP', p.symbol),
|
|
15
|
-
datasource_id: 'ASTER',
|
|
16
|
-
direction: p.positionSide === 'BOTH' ? (+p.positionAmt > 0 ? 'LONG' : 'SHORT') : p.positionSide,
|
|
17
|
-
volume: Math.abs(+p.positionAmt),
|
|
18
|
-
free_volume: Math.abs(+p.positionAmt),
|
|
19
|
-
position_price: +p.entryPrice,
|
|
20
|
-
closable_price: Math.abs(+p.notional / +p.positionAmt),
|
|
21
|
-
floating_profit: +p.unrealizedProfit,
|
|
22
|
-
valuation: Math.abs(+p.notional),
|
|
23
|
-
}));
|
|
24
|
-
return positions;
|
|
25
|
-
};
|
|
26
|
-
exports.getPerpAccountInfo = getPerpAccountInfo;
|
|
27
|
-
//# sourceMappingURL=perp.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"perp.js","sourceRoot":"","sources":["../../../src/services/accounts/perp.ts"],"names":[],"mappings":";;;AACA,yCAA2C;AAC3C,uDAAsE;AAE/D,MAAM,kBAAkB,GAAG,KAAK,EAAE,UAAuB,EAAE,EAAE;IAClE,MAAM,CAAC,CAAC,CAAC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S,CAAC;AACnB,CAAC,CAAC;AAvBW,QAAA,kBAAkB,sBAuB7B","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { encodePath } from '@yuants/utils';\nimport { getFApiV4Account, ICredential } from '../../api/private-api';\n\nexport const getPerpAccountInfo = async (credential: ICredential) => {\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('ASTER', 'PERP', 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 positions;\n};\n"]}
|