@yuants/vendor-aster 0.5.7 → 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAe,cAAc,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE1G,MAAM,uBAAuB,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;;IACpG,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC;IAEhC,MAAM,IAAI,GAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAY,CAAC,KAAK,CAAC,UAAW,CAAC,CAAC;IAChG,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;IAE1E,MAAM,IAAI,GAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAY,CACtG,KAAK,CAAC,eAAgB,CACvB,CAAC;IACF,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;IAEpF,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,C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UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAE5G,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,UAAU,EAAE;QAC5C,MAAM;QACN,IAAI;QACJ,IAAI;QACJ,QAAQ;QACR,KAAK;QACL,WAAW;QACX,YAAY;QACZ,UAAU;KACX,CAAC,CAAC;IAEH,MAAM,OAAO,GACX,MAAA,MAAA,MAAC,GAAW,aAAX,GAAG,uBAAH,GAAG,CAAU,OAAO,mCACpB,GAAW,aAAX,GAAG,uBAAH,GAAG,CAAU,QAAQ,mCACtB,MAAC,GAAW,aAAX,GAAG,uBAAH,GAAG,CAAU,IAAI,0CAAE,OAAO,mCAC3B,MAAC,GAAW,aAAX,GAAG,uBAAH,GAAG,CAAU,IAAI,0CAAE,QAAQ,CAAC;IAE/B,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAE3E,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,EAAE,CAAC;AACpC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IACrG,IAAI,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACtC,OAAO,uBAAuB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KACnD;IACD,IAAI,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACtC,OAAO,uBAAuB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;KACnD;IACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;AACjF,CAAC,CAAC","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { decodePath, roundToStep } from '@yuants/utils';\nimport { getApiV1TickerPrice, ICredential, postApiV1Order, postFApiV1Order } from '../../api/private-api';\n\nconst handleSubmitOrderOfSpot: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n const symbol = order.product_id;\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 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 timeInForce = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const price = order.price;\n\n let quantity: number | undefined = order.volume;\n let quoteOrderQty: number | undefined;\n\n if (type === 'MARKET' && side === 'BUY') {\n const spotPrice = await getApiV1TickerPrice(credential, {});\n const thePrice = spotPrice.find((x) => x.symbol === symbol)?.price;\n if (!thePrice) throw new Error(`Cannot get price for symbol ${symbol}`);\n quantity = undefined;\n quoteOrderQty = roundToStep(order.volume * +thePrice, 0.01);\n }\n\n const res = await postApiV1Order(credential, {\n symbol,\n type,\n side,\n timeInForce,\n price,\n quantity,\n quoteOrderQty,\n });\n\n if (!res.orderId) {\n throw new Error('Failed to retrieve order ID from response');\n }\n\n return { order_id: '' + res.orderId };\n};\n\nconst handleSubmitOrderOfPerp: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\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 = order.order_type === 'MAKER' ? 'GTX' : order.order_type === 'LIMIT' ? 'GTC' : undefined;\n\n const res = await postFApiV1Order(credential, {\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 if (!orderId) throw new Error('Failed to retrieve order ID from response');\n\n return { order_id: `${orderId}` };\n};\n\nexport const handleSubmitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (order.account_id.includes('/SPOT')) {\n return handleSubmitOrderOfSpot(credential, order);\n }\n if (order.account_id.includes('/PERP')) {\n return handleSubmitOrderOfPerp(credential, order);\n }\n throw new Error(`Unsupported account_id for SubmitOrder: ${order.account_id}`);\n};\n"]}
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export function
|
|
2
|
-
const bytes = new Uint8Array(buffer);
|
|
1
|
+
export function uint8ArrayToHex(bytes) {
|
|
3
2
|
const hexArray = [];
|
|
4
3
|
for (const byte of bytes) {
|
|
5
4
|
const hex = byte.toString(16).padStart(2, '0');
|
|
@@ -7,22 +6,4 @@ export function arrayBufferToHex(buffer) {
|
|
|
7
6
|
}
|
|
8
7
|
return hexArray.join('');
|
|
9
8
|
}
|
|
10
|
-
export async function opensslEquivalentHMAC(message, secretKey) {
|
|
11
|
-
try {
|
|
12
|
-
const keyBuffer = new TextEncoder().encode(secretKey);
|
|
13
|
-
const messageBuffer = new TextEncoder().encode(message);
|
|
14
|
-
// 导入密钥
|
|
15
|
-
const cryptoKey = await crypto.subtle.importKey('raw', keyBuffer, {
|
|
16
|
-
name: 'HMAC',
|
|
17
|
-
hash: { name: 'SHA-256' },
|
|
18
|
-
}, false, ['sign']);
|
|
19
|
-
// 进行 HMAC-SHA256 签名
|
|
20
|
-
const signature = await crypto.subtle.sign('HMAC', cryptoKey, messageBuffer);
|
|
21
|
-
// 转换为16进制小写(与 openssl 输出格式一致)
|
|
22
|
-
return arrayBufferToHex(signature);
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
throw new Error(`HMAC-SHA256 签名失败: ${error}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
9
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC/C,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACpB;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["export function uint8ArrayToHex(bytes: Uint8Array): string {\n const hexArray: string[] = [];\n\n for (const byte of bytes) {\n const hex = byte.toString(16).padStart(2, '0');\n hexArray.push(hex);\n }\n\n return hexArray.join('');\n}\n"]}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
export interface ICredential {
|
|
2
|
+
address: string;
|
|
3
|
+
api_key: string;
|
|
4
|
+
secret_key: string;
|
|
5
|
+
}
|
|
1
6
|
/**
|
|
2
7
|
* 获取账户信息
|
|
3
8
|
*
|
|
4
9
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data
|
|
5
10
|
*/
|
|
6
|
-
export declare const getFApiV4Account: (params: {}) => Promise<{
|
|
11
|
+
export declare const getFApiV4Account: (credential: ICredential, params: {}) => Promise<{
|
|
7
12
|
feeTier: number;
|
|
8
13
|
canTrade: boolean;
|
|
9
14
|
canDeposit: boolean;
|
|
@@ -54,7 +59,7 @@ export declare const getFApiV4Account: (params: {}) => Promise<{
|
|
|
54
59
|
updateTime: number;
|
|
55
60
|
}[];
|
|
56
61
|
}>;
|
|
57
|
-
export declare const getFApiV2Balance: (params: {}) => Promise<{
|
|
62
|
+
export declare const getFApiV2Balance: (credential: ICredential, params: {}) => Promise<{
|
|
58
63
|
accountAlias: string;
|
|
59
64
|
asset: string;
|
|
60
65
|
balance: string;
|
|
@@ -65,39 +70,17 @@ export declare const getFApiV2Balance: (params: {}) => Promise<{
|
|
|
65
70
|
marginAvailable: boolean;
|
|
66
71
|
updateTime: number;
|
|
67
72
|
}[]>;
|
|
68
|
-
export declare const
|
|
69
|
-
symbol: string;
|
|
70
|
-
price: string;
|
|
71
|
-
time?: number | undefined;
|
|
72
|
-
}[]>;
|
|
73
|
-
export declare const getFApiV1OpenInterest: (params: {
|
|
74
|
-
symbol: string;
|
|
75
|
-
}) => Promise<{
|
|
76
|
-
symbol: string;
|
|
77
|
-
openInterest: string;
|
|
78
|
-
time: number;
|
|
79
|
-
}>;
|
|
80
|
-
export declare const getFApiV1FundingRate: (params: {
|
|
81
|
-
symbol?: string | undefined;
|
|
82
|
-
startTime?: number | undefined;
|
|
83
|
-
endTime?: number | undefined;
|
|
84
|
-
limit?: number | undefined;
|
|
85
|
-
}) => Promise<{
|
|
86
|
-
symbol: string;
|
|
87
|
-
fundingRate: string;
|
|
88
|
-
fundingTime: number;
|
|
89
|
-
}[]>;
|
|
90
|
-
export declare const postFApiV1Order: (params: {
|
|
73
|
+
export declare const postFApiV1Order: (credential: ICredential, params: {
|
|
91
74
|
symbol: string;
|
|
92
75
|
side: 'BUY' | 'SELL';
|
|
93
|
-
positionSide?: "
|
|
76
|
+
positionSide?: "BOTH" | "LONG" | "SHORT" | undefined;
|
|
94
77
|
type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET' | 'TRAILING_STOP_MARKET';
|
|
95
78
|
reduceOnly?: "true" | "false" | undefined;
|
|
96
79
|
quantity?: number | undefined;
|
|
97
80
|
price?: number | undefined;
|
|
98
81
|
timeInForce?: "GTC" | "IOC" | "FOK" | "GTX" | "HIDDEN" | undefined;
|
|
99
82
|
}) => Promise<{}>;
|
|
100
|
-
export declare const getFApiV1OpenOrders: (params: {
|
|
83
|
+
export declare const getFApiV1OpenOrders: (credential: ICredential, params: {
|
|
101
84
|
symbol?: string | undefined;
|
|
102
85
|
}) => Promise<{
|
|
103
86
|
orderId: number;
|
|
@@ -113,37 +96,54 @@ export declare const getFApiV1OpenOrders: (params: {
|
|
|
113
96
|
avgPrice: string;
|
|
114
97
|
reduceOnly?: boolean | undefined;
|
|
115
98
|
closePosition?: boolean | undefined;
|
|
116
|
-
positionSide?: "
|
|
99
|
+
positionSide?: "BOTH" | "LONG" | "SHORT" | undefined;
|
|
117
100
|
workingType?: string | undefined;
|
|
118
101
|
priceProtect?: boolean | undefined;
|
|
119
102
|
origType?: string | undefined;
|
|
120
103
|
stopPrice?: string | undefined;
|
|
121
104
|
symbol: string;
|
|
122
105
|
}[]>;
|
|
123
|
-
export declare const deleteFApiV1Order: (params: {
|
|
106
|
+
export declare const deleteFApiV1Order: (credential: ICredential, params: {
|
|
124
107
|
symbol: string;
|
|
125
108
|
orderId?: string | number | undefined;
|
|
126
109
|
origClientOrderId?: string | undefined;
|
|
127
110
|
}) => Promise<{}>;
|
|
128
111
|
/**
|
|
129
|
-
*
|
|
112
|
+
* 获取账户信息 (现货)
|
|
130
113
|
*
|
|
131
|
-
* https://github.com/asterdex/api-docs/blob/master/aster-finance-
|
|
114
|
+
* 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
|
|
132
115
|
*/
|
|
133
|
-
export declare const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
[key: string]: any;
|
|
145
|
-
filterType: string;
|
|
146
|
-
}[];
|
|
116
|
+
export declare const getApiV1Account: (credential: ICredential, params: {}) => Promise<{
|
|
117
|
+
feeTier: number;
|
|
118
|
+
canTrade: boolean;
|
|
119
|
+
canDeposit: boolean;
|
|
120
|
+
canWithdraw: boolean;
|
|
121
|
+
canBurnAsset: boolean;
|
|
122
|
+
updateTime: number;
|
|
123
|
+
balances: {
|
|
124
|
+
asset: string;
|
|
125
|
+
free: string;
|
|
126
|
+
locked: string;
|
|
147
127
|
}[];
|
|
148
128
|
}>;
|
|
149
|
-
|
|
129
|
+
/**
|
|
130
|
+
* 获取最新价格
|
|
131
|
+
* 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
|
|
132
|
+
*/
|
|
133
|
+
export declare const getApiV1TickerPrice: (credential: ICredential, params: {}) => Promise<{
|
|
134
|
+
symbol: string;
|
|
135
|
+
price: string;
|
|
136
|
+
time: number;
|
|
137
|
+
}[]>;
|
|
138
|
+
export declare const postApiV1Order: (credential: ICredential, params: {
|
|
139
|
+
symbol: string;
|
|
140
|
+
side: 'BUY' | 'SELL';
|
|
141
|
+
type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';
|
|
142
|
+
timeInForce?: "GTC" | "IOC" | "FOK" | "GTX" | undefined;
|
|
143
|
+
quantity?: number | undefined;
|
|
144
|
+
quoteOrderQty?: number | undefined;
|
|
145
|
+
price?: number | undefined;
|
|
146
|
+
}) => Promise<{
|
|
147
|
+
orderId: number;
|
|
148
|
+
}>;
|
|
149
|
+
//# sourceMappingURL=private-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-api.d.ts","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AA6CD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,eAXd,WAAW;aAcb,MAAM;cACL,OAAO;gBACL,OAAO;iBACN,OAAO;gBACR,MAAM;wBACE,MAAM;sBACR,MAAM;wBACJ,MAAM;2BACH,MAAM;wBACT,MAAM;gCACE,MAAM;iCACL,MAAM;6BACV,MAAM;qBACd,MAAM;sBACL,MAAM;uBACL,MAAM;YACjB;QACN,KAAK,EAAE,MAAM,CAAC;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,gBAAgB,EAAE,MAAM,CAAC;QACzB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,qBAAqB,EAAE,MAAM,CAAC;QAC9B,sBAAsB,EAAE,MAAM,CAAC;QAC/B,iBAAiB,EAAE,MAAM,CAAC;QAC1B,kBAAkB,EAAE,MAAM,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB,EAAE,MAAM,CAAC;QACzB,eAAe,EAAE,OA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AAe,eA/Ib,WAAW;aAkJb,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;EAEoB,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,mBAAmB,eApKjB,WAAW;YAuKd,MAAM;WACP,MAAM;UACP,MAAM;IAEgB,CAAC;AAEjC,eAAO,MAAM,cAAc,eA7KZ,WAAW;YA+Kd,MAAM;UACR,KAAK,GAAG,MAAM;UACd,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,GAAG,aAAa,GAAG,oBAAoB;;;;;;aAO/E,MAAM;EAEO,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postApiV1Order = exports.getApiV1TickerPrice = exports.getApiV1Account = exports.deleteFApiV1Order = exports.getFApiV1OpenOrders = exports.postFApiV1Order = exports.getFApiV2Balance = exports.getFApiV4Account = void 0;
|
|
4
|
+
const utils_1 = require("@yuants/utils");
|
|
5
|
+
const utils_2 = require("../utils");
|
|
6
|
+
const request = async (credential, method, baseURL, endpoint, params = {}) => {
|
|
7
|
+
const url = new URL(baseURL);
|
|
8
|
+
url.pathname = endpoint;
|
|
9
|
+
for (const [key, value] of Object.entries(params)) {
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
continue;
|
|
12
|
+
url.searchParams.set(key, `${value}`);
|
|
13
|
+
}
|
|
14
|
+
url.searchParams.set('timestamp', `${Date.now()}`);
|
|
15
|
+
const msg = url.search.slice(1); // 去掉开头的 '?'
|
|
16
|
+
const signature = (0, utils_2.uint8ArrayToHex)(await (0, utils_1.HmacSHA256)(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)));
|
|
17
|
+
url.searchParams.set('signature', signature);
|
|
18
|
+
console.info(url.toString());
|
|
19
|
+
const res = await fetch(url.toString(), {
|
|
20
|
+
method,
|
|
21
|
+
headers: {
|
|
22
|
+
'X-MBX-APIKEY': credential.api_key,
|
|
23
|
+
},
|
|
24
|
+
}).then((response) => response.json());
|
|
25
|
+
if (res.code && res.code !== 0) {
|
|
26
|
+
throw JSON.stringify(res);
|
|
27
|
+
}
|
|
28
|
+
return res;
|
|
29
|
+
};
|
|
30
|
+
const createApi = (baseURL) => (method, endpoint) => (credential, params) => request(credential, method, baseURL, endpoint, params);
|
|
31
|
+
const createFutureApi = createApi('https://fapi.asterdex.com');
|
|
32
|
+
const createSpotApi = createApi('https://sapi.asterdex.com');
|
|
33
|
+
/**
|
|
34
|
+
* 获取账户信息
|
|
35
|
+
*
|
|
36
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data
|
|
37
|
+
*/
|
|
38
|
+
exports.getFApiV4Account = createFutureApi('GET', '/fapi/v4/account');
|
|
39
|
+
exports.getFApiV2Balance = createFutureApi('GET', '/fapi/v2/balance');
|
|
40
|
+
exports.postFApiV1Order = createFutureApi('POST', '/fapi/v1/order');
|
|
41
|
+
exports.getFApiV1OpenOrders = createFutureApi('GET', '/fapi/v1/openOrders');
|
|
42
|
+
exports.deleteFApiV1Order = createFutureApi('DELETE', '/fapi/v1/order');
|
|
43
|
+
/**
|
|
44
|
+
* 获取账户信息 (现货)
|
|
45
|
+
*
|
|
46
|
+
* 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
|
|
47
|
+
*/
|
|
48
|
+
exports.getApiV1Account = createSpotApi('GET', '/api/v1/account');
|
|
49
|
+
/**
|
|
50
|
+
* 获取最新价格
|
|
51
|
+
* 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
|
|
52
|
+
*/
|
|
53
|
+
exports.getApiV1TickerPrice = createSpotApi('GET', '/api/v1/ticker/price');
|
|
54
|
+
exports.postApiV1Order = createSpotApi('POST', '/api/v1/order');
|
|
55
|
+
//# sourceMappingURL=private-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAC3C,oCAA2C;AAQ3C,MAAM,OAAO,GAAG,KAAK,EACnB,UAAuB,EACvB,MAAc,EACd,OAAe,EACf,QAAgB,EAChB,SAAc,EAAE,EACJ,EAAE;IACd,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,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,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;IAC7C,MAAM,SAAS,GAAG,IAAA,uBAAe,EAC/B,MAAM,IAAA,kBAAU,EAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CACjG,CAAC;IACF,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAE7C,OA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aAAa,CAe1C,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAE5B;;;GAGG;AACU,QAAA,mBAAmB,GAAG,aAAa,CAO9C,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAEpB,QAAA,cAAc,GAAG,aAAa,CAazC,MAAM,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { HmacSHA256 } from '@yuants/utils';\nimport { uint8ArrayToHex } from '../utils';\n\nexport interface ICredential {\n address: string;\n api_key: string;\n secret_key: string;\n}\n\nconst request = async <T>(\n credential: ICredential,\n method: string,\n baseURL: string,\n endpoint: string,\n params: any = {},\n): Promise<T> => {\n const url = new URL(baseURL);\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 url.searchParams.set('timestamp', `${Date.now()}`);\n const msg = url.search.slice(1); // 去掉开头的 '?'\n const signature = uint8ArrayToHex(\n await HmacSHA256(new TextEncoder().encode(msg), new TextEncoder().encode(credential.secret_key)),\n );\n url.searchParams.set('signature', signature);\n\n console.info(url.toString());\n const res = await fetch(url.toString(), {\n method,\n headers: {\n 'X-MBX-APIKEY': credential.api_key,\n },\n }).then((response) => response.json());\n if (res.code && res.code !== 0) {\n throw JSON.stringify(res);\n }\n return res;\n};\n\nconst createApi =\n (baseURL: string) =>\n <TReq, TRes>(method: string, endpoint: string) =>\n (credential: ICredential, params: TReq) =>\n request<TRes>(credential, method, baseURL, endpoint, params);\n\nconst createFutureApi = createApi('https://fapi.asterdex.com');\nconst createSpotApi = createApi('https://sapi.asterdex.com');\n\n/**\n * 获取账户信息\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AFv4-user_data\n */\nexport const getFApiV4Account = createFutureApi<\n {},\n {\n feeTier: number;\n canTrade: boolean;\n canDeposit: boolean;\n canWithdraw: boolean;\n updateTime: number;\n totalInitialMargin: string;\n totalMaintMargin: string;\n totalWalletBalance: string;\n totalUnrealizedProfit: string;\n totalMarginBalance: string;\n totalPositionInitialMargin: string;\n totalOpenOrderInitialMargin: string;\n totalCrossWalletBalance: string;\n totalCrossUnPnl: string;\n availableBalance: string;\n maxWithdrawAmount: string;\n assets: {\n asset: string;\n walletBalance: string;\n unrealizedProfit: string;\n marginBalance: string;\n maintMargin: string;\n initialMargin: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n maxWithdrawAmount: string;\n crossWalletBalance: string;\n crossUnPnl: string;\n availableBalance: string;\n marginAvailable: boolean;\n updateTime: number;\n }[];\n positions: {\n symbol: string;\n initialMargin: string;\n maintMargin: string;\n unrealizedProfit: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n leverage: string;\n isolated: boolean;\n entryPrice: string;\n maxNotional: string;\n positionSide: 'BOTH' | 'LONG' | 'SHORT';\n positionAmt: string;\n notional: string;\n isolatedWallet: string;\n updateTime: number;\n }[];\n }\n>('GET', '/fapi/v4/account');\n\nexport const getFApiV2Balance = createFutureApi<\n {},\n {\n accountAlias: string; // 账户唯一识别码\n asset: string; // 资产\n balance: string; // 总余额\n crossWalletBalance: string; // 全仓余额\n crossUnPnl: string; // 全仓持仓未实现盈亏\n availableBalance: string; // 下单可用余额\n maxWithdrawAmount: string; // 最大可转出余额\n marginAvailable: boolean; // 是否可用作联合保证金\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/balance');\n\nexport const postFApiV1Order = createFutureApi<\n {\n symbol: string;\n side: 'BUY' | 'SELL';\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n type:\n | 'MARKET'\n | 'LIMIT'\n | 'STOP'\n | 'STOP_MARKET'\n | 'TAKE_PROFIT'\n | 'TAKE_PROFIT_MARKET'\n | 'TRAILING_STOP_MARKET';\n reduceOnly?: 'true' | 'false';\n quantity?: number;\n price?: number;\n timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX' | 'HIDDEN';\n },\n {}\n>('POST', '/fapi/v1/order');\n\nexport const getFApiV1OpenOrders = createFutureApi<\n {\n symbol?: string;\n },\n {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n updateTime: number;\n avgPrice: string;\n reduceOnly?: boolean;\n closePosition?: boolean;\n positionSide?: 'BOTH' | 'LONG' | 'SHORT';\n workingType?: string;\n priceProtect?: boolean;\n origType?: string;\n stopPrice?: string;\n symbol: string;\n }[]\n>('GET', '/fapi/v1/openOrders');\n\nexport const deleteFApiV1Order = createFutureApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/fapi/v1/order');\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 = createSpotApi<\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>('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 = createSpotApi<\n {},\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n>('GET', '/api/v1/ticker/price');\n\nexport const postApiV1Order = createSpotApi<\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 orderId: number; // 系统的订单ID\n }\n>('POST', '/api/v1/order');\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取资金费率历史
|
|
3
|
+
*
|
|
4
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E6%9F%A5%E8%AF%A2%E8%B5%84%E9%87%91%E8%B4%B9%E7%8E%87%E5%8E%86%E5%8F%B2
|
|
5
|
+
*/
|
|
6
|
+
export declare const getFApiV1FundingRate: (params: {
|
|
7
|
+
symbol?: string | undefined;
|
|
8
|
+
startTime?: number | undefined;
|
|
9
|
+
endTime?: number | undefined;
|
|
10
|
+
limit?: number | undefined;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
symbol: string;
|
|
13
|
+
fundingRate: string;
|
|
14
|
+
fundingTime: number;
|
|
15
|
+
}[]>;
|
|
16
|
+
/**
|
|
17
|
+
* 获取交易对信息
|
|
18
|
+
*
|
|
19
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E4%BA%A4%E6%98%93%E5%AF%B9%E4%BF%A1%E6%81%AF
|
|
20
|
+
*/
|
|
21
|
+
export declare const getFApiV1ExchangeInfo: (params: {}) => Promise<{
|
|
22
|
+
symbols: {
|
|
23
|
+
symbol: string;
|
|
24
|
+
status: 'TRADING' | 'BREAK' | 'HALT';
|
|
25
|
+
baseAsset: string;
|
|
26
|
+
quoteAsset: string;
|
|
27
|
+
pricePrecision: number;
|
|
28
|
+
quantityPrecision: number;
|
|
29
|
+
baseAssetPrecision: number;
|
|
30
|
+
quotePrecision: number;
|
|
31
|
+
filters: {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
filterType: string;
|
|
34
|
+
}[];
|
|
35
|
+
}[];
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* 获取未平仓合约数量
|
|
39
|
+
*
|
|
40
|
+
* 无 API 文档 (weird)
|
|
41
|
+
*/
|
|
42
|
+
export declare const getFApiV1OpenInterest: (params: {
|
|
43
|
+
symbol: string;
|
|
44
|
+
}) => Promise<{
|
|
45
|
+
symbol: string;
|
|
46
|
+
openInterest: string;
|
|
47
|
+
time: number;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* 获取最新价格
|
|
51
|
+
*
|
|
52
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC
|
|
53
|
+
*/
|
|
54
|
+
export declare const getFApiV1TickerPrice: (params: {}) => Promise<{
|
|
55
|
+
symbol: string;
|
|
56
|
+
price: string;
|
|
57
|
+
time?: number | undefined;
|
|
58
|
+
}[]>;
|
|
59
|
+
//# sourceMappingURL=public-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;YAQrB,MAAM;iBACD,MAAM;iBACN,MAAM;IAES,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;gBAIpB,MAAM;gBACN,SAAS,GAAG,OAAO,GAAG,MAAM;mBACzB,MAAM;oBACL,MAAM;wBACF,MAAM;2BACH,MAAM;4BACL,MAAM;wBACV,MAAM;;;wBAER,MAAM;;;EAKO,CAAC;AAElC;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;YAEtB,MAAM;;YAGN,MAAM;kBACA,MAAM;UACd,MAAM;EAEiB,CAAC;AAElC;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;YAGrB,MAAM;WACP,MAAM;;IAGgB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFApiV1TickerPrice = exports.getFApiV1OpenInterest = exports.getFApiV1ExchangeInfo = exports.getFApiV1FundingRate = void 0;
|
|
4
|
+
const BASE_URL = 'https://fapi.asterdex.com';
|
|
5
|
+
const request = async (method, endpoint, params = {}) => {
|
|
6
|
+
const url = new URL(BASE_URL);
|
|
7
|
+
url.pathname = endpoint;
|
|
8
|
+
for (const [key, value] of Object.entries(params)) {
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
continue;
|
|
11
|
+
url.searchParams.set(key, `${value}`);
|
|
12
|
+
}
|
|
13
|
+
console.info(url.toString());
|
|
14
|
+
const res = await fetch(url.toString(), {
|
|
15
|
+
method,
|
|
16
|
+
}).then((response) => response.json());
|
|
17
|
+
if (res.code && res.code !== 0) {
|
|
18
|
+
throw JSON.stringify(res);
|
|
19
|
+
}
|
|
20
|
+
return res;
|
|
21
|
+
};
|
|
22
|
+
const createApi = (method, endpoint) => (params) => request(method, endpoint, params);
|
|
23
|
+
/**
|
|
24
|
+
* 获取资金费率历史
|
|
25
|
+
*
|
|
26
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E6%9F%A5%E8%AF%A2%E8%B5%84%E9%87%91%E8%B4%B9%E7%8E%87%E5%8E%86%E5%8F%B2
|
|
27
|
+
*/
|
|
28
|
+
exports.getFApiV1FundingRate = createApi('GET', '/fapi/v1/fundingRate');
|
|
29
|
+
/**
|
|
30
|
+
* 获取交易对信息
|
|
31
|
+
*
|
|
32
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E4%BA%A4%E6%98%93%E5%AF%B9%E4%BF%A1%E6%81%AF
|
|
33
|
+
*/
|
|
34
|
+
exports.getFApiV1ExchangeInfo = createApi('GET', '/fapi/v1/exchangeInfo');
|
|
35
|
+
/**
|
|
36
|
+
* 获取未平仓合约数量
|
|
37
|
+
*
|
|
38
|
+
* 无 API 文档 (weird)
|
|
39
|
+
*/
|
|
40
|
+
exports.getFApiV1OpenInterest = createApi('GET', '/fapi/v1/openInterest');
|
|
41
|
+
/**
|
|
42
|
+
* 获取最新价格
|
|
43
|
+
*
|
|
44
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC
|
|
45
|
+
*/
|
|
46
|
+
exports.getFApiV1TickerPrice = createApi('GET', '/fapi/v1/ticker/price');
|
|
47
|
+
//# sourceMappingURL=public-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":";;;AAAA,MAAM,QAAQ,GAAG,2BAA2B,CAAC;AAE7C,MAAM,OAAO,GAAG,KAAK,EAAK,MAAc,EAAE,QAAgB,EAAE,SAAc,EAAE,EAAc,EAAE;IAC1F,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,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;QACtC,MAAM;KACP,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,EAAE;QAC9B,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;KAC3B;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,SAAS,GACb,CAAa,MAAc,EAAE,QAAgB,EAAE,EAAE,CACjD,CAAC,MAAY,EAAE,EAAE,CACf,OAAO,CAAO,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAE5C;;;;GAIG;AACU,QAAA,oBAAoB,GAAG,SAAS,CAY3C,KAAK,EAAE,sBAAsB,CAAC,CAAC;AAEjC;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,SAAS,CAkB5C,KAAK,EAAE,uBAAuB,CAAC,CAAC;AAElC;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,SAAS,CAS5C,KAAK,EAAE,uBAAuB,CAAC,CAAC;AAElC;;;;GAIG;AACU,QAAA,oBAAoB,GAAG,SAAS,CAO3C,KAAK,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["const BASE_URL = 'https://fapi.asterdex.com';\n\nconst request = async <T>(method: string, endpoint: string, params: any = {}): Promise<T> => {\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 console.info(url.toString());\n const res = await fetch(url.toString(), {\n method,\n }).then((response) => response.json());\n if (res.code && res.code !== 0) {\n throw JSON.stringify(res);\n }\n return res;\n};\n\nconst createApi =\n <TReq, TRes>(method: string, endpoint: string) =>\n (params: TReq) =>\n request<TRes>(method, endpoint, params);\n\n/**\n * 获取资金费率历史\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E6%9F%A5%E8%AF%A2%E8%B5%84%E9%87%91%E8%B4%B9%E7%8E%87%E5%8E%86%E5%8F%B2\n */\nexport const getFApiV1FundingRate = createApi<\n {\n symbol?: string;\n startTime?: number;\n endTime?: number;\n limit?: number;\n },\n {\n symbol: string;\n fundingRate: string;\n fundingTime: number;\n }[]\n>('GET', '/fapi/v1/fundingRate');\n\n/**\n * 获取交易对信息\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E4%BA%A4%E6%98%93%E5%AF%B9%E4%BF%A1%E6%81%AF\n */\nexport const getFApiV1ExchangeInfo = createApi<\n {},\n {\n symbols: {\n symbol: string;\n status: 'TRADING' | 'BREAK' | 'HALT';\n baseAsset: string;\n quoteAsset: string;\n pricePrecision: number;\n quantityPrecision: number;\n baseAssetPrecision: number;\n quotePrecision: number;\n filters: {\n filterType: string;\n [key: string]: any;\n }[];\n }[];\n }\n>('GET', '/fapi/v1/exchangeInfo');\n\n/**\n * 获取未平仓合约数量\n *\n * 无 API 文档 (weird)\n */\nexport const getFApiV1OpenInterest = createApi<\n {\n symbol: string;\n },\n {\n symbol: string;\n openInterest: string;\n time: number;\n }\n>('GET', '/fapi/v1/openInterest');\n\n/**\n * 获取最新价格\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E6%9C%80%E6%96%B0%E4%BB%B7%E6%A0%BC\n */\nexport const getFApiV1TickerPrice = createApi<\n {},\n {\n symbol: string;\n price: string;\n time?: number;\n }[]\n>('GET', '/fapi/v1/ticker/price');\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import './
|
|
3
|
-
import './
|
|
4
|
-
import './
|
|
5
|
-
import './
|
|
6
|
-
import './
|
|
7
|
-
import './pending-orders';
|
|
8
|
-
import './quote';
|
|
1
|
+
import './services/markets/interest_rate';
|
|
2
|
+
import './services/markets/product';
|
|
3
|
+
import './services/markets/quote';
|
|
4
|
+
import './services/account-actions-with-credential';
|
|
5
|
+
import './services/legacy';
|
|
6
|
+
import './services/order-actions-with-credential';
|
|
9
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,4CAA4C,CAAC;AACpD,OAAO,mBAAmB,CAAC;AAC3B,OAAO,0CAA0C,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
require("./
|
|
4
|
-
require("./
|
|
5
|
-
require("./
|
|
6
|
-
require("./
|
|
7
|
-
require("./
|
|
8
|
-
require("./
|
|
9
|
-
require("./pending-orders");
|
|
10
|
-
require("./quote");
|
|
3
|
+
require("./services/markets/interest_rate");
|
|
4
|
+
require("./services/markets/product");
|
|
5
|
+
require("./services/markets/quote");
|
|
6
|
+
require("./services/account-actions-with-credential");
|
|
7
|
+
require("./services/legacy");
|
|
8
|
+
require("./services/order-actions-with-credential");
|
|
11
9
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,4CAA0C;AAC1C,sCAAoC;AACpC,oCAAkC;AAClC,sDAAoD;AACpD,6BAA2B;AAC3B,oDAAkD","sourcesContent":["import './services/markets/interest_rate';\nimport './services/markets/product';\nimport './services/markets/quote';\nimport './services/account-actions-with-credential';\nimport './services/legacy';\nimport './services/order-actions-with-credential';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-actions-with-credential.d.ts","sourceRoot":"","sources":["../../src/services/account-actions-with-credential.ts"],"names":[],"mappings":""}
|
|
@@ -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,M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AAK,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":""}
|