toobit-trade-cli 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/dist/index.js +27 -877
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
- // packages/core/dist/index.js
1
+ #!/usr/bin/env node
2
+
3
+ // ../core/dist/index.js
2
4
  import { createHmac } from "crypto";
3
5
  import * as fs from "fs";
4
6
  import * as path from "path";
@@ -6,6 +8,7 @@ import * as os from "os";
6
8
  import { readFileSync as readFileSync2, writeFileSync, mkdirSync, existsSync as existsSync2 } from "fs";
7
9
  import { join as join2, dirname } from "path";
8
10
  import { homedir as homedir2 } from "os";
11
+ import { parse, stringify } from "smol-toml";
9
12
  function getTimestamp() {
10
13
  return Date.now();
11
14
  }
@@ -18,12 +21,12 @@ var ToobitMcpError = class extends Error {
18
21
  suggestion;
19
22
  endpoint;
20
23
  constructor(type, message, options) {
21
- super(message, (options == null ? void 0 : options.cause) ? { cause: options.cause } : void 0);
24
+ super(message, options?.cause ? { cause: options.cause } : void 0);
22
25
  this.name = type;
23
26
  this.type = type;
24
- this.code = options == null ? void 0 : options.code;
25
- this.suggestion = options == null ? void 0 : options.suggestion;
26
- this.endpoint = options == null ? void 0 : options.endpoint;
27
+ this.code = options?.code;
28
+ this.suggestion = options?.suggestion;
29
+ this.endpoint = options?.endpoint;
27
30
  }
28
31
  };
29
32
  var ConfigError = class extends ToobitMcpError {
@@ -295,7 +298,7 @@ var ToobitRestClient = class {
295
298
  if (codeStr === "-1002" || codeStr === "-1022" || codeStr === "-1107" || codeStr === "-2014" || codeStr === "-2015" || codeStr === "-2017") {
296
299
  throw new AuthenticationError(
297
300
  message,
298
- (behavior == null ? void 0 : behavior.suggestion) ?? "Check API key, secret key and permissions.",
301
+ behavior?.suggestion ?? "Check API key, secret key and permissions.",
299
302
  endpoint
300
303
  );
301
304
  }
@@ -305,7 +308,7 @@ var ToobitRestClient = class {
305
308
  throw new ToobitApiError(message, {
306
309
  code: codeStr,
307
310
  endpoint,
308
- suggestion: behavior == null ? void 0 : behavior.suggestion
311
+ suggestion: behavior?.suggestion
309
312
  });
310
313
  }
311
314
  if (!response.ok) {
@@ -685,7 +688,7 @@ function registerFuturesTools() {
685
688
  quantity: { type: "string", description: "Order quantity (contracts)" },
686
689
  price: { type: "string", description: "Required for LIMIT orders with priceType=INPUT" },
687
690
  leverage: { type: "string", description: "IGNORED by place-order API. Use futures_set_leverage to set leverage before placing orders." },
688
- newClientOrderId: { type: "string", description: "Unique client order ID. Auto-generated if omitted." },
691
+ newClientOrderId: { type: "string", description: "Unique client order ID. Auto-generated if omitted. Only [a-zA-Z0-9_\\-.] allowed; other characters are stripped." },
689
692
  priceType: { type: "string", enum: ["INPUT", "OPPONENT", "QUEUE", "OVER", "MARKET"], description: "Price type. INPUT=specified price, MARKET=market price" },
690
693
  stopPrice: { type: "string", description: "Trigger price for STOP orders" },
691
694
  timeInForce: { type: "string", enum: ["GTC", "IOC", "FOK"] }
@@ -701,7 +704,7 @@ function registerFuturesTools() {
701
704
  priceType = "MARKET";
702
705
  }
703
706
  const rawClientId = readString(args, "newClientOrderId");
704
- const clientId = rawClientId ? rawClientId.replace(/[<>"'&]/g, "") : `mcp_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
707
+ const clientId = rawClientId ? rawClientId.replace(/[^a-zA-Z0-9_\-\.]/g, "") : `mcp_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
705
708
  const response = await context.client.privatePost(
706
709
  "/api/v1/futures/order",
707
710
  compactObject({
@@ -1829,15 +1832,14 @@ function registerSpotTradeTools() {
1829
1832
  symbol: { type: "string", description: "e.g. BTCUSDT" },
1830
1833
  side: { type: "string", enum: ["BUY", "SELL"] },
1831
1834
  type: { type: "string", enum: ["LIMIT", "MARKET", "LIMIT_MAKER"], description: "Order type" },
1832
- quantity: { type: "string", description: "Order quantity in base asset (e.g. BTC amount). For MARKET BUY, this is the base asset quantity to purchase." },
1835
+ quantity: { type: "string", description: "For LIMIT/LIMIT_MAKER: base asset quantity (e.g. 0.001 BTC). For MARKET SELL: base asset quantity to sell. For MARKET BUY: quote asset amount to spend (e.g. 50 means spend 50 USDT)." },
1833
1836
  price: { type: "string", description: "Order price (required for LIMIT)" },
1834
- newClientOrderId: { type: "string", description: "Client order ID" },
1837
+ newClientOrderId: { type: "string", description: "Client order ID. Only [a-zA-Z0-9_\\-.] allowed; other characters are stripped." },
1835
1838
  timeInForce: { type: "string", enum: ["GTC", "IOC", "FOK"], description: "Default GTC" }
1836
1839
  },
1837
1840
  required: ["symbol", "side", "type", "quantity"]
1838
1841
  },
1839
1842
  handler: async (rawArgs, context) => {
1840
- var _a;
1841
1843
  const args = asRecord(rawArgs);
1842
1844
  const response = await context.client.privatePost(
1843
1845
  "/api/v1/spot/order",
@@ -1847,7 +1849,7 @@ function registerSpotTradeTools() {
1847
1849
  type: requireString(args, "type"),
1848
1850
  quantity: requireString(args, "quantity"),
1849
1851
  price: readString(args, "price"),
1850
- newClientOrderId: (_a = readString(args, "newClientOrderId")) == null ? void 0 : _a.replace(/[<>"'&]/g, ""),
1852
+ newClientOrderId: readString(args, "newClientOrderId")?.replace(/[^a-zA-Z0-9_\-\.]/g, ""),
1851
1853
  timeInForce: readString(args, "timeInForce")
1852
1854
  }),
1853
1855
  privateRateLimit("spot_place_order", 50)
@@ -2117,817 +2119,6 @@ function createToolRunner(client, config) {
2117
2119
  return result;
2118
2120
  };
2119
2121
  }
2120
- function getLineColFromPtr(string, ptr) {
2121
- let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
2122
- return [lines.length, lines.pop().length + 1];
2123
- }
2124
- function makeCodeBlock(string, line, column) {
2125
- let lines = string.split(/\r\n|\n|\r/g);
2126
- let codeblock = "";
2127
- let numberLen = (Math.log10(line + 1) | 0) + 1;
2128
- for (let i = line - 1; i <= line + 1; i++) {
2129
- let l = lines[i - 1];
2130
- if (!l)
2131
- continue;
2132
- codeblock += i.toString().padEnd(numberLen, " ");
2133
- codeblock += ": ";
2134
- codeblock += l;
2135
- codeblock += "\n";
2136
- if (i === line) {
2137
- codeblock += " ".repeat(numberLen + column + 2);
2138
- codeblock += "^\n";
2139
- }
2140
- }
2141
- return codeblock;
2142
- }
2143
- var TomlError = class extends Error {
2144
- line;
2145
- column;
2146
- codeblock;
2147
- constructor(message, options) {
2148
- const [line, column] = getLineColFromPtr(options.toml, options.ptr);
2149
- const codeblock = makeCodeBlock(options.toml, line, column);
2150
- super(`Invalid TOML document: ${message}
2151
-
2152
- ${codeblock}`, options);
2153
- this.line = line;
2154
- this.column = column;
2155
- this.codeblock = codeblock;
2156
- }
2157
- };
2158
- function isEscaped(str, ptr) {
2159
- let i = 0;
2160
- while (str[ptr - ++i] === "\\")
2161
- ;
2162
- return --i && i % 2;
2163
- }
2164
- function indexOfNewline(str, start = 0, end = str.length) {
2165
- let idx = str.indexOf("\n", start);
2166
- if (str[idx - 1] === "\r")
2167
- idx--;
2168
- return idx <= end ? idx : -1;
2169
- }
2170
- function skipComment(str, ptr) {
2171
- for (let i = ptr; i < str.length; i++) {
2172
- let c = str[i];
2173
- if (c === "\n")
2174
- return i;
2175
- if (c === "\r" && str[i + 1] === "\n")
2176
- return i + 1;
2177
- if (c < " " && c !== " " || c === "\x7F") {
2178
- throw new TomlError("control characters are not allowed in comments", {
2179
- toml: str,
2180
- ptr
2181
- });
2182
- }
2183
- }
2184
- return str.length;
2185
- }
2186
- function skipVoid(str, ptr, banNewLines, banComments) {
2187
- let c;
2188
- while ((c = str[ptr]) === " " || c === " " || !banNewLines && (c === "\n" || c === "\r" && str[ptr + 1] === "\n"))
2189
- ptr++;
2190
- return banComments || c !== "#" ? ptr : skipVoid(str, skipComment(str, ptr), banNewLines);
2191
- }
2192
- function skipUntil(str, ptr, sep, end, banNewLines = false) {
2193
- if (!end) {
2194
- ptr = indexOfNewline(str, ptr);
2195
- return ptr < 0 ? str.length : ptr;
2196
- }
2197
- for (let i = ptr; i < str.length; i++) {
2198
- let c = str[i];
2199
- if (c === "#") {
2200
- i = indexOfNewline(str, i);
2201
- } else if (c === sep) {
2202
- return i + 1;
2203
- } else if (c === end || banNewLines && (c === "\n" || c === "\r" && str[i + 1] === "\n")) {
2204
- return i;
2205
- }
2206
- }
2207
- throw new TomlError("cannot find end of structure", {
2208
- toml: str,
2209
- ptr
2210
- });
2211
- }
2212
- function getStringEnd(str, seek) {
2213
- let first = str[seek];
2214
- let target = first === str[seek + 1] && str[seek + 1] === str[seek + 2] ? str.slice(seek, seek + 3) : first;
2215
- seek += target.length - 1;
2216
- do
2217
- seek = str.indexOf(target, ++seek);
2218
- while (seek > -1 && first !== "'" && isEscaped(str, seek));
2219
- if (seek > -1) {
2220
- seek += target.length;
2221
- if (target.length > 1) {
2222
- if (str[seek] === first)
2223
- seek++;
2224
- if (str[seek] === first)
2225
- seek++;
2226
- }
2227
- }
2228
- return seek;
2229
- }
2230
- var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
2231
- var TomlDate = class _TomlDate extends Date {
2232
- #hasDate = false;
2233
- #hasTime = false;
2234
- #offset = null;
2235
- constructor(date) {
2236
- let hasDate = true;
2237
- let hasTime = true;
2238
- let offset = "Z";
2239
- if (typeof date === "string") {
2240
- let match = date.match(DATE_TIME_RE);
2241
- if (match) {
2242
- if (!match[1]) {
2243
- hasDate = false;
2244
- date = `0000-01-01T${date}`;
2245
- }
2246
- hasTime = !!match[2];
2247
- hasTime && date[10] === " " && (date = date.replace(" ", "T"));
2248
- if (match[2] && +match[2] > 23) {
2249
- date = "";
2250
- } else {
2251
- offset = match[3] || null;
2252
- date = date.toUpperCase();
2253
- if (!offset && hasTime)
2254
- date += "Z";
2255
- }
2256
- } else {
2257
- date = "";
2258
- }
2259
- }
2260
- super(date);
2261
- if (!isNaN(this.getTime())) {
2262
- this.#hasDate = hasDate;
2263
- this.#hasTime = hasTime;
2264
- this.#offset = offset;
2265
- }
2266
- }
2267
- isDateTime() {
2268
- return this.#hasDate && this.#hasTime;
2269
- }
2270
- isLocal() {
2271
- return !this.#hasDate || !this.#hasTime || !this.#offset;
2272
- }
2273
- isDate() {
2274
- return this.#hasDate && !this.#hasTime;
2275
- }
2276
- isTime() {
2277
- return this.#hasTime && !this.#hasDate;
2278
- }
2279
- isValid() {
2280
- return this.#hasDate || this.#hasTime;
2281
- }
2282
- toISOString() {
2283
- let iso = super.toISOString();
2284
- if (this.isDate())
2285
- return iso.slice(0, 10);
2286
- if (this.isTime())
2287
- return iso.slice(11, 23);
2288
- if (this.#offset === null)
2289
- return iso.slice(0, -1);
2290
- if (this.#offset === "Z")
2291
- return iso;
2292
- let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
2293
- offset = this.#offset[0] === "-" ? offset : -offset;
2294
- let offsetDate = new Date(this.getTime() - offset * 6e4);
2295
- return offsetDate.toISOString().slice(0, -1) + this.#offset;
2296
- }
2297
- static wrapAsOffsetDateTime(jsDate, offset = "Z") {
2298
- let date = new _TomlDate(jsDate);
2299
- date.#offset = offset;
2300
- return date;
2301
- }
2302
- static wrapAsLocalDateTime(jsDate) {
2303
- let date = new _TomlDate(jsDate);
2304
- date.#offset = null;
2305
- return date;
2306
- }
2307
- static wrapAsLocalDate(jsDate) {
2308
- let date = new _TomlDate(jsDate);
2309
- date.#hasTime = false;
2310
- date.#offset = null;
2311
- return date;
2312
- }
2313
- static wrapAsLocalTime(jsDate) {
2314
- let date = new _TomlDate(jsDate);
2315
- date.#hasDate = false;
2316
- date.#offset = null;
2317
- return date;
2318
- }
2319
- };
2320
- var INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
2321
- var FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
2322
- var LEADING_ZERO = /^[+-]?0[0-9_]/;
2323
- var ESCAPE_REGEX = /^[0-9a-f]{2,8}$/i;
2324
- var ESC_MAP = {
2325
- b: "\b",
2326
- t: " ",
2327
- n: "\n",
2328
- f: "\f",
2329
- r: "\r",
2330
- e: "\x1B",
2331
- '"': '"',
2332
- "\\": "\\"
2333
- };
2334
- function parseString(str, ptr = 0, endPtr = str.length) {
2335
- let isLiteral = str[ptr] === "'";
2336
- let isMultiline = str[ptr++] === str[ptr] && str[ptr] === str[ptr + 1];
2337
- if (isMultiline) {
2338
- endPtr -= 2;
2339
- if (str[ptr += 2] === "\r")
2340
- ptr++;
2341
- if (str[ptr] === "\n")
2342
- ptr++;
2343
- }
2344
- let tmp = 0;
2345
- let isEscape;
2346
- let parsed = "";
2347
- let sliceStart = ptr;
2348
- while (ptr < endPtr - 1) {
2349
- let c = str[ptr++];
2350
- if (c === "\n" || c === "\r" && str[ptr] === "\n") {
2351
- if (!isMultiline) {
2352
- throw new TomlError("newlines are not allowed in strings", {
2353
- toml: str,
2354
- ptr: ptr - 1
2355
- });
2356
- }
2357
- } else if (c < " " && c !== " " || c === "\x7F") {
2358
- throw new TomlError("control characters are not allowed in strings", {
2359
- toml: str,
2360
- ptr: ptr - 1
2361
- });
2362
- }
2363
- if (isEscape) {
2364
- isEscape = false;
2365
- if (c === "x" || c === "u" || c === "U") {
2366
- let code = str.slice(ptr, ptr += c === "x" ? 2 : c === "u" ? 4 : 8);
2367
- if (!ESCAPE_REGEX.test(code)) {
2368
- throw new TomlError("invalid unicode escape", {
2369
- toml: str,
2370
- ptr: tmp
2371
- });
2372
- }
2373
- try {
2374
- parsed += String.fromCodePoint(parseInt(code, 16));
2375
- } catch {
2376
- throw new TomlError("invalid unicode escape", {
2377
- toml: str,
2378
- ptr: tmp
2379
- });
2380
- }
2381
- } else if (isMultiline && (c === "\n" || c === " " || c === " " || c === "\r")) {
2382
- ptr = skipVoid(str, ptr - 1, true);
2383
- if (str[ptr] !== "\n" && str[ptr] !== "\r") {
2384
- throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
2385
- toml: str,
2386
- ptr: tmp
2387
- });
2388
- }
2389
- ptr = skipVoid(str, ptr);
2390
- } else if (c in ESC_MAP) {
2391
- parsed += ESC_MAP[c];
2392
- } else {
2393
- throw new TomlError("unrecognized escape sequence", {
2394
- toml: str,
2395
- ptr: tmp
2396
- });
2397
- }
2398
- sliceStart = ptr;
2399
- } else if (!isLiteral && c === "\\") {
2400
- tmp = ptr - 1;
2401
- isEscape = true;
2402
- parsed += str.slice(sliceStart, tmp);
2403
- }
2404
- }
2405
- return parsed + str.slice(sliceStart, endPtr - 1);
2406
- }
2407
- function parseValue(value, toml, ptr, integersAsBigInt) {
2408
- if (value === "true")
2409
- return true;
2410
- if (value === "false")
2411
- return false;
2412
- if (value === "-inf")
2413
- return -Infinity;
2414
- if (value === "inf" || value === "+inf")
2415
- return Infinity;
2416
- if (value === "nan" || value === "+nan" || value === "-nan")
2417
- return NaN;
2418
- if (value === "-0")
2419
- return integersAsBigInt ? 0n : 0;
2420
- let isInt = INT_REGEX.test(value);
2421
- if (isInt || FLOAT_REGEX.test(value)) {
2422
- if (LEADING_ZERO.test(value)) {
2423
- throw new TomlError("leading zeroes are not allowed", {
2424
- toml,
2425
- ptr
2426
- });
2427
- }
2428
- value = value.replace(/_/g, "");
2429
- let numeric = +value;
2430
- if (isNaN(numeric)) {
2431
- throw new TomlError("invalid number", {
2432
- toml,
2433
- ptr
2434
- });
2435
- }
2436
- if (isInt) {
2437
- if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) {
2438
- throw new TomlError("integer value cannot be represented losslessly", {
2439
- toml,
2440
- ptr
2441
- });
2442
- }
2443
- if (isInt || integersAsBigInt === true)
2444
- numeric = BigInt(value);
2445
- }
2446
- return numeric;
2447
- }
2448
- const date = new TomlDate(value);
2449
- if (!date.isValid()) {
2450
- throw new TomlError("invalid value", {
2451
- toml,
2452
- ptr
2453
- });
2454
- }
2455
- return date;
2456
- }
2457
- function sliceAndTrimEndOf(str, startPtr, endPtr) {
2458
- let value = str.slice(startPtr, endPtr);
2459
- let commentIdx = value.indexOf("#");
2460
- if (commentIdx > -1) {
2461
- skipComment(str, commentIdx);
2462
- value = value.slice(0, commentIdx);
2463
- }
2464
- return [value.trimEnd(), commentIdx];
2465
- }
2466
- function extractValue(str, ptr, end, depth, integersAsBigInt) {
2467
- if (depth === 0) {
2468
- throw new TomlError("document contains excessively nested structures. aborting.", {
2469
- toml: str,
2470
- ptr
2471
- });
2472
- }
2473
- let c = str[ptr];
2474
- if (c === "[" || c === "{") {
2475
- let [value, endPtr2] = c === "[" ? parseArray(str, ptr, depth, integersAsBigInt) : parseInlineTable(str, ptr, depth, integersAsBigInt);
2476
- if (end) {
2477
- endPtr2 = skipVoid(str, endPtr2);
2478
- if (str[endPtr2] === ",")
2479
- endPtr2++;
2480
- else if (str[endPtr2] !== end) {
2481
- throw new TomlError("expected comma or end of structure", {
2482
- toml: str,
2483
- ptr: endPtr2
2484
- });
2485
- }
2486
- }
2487
- return [value, endPtr2];
2488
- }
2489
- let endPtr;
2490
- if (c === '"' || c === "'") {
2491
- endPtr = getStringEnd(str, ptr);
2492
- let parsed = parseString(str, ptr, endPtr);
2493
- if (end) {
2494
- endPtr = skipVoid(str, endPtr);
2495
- if (str[endPtr] && str[endPtr] !== "," && str[endPtr] !== end && str[endPtr] !== "\n" && str[endPtr] !== "\r") {
2496
- throw new TomlError("unexpected character encountered", {
2497
- toml: str,
2498
- ptr: endPtr
2499
- });
2500
- }
2501
- endPtr += +(str[endPtr] === ",");
2502
- }
2503
- return [parsed, endPtr];
2504
- }
2505
- endPtr = skipUntil(str, ptr, ",", end);
2506
- let slice = sliceAndTrimEndOf(str, ptr, endPtr - +(str[endPtr - 1] === ","));
2507
- if (!slice[0]) {
2508
- throw new TomlError("incomplete key-value declaration: no value specified", {
2509
- toml: str,
2510
- ptr
2511
- });
2512
- }
2513
- if (end && slice[1] > -1) {
2514
- endPtr = skipVoid(str, ptr + slice[1]);
2515
- endPtr += +(str[endPtr] === ",");
2516
- }
2517
- return [
2518
- parseValue(slice[0], str, ptr, integersAsBigInt),
2519
- endPtr
2520
- ];
2521
- }
2522
- var KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
2523
- function parseKey(str, ptr, end = "=") {
2524
- let dot = ptr - 1;
2525
- let parsed = [];
2526
- let endPtr = str.indexOf(end, ptr);
2527
- if (endPtr < 0) {
2528
- throw new TomlError("incomplete key-value: cannot find end of key", {
2529
- toml: str,
2530
- ptr
2531
- });
2532
- }
2533
- do {
2534
- let c = str[ptr = ++dot];
2535
- if (c !== " " && c !== " ") {
2536
- if (c === '"' || c === "'") {
2537
- if (c === str[ptr + 1] && c === str[ptr + 2]) {
2538
- throw new TomlError("multiline strings are not allowed in keys", {
2539
- toml: str,
2540
- ptr
2541
- });
2542
- }
2543
- let eos = getStringEnd(str, ptr);
2544
- if (eos < 0) {
2545
- throw new TomlError("unfinished string encountered", {
2546
- toml: str,
2547
- ptr
2548
- });
2549
- }
2550
- dot = str.indexOf(".", eos);
2551
- let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot);
2552
- let newLine = indexOfNewline(strEnd);
2553
- if (newLine > -1) {
2554
- throw new TomlError("newlines are not allowed in keys", {
2555
- toml: str,
2556
- ptr: ptr + dot + newLine
2557
- });
2558
- }
2559
- if (strEnd.trimStart()) {
2560
- throw new TomlError("found extra tokens after the string part", {
2561
- toml: str,
2562
- ptr: eos
2563
- });
2564
- }
2565
- if (endPtr < eos) {
2566
- endPtr = str.indexOf(end, eos);
2567
- if (endPtr < 0) {
2568
- throw new TomlError("incomplete key-value: cannot find end of key", {
2569
- toml: str,
2570
- ptr
2571
- });
2572
- }
2573
- }
2574
- parsed.push(parseString(str, ptr, eos));
2575
- } else {
2576
- dot = str.indexOf(".", ptr);
2577
- let part = str.slice(ptr, dot < 0 || dot > endPtr ? endPtr : dot);
2578
- if (!KEY_PART_RE.test(part)) {
2579
- throw new TomlError("only letter, numbers, dashes and underscores are allowed in keys", {
2580
- toml: str,
2581
- ptr
2582
- });
2583
- }
2584
- parsed.push(part.trimEnd());
2585
- }
2586
- }
2587
- } while (dot + 1 && dot < endPtr);
2588
- return [parsed, skipVoid(str, endPtr + 1, true, true)];
2589
- }
2590
- function parseInlineTable(str, ptr, depth, integersAsBigInt) {
2591
- let res = {};
2592
- let seen = /* @__PURE__ */ new Set();
2593
- let c;
2594
- ptr++;
2595
- while ((c = str[ptr++]) !== "}" && c) {
2596
- if (c === ",") {
2597
- throw new TomlError("expected value, found comma", {
2598
- toml: str,
2599
- ptr: ptr - 1
2600
- });
2601
- } else if (c === "#")
2602
- ptr = skipComment(str, ptr);
2603
- else if (c !== " " && c !== " " && c !== "\n" && c !== "\r") {
2604
- let k;
2605
- let t = res;
2606
- let hasOwn = false;
2607
- let [key, keyEndPtr] = parseKey(str, ptr - 1);
2608
- for (let i = 0; i < key.length; i++) {
2609
- if (i)
2610
- t = hasOwn ? t[k] : t[k] = {};
2611
- k = key[i];
2612
- if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
2613
- throw new TomlError("trying to redefine an already defined value", {
2614
- toml: str,
2615
- ptr
2616
- });
2617
- }
2618
- if (!hasOwn && k === "__proto__") {
2619
- Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
2620
- }
2621
- }
2622
- if (hasOwn) {
2623
- throw new TomlError("trying to redefine an already defined value", {
2624
- toml: str,
2625
- ptr
2626
- });
2627
- }
2628
- let [value, valueEndPtr] = extractValue(str, keyEndPtr, "}", depth - 1, integersAsBigInt);
2629
- seen.add(value);
2630
- t[k] = value;
2631
- ptr = valueEndPtr;
2632
- }
2633
- }
2634
- if (!c) {
2635
- throw new TomlError("unfinished table encountered", {
2636
- toml: str,
2637
- ptr
2638
- });
2639
- }
2640
- return [res, ptr];
2641
- }
2642
- function parseArray(str, ptr, depth, integersAsBigInt) {
2643
- let res = [];
2644
- let c;
2645
- ptr++;
2646
- while ((c = str[ptr++]) !== "]" && c) {
2647
- if (c === ",") {
2648
- throw new TomlError("expected value, found comma", {
2649
- toml: str,
2650
- ptr: ptr - 1
2651
- });
2652
- } else if (c === "#")
2653
- ptr = skipComment(str, ptr);
2654
- else if (c !== " " && c !== " " && c !== "\n" && c !== "\r") {
2655
- let e = extractValue(str, ptr - 1, "]", depth - 1, integersAsBigInt);
2656
- res.push(e[0]);
2657
- ptr = e[1];
2658
- }
2659
- }
2660
- if (!c) {
2661
- throw new TomlError("unfinished array encountered", {
2662
- toml: str,
2663
- ptr
2664
- });
2665
- }
2666
- return [res, ptr];
2667
- }
2668
- function peekTable(key, table, meta, type) {
2669
- var _a, _b;
2670
- let t = table;
2671
- let m = meta;
2672
- let k;
2673
- let hasOwn = false;
2674
- let state;
2675
- for (let i = 0; i < key.length; i++) {
2676
- if (i) {
2677
- t = hasOwn ? t[k] : t[k] = {};
2678
- m = (state = m[k]).c;
2679
- if (type === 0 && (state.t === 1 || state.t === 2)) {
2680
- return null;
2681
- }
2682
- if (state.t === 2) {
2683
- let l = t.length - 1;
2684
- t = t[l];
2685
- m = m[l].c;
2686
- }
2687
- }
2688
- k = key[i];
2689
- if ((hasOwn = Object.hasOwn(t, k)) && ((_a = m[k]) == null ? void 0 : _a.t) === 0 && ((_b = m[k]) == null ? void 0 : _b.d)) {
2690
- return null;
2691
- }
2692
- if (!hasOwn) {
2693
- if (k === "__proto__") {
2694
- Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
2695
- Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
2696
- }
2697
- m[k] = {
2698
- t: i < key.length - 1 && type === 2 ? 3 : type,
2699
- d: false,
2700
- i: 0,
2701
- c: {}
2702
- };
2703
- }
2704
- }
2705
- state = m[k];
2706
- if (state.t !== type && !(type === 1 && state.t === 3)) {
2707
- return null;
2708
- }
2709
- if (type === 2) {
2710
- if (!state.d) {
2711
- state.d = true;
2712
- t[k] = [];
2713
- }
2714
- t[k].push(t = {});
2715
- state.c[state.i++] = state = { t: 1, d: false, i: 0, c: {} };
2716
- }
2717
- if (state.d) {
2718
- return null;
2719
- }
2720
- state.d = true;
2721
- if (type === 1) {
2722
- t = hasOwn ? t[k] : t[k] = {};
2723
- } else if (type === 0 && hasOwn) {
2724
- return null;
2725
- }
2726
- return [k, t, state.c];
2727
- }
2728
- function parse(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
2729
- let res = {};
2730
- let meta = {};
2731
- let tbl = res;
2732
- let m = meta;
2733
- for (let ptr = skipVoid(toml, 0); ptr < toml.length; ) {
2734
- if (toml[ptr] === "[") {
2735
- let isTableArray = toml[++ptr] === "[";
2736
- let k = parseKey(toml, ptr += +isTableArray, "]");
2737
- if (isTableArray) {
2738
- if (toml[k[1] - 1] !== "]") {
2739
- throw new TomlError("expected end of table declaration", {
2740
- toml,
2741
- ptr: k[1] - 1
2742
- });
2743
- }
2744
- k[1]++;
2745
- }
2746
- let p = peekTable(
2747
- k[0],
2748
- res,
2749
- meta,
2750
- isTableArray ? 2 : 1
2751
- /* Type.EXPLICIT */
2752
- );
2753
- if (!p) {
2754
- throw new TomlError("trying to redefine an already defined table or value", {
2755
- toml,
2756
- ptr
2757
- });
2758
- }
2759
- m = p[2];
2760
- tbl = p[1];
2761
- ptr = k[1];
2762
- } else {
2763
- let k = parseKey(toml, ptr);
2764
- let p = peekTable(
2765
- k[0],
2766
- tbl,
2767
- m,
2768
- 0
2769
- /* Type.DOTTED */
2770
- );
2771
- if (!p) {
2772
- throw new TomlError("trying to redefine an already defined table or value", {
2773
- toml,
2774
- ptr
2775
- });
2776
- }
2777
- let v = extractValue(toml, k[1], void 0, maxDepth, integersAsBigInt);
2778
- p[1][p[0]] = v[0];
2779
- ptr = v[1];
2780
- }
2781
- ptr = skipVoid(toml, ptr, true);
2782
- if (toml[ptr] && toml[ptr] !== "\n" && toml[ptr] !== "\r") {
2783
- throw new TomlError("each key-value declaration must be followed by an end-of-line", {
2784
- toml,
2785
- ptr
2786
- });
2787
- }
2788
- ptr = skipVoid(toml, ptr);
2789
- }
2790
- return res;
2791
- }
2792
- var BARE_KEY = /^[a-z0-9-_]+$/i;
2793
- function extendedTypeOf(obj) {
2794
- let type = typeof obj;
2795
- if (type === "object") {
2796
- if (Array.isArray(obj))
2797
- return "array";
2798
- if (obj instanceof Date)
2799
- return "date";
2800
- }
2801
- return type;
2802
- }
2803
- function isArrayOfTables(obj) {
2804
- for (let i = 0; i < obj.length; i++) {
2805
- if (extendedTypeOf(obj[i]) !== "object")
2806
- return false;
2807
- }
2808
- return obj.length != 0;
2809
- }
2810
- function formatString(s) {
2811
- return JSON.stringify(s).replace(/\x7f/g, "\\u007f");
2812
- }
2813
- function stringifyValue(val, type, depth, numberAsFloat) {
2814
- if (depth === 0) {
2815
- throw new Error("Could not stringify the object: maximum object depth exceeded");
2816
- }
2817
- if (type === "number") {
2818
- if (isNaN(val))
2819
- return "nan";
2820
- if (val === Infinity)
2821
- return "inf";
2822
- if (val === -Infinity)
2823
- return "-inf";
2824
- if (numberAsFloat && Number.isInteger(val))
2825
- return val.toFixed(1);
2826
- return val.toString();
2827
- }
2828
- if (type === "bigint" || type === "boolean") {
2829
- return val.toString();
2830
- }
2831
- if (type === "string") {
2832
- return formatString(val);
2833
- }
2834
- if (type === "date") {
2835
- if (isNaN(val.getTime())) {
2836
- throw new TypeError("cannot serialize invalid date");
2837
- }
2838
- return val.toISOString();
2839
- }
2840
- if (type === "object") {
2841
- return stringifyInlineTable(val, depth, numberAsFloat);
2842
- }
2843
- if (type === "array") {
2844
- return stringifyArray(val, depth, numberAsFloat);
2845
- }
2846
- }
2847
- function stringifyInlineTable(obj, depth, numberAsFloat) {
2848
- let keys = Object.keys(obj);
2849
- if (keys.length === 0)
2850
- return "{}";
2851
- let res = "{ ";
2852
- for (let i = 0; i < keys.length; i++) {
2853
- let k = keys[i];
2854
- if (i)
2855
- res += ", ";
2856
- res += BARE_KEY.test(k) ? k : formatString(k);
2857
- res += " = ";
2858
- res += stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat);
2859
- }
2860
- return res + " }";
2861
- }
2862
- function stringifyArray(array, depth, numberAsFloat) {
2863
- if (array.length === 0)
2864
- return "[]";
2865
- let res = "[ ";
2866
- for (let i = 0; i < array.length; i++) {
2867
- if (i)
2868
- res += ", ";
2869
- if (array[i] === null || array[i] === void 0) {
2870
- throw new TypeError("arrays cannot contain null or undefined values");
2871
- }
2872
- res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat);
2873
- }
2874
- return res + " ]";
2875
- }
2876
- function stringifyArrayTable(array, key, depth, numberAsFloat) {
2877
- if (depth === 0) {
2878
- throw new Error("Could not stringify the object: maximum object depth exceeded");
2879
- }
2880
- let res = "";
2881
- for (let i = 0; i < array.length; i++) {
2882
- res += `${res && "\n"}[[${key}]]
2883
- `;
2884
- res += stringifyTable(0, array[i], key, depth, numberAsFloat);
2885
- }
2886
- return res;
2887
- }
2888
- function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
2889
- if (depth === 0) {
2890
- throw new Error("Could not stringify the object: maximum object depth exceeded");
2891
- }
2892
- let preamble = "";
2893
- let tables = "";
2894
- let keys = Object.keys(obj);
2895
- for (let i = 0; i < keys.length; i++) {
2896
- let k = keys[i];
2897
- if (obj[k] !== null && obj[k] !== void 0) {
2898
- let type = extendedTypeOf(obj[k]);
2899
- if (type === "symbol" || type === "function") {
2900
- throw new TypeError(`cannot serialize values of type '${type}'`);
2901
- }
2902
- let key = BARE_KEY.test(k) ? k : formatString(k);
2903
- if (type === "array" && isArrayOfTables(obj[k])) {
2904
- tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
2905
- } else if (type === "object") {
2906
- let tblKey = prefix ? `${prefix}.${key}` : key;
2907
- tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
2908
- } else {
2909
- preamble += key;
2910
- preamble += " = ";
2911
- preamble += stringifyValue(obj[k], type, depth, numberAsFloat);
2912
- preamble += "\n";
2913
- }
2914
- }
2915
- }
2916
- if (tableKey && (preamble || !tables))
2917
- preamble = preamble ? `[${tableKey}]
2918
- ${preamble}` : `[${tableKey}]`;
2919
- return preamble && tables ? `${preamble}
2920
- ${tables}` : preamble || tables;
2921
- }
2922
- function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
2923
- if (extendedTypeOf(obj) !== "object") {
2924
- throw new TypeError("stringify can only be called with an object");
2925
- }
2926
- let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
2927
- if (str[str.length - 1] !== "\n")
2928
- return str + "\n";
2929
- return str;
2930
- }
2931
2122
  function configFilePath() {
2932
2123
  return join2(homedir2(), ".toobit", "config.toml");
2933
2124
  }
@@ -2938,10 +2129,9 @@ function readFullConfig() {
2938
2129
  return parse(raw);
2939
2130
  }
2940
2131
  function readTomlProfile(profileName) {
2941
- var _a;
2942
2132
  const config = readFullConfig();
2943
2133
  const name = profileName ?? config.default_profile ?? "default";
2944
- return ((_a = config.profiles) == null ? void 0 : _a[name]) ?? {};
2134
+ return config.profiles?.[name] ?? {};
2945
2135
  }
2946
2136
  function writeFullConfig(config) {
2947
2137
  const path4 = configFilePath();
@@ -2976,10 +2166,9 @@ function parseModuleList(rawModules) {
2976
2166
  return Array.from(deduped);
2977
2167
  }
2978
2168
  function loadConfig(cli) {
2979
- var _a, _b, _c;
2980
2169
  const toml = readTomlProfile(cli.profile);
2981
- const apiKey = ((_a = process.env.TOOBIT_API_KEY) == null ? void 0 : _a.trim()) ?? toml.api_key;
2982
- const secretKey = ((_b = process.env.TOOBIT_SECRET_KEY) == null ? void 0 : _b.trim()) ?? toml.secret_key;
2170
+ const apiKey = process.env.TOOBIT_API_KEY?.trim() ?? toml.api_key;
2171
+ const secretKey = process.env.TOOBIT_SECRET_KEY?.trim() ?? toml.secret_key;
2983
2172
  const hasAuth = Boolean(apiKey && secretKey);
2984
2173
  const partialAuth = Boolean(apiKey) || Boolean(secretKey);
2985
2174
  if (partialAuth && !hasAuth) {
@@ -2988,7 +2177,7 @@ function loadConfig(cli) {
2988
2177
  "Set TOOBIT_API_KEY and TOOBIT_SECRET_KEY together (env vars or config.toml profile)."
2989
2178
  );
2990
2179
  }
2991
- const rawBaseUrl = ((_c = process.env.TOOBIT_API_BASE_URL) == null ? void 0 : _c.trim()) ?? toml.base_url ?? TOOBIT_API_BASE_URL;
2180
+ const rawBaseUrl = process.env.TOOBIT_API_BASE_URL?.trim() ?? toml.base_url ?? TOOBIT_API_BASE_URL;
2992
2181
  if (!rawBaseUrl.startsWith("http://") && !rawBaseUrl.startsWith("https://")) {
2993
2182
  throw new ConfigError(
2994
2183
  `Invalid base URL "${rawBaseUrl}".`,
@@ -3024,7 +2213,7 @@ var CLIENT_NAMES = {
3024
2213
  };
3025
2214
  var SUPPORTED_CLIENTS = Object.keys(CLIENT_NAMES);
3026
2215
 
3027
- // packages/cli/src/parser.ts
2216
+ // src/parser.ts
3028
2217
  import { parseArgs } from "util";
3029
2218
  function parseCli(argv = process.argv.slice(2)) {
3030
2219
  const STRING_OPTIONS = /* @__PURE__ */ new Set([
@@ -3105,7 +2294,7 @@ function parseCli(argv = process.argv.slice(2)) {
3105
2294
  };
3106
2295
  }
3107
2296
 
3108
- // packages/cli/src/formatter.ts
2297
+ // src/formatter.ts
3109
2298
  function extractRows(value) {
3110
2299
  if (Array.isArray(value)) return value;
3111
2300
  if (typeof value === "object" && value !== null) {
@@ -3160,7 +2349,7 @@ ${separator}
3160
2349
  ${body}`;
3161
2350
  }
3162
2351
 
3163
- // packages/cli/src/commands/market.ts
2352
+ // src/commands/market.ts
3164
2353
  async function handleMarketCommand(cli, run) {
3165
2354
  const f = cli.flags;
3166
2355
  let result;
@@ -3238,7 +2427,7 @@ Available: time, info, ticker, ticker-24hr, depth, trades, klines, candles, book
3238
2427
  process.stdout.write(formatJson(result, cli.json) + "\n");
3239
2428
  }
3240
2429
 
3241
- // packages/cli/src/commands/spot.ts
2430
+ // src/commands/spot.ts
3242
2431
  async function handleSpotCommand(cli, run) {
3243
2432
  const f = cli.flags;
3244
2433
  let result;
@@ -3288,7 +2477,7 @@ Available: place, cancel, cancel-all, get, orders, open-orders, history, fills
3288
2477
  process.stdout.write(formatJson(result, cli.json) + "\n");
3289
2478
  }
3290
2479
 
3291
- // packages/cli/src/commands/futures.ts
2480
+ // src/commands/futures.ts
3292
2481
  async function handleFuturesCommand(cli, run) {
3293
2482
  const f = cli.flags;
3294
2483
  let result;
@@ -3364,7 +2553,7 @@ Available: place, cancel, cancel-all, amend, get, orders, history, positions, hi
3364
2553
  process.stdout.write(formatJson(result, cli.json) + "\n");
3365
2554
  }
3366
2555
 
3367
- // packages/cli/src/commands/account.ts
2556
+ // src/commands/account.ts
3368
2557
  async function handleAccountCommand(cli, run) {
3369
2558
  const f = cli.flags;
3370
2559
  let result;
@@ -3413,7 +2602,7 @@ Available: balance, info, balance-flow, sub-accounts, check-api-key, deposit-add
3413
2602
  process.stdout.write(formatJson(result, cli.json) + "\n");
3414
2603
  }
3415
2604
 
3416
- // packages/cli/src/commands/config.ts
2605
+ // src/commands/config.ts
3417
2606
  import * as readline from "readline";
3418
2607
  function prompt(question) {
3419
2608
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
@@ -3479,7 +2668,7 @@ Available: init, show, list
3479
2668
  }
3480
2669
  }
3481
2670
 
3482
- // packages/cli/src/index.ts
2671
+ // src/index.ts
3483
2672
  function printHelp() {
3484
2673
  const help = `
3485
2674
  Toobit Trade CLI \u2014 Trade from your terminal
@@ -3554,42 +2743,3 @@ main().catch((error) => {
3554
2743
  `);
3555
2744
  process.exitCode = 1;
3556
2745
  });
3557
- /*! Bundled license information:
3558
-
3559
- smol-toml/dist/error.js:
3560
- smol-toml/dist/util.js:
3561
- smol-toml/dist/date.js:
3562
- smol-toml/dist/primitive.js:
3563
- smol-toml/dist/extract.js:
3564
- smol-toml/dist/struct.js:
3565
- smol-toml/dist/parse.js:
3566
- smol-toml/dist/stringify.js:
3567
- smol-toml/dist/index.js:
3568
- (*!
3569
- * Copyright (c) Squirrel Chat et al., All rights reserved.
3570
- * SPDX-License-Identifier: BSD-3-Clause
3571
- *
3572
- * Redistribution and use in source and binary forms, with or without
3573
- * modification, are permitted provided that the following conditions are met:
3574
- *
3575
- * 1. Redistributions of source code must retain the above copyright notice, this
3576
- * list of conditions and the following disclaimer.
3577
- * 2. Redistributions in binary form must reproduce the above copyright notice,
3578
- * this list of conditions and the following disclaimer in the
3579
- * documentation and/or other materials provided with the distribution.
3580
- * 3. Neither the name of the copyright holder nor the names of its contributors
3581
- * may be used to endorse or promote products derived from this software without
3582
- * specific prior written permission.
3583
- *
3584
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
3585
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3586
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3587
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
3588
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3589
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3590
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
3591
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3592
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3593
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3594
- *)
3595
- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toobit-trade-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "toobit": "dist/index.js"