@yuants/vendor-aster 0.9.4 → 0.9.5
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/client.js +35 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/private-api.js +147 -15
- package/dist/api/private-api.js.map +1 -1
- package/dist/api/public-api.js +114 -11
- package/dist/api/public-api.js.map +1 -1
- package/lib/api/client.d.ts +7 -0
- package/lib/api/client.d.ts.map +1 -0
- package/lib/api/client.js +38 -0
- package/lib/api/client.js.map +1 -0
- package/lib/api/private-api.d.ts +59 -23
- package/lib/api/private-api.d.ts.map +1 -1
- package/lib/api/private-api.js +157 -14
- package/lib/api/private-api.js.map +1 -1
- package/lib/api/public-api.d.ts +33 -12
- package/lib/api/public-api.d.ts.map +1 -1
- package/lib/api/public-api.js +122 -11
- package/lib/api/public-api.js.map +1 -1
- package/package.json +1 -1
- package/temp/package-deps.json +7 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,gDAAgD;AAChD,uEAAuE;AAEvE,wEAAwE;AAC3D,QAAA,eAAe,GAAG,IAAA,mBAAW,EAAC,mBAAmB,EAAE;IAC9D,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEU,QAAA,aAAa,GAAG,IAAA,mBAAW,EAAC,mBAAmB,EAAE;IAC5D,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEU,QAAA,0BAA0B,GAAG,IAAA,mBAAW,EAAC,qBAAqB,EAAE;IAC3E,QAAQ,EAAE,GAAG;IACb,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,GAAG;CAClB,CAAC,CAAC;AAEU,QAAA,0BAA0B,GAAG,IAAA,mBAAW,EAAC,qBAAqB,EAAE;IAC3E,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEU,QAAA,wBAAwB,GAAG,IAAA,mBAAW,EAAC,mBAAmB,EAAE;IACvE,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEU,QAAA,wBAAwB,GAAG,IAAA,mBAAW,EAAC,mBAAmB,EAAE;IACvE,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC","sourcesContent":["import { tokenBucket } from '@yuants/utils';\n\n// Initialize token buckets at module load time.\n// Subsequent calls should use `tokenBucket(bucketId)` without options.\n\n// REQUEST_WEIGHT limits (source: exchangeInfo.rateLimits in Aster docs)\nexport const futureAPIBucket = tokenBucket('fapi.asterdex.com', {\n capacity: 2400,\n refillInterval: 60_000,\n refillAmount: 2400,\n});\n\nexport const spotAPIBucket = tokenBucket('sapi.asterdex.com', {\n capacity: 6000,\n refillInterval: 60_000,\n refillAmount: 6000,\n});\n\nexport const orderFutureSecondAPIBucket = tokenBucket('order/future/second', {\n capacity: 300,\n refillInterval: 10_000,\n refillAmount: 300,\n});\n\nexport const orderFutureMinuteAPIBucket = tokenBucket('order/future/minute', {\n capacity: 1200,\n refillInterval: 60_000,\n refillAmount: 1200,\n});\n\nexport const orderSpotSecondAPIBucket = tokenBucket('order/spot/second', {\n capacity: 1000,\n refillInterval: 10_000,\n refillAmount: 1000,\n});\n\nexport const orderSpotMinuteAPIBucket = tokenBucket('order/spot/minute', {\n capacity: 6000,\n refillInterval: 60_000,\n refillAmount: 6000,\n});\n"]}
|
package/lib/api/private-api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import './client';
|
|
1
2
|
export interface ICredential {
|
|
2
3
|
address: string;
|
|
3
4
|
api_key: string;
|
|
@@ -46,9 +47,11 @@ export interface IAsterSpotOpenOrder {
|
|
|
46
47
|
/**
|
|
47
48
|
* 获取账户信息
|
|
48
49
|
*
|
|
50
|
+
* Weight: 5
|
|
51
|
+
*
|
|
49
52
|
* 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
|
|
50
53
|
*/
|
|
51
|
-
export declare const getFApiV4Account: (credential: ICredential, params:
|
|
54
|
+
export declare const getFApiV4Account: (credential: ICredential, params: Record<string, never>) => Promise<{
|
|
52
55
|
feeTier: number;
|
|
53
56
|
canTrade: boolean;
|
|
54
57
|
canDeposit: boolean;
|
|
@@ -102,10 +105,12 @@ export declare const getFApiV4Account: (credential: ICredential, params: {}) =>
|
|
|
102
105
|
/**
|
|
103
106
|
* 用户持仓风险V2 (USER_DATA)
|
|
104
107
|
*
|
|
108
|
+
* Weight: 5
|
|
109
|
+
*
|
|
105
110
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E7%94%A8%E6%88%B7%E6%8C%81%E4%BB%93%E9%A3%8E%E9%99%A9v2-user_data
|
|
106
111
|
*/
|
|
107
112
|
export declare const getFApiV2PositionRisk: (credential: ICredential, params: {
|
|
108
|
-
symbol?: string
|
|
113
|
+
symbol?: string;
|
|
109
114
|
}) => Promise<{
|
|
110
115
|
entryPrice: string;
|
|
111
116
|
marginType: string;
|
|
@@ -121,7 +126,12 @@ export declare const getFApiV2PositionRisk: (credential: ICredential, params: {
|
|
|
121
126
|
positionSide: string;
|
|
122
127
|
updateTime: number;
|
|
123
128
|
}[]>;
|
|
124
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Weight: 5
|
|
131
|
+
*
|
|
132
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2840-L2855
|
|
133
|
+
*/
|
|
134
|
+
export declare const getFApiV2Balance: (credential: ICredential, params: Record<string, never>) => Promise<{
|
|
125
135
|
accountAlias: string;
|
|
126
136
|
asset: string;
|
|
127
137
|
balance: string;
|
|
@@ -132,43 +142,59 @@ export declare const getFApiV2Balance: (credential: ICredential, params: {}) =>
|
|
|
132
142
|
marginAvailable: boolean;
|
|
133
143
|
updateTime: number;
|
|
134
144
|
}[]>;
|
|
145
|
+
/**
|
|
146
|
+
* Weight: 1 by order
|
|
147
|
+
*
|
|
148
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#post-fapiv1order-%E7%9A%84%E7%A4%BA%E4%BE%8B
|
|
149
|
+
*/
|
|
135
150
|
export declare const postFApiV1Order: (credential: ICredential, params: {
|
|
136
151
|
symbol: string;
|
|
137
152
|
side: 'BUY' | 'SELL';
|
|
138
|
-
positionSide?:
|
|
153
|
+
positionSide?: 'BOTH' | 'LONG' | 'SHORT';
|
|
139
154
|
type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET' | 'TRAILING_STOP_MARKET';
|
|
140
|
-
reduceOnly?:
|
|
141
|
-
quantity?: number
|
|
142
|
-
price?: number
|
|
143
|
-
timeInForce?:
|
|
144
|
-
}) => Promise<
|
|
155
|
+
reduceOnly?: 'true' | 'false';
|
|
156
|
+
quantity?: number;
|
|
157
|
+
price?: number;
|
|
158
|
+
timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX' | 'HIDDEN';
|
|
159
|
+
}) => Promise<Record<string, never>>;
|
|
145
160
|
/**
|
|
146
161
|
* 查询当前挂单 (永续)
|
|
147
162
|
*
|
|
163
|
+
* Weight: with symbol 1, without symbol 40
|
|
164
|
+
*
|
|
148
165
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766
|
|
149
166
|
*/
|
|
150
167
|
export declare const getFApiV1OpenOrders: (credential: ICredential, params: {
|
|
151
|
-
symbol?: string
|
|
168
|
+
symbol?: string;
|
|
152
169
|
}) => Promise<IAsterFutureOpenOrder[]>;
|
|
153
170
|
/**
|
|
154
171
|
* 查询当前挂单 (现货)
|
|
155
172
|
*
|
|
173
|
+
* Weight: with symbol 1, without symbol 40
|
|
174
|
+
*
|
|
156
175
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234
|
|
157
176
|
*/
|
|
158
177
|
export declare const getApiV1OpenOrders: (credential: ICredential, params: {
|
|
159
|
-
symbol?: string
|
|
178
|
+
symbol?: string;
|
|
160
179
|
}) => Promise<IAsterSpotOpenOrder[]>;
|
|
180
|
+
/**
|
|
181
|
+
* Weight: 1
|
|
182
|
+
*
|
|
183
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2498-L2516
|
|
184
|
+
*/
|
|
161
185
|
export declare const deleteFApiV1Order: (credential: ICredential, params: {
|
|
162
186
|
symbol: string;
|
|
163
|
-
orderId?: string | number
|
|
164
|
-
origClientOrderId?: string
|
|
165
|
-
}) => Promise<
|
|
187
|
+
orderId?: string | number;
|
|
188
|
+
origClientOrderId?: string;
|
|
189
|
+
}) => Promise<Record<string, never>>;
|
|
166
190
|
/**
|
|
167
191
|
* 获取账户信息 (现货)
|
|
168
192
|
*
|
|
193
|
+
* Weight: 5
|
|
194
|
+
*
|
|
169
195
|
* 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
|
|
170
196
|
*/
|
|
171
|
-
export declare const getApiV1Account: (credential: ICredential, params:
|
|
197
|
+
export declare const getApiV1Account: (credential: ICredential, params: Record<string, never>) => Promise<{
|
|
172
198
|
feeTier: number;
|
|
173
199
|
canTrade: boolean;
|
|
174
200
|
canDeposit: boolean;
|
|
@@ -183,32 +209,42 @@ export declare const getApiV1Account: (credential: ICredential, params: {}) => P
|
|
|
183
209
|
}>;
|
|
184
210
|
/**
|
|
185
211
|
* 获取最新价格
|
|
212
|
+
*
|
|
213
|
+
* Weight: without symbol 2 (current implementation)
|
|
214
|
+
*
|
|
186
215
|
* 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
|
|
187
216
|
*/
|
|
188
|
-
export declare const getApiV1TickerPrice: (credential: ICredential, params:
|
|
217
|
+
export declare const getApiV1TickerPrice: (credential: ICredential, params: Record<string, never>) => Promise<{
|
|
189
218
|
symbol: string;
|
|
190
219
|
price: string;
|
|
191
220
|
time: number;
|
|
192
221
|
}[]>;
|
|
222
|
+
/**
|
|
223
|
+
* Weight: 1
|
|
224
|
+
*
|
|
225
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#post-apiv1order-%E7%9A%84%E7%A4%BA%E4%BE%8B
|
|
226
|
+
*/
|
|
193
227
|
export declare const postApiV1Order: (credential: ICredential, params: {
|
|
194
228
|
symbol: string;
|
|
195
229
|
side: 'BUY' | 'SELL';
|
|
196
230
|
type: 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_MARKET' | 'TAKE_PROFIT' | 'TAKE_PROFIT_MARKET';
|
|
197
|
-
timeInForce?:
|
|
198
|
-
quantity?: number
|
|
199
|
-
quoteOrderQty?: number
|
|
200
|
-
price?: number
|
|
231
|
+
timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'GTX';
|
|
232
|
+
quantity?: number;
|
|
233
|
+
quoteOrderQty?: number;
|
|
234
|
+
price?: number;
|
|
201
235
|
}) => Promise<{
|
|
202
236
|
orderId: number;
|
|
203
237
|
}>;
|
|
204
238
|
/**
|
|
205
239
|
* 取消有效订单 (现货)
|
|
206
240
|
*
|
|
241
|
+
* Weight: 1
|
|
242
|
+
*
|
|
207
243
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074
|
|
208
244
|
*/
|
|
209
245
|
export declare const deleteApiV1Order: (credential: ICredential, params: {
|
|
210
246
|
symbol: string;
|
|
211
|
-
orderId?: string | number
|
|
212
|
-
origClientOrderId?: string
|
|
213
|
-
}) => Promise<
|
|
247
|
+
orderId?: string | number;
|
|
248
|
+
origClientOrderId?: string;
|
|
249
|
+
}) => Promise<Record<string, never>>;
|
|
214
250
|
//# sourceMappingURL=private-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-api.d.ts","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"private-api.d.ts","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,CAAC;AAQlB,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,E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EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,GAAG,aAAa,GAAG,oBAAoB,CAAC;IACzF,WAAW,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,KACA,QAAQ;IACT,OAAO,EAAE,MAAM,CAAC;CACjB,CAgBA,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,eACf,WAAW,UACf;IACN,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,KACA,QAAQ,OAAO,MAAM,EAAE,KAAK,CAAC,CAgB/B,CAAC"}
|
package/lib/api/private-api.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.deleteApiV1Order = exports.postApiV1Order = exports.getApiV1TickerPrice = exports.getApiV1Account = exports.deleteFApiV1Order = exports.getApiV1OpenOrders = exports.getFApiV1OpenOrders = exports.postFApiV1Order = exports.getFApiV2Balance = exports.getFApiV2PositionRisk = exports.getFApiV4Account = void 0;
|
|
4
4
|
const utils_1 = require("@yuants/utils");
|
|
5
5
|
const protocol_1 = require("@yuants/protocol");
|
|
6
|
+
require("./client");
|
|
6
7
|
const MetricsAsterApiCallCounter = protocol_1.GlobalPrometheusRegistry.counter('aster_api_call', 'Number of aster api call');
|
|
7
8
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
8
9
|
const request = async (credential, method, baseURL, endpoint, params = {}) => {
|
|
@@ -42,52 +43,194 @@ const request = async (credential, method, baseURL, endpoint, params = {}) => {
|
|
|
42
43
|
}, e);
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const createSpotApi = createApi('https://sapi.asterdex.com');
|
|
46
|
+
const FutureBaseURL = 'https://fapi.asterdex.com';
|
|
47
|
+
const SpotBaseURL = 'https://sapi.asterdex.com';
|
|
48
48
|
/**
|
|
49
49
|
* 获取账户信息
|
|
50
50
|
*
|
|
51
|
+
* Weight: 5
|
|
52
|
+
*
|
|
51
53
|
* 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
|
|
52
54
|
*/
|
|
53
|
-
|
|
55
|
+
const getFApiV4Account = (credential, params) => {
|
|
56
|
+
const endpoint = '/fapi/v4/account';
|
|
57
|
+
const url = new URL(FutureBaseURL);
|
|
58
|
+
url.pathname = endpoint;
|
|
59
|
+
const weight = 5;
|
|
60
|
+
(0, utils_1.scopeError)('ASTER_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)(url.host).acquireSync(weight));
|
|
61
|
+
return request(credential, 'GET', FutureBaseURL, endpoint, params);
|
|
62
|
+
};
|
|
63
|
+
exports.getFApiV4Account = getFApiV4Account;
|
|
54
64
|
/**
|
|
55
65
|
* 用户持仓风险V2 (USER_DATA)
|
|
56
66
|
*
|
|
67
|
+
* Weight: 5
|
|
68
|
+
*
|
|
57
69
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E7%94%A8%E6%88%B7%E6%8C%81%E4%BB%93%E9%A3%8E%E9%99%A9v2-user_data
|
|
58
70
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
const getFApiV2PositionRisk = (credential, params) => {
|
|
72
|
+
const endpoint = '/fapi/v2/positionRisk';
|
|
73
|
+
const url = new URL(FutureBaseURL);
|
|
74
|
+
url.pathname = endpoint;
|
|
75
|
+
const weight = 5;
|
|
76
|
+
(0, utils_1.scopeError)('ASTER_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)(url.host).acquireSync(weight));
|
|
77
|
+
return request(credential, 'GET', FutureBaseURL, endpoint, params);
|
|
78
|
+
};
|
|
79
|
+
exports.getFApiV2PositionRisk = getFApiV2PositionRisk;
|
|
80
|
+
/**
|
|
81
|
+
* Weight: 5
|
|
82
|
+
*
|
|
83
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2840-L2855
|
|
84
|
+
*/
|
|
85
|
+
const getFApiV2Balance = (credential, params) => {
|
|
86
|
+
const endpoint = '/fapi/v2/balance';
|
|
87
|
+
const url = new URL(FutureBaseURL);
|
|
88
|
+
url.pathname = endpoint;
|
|
89
|
+
const weight = 5;
|
|
90
|
+
(0, utils_1.scopeError)('ASTER_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)(url.host).acquireSync(weight));
|
|
91
|
+
return request(credential, 'GET', FutureBaseURL, endpoint, params);
|
|
92
|
+
};
|
|
93
|
+
exports.getFApiV2Balance = getFApiV2Balance;
|
|
94
|
+
/**
|
|
95
|
+
* Weight: 1 by order
|
|
96
|
+
*
|
|
97
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#post-fapiv1order-%E7%9A%84%E7%A4%BA%E4%BE%8B
|
|
98
|
+
*/
|
|
99
|
+
const postFApiV1Order = (credential, params) => {
|
|
100
|
+
const endpoint = '/fapi/v1/order';
|
|
101
|
+
const url = new URL(FutureBaseURL);
|
|
102
|
+
url.pathname = endpoint;
|
|
103
|
+
const weight = 1;
|
|
104
|
+
(0, utils_1.scopeError)('ASTER_FUTURE_ORDER_API_SECOND_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)('order/future/second').acquireSync(weight));
|
|
105
|
+
(0, utils_1.scopeError)('ASTER_FUTURE_ORDER_API_MINUTE_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)('order/future/minute').acquireSync(weight));
|
|
106
|
+
return request(credential, 'POST', FutureBaseURL, endpoint, params);
|
|
107
|
+
};
|
|
108
|
+
exports.postFApiV1Order = postFApiV1Order;
|
|
62
109
|
/**
|
|
63
110
|
* 查询当前挂单 (永续)
|
|
64
111
|
*
|
|
112
|
+
* Weight: with symbol 1, without symbol 40
|
|
113
|
+
*
|
|
65
114
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766
|
|
66
115
|
*/
|
|
67
|
-
|
|
116
|
+
const getFApiV1OpenOrders = (credential, params) => {
|
|
117
|
+
const endpoint = '/fapi/v1/openOrders';
|
|
118
|
+
const url = new URL(FutureBaseURL);
|
|
119
|
+
url.pathname = endpoint;
|
|
120
|
+
const weight = (params === null || params === void 0 ? void 0 : params.symbol) ? 1 : 40;
|
|
121
|
+
(0, utils_1.scopeError)('ASTER_API_RATE_LIMIT', {
|
|
122
|
+
method: 'GET',
|
|
123
|
+
endpoint,
|
|
124
|
+
host: url.host,
|
|
125
|
+
path: url.pathname,
|
|
126
|
+
bucketId: url.host,
|
|
127
|
+
weight,
|
|
128
|
+
hasSymbol: !!(params === null || params === void 0 ? void 0 : params.symbol),
|
|
129
|
+
}, () => (0, utils_1.tokenBucket)(url.host).acquireSync(weight));
|
|
130
|
+
return request(credential, 'GET', FutureBaseURL, endpoint, params);
|
|
131
|
+
};
|
|
132
|
+
exports.getFApiV1OpenOrders = getFApiV1OpenOrders;
|
|
68
133
|
/**
|
|
69
134
|
* 查询当前挂单 (现货)
|
|
70
135
|
*
|
|
136
|
+
* Weight: with symbol 1, without symbol 40
|
|
137
|
+
*
|
|
71
138
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234
|
|
72
139
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
140
|
+
const getApiV1OpenOrders = (credential, params) => {
|
|
141
|
+
const endpoint = '/api/v1/openOrders';
|
|
142
|
+
const url = new URL(SpotBaseURL);
|
|
143
|
+
url.pathname = endpoint;
|
|
144
|
+
const weight = (params === null || params === void 0 ? void 0 : params.symbol) ? 1 : 40;
|
|
145
|
+
(0, utils_1.scopeError)('ASTER_API_RATE_LIMIT', {
|
|
146
|
+
method: 'GET',
|
|
147
|
+
endpoint,
|
|
148
|
+
host: url.host,
|
|
149
|
+
path: url.pathname,
|
|
150
|
+
bucketId: url.host,
|
|
151
|
+
weight,
|
|
152
|
+
hasSymbol: !!(params === null || params === void 0 ? void 0 : params.symbol),
|
|
153
|
+
}, () => (0, utils_1.tokenBucket)(url.host).acquireSync(weight));
|
|
154
|
+
return request(credential, 'GET', SpotBaseURL, endpoint, params);
|
|
155
|
+
};
|
|
156
|
+
exports.getApiV1OpenOrders = getApiV1OpenOrders;
|
|
157
|
+
/**
|
|
158
|
+
* Weight: 1
|
|
159
|
+
*
|
|
160
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2498-L2516
|
|
161
|
+
*/
|
|
162
|
+
const deleteFApiV1Order = (credential, params) => {
|
|
163
|
+
const endpoint = '/fapi/v1/order';
|
|
164
|
+
const url = new URL(FutureBaseURL);
|
|
165
|
+
url.pathname = endpoint;
|
|
166
|
+
const weight = 1;
|
|
167
|
+
(0, utils_1.scopeError)('ASTER_FUTURE_ORDER_API_SECOND_RATE_LIMIT', { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)('order/future/second').acquireSync(weight));
|
|
168
|
+
(0, utils_1.scopeError)('ASTER_FUTURE_ORDER_API_MINUTE_RATE_LIMIT', { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)('order/future/minute').acquireSync(weight));
|
|
169
|
+
return request(credential, 'DELETE', FutureBaseURL, endpoint, params);
|
|
170
|
+
};
|
|
171
|
+
exports.deleteFApiV1Order = deleteFApiV1Order;
|
|
75
172
|
/**
|
|
76
173
|
* 获取账户信息 (现货)
|
|
77
174
|
*
|
|
175
|
+
* Weight: 5
|
|
176
|
+
*
|
|
78
177
|
* 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
|
|
79
178
|
*/
|
|
80
|
-
|
|
179
|
+
const getApiV1Account = (credential, params) => {
|
|
180
|
+
const endpoint = '/api/v1/account';
|
|
181
|
+
const url = new URL(SpotBaseURL);
|
|
182
|
+
url.pathname = endpoint;
|
|
183
|
+
const weight = 5;
|
|
184
|
+
(0, utils_1.scopeError)('ASTER_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)(url.host).acquireSync(weight));
|
|
185
|
+
return request(credential, 'GET', SpotBaseURL, endpoint, params);
|
|
186
|
+
};
|
|
187
|
+
exports.getApiV1Account = getApiV1Account;
|
|
81
188
|
/**
|
|
82
189
|
* 获取最新价格
|
|
190
|
+
*
|
|
191
|
+
* Weight: without symbol 2 (current implementation)
|
|
192
|
+
*
|
|
83
193
|
* 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
|
|
84
194
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
195
|
+
const getApiV1TickerPrice = (credential, params) => {
|
|
196
|
+
const endpoint = '/api/v1/ticker/price';
|
|
197
|
+
const url = new URL(SpotBaseURL);
|
|
198
|
+
url.pathname = endpoint;
|
|
199
|
+
const weight = 2;
|
|
200
|
+
(0, utils_1.scopeError)('ASTER_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)(url.host).acquireSync(weight));
|
|
201
|
+
return request(credential, 'GET', SpotBaseURL, endpoint, params);
|
|
202
|
+
};
|
|
203
|
+
exports.getApiV1TickerPrice = getApiV1TickerPrice;
|
|
204
|
+
/**
|
|
205
|
+
* Weight: 1
|
|
206
|
+
*
|
|
207
|
+
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#post-apiv1order-%E7%9A%84%E7%A4%BA%E4%BE%8B
|
|
208
|
+
*/
|
|
209
|
+
const postApiV1Order = (credential, params) => {
|
|
210
|
+
const endpoint = '/api/v1/order';
|
|
211
|
+
const url = new URL(SpotBaseURL);
|
|
212
|
+
url.pathname = endpoint;
|
|
213
|
+
const weight = 1;
|
|
214
|
+
(0, utils_1.scopeError)('ASTER_SPOT_ORDER_API_SECOND_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)('order/spot/second').acquireSync(weight));
|
|
215
|
+
(0, utils_1.scopeError)('ASTER_SPOT_ORDER_API_MINUTE_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)('order/spot/minute').acquireSync(weight));
|
|
216
|
+
return request(credential, 'POST', SpotBaseURL, endpoint, params);
|
|
217
|
+
};
|
|
218
|
+
exports.postApiV1Order = postApiV1Order;
|
|
87
219
|
/**
|
|
88
220
|
* 取消有效订单 (现货)
|
|
89
221
|
*
|
|
222
|
+
* Weight: 1
|
|
223
|
+
*
|
|
90
224
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074
|
|
91
225
|
*/
|
|
92
|
-
|
|
226
|
+
const deleteApiV1Order = (credential, params) => {
|
|
227
|
+
const endpoint = '/api/v1/order';
|
|
228
|
+
const url = new URL(SpotBaseURL);
|
|
229
|
+
url.pathname = endpoint;
|
|
230
|
+
const weight = 1;
|
|
231
|
+
(0, utils_1.scopeError)('ASTER_SPOT_ORDER_API_SECOND_RATE_LIMIT', { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)('order/spot/second').acquireSync(weight));
|
|
232
|
+
(0, utils_1.scopeError)('ASTER_SPOT_ORDER_API_MINUTE_RATE_LIMIT', { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => (0, utils_1.tokenBucket)('order/spot/minute').acquireSync(weight));
|
|
233
|
+
return request(credential, 'DELETE', SpotBaseURL, endpoint, params);
|
|
234
|
+
};
|
|
235
|
+
exports.deleteApiV1Order = deleteApiV1Order;
|
|
93
236
|
//# sourceMappingURL=private-api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":";;;AAAA,yCAAgE;AAEhE,+CAAsE;AAEtE,MAAM,0BAA0B,GAAG,mCAAwB,CAAC,OAAO,CACjE,gBAAgB,EAChB,0BAA0B,CAC3B,CAAC;AACF,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAkDxC,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,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nimport { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';\n\nconst MetricsAsterApiCallCounter = GlobalPrometheusRegistry.counter(\n 'aster_api_call',\n 'Number of aster api call',\n);\nconst terminal = Terminal.fromNodeEnv();\n\nexport interface ICredential {\n address: string;\n api_key: string;\n secret_key: string;\n}\n\nexport interface IAsterFutureOpenOrder {\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\nexport interface IAsterSpotOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n cummulativeQuoteQty?: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n stopPrice?: string;\n icebergQty?: string;\n time: number;\n updateTime: number;\n isWorking?: boolean;\n avgPrice?: string;\n symbol: 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 = encodeHex(\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 MetricsAsterApiCallCounter.labels({ path: url.pathname, terminal_id: terminal.terminal_id }).inc();\n const response = await fetch(url.toString(), {\n method,\n headers: {\n 'X-MBX-APIKEY': credential.api_key,\n },\n });\n\n const resText = await response.text();\n\n try {\n const res = JSON.parse(resText);\n\n if (res.code && res.code !== 0) {\n throw resText;\n }\n return res;\n } catch (e) {\n throw newError(\n 'ASTER_API_ERROR',\n {\n status: response.status,\n statusText: response.statusText,\n resText,\n params,\n },\n e,\n );\n }\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\n/**\n * 用户持仓风险V2 (USER_DATA)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E7%94%A8%E6%88%B7%E6%8C%81%E4%BB%93%E9%A3%8E%E9%99%A9v2-user_data\n */\nexport const getFApiV2PositionRisk = createFutureApi<\n {\n symbol?: string;\n },\n {\n entryPrice: string;\n marginType: string;\n isAutoAddMargin: string;\n isolatedMargin: string;\n leverage: string;\n liquidationPrice: string;\n markPrice: string;\n maxNotionalValue: string;\n positionAmt: string;\n symbol: string;\n unRealizedProfit: string;\n positionSide: string;\n updateTime: number;\n }[]\n>('GET', '/fapi/v2/positionRisk');\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\n/**\n * 查询当前挂单 (永续)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766\n */\nexport const getFApiV1OpenOrders = createFutureApi<\n {\n symbol?: string;\n },\n IAsterFutureOpenOrder[]\n>('GET', '/fapi/v1/openOrders');\n\n/**\n * 查询当前挂单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234\n */\nexport const getApiV1OpenOrders = createSpotApi<\n {\n symbol?: string;\n },\n IAsterSpotOpenOrder[]\n>('GET', '/api/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\n/**\n * 取消有效订单 (现货)\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074\n */\nexport const deleteApiV1Order = createSpotApi<\n {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n {}\n>('DELETE', '/api/v1/order');\n"]}
|
|
1
|
+
{"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts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,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAC9F,GAAG,EAAE,CAAC,IAAA,mBAAW,EAAC,mBAAmB,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAC3D,CAAC;IACF,OAAO,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACtE,CAAC,CAAC;AAvBW,QAAA,gBAAgB,oBAuB3B","sourcesContent":["import { encodeHex, HmacSHA256, newError, scopeError, tokenBucket } from '@yuants/utils';\n\nimport { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';\n\nimport './client';\n\nconst MetricsAsterApiCallCounter = GlobalPrometheusRegistry.counter(\n 'aster_api_call',\n 'Number of aster api call',\n);\nconst terminal = Terminal.fromNodeEnv();\n\nexport interface ICredential {\n address: string;\n api_key: string;\n secret_key: string;\n}\n\nexport interface IAsterFutureOpenOrder {\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\nexport interface IAsterSpotOpenOrder {\n orderId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n cummulativeQuoteQty?: string;\n status: string;\n timeInForce: string;\n type: string;\n side: 'BUY' | 'SELL';\n stopPrice?: string;\n icebergQty?: string;\n time: number;\n updateTime: number;\n isWorking?: boolean;\n avgPrice?: string;\n symbol: string;\n}\n\nconst request = async <T>(\n credential: ICredential,\n method: string,\n baseURL: string,\n endpoint: string,\n params: Record<string, unknown> = {},\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 = encodeHex(\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 MetricsAsterApiCallCounter.labels({ path: url.pathname, terminal_id: terminal.terminal_id }).inc();\n const response = await fetch(url.toString(), {\n method,\n headers: {\n 'X-MBX-APIKEY': credential.api_key,\n },\n });\n\n const resText = await response.text();\n\n try {\n const res = JSON.parse(resText);\n\n if (res.code && res.code !== 0) {\n throw resText;\n }\n return res;\n } catch (e) {\n throw newError(\n 'ASTER_API_ERROR',\n {\n status: response.status,\n statusText: response.statusText,\n resText,\n params,\n },\n e,\n );\n }\n};\n\nconst FutureBaseURL = 'https://fapi.asterdex.com';\nconst SpotBaseURL = 'https://sapi.asterdex.com';\n\n/**\n * 获取账户信息\n *\n * Weight: 5\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 = (\n credential: ICredential,\n params: Record<string, never>,\n): Promise<{\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 const endpoint = '/fapi/v4/account';\n const url = new URL(FutureBaseURL);\n url.pathname = endpoint;\n const weight = 5;\n scopeError(\n 'ASTER_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return request(credential, 'GET', FutureBaseURL, endpoint, params);\n};\n\n/**\n * 用户持仓风险V2 (USER_DATA)\n *\n * Weight: 5\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#%E7%94%A8%E6%88%B7%E6%8C%81%E4%BB%93%E9%A3%8E%E9%99%A9v2-user_data\n */\nexport const getFApiV2PositionRisk = (\n credential: ICredential,\n params: {\n symbol?: string;\n },\n): Promise<\n {\n entryPrice: string;\n marginType: string;\n isAutoAddMargin: string;\n isolatedMargin: string;\n leverage: string;\n liquidationPrice: string;\n markPrice: string;\n maxNotionalValue: string;\n positionAmt: string;\n symbol: string;\n unRealizedProfit: string;\n positionSide: string;\n updateTime: number;\n }[]\n> => {\n const endpoint = '/fapi/v2/positionRisk';\n const url = new URL(FutureBaseURL);\n url.pathname = endpoint;\n const weight = 5;\n scopeError(\n 'ASTER_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return request(credential, 'GET', FutureBaseURL, endpoint, params);\n};\n\n/**\n * Weight: 5\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2840-L2855\n */\nexport const getFApiV2Balance = (\n credential: ICredential,\n params: Record<string, never>,\n): Promise<\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> => {\n const endpoint = '/fapi/v2/balance';\n const url = new URL(FutureBaseURL);\n url.pathname = endpoint;\n const weight = 5;\n scopeError(\n 'ASTER_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return request(credential, 'GET', FutureBaseURL, endpoint, params);\n};\n\n/**\n * Weight: 1 by order\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#post-fapiv1order-%E7%9A%84%E7%A4%BA%E4%BE%8B\n */\nexport const postFApiV1Order = (\n credential: ICredential,\n params: {\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): Promise<Record<string, never>> => {\n const endpoint = '/fapi/v1/order';\n const url = new URL(FutureBaseURL);\n url.pathname = endpoint;\n const weight = 1;\n scopeError(\n 'ASTER_FUTURE_ORDER_API_SECOND_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/future/second').acquireSync(weight),\n );\n scopeError(\n 'ASTER_FUTURE_ORDER_API_MINUTE_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/future/minute').acquireSync(weight),\n );\n return request(credential, 'POST', FutureBaseURL, endpoint, params);\n};\n\n/**\n * 查询当前挂单 (永续)\n *\n * Weight: with symbol 1, without symbol 40\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2728-L2766\n */\nexport const getFApiV1OpenOrders = (\n credential: ICredential,\n params: {\n symbol?: string;\n },\n): Promise<IAsterFutureOpenOrder[]> => {\n const endpoint = '/fapi/v1/openOrders';\n const url = new URL(FutureBaseURL);\n url.pathname = endpoint;\n const weight = params?.symbol ? 1 : 40;\n scopeError(\n 'ASTER_API_RATE_LIMIT',\n {\n method: 'GET',\n endpoint,\n host: url.host,\n path: url.pathname,\n bucketId: url.host,\n weight,\n hasSymbol: !!params?.symbol,\n },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return request(credential, 'GET', FutureBaseURL, endpoint, params);\n};\n\n/**\n * 查询当前挂单 (现货)\n *\n * Weight: with symbol 1, without symbol 40\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1196-L1234\n */\nexport const getApiV1OpenOrders = (\n credential: ICredential,\n params: {\n symbol?: string;\n },\n): Promise<IAsterSpotOpenOrder[]> => {\n const endpoint = '/api/v1/openOrders';\n const url = new URL(SpotBaseURL);\n url.pathname = endpoint;\n const weight = params?.symbol ? 1 : 40;\n scopeError(\n 'ASTER_API_RATE_LIMIT',\n {\n method: 'GET',\n endpoint,\n host: url.host,\n path: url.pathname,\n bucketId: url.host,\n weight,\n hasSymbol: !!params?.symbol,\n },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return request(credential, 'GET', SpotBaseURL, endpoint, params);\n};\n\n/**\n * Weight: 1\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#L2498-L2516\n */\nexport const deleteFApiV1Order = (\n credential: ICredential,\n params: {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n): Promise<Record<string, never>> => {\n const endpoint = '/fapi/v1/order';\n const url = new URL(FutureBaseURL);\n url.pathname = endpoint;\n const weight = 1;\n scopeError(\n 'ASTER_FUTURE_ORDER_API_SECOND_RATE_LIMIT',\n { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/future/second').acquireSync(weight),\n );\n scopeError(\n 'ASTER_FUTURE_ORDER_API_MINUTE_RATE_LIMIT',\n { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/future/minute').acquireSync(weight),\n );\n return request(credential, 'DELETE', FutureBaseURL, endpoint, params);\n};\n\n/**\n * 获取账户信息 (现货)\n *\n * Weight: 5\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 = (\n credential: ICredential,\n params: Record<string, never>,\n): Promise<{\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 const endpoint = '/api/v1/account';\n const url = new URL(SpotBaseURL);\n url.pathname = endpoint;\n const weight = 5;\n scopeError(\n 'ASTER_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return request(credential, 'GET', SpotBaseURL, endpoint, params);\n};\n\n/**\n * 获取最新价格\n *\n * Weight: without symbol 2 (current implementation)\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 = (\n credential: ICredential,\n params: Record<string, never>,\n): Promise<\n {\n symbol: string;\n price: string;\n time: number;\n }[]\n> => {\n const endpoint = '/api/v1/ticker/price';\n const url = new URL(SpotBaseURL);\n url.pathname = endpoint;\n const weight = 2;\n scopeError(\n 'ASTER_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return request(credential, 'GET', SpotBaseURL, endpoint, params);\n};\n\n/**\n * Weight: 1\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#post-apiv1order-%E7%9A%84%E7%A4%BA%E4%BE%8B\n */\nexport const postApiV1Order = (\n credential: ICredential,\n params: {\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): Promise<{\n orderId: number;\n}> => {\n const endpoint = '/api/v1/order';\n const url = new URL(SpotBaseURL);\n url.pathname = endpoint;\n const weight = 1;\n scopeError(\n 'ASTER_SPOT_ORDER_API_SECOND_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/spot/second').acquireSync(weight),\n );\n scopeError(\n 'ASTER_SPOT_ORDER_API_MINUTE_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/spot/minute').acquireSync(weight),\n );\n return request(credential, 'POST', SpotBaseURL, endpoint, params);\n};\n\n/**\n * 取消有效订单 (现货)\n *\n * Weight: 1\n *\n * https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1040-L1074\n */\nexport const deleteApiV1Order = (\n credential: ICredential,\n params: {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n): Promise<Record<string, never>> => {\n const endpoint = '/api/v1/order';\n const url = new URL(SpotBaseURL);\n url.pathname = endpoint;\n const weight = 1;\n scopeError(\n 'ASTER_SPOT_ORDER_API_SECOND_RATE_LIMIT',\n { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/spot/second').acquireSync(weight),\n );\n scopeError(\n 'ASTER_SPOT_ORDER_API_MINUTE_RATE_LIMIT',\n { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/spot/minute').acquireSync(weight),\n );\n return request(credential, 'DELETE', SpotBaseURL, endpoint, params);\n};\n"]}
|
package/lib/api/public-api.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import './client';
|
|
1
2
|
/**
|
|
2
3
|
* 获取资金费率历史
|
|
3
4
|
*
|
|
5
|
+
* Weight: 1
|
|
6
|
+
*
|
|
4
7
|
* 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
8
|
*/
|
|
6
9
|
export declare const getFApiV1FundingRate: (params: {
|
|
7
|
-
symbol?: string
|
|
8
|
-
startTime?: number
|
|
9
|
-
endTime?: number
|
|
10
|
-
limit?: number
|
|
10
|
+
symbol?: string;
|
|
11
|
+
startTime?: number;
|
|
12
|
+
endTime?: number;
|
|
13
|
+
limit?: number;
|
|
11
14
|
}) => Promise<{
|
|
12
15
|
symbol: string;
|
|
13
16
|
fundingRate: string;
|
|
@@ -39,12 +42,16 @@ export interface IAsterExchangeInfo {
|
|
|
39
42
|
/**
|
|
40
43
|
* 获取交易对信息
|
|
41
44
|
*
|
|
45
|
+
* Weight: 1
|
|
46
|
+
*
|
|
42
47
|
* 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
|
|
43
48
|
*/
|
|
44
49
|
export declare const getFApiV1ExchangeInfo: (params: Record<string, never>) => Promise<IAsterExchangeInfo>;
|
|
45
50
|
/**
|
|
46
51
|
* 获取现货交易对信息
|
|
47
52
|
*
|
|
53
|
+
* Weight: 1
|
|
54
|
+
*
|
|
48
55
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md#L1080-L1145
|
|
49
56
|
*/
|
|
50
57
|
export declare const getApiV1ExchangeInfo: (params: Record<string, never>) => Promise<IAsterExchangeInfo>;
|
|
@@ -52,6 +59,10 @@ export declare const getApiV1ExchangeInfo: (params: Record<string, never>) => Pr
|
|
|
52
59
|
* 获取未平仓合约数量
|
|
53
60
|
*
|
|
54
61
|
* 无 API 文档 (weird)
|
|
62
|
+
* 参考 Binance 风格接口:/fapi/v1/openInterest
|
|
63
|
+
*
|
|
64
|
+
* Weight: 1
|
|
65
|
+
* https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest
|
|
55
66
|
*/
|
|
56
67
|
export declare const getFApiV1OpenInterest: (params: {
|
|
57
68
|
symbol: string;
|
|
@@ -63,19 +74,24 @@ export declare const getFApiV1OpenInterest: (params: {
|
|
|
63
74
|
/**
|
|
64
75
|
* 获取最新价格
|
|
65
76
|
*
|
|
77
|
+
* Weight: without symbol 2 (current implementation)
|
|
78
|
+
*
|
|
66
79
|
* 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
|
|
67
80
|
*/
|
|
68
81
|
export declare const getFApiV1TickerPrice: (params: Record<string, never>) => Promise<{
|
|
69
82
|
symbol: string;
|
|
70
83
|
price: string;
|
|
71
|
-
time?: number
|
|
84
|
+
time?: number;
|
|
72
85
|
}[]>;
|
|
73
86
|
/**
|
|
74
87
|
* 获取资金费率
|
|
88
|
+
*
|
|
89
|
+
* Weight: 1
|
|
90
|
+
*
|
|
75
91
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md
|
|
76
92
|
*/
|
|
77
93
|
export declare const getFApiV1PremiumIndex: (params: {
|
|
78
|
-
symbol?: string
|
|
94
|
+
symbol?: string;
|
|
79
95
|
}) => Promise<{
|
|
80
96
|
symbol: string;
|
|
81
97
|
markPrice: string;
|
|
@@ -113,27 +129,32 @@ export interface IAsterKline extends Array<string | number> {
|
|
|
113
129
|
* 获取 K 线
|
|
114
130
|
*
|
|
115
131
|
* 参考 Binance 风格接口:/fapi/v1/klines
|
|
132
|
+
*
|
|
133
|
+
* Weight: by limit
|
|
134
|
+
*
|
|
116
135
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api_CN.md#k%E7%BA%BF%E6%95%B0%E6%8D%AE
|
|
117
136
|
*/
|
|
118
137
|
export declare const getFApiV1Klines: (params: {
|
|
119
138
|
symbol: string;
|
|
120
139
|
interval: string;
|
|
121
|
-
startTime?: number
|
|
122
|
-
endTime?: number
|
|
123
|
-
limit?: number
|
|
140
|
+
startTime?: number;
|
|
141
|
+
endTime?: number;
|
|
142
|
+
limit?: number;
|
|
124
143
|
}) => Promise<IAsterKline[]>;
|
|
125
144
|
/**
|
|
126
145
|
* 获取现货 K 线
|
|
127
146
|
*
|
|
128
147
|
* 参考 Binance 风格接口:/api/v1/klines
|
|
129
148
|
*
|
|
149
|
+
* Weight: not documented (temporary: follow futures limit table)
|
|
150
|
+
*
|
|
130
151
|
* https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api_CN.md
|
|
131
152
|
*/
|
|
132
153
|
export declare const getApiV1Klines: (params: {
|
|
133
154
|
symbol: string;
|
|
134
155
|
interval: string;
|
|
135
|
-
startTime?: number
|
|
136
|
-
endTime?: number
|
|
137
|
-
limit?: number
|
|
156
|
+
startTime?: number;
|
|
157
|
+
endTime?: number;
|
|
158
|
+
limit?: number;
|
|
138
159
|
}) => Promise<IAsterKline[]>;
|
|
139
160
|
//# sourceMappingURL=public-api.d.ts.map
|