@yuants/vendor-aster 0.5.8 → 0.6.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 +52 -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 +54 -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 +17 -0
- package/dist/services/order-actions-with-credential.js.map +1 -0
- package/dist/services/orders/cancelOrder.js +16 -0
- package/dist/services/orders/cancelOrder.js.map +1 -0
- package/dist/{pending-orders.js → services/orders/listOrders.js} +6 -10
- package/dist/services/orders/listOrders.js.map +1 -0
- package/dist/services/orders/submitOrder.js +84 -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.d.ts → api/private-api.d.ts} +46 -46
- package/lib/api/private-api.d.ts.map +1 -0
- package/lib/api/private-api.js +55 -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 +56 -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 +19 -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 +20 -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/{pending-orders.js → services/orders/listOrders.js} +8 -10
- 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 +88 -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 +20 -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.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.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.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
package/lib/order.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const protocol_1 = require("@yuants/protocol");
|
|
4
|
-
const utils_1 = require("@yuants/utils");
|
|
5
|
-
const account_1 = require("./account");
|
|
6
|
-
const api_1 = require("./api");
|
|
7
|
-
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
8
|
-
terminal.server.provideService('SubmitOrder', { required: ['account_id'], properties: { account_id: { type: 'string', const: account_1.ACCOUNT_ID } } }, async (msg) => {
|
|
9
|
-
var _a, _b, _c, _d, _e;
|
|
10
|
-
const order = msg.req;
|
|
11
|
-
const [, decodedSymbol] = (0, utils_1.decodePath)(order.product_id);
|
|
12
|
-
if (!decodedSymbol) {
|
|
13
|
-
throw new Error(`Invalid product_id: unable to decode symbol from "${order.product_id}"`);
|
|
14
|
-
}
|
|
15
|
-
const symbol = decodedSymbol;
|
|
16
|
-
const side = { OPEN_LONG: 'BUY', OPEN_SHORT: 'SELL', CLOSE_LONG: 'SELL', CLOSE_SHORT: 'BUY' }[order.order_direction];
|
|
17
|
-
if (!side)
|
|
18
|
-
throw new Error(`Unsupported order_direction: ${order.order_direction}`);
|
|
19
|
-
const type = { MARKET: 'MARKET', LIMIT: 'LIMIT', MAKER: 'LIMIT' }[order.order_type];
|
|
20
|
-
if (!type)
|
|
21
|
-
throw new Error(`Unsupported order_type: ${order.order_type}`);
|
|
22
|
-
const quantity = order.volume;
|
|
23
|
-
const price = order.price;
|
|
24
|
-
const positionSide = order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_LONG'
|
|
25
|
-
? 'LONG'
|
|
26
|
-
: order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_SHORT'
|
|
27
|
-
? 'SHORT'
|
|
28
|
-
: undefined;
|
|
29
|
-
const reduceOnly = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'true' : undefined;
|
|
30
|
-
const timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;
|
|
31
|
-
const res = await (0, api_1.postFApiV1Order)({
|
|
32
|
-
symbol,
|
|
33
|
-
side,
|
|
34
|
-
type,
|
|
35
|
-
quantity,
|
|
36
|
-
price,
|
|
37
|
-
timeInForce,
|
|
38
|
-
positionSide,
|
|
39
|
-
reduceOnly,
|
|
40
|
-
});
|
|
41
|
-
const orderId = (_d = (_b = (_a = res === null || res === void 0 ? void 0 : res.orderId) !== null && _a !== void 0 ? _a : res === null || res === void 0 ? void 0 : res.order_id) !== null && _b !== void 0 ? _b : (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.orderId) !== null && _d !== void 0 ? _d : (_e = res === null || res === void 0 ? void 0 : res.data) === null || _e === void 0 ? void 0 : _e.order_id;
|
|
42
|
-
return {
|
|
43
|
-
res: {
|
|
44
|
-
code: 0,
|
|
45
|
-
message: 'OK',
|
|
46
|
-
data: orderId ? { order_id: `${orderId}` } : undefined,
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
terminal.server.provideService('CancelOrder', {
|
|
51
|
-
required: ['account_id', 'order_id', 'product_id'],
|
|
52
|
-
properties: {
|
|
53
|
-
account_id: { type: 'string', const: account_1.ACCOUNT_ID },
|
|
54
|
-
order_id: { type: ['string', 'number'] },
|
|
55
|
-
product_id: { type: 'string' },
|
|
56
|
-
},
|
|
57
|
-
}, async (msg) => {
|
|
58
|
-
const order = msg.req;
|
|
59
|
-
const [, decodedSymbol] = (0, utils_1.decodePath)(order.product_id);
|
|
60
|
-
if (!decodedSymbol) {
|
|
61
|
-
throw new Error(`Invalid product_id: unable to decode symbol from "${order.product_id}"`);
|
|
62
|
-
}
|
|
63
|
-
if (!order.order_id) {
|
|
64
|
-
throw new Error('order_id is required for CancelOrder');
|
|
65
|
-
}
|
|
66
|
-
await (0, api_1.deleteFApiV1Order)({
|
|
67
|
-
symbol: decodedSymbol,
|
|
68
|
-
orderId: order.order_id,
|
|
69
|
-
});
|
|
70
|
-
return { res: { code: 0, message: 'OK' } };
|
|
71
|
-
});
|
|
72
|
-
//# sourceMappingURL=order.js.map
|
package/lib/order.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAE5C,yCAA2C;AAC3C,uCAAuC;AACvC,+BAA2D;AAE3D,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,aAAa,EACb,EAAE,QAAQ,EAAE,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,oBAAU,EAAE,EAAE,EAAE,EAC/F,KAAK,EAAE,GAAG,EAAE,EAAE;;IACZ,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;IAEtB,MAAM,CAAC,EAAE,aAAa,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACvD,IAAI,CAAC,aAAa,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,qDAAqD,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC;KAC3F;IACD,MAAM,MAAM,GAAG,aAAa,CAAC;IAE7B,MAAM,IAAI,GAAI,EAAE,SAAS,EAAE,KAAK,EAAE,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QACnB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;KACzD;IAED,MAAM,IAAA,uBAAiB,EAAC;QACtB,MAAM,EAAE,aAAa;QACrB,OAAO,EAAE,KAAK,CAAC,QAAQ;KACxB,CAAC,CAAC;IAEH,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;AAC7C,CAAC,CACF,CAAC","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { IOrder } from '@yuants/data-order';\nimport { decodePath } from '@yuants/utils';\nimport { ACCOUNT_ID } from './account';\nimport { deleteFApiV1Order, postFApiV1Order } from './api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nterminal.server.provideService<IOrder, { order_id?: string }>(\n 'SubmitOrder',\n { required: ['account_id'], properties: { account_id: { type: 'string', const: ACCOUNT_ID } } },\n async (msg) => {\n const order = msg.req;\n\n const [, decodedSymbol] = decodePath(order.product_id);\n if (!decodedSymbol) {\n throw new Error(`Invalid product_id: unable to decode symbol from \"${order.product_id}\"`);\n }\n const symbol = decodedSymbol;\n\n const side = ({ OPEN_LONG: 'BUY', OPEN_SHORT: 'SELL', CLOSE_LONG: 'SELL', CLOSE_SHORT: 'BUY' } as const)[\n order.order_direction!\n ];\n if (!side) throw new Error(`Unsupported order_direction: ${order.order_direction}`);\n\n const type = ({ MARKET: 'MARKET', LIMIT: 'LIMIT', MAKER: 'LIMIT' } as const)[order.order_type!];\n if (!type) throw new Error(`Unsupported order_type: ${order.order_type}`);\n\n const quantity = order.volume;\n const price = order.price;\n\n const positionSide =\n order.order_direction === 'OPEN_LONG' || order.order_direction === 'CLOSE_LONG'\n ? 'LONG'\n : order.order_direction === 'OPEN_SHORT' || order.order_direction === 'CLOSE_SHORT'\n ? 'SHORT'\n : undefined;\n\n const reduceOnly =\n order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT' ? 'true' : undefined;\n\n const timeInForce =\n order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const res = await postFApiV1Order({\n symbol,\n side,\n type,\n quantity,\n price,\n timeInForce,\n positionSide,\n reduceOnly,\n });\n\n const orderId =\n (res as any)?.orderId ??\n (res as any)?.order_id ??\n (res as any)?.data?.orderId ??\n (res as any)?.data?.order_id;\n\n return {\n res: {\n code: 0,\n message: 'OK',\n data: orderId ? { order_id: `${orderId}` } : undefined,\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: ACCOUNT_ID },\n order_id: { type: ['string', 'number'] },\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n const order = msg.req;\n const [, decodedSymbol] = decodePath(order.product_id);\n if (!decodedSymbol) {\n throw new Error(`Invalid product_id: unable to decode symbol from \"${order.product_id}\"`);\n }\n if (!order.order_id) {\n throw new Error('order_id is required for CancelOrder');\n }\n\n await deleteFApiV1Order({\n symbol: decodedSymbol,\n orderId: order.order_id,\n });\n\n return { res: { code: 0, message: 'OK' } };\n },\n);\n"]}
|
package/lib/pending-orders.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pending-orders.d.ts","sourceRoot":"","sources":["../src/pending-orders.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pending-orders.js","sourceRoot":"","sources":["../src/pending-orders.ts"],"names":[],"mappings":";;AAAA,mDAAyE;AACzE,+CAA4C;AAC5C,yCAA2C;AAC3C,uCAAuC;AACvC,+BAA4C;AAE5C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAoBxC,MAAM,qBAAqB,GAAG,CAAC,UAA2B,EAAkB,EAAE;IAC5E,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,IAAI,UAAU,CAAC,aAAa,CAAC;IAErE,IAAI,UAAU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qB,CAAC,KAAK,CAAC;YAC7C,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC5C,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;YACjD,SAAS,EAAE,KAAK,CAAC,UAAU;YAC3B,aAAa,EAAE,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;YACvE,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YAC9E,YAAY,EAAE,KAAK,CAAC,MAAM;SAC3B,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAChC,CAAC","sourcesContent":["import { IOrder, providePendingOrdersService } from '@yuants/data-order';\nimport { Terminal } from '@yuants/protocol';\nimport { encodePath } from '@yuants/utils';\nimport { ACCOUNT_ID } from './account';\nimport { getFApiV1OpenOrders } from './api';\n\nconst terminal = Terminal.fromNodeEnv();\n\ntype OrderDirection = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT';\n\ninterface IAsterOpenOrder {\n orderId: number;\n symbol: string;\n side: 'BUY' | 'SELL';\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n reduceOnly?: boolean;\n closePosition?: boolean;\n type: string;\n origQty: string;\n executedQty: string;\n price: string;\n avgPrice: string;\n status: string;\n updateTime: number;\n}\n\nconst resolveOrderDirection = (asterOrder: IAsterOpenOrder): 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\nprovidePendingOrdersService(\n terminal,\n ACCOUNT_ID,\n async () => {\n const orders = (await getFApiV1OpenOrders({})) as IAsterOpenOrder[];\n return orders.map((order) => {\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 const mapped: IOrder = {\n order_id: `${order.orderId}`,\n account_id: ACCOUNT_ID,\n product_id: encodePath('PERPETUAL', order.symbol),\n order_type: order.type,\n order_direction: resolveOrderDirection(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 return mapped;\n });\n },\n { auto_refresh_interval: 2000 },\n);\n"]}
|
package/lib/product.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../src/product.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,sDA4C1B,CAAC"}
|
package/lib/product.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"product.js","sourceRoot":"","sources":["../src/product.ts"],"names":[],"mappings":";;;AAAA,uDAAoG;AACpG,+CAA4C;AAC5C,yCAA2C;AAC3C,+BAA8C;AAE9C,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,0CAA0C;AAC7B,QAAA,c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AAC;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';\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"]}
|
package/lib/quote.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quote.js","sourceRoot":"","sources":["../src/quote.ts"],"names":[],"mappings":";;AAAA,yCAA4C;AAC5C,+CAA4C;AAC5C,qCAAyC;AACzC,yCAAuD;AACvD,+BAAsF;AAEtF,+BAAoE;AAEpE,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,2BAAqB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,YAAY,CAAC;KAC1B;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,IAAI,CAAC,8BAA8B,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAC5D,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,EACD,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAC9B,CAAC;AAEF,MAAM,MAAM,GAAG,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,0BAAoB,EAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CACvD,IAAA,eAAQ,EAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,EACpC,IAAA,eAAQ,EACN,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,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 { 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 type { IQuote } from '../../../libraries/data-quote/lib';\nimport { getFApiV1OpenInterest, getFApiV1TickerPrice } from './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"]}
|
package/lib/sapi.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 获取账户信息 (现货)
|
|
3
|
-
*
|
|
4
|
-
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data
|
|
5
|
-
*/
|
|
6
|
-
export declare const getApiV1Account: (params: {}) => Promise<{
|
|
7
|
-
feeTier: number;
|
|
8
|
-
canTrade: boolean;
|
|
9
|
-
canDeposit: boolean;
|
|
10
|
-
canWithdraw: boolean;
|
|
11
|
-
canBurnAsset: boolean;
|
|
12
|
-
updateTime: number;
|
|
13
|
-
balances: {
|
|
14
|
-
asset: string;
|
|
15
|
-
free: string;
|
|
16
|
-
locked: string;
|
|
17
|
-
}[];
|
|
18
|
-
}>;
|
|
19
|
-
/**
|
|
20
|
-
* 获取最新价格
|
|
21
|
-
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC
|
|
22
|
-
*/
|
|
23
|
-
export declare const getApiV1TickerPrice: (params: {}) => Promise<{
|
|
24
|
-
symbol: string;
|
|
25
|
-
price: string;
|
|
26
|
-
time: number;
|
|
27
|
-
}[]>;
|
|
28
|
-
export declare const postApiV1Order: (params: {
|
|
29
|
-
symbol: string;
|
|
30
|
-
side: 'BUY' | 'SELL';
|
|
31
|
-
type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';
|
|
32
|
-
timeInForce?: "GTC" | "IOC" | "FOK" | "GTX" | undefined;
|
|
33
|
-
quantity?: number | undefined;
|
|
34
|
-
quoteOrderQty?: number | undefined;
|
|
35
|
-
price?: number | undefined;
|
|
36
|
-
}) => Promise<{}>;
|
|
37
|
-
//# sourceMappingURL=sapi.d.ts.map
|
package/lib/sapi.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sapi.d.ts","sourceRoot":"","sources":["../src/sapi.ts"],"names":[],"mappings":"AAyDA;;;;GAIG;AACH,eAAO,MAAM,eAAe;aAGf,MAAM;cACL,OAAO;gBACL,OAAO;iBACN,OAAO;kBACN,OAAO;gBACT,MAAM;cACR;QACR,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KAChB,EAAE;EAEiC,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,mBAAmB;YAGpB,MAAM;WACP,MAAM;UACP,MAAM;IAE+B,CAAC;AAEhD,eAAO,MAAM,cAAc;YAEf,MAAM;UACR,KAAK,GAAG,MAAM;UACd,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,GAAG,aAAa,GAAG,oBAAoB;;;;;iBAOzD,CAAC"}
|
package/lib/sapi.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.postApiV1Order = exports.getApiV1TickerPrice = exports.getApiV1Account = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
const API_KEY = process.env.API_KEY;
|
|
6
|
-
const SECRET_KEY = process.env.SECRET_KEY;
|
|
7
|
-
const BASE_URL = 'https://sapi.asterdex.com';
|
|
8
|
-
const request = async (type, method, endpoint, params = {}) => {
|
|
9
|
-
const needApiKey = type !== 'NONE';
|
|
10
|
-
const needSign = type === 'TRADE' || type === 'USER_DATA';
|
|
11
|
-
const url = new URL(BASE_URL);
|
|
12
|
-
url.pathname = endpoint;
|
|
13
|
-
for (const [key, value] of Object.entries(params)) {
|
|
14
|
-
if (value === undefined)
|
|
15
|
-
continue;
|
|
16
|
-
url.searchParams.set(key, `${value}`);
|
|
17
|
-
}
|
|
18
|
-
if (needSign) {
|
|
19
|
-
url.searchParams.set('timestamp', `${Date.now()}`);
|
|
20
|
-
const msg = url.search.slice(1); // 去掉开头的 '?'
|
|
21
|
-
const signature = await (0, utils_1.opensslEquivalentHMAC)(msg, SECRET_KEY);
|
|
22
|
-
url.searchParams.set('signature', signature);
|
|
23
|
-
}
|
|
24
|
-
console.info(url.toString());
|
|
25
|
-
const response = await fetch(url.toString(), {
|
|
26
|
-
method,
|
|
27
|
-
headers: needApiKey
|
|
28
|
-
? {
|
|
29
|
-
'X-MBX-APIKEY': API_KEY,
|
|
30
|
-
}
|
|
31
|
-
: {},
|
|
32
|
-
}).then((response) => response.json());
|
|
33
|
-
if (response.code && response.code !== 0) {
|
|
34
|
-
throw JSON.stringify(response);
|
|
35
|
-
}
|
|
36
|
-
return response;
|
|
37
|
-
};
|
|
38
|
-
const createApi = (type, method, endpoint) => (params) => request(type, method, endpoint, params);
|
|
39
|
-
/**
|
|
40
|
-
* 获取账户信息 (现货)
|
|
41
|
-
*
|
|
42
|
-
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data
|
|
43
|
-
*/
|
|
44
|
-
exports.getApiV1Account = createApi('USER_DATA', 'GET', '/api/v1/account');
|
|
45
|
-
/**
|
|
46
|
-
* 获取最新价格
|
|
47
|
-
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC
|
|
48
|
-
*/
|
|
49
|
-
exports.getApiV1TickerPrice = createApi('MARKET_DATA', 'GET', '/api/v1/ticker/price');
|
|
50
|
-
exports.postApiV1Order = createApi('TRADE', 'POST', '/api/v1/order');
|
|
51
|
-
//# sourceMappingURL=sapi.js.map
|
package/lib/sapi.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sapi.js","sourceRoot":"","sources":["../src/sapi.ts"],"names":[],"mappings":";;;AAAA,mCAAgD;AAEhD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAQ,CAAC;AACrC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAW,CAAC;AAE3C,MAAM,QAAQ,GAAG,2BAA2B,CAAC;AAE7C,MAAM,OAAO,GAAG,KAAK,EACnB,IAAoE,EACpE,MAAc,EACd,QAAgB,EAChB,SAAc,EAAE,EACJ,EAAE;IACd,MAAM,UAAU,GAAG,IAAI,KAAK,MAAM,CAAC;IACnC,MAAM,QAAQ,GAAG,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,WAAW,CAAC;IAE1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;KACvC;IAED,IAAI,QAAQ,EAAE;QACZ,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC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Content":["import { opensslEquivalentHMAC } from './utils';\n\nconst API_KEY = process.env.API_KEY!;\nconst SECRET_KEY = process.env.SECRET_KEY!;\n\nconst BASE_URL = 'https://sapi.asterdex.com';\n\nconst request = async <T>(\n type: 'NONE' | 'TRADE' | 'USER_DATA' | 'USER_STREAM' | 'MARKET_DATA',\n method: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const needApiKey = type !== 'NONE';\n const needSign = type === 'TRADE' || type === 'USER_DATA';\n\n const url = new URL(BASE_URL);\n url.pathname = endpoint;\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined) continue;\n url.searchParams.set(key, `${value}`);\n }\n\n if (needSign) {\n url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = await opensslEquivalentHMAC(msg, SECRET_KEY);\n url.searchParams.set('signature', signature);\n }\n\n console.info(url.toString());\n\n const response = await fetch(url.toString(), {\n method,\n headers: needApiKey\n ? {\n 'X-MBX-APIKEY': API_KEY,\n }\n : {},\n }).then((response) => response.json() as any);\n\n if (response.code && response.code !== 0) {\n throw JSON.stringify(response);\n }\n\n return response;\n};\n\nconst createApi =\n <TReq, TRes>(\n type: 'NONE' | 'TRADE' | 'USER_DATA' | 'USER_STREAM' | 'MARKET_DATA',\n method: string,\n endpoint: string,\n ) =>\n (params: TReq) =>\n request<TRes>(type, method, endpoint, params);\n\n/**\n * 获取账户信息 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data\n */\nexport const getApiV1Account = createApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n canBurnAsset: boolean;\n updateTime: number;\n balances: {\n asset: string;\n free: string;\n locked: string;\n }[];\n }\n>('USER_DATA', 'GET', '/api/v1/account');\n\n/**\n * 获取最新价格\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC\n */\nexport const getApiV1TickerPrice = createApi<\n {},\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n>('MARKET_DATA', 'GET', '/api/v1/ticker/price');\n\nexport const postApiV1Order = createApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX';\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n },\n {}\n>('TRADE', 'POST', '/api/v1/order');\n"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|