@nemesis-oss/binance-sdk 1.0.0 → 2.0.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/README.md +136 -8
- package/dist/index-BO27qOb5.d.cts +3887 -0
- package/dist/index-BO27qOb5.d.ts +3887 -0
- package/dist/index.cjs +2640 -629
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -8
- package/dist/index.d.ts +62 -8
- package/dist/index.js +2536 -632
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.cjs +2429 -632
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +2430 -633
- package/dist/mcp/index.js.map +1 -1
- package/dist/tools/index.d.cts +2 -1
- package/dist/tools/index.d.ts +2 -1
- package/package.json +8 -3
- package/dist/index-D2T_Rhwj.d.cts +0 -2055
- package/dist/index-D2T_Rhwj.d.ts +0 -2055
package/dist/mcp/index.cjs
CHANGED
|
@@ -28,7 +28,6 @@ var import_node_http = __toESM(require("http"), 1);
|
|
|
28
28
|
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
29
29
|
|
|
30
30
|
// src/client/HttpClient.ts
|
|
31
|
-
var import_node_crypto = require("crypto");
|
|
32
31
|
var import_axios = __toESM(require("axios"), 1);
|
|
33
32
|
var import_bottleneck = __toESM(require("bottleneck"), 1);
|
|
34
33
|
|
|
@@ -51,18 +50,33 @@ var BinanceAuthError = class extends BinanceError {
|
|
|
51
50
|
|
|
52
51
|
// src/errors/BinanceApiError.ts
|
|
53
52
|
var BinanceApiError = class extends BinanceError {
|
|
54
|
-
constructor(message, code, status) {
|
|
53
|
+
constructor(message, code, status, context) {
|
|
55
54
|
super(message);
|
|
56
55
|
this.name = "BinanceApiError";
|
|
57
56
|
this.code = code;
|
|
58
57
|
this.status = status;
|
|
58
|
+
this.endpoint = context?.endpoint;
|
|
59
|
+
this.method = context?.method;
|
|
60
|
+
this.headers = context?.headers;
|
|
61
|
+
}
|
|
62
|
+
/** -1003 (way too many requests) or HTTP 429/418. */
|
|
63
|
+
isRateLimitError() {
|
|
64
|
+
return this.code === -1003 || this.status === 429 || this.status === 418;
|
|
65
|
+
}
|
|
66
|
+
/** -1021: request timestamp outside recvWindow, usually caused by local clock drift. */
|
|
67
|
+
isTimestampError() {
|
|
68
|
+
return this.code === -1021;
|
|
69
|
+
}
|
|
70
|
+
/** -2010: account has insufficient balance for the requested action. */
|
|
71
|
+
isInsufficientBalance() {
|
|
72
|
+
return this.code === -2010;
|
|
59
73
|
}
|
|
60
74
|
};
|
|
61
75
|
|
|
62
76
|
// src/errors/RateLimitError.ts
|
|
63
77
|
var RateLimitError = class extends BinanceApiError {
|
|
64
|
-
constructor(message, code, status, retryAfterMs) {
|
|
65
|
-
super(message, code, status);
|
|
78
|
+
constructor(message, code, status, retryAfterMs, context) {
|
|
79
|
+
super(message, code, status, context);
|
|
66
80
|
this.name = "RateLimitError";
|
|
67
81
|
this.retryAfterMs = retryAfterMs;
|
|
68
82
|
}
|
|
@@ -77,16 +91,144 @@ var NetworkError = class extends BinanceError {
|
|
|
77
91
|
}
|
|
78
92
|
};
|
|
79
93
|
|
|
94
|
+
// src/errors/PolicyViolationError.ts
|
|
95
|
+
var PolicyViolationError = class extends BinanceError {
|
|
96
|
+
constructor(rule, message, method, endpoint, details) {
|
|
97
|
+
super(`Blocked by trading policy (${rule}): ${message} [${method} ${endpoint}]`);
|
|
98
|
+
this.name = "PolicyViolationError";
|
|
99
|
+
this.rule = rule;
|
|
100
|
+
this.method = method;
|
|
101
|
+
this.endpoint = endpoint;
|
|
102
|
+
this.details = details;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/errors/DryRunError.ts
|
|
107
|
+
var DryRunError = class extends BinanceError {
|
|
108
|
+
constructor(method, endpoint, params = {}) {
|
|
109
|
+
super(`DRY RUN \u2014 request not sent: ${method} ${endpoint} ${JSON.stringify(params)}`);
|
|
110
|
+
this.name = "DryRunError";
|
|
111
|
+
this.method = method;
|
|
112
|
+
this.endpoint = endpoint;
|
|
113
|
+
this.params = params;
|
|
114
|
+
}
|
|
115
|
+
/** Human/LLM-readable description of the suppressed request. */
|
|
116
|
+
describe() {
|
|
117
|
+
return `Would have sent ${this.method} ${this.endpoint} with ${JSON.stringify(this.params)}`;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/client/RateLimitTracker.ts
|
|
122
|
+
var WEIGHT_HEADER = /^x-mbx-used-weight-(.+)$/i;
|
|
123
|
+
var ORDER_COUNT_HEADER = /^x-mbx-order-count-(.+)$/i;
|
|
124
|
+
var RateLimitTracker = class {
|
|
125
|
+
constructor(options = {}) {
|
|
126
|
+
this.usage = {
|
|
127
|
+
usedWeight: 0,
|
|
128
|
+
usedWeightByInterval: {},
|
|
129
|
+
orderCountByInterval: {},
|
|
130
|
+
lastUpdated: 0
|
|
131
|
+
};
|
|
132
|
+
this.weightLimitPerMinute = options.weightLimitPerMinute ?? 6e3;
|
|
133
|
+
this.safetyMargin = options.safetyMargin ?? 0.8;
|
|
134
|
+
}
|
|
135
|
+
update(headers) {
|
|
136
|
+
if (!headers) return;
|
|
137
|
+
const usedWeightByInterval = {};
|
|
138
|
+
const orderCountByInterval = {};
|
|
139
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
140
|
+
const weightMatch = key.match(WEIGHT_HEADER);
|
|
141
|
+
if (weightMatch?.[1]) {
|
|
142
|
+
usedWeightByInterval[weightMatch[1]] = Number(value);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const orderMatch = key.match(ORDER_COUNT_HEADER);
|
|
146
|
+
if (orderMatch?.[1]) {
|
|
147
|
+
orderCountByInterval[orderMatch[1]] = Number(value);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (Object.keys(usedWeightByInterval).length === 0 && Object.keys(orderCountByInterval).length === 0) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.usage = {
|
|
154
|
+
usedWeight: Math.max(0, ...Object.values(usedWeightByInterval)),
|
|
155
|
+
usedWeightByInterval,
|
|
156
|
+
orderCountByInterval,
|
|
157
|
+
lastUpdated: Date.now()
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
getUsage() {
|
|
161
|
+
return this.usage;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Milliseconds a caller should wait before its next request, based on the most recently
|
|
165
|
+
* observed 1-minute weight usage. Returns 0 when usage is stale or under the safety margin.
|
|
166
|
+
*/
|
|
167
|
+
getThrottleDelayMs() {
|
|
168
|
+
if (this.safetyMargin >= 1) return 0;
|
|
169
|
+
const oneMinuteWeight = this.usage.usedWeightByInterval["1m"] ?? this.usage.usedWeight;
|
|
170
|
+
if (!oneMinuteWeight) return 0;
|
|
171
|
+
if (Date.now() - this.usage.lastUpdated > 6e4) return 0;
|
|
172
|
+
const threshold = this.weightLimitPerMinute * this.safetyMargin;
|
|
173
|
+
if (oneMinuteWeight < threshold) return 0;
|
|
174
|
+
const msIntoMinute = Date.now() % 6e4;
|
|
175
|
+
return 6e4 - msIntoMinute;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// src/client/Signer.ts
|
|
180
|
+
var import_node_crypto = require("crypto");
|
|
181
|
+
var Signer = class {
|
|
182
|
+
constructor(options) {
|
|
183
|
+
this.algorithm = options.algorithm ?? (options.privateKey ? "ED25519" : "HMAC");
|
|
184
|
+
this.apiSecret = options.apiSecret;
|
|
185
|
+
if (options.privateKey) {
|
|
186
|
+
this.privateKey = (0, import_node_crypto.createPrivateKey)(options.privateKey);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
canSign() {
|
|
190
|
+
return this.algorithm === "HMAC" ? Boolean(this.apiSecret) : Boolean(this.privateKey);
|
|
191
|
+
}
|
|
192
|
+
sign(payload) {
|
|
193
|
+
switch (this.algorithm) {
|
|
194
|
+
case "HMAC": {
|
|
195
|
+
if (!this.apiSecret) throw new Error("apiSecret is required for HMAC signing");
|
|
196
|
+
return (0, import_node_crypto.createHmac)("sha256", this.apiSecret).update(payload).digest("hex");
|
|
197
|
+
}
|
|
198
|
+
case "ED25519": {
|
|
199
|
+
if (!this.privateKey) throw new Error("privateKey is required for ED25519 signing");
|
|
200
|
+
return (0, import_node_crypto.sign)(null, Buffer.from(payload), this.privateKey).toString("base64");
|
|
201
|
+
}
|
|
202
|
+
case "RSA": {
|
|
203
|
+
if (!this.privateKey) throw new Error("privateKey is required for RSA signing");
|
|
204
|
+
return (0, import_node_crypto.createSign)("RSA-SHA256").update(payload).sign(this.privateKey, "base64");
|
|
205
|
+
}
|
|
206
|
+
default: {
|
|
207
|
+
const exhaustive = this.algorithm;
|
|
208
|
+
throw new Error(`Unsupported signature algorithm: ${String(exhaustive)}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
80
214
|
// src/client/HttpClient.ts
|
|
81
215
|
var RETRYABLE_STATUS = /* @__PURE__ */ new Set([429, 418, 500, 502, 503, 504]);
|
|
82
216
|
function sleep(ms) {
|
|
83
217
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
84
218
|
}
|
|
219
|
+
function normalizeHeaders(headers) {
|
|
220
|
+
const result = {};
|
|
221
|
+
if (!headers || typeof headers !== "object") return result;
|
|
222
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
223
|
+
if (value !== void 0 && value !== null) result[key.toLowerCase()] = String(value);
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
85
227
|
var HttpClient = class {
|
|
86
228
|
constructor(options) {
|
|
87
229
|
this.pendingRequests = 0;
|
|
230
|
+
this.timeOffsetMs = 0;
|
|
88
231
|
this.apiKey = options.apiKey;
|
|
89
|
-
this.apiSecret = options.apiSecret;
|
|
90
232
|
this.recvWindow = options.recvWindow ?? 5e3;
|
|
91
233
|
this.timeoutMs = options.timeoutMs ?? 15e3;
|
|
92
234
|
this.maxRetries = options.maxRetries ?? 3;
|
|
@@ -94,7 +236,22 @@ var HttpClient = class {
|
|
|
94
236
|
this.retryBaseDelayMs = options.retryBaseDelayMs ?? 1e3;
|
|
95
237
|
this.retryMaxDelayMs = options.retryMaxDelayMs ?? 3e4;
|
|
96
238
|
this.retryFactor = options.retryFactor ?? 2;
|
|
97
|
-
this.
|
|
239
|
+
this.signer = new Signer({
|
|
240
|
+
algorithm: options.signatureAlgorithm,
|
|
241
|
+
apiSecret: options.apiSecret,
|
|
242
|
+
privateKey: options.privateKey
|
|
243
|
+
});
|
|
244
|
+
this.rateLimitTracker = new RateLimitTracker({
|
|
245
|
+
weightLimitPerMinute: options.rateLimitWeightPerMinute,
|
|
246
|
+
safetyMargin: options.rateLimitSafetyMargin
|
|
247
|
+
});
|
|
248
|
+
this.policy = options.policy;
|
|
249
|
+
this.axios = import_axios.default.create({
|
|
250
|
+
baseURL: options.baseURL,
|
|
251
|
+
timeout: this.timeoutMs,
|
|
252
|
+
httpsAgent: options.httpsAgent,
|
|
253
|
+
proxy: options.proxy
|
|
254
|
+
});
|
|
98
255
|
this.limiter = new import_bottleneck.default({ minTime: this.minTimeMs });
|
|
99
256
|
}
|
|
100
257
|
async get(path, params, mode = "public") {
|
|
@@ -112,6 +269,10 @@ var HttpClient = class {
|
|
|
112
269
|
getRateLimiterStatus() {
|
|
113
270
|
return { minTimeMs: this.minTimeMs, queueLength: this.pendingRequests };
|
|
114
271
|
}
|
|
272
|
+
/** Snapshot of the most recently observed `X-MBX-USED-WEIGHT-*` / `X-MBX-ORDER-COUNT-*` response headers. */
|
|
273
|
+
getRateLimitUsage() {
|
|
274
|
+
return this.rateLimitTracker.getUsage();
|
|
275
|
+
}
|
|
115
276
|
configureRateLimiter(options) {
|
|
116
277
|
if (options.minTimeMs !== void 0) {
|
|
117
278
|
this.minTimeMs = options.minTimeMs;
|
|
@@ -132,10 +293,28 @@ var HttpClient = class {
|
|
|
132
293
|
if (options.maxDelayMs !== void 0) this.retryMaxDelayMs = options.maxDelayMs;
|
|
133
294
|
if (options.factor !== void 0) this.retryFactor = options.factor;
|
|
134
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Fetches server time from `timePath` (e.g. '/time', '/fapi/v1/time', '/dapi/v1/time') and
|
|
298
|
+
* stores the offset from local time, applied to every signed request's `timestamp` param.
|
|
299
|
+
* Mitigates `-1021` (timestamp outside recvWindow) errors caused by local clock drift.
|
|
300
|
+
*/
|
|
301
|
+
async syncTime(timePath = "/time") {
|
|
302
|
+
const res = await this.axios.request({ method: "GET", url: timePath });
|
|
303
|
+
this.timeOffsetMs = res.data.serverTime - Date.now();
|
|
304
|
+
return this.timeOffsetMs;
|
|
305
|
+
}
|
|
306
|
+
getTimeOffsetMs() {
|
|
307
|
+
return this.timeOffsetMs;
|
|
308
|
+
}
|
|
135
309
|
async request(method, path, params, mode) {
|
|
310
|
+
this.policy?.check(method, path, params ?? {});
|
|
136
311
|
const url = this.buildUrl(path, params, mode);
|
|
137
312
|
const config = { method, url, headers: this.buildHeaders(mode) };
|
|
138
|
-
return this.limiter.schedule(() =>
|
|
313
|
+
return this.limiter.schedule(async () => {
|
|
314
|
+
const throttleMs = this.rateLimitTracker.getThrottleDelayMs();
|
|
315
|
+
if (throttleMs > 0) await sleep(throttleMs);
|
|
316
|
+
return this.requestWithRetry(config, 0, method, path);
|
|
317
|
+
});
|
|
139
318
|
}
|
|
140
319
|
buildHeaders(mode) {
|
|
141
320
|
const headers = {
|
|
@@ -147,7 +326,7 @@ var HttpClient = class {
|
|
|
147
326
|
}
|
|
148
327
|
buildUrl(path, params, mode) {
|
|
149
328
|
if (mode !== "signed") return this.appendQuery(path, params);
|
|
150
|
-
const requestData = { ...params, timestamp: Date.now(), recvWindow: this.recvWindow };
|
|
329
|
+
const requestData = { ...params, timestamp: Date.now() + this.timeOffsetMs, recvWindow: this.recvWindow };
|
|
151
330
|
const queryString = this.buildQueryString(requestData);
|
|
152
331
|
const signature = this.sign(queryString);
|
|
153
332
|
return `${path}?${queryString}&signature=${signature}`;
|
|
@@ -158,20 +337,25 @@ var HttpClient = class {
|
|
|
158
337
|
}
|
|
159
338
|
buildQueryString(params) {
|
|
160
339
|
if (!params) return "";
|
|
161
|
-
return Object.entries(params).filter(([, val]) => val !== void 0 && val !== null).
|
|
340
|
+
return Object.entries(params).filter(([, val]) => val !== void 0 && val !== null).flatMap(
|
|
341
|
+
([key, val]) => Array.isArray(val) ? val.map((item) => `${key}=${encodeURIComponent(String(item))}`) : [`${key}=${encodeURIComponent(String(val))}`]
|
|
342
|
+
).join("&");
|
|
162
343
|
}
|
|
163
344
|
sign(queryString) {
|
|
164
|
-
if (!this.
|
|
165
|
-
|
|
345
|
+
if (!this.signer.canSign()) {
|
|
346
|
+
throw new BinanceAuthError(this.signer.algorithm === "HMAC" ? "apiSecret" : "privateKey");
|
|
347
|
+
}
|
|
348
|
+
return this.signer.sign(queryString);
|
|
166
349
|
}
|
|
167
350
|
requireApiKey() {
|
|
168
351
|
if (!this.apiKey) throw new BinanceAuthError("apiKey");
|
|
169
352
|
return this.apiKey;
|
|
170
353
|
}
|
|
171
|
-
async requestWithRetry(config, attempt) {
|
|
354
|
+
async requestWithRetry(config, attempt, method, endpoint) {
|
|
172
355
|
this.pendingRequests += 1;
|
|
173
356
|
try {
|
|
174
357
|
const res = await this.axios.request(config);
|
|
358
|
+
this.rateLimitTracker.update(normalizeHeaders(res.headers));
|
|
175
359
|
return res.data;
|
|
176
360
|
} catch (err) {
|
|
177
361
|
if (!import_axios.default.isAxiosError(err)) {
|
|
@@ -179,21 +363,36 @@ var HttpClient = class {
|
|
|
179
363
|
}
|
|
180
364
|
const status = err.response?.status;
|
|
181
365
|
const body = err.response?.data;
|
|
366
|
+
const headers = normalizeHeaders(err.response?.headers);
|
|
367
|
+
this.rateLimitTracker.update(headers);
|
|
182
368
|
if (attempt < this.maxRetries && this.shouldRetry(err)) {
|
|
183
369
|
await sleep(this.calculateDelay(attempt));
|
|
184
|
-
return this.requestWithRetry(config, attempt + 1);
|
|
370
|
+
return this.requestWithRetry(config, attempt + 1, method, endpoint);
|
|
185
371
|
}
|
|
372
|
+
const context = { endpoint, method, headers };
|
|
186
373
|
if (status === 429 || status === 418) {
|
|
187
|
-
throw new RateLimitError(
|
|
374
|
+
throw new RateLimitError(
|
|
375
|
+
body?.msg ?? "Binance rate limit exceeded",
|
|
376
|
+
body?.code ?? -1,
|
|
377
|
+
status,
|
|
378
|
+
this.parseRetryAfterMs(headers),
|
|
379
|
+
context
|
|
380
|
+
);
|
|
188
381
|
}
|
|
189
382
|
if (status && body) {
|
|
190
|
-
throw new BinanceApiError(body.msg ?? "Binance API error", body.code ?? -1, status);
|
|
383
|
+
throw new BinanceApiError(body.msg ?? "Binance API error", body.code ?? -1, status, context);
|
|
191
384
|
}
|
|
192
385
|
throw new NetworkError(err.message, err);
|
|
193
386
|
} finally {
|
|
194
387
|
this.pendingRequests -= 1;
|
|
195
388
|
}
|
|
196
389
|
}
|
|
390
|
+
parseRetryAfterMs(headers) {
|
|
391
|
+
const raw = headers["retry-after"];
|
|
392
|
+
if (!raw) return void 0;
|
|
393
|
+
const seconds = Number(raw);
|
|
394
|
+
return Number.isFinite(seconds) ? seconds * 1e3 : void 0;
|
|
395
|
+
}
|
|
197
396
|
shouldRetry(err) {
|
|
198
397
|
if (err.response?.status !== void 0) return RETRYABLE_STATUS.has(err.response.status);
|
|
199
398
|
return true;
|
|
@@ -205,6 +404,92 @@ var HttpClient = class {
|
|
|
205
404
|
}
|
|
206
405
|
};
|
|
207
406
|
|
|
407
|
+
// src/client/TradingPolicy.ts
|
|
408
|
+
var WITHDRAW_FRAGMENTS = ["/capital/withdraw/apply"];
|
|
409
|
+
var TRANSFER_FRAGMENTS = [
|
|
410
|
+
"/asset/transfer",
|
|
411
|
+
"/margin/transfer",
|
|
412
|
+
"/margin/isolated/transfer",
|
|
413
|
+
"/universaltransfer",
|
|
414
|
+
"/futures/transfer"
|
|
415
|
+
];
|
|
416
|
+
var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "DELETE"]);
|
|
417
|
+
function toNumber(value) {
|
|
418
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
419
|
+
const num2 = Number(value);
|
|
420
|
+
return Number.isFinite(num2) ? num2 : void 0;
|
|
421
|
+
}
|
|
422
|
+
function includesFragment(path, fragments) {
|
|
423
|
+
const lower = path.toLowerCase();
|
|
424
|
+
return fragments.some((fragment) => lower.includes(fragment.toLowerCase()));
|
|
425
|
+
}
|
|
426
|
+
var TradingPolicy = class {
|
|
427
|
+
constructor(options = {}) {
|
|
428
|
+
this.options = options;
|
|
429
|
+
if (options.allowedSymbols?.length) {
|
|
430
|
+
this.allowedSymbols = new Set(options.allowedSymbols.map((s) => s.toUpperCase()));
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/** Throws {@link PolicyViolationError} or {@link DryRunError} if the request is not permitted. */
|
|
434
|
+
check(method, path, params = {}) {
|
|
435
|
+
if (!MUTATING_METHODS.has(method)) return;
|
|
436
|
+
const deny = (rule, message, details) => {
|
|
437
|
+
throw new PolicyViolationError(rule, message, method, path, details);
|
|
438
|
+
};
|
|
439
|
+
if (this.options.blockedPaths?.length && includesFragment(path, this.options.blockedPaths)) {
|
|
440
|
+
deny("blockedPath", "endpoint is on the blocked-path list");
|
|
441
|
+
}
|
|
442
|
+
if (this.options.readOnly) {
|
|
443
|
+
deny("readOnly", "client is in read-only mode; mutating requests are refused");
|
|
444
|
+
}
|
|
445
|
+
if (includesFragment(path, WITHDRAW_FRAGMENTS) && this.options.allowWithdrawals !== true) {
|
|
446
|
+
deny("withdrawalsBlocked", "withdrawals are disabled; set safety.allowWithdrawals to permit them");
|
|
447
|
+
}
|
|
448
|
+
if (includesFragment(path, TRANSFER_FRAGMENTS) && this.options.allowTransfers === false) {
|
|
449
|
+
deny("transfersBlocked", "account transfers are disabled by policy");
|
|
450
|
+
}
|
|
451
|
+
this.checkSymbol(path, params, deny);
|
|
452
|
+
this.checkNotional(path, params, deny);
|
|
453
|
+
if (this.options.dryRun) {
|
|
454
|
+
throw new DryRunError(method, path, params);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
checkSymbol(path, params, deny) {
|
|
458
|
+
if (!this.allowedSymbols) return;
|
|
459
|
+
const symbol3 = params.symbol;
|
|
460
|
+
if (typeof symbol3 !== "string" || symbol3 === "") return;
|
|
461
|
+
if (!this.allowedSymbols.has(symbol3.toUpperCase())) {
|
|
462
|
+
deny("symbolNotAllowed", `symbol ${symbol3} is not in the allowed list`, {
|
|
463
|
+
symbol: symbol3,
|
|
464
|
+
allowed: [...this.allowedSymbols]
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
checkNotional(path, params, deny) {
|
|
469
|
+
const max = this.options.maxNotionalPerOrder;
|
|
470
|
+
if (max === void 0) return;
|
|
471
|
+
if (!path.toLowerCase().includes("order")) return;
|
|
472
|
+
const quantity = toNumber(params.quantity);
|
|
473
|
+
const quoteOrderQty = toNumber(params.quoteOrderQty);
|
|
474
|
+
if (quantity === void 0 && quoteOrderQty === void 0) return;
|
|
475
|
+
const price = toNumber(params.price);
|
|
476
|
+
const notional = quoteOrderQty ?? (price !== void 0 && quantity !== void 0 ? price * quantity : void 0);
|
|
477
|
+
if (notional === void 0) {
|
|
478
|
+
deny(
|
|
479
|
+
"notionalUndeterminable",
|
|
480
|
+
`cannot verify notional against the ${max} cap (no price on this order); supply a price or raise/remove maxNotionalPerOrder`,
|
|
481
|
+
{ quantity, maxNotionalPerOrder: max }
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
if (notional > max) {
|
|
485
|
+
deny("maxNotionalPerOrder", `order notional ${notional} exceeds the ${max} cap`, {
|
|
486
|
+
notional,
|
|
487
|
+
maxNotionalPerOrder: max
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
|
|
208
493
|
// src/client/endpoints.ts
|
|
209
494
|
function resolveEnvironment(options) {
|
|
210
495
|
const env = options?.demo ? "demo" : options?.testnet ? "testnet" : "live";
|
|
@@ -215,6 +500,9 @@ function resolveEnvironment(options) {
|
|
|
215
500
|
const restSpotHost = options?.apiBase ?? (env === "testnet" ? "https://testnet.binance.vision" : "https://api.binance.com");
|
|
216
501
|
const wsSpotMarketHost = options?.wsBase ?? (env === "testnet" ? "wss://testnet.binance.vision/stream" : "wss://stream.binance.com:9443/stream");
|
|
217
502
|
const wsSpotUserHost = options?.wsUserBase ?? (env === "testnet" ? "wss://testnet.binance.vision/ws" : "wss://stream.binance.com:9443/ws");
|
|
503
|
+
const restDapiHost = options?.dapiBase ?? (env === "testnet" || env === "demo" ? "https://testnet.binancefuture.com" : "https://dapi.binance.com");
|
|
504
|
+
const wsSpotApiHost = options?.wsSpotApiBase ?? (env === "testnet" ? "wss://testnet.binance.vision/ws-api/v3" : "wss://ws-api.binance.com:443/ws-api/v3");
|
|
505
|
+
const wsDapiHost = options?.wsDapiBase ?? (env === "testnet" || env === "demo" ? "wss://dstream.binancefuture.com" : "wss://dstream.binance.com");
|
|
218
506
|
return {
|
|
219
507
|
env,
|
|
220
508
|
endpoints: {
|
|
@@ -222,11 +510,17 @@ function resolveEnvironment(options) {
|
|
|
222
510
|
restFapi: `${restHost}/fapi/v1`,
|
|
223
511
|
restFuturesData: `${restHost}/futures/data`,
|
|
224
512
|
restSpot: `${restSpotHost}/api/v3`,
|
|
513
|
+
restApiRoot: restSpotHost,
|
|
514
|
+
restDapiRoot: restDapiHost,
|
|
515
|
+
restDapi: `${restDapiHost}/dapi/v1`,
|
|
225
516
|
wsMarket: wsMarketHost,
|
|
226
517
|
wsUser: wsUserHost,
|
|
227
518
|
wsApi: wsApiHost,
|
|
228
519
|
wsSpotMarket: wsSpotMarketHost,
|
|
229
|
-
wsSpotUser: wsSpotUserHost
|
|
520
|
+
wsSpotUser: wsSpotUserHost,
|
|
521
|
+
wsSpotApi: wsSpotApiHost,
|
|
522
|
+
wsDapiMarket: `${wsDapiHost}/stream`,
|
|
523
|
+
wsDapiUser: `${wsDapiHost}/ws`
|
|
230
524
|
}
|
|
231
525
|
};
|
|
232
526
|
}
|
|
@@ -1875,301 +2169,1404 @@ var UserDataStream = class {
|
|
|
1875
2169
|
}
|
|
1876
2170
|
};
|
|
1877
2171
|
|
|
1878
|
-
// src/
|
|
1879
|
-
var import_node_events = require("events");
|
|
1880
|
-
var import_ws = __toESM(require("ws"), 1);
|
|
1881
|
-
|
|
1882
|
-
// src/types/ws.types.ts
|
|
2172
|
+
// src/types/coinm.types.ts
|
|
1883
2173
|
var import_zod7 = require("zod");
|
|
1884
|
-
var
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
o: import_zod7.z.string().transform(Number),
|
|
1894
|
-
c: import_zod7.z.string().transform(Number),
|
|
1895
|
-
h: import_zod7.z.string().transform(Number),
|
|
1896
|
-
l: import_zod7.z.string().transform(Number),
|
|
1897
|
-
v: import_zod7.z.string().transform(Number),
|
|
1898
|
-
n: import_zod7.z.number(),
|
|
1899
|
-
x: import_zod7.z.boolean(),
|
|
1900
|
-
q: import_zod7.z.string().transform(Number),
|
|
1901
|
-
V: import_zod7.z.string().transform(Number),
|
|
1902
|
-
Q: import_zod7.z.string().transform(Number)
|
|
1903
|
-
})
|
|
2174
|
+
var CoinMBalanceSchema = import_zod7.z.object({
|
|
2175
|
+
accountAlias: import_zod7.z.string(),
|
|
2176
|
+
asset: import_zod7.z.string(),
|
|
2177
|
+
balance: import_zod7.z.string().transform(Number),
|
|
2178
|
+
withdrawAvailable: import_zod7.z.string().transform(Number),
|
|
2179
|
+
crossWalletBalance: import_zod7.z.string().transform(Number),
|
|
2180
|
+
crossUnPnl: import_zod7.z.string().transform(Number),
|
|
2181
|
+
availableBalance: import_zod7.z.string().transform(Number),
|
|
2182
|
+
updateTime: import_zod7.z.number()
|
|
1904
2183
|
});
|
|
1905
|
-
var
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
2184
|
+
var CoinMBalanceResponseSchema = import_zod7.z.array(CoinMBalanceSchema);
|
|
2185
|
+
var CoinMPositionRiskSchema = import_zod7.z.object({
|
|
2186
|
+
symbol: import_zod7.z.string(),
|
|
2187
|
+
pair: import_zod7.z.string().optional(),
|
|
2188
|
+
positionAmt: import_zod7.z.string().transform(Number),
|
|
2189
|
+
entryPrice: import_zod7.z.string().transform(Number),
|
|
2190
|
+
markPrice: import_zod7.z.string().transform(Number),
|
|
2191
|
+
unRealizedProfit: import_zod7.z.string().transform(Number),
|
|
2192
|
+
liquidationPrice: import_zod7.z.string().transform(Number),
|
|
2193
|
+
leverage: import_zod7.z.string().transform(Number),
|
|
2194
|
+
maxQty: import_zod7.z.string().transform(Number).optional(),
|
|
2195
|
+
marginType: import_zod7.z.enum(["isolated", "cross"]),
|
|
2196
|
+
isolatedMargin: import_zod7.z.string().transform(Number).optional(),
|
|
2197
|
+
isAutoAddMargin: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.boolean()]).optional(),
|
|
2198
|
+
positionSide: import_zod7.z.string(),
|
|
2199
|
+
notionalValue: import_zod7.z.string().transform(Number).optional(),
|
|
2200
|
+
breakEvenPrice: import_zod7.z.string().transform(Number).optional(),
|
|
2201
|
+
updateTime: import_zod7.z.number().optional()
|
|
2202
|
+
}).loose();
|
|
2203
|
+
var CoinMPositionRiskResponseSchema = import_zod7.z.array(CoinMPositionRiskSchema);
|
|
2204
|
+
var CoinMAccountAssetSchema = import_zod7.z.object({
|
|
2205
|
+
asset: import_zod7.z.string(),
|
|
2206
|
+
walletBalance: import_zod7.z.string().transform(Number),
|
|
2207
|
+
unrealizedProfit: import_zod7.z.string().transform(Number),
|
|
2208
|
+
marginBalance: import_zod7.z.string().transform(Number),
|
|
2209
|
+
maintMargin: import_zod7.z.string().transform(Number),
|
|
2210
|
+
initialMargin: import_zod7.z.string().transform(Number),
|
|
2211
|
+
positionInitialMargin: import_zod7.z.string().transform(Number),
|
|
2212
|
+
openOrderInitialMargin: import_zod7.z.string().transform(Number),
|
|
2213
|
+
maxWithdrawAmount: import_zod7.z.string().transform(Number),
|
|
2214
|
+
crossWalletBalance: import_zod7.z.string().transform(Number),
|
|
2215
|
+
crossUnPnl: import_zod7.z.string().transform(Number),
|
|
2216
|
+
availableBalance: import_zod7.z.string().transform(Number),
|
|
2217
|
+
updateTime: import_zod7.z.number()
|
|
2218
|
+
}).loose();
|
|
2219
|
+
var CoinMAccountPositionSchema = import_zod7.z.object({
|
|
2220
|
+
symbol: import_zod7.z.string(),
|
|
2221
|
+
positionAmt: import_zod7.z.string().transform(Number),
|
|
2222
|
+
initialMargin: import_zod7.z.string().transform(Number),
|
|
2223
|
+
maintMargin: import_zod7.z.string().transform(Number),
|
|
2224
|
+
unrealizedProfit: import_zod7.z.string().transform(Number),
|
|
2225
|
+
positionInitialMargin: import_zod7.z.string().transform(Number),
|
|
2226
|
+
openOrderInitialMargin: import_zod7.z.string().transform(Number),
|
|
2227
|
+
leverage: import_zod7.z.string().transform(Number),
|
|
2228
|
+
isolated: import_zod7.z.boolean(),
|
|
2229
|
+
positionSide: import_zod7.z.string(),
|
|
2230
|
+
entryPrice: import_zod7.z.string().transform(Number),
|
|
2231
|
+
maxQty: import_zod7.z.string().transform(Number).optional(),
|
|
2232
|
+
updateTime: import_zod7.z.number().optional()
|
|
2233
|
+
}).loose();
|
|
2234
|
+
var CoinMAccountSchema = import_zod7.z.object({
|
|
2235
|
+
canDeposit: import_zod7.z.boolean(),
|
|
2236
|
+
canTrade: import_zod7.z.boolean(),
|
|
2237
|
+
canWithdraw: import_zod7.z.boolean(),
|
|
2238
|
+
feeTier: import_zod7.z.number(),
|
|
2239
|
+
updateTime: import_zod7.z.number(),
|
|
2240
|
+
assets: import_zod7.z.array(CoinMAccountAssetSchema),
|
|
2241
|
+
positions: import_zod7.z.array(CoinMAccountPositionSchema)
|
|
2242
|
+
}).loose();
|
|
2243
|
+
var CoinMOrderSchema = import_zod7.z.object({
|
|
2244
|
+
orderId: import_zod7.z.number(),
|
|
2245
|
+
symbol: import_zod7.z.string(),
|
|
2246
|
+
pair: import_zod7.z.string().optional(),
|
|
2247
|
+
status: import_zod7.z.string(),
|
|
2248
|
+
clientOrderId: import_zod7.z.string(),
|
|
2249
|
+
price: import_zod7.z.string().transform(Number),
|
|
2250
|
+
avgPrice: import_zod7.z.string().transform(Number),
|
|
2251
|
+
origQty: import_zod7.z.string().transform(Number),
|
|
2252
|
+
executedQty: import_zod7.z.string().transform(Number),
|
|
2253
|
+
cumBase: import_zod7.z.string().transform(Number).optional(),
|
|
2254
|
+
type: import_zod7.z.string(),
|
|
2255
|
+
reduceOnly: import_zod7.z.boolean(),
|
|
2256
|
+
closePosition: import_zod7.z.boolean().optional(),
|
|
2257
|
+
side: import_zod7.z.string(),
|
|
2258
|
+
positionSide: import_zod7.z.string(),
|
|
2259
|
+
stopPrice: import_zod7.z.string().transform(Number).optional(),
|
|
2260
|
+
workingType: import_zod7.z.string().optional(),
|
|
2261
|
+
priceProtect: import_zod7.z.boolean().optional(),
|
|
2262
|
+
origType: import_zod7.z.string().optional(),
|
|
2263
|
+
timeInForce: import_zod7.z.string().optional(),
|
|
2264
|
+
activatePrice: import_zod7.z.string().transform(Number).optional(),
|
|
2265
|
+
priceRate: import_zod7.z.string().transform(Number).optional(),
|
|
2266
|
+
time: import_zod7.z.number(),
|
|
2267
|
+
updateTime: import_zod7.z.number()
|
|
2268
|
+
}).loose();
|
|
2269
|
+
var CoinMOrderResponseSchema = CoinMOrderSchema;
|
|
2270
|
+
var CoinMOrdersResponseSchema = import_zod7.z.array(CoinMOrderSchema);
|
|
2271
|
+
var CoinMCreateOrderParamsSchema = import_zod7.z.object({
|
|
2272
|
+
symbol: import_zod7.z.string(),
|
|
2273
|
+
side: import_zod7.z.enum(["BUY", "SELL"]),
|
|
2274
|
+
positionSide: import_zod7.z.enum(["BOTH", "LONG", "SHORT"]).optional(),
|
|
2275
|
+
type: import_zod7.z.string(),
|
|
2276
|
+
timeInForce: import_zod7.z.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
|
|
2277
|
+
quantity: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.number()]).optional(),
|
|
2278
|
+
reduceOnly: import_zod7.z.boolean().optional(),
|
|
2279
|
+
price: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.number()]).optional(),
|
|
2280
|
+
newClientOrderId: import_zod7.z.string().optional(),
|
|
2281
|
+
stopPrice: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.number()]).optional(),
|
|
2282
|
+
closePosition: import_zod7.z.boolean().optional(),
|
|
2283
|
+
activationPrice: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.number()]).optional(),
|
|
2284
|
+
callbackRate: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.number()]).optional(),
|
|
2285
|
+
workingType: import_zod7.z.enum(["MARK_PRICE", "CONTRACT_PRICE"]).optional(),
|
|
2286
|
+
priceProtect: import_zod7.z.boolean().optional(),
|
|
2287
|
+
newOrderRespType: import_zod7.z.enum(["ACK", "RESULT"]).optional()
|
|
1996
2288
|
});
|
|
1997
|
-
var
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
p: import_zod7.z.string().transform(Number),
|
|
2002
|
-
c: import_zod7.z.array(
|
|
2003
|
-
import_zod7.z.object({
|
|
2004
|
-
b: import_zod7.z.string(),
|
|
2005
|
-
q: import_zod7.z.string(),
|
|
2006
|
-
w: import_zod7.z.string().transform(Number),
|
|
2007
|
-
p: import_zod7.z.string().transform(Number)
|
|
2008
|
-
})
|
|
2009
|
-
)
|
|
2289
|
+
var CoinMLeverageChangeSchema = import_zod7.z.object({
|
|
2290
|
+
leverage: import_zod7.z.number(),
|
|
2291
|
+
maxQty: import_zod7.z.string().transform(Number),
|
|
2292
|
+
symbol: import_zod7.z.string()
|
|
2010
2293
|
});
|
|
2011
|
-
var
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2294
|
+
var CoinMMarginTypeChangeSchema = import_zod7.z.object({ code: import_zod7.z.number(), msg: import_zod7.z.string() });
|
|
2295
|
+
var CoinMPositionMarginChangeSchema = import_zod7.z.object({
|
|
2296
|
+
amount: import_zod7.z.number(),
|
|
2297
|
+
code: import_zod7.z.number(),
|
|
2298
|
+
msg: import_zod7.z.string(),
|
|
2299
|
+
type: import_zod7.z.number()
|
|
2300
|
+
});
|
|
2301
|
+
var CoinMIncomeSchema = import_zod7.z.object({
|
|
2302
|
+
symbol: import_zod7.z.string().optional(),
|
|
2303
|
+
incomeType: import_zod7.z.string(),
|
|
2304
|
+
income: import_zod7.z.string().transform(Number),
|
|
2305
|
+
asset: import_zod7.z.string(),
|
|
2306
|
+
info: import_zod7.z.string().optional(),
|
|
2307
|
+
time: import_zod7.z.number(),
|
|
2308
|
+
tranId: import_zod7.z.number(),
|
|
2309
|
+
tradeId: import_zod7.z.string().optional()
|
|
2310
|
+
}).loose();
|
|
2311
|
+
var CoinMIncomeHistoryResponseSchema = import_zod7.z.array(CoinMIncomeSchema);
|
|
2312
|
+
var CoinMUserTradeSchema = import_zod7.z.object({
|
|
2313
|
+
symbol: import_zod7.z.string(),
|
|
2314
|
+
id: import_zod7.z.number(),
|
|
2315
|
+
orderId: import_zod7.z.number(),
|
|
2316
|
+
pair: import_zod7.z.string().optional(),
|
|
2317
|
+
side: import_zod7.z.string(),
|
|
2318
|
+
price: import_zod7.z.string().transform(Number),
|
|
2319
|
+
qty: import_zod7.z.string().transform(Number),
|
|
2320
|
+
realizedPnl: import_zod7.z.string().transform(Number),
|
|
2321
|
+
marginAsset: import_zod7.z.string().optional(),
|
|
2322
|
+
baseQty: import_zod7.z.string().transform(Number).optional(),
|
|
2323
|
+
commission: import_zod7.z.string().transform(Number),
|
|
2324
|
+
commissionAsset: import_zod7.z.string(),
|
|
2325
|
+
time: import_zod7.z.number(),
|
|
2326
|
+
positionSide: import_zod7.z.string(),
|
|
2327
|
+
buyer: import_zod7.z.boolean(),
|
|
2328
|
+
maker: import_zod7.z.boolean()
|
|
2329
|
+
}).loose();
|
|
2330
|
+
var CoinMUserTradesResponseSchema = import_zod7.z.array(CoinMUserTradeSchema);
|
|
2331
|
+
var CoinMOpenInterestHistEntrySchema = import_zod7.z.object({
|
|
2332
|
+
pair: import_zod7.z.string(),
|
|
2333
|
+
contractType: import_zod7.z.string(),
|
|
2334
|
+
sumOpenInterest: import_zod7.z.string().transform(Number),
|
|
2335
|
+
sumOpenInterestValue: import_zod7.z.string().transform(Number),
|
|
2336
|
+
timestamp: import_zod7.z.number()
|
|
2337
|
+
});
|
|
2338
|
+
var CoinMOpenInterestHistSchema = import_zod7.z.array(CoinMOpenInterestHistEntrySchema);
|
|
2339
|
+
var CoinMPositionModeSchema = import_zod7.z.object({ dualSidePosition: import_zod7.z.boolean() });
|
|
2340
|
+
var CoinMLeverageBracketSchema = import_zod7.z.object({
|
|
2341
|
+
bracket: import_zod7.z.number(),
|
|
2342
|
+
initialLeverage: import_zod7.z.number(),
|
|
2343
|
+
qtyCap: import_zod7.z.number(),
|
|
2344
|
+
qtyFloor: import_zod7.z.number(),
|
|
2345
|
+
maintMarginRatio: import_zod7.z.number(),
|
|
2346
|
+
cum: import_zod7.z.number().optional()
|
|
2347
|
+
});
|
|
2348
|
+
var CoinMLeverageBracketResponseSchema = import_zod7.z.array(
|
|
2349
|
+
import_zod7.z.object({
|
|
2350
|
+
symbol: import_zod7.z.string().optional(),
|
|
2351
|
+
pair: import_zod7.z.string().optional(),
|
|
2352
|
+
brackets: import_zod7.z.array(CoinMLeverageBracketSchema)
|
|
2353
|
+
})
|
|
2354
|
+
);
|
|
2355
|
+
var CoinMCommissionRateSchema = import_zod7.z.object({
|
|
2356
|
+
symbol: import_zod7.z.string(),
|
|
2357
|
+
makerCommissionRate: import_zod7.z.string().transform(Number),
|
|
2358
|
+
takerCommissionRate: import_zod7.z.string().transform(Number)
|
|
2041
2359
|
});
|
|
2042
|
-
function parseWsPayload(streamName, raw) {
|
|
2043
|
-
if (streamName.includes("@kline_")) return WsKlinePayloadSchema.parse(raw);
|
|
2044
|
-
if (streamName.includes("@continuousKline_") || streamName.includes("@indexPriceKline_") || streamName.includes("@markPriceKline_")) {
|
|
2045
|
-
return WsKlinePayloadSchema.parse(raw);
|
|
2046
|
-
}
|
|
2047
|
-
if (streamName.includes("@aggTrade")) return WsAggTradePayloadSchema.parse(raw);
|
|
2048
|
-
if (streamName.includes("@trade")) return WsTradePayloadSchema.parse(raw);
|
|
2049
|
-
if (streamName.includes("@depth")) return WsDepthUpdatePayloadSchema.parse(raw);
|
|
2050
|
-
if (streamName.includes("@bookTicker")) return WsBookTickerPayloadSchema.parse(raw);
|
|
2051
|
-
if (streamName.includes("@markPrice")) return WsMarkPricePayloadSchema.parse(raw);
|
|
2052
|
-
if (streamName.includes("@miniTicker")) return WsMiniTickerPayloadSchema.parse(raw);
|
|
2053
|
-
if (streamName.includes("@forceOrder")) return WsForceOrderPayloadSchema.parse(raw);
|
|
2054
|
-
if (streamName.includes("@compositeIndex")) return WsCompositeIndexPayloadSchema.parse(raw);
|
|
2055
|
-
if (streamName.includes("@assetIndex")) return WsAssetIndexPayloadSchema.parse(raw);
|
|
2056
|
-
if (streamName.includes("@avgPrice")) return WsSpotAvgPricePayloadSchema.parse(raw);
|
|
2057
|
-
if (streamName.includes("@ticker_")) return WsRollingWindowTickerPayloadSchema.parse(raw);
|
|
2058
|
-
if (streamName.includes("@ticker")) return WsTicker24hrPayloadSchema.parse(raw);
|
|
2059
|
-
throw new Error(`Unknown WS stream type: ${streamName}`);
|
|
2060
|
-
}
|
|
2061
2360
|
|
|
2062
|
-
// src/
|
|
2063
|
-
var
|
|
2064
|
-
constructor(
|
|
2065
|
-
super();
|
|
2066
|
-
this.options = options;
|
|
2067
|
-
this.ws = null;
|
|
2068
|
-
this.streams = /* @__PURE__ */ new Set();
|
|
2069
|
-
this.reconnectAttempt = 0;
|
|
2070
|
-
this.closedByUser = false;
|
|
2071
|
-
}
|
|
2072
|
-
subscribe(streams) {
|
|
2073
|
-
streams.forEach((s) => this.streams.add(s));
|
|
2074
|
-
if (this.isOpen()) {
|
|
2075
|
-
this.send({ method: "SUBSCRIBE", params: streams, id: Date.now() });
|
|
2076
|
-
} else {
|
|
2077
|
-
this.connect();
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
unsubscribe(streams) {
|
|
2081
|
-
streams.forEach((s) => this.streams.delete(s));
|
|
2082
|
-
if (this.isOpen()) {
|
|
2083
|
-
this.send({ method: "UNSUBSCRIBE", params: streams, id: Date.now() });
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
close() {
|
|
2087
|
-
this.closedByUser = true;
|
|
2088
|
-
this.ws?.close();
|
|
2361
|
+
// src/resources/CoinMMarket.ts
|
|
2362
|
+
var CoinMMarket = class extends MarketDataBase {
|
|
2363
|
+
constructor(http2) {
|
|
2364
|
+
super(http2 ?? new HttpClient({ baseURL: "https://dapi.binance.com/dapi/v1" }));
|
|
2089
2365
|
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2366
|
+
async continuousKlines(pair, contractType2, interval, options) {
|
|
2367
|
+
const data = await this.http.get("/continuousKlines", {
|
|
2368
|
+
pair,
|
|
2369
|
+
contractType: contractType2,
|
|
2370
|
+
interval,
|
|
2371
|
+
startTime: options?.startTime,
|
|
2372
|
+
endTime: options?.endTime,
|
|
2373
|
+
limit: options?.limit ?? 500
|
|
2374
|
+
});
|
|
2375
|
+
return KlinesResponseSchema.parse(data);
|
|
2094
2376
|
}
|
|
2095
|
-
|
|
2096
|
-
this.
|
|
2377
|
+
async indexPriceKlines(pair, interval, options) {
|
|
2378
|
+
const data = await this.http.get("/indexPriceKlines", {
|
|
2379
|
+
pair,
|
|
2380
|
+
interval,
|
|
2381
|
+
startTime: options?.startTime,
|
|
2382
|
+
endTime: options?.endTime,
|
|
2383
|
+
limit: options?.limit ?? 500
|
|
2384
|
+
});
|
|
2385
|
+
return KlinesResponseSchema.parse(data);
|
|
2097
2386
|
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2387
|
+
async markPriceKlines(symbol3, interval, options) {
|
|
2388
|
+
const data = await this.http.get("/markPriceKlines", {
|
|
2389
|
+
symbol: symbol3,
|
|
2390
|
+
interval,
|
|
2391
|
+
startTime: options?.startTime,
|
|
2392
|
+
endTime: options?.endTime,
|
|
2393
|
+
limit: options?.limit ?? 500
|
|
2394
|
+
});
|
|
2395
|
+
return KlinesResponseSchema.parse(data);
|
|
2100
2396
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2397
|
+
async premiumIndex(options) {
|
|
2398
|
+
return PremiumIndexSchema.or(PremiumIndexSchema.array()).parse(
|
|
2399
|
+
await this.http.get("/premiumIndex", options)
|
|
2400
|
+
);
|
|
2103
2401
|
}
|
|
2104
|
-
|
|
2105
|
-
this.
|
|
2106
|
-
const url = `${this.options.baseStreamUrl}?streams=${[...this.streams].join("/")}`;
|
|
2107
|
-
this.ws = new import_ws.default(url);
|
|
2108
|
-
this.ws.on("open", () => {
|
|
2109
|
-
this.reconnectAttempt = 0;
|
|
2110
|
-
this.emit("open");
|
|
2111
|
-
});
|
|
2112
|
-
this.ws.on("message", (raw) => {
|
|
2113
|
-
this.handleMessage(raw.toString());
|
|
2114
|
-
});
|
|
2115
|
-
this.ws.on("close", () => {
|
|
2116
|
-
this.emit("close");
|
|
2117
|
-
if (!this.closedByUser) this.scheduleReconnect();
|
|
2118
|
-
});
|
|
2119
|
-
this.ws.on("error", (err) => {
|
|
2120
|
-
if (this.closedByUser) return;
|
|
2121
|
-
this.emit("error", err);
|
|
2122
|
-
});
|
|
2402
|
+
async fundingRateHistory(symbol3, options) {
|
|
2403
|
+
return FundingRateHistorySchema.parse(await this.http.get("/fundingRate", { symbol: symbol3, ...options }));
|
|
2123
2404
|
}
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
try {
|
|
2127
|
-
parsed = JSON.parse(raw);
|
|
2128
|
-
} catch {
|
|
2129
|
-
return;
|
|
2130
|
-
}
|
|
2131
|
-
if (!parsed.stream || parsed.data === void 0) return;
|
|
2132
|
-
try {
|
|
2133
|
-
const payload = parseWsPayload(parsed.stream, parsed.data);
|
|
2134
|
-
this.emit("message", parsed.stream, payload);
|
|
2135
|
-
this.emit(parsed.stream, payload);
|
|
2136
|
-
} catch (err) {
|
|
2137
|
-
this.emit("error", err);
|
|
2138
|
-
}
|
|
2405
|
+
async openInterest(symbol3) {
|
|
2406
|
+
return OpenInterestSchema.parse(await this.http.get("/openInterest", { symbol: symbol3 }));
|
|
2139
2407
|
}
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
this.reconnectAttempt += 1;
|
|
2145
|
-
setTimeout(() => {
|
|
2146
|
-
if (!this.closedByUser) this.connect();
|
|
2147
|
-
}, delay);
|
|
2408
|
+
async openInterestHist(pair, contractType2, period2, options) {
|
|
2409
|
+
return CoinMOpenInterestHistSchema.parse(
|
|
2410
|
+
await this.http.get("/openInterestHist", { pair, contractType: contractType2, period: period2, ...options })
|
|
2411
|
+
);
|
|
2148
2412
|
}
|
|
2149
2413
|
};
|
|
2150
2414
|
|
|
2151
|
-
// src/
|
|
2152
|
-
var
|
|
2153
|
-
constructor(
|
|
2154
|
-
|
|
2415
|
+
// src/resources/CoinMAccount.ts
|
|
2416
|
+
var CoinMAccount = class {
|
|
2417
|
+
constructor(http2) {
|
|
2418
|
+
this.http = http2;
|
|
2155
2419
|
}
|
|
2156
|
-
|
|
2157
|
-
return
|
|
2420
|
+
async balance() {
|
|
2421
|
+
return CoinMBalanceResponseSchema.parse(await this.http.get("/dapi/v1/balance", void 0, "signed"));
|
|
2158
2422
|
}
|
|
2159
|
-
|
|
2160
|
-
return
|
|
2423
|
+
async account() {
|
|
2424
|
+
return CoinMAccountSchema.parse(await this.http.get("/dapi/v1/account", void 0, "signed"));
|
|
2161
2425
|
}
|
|
2162
|
-
|
|
2163
|
-
return
|
|
2426
|
+
async positionRisk(options) {
|
|
2427
|
+
return CoinMPositionRiskResponseSchema.parse(
|
|
2428
|
+
await this.http.get("/dapi/v1/positionRisk", options, "signed")
|
|
2429
|
+
);
|
|
2164
2430
|
}
|
|
2165
|
-
|
|
2166
|
-
return
|
|
2431
|
+
async incomeHistory(options) {
|
|
2432
|
+
return CoinMIncomeHistoryResponseSchema.parse(await this.http.get("/dapi/v1/income", options, "signed"));
|
|
2167
2433
|
}
|
|
2168
|
-
|
|
2169
|
-
return
|
|
2434
|
+
async userTrades(options) {
|
|
2435
|
+
return CoinMUserTradesResponseSchema.parse(
|
|
2436
|
+
await this.http.get("/dapi/v1/userTrades", options, "signed")
|
|
2437
|
+
);
|
|
2170
2438
|
}
|
|
2171
|
-
|
|
2172
|
-
|
|
2439
|
+
async leverageBrackets(symbol3) {
|
|
2440
|
+
const params = symbol3 ? { symbol: symbol3 } : void 0;
|
|
2441
|
+
return CoinMLeverageBracketResponseSchema.parse(
|
|
2442
|
+
await this.http.get("/dapi/v1/leverageBracket", params, "signed")
|
|
2443
|
+
);
|
|
2444
|
+
}
|
|
2445
|
+
async commissionRate(symbol3) {
|
|
2446
|
+
return CoinMCommissionRateSchema.parse(
|
|
2447
|
+
await this.http.get("/dapi/v1/commissionRate", { symbol: symbol3 }, "signed")
|
|
2448
|
+
);
|
|
2449
|
+
}
|
|
2450
|
+
async positionMode() {
|
|
2451
|
+
return CoinMPositionModeSchema.parse(
|
|
2452
|
+
await this.http.get("/dapi/v1/positionSide/dual", void 0, "signed")
|
|
2453
|
+
);
|
|
2454
|
+
}
|
|
2455
|
+
async setPositionMode(dualSidePosition) {
|
|
2456
|
+
return this.http.post("/dapi/v1/positionSide/dual", { dualSidePosition }, "signed");
|
|
2457
|
+
}
|
|
2458
|
+
};
|
|
2459
|
+
|
|
2460
|
+
// src/resources/CoinMTrading.ts
|
|
2461
|
+
var CoinMTrading = class {
|
|
2462
|
+
constructor(http2) {
|
|
2463
|
+
this.http = http2;
|
|
2464
|
+
}
|
|
2465
|
+
async setLeverage(symbol3, leverage) {
|
|
2466
|
+
return CoinMLeverageChangeSchema.parse(
|
|
2467
|
+
await this.http.post("/dapi/v1/leverage", { symbol: symbol3, leverage }, "signed")
|
|
2468
|
+
);
|
|
2469
|
+
}
|
|
2470
|
+
async setMarginType(symbol3, marginType) {
|
|
2471
|
+
return CoinMMarginTypeChangeSchema.parse(
|
|
2472
|
+
await this.http.post("/dapi/v1/marginType", { symbol: symbol3, marginType }, "signed")
|
|
2473
|
+
);
|
|
2474
|
+
}
|
|
2475
|
+
async createOrder(params) {
|
|
2476
|
+
return CoinMOrderResponseSchema.parse(await this.http.post("/dapi/v1/order", params, "signed"));
|
|
2477
|
+
}
|
|
2478
|
+
async createTestOrder(params) {
|
|
2479
|
+
return this.http.post("/dapi/v1/order/test", params, "signed");
|
|
2480
|
+
}
|
|
2481
|
+
async getOrder(symbol3, options) {
|
|
2482
|
+
return CoinMOrderResponseSchema.parse(
|
|
2483
|
+
await this.http.get("/dapi/v1/order", { symbol: symbol3, ...options }, "signed")
|
|
2484
|
+
);
|
|
2485
|
+
}
|
|
2486
|
+
async cancelOrder(symbol3, options) {
|
|
2487
|
+
return CoinMOrderResponseSchema.parse(
|
|
2488
|
+
await this.http.delete("/dapi/v1/order", { symbol: symbol3, ...options }, "signed")
|
|
2489
|
+
);
|
|
2490
|
+
}
|
|
2491
|
+
async cancelAllOpenOrders(symbol3) {
|
|
2492
|
+
return this.http.delete("/dapi/v1/allOpenOrders", { symbol: symbol3 }, "signed");
|
|
2493
|
+
}
|
|
2494
|
+
async getOpenOrders(symbol3) {
|
|
2495
|
+
const params = symbol3 ? { symbol: symbol3 } : void 0;
|
|
2496
|
+
return CoinMOrdersResponseSchema.parse(await this.http.get("/dapi/v1/openOrders", params, "signed"));
|
|
2497
|
+
}
|
|
2498
|
+
async getAllOrders(symbol3, options) {
|
|
2499
|
+
return CoinMOrdersResponseSchema.parse(
|
|
2500
|
+
await this.http.get("/dapi/v1/allOrders", { symbol: symbol3, ...options }, "signed")
|
|
2501
|
+
);
|
|
2502
|
+
}
|
|
2503
|
+
async modifyPositionMargin(symbol3, amount, type) {
|
|
2504
|
+
return CoinMPositionMarginChangeSchema.parse(
|
|
2505
|
+
await this.http.post("/dapi/v1/positionMargin", { symbol: symbol3, amount, type }, "signed")
|
|
2506
|
+
);
|
|
2507
|
+
}
|
|
2508
|
+
};
|
|
2509
|
+
|
|
2510
|
+
// src/resources/CoinMUserDataStream.ts
|
|
2511
|
+
var CoinMUserDataStream = class {
|
|
2512
|
+
constructor(http2) {
|
|
2513
|
+
this.http = http2;
|
|
2514
|
+
}
|
|
2515
|
+
async createListenKey() {
|
|
2516
|
+
return ListenKeySchema.parse(await this.http.post("/dapi/v1/listenKey", void 0, "apiKey"));
|
|
2517
|
+
}
|
|
2518
|
+
async keepAliveListenKey() {
|
|
2519
|
+
return this.http.put("/dapi/v1/listenKey", void 0, "apiKey");
|
|
2520
|
+
}
|
|
2521
|
+
async closeListenKey() {
|
|
2522
|
+
return this.http.delete("/dapi/v1/listenKey", void 0, "apiKey");
|
|
2523
|
+
}
|
|
2524
|
+
};
|
|
2525
|
+
|
|
2526
|
+
// src/types/margin.types.ts
|
|
2527
|
+
var import_zod8 = require("zod");
|
|
2528
|
+
var MarginAssetBalanceSchema = import_zod8.z.object({
|
|
2529
|
+
asset: import_zod8.z.string(),
|
|
2530
|
+
borrowed: import_zod8.z.string().transform(Number),
|
|
2531
|
+
free: import_zod8.z.string().transform(Number),
|
|
2532
|
+
interest: import_zod8.z.string().transform(Number),
|
|
2533
|
+
locked: import_zod8.z.string().transform(Number),
|
|
2534
|
+
netAsset: import_zod8.z.string().transform(Number)
|
|
2535
|
+
});
|
|
2536
|
+
var CrossMarginAccountSchema = import_zod8.z.object({
|
|
2537
|
+
borrowEnabled: import_zod8.z.boolean(),
|
|
2538
|
+
marginLevel: import_zod8.z.string().transform(Number),
|
|
2539
|
+
totalAssetOfBtc: import_zod8.z.string().transform(Number),
|
|
2540
|
+
totalLiabilityOfBtc: import_zod8.z.string().transform(Number),
|
|
2541
|
+
totalNetAssetOfBtc: import_zod8.z.string().transform(Number),
|
|
2542
|
+
tradeEnabled: import_zod8.z.boolean(),
|
|
2543
|
+
transferEnabled: import_zod8.z.boolean(),
|
|
2544
|
+
accountType: import_zod8.z.string().optional(),
|
|
2545
|
+
userAssets: import_zod8.z.array(MarginAssetBalanceSchema)
|
|
2546
|
+
}).loose();
|
|
2547
|
+
var IsolatedMarginAssetSchema = import_zod8.z.object({
|
|
2548
|
+
asset: import_zod8.z.string(),
|
|
2549
|
+
borrowEnabled: import_zod8.z.boolean(),
|
|
2550
|
+
borrowed: import_zod8.z.string().transform(Number),
|
|
2551
|
+
free: import_zod8.z.string().transform(Number),
|
|
2552
|
+
interest: import_zod8.z.string().transform(Number),
|
|
2553
|
+
locked: import_zod8.z.string().transform(Number),
|
|
2554
|
+
netAsset: import_zod8.z.string().transform(Number),
|
|
2555
|
+
netAssetOfBtc: import_zod8.z.string().transform(Number),
|
|
2556
|
+
repayEnabled: import_zod8.z.boolean(),
|
|
2557
|
+
totalAsset: import_zod8.z.string().transform(Number)
|
|
2558
|
+
}).loose();
|
|
2559
|
+
var IsolatedMarginSymbolSchema = import_zod8.z.object({
|
|
2560
|
+
baseAsset: IsolatedMarginAssetSchema,
|
|
2561
|
+
quoteAsset: IsolatedMarginAssetSchema,
|
|
2562
|
+
symbol: import_zod8.z.string(),
|
|
2563
|
+
isolatedCreated: import_zod8.z.boolean().optional(),
|
|
2564
|
+
enabled: import_zod8.z.boolean(),
|
|
2565
|
+
marginLevel: import_zod8.z.string().transform(Number),
|
|
2566
|
+
marginLevelStatus: import_zod8.z.string().optional(),
|
|
2567
|
+
marginRatio: import_zod8.z.string().transform(Number).optional(),
|
|
2568
|
+
indexPrice: import_zod8.z.string().transform(Number).optional(),
|
|
2569
|
+
liquidatePrice: import_zod8.z.string().transform(Number).optional(),
|
|
2570
|
+
liquidateRate: import_zod8.z.string().transform(Number).optional(),
|
|
2571
|
+
tradeEnabled: import_zod8.z.boolean()
|
|
2572
|
+
}).loose();
|
|
2573
|
+
var IsolatedMarginAccountSchema = import_zod8.z.object({
|
|
2574
|
+
assets: import_zod8.z.array(IsolatedMarginSymbolSchema),
|
|
2575
|
+
totalAssetOfBtc: import_zod8.z.string().transform(Number).optional(),
|
|
2576
|
+
totalLiabilityOfBtc: import_zod8.z.string().transform(Number).optional(),
|
|
2577
|
+
totalNetAssetOfBtc: import_zod8.z.string().transform(Number).optional()
|
|
2578
|
+
});
|
|
2579
|
+
var MaxBorrowableSchema = import_zod8.z.object({
|
|
2580
|
+
amount: import_zod8.z.string().transform(Number),
|
|
2581
|
+
borrowLimit: import_zod8.z.string().transform(Number)
|
|
2582
|
+
});
|
|
2583
|
+
var MaxTransferableSchema = import_zod8.z.object({
|
|
2584
|
+
amount: import_zod8.z.string().transform(Number),
|
|
2585
|
+
fullAmount: import_zod8.z.string().transform(Number).optional()
|
|
2586
|
+
});
|
|
2587
|
+
var BorrowRepayParamsSchema = import_zod8.z.object({
|
|
2588
|
+
asset: import_zod8.z.string(),
|
|
2589
|
+
isIsolated: import_zod8.z.enum(["TRUE", "FALSE"]).optional(),
|
|
2590
|
+
symbol: import_zod8.z.string().optional(),
|
|
2591
|
+
amount: import_zod8.z.union([import_zod8.z.string(), import_zod8.z.number()]),
|
|
2592
|
+
type: import_zod8.z.enum(["BORROW", "REPAY"])
|
|
2593
|
+
});
|
|
2594
|
+
var BorrowRepayResultSchema = import_zod8.z.object({ tranId: import_zod8.z.number() });
|
|
2595
|
+
var BorrowRepayRecordEntrySchema = import_zod8.z.object({
|
|
2596
|
+
isolatedSymbol: import_zod8.z.string().optional(),
|
|
2597
|
+
txId: import_zod8.z.number(),
|
|
2598
|
+
asset: import_zod8.z.string(),
|
|
2599
|
+
principal: import_zod8.z.string().transform(Number),
|
|
2600
|
+
timestamp: import_zod8.z.number(),
|
|
2601
|
+
status: import_zod8.z.string()
|
|
2602
|
+
}).loose();
|
|
2603
|
+
var BorrowRepayRecordResponseSchema = import_zod8.z.object({
|
|
2604
|
+
rows: import_zod8.z.array(BorrowRepayRecordEntrySchema),
|
|
2605
|
+
total: import_zod8.z.number()
|
|
2606
|
+
});
|
|
2607
|
+
var MarginTransferResultSchema = import_zod8.z.object({ tranId: import_zod8.z.number() });
|
|
2608
|
+
var IsolatedTransferParamsSchema = import_zod8.z.object({
|
|
2609
|
+
asset: import_zod8.z.string(),
|
|
2610
|
+
symbol: import_zod8.z.string(),
|
|
2611
|
+
transFrom: import_zod8.z.enum(["SPOT", "ISOLATED_MARGIN"]),
|
|
2612
|
+
transTo: import_zod8.z.enum(["SPOT", "ISOLATED_MARGIN"]),
|
|
2613
|
+
amount: import_zod8.z.union([import_zod8.z.string(), import_zod8.z.number()])
|
|
2614
|
+
});
|
|
2615
|
+
var MarginInterestHistoryEntrySchema = import_zod8.z.object({
|
|
2616
|
+
txId: import_zod8.z.number(),
|
|
2617
|
+
interestAccuredTime: import_zod8.z.number(),
|
|
2618
|
+
asset: import_zod8.z.string(),
|
|
2619
|
+
rawAsset: import_zod8.z.string().optional(),
|
|
2620
|
+
principal: import_zod8.z.string().transform(Number),
|
|
2621
|
+
interest: import_zod8.z.string().transform(Number),
|
|
2622
|
+
interestRate: import_zod8.z.string().transform(Number),
|
|
2623
|
+
type: import_zod8.z.string(),
|
|
2624
|
+
isolatedSymbol: import_zod8.z.string().optional()
|
|
2625
|
+
}).loose();
|
|
2626
|
+
var MarginInterestHistoryResponseSchema = import_zod8.z.object({
|
|
2627
|
+
rows: import_zod8.z.array(MarginInterestHistoryEntrySchema),
|
|
2628
|
+
total: import_zod8.z.number()
|
|
2629
|
+
});
|
|
2630
|
+
var MarginForceLiquidationEntrySchema = import_zod8.z.object({
|
|
2631
|
+
avgPrice: import_zod8.z.string().transform(Number),
|
|
2632
|
+
executedQty: import_zod8.z.string().transform(Number),
|
|
2633
|
+
orderId: import_zod8.z.number(),
|
|
2634
|
+
price: import_zod8.z.string().transform(Number),
|
|
2635
|
+
qty: import_zod8.z.string().transform(Number),
|
|
2636
|
+
side: import_zod8.z.string(),
|
|
2637
|
+
symbol: import_zod8.z.string(),
|
|
2638
|
+
timeInForce: import_zod8.z.string(),
|
|
2639
|
+
isIsolated: import_zod8.z.boolean().optional(),
|
|
2640
|
+
updatedTime: import_zod8.z.number()
|
|
2641
|
+
}).loose();
|
|
2642
|
+
var MarginForceLiquidationResponseSchema = import_zod8.z.object({
|
|
2643
|
+
rows: import_zod8.z.array(MarginForceLiquidationEntrySchema),
|
|
2644
|
+
total: import_zod8.z.number()
|
|
2645
|
+
});
|
|
2646
|
+
var MarginPriceIndexSchema = import_zod8.z.object({
|
|
2647
|
+
calcTime: import_zod8.z.number(),
|
|
2648
|
+
price: import_zod8.z.string().transform(Number),
|
|
2649
|
+
symbol: import_zod8.z.string()
|
|
2650
|
+
});
|
|
2651
|
+
var MarginOrderSchema = import_zod8.z.object({
|
|
2652
|
+
symbol: import_zod8.z.string(),
|
|
2653
|
+
orderId: import_zod8.z.number(),
|
|
2654
|
+
clientOrderId: import_zod8.z.string(),
|
|
2655
|
+
isIsolated: import_zod8.z.boolean().optional(),
|
|
2656
|
+
price: import_zod8.z.string().transform(Number),
|
|
2657
|
+
origQty: import_zod8.z.string().transform(Number),
|
|
2658
|
+
executedQty: import_zod8.z.string().transform(Number),
|
|
2659
|
+
cummulativeQuoteQty: import_zod8.z.string().transform(Number),
|
|
2660
|
+
status: import_zod8.z.string(),
|
|
2661
|
+
timeInForce: import_zod8.z.string().optional(),
|
|
2662
|
+
type: import_zod8.z.string(),
|
|
2663
|
+
side: import_zod8.z.string(),
|
|
2664
|
+
transactTime: import_zod8.z.number().optional(),
|
|
2665
|
+
time: import_zod8.z.number().optional(),
|
|
2666
|
+
updateTime: import_zod8.z.number().optional(),
|
|
2667
|
+
fills: import_zod8.z.array(import_zod8.z.unknown()).optional()
|
|
2668
|
+
}).loose();
|
|
2669
|
+
var MarginOrderResponseSchema = MarginOrderSchema;
|
|
2670
|
+
var MarginOrdersResponseSchema = import_zod8.z.array(MarginOrderSchema);
|
|
2671
|
+
var MarginCreateOrderParamsSchema = import_zod8.z.object({
|
|
2672
|
+
symbol: import_zod8.z.string(),
|
|
2673
|
+
isIsolated: import_zod8.z.enum(["TRUE", "FALSE"]).optional(),
|
|
2674
|
+
side: import_zod8.z.enum(["BUY", "SELL"]),
|
|
2675
|
+
type: import_zod8.z.string(),
|
|
2676
|
+
quantity: import_zod8.z.union([import_zod8.z.string(), import_zod8.z.number()]).optional(),
|
|
2677
|
+
quoteOrderQty: import_zod8.z.union([import_zod8.z.string(), import_zod8.z.number()]).optional(),
|
|
2678
|
+
price: import_zod8.z.union([import_zod8.z.string(), import_zod8.z.number()]).optional(),
|
|
2679
|
+
stopPrice: import_zod8.z.union([import_zod8.z.string(), import_zod8.z.number()]).optional(),
|
|
2680
|
+
newClientOrderId: import_zod8.z.string().optional(),
|
|
2681
|
+
icebergQty: import_zod8.z.union([import_zod8.z.string(), import_zod8.z.number()]).optional(),
|
|
2682
|
+
timeInForce: import_zod8.z.enum(["GTC", "IOC", "FOK"]).optional(),
|
|
2683
|
+
sideEffectType: import_zod8.z.enum(["NO_SIDE_EFFECT", "MARGIN_BUY", "AUTO_REPAY", "AUTO_BORROW_REPAY"]).optional(),
|
|
2684
|
+
newOrderRespType: import_zod8.z.enum(["ACK", "RESULT", "FULL"]).optional(),
|
|
2685
|
+
autoRepayAtCancel: import_zod8.z.boolean().optional()
|
|
2686
|
+
});
|
|
2687
|
+
var MarginTradeSchema = import_zod8.z.object({
|
|
2688
|
+
symbol: import_zod8.z.string(),
|
|
2689
|
+
id: import_zod8.z.number(),
|
|
2690
|
+
orderId: import_zod8.z.number(),
|
|
2691
|
+
price: import_zod8.z.string().transform(Number),
|
|
2692
|
+
qty: import_zod8.z.string().transform(Number),
|
|
2693
|
+
quoteQty: import_zod8.z.string().transform(Number),
|
|
2694
|
+
commission: import_zod8.z.string().transform(Number),
|
|
2695
|
+
commissionAsset: import_zod8.z.string(),
|
|
2696
|
+
time: import_zod8.z.number(),
|
|
2697
|
+
isBuyer: import_zod8.z.boolean(),
|
|
2698
|
+
isMaker: import_zod8.z.boolean(),
|
|
2699
|
+
isBestMatch: import_zod8.z.boolean().optional(),
|
|
2700
|
+
isIsolated: import_zod8.z.boolean().optional()
|
|
2701
|
+
}).loose();
|
|
2702
|
+
var MarginTradesResponseSchema = import_zod8.z.array(MarginTradeSchema);
|
|
2703
|
+
|
|
2704
|
+
// src/resources/Margin.ts
|
|
2705
|
+
var MarginAccount = class {
|
|
2706
|
+
constructor(http2) {
|
|
2707
|
+
this.http = http2;
|
|
2708
|
+
}
|
|
2709
|
+
async crossAccount() {
|
|
2710
|
+
return CrossMarginAccountSchema.parse(await this.http.get("/sapi/v1/margin/account", void 0, "signed"));
|
|
2711
|
+
}
|
|
2712
|
+
async isolatedAccount(symbols) {
|
|
2713
|
+
const params = symbols?.length ? { symbols: symbols.join(",") } : void 0;
|
|
2714
|
+
return IsolatedMarginAccountSchema.parse(
|
|
2715
|
+
await this.http.get("/sapi/v1/margin/isolated/account", params, "signed")
|
|
2716
|
+
);
|
|
2717
|
+
}
|
|
2718
|
+
async maxBorrowable(asset, isolatedSymbol) {
|
|
2719
|
+
return MaxBorrowableSchema.parse(
|
|
2720
|
+
await this.http.get("/sapi/v1/margin/maxBorrowable", { asset, isolatedSymbol }, "signed")
|
|
2721
|
+
);
|
|
2722
|
+
}
|
|
2723
|
+
async maxTransferable(asset, isolatedSymbol) {
|
|
2724
|
+
return MaxTransferableSchema.parse(
|
|
2725
|
+
await this.http.get("/sapi/v1/margin/maxTransferable", { asset, isolatedSymbol }, "signed")
|
|
2726
|
+
);
|
|
2727
|
+
}
|
|
2728
|
+
async borrowRepay(params) {
|
|
2729
|
+
return BorrowRepayResultSchema.parse(
|
|
2730
|
+
await this.http.post("/sapi/v1/margin/borrow-repay", params, "signed")
|
|
2731
|
+
);
|
|
2732
|
+
}
|
|
2733
|
+
async borrow(asset, amount, options) {
|
|
2734
|
+
return this.borrowRepay({
|
|
2735
|
+
asset,
|
|
2736
|
+
amount,
|
|
2737
|
+
type: "BORROW",
|
|
2738
|
+
isIsolated: options?.isIsolated ? "TRUE" : void 0,
|
|
2739
|
+
symbol: options?.symbol
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
async repay(asset, amount, options) {
|
|
2743
|
+
return this.borrowRepay({
|
|
2744
|
+
asset,
|
|
2745
|
+
amount,
|
|
2746
|
+
type: "REPAY",
|
|
2747
|
+
isIsolated: options?.isIsolated ? "TRUE" : void 0,
|
|
2748
|
+
symbol: options?.symbol
|
|
2749
|
+
});
|
|
2750
|
+
}
|
|
2751
|
+
async borrowRepayRecord(type, options) {
|
|
2752
|
+
return BorrowRepayRecordResponseSchema.parse(
|
|
2753
|
+
await this.http.get("/sapi/v1/margin/borrow-repay", { type, ...options }, "signed")
|
|
2754
|
+
);
|
|
2755
|
+
}
|
|
2756
|
+
async transfer(asset, amount, type) {
|
|
2757
|
+
return MarginTransferResultSchema.parse(
|
|
2758
|
+
await this.http.post("/sapi/v1/margin/transfer", { asset, amount, type }, "signed")
|
|
2759
|
+
);
|
|
2760
|
+
}
|
|
2761
|
+
async isolatedTransfer(params) {
|
|
2762
|
+
return MarginTransferResultSchema.parse(
|
|
2763
|
+
await this.http.post("/sapi/v1/margin/isolated/transfer", params, "signed")
|
|
2764
|
+
);
|
|
2765
|
+
}
|
|
2766
|
+
async interestHistory(options) {
|
|
2767
|
+
return MarginInterestHistoryResponseSchema.parse(
|
|
2768
|
+
await this.http.get("/sapi/v1/margin/interestHistory", options, "signed")
|
|
2769
|
+
);
|
|
2770
|
+
}
|
|
2771
|
+
async forceLiquidationRecord(options) {
|
|
2772
|
+
return MarginForceLiquidationResponseSchema.parse(
|
|
2773
|
+
await this.http.get("/sapi/v1/margin/forceLiquidationRec", options, "signed")
|
|
2774
|
+
);
|
|
2775
|
+
}
|
|
2776
|
+
async priceIndex(symbol3) {
|
|
2777
|
+
return MarginPriceIndexSchema.parse(await this.http.get("/sapi/v1/margin/priceIndex", { symbol: symbol3 }));
|
|
2778
|
+
}
|
|
2779
|
+
};
|
|
2780
|
+
var MarginTrading = class {
|
|
2781
|
+
constructor(http2) {
|
|
2782
|
+
this.http = http2;
|
|
2783
|
+
}
|
|
2784
|
+
async createOrder(params) {
|
|
2785
|
+
return MarginOrderResponseSchema.parse(await this.http.post("/sapi/v1/margin/order", params, "signed"));
|
|
2786
|
+
}
|
|
2787
|
+
async cancelOrder(symbol3, options) {
|
|
2788
|
+
return MarginOrderResponseSchema.parse(
|
|
2789
|
+
await this.http.delete("/sapi/v1/margin/order", { symbol: symbol3, ...options }, "signed")
|
|
2790
|
+
);
|
|
2791
|
+
}
|
|
2792
|
+
async cancelAllOpenOrders(symbol3, isIsolated) {
|
|
2793
|
+
return MarginOrdersResponseSchema.parse(
|
|
2794
|
+
await this.http.delete("/sapi/v1/margin/openOrders", { symbol: symbol3, isIsolated }, "signed")
|
|
2795
|
+
);
|
|
2796
|
+
}
|
|
2797
|
+
async getOrder(symbol3, options) {
|
|
2798
|
+
return MarginOrderResponseSchema.parse(
|
|
2799
|
+
await this.http.get("/sapi/v1/margin/order", { symbol: symbol3, ...options }, "signed")
|
|
2800
|
+
);
|
|
2801
|
+
}
|
|
2802
|
+
async getOpenOrders(options) {
|
|
2803
|
+
return MarginOrdersResponseSchema.parse(await this.http.get("/sapi/v1/margin/openOrders", options, "signed"));
|
|
2804
|
+
}
|
|
2805
|
+
async getAllOrders(symbol3, options) {
|
|
2806
|
+
return MarginOrdersResponseSchema.parse(
|
|
2807
|
+
await this.http.get("/sapi/v1/margin/allOrders", { symbol: symbol3, ...options }, "signed")
|
|
2808
|
+
);
|
|
2809
|
+
}
|
|
2810
|
+
async myTrades(symbol3, options) {
|
|
2811
|
+
return MarginTradesResponseSchema.parse(
|
|
2812
|
+
await this.http.get("/sapi/v1/margin/myTrades", { symbol: symbol3, ...options }, "signed")
|
|
2813
|
+
);
|
|
2814
|
+
}
|
|
2815
|
+
};
|
|
2816
|
+
|
|
2817
|
+
// src/types/wallet.types.ts
|
|
2818
|
+
var import_zod9 = require("zod");
|
|
2819
|
+
var TransferTypeSchema = import_zod9.z.enum([
|
|
2820
|
+
"MAIN_UMFUTURE",
|
|
2821
|
+
"MAIN_CMFUTURE",
|
|
2822
|
+
"MAIN_MARGIN",
|
|
2823
|
+
"MAIN_MINING",
|
|
2824
|
+
"MAIN_FUNDING",
|
|
2825
|
+
"MAIN_OPTION",
|
|
2826
|
+
"UMFUTURE_MAIN",
|
|
2827
|
+
"UMFUTURE_MARGIN",
|
|
2828
|
+
"UMFUTURE_FUNDING",
|
|
2829
|
+
"CMFUTURE_MAIN",
|
|
2830
|
+
"CMFUTURE_MARGIN",
|
|
2831
|
+
"MARGIN_MAIN",
|
|
2832
|
+
"MARGIN_UMFUTURE",
|
|
2833
|
+
"MARGIN_CMFUTURE",
|
|
2834
|
+
"MARGIN_MINING",
|
|
2835
|
+
"MARGIN_FUNDING",
|
|
2836
|
+
"MINING_MAIN",
|
|
2837
|
+
"MINING_UMFUTURE",
|
|
2838
|
+
"MINING_MARGIN",
|
|
2839
|
+
"FUNDING_MAIN",
|
|
2840
|
+
"FUNDING_UMFUTURE",
|
|
2841
|
+
"FUNDING_MARGIN",
|
|
2842
|
+
"FUNDING_CMFUTURE",
|
|
2843
|
+
"OPTION_MAIN",
|
|
2844
|
+
"MAIN_OPTION_MARGIN",
|
|
2845
|
+
"MAIN_PORTFOLIO_MARGIN",
|
|
2846
|
+
"PORTFOLIO_MARGIN_MAIN",
|
|
2847
|
+
"ISOLATEDMARGIN_MARGIN",
|
|
2848
|
+
"MARGIN_ISOLATEDMARGIN",
|
|
2849
|
+
"ISOLATEDMARGIN_ISOLATEDMARGIN"
|
|
2850
|
+
]);
|
|
2851
|
+
var UniversalTransferParamsSchema = import_zod9.z.object({
|
|
2852
|
+
type: TransferTypeSchema,
|
|
2853
|
+
asset: import_zod9.z.string(),
|
|
2854
|
+
amount: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.number()]),
|
|
2855
|
+
fromSymbol: import_zod9.z.string().optional(),
|
|
2856
|
+
toSymbol: import_zod9.z.string().optional()
|
|
2857
|
+
});
|
|
2858
|
+
var UniversalTransferResultSchema = import_zod9.z.object({ tranId: import_zod9.z.number() });
|
|
2859
|
+
var UniversalTransferHistoryEntrySchema = import_zod9.z.object({
|
|
2860
|
+
asset: import_zod9.z.string(),
|
|
2861
|
+
amount: import_zod9.z.string().transform(Number),
|
|
2862
|
+
type: import_zod9.z.string(),
|
|
2863
|
+
status: import_zod9.z.string(),
|
|
2864
|
+
tranId: import_zod9.z.number(),
|
|
2865
|
+
timestamp: import_zod9.z.number(),
|
|
2866
|
+
fromSymbol: import_zod9.z.string().nullable().optional(),
|
|
2867
|
+
toSymbol: import_zod9.z.string().nullable().optional()
|
|
2868
|
+
}).loose();
|
|
2869
|
+
var UniversalTransferHistoryResponseSchema = import_zod9.z.object({
|
|
2870
|
+
total: import_zod9.z.number(),
|
|
2871
|
+
rows: import_zod9.z.array(UniversalTransferHistoryEntrySchema)
|
|
2872
|
+
});
|
|
2873
|
+
var FundingAssetSchema = import_zod9.z.object({
|
|
2874
|
+
asset: import_zod9.z.string(),
|
|
2875
|
+
free: import_zod9.z.string().transform(Number),
|
|
2876
|
+
locked: import_zod9.z.string().transform(Number),
|
|
2877
|
+
freeze: import_zod9.z.string().transform(Number),
|
|
2878
|
+
withdrawing: import_zod9.z.string().transform(Number),
|
|
2879
|
+
btcValuation: import_zod9.z.string().transform(Number)
|
|
2880
|
+
});
|
|
2881
|
+
var FundingAssetsResponseSchema = import_zod9.z.array(FundingAssetSchema);
|
|
2882
|
+
var UserAssetSchema = import_zod9.z.object({
|
|
2883
|
+
asset: import_zod9.z.string(),
|
|
2884
|
+
free: import_zod9.z.string().transform(Number),
|
|
2885
|
+
locked: import_zod9.z.string().transform(Number),
|
|
2886
|
+
freeze: import_zod9.z.string().transform(Number),
|
|
2887
|
+
withdrawing: import_zod9.z.string().transform(Number),
|
|
2888
|
+
ipoable: import_zod9.z.string().transform(Number),
|
|
2889
|
+
btcValuation: import_zod9.z.string().transform(Number)
|
|
2890
|
+
});
|
|
2891
|
+
var UserAssetsResponseSchema = import_zod9.z.array(UserAssetSchema);
|
|
2892
|
+
var DepositHistoryEntrySchema = import_zod9.z.object({
|
|
2893
|
+
id: import_zod9.z.string(),
|
|
2894
|
+
amount: import_zod9.z.string().transform(Number),
|
|
2895
|
+
coin: import_zod9.z.string(),
|
|
2896
|
+
network: import_zod9.z.string(),
|
|
2897
|
+
status: import_zod9.z.number(),
|
|
2898
|
+
address: import_zod9.z.string(),
|
|
2899
|
+
addressTag: import_zod9.z.string().optional(),
|
|
2900
|
+
txId: import_zod9.z.string(),
|
|
2901
|
+
insertTime: import_zod9.z.number(),
|
|
2902
|
+
transferType: import_zod9.z.number(),
|
|
2903
|
+
confirmTimes: import_zod9.z.string().optional(),
|
|
2904
|
+
unlockConfirm: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.number()]).optional(),
|
|
2905
|
+
walletType: import_zod9.z.number().optional()
|
|
2906
|
+
}).loose();
|
|
2907
|
+
var DepositHistoryResponseSchema = import_zod9.z.array(DepositHistoryEntrySchema);
|
|
2908
|
+
var WithdrawHistoryEntrySchema = import_zod9.z.object({
|
|
2909
|
+
id: import_zod9.z.string(),
|
|
2910
|
+
amount: import_zod9.z.string().transform(Number),
|
|
2911
|
+
transactionFee: import_zod9.z.string().transform(Number),
|
|
2912
|
+
coin: import_zod9.z.string(),
|
|
2913
|
+
status: import_zod9.z.number(),
|
|
2914
|
+
address: import_zod9.z.string(),
|
|
2915
|
+
txId: import_zod9.z.string().optional(),
|
|
2916
|
+
applyTime: import_zod9.z.string(),
|
|
2917
|
+
network: import_zod9.z.string(),
|
|
2918
|
+
transferType: import_zod9.z.number(),
|
|
2919
|
+
withdrawOrderId: import_zod9.z.string().nullable().optional(),
|
|
2920
|
+
info: import_zod9.z.string().optional(),
|
|
2921
|
+
confirmNo: import_zod9.z.number().optional(),
|
|
2922
|
+
walletType: import_zod9.z.number().optional()
|
|
2923
|
+
}).loose();
|
|
2924
|
+
var WithdrawHistoryResponseSchema = import_zod9.z.array(WithdrawHistoryEntrySchema);
|
|
2925
|
+
var WithdrawParamsSchema = import_zod9.z.object({
|
|
2926
|
+
coin: import_zod9.z.string(),
|
|
2927
|
+
address: import_zod9.z.string(),
|
|
2928
|
+
amount: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.number()]),
|
|
2929
|
+
withdrawOrderId: import_zod9.z.string().optional(),
|
|
2930
|
+
network: import_zod9.z.string().optional(),
|
|
2931
|
+
addressTag: import_zod9.z.string().optional(),
|
|
2932
|
+
transactionFeeFlag: import_zod9.z.boolean().optional(),
|
|
2933
|
+
name: import_zod9.z.string().optional(),
|
|
2934
|
+
walletType: import_zod9.z.number().optional()
|
|
2935
|
+
});
|
|
2936
|
+
var WithdrawResultSchema = import_zod9.z.object({ id: import_zod9.z.string() });
|
|
2937
|
+
var DepositAddressSchema = import_zod9.z.object({
|
|
2938
|
+
address: import_zod9.z.string(),
|
|
2939
|
+
coin: import_zod9.z.string(),
|
|
2940
|
+
tag: import_zod9.z.string(),
|
|
2941
|
+
url: import_zod9.z.string().optional()
|
|
2942
|
+
});
|
|
2943
|
+
var ApiKeyPermissionsSchema = import_zod9.z.object({
|
|
2944
|
+
ipRestrict: import_zod9.z.boolean(),
|
|
2945
|
+
createTime: import_zod9.z.number(),
|
|
2946
|
+
enableWithdrawals: import_zod9.z.boolean(),
|
|
2947
|
+
enableInternalTransfer: import_zod9.z.boolean(),
|
|
2948
|
+
enableFutures: import_zod9.z.boolean(),
|
|
2949
|
+
enableMargin: import_zod9.z.boolean(),
|
|
2950
|
+
enableSpotAndMarginTrading: import_zod9.z.boolean(),
|
|
2951
|
+
permitsUniversalTransfer: import_zod9.z.boolean().optional(),
|
|
2952
|
+
enableReading: import_zod9.z.boolean().optional(),
|
|
2953
|
+
tradingAuthorityExpirationTime: import_zod9.z.number().optional()
|
|
2954
|
+
}).loose();
|
|
2955
|
+
var AssetDetailSchema = import_zod9.z.record(
|
|
2956
|
+
import_zod9.z.string(),
|
|
2957
|
+
import_zod9.z.object({
|
|
2958
|
+
minWithdrawAmount: import_zod9.z.string().transform(Number),
|
|
2959
|
+
depositStatus: import_zod9.z.boolean(),
|
|
2960
|
+
withdrawFee: import_zod9.z.number(),
|
|
2961
|
+
withdrawStatus: import_zod9.z.boolean(),
|
|
2962
|
+
depositTip: import_zod9.z.string().optional()
|
|
2963
|
+
}).loose()
|
|
2964
|
+
);
|
|
2965
|
+
var DustLogEntrySchema = import_zod9.z.object({
|
|
2966
|
+
transId: import_zod9.z.number(),
|
|
2967
|
+
serviceChargeAmount: import_zod9.z.string().transform(Number),
|
|
2968
|
+
amount: import_zod9.z.string().transform(Number),
|
|
2969
|
+
operateTime: import_zod9.z.string(),
|
|
2970
|
+
transferedAmount: import_zod9.z.string().transform(Number),
|
|
2971
|
+
fromAsset: import_zod9.z.string()
|
|
2972
|
+
}).loose();
|
|
2973
|
+
var DustLogResponseSchema = import_zod9.z.object({
|
|
2974
|
+
total: import_zod9.z.number(),
|
|
2975
|
+
userAssetDribblets: import_zod9.z.array(
|
|
2976
|
+
import_zod9.z.object({
|
|
2977
|
+
operateTime: import_zod9.z.number(),
|
|
2978
|
+
totalTransferedAmount: import_zod9.z.string().transform(Number),
|
|
2979
|
+
totalServiceChargeAmount: import_zod9.z.string().transform(Number),
|
|
2980
|
+
transId: import_zod9.z.number(),
|
|
2981
|
+
userAssetDribbletDetails: import_zod9.z.array(DustLogEntrySchema)
|
|
2982
|
+
})
|
|
2983
|
+
)
|
|
2984
|
+
});
|
|
2985
|
+
var DustConversionResultSchema = import_zod9.z.object({
|
|
2986
|
+
totalServiceCharge: import_zod9.z.string().transform(Number),
|
|
2987
|
+
totalTransfered: import_zod9.z.string().transform(Number),
|
|
2988
|
+
transferResult: import_zod9.z.array(
|
|
2989
|
+
import_zod9.z.object({
|
|
2990
|
+
amount: import_zod9.z.string().transform(Number),
|
|
2991
|
+
fromAsset: import_zod9.z.string(),
|
|
2992
|
+
operateTime: import_zod9.z.number(),
|
|
2993
|
+
serviceChargeAmount: import_zod9.z.string().transform(Number),
|
|
2994
|
+
tranId: import_zod9.z.number(),
|
|
2995
|
+
transferedAmount: import_zod9.z.string().transform(Number)
|
|
2996
|
+
}).loose()
|
|
2997
|
+
)
|
|
2998
|
+
}).loose();
|
|
2999
|
+
var TradeFeeEntrySchema = import_zod9.z.object({
|
|
3000
|
+
symbol: import_zod9.z.string(),
|
|
3001
|
+
makerCommission: import_zod9.z.string().transform(Number),
|
|
3002
|
+
takerCommission: import_zod9.z.string().transform(Number)
|
|
3003
|
+
});
|
|
3004
|
+
var TradeFeeResponseSchema = import_zod9.z.array(TradeFeeEntrySchema);
|
|
3005
|
+
var AccountSnapshotSchema = import_zod9.z.object({
|
|
3006
|
+
code: import_zod9.z.number(),
|
|
3007
|
+
msg: import_zod9.z.string(),
|
|
3008
|
+
snapshotVos: import_zod9.z.array(
|
|
3009
|
+
import_zod9.z.object({
|
|
3010
|
+
type: import_zod9.z.string(),
|
|
3011
|
+
updateTime: import_zod9.z.number(),
|
|
3012
|
+
data: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.unknown())
|
|
3013
|
+
}).loose()
|
|
3014
|
+
)
|
|
3015
|
+
}).loose();
|
|
3016
|
+
|
|
3017
|
+
// src/resources/Wallet.ts
|
|
3018
|
+
var Wallet = class {
|
|
3019
|
+
constructor(http2) {
|
|
3020
|
+
this.http = http2;
|
|
3021
|
+
}
|
|
3022
|
+
async universalTransfer(params) {
|
|
3023
|
+
return UniversalTransferResultSchema.parse(
|
|
3024
|
+
await this.http.post("/sapi/v1/asset/transfer", params, "signed")
|
|
3025
|
+
);
|
|
3026
|
+
}
|
|
3027
|
+
async universalTransferHistory(options) {
|
|
3028
|
+
return UniversalTransferHistoryResponseSchema.parse(
|
|
3029
|
+
await this.http.get("/sapi/v1/asset/transfer", options, "signed")
|
|
3030
|
+
);
|
|
3031
|
+
}
|
|
3032
|
+
async fundingWallet(options) {
|
|
3033
|
+
return FundingAssetsResponseSchema.parse(
|
|
3034
|
+
await this.http.post("/sapi/v1/asset/get-funding-asset", options, "signed")
|
|
3035
|
+
);
|
|
3036
|
+
}
|
|
3037
|
+
async userAsset(options) {
|
|
3038
|
+
return UserAssetsResponseSchema.parse(
|
|
3039
|
+
await this.http.post("/sapi/v3/asset/getUserAsset", options, "signed")
|
|
3040
|
+
);
|
|
3041
|
+
}
|
|
3042
|
+
async depositHistory(options) {
|
|
3043
|
+
return DepositHistoryResponseSchema.parse(
|
|
3044
|
+
await this.http.get("/sapi/v1/capital/deposit/hisrec", options, "signed")
|
|
3045
|
+
);
|
|
3046
|
+
}
|
|
3047
|
+
async withdrawHistory(options) {
|
|
3048
|
+
return WithdrawHistoryResponseSchema.parse(
|
|
3049
|
+
await this.http.get("/sapi/v1/capital/withdraw/history", options, "signed")
|
|
3050
|
+
);
|
|
3051
|
+
}
|
|
3052
|
+
async withdraw(params) {
|
|
3053
|
+
return WithdrawResultSchema.parse(
|
|
3054
|
+
await this.http.post("/sapi/v1/capital/withdraw/apply", params, "signed")
|
|
3055
|
+
);
|
|
3056
|
+
}
|
|
3057
|
+
async depositAddress(coin, network) {
|
|
3058
|
+
return DepositAddressSchema.parse(
|
|
3059
|
+
await this.http.get("/sapi/v1/capital/deposit/address", { coin, network }, "signed")
|
|
3060
|
+
);
|
|
3061
|
+
}
|
|
3062
|
+
async accountSnapshot(type, options) {
|
|
3063
|
+
return AccountSnapshotSchema.parse(
|
|
3064
|
+
await this.http.get("/sapi/v1/accountSnapshot", { type, ...options }, "signed")
|
|
3065
|
+
);
|
|
3066
|
+
}
|
|
3067
|
+
async apiKeyPermissions() {
|
|
3068
|
+
return ApiKeyPermissionsSchema.parse(
|
|
3069
|
+
await this.http.get("/sapi/v1/account/apiRestrictions", void 0, "signed")
|
|
3070
|
+
);
|
|
3071
|
+
}
|
|
3072
|
+
async assetDetail(asset) {
|
|
3073
|
+
const params = asset ? { asset } : void 0;
|
|
3074
|
+
return AssetDetailSchema.parse(await this.http.get("/sapi/v1/asset/assetDetail", params, "signed"));
|
|
3075
|
+
}
|
|
3076
|
+
async dustLog(options) {
|
|
3077
|
+
return DustLogResponseSchema.parse(
|
|
3078
|
+
await this.http.get("/sapi/v1/asset/dribblet", options, "signed")
|
|
3079
|
+
);
|
|
3080
|
+
}
|
|
3081
|
+
async convertDustToBnb(assets, accountType) {
|
|
3082
|
+
return DustConversionResultSchema.parse(
|
|
3083
|
+
await this.http.post("/sapi/v1/asset/dust", { asset: assets, accountType }, "signed")
|
|
3084
|
+
);
|
|
3085
|
+
}
|
|
3086
|
+
async tradeFee(symbol3) {
|
|
3087
|
+
const params = symbol3 ? { symbol: symbol3 } : void 0;
|
|
3088
|
+
return TradeFeeResponseSchema.parse(await this.http.get("/sapi/v1/asset/tradeFee", params, "signed"));
|
|
3089
|
+
}
|
|
3090
|
+
};
|
|
3091
|
+
|
|
3092
|
+
// src/types/subaccount.types.ts
|
|
3093
|
+
var import_zod10 = require("zod");
|
|
3094
|
+
var SubAccountEntrySchema = import_zod10.z.object({
|
|
3095
|
+
email: import_zod10.z.string(),
|
|
3096
|
+
isFreeze: import_zod10.z.boolean(),
|
|
3097
|
+
createTime: import_zod10.z.number(),
|
|
3098
|
+
isManagedSubAccount: import_zod10.z.boolean().optional(),
|
|
3099
|
+
isAssetManagementSubAccount: import_zod10.z.boolean().optional(),
|
|
3100
|
+
type: import_zod10.z.string().optional()
|
|
3101
|
+
}).loose();
|
|
3102
|
+
var SubAccountListResponseSchema = import_zod10.z.object({
|
|
3103
|
+
subAccounts: import_zod10.z.array(SubAccountEntrySchema)
|
|
3104
|
+
});
|
|
3105
|
+
var SubAccountStatusSchema = import_zod10.z.object({
|
|
3106
|
+
email: import_zod10.z.string(),
|
|
3107
|
+
isSubUserEnabled: import_zod10.z.boolean(),
|
|
3108
|
+
isUserActive: import_zod10.z.boolean(),
|
|
3109
|
+
insertTime: import_zod10.z.number(),
|
|
3110
|
+
isMarginEnabled: import_zod10.z.boolean(),
|
|
3111
|
+
isFutureEnabled: import_zod10.z.boolean(),
|
|
3112
|
+
mobile: import_zod10.z.number().optional()
|
|
3113
|
+
}).loose();
|
|
3114
|
+
var SubAccountStatusResponseSchema = import_zod10.z.array(SubAccountStatusSchema);
|
|
3115
|
+
var SubAccountSpotAssetSchema = import_zod10.z.object({
|
|
3116
|
+
asset: import_zod10.z.string(),
|
|
3117
|
+
free: import_zod10.z.string().transform(Number),
|
|
3118
|
+
locked: import_zod10.z.string().transform(Number)
|
|
3119
|
+
});
|
|
3120
|
+
var SubAccountSpotAssetsResponseSchema = import_zod10.z.object({
|
|
3121
|
+
balances: import_zod10.z.array(SubAccountSpotAssetSchema)
|
|
3122
|
+
});
|
|
3123
|
+
var SubAccountSpotSummaryEntrySchema = import_zod10.z.object({
|
|
3124
|
+
email: import_zod10.z.string(),
|
|
3125
|
+
totalAsset: import_zod10.z.string().transform(Number)
|
|
3126
|
+
}).loose();
|
|
3127
|
+
var SubAccountSpotSummarySchema = import_zod10.z.object({
|
|
3128
|
+
totalCount: import_zod10.z.number(),
|
|
3129
|
+
masterAccountTotalAsset: import_zod10.z.string().transform(Number),
|
|
3130
|
+
spotSubUserAssetBtcVoList: import_zod10.z.array(SubAccountSpotSummaryEntrySchema)
|
|
3131
|
+
});
|
|
3132
|
+
var SubAccountFuturesSummarySchema = import_zod10.z.object({
|
|
3133
|
+
totalCount: import_zod10.z.number().optional(),
|
|
3134
|
+
totalMarginBalanceOfBTC: import_zod10.z.string().transform(Number).optional(),
|
|
3135
|
+
totalUnrealizedProfitOfBTC: import_zod10.z.string().transform(Number).optional(),
|
|
3136
|
+
totalWalletBalanceOfBTC: import_zod10.z.string().transform(Number).optional(),
|
|
3137
|
+
subAccountList: import_zod10.z.array(import_zod10.z.record(import_zod10.z.string(), import_zod10.z.unknown())).optional()
|
|
3138
|
+
}).loose();
|
|
3139
|
+
var SubAccountMarginAccountSchema = import_zod10.z.object({
|
|
3140
|
+
email: import_zod10.z.string(),
|
|
3141
|
+
marginLevel: import_zod10.z.string().transform(Number),
|
|
3142
|
+
totalAssetOfBtc: import_zod10.z.string().transform(Number),
|
|
3143
|
+
totalLiabilityOfBtc: import_zod10.z.string().transform(Number),
|
|
3144
|
+
totalNetAssetOfBtc: import_zod10.z.string().transform(Number),
|
|
3145
|
+
marginTradeCoeffVo: import_zod10.z.record(import_zod10.z.string(), import_zod10.z.unknown()).optional(),
|
|
3146
|
+
marginUserAssetVoList: import_zod10.z.array(import_zod10.z.record(import_zod10.z.string(), import_zod10.z.unknown())).optional()
|
|
3147
|
+
}).loose();
|
|
3148
|
+
var SubAccountUniversalTransferParamsSchema = import_zod10.z.object({
|
|
3149
|
+
fromEmail: import_zod10.z.string().optional(),
|
|
3150
|
+
toEmail: import_zod10.z.string().optional(),
|
|
3151
|
+
fromAccountType: import_zod10.z.enum(["SPOT", "USDT_FUTURE", "COIN_FUTURE", "MARGIN", "ISOLATED_MARGIN"]),
|
|
3152
|
+
toAccountType: import_zod10.z.enum(["SPOT", "USDT_FUTURE", "COIN_FUTURE", "MARGIN", "ISOLATED_MARGIN"]),
|
|
3153
|
+
symbol: import_zod10.z.string().optional(),
|
|
3154
|
+
asset: import_zod10.z.string(),
|
|
3155
|
+
amount: import_zod10.z.union([import_zod10.z.string(), import_zod10.z.number()]),
|
|
3156
|
+
clientTranId: import_zod10.z.string().optional()
|
|
3157
|
+
});
|
|
3158
|
+
var SubAccountUniversalTransferResultSchema = import_zod10.z.object({
|
|
3159
|
+
tranId: import_zod10.z.number(),
|
|
3160
|
+
clientTranId: import_zod10.z.string().optional()
|
|
3161
|
+
});
|
|
3162
|
+
var SubAccountUniversalTransferEntrySchema = import_zod10.z.object({
|
|
3163
|
+
tranId: import_zod10.z.number(),
|
|
3164
|
+
fromEmail: import_zod10.z.string(),
|
|
3165
|
+
toEmail: import_zod10.z.string(),
|
|
3166
|
+
asset: import_zod10.z.string(),
|
|
3167
|
+
amount: import_zod10.z.string().transform(Number),
|
|
3168
|
+
fromAccountType: import_zod10.z.string(),
|
|
3169
|
+
toAccountType: import_zod10.z.string(),
|
|
3170
|
+
status: import_zod10.z.string(),
|
|
3171
|
+
createTimeStamp: import_zod10.z.number(),
|
|
3172
|
+
clientTranId: import_zod10.z.string().optional()
|
|
3173
|
+
}).loose();
|
|
3174
|
+
var SubAccountUniversalTransferHistoryResponseSchema = import_zod10.z.object({
|
|
3175
|
+
result: import_zod10.z.array(SubAccountUniversalTransferEntrySchema),
|
|
3176
|
+
totalCount: import_zod10.z.number()
|
|
3177
|
+
});
|
|
3178
|
+
var VirtualSubAccountResultSchema = import_zod10.z.object({ email: import_zod10.z.string() });
|
|
3179
|
+
var SubAccountDepositAddressSchema = import_zod10.z.object({
|
|
3180
|
+
address: import_zod10.z.string(),
|
|
3181
|
+
coin: import_zod10.z.string(),
|
|
3182
|
+
tag: import_zod10.z.string(),
|
|
3183
|
+
url: import_zod10.z.string().optional()
|
|
3184
|
+
});
|
|
3185
|
+
var SubAccountDepositHistoryEntrySchema = import_zod10.z.object({
|
|
3186
|
+
id: import_zod10.z.string(),
|
|
3187
|
+
amount: import_zod10.z.string().transform(Number),
|
|
3188
|
+
coin: import_zod10.z.string(),
|
|
3189
|
+
network: import_zod10.z.string(),
|
|
3190
|
+
status: import_zod10.z.number(),
|
|
3191
|
+
address: import_zod10.z.string(),
|
|
3192
|
+
txId: import_zod10.z.string(),
|
|
3193
|
+
insertTime: import_zod10.z.number(),
|
|
3194
|
+
transferType: import_zod10.z.number()
|
|
3195
|
+
}).loose();
|
|
3196
|
+
var SubAccountDepositHistoryResponseSchema = import_zod10.z.array(SubAccountDepositHistoryEntrySchema);
|
|
3197
|
+
var SubAccountEnableResultSchema = import_zod10.z.object({
|
|
3198
|
+
email: import_zod10.z.string(),
|
|
3199
|
+
isFuturesEnabled: import_zod10.z.boolean().optional(),
|
|
3200
|
+
isMarginEnabled: import_zod10.z.boolean().optional()
|
|
3201
|
+
}).loose();
|
|
3202
|
+
|
|
3203
|
+
// src/resources/SubAccount.ts
|
|
3204
|
+
var SubAccount = class {
|
|
3205
|
+
constructor(http2) {
|
|
3206
|
+
this.http = http2;
|
|
3207
|
+
}
|
|
3208
|
+
async list(options) {
|
|
3209
|
+
const res = await this.http.get("/sapi/v1/sub-account/list", options, "signed");
|
|
3210
|
+
return SubAccountListResponseSchema.parse(res).subAccounts;
|
|
3211
|
+
}
|
|
3212
|
+
async status(email) {
|
|
3213
|
+
const params = email ? { email } : void 0;
|
|
3214
|
+
return SubAccountStatusResponseSchema.parse(
|
|
3215
|
+
await this.http.get("/sapi/v1/sub-account/status", params, "signed")
|
|
3216
|
+
);
|
|
3217
|
+
}
|
|
3218
|
+
async spotAssets(email) {
|
|
3219
|
+
return SubAccountSpotAssetsResponseSchema.parse(
|
|
3220
|
+
await this.http.get("/sapi/v3/sub-account/assets", { email }, "signed")
|
|
3221
|
+
);
|
|
3222
|
+
}
|
|
3223
|
+
async spotSummary(options) {
|
|
3224
|
+
return SubAccountSpotSummarySchema.parse(
|
|
3225
|
+
await this.http.get("/sapi/v1/sub-account/spotSummary", options, "signed")
|
|
3226
|
+
);
|
|
3227
|
+
}
|
|
3228
|
+
async futuresAccountSummary(futuresType) {
|
|
3229
|
+
return SubAccountFuturesSummarySchema.parse(
|
|
3230
|
+
await this.http.get("/sapi/v2/sub-account/futures/accountSummary", { futuresType }, "signed")
|
|
3231
|
+
);
|
|
3232
|
+
}
|
|
3233
|
+
async marginAccount(email) {
|
|
3234
|
+
return SubAccountMarginAccountSchema.parse(
|
|
3235
|
+
await this.http.get("/sapi/v1/sub-account/margin/account", { email }, "signed")
|
|
3236
|
+
);
|
|
3237
|
+
}
|
|
3238
|
+
async universalTransfer(params) {
|
|
3239
|
+
return SubAccountUniversalTransferResultSchema.parse(
|
|
3240
|
+
await this.http.post("/sapi/v1/sub-account/universalTransfer", params, "signed")
|
|
3241
|
+
);
|
|
3242
|
+
}
|
|
3243
|
+
async universalTransferHistory(options) {
|
|
3244
|
+
return SubAccountUniversalTransferHistoryResponseSchema.parse(
|
|
3245
|
+
await this.http.get("/sapi/v1/sub-account/universalTransfer", options, "signed")
|
|
3246
|
+
);
|
|
3247
|
+
}
|
|
3248
|
+
async createVirtualSubAccount(subAccountString) {
|
|
3249
|
+
return VirtualSubAccountResultSchema.parse(
|
|
3250
|
+
await this.http.post("/sapi/v1/sub-account/virtualSubAccount", { subAccountString }, "signed")
|
|
3251
|
+
);
|
|
3252
|
+
}
|
|
3253
|
+
async enableFutures(email) {
|
|
3254
|
+
return SubAccountEnableResultSchema.parse(
|
|
3255
|
+
await this.http.post("/sapi/v1/sub-account/futures/enable", { email }, "signed")
|
|
3256
|
+
);
|
|
3257
|
+
}
|
|
3258
|
+
async enableMargin(email) {
|
|
3259
|
+
return SubAccountEnableResultSchema.parse(
|
|
3260
|
+
await this.http.post("/sapi/v1/sub-account/margin/enable", { email }, "signed")
|
|
3261
|
+
);
|
|
3262
|
+
}
|
|
3263
|
+
async depositAddress(email, coin, network) {
|
|
3264
|
+
return SubAccountDepositAddressSchema.parse(
|
|
3265
|
+
await this.http.get("/sapi/v1/capital/deposit/subAddress", { email, coin, network }, "signed")
|
|
3266
|
+
);
|
|
3267
|
+
}
|
|
3268
|
+
async depositHistory(options) {
|
|
3269
|
+
return SubAccountDepositHistoryResponseSchema.parse(
|
|
3270
|
+
await this.http.get("/sapi/v1/capital/deposit/subHisrec", options, "signed")
|
|
3271
|
+
);
|
|
3272
|
+
}
|
|
3273
|
+
};
|
|
3274
|
+
|
|
3275
|
+
// src/ws/BaseWS.ts
|
|
3276
|
+
var import_node_events = require("events");
|
|
3277
|
+
var import_ws = __toESM(require("ws"), 1);
|
|
3278
|
+
|
|
3279
|
+
// src/types/ws.types.ts
|
|
3280
|
+
var import_zod11 = require("zod");
|
|
3281
|
+
var WsKlinePayloadSchema = import_zod11.z.object({
|
|
3282
|
+
e: import_zod11.z.literal("kline"),
|
|
3283
|
+
E: import_zod11.z.number(),
|
|
3284
|
+
s: import_zod11.z.string(),
|
|
3285
|
+
k: import_zod11.z.object({
|
|
3286
|
+
t: import_zod11.z.number(),
|
|
3287
|
+
T: import_zod11.z.number(),
|
|
3288
|
+
s: import_zod11.z.string(),
|
|
3289
|
+
i: import_zod11.z.string(),
|
|
3290
|
+
o: import_zod11.z.string().transform(Number),
|
|
3291
|
+
c: import_zod11.z.string().transform(Number),
|
|
3292
|
+
h: import_zod11.z.string().transform(Number),
|
|
3293
|
+
l: import_zod11.z.string().transform(Number),
|
|
3294
|
+
v: import_zod11.z.string().transform(Number),
|
|
3295
|
+
n: import_zod11.z.number(),
|
|
3296
|
+
x: import_zod11.z.boolean(),
|
|
3297
|
+
q: import_zod11.z.string().transform(Number),
|
|
3298
|
+
V: import_zod11.z.string().transform(Number),
|
|
3299
|
+
Q: import_zod11.z.string().transform(Number)
|
|
3300
|
+
})
|
|
3301
|
+
});
|
|
3302
|
+
var WsAggTradePayloadSchema = import_zod11.z.object({
|
|
3303
|
+
e: import_zod11.z.literal("aggTrade"),
|
|
3304
|
+
E: import_zod11.z.number(),
|
|
3305
|
+
s: import_zod11.z.string(),
|
|
3306
|
+
a: import_zod11.z.number(),
|
|
3307
|
+
p: import_zod11.z.string().transform(Number),
|
|
3308
|
+
q: import_zod11.z.string().transform(Number),
|
|
3309
|
+
f: import_zod11.z.number(),
|
|
3310
|
+
l: import_zod11.z.number(),
|
|
3311
|
+
T: import_zod11.z.number(),
|
|
3312
|
+
m: import_zod11.z.boolean()
|
|
3313
|
+
});
|
|
3314
|
+
var WsTradePayloadSchema = import_zod11.z.object({
|
|
3315
|
+
e: import_zod11.z.literal("trade"),
|
|
3316
|
+
E: import_zod11.z.number(),
|
|
3317
|
+
s: import_zod11.z.string(),
|
|
3318
|
+
t: import_zod11.z.number(),
|
|
3319
|
+
p: import_zod11.z.string().transform(Number),
|
|
3320
|
+
q: import_zod11.z.string().transform(Number),
|
|
3321
|
+
T: import_zod11.z.number(),
|
|
3322
|
+
m: import_zod11.z.boolean()
|
|
3323
|
+
});
|
|
3324
|
+
var WsDepthUpdatePayloadSchema = import_zod11.z.object({
|
|
3325
|
+
e: import_zod11.z.literal("depthUpdate"),
|
|
3326
|
+
E: import_zod11.z.number(),
|
|
3327
|
+
s: import_zod11.z.string(),
|
|
3328
|
+
U: import_zod11.z.number(),
|
|
3329
|
+
u: import_zod11.z.number(),
|
|
3330
|
+
T: import_zod11.z.number().optional(),
|
|
3331
|
+
pu: import_zod11.z.number().optional(),
|
|
3332
|
+
b: import_zod11.z.array(import_zod11.z.tuple([import_zod11.z.string(), import_zod11.z.string()])),
|
|
3333
|
+
a: import_zod11.z.array(import_zod11.z.tuple([import_zod11.z.string(), import_zod11.z.string()]))
|
|
3334
|
+
});
|
|
3335
|
+
var WsTicker24hrPayloadSchema = import_zod11.z.object({
|
|
3336
|
+
e: import_zod11.z.literal("24hrTicker"),
|
|
3337
|
+
E: import_zod11.z.number(),
|
|
3338
|
+
s: import_zod11.z.string(),
|
|
3339
|
+
p: import_zod11.z.string().transform(Number),
|
|
3340
|
+
P: import_zod11.z.string().transform(Number),
|
|
3341
|
+
c: import_zod11.z.string().transform(Number),
|
|
3342
|
+
o: import_zod11.z.string().transform(Number),
|
|
3343
|
+
h: import_zod11.z.string().transform(Number),
|
|
3344
|
+
l: import_zod11.z.string().transform(Number),
|
|
3345
|
+
v: import_zod11.z.string().transform(Number),
|
|
3346
|
+
q: import_zod11.z.string().transform(Number)
|
|
3347
|
+
});
|
|
3348
|
+
var WsBookTickerPayloadSchema = import_zod11.z.object({
|
|
3349
|
+
u: import_zod11.z.number(),
|
|
3350
|
+
s: import_zod11.z.string(),
|
|
3351
|
+
b: import_zod11.z.string().transform(Number),
|
|
3352
|
+
B: import_zod11.z.string().transform(Number),
|
|
3353
|
+
a: import_zod11.z.string().transform(Number),
|
|
3354
|
+
A: import_zod11.z.string().transform(Number)
|
|
3355
|
+
});
|
|
3356
|
+
var WsMarkPricePayloadSchema = import_zod11.z.object({
|
|
3357
|
+
e: import_zod11.z.literal("markPriceUpdate"),
|
|
3358
|
+
E: import_zod11.z.number(),
|
|
3359
|
+
s: import_zod11.z.string(),
|
|
3360
|
+
p: import_zod11.z.string().transform(Number),
|
|
3361
|
+
i: import_zod11.z.string().transform(Number),
|
|
3362
|
+
P: import_zod11.z.string().transform(Number),
|
|
3363
|
+
r: import_zod11.z.string().transform(Number),
|
|
3364
|
+
T: import_zod11.z.number()
|
|
3365
|
+
});
|
|
3366
|
+
var WsMiniTickerPayloadSchema = import_zod11.z.object({
|
|
3367
|
+
e: import_zod11.z.literal("24hrMiniTicker"),
|
|
3368
|
+
E: import_zod11.z.number(),
|
|
3369
|
+
s: import_zod11.z.string(),
|
|
3370
|
+
c: import_zod11.z.string().transform(Number),
|
|
3371
|
+
o: import_zod11.z.string().transform(Number),
|
|
3372
|
+
h: import_zod11.z.string().transform(Number),
|
|
3373
|
+
l: import_zod11.z.string().transform(Number),
|
|
3374
|
+
v: import_zod11.z.string().transform(Number),
|
|
3375
|
+
q: import_zod11.z.string().transform(Number)
|
|
3376
|
+
});
|
|
3377
|
+
var WsForceOrderPayloadSchema = import_zod11.z.object({
|
|
3378
|
+
e: import_zod11.z.literal("forceOrder"),
|
|
3379
|
+
E: import_zod11.z.number(),
|
|
3380
|
+
o: import_zod11.z.object({
|
|
3381
|
+
s: import_zod11.z.string(),
|
|
3382
|
+
S: import_zod11.z.string(),
|
|
3383
|
+
o: import_zod11.z.string(),
|
|
3384
|
+
f: import_zod11.z.string(),
|
|
3385
|
+
q: import_zod11.z.string().transform(Number),
|
|
3386
|
+
p: import_zod11.z.string().transform(Number),
|
|
3387
|
+
ap: import_zod11.z.string().transform(Number),
|
|
3388
|
+
X: import_zod11.z.string(),
|
|
3389
|
+
l: import_zod11.z.string().transform(Number),
|
|
3390
|
+
z: import_zod11.z.string().transform(Number),
|
|
3391
|
+
T: import_zod11.z.number()
|
|
3392
|
+
})
|
|
3393
|
+
});
|
|
3394
|
+
var WsCompositeIndexPayloadSchema = import_zod11.z.object({
|
|
3395
|
+
e: import_zod11.z.literal("compositeIndex"),
|
|
3396
|
+
E: import_zod11.z.number(),
|
|
3397
|
+
s: import_zod11.z.string(),
|
|
3398
|
+
p: import_zod11.z.string().transform(Number),
|
|
3399
|
+
c: import_zod11.z.array(
|
|
3400
|
+
import_zod11.z.object({
|
|
3401
|
+
b: import_zod11.z.string(),
|
|
3402
|
+
q: import_zod11.z.string(),
|
|
3403
|
+
w: import_zod11.z.string().transform(Number),
|
|
3404
|
+
p: import_zod11.z.string().transform(Number)
|
|
3405
|
+
})
|
|
3406
|
+
)
|
|
3407
|
+
});
|
|
3408
|
+
var WsAssetIndexPayloadSchema = import_zod11.z.object({
|
|
3409
|
+
e: import_zod11.z.literal("assetIndex"),
|
|
3410
|
+
E: import_zod11.z.number(),
|
|
3411
|
+
s: import_zod11.z.string(),
|
|
3412
|
+
i: import_zod11.z.string().transform(Number),
|
|
3413
|
+
b: import_zod11.z.string().transform(Number),
|
|
3414
|
+
a: import_zod11.z.string().transform(Number)
|
|
3415
|
+
});
|
|
3416
|
+
var WsRollingWindowTickerPayloadSchema = import_zod11.z.object({
|
|
3417
|
+
e: import_zod11.z.enum(["1hTicker", "4hTicker", "1dTicker", "7dTicker", "30dTicker"]),
|
|
3418
|
+
E: import_zod11.z.number(),
|
|
3419
|
+
s: import_zod11.z.string(),
|
|
3420
|
+
p: import_zod11.z.string().transform(Number),
|
|
3421
|
+
P: import_zod11.z.string().transform(Number),
|
|
3422
|
+
o: import_zod11.z.string().transform(Number),
|
|
3423
|
+
h: import_zod11.z.string().transform(Number),
|
|
3424
|
+
l: import_zod11.z.string().transform(Number),
|
|
3425
|
+
c: import_zod11.z.string().transform(Number),
|
|
3426
|
+
v: import_zod11.z.string().transform(Number),
|
|
3427
|
+
q: import_zod11.z.string().transform(Number),
|
|
3428
|
+
O: import_zod11.z.number(),
|
|
3429
|
+
C: import_zod11.z.number()
|
|
3430
|
+
});
|
|
3431
|
+
var WsSpotAvgPricePayloadSchema = import_zod11.z.object({
|
|
3432
|
+
e: import_zod11.z.literal("avgPrice"),
|
|
3433
|
+
E: import_zod11.z.number(),
|
|
3434
|
+
s: import_zod11.z.string(),
|
|
3435
|
+
i: import_zod11.z.string(),
|
|
3436
|
+
w: import_zod11.z.string().transform(Number),
|
|
3437
|
+
T: import_zod11.z.number()
|
|
3438
|
+
});
|
|
3439
|
+
function parseWsPayload(streamName, raw) {
|
|
3440
|
+
if (streamName.includes("@kline_")) return WsKlinePayloadSchema.parse(raw);
|
|
3441
|
+
if (streamName.includes("@continuousKline_") || streamName.includes("@indexPriceKline_") || streamName.includes("@markPriceKline_")) {
|
|
3442
|
+
return WsKlinePayloadSchema.parse(raw);
|
|
3443
|
+
}
|
|
3444
|
+
if (streamName.includes("@aggTrade")) return WsAggTradePayloadSchema.parse(raw);
|
|
3445
|
+
if (streamName.includes("@trade")) return WsTradePayloadSchema.parse(raw);
|
|
3446
|
+
if (streamName.includes("@depth")) return WsDepthUpdatePayloadSchema.parse(raw);
|
|
3447
|
+
if (streamName.includes("@bookTicker")) return WsBookTickerPayloadSchema.parse(raw);
|
|
3448
|
+
if (streamName.includes("@markPrice")) return WsMarkPricePayloadSchema.parse(raw);
|
|
3449
|
+
if (streamName.includes("@miniTicker")) return WsMiniTickerPayloadSchema.parse(raw);
|
|
3450
|
+
if (streamName.includes("@forceOrder")) return WsForceOrderPayloadSchema.parse(raw);
|
|
3451
|
+
if (streamName.includes("@compositeIndex")) return WsCompositeIndexPayloadSchema.parse(raw);
|
|
3452
|
+
if (streamName.includes("@assetIndex")) return WsAssetIndexPayloadSchema.parse(raw);
|
|
3453
|
+
if (streamName.includes("@avgPrice")) return WsSpotAvgPricePayloadSchema.parse(raw);
|
|
3454
|
+
if (streamName.includes("@ticker_")) return WsRollingWindowTickerPayloadSchema.parse(raw);
|
|
3455
|
+
if (streamName.includes("@ticker")) return WsTicker24hrPayloadSchema.parse(raw);
|
|
3456
|
+
throw new Error(`Unknown WS stream type: ${streamName}`);
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
// src/ws/BaseWS.ts
|
|
3460
|
+
var BaseWS = class extends import_node_events.EventEmitter {
|
|
3461
|
+
constructor(options) {
|
|
3462
|
+
super();
|
|
3463
|
+
this.options = options;
|
|
3464
|
+
this.ws = null;
|
|
3465
|
+
this.streams = /* @__PURE__ */ new Set();
|
|
3466
|
+
this.reconnectAttempt = 0;
|
|
3467
|
+
this.closedByUser = false;
|
|
3468
|
+
}
|
|
3469
|
+
subscribe(streams) {
|
|
3470
|
+
streams.forEach((s) => this.streams.add(s));
|
|
3471
|
+
if (this.isOpen()) {
|
|
3472
|
+
this.send({ method: "SUBSCRIBE", params: streams, id: Date.now() });
|
|
3473
|
+
} else {
|
|
3474
|
+
this.connect();
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
unsubscribe(streams) {
|
|
3478
|
+
streams.forEach((s) => this.streams.delete(s));
|
|
3479
|
+
if (this.isOpen()) {
|
|
3480
|
+
this.send({ method: "UNSUBSCRIBE", params: streams, id: Date.now() });
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
close() {
|
|
3484
|
+
this.closedByUser = true;
|
|
3485
|
+
this.ws?.close();
|
|
3486
|
+
}
|
|
3487
|
+
reconnect() {
|
|
3488
|
+
if (this.ws?.readyState === import_ws.default.OPEN) this.ws.close();
|
|
3489
|
+
this.reconnectAttempt = 0;
|
|
3490
|
+
if (!this.closedByUser) this.connect();
|
|
3491
|
+
}
|
|
3492
|
+
resetReconnectAttempts() {
|
|
3493
|
+
this.reconnectAttempt = 0;
|
|
3494
|
+
}
|
|
3495
|
+
isOpen() {
|
|
3496
|
+
return this.ws?.readyState === import_ws.default.OPEN;
|
|
3497
|
+
}
|
|
3498
|
+
send(payload) {
|
|
3499
|
+
this.ws?.send(JSON.stringify(payload));
|
|
3500
|
+
}
|
|
3501
|
+
connect() {
|
|
3502
|
+
this.closedByUser = false;
|
|
3503
|
+
const url = `${this.options.baseStreamUrl}?streams=${[...this.streams].join("/")}`;
|
|
3504
|
+
this.ws = new import_ws.default(url);
|
|
3505
|
+
this.ws.on("open", () => {
|
|
3506
|
+
this.reconnectAttempt = 0;
|
|
3507
|
+
this.emit("open");
|
|
3508
|
+
});
|
|
3509
|
+
this.ws.on("message", (raw) => {
|
|
3510
|
+
this.handleMessage(raw.toString());
|
|
3511
|
+
});
|
|
3512
|
+
this.ws.on("close", () => {
|
|
3513
|
+
this.emit("close");
|
|
3514
|
+
if (!this.closedByUser) this.scheduleReconnect();
|
|
3515
|
+
});
|
|
3516
|
+
this.ws.on("error", (err) => {
|
|
3517
|
+
if (this.closedByUser) return;
|
|
3518
|
+
this.emit("error", err);
|
|
3519
|
+
});
|
|
3520
|
+
}
|
|
3521
|
+
handleMessage(raw) {
|
|
3522
|
+
let parsed;
|
|
3523
|
+
try {
|
|
3524
|
+
parsed = JSON.parse(raw);
|
|
3525
|
+
} catch {
|
|
3526
|
+
return;
|
|
3527
|
+
}
|
|
3528
|
+
if (!parsed.stream || parsed.data === void 0) return;
|
|
3529
|
+
try {
|
|
3530
|
+
const payload = parseWsPayload(parsed.stream, parsed.data);
|
|
3531
|
+
this.emit("message", parsed.stream, payload);
|
|
3532
|
+
this.emit(parsed.stream, payload);
|
|
3533
|
+
} catch (err) {
|
|
3534
|
+
this.emit("error", err);
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
scheduleReconnect() {
|
|
3538
|
+
const base = this.options.reconnectDelayMs ?? 1e3;
|
|
3539
|
+
const max = this.options.maxReconnectDelayMs ?? 3e4;
|
|
3540
|
+
const delay = Math.min(base * 2 ** this.reconnectAttempt, max);
|
|
3541
|
+
this.reconnectAttempt += 1;
|
|
3542
|
+
setTimeout(() => {
|
|
3543
|
+
if (!this.closedByUser) this.connect();
|
|
3544
|
+
}, delay);
|
|
3545
|
+
}
|
|
3546
|
+
};
|
|
3547
|
+
|
|
3548
|
+
// src/ws/FuturesMarketWS.ts
|
|
3549
|
+
var FuturesMarketWS = class extends BaseWS {
|
|
3550
|
+
constructor(baseStreamUrl = "wss://fstream.binance.com/stream") {
|
|
3551
|
+
super({ baseStreamUrl });
|
|
3552
|
+
}
|
|
3553
|
+
kline(symbol3, interval) {
|
|
3554
|
+
return `${symbol3.toLowerCase()}@kline_${interval}`;
|
|
3555
|
+
}
|
|
3556
|
+
continuousKline(symbol3, contractType2, interval) {
|
|
3557
|
+
return `${symbol3.toLowerCase()}@continuousKline_${contractType2}_${interval}`;
|
|
3558
|
+
}
|
|
3559
|
+
indexPriceKline(symbol3, interval) {
|
|
3560
|
+
return `${symbol3.toLowerCase()}@indexPriceKline_${interval}`;
|
|
3561
|
+
}
|
|
3562
|
+
markPriceKline(symbol3, interval) {
|
|
3563
|
+
return `${symbol3.toLowerCase()}@markPriceKline_${interval}`;
|
|
3564
|
+
}
|
|
3565
|
+
aggTrade(symbol3) {
|
|
3566
|
+
return `${symbol3.toLowerCase()}@aggTrade`;
|
|
3567
|
+
}
|
|
3568
|
+
trade(symbol3) {
|
|
3569
|
+
return `${symbol3.toLowerCase()}@trade`;
|
|
2173
3570
|
}
|
|
2174
3571
|
depth(symbol3, level = 20) {
|
|
2175
3572
|
return `${symbol3.toLowerCase()}@depth${level}`;
|
|
@@ -2314,48 +3711,185 @@ var SpotUserWS = class extends import_node_events2.EventEmitter {
|
|
|
2314
3711
|
this.emit("error", err);
|
|
2315
3712
|
});
|
|
2316
3713
|
}
|
|
2317
|
-
close() {
|
|
2318
|
-
this.closedByUser = true;
|
|
2319
|
-
this.ws?.close();
|
|
3714
|
+
close() {
|
|
3715
|
+
this.closedByUser = true;
|
|
3716
|
+
this.ws?.close();
|
|
3717
|
+
}
|
|
3718
|
+
reconnect() {
|
|
3719
|
+
if (this.ws?.readyState === import_ws2.default.OPEN) this.ws.close();
|
|
3720
|
+
this.reconnectAttempt = 0;
|
|
3721
|
+
if (!this.closedByUser) this.connect();
|
|
3722
|
+
}
|
|
3723
|
+
resetReconnectAttempts() {
|
|
3724
|
+
this.reconnectAttempt = 0;
|
|
3725
|
+
}
|
|
3726
|
+
handleMessage(raw) {
|
|
3727
|
+
let parsed;
|
|
3728
|
+
try {
|
|
3729
|
+
parsed = JSON.parse(raw);
|
|
3730
|
+
} catch {
|
|
3731
|
+
return;
|
|
3732
|
+
}
|
|
3733
|
+
try {
|
|
3734
|
+
const event = parseSpotUserDataEvent(parsed);
|
|
3735
|
+
this.emit(event.e, event);
|
|
3736
|
+
this.emit("userData", event);
|
|
3737
|
+
} catch (err) {
|
|
3738
|
+
this.emit("error", err);
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
scheduleReconnect() {
|
|
3742
|
+
const base = this.options.reconnectDelayMs ?? 1e3;
|
|
3743
|
+
const max = this.options.maxReconnectDelayMs ?? 3e4;
|
|
3744
|
+
const delay = Math.min(base * 2 ** this.reconnectAttempt, max);
|
|
3745
|
+
this.reconnectAttempt += 1;
|
|
3746
|
+
setTimeout(() => {
|
|
3747
|
+
if (!this.closedByUser) this.connect();
|
|
3748
|
+
}, delay);
|
|
3749
|
+
}
|
|
3750
|
+
};
|
|
3751
|
+
|
|
3752
|
+
// src/ws/FuturesUserWS.ts
|
|
3753
|
+
var import_node_events3 = require("events");
|
|
3754
|
+
var import_ws3 = __toESM(require("ws"), 1);
|
|
3755
|
+
var FuturesUserWS = class extends import_node_events3.EventEmitter {
|
|
3756
|
+
constructor(options) {
|
|
3757
|
+
super();
|
|
3758
|
+
this.options = options;
|
|
3759
|
+
this.ws = null;
|
|
3760
|
+
this.reconnectAttempt = 0;
|
|
3761
|
+
this.closedByUser = false;
|
|
3762
|
+
}
|
|
3763
|
+
connect() {
|
|
3764
|
+
const listenKey = this.options.getListenKey();
|
|
3765
|
+
if (!listenKey) {
|
|
3766
|
+
this.emit("error", new Error("No listenKey available for user data stream"));
|
|
3767
|
+
return;
|
|
3768
|
+
}
|
|
3769
|
+
this.closedByUser = false;
|
|
3770
|
+
const url = `${this.options.baseUserUrl}/${listenKey}`;
|
|
3771
|
+
this.ws = new import_ws3.default(url);
|
|
3772
|
+
this.ws.on("open", () => {
|
|
3773
|
+
this.reconnectAttempt = 0;
|
|
3774
|
+
this.emit("open");
|
|
3775
|
+
});
|
|
3776
|
+
this.ws.on("message", (raw) => {
|
|
3777
|
+
this.handleMessage(raw.toString());
|
|
3778
|
+
});
|
|
3779
|
+
this.ws.on("close", () => {
|
|
3780
|
+
this.emit("close");
|
|
3781
|
+
if (!this.closedByUser) this.scheduleReconnect();
|
|
3782
|
+
});
|
|
3783
|
+
this.ws.on("error", (err) => {
|
|
3784
|
+
this.emit("error", err);
|
|
3785
|
+
});
|
|
3786
|
+
}
|
|
3787
|
+
close() {
|
|
3788
|
+
this.closedByUser = true;
|
|
3789
|
+
this.ws?.close();
|
|
3790
|
+
}
|
|
3791
|
+
reconnect() {
|
|
3792
|
+
if (this.ws?.readyState === import_ws3.default.OPEN) this.ws.close();
|
|
3793
|
+
this.reconnectAttempt = 0;
|
|
3794
|
+
if (!this.closedByUser) this.connect();
|
|
3795
|
+
}
|
|
3796
|
+
resetReconnectAttempts() {
|
|
3797
|
+
this.reconnectAttempt = 0;
|
|
3798
|
+
}
|
|
3799
|
+
handleMessage(raw) {
|
|
3800
|
+
let parsed;
|
|
3801
|
+
try {
|
|
3802
|
+
parsed = JSON.parse(raw);
|
|
3803
|
+
} catch {
|
|
3804
|
+
return;
|
|
3805
|
+
}
|
|
3806
|
+
try {
|
|
3807
|
+
const event = parseUserDataEvent(parsed);
|
|
3808
|
+
this.emit(event.e, event);
|
|
3809
|
+
this.emit("userData", event);
|
|
3810
|
+
} catch (err) {
|
|
3811
|
+
this.emit("error", err);
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3814
|
+
scheduleReconnect() {
|
|
3815
|
+
const base = this.options.reconnectDelayMs ?? 1e3;
|
|
3816
|
+
const max = this.options.maxReconnectDelayMs ?? 3e4;
|
|
3817
|
+
const delay = Math.min(base * 2 ** this.reconnectAttempt, max);
|
|
3818
|
+
this.reconnectAttempt += 1;
|
|
3819
|
+
setTimeout(() => {
|
|
3820
|
+
if (!this.closedByUser) this.connect();
|
|
3821
|
+
}, delay);
|
|
3822
|
+
}
|
|
3823
|
+
};
|
|
3824
|
+
|
|
3825
|
+
// src/ws/CoinMMarketWS.ts
|
|
3826
|
+
var CoinMMarketWS = class extends BaseWS {
|
|
3827
|
+
constructor(baseStreamUrl = "wss://dstream.binance.com/stream") {
|
|
3828
|
+
super({ baseStreamUrl });
|
|
3829
|
+
}
|
|
3830
|
+
kline(symbol3, interval) {
|
|
3831
|
+
return `${symbol3.toLowerCase()}@kline_${interval}`;
|
|
3832
|
+
}
|
|
3833
|
+
continuousKline(pair, contractType2, interval) {
|
|
3834
|
+
return `${pair.toLowerCase()}_${contractType2}@continuousKline_${interval}`;
|
|
3835
|
+
}
|
|
3836
|
+
indexPriceKline(pair, interval) {
|
|
3837
|
+
return `${pair.toLowerCase()}@indexPriceKline_${interval}`;
|
|
3838
|
+
}
|
|
3839
|
+
markPriceKline(symbol3, interval) {
|
|
3840
|
+
return `${symbol3.toLowerCase()}@markPriceKline_${interval}`;
|
|
3841
|
+
}
|
|
3842
|
+
aggTrade(symbol3) {
|
|
3843
|
+
return `${symbol3.toLowerCase()}@aggTrade`;
|
|
3844
|
+
}
|
|
3845
|
+
trade(symbol3) {
|
|
3846
|
+
return `${symbol3.toLowerCase()}@trade`;
|
|
3847
|
+
}
|
|
3848
|
+
depth(symbol3, level = 20) {
|
|
3849
|
+
return `${symbol3.toLowerCase()}@depth${level}`;
|
|
3850
|
+
}
|
|
3851
|
+
depthDiff(symbol3) {
|
|
3852
|
+
return `${symbol3.toLowerCase()}@depth`;
|
|
3853
|
+
}
|
|
3854
|
+
depthDiffSpeed(symbol3, updateSpeed) {
|
|
3855
|
+
return `${symbol3.toLowerCase()}@depth@${updateSpeed}`;
|
|
3856
|
+
}
|
|
3857
|
+
ticker(symbol3) {
|
|
3858
|
+
return `${symbol3.toLowerCase()}@ticker`;
|
|
3859
|
+
}
|
|
3860
|
+
allMarketTickers() {
|
|
3861
|
+
return "!ticker@arr";
|
|
3862
|
+
}
|
|
3863
|
+
miniTicker(symbol3) {
|
|
3864
|
+
return `${symbol3.toLowerCase()}@miniTicker`;
|
|
3865
|
+
}
|
|
3866
|
+
allMiniTickers() {
|
|
3867
|
+
return "!miniTicker@arr";
|
|
3868
|
+
}
|
|
3869
|
+
bookTicker(symbol3) {
|
|
3870
|
+
return `${symbol3.toLowerCase()}@bookTicker`;
|
|
2320
3871
|
}
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
this.reconnectAttempt = 0;
|
|
2324
|
-
if (!this.closedByUser) this.connect();
|
|
3872
|
+
allBookTickers() {
|
|
3873
|
+
return "!bookTicker";
|
|
2325
3874
|
}
|
|
2326
|
-
|
|
2327
|
-
|
|
3875
|
+
markPrice(symbol3, updateSpeed = "3s") {
|
|
3876
|
+
return `${symbol3.toLowerCase()}@markPrice@${updateSpeed}`;
|
|
2328
3877
|
}
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
try {
|
|
2332
|
-
parsed = JSON.parse(raw);
|
|
2333
|
-
} catch {
|
|
2334
|
-
return;
|
|
2335
|
-
}
|
|
2336
|
-
try {
|
|
2337
|
-
const event = parseSpotUserDataEvent(parsed);
|
|
2338
|
-
this.emit(event.e, event);
|
|
2339
|
-
this.emit("userData", event);
|
|
2340
|
-
} catch (err) {
|
|
2341
|
-
this.emit("error", err);
|
|
2342
|
-
}
|
|
3878
|
+
markPriceForPair(pair, updateSpeed = "3s") {
|
|
3879
|
+
return `${pair.toLowerCase()}@markPrice@${updateSpeed}`;
|
|
2343
3880
|
}
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
setTimeout(() => {
|
|
2350
|
-
if (!this.closedByUser) this.connect();
|
|
2351
|
-
}, delay);
|
|
3881
|
+
liquidationOrder(symbol3) {
|
|
3882
|
+
return `${symbol3.toLowerCase()}@forceOrder`;
|
|
3883
|
+
}
|
|
3884
|
+
allLiquidationOrders() {
|
|
3885
|
+
return "!forceOrder@arr";
|
|
2352
3886
|
}
|
|
2353
3887
|
};
|
|
2354
3888
|
|
|
2355
|
-
// src/ws/
|
|
2356
|
-
var
|
|
2357
|
-
var
|
|
2358
|
-
var
|
|
3889
|
+
// src/ws/CoinMUserWS.ts
|
|
3890
|
+
var import_node_events4 = require("events");
|
|
3891
|
+
var import_ws4 = __toESM(require("ws"), 1);
|
|
3892
|
+
var CoinMUserWS = class extends import_node_events4.EventEmitter {
|
|
2359
3893
|
constructor(options) {
|
|
2360
3894
|
super();
|
|
2361
3895
|
this.options = options;
|
|
@@ -2366,12 +3900,12 @@ var FuturesUserWS = class extends import_node_events3.EventEmitter {
|
|
|
2366
3900
|
connect() {
|
|
2367
3901
|
const listenKey = this.options.getListenKey();
|
|
2368
3902
|
if (!listenKey) {
|
|
2369
|
-
this.emit("error", new Error("No listenKey available for user data stream"));
|
|
3903
|
+
this.emit("error", new Error("No listenKey available for COIN-M user data stream"));
|
|
2370
3904
|
return;
|
|
2371
3905
|
}
|
|
2372
3906
|
this.closedByUser = false;
|
|
2373
3907
|
const url = `${this.options.baseUserUrl}/${listenKey}`;
|
|
2374
|
-
this.ws = new
|
|
3908
|
+
this.ws = new import_ws4.default(url);
|
|
2375
3909
|
this.ws.on("open", () => {
|
|
2376
3910
|
this.reconnectAttempt = 0;
|
|
2377
3911
|
this.emit("open");
|
|
@@ -2392,7 +3926,7 @@ var FuturesUserWS = class extends import_node_events3.EventEmitter {
|
|
|
2392
3926
|
this.ws?.close();
|
|
2393
3927
|
}
|
|
2394
3928
|
reconnect() {
|
|
2395
|
-
if (this.ws?.readyState ===
|
|
3929
|
+
if (this.ws?.readyState === import_ws4.default.OPEN) this.ws.close();
|
|
2396
3930
|
this.reconnectAttempt = 0;
|
|
2397
3931
|
if (!this.closedByUser) this.connect();
|
|
2398
3932
|
}
|
|
@@ -2427,31 +3961,36 @@ var FuturesUserWS = class extends import_node_events3.EventEmitter {
|
|
|
2427
3961
|
|
|
2428
3962
|
// src/ws/WsApi.ts
|
|
2429
3963
|
var import_node_crypto2 = require("crypto");
|
|
2430
|
-
var
|
|
3964
|
+
var import_ws5 = __toESM(require("ws"), 1);
|
|
2431
3965
|
function buildQueryString(data) {
|
|
2432
3966
|
return Object.entries(data).filter(([, val]) => val !== void 0 && val !== null).map(([key, val]) => `${key}=${encodeURIComponent(String(val))}`).join("&");
|
|
2433
3967
|
}
|
|
2434
3968
|
var WsApi = class {
|
|
2435
3969
|
constructor(options) {
|
|
2436
3970
|
this.options = options;
|
|
3971
|
+
this.signer = new Signer({
|
|
3972
|
+
algorithm: options.signatureAlgorithm,
|
|
3973
|
+
apiSecret: options.apiSecret,
|
|
3974
|
+
privateKey: options.privateKey
|
|
3975
|
+
});
|
|
2437
3976
|
}
|
|
2438
3977
|
async request(method, params = {}, options) {
|
|
2439
|
-
const { apiKey
|
|
3978
|
+
const { apiKey } = this.options;
|
|
2440
3979
|
const signed = options?.signed ?? true;
|
|
2441
3980
|
const { id = (0, import_node_crypto2.randomUUID)(), ...methodParams } = params;
|
|
2442
3981
|
const requestParams = { ...methodParams };
|
|
2443
3982
|
if (signed) {
|
|
2444
|
-
if (!apiKey || !
|
|
2445
|
-
throw new Error("API key and secret required for signed WebSocket API requests");
|
|
3983
|
+
if (!apiKey || !this.signer.canSign()) {
|
|
3984
|
+
throw new Error("API key and secret (or privateKey) required for signed WebSocket API requests");
|
|
2446
3985
|
}
|
|
2447
3986
|
requestParams.apiKey = apiKey;
|
|
2448
3987
|
requestParams.timestamp = Date.now();
|
|
2449
3988
|
requestParams.recvWindow = this.options.recvWindow ?? 5e3;
|
|
2450
3989
|
const queryString = buildQueryString(requestParams);
|
|
2451
|
-
requestParams.signature =
|
|
3990
|
+
requestParams.signature = this.signer.sign(queryString);
|
|
2452
3991
|
}
|
|
2453
3992
|
return new Promise((resolve, reject) => {
|
|
2454
|
-
const ws = new
|
|
3993
|
+
const ws = new import_ws5.default(this.options.baseUrl);
|
|
2455
3994
|
const timeout = setTimeout(() => {
|
|
2456
3995
|
ws.close();
|
|
2457
3996
|
reject(new NetworkError(`WebSocket API request timed out: ${method}`));
|
|
@@ -2552,6 +4091,174 @@ var WsApi = class {
|
|
|
2552
4091
|
}
|
|
2553
4092
|
};
|
|
2554
4093
|
|
|
4094
|
+
// src/ws/SpotWsApi.ts
|
|
4095
|
+
var import_node_crypto3 = require("crypto");
|
|
4096
|
+
var import_ws6 = __toESM(require("ws"), 1);
|
|
4097
|
+
function buildQueryString2(data) {
|
|
4098
|
+
return Object.entries(data).filter(([, val]) => val !== void 0 && val !== null).map(([key, val]) => `${key}=${encodeURIComponent(String(val))}`).join("&");
|
|
4099
|
+
}
|
|
4100
|
+
var SpotWsApi = class {
|
|
4101
|
+
constructor(options) {
|
|
4102
|
+
this.options = options;
|
|
4103
|
+
this.signer = new Signer({
|
|
4104
|
+
algorithm: options.signatureAlgorithm,
|
|
4105
|
+
apiSecret: options.apiSecret,
|
|
4106
|
+
privateKey: options.privateKey
|
|
4107
|
+
});
|
|
4108
|
+
}
|
|
4109
|
+
async request(method, params = {}, options) {
|
|
4110
|
+
const { apiKey } = this.options;
|
|
4111
|
+
const signed = options?.signed ?? true;
|
|
4112
|
+
const { id = (0, import_node_crypto3.randomUUID)(), ...methodParams } = params;
|
|
4113
|
+
const requestParams = { ...methodParams };
|
|
4114
|
+
if (signed) {
|
|
4115
|
+
if (!apiKey || !this.signer.canSign()) {
|
|
4116
|
+
throw new Error("API key and secret (or privateKey) required for signed WebSocket API requests");
|
|
4117
|
+
}
|
|
4118
|
+
requestParams.apiKey = apiKey;
|
|
4119
|
+
requestParams.timestamp = Date.now();
|
|
4120
|
+
requestParams.recvWindow = this.options.recvWindow ?? 5e3;
|
|
4121
|
+
const queryString = buildQueryString2(requestParams);
|
|
4122
|
+
requestParams.signature = this.signer.sign(queryString);
|
|
4123
|
+
}
|
|
4124
|
+
return new Promise((resolve, reject) => {
|
|
4125
|
+
const ws = new import_ws6.default(this.options.baseUrl);
|
|
4126
|
+
const timeout = setTimeout(() => {
|
|
4127
|
+
ws.close();
|
|
4128
|
+
reject(new NetworkError(`WebSocket API request timed out: ${method}`));
|
|
4129
|
+
}, this.options.timeoutMs ?? 15e3);
|
|
4130
|
+
ws.on("open", () => ws.send(JSON.stringify({ id, method, params: requestParams })));
|
|
4131
|
+
ws.on("message", (raw) => {
|
|
4132
|
+
clearTimeout(timeout);
|
|
4133
|
+
ws.close();
|
|
4134
|
+
try {
|
|
4135
|
+
const parsed = JSON.parse(raw.toString());
|
|
4136
|
+
if (parsed.status >= 400) {
|
|
4137
|
+
reject(new Error(parsed.error?.msg ?? `WebSocket API error: ${method}`));
|
|
4138
|
+
} else {
|
|
4139
|
+
resolve(parsed);
|
|
4140
|
+
}
|
|
4141
|
+
} catch (err) {
|
|
4142
|
+
reject(new NetworkError("Invalid WebSocket API JSON payload", err));
|
|
4143
|
+
}
|
|
4144
|
+
});
|
|
4145
|
+
ws.on("error", (err) => {
|
|
4146
|
+
clearTimeout(timeout);
|
|
4147
|
+
reject(new NetworkError(err.message, err));
|
|
4148
|
+
});
|
|
4149
|
+
});
|
|
4150
|
+
}
|
|
4151
|
+
// ---- Trading (signed) ----
|
|
4152
|
+
placeOrder(params) {
|
|
4153
|
+
return this.request("order.place", params);
|
|
4154
|
+
}
|
|
4155
|
+
testOrder(params) {
|
|
4156
|
+
return this.request("order.test", params);
|
|
4157
|
+
}
|
|
4158
|
+
cancelOrder(params) {
|
|
4159
|
+
return this.request("order.cancel", params);
|
|
4160
|
+
}
|
|
4161
|
+
cancelReplaceOrder(params) {
|
|
4162
|
+
return this.request("order.cancelReplace", params);
|
|
4163
|
+
}
|
|
4164
|
+
orderStatus(params) {
|
|
4165
|
+
return this.request("order.status", params);
|
|
4166
|
+
}
|
|
4167
|
+
openOrdersStatus(params = {}) {
|
|
4168
|
+
return this.request("openOrders.status", params);
|
|
4169
|
+
}
|
|
4170
|
+
cancelOpenOrders(params) {
|
|
4171
|
+
return this.request("openOrders.cancelAll", params);
|
|
4172
|
+
}
|
|
4173
|
+
placeOrderList(params) {
|
|
4174
|
+
return this.request("orderList.place", params);
|
|
4175
|
+
}
|
|
4176
|
+
cancelOrderList(params) {
|
|
4177
|
+
return this.request("orderList.cancel", params);
|
|
4178
|
+
}
|
|
4179
|
+
orderListStatus(params) {
|
|
4180
|
+
return this.request("orderList.status", params);
|
|
4181
|
+
}
|
|
4182
|
+
openOrderListsStatus() {
|
|
4183
|
+
return this.request("openOrderLists.status", {});
|
|
4184
|
+
}
|
|
4185
|
+
// ---- Account (signed) ----
|
|
4186
|
+
accountStatus() {
|
|
4187
|
+
return this.request("account.status", {});
|
|
4188
|
+
}
|
|
4189
|
+
accountCommission(params) {
|
|
4190
|
+
return this.request("account.commission", params);
|
|
4191
|
+
}
|
|
4192
|
+
accountRateLimitsOrders() {
|
|
4193
|
+
return this.request("account.rateLimits.orders", {});
|
|
4194
|
+
}
|
|
4195
|
+
allOrders(params) {
|
|
4196
|
+
return this.request("allOrders", params);
|
|
4197
|
+
}
|
|
4198
|
+
allOrderLists(params = {}) {
|
|
4199
|
+
return this.request("allOrderLists", params);
|
|
4200
|
+
}
|
|
4201
|
+
myTrades(params) {
|
|
4202
|
+
return this.request("myTrades", params);
|
|
4203
|
+
}
|
|
4204
|
+
// ---- User data stream (managed listen keys) ----
|
|
4205
|
+
userDataStreamStart() {
|
|
4206
|
+
return this.request("userDataStream.start", {});
|
|
4207
|
+
}
|
|
4208
|
+
userDataStreamPing(listenKey) {
|
|
4209
|
+
return this.request("userDataStream.ping", { listenKey });
|
|
4210
|
+
}
|
|
4211
|
+
userDataStreamStop(listenKey) {
|
|
4212
|
+
return this.request("userDataStream.stop", { listenKey });
|
|
4213
|
+
}
|
|
4214
|
+
// ---- Public market data (no signature required) ----
|
|
4215
|
+
ping() {
|
|
4216
|
+
return this.request("ping", {}, { signed: false });
|
|
4217
|
+
}
|
|
4218
|
+
time() {
|
|
4219
|
+
return this.request("time", {}, { signed: false });
|
|
4220
|
+
}
|
|
4221
|
+
exchangeInfo(params = {}) {
|
|
4222
|
+
return this.request("exchangeInfo", params, { signed: false });
|
|
4223
|
+
}
|
|
4224
|
+
depth(params) {
|
|
4225
|
+
return this.request("depth", params, { signed: false });
|
|
4226
|
+
}
|
|
4227
|
+
recentTrades(params) {
|
|
4228
|
+
return this.request("trades.recent", params, { signed: false });
|
|
4229
|
+
}
|
|
4230
|
+
historicalTrades(params) {
|
|
4231
|
+
return this.request("trades.historical", params, { signed: false });
|
|
4232
|
+
}
|
|
4233
|
+
aggTrades(params) {
|
|
4234
|
+
return this.request("trades.aggregate", params, { signed: false });
|
|
4235
|
+
}
|
|
4236
|
+
klines(params) {
|
|
4237
|
+
return this.request("klines", params, { signed: false });
|
|
4238
|
+
}
|
|
4239
|
+
uiKlines(params) {
|
|
4240
|
+
return this.request("uiKlines", params, { signed: false });
|
|
4241
|
+
}
|
|
4242
|
+
avgPrice(params) {
|
|
4243
|
+
return this.request("avgPrice", params, { signed: false });
|
|
4244
|
+
}
|
|
4245
|
+
ticker24hr(params = {}) {
|
|
4246
|
+
return this.request("ticker.24hr", params, { signed: false });
|
|
4247
|
+
}
|
|
4248
|
+
tickerTradingDay(params) {
|
|
4249
|
+
return this.request("ticker.tradingDay", params, { signed: false });
|
|
4250
|
+
}
|
|
4251
|
+
tickerPrice(params = {}) {
|
|
4252
|
+
return this.request("ticker.price", params, { signed: false });
|
|
4253
|
+
}
|
|
4254
|
+
tickerBook(params = {}) {
|
|
4255
|
+
return this.request("ticker.book", params, { signed: false });
|
|
4256
|
+
}
|
|
4257
|
+
ticker(params) {
|
|
4258
|
+
return this.request("ticker", params, { signed: false });
|
|
4259
|
+
}
|
|
4260
|
+
};
|
|
4261
|
+
|
|
2555
4262
|
// src/client/BinanceClient.ts
|
|
2556
4263
|
var BinanceClient = class {
|
|
2557
4264
|
constructor(options = {}) {
|
|
@@ -2559,18 +4266,29 @@ var BinanceClient = class {
|
|
|
2559
4266
|
this.keepAliveInterval = null;
|
|
2560
4267
|
this.spotListenKeyValue = null;
|
|
2561
4268
|
this.spotKeepAliveInterval = null;
|
|
4269
|
+
this.coinmListenKeyValue = null;
|
|
4270
|
+
this.coinmKeepAliveInterval = null;
|
|
2562
4271
|
const { endpoints } = resolveEnvironment(options);
|
|
4272
|
+
this.policy = options.safety ? new TradingPolicy(options.safety) : void 0;
|
|
2563
4273
|
const httpOptions = {
|
|
4274
|
+
policy: this.policy,
|
|
2564
4275
|
apiKey: options.apiKey,
|
|
2565
4276
|
apiSecret: options.apiSecret,
|
|
4277
|
+
privateKey: options.privateKey,
|
|
4278
|
+
signatureAlgorithm: options.signatureAlgorithm,
|
|
2566
4279
|
recvWindow: options.recvWindow ?? 5e3,
|
|
2567
4280
|
timeoutMs: options.timeoutMs ?? 15e3,
|
|
2568
4281
|
maxRetries: options.maxRetries ?? 3,
|
|
2569
4282
|
retryBaseDelayMs: options.retryBaseDelayMs,
|
|
2570
|
-
retryMaxDelayMs: options.retryMaxDelayMs
|
|
4283
|
+
retryMaxDelayMs: options.retryMaxDelayMs,
|
|
4284
|
+
rateLimitWeightPerMinute: options.rateLimitWeightPerMinute,
|
|
4285
|
+
rateLimitSafetyMargin: options.rateLimitSafetyMargin,
|
|
4286
|
+
httpsAgent: options.httpsAgent,
|
|
4287
|
+
proxy: options.proxy
|
|
2571
4288
|
};
|
|
2572
4289
|
this.authHttp = new HttpClient({ baseURL: endpoints.restRoot, ...httpOptions });
|
|
2573
|
-
|
|
4290
|
+
this.spotHttp = new HttpClient({ baseURL: endpoints.restSpot, ...httpOptions });
|
|
4291
|
+
const spotHttp = this.spotHttp;
|
|
2574
4292
|
this.spot = {
|
|
2575
4293
|
market: new SpotMarket(spotHttp),
|
|
2576
4294
|
account: new SpotAccount(spotHttp),
|
|
@@ -2580,6 +4298,14 @@ var BinanceClient = class {
|
|
|
2580
4298
|
wsUser: new SpotUserWS({
|
|
2581
4299
|
baseUserUrl: endpoints.wsSpotUser,
|
|
2582
4300
|
getListenKey: () => this.spotListenKeyValue
|
|
4301
|
+
}),
|
|
4302
|
+
wsApi: new SpotWsApi({
|
|
4303
|
+
baseUrl: endpoints.wsSpotApi,
|
|
4304
|
+
apiKey: options.apiKey,
|
|
4305
|
+
apiSecret: options.apiSecret,
|
|
4306
|
+
privateKey: options.privateKey,
|
|
4307
|
+
signatureAlgorithm: options.signatureAlgorithm,
|
|
4308
|
+
recvWindow: options.recvWindow
|
|
2583
4309
|
})
|
|
2584
4310
|
};
|
|
2585
4311
|
const futuresMarket = new FuturesMarket(
|
|
@@ -2609,9 +4335,30 @@ var BinanceClient = class {
|
|
|
2609
4335
|
baseUrl: endpoints.wsApi,
|
|
2610
4336
|
apiKey: options.apiKey,
|
|
2611
4337
|
apiSecret: options.apiSecret,
|
|
4338
|
+
privateKey: options.privateKey,
|
|
4339
|
+
signatureAlgorithm: options.signatureAlgorithm,
|
|
2612
4340
|
recvWindow: options.recvWindow
|
|
2613
4341
|
})
|
|
2614
4342
|
};
|
|
4343
|
+
this.dapiHttp = new HttpClient({ baseURL: endpoints.restDapiRoot, ...httpOptions });
|
|
4344
|
+
this.coinm = {
|
|
4345
|
+
market: new CoinMMarket(new HttpClient({ baseURL: endpoints.restDapi, ...httpOptions })),
|
|
4346
|
+
account: new CoinMAccount(this.dapiHttp),
|
|
4347
|
+
trading: new CoinMTrading(this.dapiHttp),
|
|
4348
|
+
userStream: new CoinMUserDataStream(this.dapiHttp),
|
|
4349
|
+
ws: new CoinMMarketWS(endpoints.wsDapiMarket),
|
|
4350
|
+
wsUser: new CoinMUserWS({
|
|
4351
|
+
baseUserUrl: endpoints.wsDapiUser,
|
|
4352
|
+
getListenKey: () => this.coinmListenKeyValue
|
|
4353
|
+
})
|
|
4354
|
+
};
|
|
4355
|
+
this.sapiHttp = new HttpClient({ baseURL: endpoints.restApiRoot, ...httpOptions });
|
|
4356
|
+
this.margin = {
|
|
4357
|
+
account: new MarginAccount(this.sapiHttp),
|
|
4358
|
+
trading: new MarginTrading(this.sapiHttp)
|
|
4359
|
+
};
|
|
4360
|
+
this.wallet = new Wallet(this.sapiHttp);
|
|
4361
|
+
this.subaccount = new SubAccount(this.sapiHttp);
|
|
2615
4362
|
}
|
|
2616
4363
|
static nowSeconds() {
|
|
2617
4364
|
return Math.floor(Date.now() / 1e3);
|
|
@@ -2628,6 +4375,31 @@ var BinanceClient = class {
|
|
|
2628
4375
|
const dir = side3 === "buy" ? 1 : -1;
|
|
2629
4376
|
return dir === 1 ? entryPrice * (1 - 1 / leverage + mm) : entryPrice * (1 + 1 / leverage - mm);
|
|
2630
4377
|
}
|
|
4378
|
+
/**
|
|
4379
|
+
* Syncs local time against each REST host's server clock and stores the offset, applied to
|
|
4380
|
+
* every subsequent signed request's `timestamp` param. Call this once after construction to
|
|
4381
|
+
* mitigate `-1021` errors caused by local clock drift.
|
|
4382
|
+
*/
|
|
4383
|
+
async syncTime() {
|
|
4384
|
+
await Promise.all([
|
|
4385
|
+
this.authHttp.syncTime("/fapi/v1/time"),
|
|
4386
|
+
this.spotHttp.syncTime("/time"),
|
|
4387
|
+
this.dapiHttp.syncTime("/dapi/v1/time"),
|
|
4388
|
+
this.sapiHttp.syncTime("/api/v3/time")
|
|
4389
|
+
]);
|
|
4390
|
+
}
|
|
4391
|
+
/**
|
|
4392
|
+
* Snapshot of the most recently observed `X-MBX-USED-WEIGHT-*` / `X-MBX-ORDER-COUNT-*`
|
|
4393
|
+
* response headers, per REST host. Each host tracks its own weight budget independently.
|
|
4394
|
+
*/
|
|
4395
|
+
getRateLimitUsage() {
|
|
4396
|
+
return {
|
|
4397
|
+
spot: this.spotHttp.getRateLimitUsage(),
|
|
4398
|
+
futures: this.authHttp.getRateLimitUsage(),
|
|
4399
|
+
coinm: this.dapiHttp.getRateLimitUsage(),
|
|
4400
|
+
sapi: this.sapiHttp.getRateLimitUsage()
|
|
4401
|
+
};
|
|
4402
|
+
}
|
|
2631
4403
|
async startUserStream() {
|
|
2632
4404
|
const { listenKey } = await this.futures.userStream.createListenKey();
|
|
2633
4405
|
this.listenKeyValue = listenKey;
|
|
@@ -2664,25 +4436,50 @@ var BinanceClient = class {
|
|
|
2664
4436
|
});
|
|
2665
4437
|
this.spotListenKeyValue = null;
|
|
2666
4438
|
}
|
|
4439
|
+
async startCoinMUserStream() {
|
|
4440
|
+
const { listenKey } = await this.coinm.userStream.createListenKey();
|
|
4441
|
+
this.coinmListenKeyValue = listenKey;
|
|
4442
|
+
this.coinmKeepAliveInterval = setInterval(() => {
|
|
4443
|
+
this.coinm.userStream.keepAliveListenKey().catch(() => {
|
|
4444
|
+
});
|
|
4445
|
+
}, 30 * 60 * 1e3);
|
|
4446
|
+
this.coinm.wsUser.connect();
|
|
4447
|
+
return listenKey;
|
|
4448
|
+
}
|
|
4449
|
+
closeCoinMUserStream() {
|
|
4450
|
+
if (this.coinmKeepAliveInterval) clearInterval(this.coinmKeepAliveInterval);
|
|
4451
|
+
this.coinmKeepAliveInterval = null;
|
|
4452
|
+
this.coinm.wsUser.close();
|
|
4453
|
+
this.coinm.userStream.closeListenKey().catch(() => {
|
|
4454
|
+
});
|
|
4455
|
+
this.coinmListenKeyValue = null;
|
|
4456
|
+
}
|
|
2667
4457
|
closeAllWebSockets() {
|
|
2668
4458
|
this.futures.ws.close();
|
|
2669
4459
|
this.futures.wsUser.close();
|
|
2670
4460
|
this.spot.ws.close();
|
|
2671
4461
|
this.spot.wsUser.close();
|
|
4462
|
+
this.coinm.ws.close();
|
|
4463
|
+
this.coinm.wsUser.close();
|
|
2672
4464
|
this.closeUserStream();
|
|
2673
4465
|
this.closeSpotUserStream();
|
|
4466
|
+
this.closeCoinMUserStream();
|
|
2674
4467
|
}
|
|
2675
4468
|
reconnectWebSocket(target) {
|
|
2676
4469
|
if (target === "ws") this.futures.ws.reconnect();
|
|
2677
4470
|
else if (target === "wsUser") this.futures.wsUser.reconnect();
|
|
2678
4471
|
else if (target === "spot") this.spot.ws.reconnect();
|
|
2679
|
-
else this.spot.wsUser.reconnect();
|
|
4472
|
+
else if (target === "spotUser") this.spot.wsUser.reconnect();
|
|
4473
|
+
else if (target === "coinm") this.coinm.ws.reconnect();
|
|
4474
|
+
else this.coinm.wsUser.reconnect();
|
|
2680
4475
|
}
|
|
2681
4476
|
resetReconnectAttempts() {
|
|
2682
4477
|
this.futures.ws.resetReconnectAttempts();
|
|
2683
4478
|
this.futures.wsUser.resetReconnectAttempts();
|
|
2684
4479
|
this.spot.ws.resetReconnectAttempts();
|
|
2685
4480
|
this.spot.wsUser.resetReconnectAttempts();
|
|
4481
|
+
this.coinm.ws.resetReconnectAttempts();
|
|
4482
|
+
this.coinm.wsUser.resetReconnectAttempts();
|
|
2686
4483
|
}
|
|
2687
4484
|
};
|
|
2688
4485
|
|
|
@@ -2690,10 +4487,10 @@ var BinanceClient = class {
|
|
|
2690
4487
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
2691
4488
|
|
|
2692
4489
|
// src/tools/account.tools.ts
|
|
2693
|
-
var
|
|
4490
|
+
var import_zod13 = require("zod");
|
|
2694
4491
|
|
|
2695
4492
|
// src/tools/types.ts
|
|
2696
|
-
var
|
|
4493
|
+
var import_zod12 = require("zod");
|
|
2697
4494
|
function normalizeSymbol(value) {
|
|
2698
4495
|
return String(value ?? "").trim().toUpperCase();
|
|
2699
4496
|
}
|
|
@@ -2702,248 +4499,248 @@ function textResult(data) {
|
|
|
2702
4499
|
}
|
|
2703
4500
|
|
|
2704
4501
|
// src/tools/account.tools.ts
|
|
2705
|
-
var optionalSymbol =
|
|
2706
|
-
var limit =
|
|
2707
|
-
var startTime =
|
|
2708
|
-
var endTime =
|
|
4502
|
+
var optionalSymbol = import_zod13.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional();
|
|
4503
|
+
var limit = import_zod13.z.number().int().positive().max(1e3).default(100);
|
|
4504
|
+
var startTime = import_zod13.z.number().int().positive().optional();
|
|
4505
|
+
var endTime = import_zod13.z.number().int().positive().optional();
|
|
2709
4506
|
function accountTools(client) {
|
|
2710
4507
|
const a = client.futures.account;
|
|
2711
4508
|
return [
|
|
2712
4509
|
{
|
|
2713
4510
|
name: "futures_balance",
|
|
2714
4511
|
description: "Get futures account balances (v3): asset, wallet balance, unrealized profit, margin balance, available balance (signed).",
|
|
2715
|
-
inputSchema:
|
|
4512
|
+
inputSchema: import_zod13.z.object({}),
|
|
2716
4513
|
handler: async () => textResult(await a.balanceV3())
|
|
2717
4514
|
},
|
|
2718
4515
|
{
|
|
2719
4516
|
name: "futures_account",
|
|
2720
4517
|
description: "Get full account information (v3): total wallet/margin balance, unrealized profit, available balance, assets & positions (signed).",
|
|
2721
|
-
inputSchema:
|
|
4518
|
+
inputSchema: import_zod13.z.object({}),
|
|
2722
4519
|
handler: async () => textResult(await a.accountV3())
|
|
2723
4520
|
},
|
|
2724
4521
|
{
|
|
2725
4522
|
name: "futures_balance_v2",
|
|
2726
4523
|
description: "Get futures account balance (v2 legacy) per asset (signed).",
|
|
2727
|
-
inputSchema:
|
|
4524
|
+
inputSchema: import_zod13.z.object({}),
|
|
2728
4525
|
handler: async () => textResult(await a.balance())
|
|
2729
4526
|
},
|
|
2730
4527
|
{
|
|
2731
4528
|
name: "futures_account_v2",
|
|
2732
4529
|
description: "Get futures account information (v2 legacy) (signed).",
|
|
2733
|
-
inputSchema:
|
|
4530
|
+
inputSchema: import_zod13.z.object({}),
|
|
2734
4531
|
handler: async () => textResult(await a.account())
|
|
2735
4532
|
},
|
|
2736
4533
|
{
|
|
2737
4534
|
name: "futures_position_risk",
|
|
2738
4535
|
description: "Get current open positions (v3): symbol, side, size, entry price, mark price, liquidation price, leverage, unrealized PnL, margin (signed).",
|
|
2739
|
-
inputSchema:
|
|
4536
|
+
inputSchema: import_zod13.z.object({ symbol: optionalSymbol }),
|
|
2740
4537
|
handler: async ({ symbol: symbol3 }) => textResult(await a.positionRiskV3(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
2741
4538
|
},
|
|
2742
4539
|
{
|
|
2743
4540
|
name: "futures_income_history",
|
|
2744
4541
|
description: "Get futures income history (realized PnL, funding fees, commissions, transfers, insurance clearing). incomeType examples: TRANSFER, REALIZED_PNL, FUNDING_FEE, COMMISSION, INSURANCE_CLEAR, REFERRAL_KICKBACK (signed).",
|
|
2745
|
-
inputSchema:
|
|
4542
|
+
inputSchema: import_zod13.z.object({ symbol: optionalSymbol, incomeType: import_zod13.z.string().optional().describe("e.g. TRANSFER, REALIZED_PNL, FUNDING_FEE, COMMISSION"), startTime, endTime, limit: limit.default(100) }),
|
|
2746
4543
|
handler: async ({ symbol: symbol3, incomeType, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await a.incomeHistory({ symbol: symbol3 ? normalizeSymbol(symbol3) : void 0, incomeType, startTime: startTime5, endTime: endTime5, limit: Number(limit4) }))
|
|
2747
4544
|
},
|
|
2748
4545
|
{
|
|
2749
4546
|
name: "futures_user_trades",
|
|
2750
4547
|
description: "Get account trade list (filled trades) for a symbol with optional time range (signed).",
|
|
2751
|
-
inputSchema:
|
|
4548
|
+
inputSchema: import_zod13.z.object({ symbol: import_zod13.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), startTime, endTime, limit: limit.default(100), fromId: import_zod13.z.number().int().positive().optional() }),
|
|
2752
4549
|
handler: async ({ symbol: symbol3, startTime: startTime5, endTime: endTime5, limit: limit4, fromId }) => textResult(await a.userTrades({ symbol: normalizeSymbol(symbol3), startTime: startTime5, endTime: endTime5, limit: Number(limit4), fromId }))
|
|
2753
4550
|
},
|
|
2754
4551
|
{
|
|
2755
4552
|
name: "futures_leverage_brackets",
|
|
2756
4553
|
description: "Get notional and leverage brackets for one symbol or all: tier caps, maintenance margin rate, max leverage (signed).",
|
|
2757
|
-
inputSchema:
|
|
4554
|
+
inputSchema: import_zod13.z.object({ symbol: optionalSymbol }),
|
|
2758
4555
|
handler: async ({ symbol: symbol3 }) => textResult(await a.leverageBrackets(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
2759
4556
|
},
|
|
2760
4557
|
{
|
|
2761
4558
|
name: "futures_commission_rate",
|
|
2762
4559
|
description: "Get user commission rate (taker & maker fee) for a symbol (signed).",
|
|
2763
|
-
inputSchema:
|
|
4560
|
+
inputSchema: import_zod13.z.object({ symbol: import_zod13.z.string().min(1).describe("USD-M pair, e.g. ETHUSDT") }),
|
|
2764
4561
|
handler: async ({ symbol: symbol3 }) => textResult(await a.commissionRate(normalizeSymbol(symbol3)))
|
|
2765
4562
|
},
|
|
2766
4563
|
{
|
|
2767
4564
|
name: "futures_multi_assets_mode",
|
|
2768
4565
|
description: "Get current multi-assets margin mode status (signed).",
|
|
2769
|
-
inputSchema:
|
|
4566
|
+
inputSchema: import_zod13.z.object({}),
|
|
2770
4567
|
handler: async () => textResult(await a.multiAssetsMargin())
|
|
2771
4568
|
},
|
|
2772
4569
|
{
|
|
2773
4570
|
name: "futures_set_multi_assets_mode",
|
|
2774
4571
|
description: "Enable or disable multi-assets mode (signed; 7-day cooldown between toggles).",
|
|
2775
|
-
inputSchema:
|
|
4572
|
+
inputSchema: import_zod13.z.object({ enabled: import_zod13.z.boolean().describe("true to enable, false to disable") }),
|
|
2776
4573
|
handler: async ({ enabled }) => textResult(await a.setMultiAssetsMargin(enabled))
|
|
2777
4574
|
},
|
|
2778
4575
|
{
|
|
2779
4576
|
name: "futures_fee_burn_status",
|
|
2780
4577
|
description: "Get BNB fee burn status for futures trades (signed).",
|
|
2781
|
-
inputSchema:
|
|
4578
|
+
inputSchema: import_zod13.z.object({}),
|
|
2782
4579
|
handler: async () => textResult(await a.feeBurnStatus())
|
|
2783
4580
|
},
|
|
2784
4581
|
{
|
|
2785
4582
|
name: "futures_set_fee_burn",
|
|
2786
4583
|
description: "Toggle BNB fee burn on futures trades (signed).",
|
|
2787
|
-
inputSchema:
|
|
4584
|
+
inputSchema: import_zod13.z.object({ enabled: import_zod13.z.boolean().describe("true to enable fee burn") }),
|
|
2788
4585
|
handler: async ({ enabled }) => textResult(await a.setFeeBurnStatus(enabled))
|
|
2789
4586
|
},
|
|
2790
4587
|
{
|
|
2791
4588
|
name: "futures_position_mode",
|
|
2792
4589
|
description: "Get current position mode: one-way (BOTH) or hedge mode (LONG/SHORT) (signed).",
|
|
2793
|
-
inputSchema:
|
|
4590
|
+
inputSchema: import_zod13.z.object({}),
|
|
2794
4591
|
handler: async () => textResult(await a.positionMode())
|
|
2795
4592
|
},
|
|
2796
4593
|
{
|
|
2797
4594
|
name: "futures_set_position_mode",
|
|
2798
4595
|
description: "Change position mode: hedgeMode true = dual side (hedge), false = one-way (signed; 30-day cooldown).",
|
|
2799
|
-
inputSchema:
|
|
4596
|
+
inputSchema: import_zod13.z.object({ hedgeMode: import_zod13.z.boolean().describe("true = hedge mode, false = one-way") }),
|
|
2800
4597
|
handler: async ({ hedgeMode }) => textResult(await a.setPositionMode(hedgeMode))
|
|
2801
4598
|
},
|
|
2802
4599
|
{
|
|
2803
4600
|
name: "futures_api_trading_status",
|
|
2804
4601
|
description: "Get futures trading quantitative rules indicators and disable intervals (signed).",
|
|
2805
|
-
inputSchema:
|
|
4602
|
+
inputSchema: import_zod13.z.object({}),
|
|
2806
4603
|
handler: async () => textResult(await a.apiTradingStatus())
|
|
2807
4604
|
},
|
|
2808
4605
|
{
|
|
2809
4606
|
name: "futures_position_margin_history",
|
|
2810
4607
|
description: "Get isolated position margin change history. type: 1 = add margin, 2 = reduce margin (signed).",
|
|
2811
|
-
inputSchema:
|
|
4608
|
+
inputSchema: import_zod13.z.object({ symbol: import_zod13.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), type: import_zod13.z.enum(["1", "2"]).describe("1 = add margin, 2 = reduce margin"), startTime, endTime, limit: limit.default(50) }),
|
|
2812
4609
|
handler: async ({ symbol: symbol3, type, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await a.positionMarginHistory({ symbol: normalizeSymbol(symbol3), type: Number(type), startTime: startTime5, endTime: endTime5, limit: Number(limit4) }))
|
|
2813
4610
|
},
|
|
2814
4611
|
{
|
|
2815
4612
|
name: "futures_rate_limit_order",
|
|
2816
4613
|
description: "Query the current user order rate limit usage (signed).",
|
|
2817
|
-
inputSchema:
|
|
4614
|
+
inputSchema: import_zod13.z.object({}),
|
|
2818
4615
|
handler: async () => textResult(await a.rateLimitOrder())
|
|
2819
4616
|
},
|
|
2820
4617
|
{
|
|
2821
4618
|
name: "futures_request_order_download",
|
|
2822
4619
|
description: "Request a futures order-history download (async, 7-day window). Returns a downloadId (signed).",
|
|
2823
|
-
inputSchema:
|
|
4620
|
+
inputSchema: import_zod13.z.object({ symbol: optionalSymbol, startTime, endTime }),
|
|
2824
4621
|
handler: async ({ symbol: symbol3, startTime: startTime5, endTime: endTime5 }) => textResult(await a.requestOrderDownload({ symbol: symbol3 ? normalizeSymbol(symbol3) : void 0, startTime: startTime5, endTime: endTime5 }))
|
|
2825
4622
|
},
|
|
2826
4623
|
{
|
|
2827
4624
|
name: "futures_order_download_status",
|
|
2828
4625
|
description: "Get the futures order-history download link by downloadId (signed).",
|
|
2829
|
-
inputSchema:
|
|
4626
|
+
inputSchema: import_zod13.z.object({ downloadId: import_zod13.z.string().min(1) }),
|
|
2830
4627
|
handler: async ({ downloadId }) => textResult(await a.getOrderDownloadStatus(downloadId))
|
|
2831
4628
|
},
|
|
2832
4629
|
{
|
|
2833
4630
|
name: "futures_request_trade_download",
|
|
2834
4631
|
description: "Request a futures trade-history download (async, 7-day window). Returns a downloadId (signed).",
|
|
2835
|
-
inputSchema:
|
|
4632
|
+
inputSchema: import_zod13.z.object({ symbol: optionalSymbol, startTime, endTime }),
|
|
2836
4633
|
handler: async ({ symbol: symbol3, startTime: startTime5, endTime: endTime5 }) => textResult(await a.requestTradeDownload({ symbol: symbol3 ? normalizeSymbol(symbol3) : void 0, startTime: startTime5, endTime: endTime5 }))
|
|
2837
4634
|
},
|
|
2838
4635
|
{
|
|
2839
4636
|
name: "futures_trade_download_status",
|
|
2840
4637
|
description: "Get the futures trade-history download link by downloadId (signed).",
|
|
2841
|
-
inputSchema:
|
|
4638
|
+
inputSchema: import_zod13.z.object({ downloadId: import_zod13.z.string().min(1) }),
|
|
2842
4639
|
handler: async ({ downloadId }) => textResult(await a.getTradeDownloadStatus(downloadId))
|
|
2843
4640
|
},
|
|
2844
4641
|
{
|
|
2845
4642
|
name: "futures_account_config",
|
|
2846
4643
|
description: "Get futures account configuration: fee tier, trading permissions, dual-side position setting (signed).",
|
|
2847
|
-
inputSchema:
|
|
4644
|
+
inputSchema: import_zod13.z.object({}),
|
|
2848
4645
|
handler: async () => textResult(await a.accountConfig())
|
|
2849
4646
|
},
|
|
2850
4647
|
{
|
|
2851
4648
|
name: "futures_portfolio_margin_account_info",
|
|
2852
4649
|
description: "Get Portfolio Margin account info for an asset: cross margin balance and liability (signed).",
|
|
2853
|
-
inputSchema:
|
|
4650
|
+
inputSchema: import_zod13.z.object({ asset: import_zod13.z.string().min(1).describe("Asset, e.g. USDT") }),
|
|
2854
4651
|
handler: async ({ asset }) => textResult(await a.pmAccountInfo(asset))
|
|
2855
4652
|
},
|
|
2856
4653
|
{
|
|
2857
4654
|
name: "futures_request_income_download",
|
|
2858
4655
|
description: "Request a futures income/transaction-history download (async). Returns a downloadId (signed).",
|
|
2859
|
-
inputSchema:
|
|
4656
|
+
inputSchema: import_zod13.z.object({ startTime: startTime.unwrap(), endTime: endTime.unwrap() }),
|
|
2860
4657
|
handler: async ({ startTime: startTime5, endTime: endTime5 }) => textResult(await a.requestIncomeDownload({ startTime: startTime5, endTime: endTime5 }))
|
|
2861
4658
|
},
|
|
2862
4659
|
{
|
|
2863
4660
|
name: "futures_income_download_status",
|
|
2864
4661
|
description: "Get the futures income/transaction-history download link by downloadId (signed).",
|
|
2865
|
-
inputSchema:
|
|
4662
|
+
inputSchema: import_zod13.z.object({ downloadId: import_zod13.z.string().min(1) }),
|
|
2866
4663
|
handler: async ({ downloadId }) => textResult(await a.getIncomeDownloadStatus(downloadId))
|
|
2867
4664
|
}
|
|
2868
4665
|
];
|
|
2869
4666
|
}
|
|
2870
4667
|
|
|
2871
4668
|
// src/tools/derived.tools.ts
|
|
2872
|
-
var
|
|
2873
|
-
var symbol =
|
|
4669
|
+
var import_zod14 = require("zod");
|
|
4670
|
+
var symbol = import_zod14.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT");
|
|
2874
4671
|
function derivedTools(client) {
|
|
2875
4672
|
const ops = client.futures.ops;
|
|
2876
4673
|
return [
|
|
2877
4674
|
{
|
|
2878
4675
|
name: "futures_symbol_rules",
|
|
2879
4676
|
description: "Get the tradeable rules for a symbol in one call: tick size, step size, min/max quantity, market-order lot bounds and minimum notional, flattened out of exchangeInfo filters. Call this before sizing or pricing any order.",
|
|
2880
|
-
inputSchema:
|
|
4677
|
+
inputSchema: import_zod14.z.object({ symbol, refresh: import_zod14.z.boolean().default(false).describe("Bypass the 60s cache") }),
|
|
2881
4678
|
handler: async ({ symbol: s, refresh }) => textResult(await ops.symbolRules(normalizeSymbol(s), { refresh }))
|
|
2882
4679
|
},
|
|
2883
4680
|
{
|
|
2884
4681
|
name: "futures_quantize",
|
|
2885
4682
|
description: "Round a price to the symbol's tick size and a quantity to its step size, returning exchange-ready strings. Use this instead of rounding numbers yourself \u2014 Binance rejects off-tick prices (-1111).",
|
|
2886
|
-
inputSchema:
|
|
4683
|
+
inputSchema: import_zod14.z.object({
|
|
2887
4684
|
symbol,
|
|
2888
|
-
price:
|
|
2889
|
-
quantity:
|
|
2890
|
-
marketOrder:
|
|
4685
|
+
price: import_zod14.z.number().positive().optional(),
|
|
4686
|
+
quantity: import_zod14.z.number().positive().optional(),
|
|
4687
|
+
marketOrder: import_zod14.z.boolean().default(false).describe("Use MARKET_LOT_SIZE bounds instead of LOT_SIZE")
|
|
2891
4688
|
}),
|
|
2892
4689
|
handler: async ({ symbol: s, price, quantity, marketOrder }) => textResult(await ops.quantize(normalizeSymbol(s), { price, quantity, marketOrder }))
|
|
2893
4690
|
},
|
|
2894
4691
|
{
|
|
2895
4692
|
name: "futures_size_position",
|
|
2896
4693
|
description: "Convert a risk budget into an exchange-ready order quantity. Given a stop price and either riskAmount (quote currency) or riskPct (percent of available balance), returns the quantity rounded down to the symbol step size, plus the notional, required margin and every constraint that failed (min notional, lot bounds, wrong-side stop). Never increases risk to satisfy a minimum \u2014 it reports instead.",
|
|
2897
|
-
inputSchema:
|
|
4694
|
+
inputSchema: import_zod14.z.object({
|
|
2898
4695
|
symbol,
|
|
2899
|
-
side:
|
|
2900
|
-
stopPrice:
|
|
2901
|
-
entryPrice:
|
|
2902
|
-
riskAmount:
|
|
2903
|
-
riskPct:
|
|
2904
|
-
leverage:
|
|
2905
|
-
marketOrder:
|
|
4696
|
+
side: import_zod14.z.enum(["BUY", "SELL"]),
|
|
4697
|
+
stopPrice: import_zod14.z.number().positive().describe("Protective stop price"),
|
|
4698
|
+
entryPrice: import_zod14.z.number().positive().optional().describe("Defaults to current mark price"),
|
|
4699
|
+
riskAmount: import_zod14.z.number().positive().optional().describe("Quote-currency amount to risk, e.g. 50 USDT"),
|
|
4700
|
+
riskPct: import_zod14.z.number().positive().max(100).optional().describe("Percent of available balance to risk (signed call)"),
|
|
4701
|
+
leverage: import_zod14.z.number().int().min(1).max(125).optional().describe("Used to report required margin"),
|
|
4702
|
+
marketOrder: import_zod14.z.boolean().default(false)
|
|
2906
4703
|
}),
|
|
2907
4704
|
handler: async (args) => textResult(await ops.sizePosition({ ...args, symbol: normalizeSymbol(args.symbol) }))
|
|
2908
4705
|
},
|
|
2909
4706
|
{
|
|
2910
4707
|
name: "futures_close_position",
|
|
2911
4708
|
description: "Flatten an open position with a reduce-only market order. Reads the current position, derives the closing side from its sign, and automatically uses reduceOnly in one-way mode vs positionSide in hedge mode (Binance rejects the wrong one). Set dryRun to preview the order without sending it. Signed, destructive.",
|
|
2912
|
-
inputSchema:
|
|
4709
|
+
inputSchema: import_zod14.z.object({
|
|
2913
4710
|
symbol,
|
|
2914
|
-
positionSide:
|
|
2915
|
-
portion:
|
|
2916
|
-
dryRun:
|
|
4711
|
+
positionSide: import_zod14.z.enum(["BOTH", "LONG", "SHORT"]).optional().describe("Required when hedge mode has both sides open"),
|
|
4712
|
+
portion: import_zod14.z.number().positive().max(1).default(1).describe("Fraction of the position to close, e.g. 0.5 for half"),
|
|
4713
|
+
dryRun: import_zod14.z.boolean().default(false)
|
|
2917
4714
|
}),
|
|
2918
4715
|
handler: async (args) => textResult(await ops.closePosition({ ...args, symbol: normalizeSymbol(args.symbol) }))
|
|
2919
4716
|
},
|
|
2920
4717
|
{
|
|
2921
4718
|
name: "futures_market_snapshot",
|
|
2922
4719
|
description: "One-call market picture for a symbol: 24h stats, mark/index price with funding, open interest and long/short positioning. Replaces four separate primitive calls; individual feeds degrade to an error field rather than failing the whole snapshot.",
|
|
2923
|
-
inputSchema:
|
|
4720
|
+
inputSchema: import_zod14.z.object({
|
|
2924
4721
|
symbol,
|
|
2925
|
-
period:
|
|
4722
|
+
period: import_zod14.z.enum(["5m", "15m", "30m", "1h", "2h", "4h", "6h", "12h", "1d"]).default("1h")
|
|
2926
4723
|
}),
|
|
2927
4724
|
handler: async ({ symbol: s, period: period2 }) => textResult(await ops.marketSnapshot(normalizeSymbol(s), { period: period2 }))
|
|
2928
4725
|
},
|
|
2929
4726
|
{
|
|
2930
4727
|
name: "futures_account_overview",
|
|
2931
4728
|
description: "One-call account picture: funded balances, open positions only (zero-size entries filtered out), working orders, and totals for unrealized PnL and gross notional. Signed.",
|
|
2932
|
-
inputSchema:
|
|
4729
|
+
inputSchema: import_zod14.z.object({}),
|
|
2933
4730
|
handler: async () => textResult(await ops.accountOverview())
|
|
2934
4731
|
},
|
|
2935
4732
|
{
|
|
2936
4733
|
name: "futures_place_bracket_order",
|
|
2937
4734
|
description: "Place an entry order together with its protective stop-loss and optional take-profit, with all prices quantized to the symbol tick. Returns each leg separately; if a protective leg fails the response is flagged protectionComplete=false and the entry is NOT auto-cancelled (it may already have filled). Signed, destructive.",
|
|
2938
|
-
inputSchema:
|
|
4735
|
+
inputSchema: import_zod14.z.object({
|
|
2939
4736
|
symbol,
|
|
2940
|
-
side:
|
|
2941
|
-
quantity:
|
|
2942
|
-
entryPrice:
|
|
2943
|
-
stopLossPrice:
|
|
2944
|
-
takeProfitPrice:
|
|
2945
|
-
positionSide:
|
|
2946
|
-
workingType:
|
|
4737
|
+
side: import_zod14.z.enum(["BUY", "SELL"]),
|
|
4738
|
+
quantity: import_zod14.z.union([import_zod14.z.string(), import_zod14.z.number()]),
|
|
4739
|
+
entryPrice: import_zod14.z.number().positive().optional().describe("Omit for a MARKET entry"),
|
|
4740
|
+
stopLossPrice: import_zod14.z.number().positive(),
|
|
4741
|
+
takeProfitPrice: import_zod14.z.number().positive().optional(),
|
|
4742
|
+
positionSide: import_zod14.z.enum(["BOTH", "LONG", "SHORT"]).optional(),
|
|
4743
|
+
workingType: import_zod14.z.enum(["MARK_PRICE", "CONTRACT_PRICE"]).default("MARK_PRICE")
|
|
2947
4744
|
}),
|
|
2948
4745
|
handler: async (args) => textResult(await ops.placeBracketOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
|
|
2949
4746
|
}
|
|
@@ -2951,14 +4748,14 @@ function derivedTools(client) {
|
|
|
2951
4748
|
}
|
|
2952
4749
|
|
|
2953
4750
|
// src/tools/market-data.tools.ts
|
|
2954
|
-
var
|
|
4751
|
+
var import_zod15 = require("zod");
|
|
2955
4752
|
var u = (s) => s.optional();
|
|
2956
|
-
var optSymbol = u(
|
|
2957
|
-
var limitDefault =
|
|
2958
|
-
var startTime2 =
|
|
2959
|
-
var endTime2 =
|
|
2960
|
-
var period =
|
|
2961
|
-
var contractType =
|
|
4753
|
+
var optSymbol = u(import_zod15.z.string().min(1)).describe("USD-M pair, e.g. BTCUSDT");
|
|
4754
|
+
var limitDefault = import_zod15.z.number().int().positive().max(1500).default(100);
|
|
4755
|
+
var startTime2 = import_zod15.z.number().int().positive().optional();
|
|
4756
|
+
var endTime2 = import_zod15.z.number().int().positive().optional();
|
|
4757
|
+
var period = import_zod15.z.enum(["5m", "15m", "30m", "1h", "2h", "4h", "6h", "12h", "1d"]).default("1h");
|
|
4758
|
+
var contractType = import_zod15.z.enum(["perpetual", "current_quarter", "next_quarter"]).default("perpetual");
|
|
2962
4759
|
function marketDataTools(client) {
|
|
2963
4760
|
const m = client.futures.market;
|
|
2964
4761
|
const d = client.futures.data;
|
|
@@ -2966,65 +4763,65 @@ function marketDataTools(client) {
|
|
|
2966
4763
|
{
|
|
2967
4764
|
name: "futures_ping",
|
|
2968
4765
|
description: "Test connectivity to the Binance USD-M futures REST API. Returns empty object {} on success.",
|
|
2969
|
-
inputSchema:
|
|
4766
|
+
inputSchema: import_zod15.z.object({}),
|
|
2970
4767
|
handler: async () => textResult(await m.ping())
|
|
2971
4768
|
},
|
|
2972
4769
|
{
|
|
2973
4770
|
name: "futures_server_time",
|
|
2974
4771
|
description: "Get the current Binance USD-M futures server time in milliseconds since epoch.",
|
|
2975
|
-
inputSchema:
|
|
4772
|
+
inputSchema: import_zod15.z.object({}),
|
|
2976
4773
|
handler: async () => textResult(await m.serverTime())
|
|
2977
4774
|
},
|
|
2978
4775
|
{
|
|
2979
4776
|
name: "futures_exchange_info",
|
|
2980
4777
|
description: "Get exchange trading rules and symbol metadata: contract type, status, base/quote assets, price/quantity filters, tick size, step size, notional and leverage brackets, delivery dates.",
|
|
2981
|
-
inputSchema:
|
|
4778
|
+
inputSchema: import_zod15.z.object({}),
|
|
2982
4779
|
handler: async () => textResult(await m.exchangeInfo())
|
|
2983
4780
|
},
|
|
2984
4781
|
{
|
|
2985
4782
|
name: "futures_ticker_price",
|
|
2986
4783
|
description: "Get latest price for one symbol (v1).",
|
|
2987
|
-
inputSchema:
|
|
4784
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
|
|
2988
4785
|
handler: async ({ symbol: symbol3 }) => textResult(await m.tickerPrice(normalizeSymbol(symbol3)))
|
|
2989
4786
|
},
|
|
2990
4787
|
{
|
|
2991
4788
|
name: "futures_ticker_price_v2",
|
|
2992
4789
|
description: "Get latest price for one symbol, or for all symbols when symbol is omitted (v2 endpoint). Use all-symbols mode for market overviews.",
|
|
2993
|
-
inputSchema:
|
|
4790
|
+
inputSchema: import_zod15.z.object({ symbol: optSymbol }),
|
|
2994
4791
|
handler: async ({ symbol: symbol3 }) => textResult(await m.tickerPriceV2(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
2995
4792
|
},
|
|
2996
4793
|
{
|
|
2997
4794
|
name: "futures_ticker_24hr",
|
|
2998
4795
|
description: "Get 24-hour rolling price change statistics for a symbol: price change %, high, low, volume, quote volume, open interest.",
|
|
2999
|
-
inputSchema:
|
|
4796
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
|
|
3000
4797
|
handler: async ({ symbol: symbol3 }) => textResult(await m.ticker24hr(normalizeSymbol(symbol3)))
|
|
3001
4798
|
},
|
|
3002
4799
|
{
|
|
3003
4800
|
name: "futures_book_ticker",
|
|
3004
4801
|
description: "Get best bid/ask (top of book) for a single symbol (v1).",
|
|
3005
|
-
inputSchema:
|
|
4802
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
|
|
3006
4803
|
handler: async ({ symbol: symbol3 }) => textResult(await m.bookTicker(normalizeSymbol(symbol3)))
|
|
3007
4804
|
},
|
|
3008
4805
|
{
|
|
3009
4806
|
name: "futures_book_ticker_v2",
|
|
3010
4807
|
description: "Get best bid/ask (top of book) for one symbol, or all symbols when omitted (v2 endpoint).",
|
|
3011
|
-
inputSchema:
|
|
4808
|
+
inputSchema: import_zod15.z.object({ symbol: optSymbol }),
|
|
3012
4809
|
handler: async ({ symbol: symbol3 }) => textResult(await m.bookTickerV2(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
3013
4810
|
},
|
|
3014
4811
|
{
|
|
3015
4812
|
name: "futures_order_book",
|
|
3016
4813
|
description: "Get order book depth for a symbol. Limits: 5, 10, 20, 50, 100, 500, 1000.",
|
|
3017
|
-
inputSchema:
|
|
3018
|
-
symbol:
|
|
3019
|
-
limit:
|
|
4814
|
+
inputSchema: import_zod15.z.object({
|
|
4815
|
+
symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
|
|
4816
|
+
limit: import_zod15.z.enum(["5", "10", "20", "50", "100", "500", "1000"]).default("100")
|
|
3020
4817
|
}),
|
|
3021
4818
|
handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.depth(normalizeSymbol(symbol3), Number(limit4)))
|
|
3022
4819
|
},
|
|
3023
4820
|
{
|
|
3024
4821
|
name: "futures_recent_trades",
|
|
3025
4822
|
description: "Get the most recent executed trades for a symbol (public endpoint).",
|
|
3026
|
-
inputSchema:
|
|
3027
|
-
symbol:
|
|
4823
|
+
inputSchema: import_zod15.z.object({
|
|
4824
|
+
symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
|
|
3028
4825
|
limit: limitDefault.default(500)
|
|
3029
4826
|
}),
|
|
3030
4827
|
handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.trades(normalizeSymbol(symbol3), Number(limit4)))
|
|
@@ -3032,30 +4829,30 @@ function marketDataTools(client) {
|
|
|
3032
4829
|
{
|
|
3033
4830
|
name: "futures_historical_trades",
|
|
3034
4831
|
description: "Get older trades for a symbol by fromId (older than recent).",
|
|
3035
|
-
inputSchema:
|
|
3036
|
-
symbol:
|
|
4832
|
+
inputSchema: import_zod15.z.object({
|
|
4833
|
+
symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
|
|
3037
4834
|
limit: limitDefault.default(500),
|
|
3038
|
-
fromId:
|
|
4835
|
+
fromId: import_zod15.z.number().int().positive().optional()
|
|
3039
4836
|
}),
|
|
3040
4837
|
handler: async ({ symbol: symbol3, limit: limit4, fromId }) => textResult(await m.historicalTrades(normalizeSymbol(symbol3), { limit: Number(limit4), fromId }))
|
|
3041
4838
|
},
|
|
3042
4839
|
{
|
|
3043
4840
|
name: "futures_agg_trades",
|
|
3044
4841
|
description: "Get compressed/aggregate trades for a symbol within an optional time window. Each entry aggregates trades with the same price and side.",
|
|
3045
|
-
inputSchema:
|
|
4842
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
|
|
3046
4843
|
handler: async ({ symbol: symbol3, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.aggTrades(normalizeSymbol(symbol3), { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3047
4844
|
},
|
|
3048
4845
|
{
|
|
3049
4846
|
name: "futures_klines",
|
|
3050
4847
|
description: "Get candlestick (OHLCV) data for a symbol. Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M. Max 1500 per request.",
|
|
3051
|
-
inputSchema:
|
|
4848
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
|
|
3052
4849
|
handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.klines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3053
4850
|
},
|
|
3054
4851
|
{
|
|
3055
4852
|
name: "futures_continuous_klines",
|
|
3056
4853
|
description: "Get klines for a continuous contract (perpetual, current_quarter, next_quarter) identified by base pair (e.g. BTCUSDT).",
|
|
3057
|
-
inputSchema:
|
|
3058
|
-
symbol:
|
|
4854
|
+
inputSchema: import_zod15.z.object({
|
|
4855
|
+
symbol: import_zod15.z.string().min(1).describe("Base pair, e.g. BTCUSDT"),
|
|
3059
4856
|
contractType,
|
|
3060
4857
|
interval: KlineIntervalSchema,
|
|
3061
4858
|
limit: limitDefault.default(500),
|
|
@@ -3067,80 +4864,80 @@ function marketDataTools(client) {
|
|
|
3067
4864
|
{
|
|
3068
4865
|
name: "futures_index_price_klines",
|
|
3069
4866
|
description: "Get index price candlesticks for a pair (e.g. BTCUSDT index).",
|
|
3070
|
-
inputSchema:
|
|
4867
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("Base pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
|
|
3071
4868
|
handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.indexPriceKlines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3072
4869
|
},
|
|
3073
4870
|
{
|
|
3074
4871
|
name: "futures_mark_price_klines",
|
|
3075
4872
|
description: "Get mark price candlesticks for a symbol.",
|
|
3076
|
-
inputSchema:
|
|
4873
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
|
|
3077
4874
|
handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.markPriceKlines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3078
4875
|
},
|
|
3079
4876
|
{
|
|
3080
4877
|
name: "futures_trading_day_ticker",
|
|
3081
4878
|
description: "Get the trading-day ticker (v1: rolling window stats by symbol, including open, close, high, low, volume, closeTime).",
|
|
3082
|
-
inputSchema:
|
|
4879
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
|
|
3083
4880
|
handler: async ({ symbol: symbol3 }) => textResult(await m.tradingDayTicker(normalizeSymbol(symbol3)))
|
|
3084
4881
|
},
|
|
3085
4882
|
{
|
|
3086
4883
|
name: "futures_mark_price",
|
|
3087
4884
|
description: "Get mark price, index price, estimated settle price, last funding rate, next funding time and interest rate for a symbol.",
|
|
3088
|
-
inputSchema:
|
|
4885
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
|
|
3089
4886
|
handler: async ({ symbol: symbol3 }) => textResult(await d.premiumIndex(normalizeSymbol(symbol3)))
|
|
3090
4887
|
},
|
|
3091
4888
|
{
|
|
3092
4889
|
name: "futures_funding_rate_history",
|
|
3093
4890
|
description: "Get historical funding rates for a symbol.",
|
|
3094
|
-
inputSchema:
|
|
4891
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), limit: limitDefault.default(100), startTime: startTime2, endTime: endTime2 }),
|
|
3095
4892
|
handler: async ({ symbol: symbol3, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await d.fundingRateHistory(normalizeSymbol(symbol3), { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3096
4893
|
},
|
|
3097
4894
|
{
|
|
3098
4895
|
name: "futures_funding_info",
|
|
3099
4896
|
description: "Get funding rate configuration for all symbols with adjusted funding cap/floor or interval (e.g. under extreme volatility).",
|
|
3100
|
-
inputSchema:
|
|
4897
|
+
inputSchema: import_zod15.z.object({}),
|
|
3101
4898
|
handler: async () => textResult(await d.fundingInfo())
|
|
3102
4899
|
},
|
|
3103
4900
|
{
|
|
3104
4901
|
name: "futures_open_interest",
|
|
3105
4902
|
description: "Get the current total open interest for a symbol.",
|
|
3106
|
-
inputSchema:
|
|
4903
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
|
|
3107
4904
|
handler: async ({ symbol: symbol3 }) => textResult(await d.openInterest(normalizeSymbol(symbol3)))
|
|
3108
4905
|
},
|
|
3109
4906
|
{
|
|
3110
4907
|
name: "futures_open_interest_hist",
|
|
3111
4908
|
description: "Get historical open interest statistics per period.",
|
|
3112
|
-
inputSchema:
|
|
4909
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
|
|
3113
4910
|
handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.openInterestHist(normalizeSymbol(symbol3), period2, Number(limit4)))
|
|
3114
4911
|
},
|
|
3115
4912
|
{
|
|
3116
4913
|
name: "futures_top_long_short_account_ratio",
|
|
3117
4914
|
description: "Get top trader long/short account ratio (number of accounts) for a symbol.",
|
|
3118
|
-
inputSchema:
|
|
4915
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
|
|
3119
4916
|
handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.topLongShortAccountRatio(normalizeSymbol(symbol3), period2, Number(limit4)))
|
|
3120
4917
|
},
|
|
3121
4918
|
{
|
|
3122
4919
|
name: "futures_top_long_short_position_ratio",
|
|
3123
4920
|
description: "Get top trader long/short position ratio (accounts with net positions) for a symbol.",
|
|
3124
|
-
inputSchema:
|
|
4921
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
|
|
3125
4922
|
handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.topLongShortPositionRatio(normalizeSymbol(symbol3), period2, Number(limit4)))
|
|
3126
4923
|
},
|
|
3127
4924
|
{
|
|
3128
4925
|
name: "futures_global_long_short_ratio",
|
|
3129
4926
|
description: "Get global long/short account ratio for a symbol (all accounts).",
|
|
3130
|
-
inputSchema:
|
|
4927
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
|
|
3131
4928
|
handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.globalLongShortAccountRatio(normalizeSymbol(symbol3), period2, Number(limit4)))
|
|
3132
4929
|
},
|
|
3133
4930
|
{
|
|
3134
4931
|
name: "futures_taker_long_short_ratio",
|
|
3135
4932
|
description: "Get taker buy/sell volume ratio for a symbol.",
|
|
3136
|
-
inputSchema:
|
|
4933
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), period, limit: limitDefault.default(30) }),
|
|
3137
4934
|
handler: async ({ symbol: symbol3, period: period2, limit: limit4 }) => textResult(await d.takerLongShortRatio(normalizeSymbol(symbol3), period2, Number(limit4)))
|
|
3138
4935
|
},
|
|
3139
4936
|
{
|
|
3140
4937
|
name: "futures_basis",
|
|
3141
4938
|
description: "Get basis data (spot-futures spread, mark price - index price) for a pair and contract type.",
|
|
3142
|
-
inputSchema:
|
|
3143
|
-
symbol:
|
|
4939
|
+
inputSchema: import_zod15.z.object({
|
|
4940
|
+
symbol: import_zod15.z.string().min(1).describe("Base pair, e.g. BTCUSDT"),
|
|
3144
4941
|
period,
|
|
3145
4942
|
limit: limitDefault.default(30),
|
|
3146
4943
|
startTime: startTime2,
|
|
@@ -3151,63 +4948,63 @@ function marketDataTools(client) {
|
|
|
3151
4948
|
{
|
|
3152
4949
|
name: "futures_asset_index",
|
|
3153
4950
|
description: "Get multi-assets mode asset index (collateral price) for one asset or all assets.",
|
|
3154
|
-
inputSchema:
|
|
4951
|
+
inputSchema: import_zod15.z.object({ symbol: optSymbol.describe("Asset index symbol, e.g. ADAUSD") }),
|
|
3155
4952
|
handler: async ({ symbol: symbol3 }) => textResult(await d.assetIndex(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
3156
4953
|
},
|
|
3157
4954
|
{
|
|
3158
4955
|
name: "futures_composite_index_info",
|
|
3159
4956
|
description: "Get composite index symbol information (e.g. DEFIUSDT) with constituent weights.",
|
|
3160
|
-
inputSchema:
|
|
4957
|
+
inputSchema: import_zod15.z.object({ symbol: optSymbol }),
|
|
3161
4958
|
handler: async ({ symbol: symbol3 }) => textResult(await d.compositeIndexInfo(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
3162
4959
|
},
|
|
3163
4960
|
{
|
|
3164
4961
|
name: "futures_insurance_balance",
|
|
3165
4962
|
description: "Get insurance fund balance snapshots for a symbol.",
|
|
3166
|
-
inputSchema:
|
|
4963
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BNBUSDT"), limit: limitDefault.default(100), startTime: startTime2, endTime: endTime2 }),
|
|
3167
4964
|
handler: async ({ symbol: symbol3, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await d.insuranceFundBalance({ symbol: normalizeSymbol(symbol3), limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3168
4965
|
},
|
|
3169
4966
|
{
|
|
3170
4967
|
name: "futures_index_price_constituents",
|
|
3171
4968
|
description: "Get the index price constituents (exchange weights) for a symbol.",
|
|
3172
|
-
inputSchema:
|
|
4969
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT") }),
|
|
3173
4970
|
handler: async ({ symbol: symbol3 }) => textResult(await d.indexPriceConstituents(normalizeSymbol(symbol3)))
|
|
3174
4971
|
},
|
|
3175
4972
|
{
|
|
3176
4973
|
name: "futures_premium_index_klines",
|
|
3177
4974
|
description: "Get premium index candlesticks for a symbol (mark price premium over index price).",
|
|
3178
|
-
inputSchema:
|
|
4975
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), interval: KlineIntervalSchema, limit: limitDefault.default(500), startTime: startTime2, endTime: endTime2 }),
|
|
3179
4976
|
handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.premiumIndexKlines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3180
4977
|
},
|
|
3181
4978
|
{
|
|
3182
4979
|
name: "futures_rpi_depth",
|
|
3183
4980
|
description: "Get the RPI (Retail Price Improvement) order book depth for a symbol.",
|
|
3184
|
-
inputSchema:
|
|
4981
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"), limit: import_zod15.z.number().int().positive().default(1e3) }),
|
|
3185
4982
|
handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.rpiDepth(normalizeSymbol(symbol3), Number(limit4)))
|
|
3186
4983
|
},
|
|
3187
4984
|
{
|
|
3188
4985
|
name: "futures_delivery_price",
|
|
3189
4986
|
description: "Get historical quarterly contract settlement/delivery prices for a pair.",
|
|
3190
|
-
inputSchema:
|
|
4987
|
+
inputSchema: import_zod15.z.object({ symbol: import_zod15.z.string().min(1).describe("Base pair, e.g. BTCUSDT") }),
|
|
3191
4988
|
handler: async ({ symbol: symbol3 }) => textResult(await d.deliveryPrice(normalizeSymbol(symbol3)))
|
|
3192
4989
|
},
|
|
3193
4990
|
{
|
|
3194
4991
|
name: "futures_symbol_adl_risk",
|
|
3195
4992
|
description: "Get the auto-deleveraging (ADL) risk level for one symbol or all symbols on the account (signed).",
|
|
3196
|
-
inputSchema:
|
|
4993
|
+
inputSchema: import_zod15.z.object({ symbol: optSymbol }),
|
|
3197
4994
|
handler: async ({ symbol: symbol3 }) => textResult(await d.symbolAdlRisk(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
3198
4995
|
},
|
|
3199
4996
|
{
|
|
3200
4997
|
name: "futures_adl_quantile",
|
|
3201
4998
|
description: "Get the position ADL (auto-deleveraging) quantile estimation for one symbol or all symbols (signed).",
|
|
3202
|
-
inputSchema:
|
|
4999
|
+
inputSchema: import_zod15.z.object({ symbol: optSymbol }),
|
|
3203
5000
|
handler: async ({ symbol: symbol3 }) => textResult(await d.adlQuantile(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
3204
5001
|
},
|
|
3205
5002
|
{
|
|
3206
5003
|
name: "futures_force_orders",
|
|
3207
5004
|
description: "Get the user's force-liquidation orders (LIQUIDATION) and ADL orders for a symbol or all symbols (signed).",
|
|
3208
|
-
inputSchema:
|
|
5005
|
+
inputSchema: import_zod15.z.object({
|
|
3209
5006
|
symbol: optSymbol,
|
|
3210
|
-
autoCloseType:
|
|
5007
|
+
autoCloseType: import_zod15.z.enum(["LIQUIDATION", "ADL"]).optional(),
|
|
3211
5008
|
startTime: startTime2,
|
|
3212
5009
|
endTime: endTime2,
|
|
3213
5010
|
limit: limitDefault.default(50)
|
|
@@ -3227,7 +5024,7 @@ function marketDataTools(client) {
|
|
|
3227
5024
|
}
|
|
3228
5025
|
|
|
3229
5026
|
// src/tools/paper.tools.ts
|
|
3230
|
-
var
|
|
5027
|
+
var import_zod16 = require("zod");
|
|
3231
5028
|
function createPaperContext(client, initialState = {}) {
|
|
3232
5029
|
return {
|
|
3233
5030
|
client,
|
|
@@ -3245,7 +5042,7 @@ function paperTools(ctx) {
|
|
|
3245
5042
|
{
|
|
3246
5043
|
name: "paper_init",
|
|
3247
5044
|
description: "Initialize paper-trading state (reset balances, positions, history). No API keys required.",
|
|
3248
|
-
inputSchema:
|
|
5045
|
+
inputSchema: import_zod16.z.object({ balance: import_zod16.z.number().positive().default(1e4).describe("Starting USDT balance") }),
|
|
3249
5046
|
handler: async ({ balance }) => {
|
|
3250
5047
|
s.balance = balance;
|
|
3251
5048
|
s.positions = [];
|
|
@@ -3256,17 +5053,17 @@ function paperTools(ctx) {
|
|
|
3256
5053
|
{
|
|
3257
5054
|
name: "paper_balance",
|
|
3258
5055
|
description: "Get current paper-trading balance and open-position equity (uses live market prices if an open position exists). No API keys required.",
|
|
3259
|
-
inputSchema:
|
|
5056
|
+
inputSchema: import_zod16.z.object({}),
|
|
3260
5057
|
handler: async () => textResult(s)
|
|
3261
5058
|
},
|
|
3262
5059
|
{
|
|
3263
5060
|
name: "paper_open_position",
|
|
3264
5061
|
description: "Open an in-memory paper position at the live ticker price (or a fixed price). No API keys required.",
|
|
3265
|
-
inputSchema:
|
|
3266
|
-
symbol:
|
|
3267
|
-
side:
|
|
3268
|
-
quantity:
|
|
3269
|
-
price:
|
|
5062
|
+
inputSchema: import_zod16.z.object({
|
|
5063
|
+
symbol: import_zod16.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
|
|
5064
|
+
side: import_zod16.z.enum(["LONG", "SHORT"]),
|
|
5065
|
+
quantity: import_zod16.z.number().positive(),
|
|
5066
|
+
price: import_zod16.z.number().positive().optional().describe("If omitted, uses live ticker price")
|
|
3270
5067
|
}),
|
|
3271
5068
|
handler: async ({ symbol: symbol3, side: side3, quantity, price }) => {
|
|
3272
5069
|
const sym = normalizeSymbol(symbol3);
|
|
@@ -3280,10 +5077,10 @@ function paperTools(ctx) {
|
|
|
3280
5077
|
{
|
|
3281
5078
|
name: "paper_close_position",
|
|
3282
5079
|
description: "Close a paper position by id (or symbol) and realize PnL at the live/last price.",
|
|
3283
|
-
inputSchema:
|
|
3284
|
-
id:
|
|
3285
|
-
symbol:
|
|
3286
|
-
price:
|
|
5080
|
+
inputSchema: import_zod16.z.object({
|
|
5081
|
+
id: import_zod16.z.string().optional().describe("Position id from paper_open_position"),
|
|
5082
|
+
symbol: import_zod16.z.string().min(1).optional().describe("Close the position for this symbol"),
|
|
5083
|
+
price: import_zod16.z.number().positive().optional().describe("If omitted, uses live ticker price")
|
|
3287
5084
|
}),
|
|
3288
5085
|
handler: async ({ id, symbol: symbol3, price }) => {
|
|
3289
5086
|
const idx = s.positions.findIndex((p) => id ? p.id === id : normalizeSymbol(p.symbol) === normalizeSymbol(symbol3 ?? ""));
|
|
@@ -3301,7 +5098,7 @@ function paperTools(ctx) {
|
|
|
3301
5098
|
{
|
|
3302
5099
|
name: "paper_positions",
|
|
3303
5100
|
description: "List open paper positions with live unrealized PnL (marked to market).",
|
|
3304
|
-
inputSchema:
|
|
5101
|
+
inputSchema: import_zod16.z.object({}),
|
|
3305
5102
|
handler: async () => {
|
|
3306
5103
|
const out = await Promise.all(
|
|
3307
5104
|
s.positions.map(async (p) => {
|
|
@@ -3315,39 +5112,39 @@ function paperTools(ctx) {
|
|
|
3315
5112
|
{
|
|
3316
5113
|
name: "paper_history",
|
|
3317
5114
|
description: "List paper-trading history of open/close events with realized PnL.",
|
|
3318
|
-
inputSchema:
|
|
5115
|
+
inputSchema: import_zod16.z.object({}),
|
|
3319
5116
|
handler: async () => textResult(s.history)
|
|
3320
5117
|
},
|
|
3321
5118
|
{
|
|
3322
5119
|
name: "paper_summary",
|
|
3323
5120
|
description: "Summarize paper-trading state: balance, open positions, trade count.",
|
|
3324
|
-
inputSchema:
|
|
5121
|
+
inputSchema: import_zod16.z.object({}),
|
|
3325
5122
|
handler: async () => textResult({ balance: s.balance, openPositions: s.positions.length, trades: s.history.length })
|
|
3326
5123
|
}
|
|
3327
5124
|
];
|
|
3328
5125
|
}
|
|
3329
5126
|
|
|
3330
5127
|
// src/tools/spot.tools.ts
|
|
3331
|
-
var
|
|
3332
|
-
var spotSymbol =
|
|
3333
|
-
var optionalSymbol2 =
|
|
3334
|
-
var limit2 =
|
|
3335
|
-
var startTime3 =
|
|
3336
|
-
var endTime3 =
|
|
3337
|
-
var side =
|
|
3338
|
-
var spotOrderParamsSchema =
|
|
5128
|
+
var import_zod17 = require("zod");
|
|
5129
|
+
var spotSymbol = import_zod17.z.string().min(1).describe("Spot pair, e.g. BTCUSDT");
|
|
5130
|
+
var optionalSymbol2 = import_zod17.z.string().min(1).describe("Spot pair, e.g. BTCUSDT").optional();
|
|
5131
|
+
var limit2 = import_zod17.z.number().int().positive().max(1e3).default(100);
|
|
5132
|
+
var startTime3 = import_zod17.z.number().int().positive().optional();
|
|
5133
|
+
var endTime3 = import_zod17.z.number().int().positive().optional();
|
|
5134
|
+
var side = import_zod17.z.enum(["BUY", "SELL"]);
|
|
5135
|
+
var spotOrderParamsSchema = import_zod17.z.object({
|
|
3339
5136
|
symbol: spotSymbol,
|
|
3340
5137
|
side,
|
|
3341
|
-
type:
|
|
3342
|
-
quantity:
|
|
3343
|
-
quoteOrderQty:
|
|
3344
|
-
price:
|
|
3345
|
-
stopPrice:
|
|
3346
|
-
timeInForce:
|
|
3347
|
-
newClientOrderId:
|
|
3348
|
-
newOrderRespType:
|
|
3349
|
-
icebergQty:
|
|
3350
|
-
selfTradePreventionMode:
|
|
5138
|
+
type: import_zod17.z.enum(["LIMIT", "MARKET", "LIMIT_MAKER", "STOP_LOSS", "STOP_LOSS_LIMIT", "TAKE_PROFIT", "TAKE_PROFIT_LIMIT"]),
|
|
5139
|
+
quantity: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional().describe("Base-asset quantity; omit if using quoteOrderQty"),
|
|
5140
|
+
quoteOrderQty: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional().describe("Quote-asset quantity (e.g. spend 100 USDT on a MARKET order)"),
|
|
5141
|
+
price: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional().describe("Required for LIMIT / STOP_LOSS_LIMIT / TAKE_PROFIT_LIMIT"),
|
|
5142
|
+
stopPrice: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional().describe("Trigger price for STOP_LOSS / TAKE_PROFIT variants"),
|
|
5143
|
+
timeInForce: import_zod17.z.enum(["GTC", "IOC", "FOK"]).optional().describe("Required for LIMIT"),
|
|
5144
|
+
newClientOrderId: import_zod17.z.string().optional(),
|
|
5145
|
+
newOrderRespType: import_zod17.z.enum(["ACK", "RESULT", "FULL"]).optional(),
|
|
5146
|
+
icebergQty: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional(),
|
|
5147
|
+
selfTradePreventionMode: import_zod17.z.enum(["NONE", "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH"]).optional()
|
|
3351
5148
|
});
|
|
3352
5149
|
function spotTools(client) {
|
|
3353
5150
|
const m = client.spot.market;
|
|
@@ -3358,128 +5155,128 @@ function spotTools(client) {
|
|
|
3358
5155
|
{
|
|
3359
5156
|
name: "spot_ping",
|
|
3360
5157
|
description: "Test connectivity to the Binance Spot REST API.",
|
|
3361
|
-
inputSchema:
|
|
5158
|
+
inputSchema: import_zod17.z.object({}),
|
|
3362
5159
|
handler: async () => textResult(await m.ping())
|
|
3363
5160
|
},
|
|
3364
5161
|
{
|
|
3365
5162
|
name: "spot_server_time",
|
|
3366
5163
|
description: "Get the current Binance Spot server time in ms since epoch.",
|
|
3367
|
-
inputSchema:
|
|
5164
|
+
inputSchema: import_zod17.z.object({}),
|
|
3368
5165
|
handler: async () => textResult(await m.serverTime())
|
|
3369
5166
|
},
|
|
3370
5167
|
{
|
|
3371
5168
|
name: "spot_exchange_info",
|
|
3372
5169
|
description: "Get Spot exchange trading rules and symbol metadata (status, base/quote assets, filters, permissions).",
|
|
3373
|
-
inputSchema:
|
|
5170
|
+
inputSchema: import_zod17.z.object({}),
|
|
3374
5171
|
handler: async () => textResult(await m.exchangeInfo())
|
|
3375
5172
|
},
|
|
3376
5173
|
{
|
|
3377
5174
|
name: "spot_ticker_price",
|
|
3378
5175
|
description: "Get the latest price for a Spot symbol.",
|
|
3379
|
-
inputSchema:
|
|
5176
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol }),
|
|
3380
5177
|
handler: async ({ symbol: symbol3 }) => textResult(await m.tickerPrice(normalizeSymbol(symbol3)))
|
|
3381
5178
|
},
|
|
3382
5179
|
{
|
|
3383
5180
|
name: "spot_ticker_24hr",
|
|
3384
5181
|
description: "Get 24-hour rolling price change statistics for a Spot symbol.",
|
|
3385
|
-
inputSchema:
|
|
5182
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol }),
|
|
3386
5183
|
handler: async ({ symbol: symbol3 }) => textResult(await m.ticker24hr(normalizeSymbol(symbol3)))
|
|
3387
5184
|
},
|
|
3388
5185
|
{
|
|
3389
5186
|
name: "spot_book_ticker",
|
|
3390
5187
|
description: "Get the best bid/ask (top of book) for a Spot symbol.",
|
|
3391
|
-
inputSchema:
|
|
5188
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol }),
|
|
3392
5189
|
handler: async ({ symbol: symbol3 }) => textResult(await m.bookTicker(normalizeSymbol(symbol3)))
|
|
3393
5190
|
},
|
|
3394
5191
|
{
|
|
3395
5192
|
name: "spot_order_book",
|
|
3396
5193
|
description: "Get the Spot order book depth for a symbol (limits 5/10/20/50/100/500/1000/5000).",
|
|
3397
|
-
inputSchema:
|
|
5194
|
+
inputSchema: import_zod17.z.object({
|
|
3398
5195
|
symbol: spotSymbol,
|
|
3399
|
-
limit:
|
|
5196
|
+
limit: import_zod17.z.enum(["5", "10", "20", "50", "100", "500", "1000", "5000"]).default("100")
|
|
3400
5197
|
}),
|
|
3401
5198
|
handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.depth(normalizeSymbol(symbol3), Number(limit4)))
|
|
3402
5199
|
},
|
|
3403
5200
|
{
|
|
3404
5201
|
name: "spot_recent_trades",
|
|
3405
5202
|
description: "Get the most recent executed trades for a Spot symbol.",
|
|
3406
|
-
inputSchema:
|
|
5203
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, limit: limit2.default(500) }),
|
|
3407
5204
|
handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await m.trades(normalizeSymbol(symbol3), Number(limit4)))
|
|
3408
5205
|
},
|
|
3409
5206
|
{
|
|
3410
5207
|
name: "spot_historical_trades",
|
|
3411
5208
|
description: "Get older Spot trades for a symbol by fromId.",
|
|
3412
|
-
inputSchema:
|
|
5209
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, limit: limit2.default(500), fromId: import_zod17.z.number().int().positive().optional() }),
|
|
3413
5210
|
handler: async ({ symbol: symbol3, limit: limit4, fromId }) => textResult(await m.historicalTrades(normalizeSymbol(symbol3), { limit: Number(limit4), fromId }))
|
|
3414
5211
|
},
|
|
3415
5212
|
{
|
|
3416
5213
|
name: "spot_agg_trades",
|
|
3417
5214
|
description: "Get compressed/aggregate Spot trades for a symbol within an optional time window.",
|
|
3418
|
-
inputSchema:
|
|
5215
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, limit: limit2.default(500), startTime: startTime3, endTime: endTime3 }),
|
|
3419
5216
|
handler: async ({ symbol: symbol3, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.aggTrades(normalizeSymbol(symbol3), { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3420
5217
|
},
|
|
3421
5218
|
{
|
|
3422
5219
|
name: "spot_klines",
|
|
3423
5220
|
description: "Get Spot candlesticks (OHLCV). Intervals 1m\u20261M; max 1000 per request.",
|
|
3424
|
-
inputSchema:
|
|
5221
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, interval: KlineIntervalSchema, limit: limit2.default(500), startTime: startTime3, endTime: endTime3 }),
|
|
3425
5222
|
handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.klines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3426
5223
|
},
|
|
3427
5224
|
{
|
|
3428
5225
|
name: "spot_ui_klines",
|
|
3429
5226
|
description: "Get Spot candlesticks via the optimized uiKlines endpoint (same shape as spot_klines).",
|
|
3430
|
-
inputSchema:
|
|
5227
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, interval: KlineIntervalSchema, limit: limit2.default(500), startTime: startTime3, endTime: endTime3 }),
|
|
3431
5228
|
handler: async ({ symbol: symbol3, interval, limit: limit4, startTime: startTime5, endTime: endTime5 }) => textResult(await m.uiKlines(normalizeSymbol(symbol3), interval, { limit: Number(limit4), startTime: startTime5, endTime: endTime5 }))
|
|
3432
5229
|
},
|
|
3433
5230
|
{
|
|
3434
5231
|
name: "spot_avg_price",
|
|
3435
5232
|
description: "Get the current average price (5-minute rolling average) for a Spot symbol.",
|
|
3436
|
-
inputSchema:
|
|
5233
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol }),
|
|
3437
5234
|
handler: async ({ symbol: symbol3 }) => textResult(await m.avgPrice(normalizeSymbol(symbol3)))
|
|
3438
5235
|
},
|
|
3439
5236
|
{
|
|
3440
5237
|
name: "spot_rolling_window_ticker",
|
|
3441
5238
|
description: "Get rolling-window price change statistics (1d/7d/30d). Omit symbol for all symbols.",
|
|
3442
|
-
inputSchema:
|
|
5239
|
+
inputSchema: import_zod17.z.object({
|
|
3443
5240
|
symbol: optionalSymbol2,
|
|
3444
|
-
windowSize:
|
|
5241
|
+
windowSize: import_zod17.z.enum(["1d", "7d", "30d"]).optional()
|
|
3445
5242
|
}),
|
|
3446
5243
|
handler: async ({ symbol: symbol3, windowSize }) => textResult(await m.rollingWindowTicker(symbol3 ? normalizeSymbol(symbol3) : void 0, windowSize))
|
|
3447
5244
|
},
|
|
3448
5245
|
{
|
|
3449
5246
|
name: "spot_trading_day_ticker",
|
|
3450
5247
|
description: "Get the Spot trading-day ticker (open/close/high/low/volume by UTC day). Omit symbol for all symbols.",
|
|
3451
|
-
inputSchema:
|
|
5248
|
+
inputSchema: import_zod17.z.object({ symbol: optionalSymbol2, timeZone: import_zod17.z.string().optional(), type: import_zod17.z.enum(["FULL", "MINI"]).optional() }),
|
|
3452
5249
|
handler: async ({ symbol: symbol3, timeZone, type }) => textResult(await m.tradingDayTicker(symbol3 ? normalizeSymbol(symbol3) : void 0, { timeZone, type }))
|
|
3453
5250
|
},
|
|
3454
5251
|
// ---- Account (signed) ----
|
|
3455
5252
|
{
|
|
3456
5253
|
name: "spot_account",
|
|
3457
5254
|
description: "Get the Spot account: balances (free/locked), commissions, permissions (signed).",
|
|
3458
|
-
inputSchema:
|
|
5255
|
+
inputSchema: import_zod17.z.object({}),
|
|
3459
5256
|
handler: async () => textResult(await a.account())
|
|
3460
5257
|
},
|
|
3461
5258
|
{
|
|
3462
5259
|
name: "spot_my_trades",
|
|
3463
5260
|
description: "Get the Spot account trade list (filled trades) for a symbol with optional time range (signed).",
|
|
3464
|
-
inputSchema:
|
|
5261
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, orderId: import_zod17.z.number().int().positive().optional(), startTime: startTime3, endTime: endTime3, fromId: import_zod17.z.number().int().positive().optional(), limit: limit2.default(500) }),
|
|
3465
5262
|
handler: async ({ symbol: symbol3, orderId, startTime: startTime5, endTime: endTime5, fromId, limit: limit4 }) => textResult(await a.myTrades(normalizeSymbol(symbol3), { orderId, startTime: startTime5, endTime: endTime5, fromId, limit: Number(limit4) }))
|
|
3466
5263
|
},
|
|
3467
5264
|
{
|
|
3468
5265
|
name: "spot_my_prevented_matches",
|
|
3469
5266
|
description: "Get Spot orders that were expired by the self-trade-prevention (STP) mechanism (signed).",
|
|
3470
|
-
inputSchema:
|
|
5267
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, preventedMatchId: import_zod17.z.number().int().positive().optional(), orderId: import_zod17.z.number().int().positive().optional(), limit: limit2.default(500) }),
|
|
3471
5268
|
handler: async ({ symbol: symbol3, preventedMatchId, orderId, limit: limit4 }) => textResult(await a.myPreventedMatches(normalizeSymbol(symbol3), { preventedMatchId, orderId, limit: Number(limit4) }))
|
|
3472
5269
|
},
|
|
3473
5270
|
{
|
|
3474
5271
|
name: "spot_account_commission",
|
|
3475
5272
|
description: "Get the Spot account commission rates for a symbol (signed).",
|
|
3476
|
-
inputSchema:
|
|
5273
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol }),
|
|
3477
5274
|
handler: async ({ symbol: symbol3 }) => textResult(await a.accountCommission(normalizeSymbol(symbol3)))
|
|
3478
5275
|
},
|
|
3479
5276
|
{
|
|
3480
5277
|
name: "spot_rate_limit_order",
|
|
3481
5278
|
description: "Query the current Spot order rate limit usage (signed).",
|
|
3482
|
-
inputSchema:
|
|
5279
|
+
inputSchema: import_zod17.z.object({}),
|
|
3483
5280
|
handler: async () => textResult(await a.rateLimitOrder())
|
|
3484
5281
|
},
|
|
3485
5282
|
// ---- Trading (signed) ----
|
|
@@ -3498,109 +5295,109 @@ function spotTools(client) {
|
|
|
3498
5295
|
{
|
|
3499
5296
|
name: "spot_get_order",
|
|
3500
5297
|
description: "Query a specific Spot order by orderId or client order id. Signed.",
|
|
3501
|
-
inputSchema:
|
|
5298
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, orderId: import_zod17.z.number().int().positive().optional(), origClientOrderId: import_zod17.z.string().optional() }),
|
|
3502
5299
|
handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.getOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
|
|
3503
5300
|
},
|
|
3504
5301
|
{
|
|
3505
5302
|
name: "spot_cancel_order",
|
|
3506
5303
|
description: "Cancel a specific open Spot order by orderId or client order id. Signed.",
|
|
3507
|
-
inputSchema:
|
|
5304
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, orderId: import_zod17.z.number().int().positive().optional(), origClientOrderId: import_zod17.z.string().optional(), newClientOrderId: import_zod17.z.string().optional() }),
|
|
3508
5305
|
handler: async ({ symbol: symbol3, orderId, origClientOrderId, newClientOrderId }) => textResult(await t.cancelOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId, newClientOrderId }))
|
|
3509
5306
|
},
|
|
3510
5307
|
{
|
|
3511
5308
|
name: "spot_open_orders",
|
|
3512
5309
|
description: "Get all current open Spot orders, for one symbol or all symbols. Signed.",
|
|
3513
|
-
inputSchema:
|
|
5310
|
+
inputSchema: import_zod17.z.object({ symbol: optionalSymbol2 }),
|
|
3514
5311
|
handler: async ({ symbol: symbol3 }) => textResult(await t.getOpenOrders(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
3515
5312
|
},
|
|
3516
5313
|
{
|
|
3517
5314
|
name: "spot_all_orders",
|
|
3518
5315
|
description: "Get historical Spot orders for a symbol with optional time range. Signed.",
|
|
3519
|
-
inputSchema:
|
|
5316
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, orderId: import_zod17.z.number().int().positive().optional(), startTime: startTime3, endTime: endTime3, limit: limit2 }),
|
|
3520
5317
|
handler: async ({ symbol: symbol3, orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllOrders(normalizeSymbol(symbol3), { orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }))
|
|
3521
5318
|
},
|
|
3522
5319
|
{
|
|
3523
5320
|
name: "spot_cancel_open_orders",
|
|
3524
5321
|
description: "Cancel all open Spot orders for a symbol. Signed.",
|
|
3525
|
-
inputSchema:
|
|
5322
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol }),
|
|
3526
5323
|
handler: async ({ symbol: symbol3 }) => textResult(await t.cancelOpenOrders(normalizeSymbol(symbol3)))
|
|
3527
5324
|
},
|
|
3528
5325
|
{
|
|
3529
5326
|
name: "spot_cancel_replace_order",
|
|
3530
5327
|
description: "Cancel an existing Spot order and place a new one on the same symbol (cancel-replace). Signed.",
|
|
3531
|
-
inputSchema:
|
|
5328
|
+
inputSchema: import_zod17.z.object({
|
|
3532
5329
|
symbol: spotSymbol,
|
|
3533
5330
|
side,
|
|
3534
|
-
type:
|
|
3535
|
-
cancelReplaceMode:
|
|
3536
|
-
cancelOrderId:
|
|
3537
|
-
cancelOrigClientOrderId:
|
|
3538
|
-
cancelNewClientOrderId:
|
|
3539
|
-
quantity:
|
|
3540
|
-
price:
|
|
3541
|
-
timeInForce:
|
|
3542
|
-
newClientOrderId:
|
|
5331
|
+
type: import_zod17.z.enum(["LIMIT", "MARKET", "STOP_LOSS", "STOP_LOSS_LIMIT", "TAKE_PROFIT", "TAKE_PROFIT_LIMIT"]),
|
|
5332
|
+
cancelReplaceMode: import_zod17.z.enum(["STOP_ON_FAILURE", "ALLOW_FAILURE"]).default("STOP_ON_FAILURE"),
|
|
5333
|
+
cancelOrderId: import_zod17.z.number().int().positive().optional(),
|
|
5334
|
+
cancelOrigClientOrderId: import_zod17.z.string().optional(),
|
|
5335
|
+
cancelNewClientOrderId: import_zod17.z.string().optional(),
|
|
5336
|
+
quantity: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional(),
|
|
5337
|
+
price: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional(),
|
|
5338
|
+
timeInForce: import_zod17.z.enum(["GTC", "IOC", "FOK"]).optional(),
|
|
5339
|
+
newClientOrderId: import_zod17.z.string().optional()
|
|
3543
5340
|
}),
|
|
3544
5341
|
handler: async (args) => textResult(await t.cancelReplaceOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
|
|
3545
5342
|
},
|
|
3546
5343
|
{
|
|
3547
5344
|
name: "spot_new_oco_order",
|
|
3548
5345
|
description: "Place a new Spot OCO (one-cancels-other) order: a stop-loss limit + a limit-maker take-profit. Signed.",
|
|
3549
|
-
inputSchema:
|
|
5346
|
+
inputSchema: import_zod17.z.object({
|
|
3550
5347
|
symbol: spotSymbol,
|
|
3551
5348
|
side,
|
|
3552
|
-
quantity:
|
|
3553
|
-
price:
|
|
3554
|
-
stopPrice:
|
|
3555
|
-
stopLimitPrice:
|
|
3556
|
-
stopLimitTimeInForce:
|
|
3557
|
-
listClientOrderId:
|
|
3558
|
-
limitClientOrderId:
|
|
3559
|
-
stopClientOrderId:
|
|
5349
|
+
quantity: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).describe("Total base-asset quantity for both legs"),
|
|
5350
|
+
price: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).describe("Limit (take-profit) price"),
|
|
5351
|
+
stopPrice: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).describe("Stop-loss trigger price"),
|
|
5352
|
+
stopLimitPrice: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional().describe("Stop-loss limit price (defaults to stopPrice)"),
|
|
5353
|
+
stopLimitTimeInForce: import_zod17.z.enum(["GTC", "IOC", "FOK"]).optional(),
|
|
5354
|
+
listClientOrderId: import_zod17.z.string().optional(),
|
|
5355
|
+
limitClientOrderId: import_zod17.z.string().optional(),
|
|
5356
|
+
stopClientOrderId: import_zod17.z.string().optional()
|
|
3560
5357
|
}),
|
|
3561
5358
|
handler: async (args) => textResult(await t.createOCOOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
|
|
3562
5359
|
},
|
|
3563
5360
|
{
|
|
3564
5361
|
name: "spot_cancel_oco_order",
|
|
3565
5362
|
description: "Cancel an entire Spot OCO order list by orderListId or listClientOrderId. Signed.",
|
|
3566
|
-
inputSchema:
|
|
5363
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, orderListId: import_zod17.z.number().int().positive().optional(), listClientOrderId: import_zod17.z.string().optional(), newClientOrderId: import_zod17.z.string().optional() }),
|
|
3567
5364
|
handler: async ({ symbol: symbol3, orderListId, listClientOrderId, newClientOrderId }) => textResult(await t.cancelOCOOrder(normalizeSymbol(symbol3), { orderListId, listClientOrderId, newClientOrderId }))
|
|
3568
5365
|
},
|
|
3569
5366
|
{
|
|
3570
5367
|
name: "spot_get_oco_order",
|
|
3571
5368
|
description: "Query a Spot OCO order list by orderListId or listClientOrderId. Signed.",
|
|
3572
|
-
inputSchema:
|
|
5369
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, orderListId: import_zod17.z.number().int().positive().optional(), origClientOrderId: import_zod17.z.string().optional() }),
|
|
3573
5370
|
handler: async ({ symbol: symbol3, orderListId, origClientOrderId }) => textResult(await t.getOCOOrder(normalizeSymbol(symbol3), { orderListId, origClientOrderId }))
|
|
3574
5371
|
},
|
|
3575
5372
|
{
|
|
3576
5373
|
name: "spot_open_oco_orders",
|
|
3577
5374
|
description: "Get all current open Spot OCO order lists. Signed.",
|
|
3578
|
-
inputSchema:
|
|
5375
|
+
inputSchema: import_zod17.z.object({}),
|
|
3579
5376
|
handler: async () => textResult(await t.getOpenOCOOrders())
|
|
3580
5377
|
},
|
|
3581
5378
|
{
|
|
3582
5379
|
name: "spot_all_oco_orders",
|
|
3583
5380
|
description: "Get historical Spot OCO order lists for a symbol with optional time range. Signed.",
|
|
3584
|
-
inputSchema:
|
|
5381
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol, fromId: import_zod17.z.number().int().positive().optional(), startTime: startTime3, endTime: endTime3, limit: limit2 }),
|
|
3585
5382
|
handler: async ({ symbol: symbol3, fromId, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllOCOOrders(normalizeSymbol(symbol3), { fromId, startTime: startTime5, endTime: endTime5, limit: limit4 }))
|
|
3586
5383
|
},
|
|
3587
5384
|
{
|
|
3588
5385
|
name: "spot_cancel_open_oco_orders",
|
|
3589
5386
|
description: "Cancel all open Spot OCO order lists for a symbol. Signed.",
|
|
3590
|
-
inputSchema:
|
|
5387
|
+
inputSchema: import_zod17.z.object({ symbol: spotSymbol }),
|
|
3591
5388
|
handler: async ({ symbol: symbol3 }) => textResult(await t.cancelOpenOCOOrders(normalizeSymbol(symbol3)))
|
|
3592
5389
|
},
|
|
3593
5390
|
// ---- User data stream (signed) ----
|
|
3594
5391
|
{
|
|
3595
5392
|
name: "spot_ws_start_user_stream",
|
|
3596
5393
|
description: "Start the Spot user data stream: creates a listenKey, connects the private WebSocket, and begins keep-alive. Emits executionReport, outboundAccountPosition, balanceUpdate, listStatus.",
|
|
3597
|
-
inputSchema:
|
|
5394
|
+
inputSchema: import_zod17.z.object({}),
|
|
3598
5395
|
handler: async () => textResult({ listenKey: await client.startSpotUserStream() })
|
|
3599
5396
|
},
|
|
3600
5397
|
{
|
|
3601
5398
|
name: "spot_ws_stop_user_stream",
|
|
3602
5399
|
description: "Stop the Spot user data stream: closes the private WebSocket and invalidates the listenKey.",
|
|
3603
|
-
inputSchema:
|
|
5400
|
+
inputSchema: import_zod17.z.object({}),
|
|
3604
5401
|
handler: async () => {
|
|
3605
5402
|
client.closeSpotUserStream();
|
|
3606
5403
|
return textResult({ stopped: true });
|
|
@@ -3611,33 +5408,33 @@ function spotTools(client) {
|
|
|
3611
5408
|
}
|
|
3612
5409
|
|
|
3613
5410
|
// src/tools/trading.tools.ts
|
|
3614
|
-
var
|
|
3615
|
-
var symbol2 =
|
|
3616
|
-
var optionalSymbol3 =
|
|
3617
|
-
var limit3 =
|
|
3618
|
-
var startTime4 =
|
|
3619
|
-
var endTime4 =
|
|
3620
|
-
var side2 =
|
|
3621
|
-
var positionSide =
|
|
3622
|
-
var orderParamsSchema =
|
|
5411
|
+
var import_zod18 = require("zod");
|
|
5412
|
+
var symbol2 = import_zod18.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT");
|
|
5413
|
+
var optionalSymbol3 = import_zod18.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional();
|
|
5414
|
+
var limit3 = import_zod18.z.number().int().positive().max(1e3).default(100);
|
|
5415
|
+
var startTime4 = import_zod18.z.number().int().positive().optional();
|
|
5416
|
+
var endTime4 = import_zod18.z.number().int().positive().optional();
|
|
5417
|
+
var side2 = import_zod18.z.enum(["BUY", "SELL"]);
|
|
5418
|
+
var positionSide = import_zod18.z.enum(["BOTH", "LONG", "SHORT"]).optional();
|
|
5419
|
+
var orderParamsSchema = import_zod18.z.object({
|
|
3623
5420
|
symbol: symbol2,
|
|
3624
5421
|
side: side2,
|
|
3625
|
-
type:
|
|
3626
|
-
quantity:
|
|
3627
|
-
price:
|
|
3628
|
-
timeInForce:
|
|
3629
|
-
stopPrice:
|
|
3630
|
-
reduceOnly:
|
|
5422
|
+
type: import_zod18.z.enum(["LIMIT", "MARKET", "STOP", "STOP_MARKET", "TAKE_PROFIT", "TAKE_PROFIT_MARKET", "TRAILING_STOP_MARKET"]),
|
|
5423
|
+
quantity: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).describe("Order quantity in base asset"),
|
|
5424
|
+
price: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional().describe("Required for LIMIT and STOP/TAKE_PROFIT (limit-triggered) types"),
|
|
5425
|
+
timeInForce: import_zod18.z.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
|
|
5426
|
+
stopPrice: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional().describe("Trigger price for STOP/STOP_MARKET/TAKE_PROFIT/TAKE_PROFIT_MARKET"),
|
|
5427
|
+
reduceOnly: import_zod18.z.boolean().optional().describe("true = only reduces the position, never opens"),
|
|
3631
5428
|
positionSide,
|
|
3632
|
-
newClientOrderId:
|
|
3633
|
-
closePosition:
|
|
3634
|
-
newOrderRespType:
|
|
3635
|
-
priceProtect:
|
|
3636
|
-
workingType:
|
|
3637
|
-
callbackRate:
|
|
3638
|
-
activationPrice:
|
|
3639
|
-
selfTradePreventionMode:
|
|
3640
|
-
goodTillDate:
|
|
5429
|
+
newClientOrderId: import_zod18.z.string().optional(),
|
|
5430
|
+
closePosition: import_zod18.z.boolean().optional().describe("Close the full position on trigger (mutually exclusive with quantity)"),
|
|
5431
|
+
newOrderRespType: import_zod18.z.enum(["ACK", "RESULT"]).optional(),
|
|
5432
|
+
priceProtect: import_zod18.z.boolean().optional(),
|
|
5433
|
+
workingType: import_zod18.z.enum(["MARK_PRICE", "CONTRACT_PRICE"]).optional().describe("Trigger price basis; default CONTRACT_PRICE"),
|
|
5434
|
+
callbackRate: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional().describe("Percent callback for TRAILING_STOP_MARKET, e.g. 0.5"),
|
|
5435
|
+
activationPrice: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional().describe("Activation price for TRAILING_STOP_MARKET"),
|
|
5436
|
+
selfTradePreventionMode: import_zod18.z.enum(["NONE", "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH"]).optional(),
|
|
5437
|
+
goodTillDate: import_zod18.z.number().int().optional().describe("Timestamp when a GTD order expires")
|
|
3641
5438
|
});
|
|
3642
5439
|
function tradingTools(client) {
|
|
3643
5440
|
const t = client.futures.trading;
|
|
@@ -3657,66 +5454,66 @@ function tradingTools(client) {
|
|
|
3657
5454
|
{
|
|
3658
5455
|
name: "futures_get_order",
|
|
3659
5456
|
description: "Query a specific order by orderId or client order id. Signed.",
|
|
3660
|
-
inputSchema:
|
|
5457
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, orderId: import_zod18.z.number().int().positive().optional(), origClientOrderId: import_zod18.z.string().optional() }),
|
|
3661
5458
|
handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.getOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
|
|
3662
5459
|
},
|
|
3663
5460
|
{
|
|
3664
5461
|
name: "futures_cancel_order",
|
|
3665
5462
|
description: "Cancel a specific open order by orderId or client order id. Signed.",
|
|
3666
|
-
inputSchema:
|
|
5463
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, orderId: import_zod18.z.number().int().positive().optional(), origClientOrderId: import_zod18.z.string().optional() }),
|
|
3667
5464
|
handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.cancelOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
|
|
3668
5465
|
},
|
|
3669
5466
|
{
|
|
3670
5467
|
name: "futures_get_open_order",
|
|
3671
5468
|
description: "Query a current open order (must exist in the open order book). Signed.",
|
|
3672
|
-
inputSchema:
|
|
5469
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, orderId: import_zod18.z.number().int().positive().optional(), origClientOrderId: import_zod18.z.string().optional() }),
|
|
3673
5470
|
handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await t.getCurrentOrder(normalizeSymbol(symbol3), { orderId, origClientOrderId }))
|
|
3674
5471
|
},
|
|
3675
5472
|
{
|
|
3676
5473
|
name: "futures_open_orders",
|
|
3677
5474
|
description: "Get all current open orders, for one symbol or all symbols. Signed.",
|
|
3678
|
-
inputSchema:
|
|
5475
|
+
inputSchema: import_zod18.z.object({ symbol: optionalSymbol3 }),
|
|
3679
5476
|
handler: async ({ symbol: symbol3 }) => textResult(await t.getOpenOrders(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
3680
5477
|
},
|
|
3681
5478
|
{
|
|
3682
5479
|
name: "futures_all_orders",
|
|
3683
5480
|
description: "Get historical orders for a symbol with optional time range (last 7 days by default). Signed.",
|
|
3684
|
-
inputSchema:
|
|
5481
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, orderId: import_zod18.z.number().int().positive().optional(), startTime: startTime4, endTime: endTime4, limit: limit3 }),
|
|
3685
5482
|
handler: async ({ symbol: symbol3, orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllOrders(normalizeSymbol(symbol3), { orderId, startTime: startTime5, endTime: endTime5, limit: limit4 }))
|
|
3686
5483
|
},
|
|
3687
5484
|
{
|
|
3688
5485
|
name: "futures_cancel_all_orders",
|
|
3689
5486
|
description: "Cancel all open orders for a symbol. Signed.",
|
|
3690
|
-
inputSchema:
|
|
5487
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2 }),
|
|
3691
5488
|
handler: async ({ symbol: symbol3 }) => textResult(await t.cancelAllOpenOrders(normalizeSymbol(symbol3)))
|
|
3692
5489
|
},
|
|
3693
5490
|
{
|
|
3694
5491
|
name: "futures_modify_order",
|
|
3695
5492
|
description: "Modify an open order (price/quantity/stopPrice). Cannot modify when position side is BOTH and closePosition is true. Signed.",
|
|
3696
|
-
inputSchema:
|
|
5493
|
+
inputSchema: import_zod18.z.object({
|
|
3697
5494
|
symbol: symbol2,
|
|
3698
5495
|
side: side2,
|
|
3699
|
-
quantity:
|
|
3700
|
-
price:
|
|
3701
|
-
orderId:
|
|
3702
|
-
origClientOrderId:
|
|
3703
|
-
stopPrice:
|
|
3704
|
-
timeInForce:
|
|
5496
|
+
quantity: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]),
|
|
5497
|
+
price: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional(),
|
|
5498
|
+
orderId: import_zod18.z.number().int().positive().optional(),
|
|
5499
|
+
origClientOrderId: import_zod18.z.string().optional(),
|
|
5500
|
+
stopPrice: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional(),
|
|
5501
|
+
timeInForce: import_zod18.z.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
|
|
3705
5502
|
positionSide,
|
|
3706
|
-
newClientOrderId:
|
|
5503
|
+
newClientOrderId: import_zod18.z.string().optional()
|
|
3707
5504
|
}),
|
|
3708
5505
|
handler: async (args) => textResult(await t.modifyOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
|
|
3709
5506
|
},
|
|
3710
5507
|
{
|
|
3711
5508
|
name: "futures_order_modify_history",
|
|
3712
5509
|
description: "Get order modification history for a symbol. Signed.",
|
|
3713
|
-
inputSchema:
|
|
5510
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, startTime: startTime4, endTime: endTime4, limit: limit3 }),
|
|
3714
5511
|
handler: async ({ symbol: symbol3, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getOrderModifyHistory(normalizeSymbol(symbol3), { startTime: startTime5, endTime: endTime5, limit: limit4 }))
|
|
3715
5512
|
},
|
|
3716
5513
|
{
|
|
3717
5514
|
name: "futures_batch_orders",
|
|
3718
5515
|
description: "Place up to 5 orders in one request (array of order objects, max 30 per minute per symbol). Signed.",
|
|
3719
|
-
inputSchema:
|
|
5516
|
+
inputSchema: import_zod18.z.object({ orders: import_zod18.z.array(orderParamsSchema).min(1).max(5) }),
|
|
3720
5517
|
handler: async (args) => {
|
|
3721
5518
|
const mapped = args.orders.map((o) => ({ ...o, symbol: normalizeSymbol(o.symbol) }));
|
|
3722
5519
|
return textResult(await t.createBatchOrders(mapped));
|
|
@@ -3725,124 +5522,124 @@ function tradingTools(client) {
|
|
|
3725
5522
|
{
|
|
3726
5523
|
name: "futures_cancel_batch_orders",
|
|
3727
5524
|
description: "Cancel multiple orders at once (up to 10 by orderId list or client order id list). Signed.",
|
|
3728
|
-
inputSchema:
|
|
5525
|
+
inputSchema: import_zod18.z.object({
|
|
3729
5526
|
symbol: symbol2,
|
|
3730
|
-
orderIdList:
|
|
3731
|
-
origClientOrderIdList:
|
|
5527
|
+
orderIdList: import_zod18.z.array(import_zod18.z.number().int().positive()).max(10).optional(),
|
|
5528
|
+
origClientOrderIdList: import_zod18.z.array(import_zod18.z.string()).max(10).optional()
|
|
3732
5529
|
}),
|
|
3733
5530
|
handler: async ({ symbol: symbol3, orderIdList, origClientOrderIdList }) => textResult(await t.cancelBatchOrders(normalizeSymbol(symbol3), { orderIdList, origClientOrderIdList }))
|
|
3734
5531
|
},
|
|
3735
5532
|
{
|
|
3736
5533
|
name: "futures_set_leverage",
|
|
3737
5534
|
description: "Change initial leverage for a symbol (1-125, within bracket). Signed.",
|
|
3738
|
-
inputSchema:
|
|
5535
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, leverage: import_zod18.z.number().int().min(1).max(125) }),
|
|
3739
5536
|
handler: async ({ symbol: symbol3, leverage }) => textResult(await t.setLeverage(normalizeSymbol(symbol3), leverage))
|
|
3740
5537
|
},
|
|
3741
5538
|
{
|
|
3742
5539
|
name: "futures_set_margin_type",
|
|
3743
5540
|
description: "Change margin type for a symbol: isolated or cross. Only allowed when no open position for the symbol. Signed.",
|
|
3744
|
-
inputSchema:
|
|
5541
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, marginType: import_zod18.z.enum(["isolated", "cross"]) }),
|
|
3745
5542
|
handler: async ({ symbol: symbol3, marginType }) => textResult(await t.setMarginType(normalizeSymbol(symbol3), marginType))
|
|
3746
5543
|
},
|
|
3747
5544
|
{
|
|
3748
5545
|
name: "futures_modify_position_margin",
|
|
3749
5546
|
description: "Add or reduce isolated position margin. marginType: 1 = add margin, 2 = reduce margin. Signed.",
|
|
3750
|
-
inputSchema:
|
|
5547
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, amount: import_zod18.z.number().positive(), marginType: import_zod18.z.enum(["1", "2"]).describe("1 = add margin, 2 = reduce margin") }),
|
|
3751
5548
|
handler: async ({ symbol: symbol3, amount, marginType }) => textResult(await t.modifyPositionMargin(normalizeSymbol(symbol3), amount, Number(marginType)))
|
|
3752
5549
|
},
|
|
3753
5550
|
{
|
|
3754
5551
|
name: "futures_countdown_cancel_all",
|
|
3755
5552
|
description: "Auto-cancel all open orders for a symbol after countdownTime ms (0 = cancel the countdown). Emergency circuit breaker. Signed.",
|
|
3756
|
-
inputSchema:
|
|
5553
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, countdownTime: import_zod18.z.number().int().min(100).max(6e4) }),
|
|
3757
5554
|
handler: async ({ symbol: symbol3, countdownTime }) => textResult(await t.setCountdownCancelAll(normalizeSymbol(symbol3), countdownTime))
|
|
3758
5555
|
},
|
|
3759
5556
|
{
|
|
3760
5557
|
name: "futures_new_algo_order",
|
|
3761
5558
|
description: "Place a conditional algo order (CONDITIONAL or VP). CONDITIONAL supports STOP_MARKET/TAKE_PROFIT_MARKET types with triggerPrice; VP is a volume-participation order with urgency and quantity. Signed.",
|
|
3762
|
-
inputSchema:
|
|
3763
|
-
algoType:
|
|
5559
|
+
inputSchema: import_zod18.z.object({
|
|
5560
|
+
algoType: import_zod18.z.enum(["CONDITIONAL", "VP"]),
|
|
3764
5561
|
symbol: symbol2,
|
|
3765
5562
|
side: side2,
|
|
3766
5563
|
positionSide,
|
|
3767
|
-
type:
|
|
3768
|
-
quantity:
|
|
3769
|
-
triggerPrice:
|
|
3770
|
-
price:
|
|
3771
|
-
timeInForce:
|
|
3772
|
-
workingType:
|
|
3773
|
-
priceProtect:
|
|
3774
|
-
reduceOnly:
|
|
3775
|
-
closePosition:
|
|
3776
|
-
urgency:
|
|
3777
|
-
clientAlgoId:
|
|
5564
|
+
type: import_zod18.z.enum(["STOP_MARKET", "TAKE_PROFIT_MARKET", "LIMIT"]).describe("For CONDITIONAL: STOP_MARKET/TAKE_PROFIT_MARKET. For VP: LIMIT"),
|
|
5565
|
+
quantity: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]),
|
|
5566
|
+
triggerPrice: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional().describe("Required for CONDITIONAL"),
|
|
5567
|
+
price: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional(),
|
|
5568
|
+
timeInForce: import_zod18.z.enum(["GTC", "IOC", "FOK", "GTX"]).optional(),
|
|
5569
|
+
workingType: import_zod18.z.enum(["MARK_PRICE", "CONTRACT_PRICE"]).optional(),
|
|
5570
|
+
priceProtect: import_zod18.z.boolean().optional(),
|
|
5571
|
+
reduceOnly: import_zod18.z.boolean().optional(),
|
|
5572
|
+
closePosition: import_zod18.z.boolean().optional(),
|
|
5573
|
+
urgency: import_zod18.z.enum(["LOW", "MEDIUM", "HIGH"]).optional().describe("Required for VP"),
|
|
5574
|
+
clientAlgoId: import_zod18.z.string().optional()
|
|
3778
5575
|
}),
|
|
3779
5576
|
handler: async (args) => textResult(await t.createAlgoOrder({ ...args, symbol: normalizeSymbol(args.symbol) }))
|
|
3780
5577
|
},
|
|
3781
5578
|
{
|
|
3782
5579
|
name: "futures_cancel_algo_order",
|
|
3783
5580
|
description: "Cancel an open algo order by algoId or clientAlgoId. Signed.",
|
|
3784
|
-
inputSchema:
|
|
5581
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, algoId: import_zod18.z.number().int().positive().optional(), clientAlgoId: import_zod18.z.string().optional() }),
|
|
3785
5582
|
handler: async ({ symbol: symbol3, algoId, clientAlgoId }) => textResult(await t.cancelAlgoOrder(normalizeSymbol(symbol3), { algoId, clientAlgoId }))
|
|
3786
5583
|
},
|
|
3787
5584
|
{
|
|
3788
5585
|
name: "futures_cancel_all_algo_orders",
|
|
3789
5586
|
description: "Cancel all open algo orders for a symbol. Signed.",
|
|
3790
|
-
inputSchema:
|
|
5587
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2 }),
|
|
3791
5588
|
handler: async ({ symbol: symbol3 }) => textResult(await t.cancelAllOpenAlgoOrders(normalizeSymbol(symbol3)))
|
|
3792
5589
|
},
|
|
3793
5590
|
{
|
|
3794
5591
|
name: "futures_get_algo_order",
|
|
3795
5592
|
description: "Query an algo order by algoId or clientAlgoId. Signed.",
|
|
3796
|
-
inputSchema:
|
|
5593
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, algoId: import_zod18.z.number().int().positive().optional(), clientAlgoId: import_zod18.z.string().optional() }),
|
|
3797
5594
|
handler: async ({ symbol: symbol3, algoId, clientAlgoId }) => textResult(await t.getAlgoOrder(normalizeSymbol(symbol3), { algoId, clientAlgoId }))
|
|
3798
5595
|
},
|
|
3799
5596
|
{
|
|
3800
5597
|
name: "futures_open_algo_orders",
|
|
3801
5598
|
description: "Get all current open algo orders, optionally filtered by symbol. Signed.",
|
|
3802
|
-
inputSchema:
|
|
5599
|
+
inputSchema: import_zod18.z.object({ symbol: optionalSymbol3 }),
|
|
3803
5600
|
handler: async ({ symbol: symbol3 }) => textResult(await t.getOpenAlgoOrders(symbol3 ? normalizeSymbol(symbol3) : void 0))
|
|
3804
5601
|
},
|
|
3805
5602
|
{
|
|
3806
5603
|
name: "futures_all_algo_orders",
|
|
3807
5604
|
description: "Get historical algo orders for a symbol with optional time range. Signed.",
|
|
3808
|
-
inputSchema:
|
|
5605
|
+
inputSchema: import_zod18.z.object({ symbol: symbol2, startTime: startTime4, endTime: endTime4, limit: limit3 }),
|
|
3809
5606
|
handler: async ({ symbol: symbol3, startTime: startTime5, endTime: endTime5, limit: limit4 }) => textResult(await t.getAllAlgoOrders(normalizeSymbol(symbol3), { startTime: startTime5, endTime: endTime5, limit: limit4 }))
|
|
3810
5607
|
},
|
|
3811
5608
|
{
|
|
3812
5609
|
name: "futures_convert_exchange_info",
|
|
3813
5610
|
description: "List asset pairs eligible for futures Convert, optionally filtered by fromAsset/toAsset.",
|
|
3814
|
-
inputSchema:
|
|
5611
|
+
inputSchema: import_zod18.z.object({ fromAsset: import_zod18.z.string().optional(), toAsset: import_zod18.z.string().optional() }),
|
|
3815
5612
|
handler: async ({ fromAsset, toAsset }) => textResult(await t.convertExchangeInfo({ fromAsset, toAsset }))
|
|
3816
5613
|
},
|
|
3817
5614
|
{
|
|
3818
5615
|
name: "futures_convert_get_quote",
|
|
3819
5616
|
description: "Request a Convert quote between two assets (quote expires quickly; accept with futures_convert_accept_quote). Signed.",
|
|
3820
|
-
inputSchema:
|
|
3821
|
-
fromAsset:
|
|
3822
|
-
toAsset:
|
|
3823
|
-
fromAmount:
|
|
3824
|
-
toAmount:
|
|
3825
|
-
validTime:
|
|
5617
|
+
inputSchema: import_zod18.z.object({
|
|
5618
|
+
fromAsset: import_zod18.z.string().min(1),
|
|
5619
|
+
toAsset: import_zod18.z.string().min(1),
|
|
5620
|
+
fromAmount: import_zod18.z.number().positive().optional(),
|
|
5621
|
+
toAmount: import_zod18.z.number().positive().optional(),
|
|
5622
|
+
validTime: import_zod18.z.enum(["10s", "30s", "1m", "2m"]).optional()
|
|
3826
5623
|
}),
|
|
3827
5624
|
handler: async (args) => textResult(await t.convertGetQuote(args))
|
|
3828
5625
|
},
|
|
3829
5626
|
{
|
|
3830
5627
|
name: "futures_convert_accept_quote",
|
|
3831
5628
|
description: "Accept a previously requested Convert quote by quoteId. Signed.",
|
|
3832
|
-
inputSchema:
|
|
5629
|
+
inputSchema: import_zod18.z.object({ quoteId: import_zod18.z.string().min(1) }),
|
|
3833
5630
|
handler: async ({ quoteId }) => textResult(await t.convertAcceptQuote(quoteId))
|
|
3834
5631
|
},
|
|
3835
5632
|
{
|
|
3836
5633
|
name: "futures_convert_order_status",
|
|
3837
5634
|
description: "Query the status of a Convert order by orderId or quoteId. Signed.",
|
|
3838
|
-
inputSchema:
|
|
5635
|
+
inputSchema: import_zod18.z.object({ orderId: import_zod18.z.string().optional(), quoteId: import_zod18.z.string().optional() }),
|
|
3839
5636
|
handler: async ({ orderId, quoteId }) => textResult(await t.convertOrderStatus({ orderId, quoteId }))
|
|
3840
5637
|
}
|
|
3841
5638
|
];
|
|
3842
5639
|
}
|
|
3843
5640
|
|
|
3844
5641
|
// src/tools/ws.tools.ts
|
|
3845
|
-
var
|
|
5642
|
+
var import_zod19 = require("zod");
|
|
3846
5643
|
var buffers = /* @__PURE__ */ new Map();
|
|
3847
5644
|
var MAX_BUFFER = 500;
|
|
3848
5645
|
function bufferFor(client) {
|
|
@@ -3869,8 +5666,8 @@ function wsTools(client) {
|
|
|
3869
5666
|
{
|
|
3870
5667
|
name: "futures_ws_subscribe",
|
|
3871
5668
|
description: "Subscribe to real-time market data streams. Topic format: <symbol>@<stream>, e.g. btcusdt@aggTrade, btcusdt@kline_1m, btcusdt@depth20, btcusdt@markPrice@1s, btcusdt@bookTicker, btcusdt@ticker, btcusdt@miniTicker, btcusdt@forceOrder, or all-market topics !ticker@arr, !bookTicker, !markPrice@arr, !forceOrder@arr, !miniTicker@arr. Multiple topics can be passed at once.",
|
|
3872
|
-
inputSchema:
|
|
3873
|
-
topics:
|
|
5669
|
+
inputSchema: import_zod19.z.object({
|
|
5670
|
+
topics: import_zod19.z.array(import_zod19.z.string().min(1)).min(1).describe('Stream topics, e.g. ["btcusdt@aggTrade", "btcusdt@kline_1m"]')
|
|
3874
5671
|
}),
|
|
3875
5672
|
handler: async ({ topics }) => {
|
|
3876
5673
|
const normalized = topics.map((t) => t.trim().toLowerCase());
|
|
@@ -3882,7 +5679,7 @@ function wsTools(client) {
|
|
|
3882
5679
|
{
|
|
3883
5680
|
name: "futures_ws_unsubscribe",
|
|
3884
5681
|
description: "Unsubscribe from previously subscribed market data streams.",
|
|
3885
|
-
inputSchema:
|
|
5682
|
+
inputSchema: import_zod19.z.object({ topics: import_zod19.z.array(import_zod19.z.string().min(1)).min(1) }),
|
|
3886
5683
|
handler: async ({ topics }) => {
|
|
3887
5684
|
const normalized = topics.map((t) => t.trim().toLowerCase());
|
|
3888
5685
|
client.futures.ws.unsubscribe(normalized);
|
|
@@ -3893,19 +5690,19 @@ function wsTools(client) {
|
|
|
3893
5690
|
{
|
|
3894
5691
|
name: "futures_ws_subscriptions",
|
|
3895
5692
|
description: "List the currently subscribed WebSocket market streams for this client.",
|
|
3896
|
-
inputSchema:
|
|
5693
|
+
inputSchema: import_zod19.z.object({}),
|
|
3897
5694
|
handler: async () => textResult({ active: [...buffer.subscriptions] })
|
|
3898
5695
|
},
|
|
3899
5696
|
{
|
|
3900
5697
|
name: "futures_ws_events",
|
|
3901
5698
|
description: "Read the buffered real-time payloads received since the last read for the subscribed streams (aggregate trades, klines, depth deltas, mark price, book tickers, tickers, force orders). Payloads are parsed; depth deltas must be applied to a snapshot from futures_order_book.",
|
|
3902
|
-
inputSchema:
|
|
5699
|
+
inputSchema: import_zod19.z.object({ limit: import_zod19.z.number().int().min(1).max(200).default(50) }),
|
|
3903
5700
|
handler: async ({ limit: limit4 }) => textResult(getBufferedWsEvents(client, limit4))
|
|
3904
5701
|
},
|
|
3905
5702
|
{
|
|
3906
5703
|
name: "futures_ws_clear_events",
|
|
3907
5704
|
description: "Clear the buffered WebSocket events so the next read only returns new payloads.",
|
|
3908
|
-
inputSchema:
|
|
5705
|
+
inputSchema: import_zod19.z.object({}),
|
|
3909
5706
|
handler: async () => {
|
|
3910
5707
|
clearBufferedWsEvents(client);
|
|
3911
5708
|
return textResult({ cleared: true });
|
|
@@ -3914,13 +5711,13 @@ function wsTools(client) {
|
|
|
3914
5711
|
{
|
|
3915
5712
|
name: "futures_ws_start_user_stream",
|
|
3916
5713
|
description: "Start the user data stream: creates a listenKey, connects the private WebSocket, and begins a 30-minute keep-alive. Emits private events (ACCOUNT_UPDATE, ORDER_TRADE_UPDATE, MARGIN_CALL, ACCOUNT_CONFIG_UPDATE, listenKeyExpired) that the application can consume from the client.",
|
|
3917
|
-
inputSchema:
|
|
5714
|
+
inputSchema: import_zod19.z.object({}),
|
|
3918
5715
|
handler: async () => textResult({ listenKey: await client.startUserStream() })
|
|
3919
5716
|
},
|
|
3920
5717
|
{
|
|
3921
5718
|
name: "futures_ws_stop_user_stream",
|
|
3922
5719
|
description: "Stop the user data stream: closes the private WebSocket and invalidates the listenKey.",
|
|
3923
|
-
inputSchema:
|
|
5720
|
+
inputSchema: import_zod19.z.object({}),
|
|
3924
5721
|
handler: async () => {
|
|
3925
5722
|
client.closeUserStream();
|
|
3926
5723
|
return textResult({ stopped: true });
|
|
@@ -3929,49 +5726,49 @@ function wsTools(client) {
|
|
|
3929
5726
|
{
|
|
3930
5727
|
name: "futures_ws_api_order_status",
|
|
3931
5728
|
description: "Query an order via the signed WebSocket API (order.status) \u2014 lower-latency alternative to futures_get_order.",
|
|
3932
|
-
inputSchema:
|
|
3933
|
-
symbol:
|
|
3934
|
-
orderId:
|
|
3935
|
-
origClientOrderId:
|
|
5729
|
+
inputSchema: import_zod19.z.object({
|
|
5730
|
+
symbol: import_zod19.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
|
|
5731
|
+
orderId: import_zod19.z.number().int().positive().optional(),
|
|
5732
|
+
origClientOrderId: import_zod19.z.string().optional()
|
|
3936
5733
|
}),
|
|
3937
5734
|
handler: async ({ symbol: symbol3, orderId, origClientOrderId }) => textResult(await client.futures.wsApi.orderStatus({ symbol: normalizeSymbol(symbol3), orderId, origClientOrderId }))
|
|
3938
5735
|
},
|
|
3939
5736
|
{
|
|
3940
5737
|
name: "futures_ws_api_account_status",
|
|
3941
5738
|
description: "Get account info via the signed WebSocket API (account.status).",
|
|
3942
|
-
inputSchema:
|
|
5739
|
+
inputSchema: import_zod19.z.object({}),
|
|
3943
5740
|
handler: async () => textResult(await client.futures.wsApi.accountStatus())
|
|
3944
5741
|
},
|
|
3945
5742
|
{
|
|
3946
5743
|
name: "futures_ws_api_account_position",
|
|
3947
5744
|
description: "Get current positions via the signed WebSocket API (account.position).",
|
|
3948
|
-
inputSchema:
|
|
5745
|
+
inputSchema: import_zod19.z.object({ symbol: import_zod19.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional() }),
|
|
3949
5746
|
handler: async ({ symbol: symbol3 }) => textResult(await client.futures.wsApi.accountPosition(symbol3 ? { symbol: normalizeSymbol(symbol3) } : {}))
|
|
3950
5747
|
},
|
|
3951
5748
|
{
|
|
3952
5749
|
name: "futures_ws_api_user_data_stream_start",
|
|
3953
5750
|
description: "Create a listenKey via the signed WebSocket API (userDataStream.start) \u2014 no REST call required.",
|
|
3954
|
-
inputSchema:
|
|
5751
|
+
inputSchema: import_zod19.z.object({}),
|
|
3955
5752
|
handler: async () => textResult(await client.futures.wsApi.userDataStreamStart())
|
|
3956
5753
|
},
|
|
3957
5754
|
{
|
|
3958
5755
|
name: "futures_ws_api_user_data_stream_stop",
|
|
3959
5756
|
description: "Invalidate a listenKey via the signed WebSocket API (userDataStream.stop).",
|
|
3960
|
-
inputSchema:
|
|
5757
|
+
inputSchema: import_zod19.z.object({ listenKey: import_zod19.z.string().min(1) }),
|
|
3961
5758
|
handler: async ({ listenKey }) => textResult(await client.futures.wsApi.userDataStreamStop(listenKey))
|
|
3962
5759
|
},
|
|
3963
5760
|
{
|
|
3964
5761
|
name: "futures_ws_api_ticker_price",
|
|
3965
5762
|
description: "Get latest price via the unsigned WebSocket API (ticker.price); omit symbol for all symbols.",
|
|
3966
|
-
inputSchema:
|
|
5763
|
+
inputSchema: import_zod19.z.object({ symbol: import_zod19.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT").optional() }),
|
|
3967
5764
|
handler: async ({ symbol: symbol3 }) => textResult(await client.futures.wsApi.tickerPrice(symbol3 ? { symbol: normalizeSymbol(symbol3) } : {}))
|
|
3968
5765
|
},
|
|
3969
5766
|
{
|
|
3970
5767
|
name: "futures_ws_api_order_book",
|
|
3971
5768
|
description: "Get order-book depth via the unsigned WebSocket API (depth).",
|
|
3972
|
-
inputSchema:
|
|
3973
|
-
symbol:
|
|
3974
|
-
limit:
|
|
5769
|
+
inputSchema: import_zod19.z.object({
|
|
5770
|
+
symbol: import_zod19.z.string().min(1).describe("USD-M pair, e.g. BTCUSDT"),
|
|
5771
|
+
limit: import_zod19.z.enum(["5", "10", "20", "50", "100", "500", "1000"]).optional()
|
|
3975
5772
|
}),
|
|
3976
5773
|
handler: async ({ symbol: symbol3, limit: limit4 }) => textResult(await client.futures.wsApi.depth({ symbol: normalizeSymbol(symbol3), limit: limit4 }))
|
|
3977
5774
|
}
|
|
@@ -4004,7 +5801,7 @@ function createFuturesToolkit(client) {
|
|
|
4004
5801
|
|
|
4005
5802
|
// src/mcp/server.ts
|
|
4006
5803
|
function createBinanceMcpServer(client) {
|
|
4007
|
-
const server = new import_mcp.McpServer({ name: "binance-sdk", version: "
|
|
5804
|
+
const server = new import_mcp.McpServer({ name: "binance-sdk", version: "2.0.0" });
|
|
4008
5805
|
const toolkit = createFuturesToolkit(client);
|
|
4009
5806
|
toolkit.tools.forEach((tool) => {
|
|
4010
5807
|
server.registerTool(tool.name, { description: tool.description, inputSchema: tool.inputSchema }, async (args) => ({
|