@onebullex-group/cli 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1627 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ effectiveFormat,
4
+ render
5
+ } from "./chunk-J3TAAD3Q.js";
6
+ import {
7
+ DEFAULT_CONFIG_PATH,
8
+ checkConfigPermissions,
9
+ readConfigFile,
10
+ redactProfile,
11
+ resolveConfig,
12
+ writeConfigFile
13
+ } from "./chunk-AKGCHJPQ.js";
14
+ import {
15
+ HttpClient
16
+ } from "./chunk-CVOY2SOS.js";
17
+ import {
18
+ ConfigError,
19
+ DryRunInterception,
20
+ EXIT,
21
+ OneBullExError
22
+ } from "./chunk-JRUFIHU7.js";
23
+ import {
24
+ redactSecret
25
+ } from "./chunk-OOLZIYXS.js";
26
+ import "./chunk-ZYO5P4DH.js";
27
+ import "./chunk-LVNSFQXS.js";
28
+
29
+ // src/index.ts
30
+ import { Command } from "commander";
31
+
32
+ // src/commands/public/time.ts
33
+ function registerPublicTime(parent, ctx) {
34
+ parent.command("time").description("Get server time (GET /v2/public/time)").action(async () => {
35
+ const c = ctx.http({ requireAuth: false });
36
+ const data = await c.getPublic("/v2/public/time");
37
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
38
+ ctx.stdout(
39
+ render2(data, {
40
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
41
+ isTTY: ctx.isTTY
42
+ })
43
+ );
44
+ });
45
+ }
46
+
47
+ // src/commands/symbol/list.ts
48
+ function registerSymbolList(parent, ctx) {
49
+ parent.command("list").description("List all trading pairs (GET /v2/public/symbol/list)").action(async () => {
50
+ const c = ctx.http({ requireAuth: false });
51
+ const data = await c.getPublic("/v2/public/symbol/list");
52
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
53
+ ctx.stdout(
54
+ render2(data, {
55
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
56
+ isTTY: ctx.isTTY
57
+ })
58
+ );
59
+ });
60
+ }
61
+
62
+ // src/commands/symbol/get.ts
63
+ function registerSymbolGet(parent, ctx) {
64
+ parent.command("get <symbol>").description("Get symbol detail (GET /v2/public/symbol/detail)").action(async (symbol) => {
65
+ const c = ctx.http({ requireAuth: false });
66
+ const data = await c.getPublic("/v2/public/symbol/detail", { symbol });
67
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
68
+ ctx.stdout(
69
+ render2(data, {
70
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
71
+ isTTY: ctx.isTTY
72
+ })
73
+ );
74
+ });
75
+ }
76
+
77
+ // src/commands/symbol/coins.ts
78
+ function registerSymbolCoins(parent, ctx) {
79
+ parent.command("coins").description("List all coins (GET /v2/public/symbol/coins)").action(async () => {
80
+ const c = ctx.http({ requireAuth: false });
81
+ const data = await c.getPublic("/v2/public/symbol/coins");
82
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
83
+ ctx.stdout(
84
+ render2(data, {
85
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
86
+ isTTY: ctx.isTTY
87
+ })
88
+ );
89
+ });
90
+ }
91
+
92
+ // src/commands/symbol/all.ts
93
+ function registerSymbolAll(parent, ctx) {
94
+ parent.command("all").description("List all symbols (GET /v2/public/symbol/all)").action(async () => {
95
+ const c = ctx.http({ requireAuth: false });
96
+ const data = await c.getPublic("/v2/public/symbol/all");
97
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
98
+ ctx.stdout(
99
+ render2(data, {
100
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
101
+ isTTY: ctx.isTTY
102
+ })
103
+ );
104
+ });
105
+ }
106
+
107
+ // src/commands/ticker/get.ts
108
+ function prune(o) {
109
+ const out = {};
110
+ for (const [k, v] of Object.entries(o)) {
111
+ if (v != null && v !== "") out[k] = v;
112
+ }
113
+ return out;
114
+ }
115
+ function registerTickerGet(parent, ctx) {
116
+ parent.command("get <symbol>").description("Get ticker for a symbol (GET /v2/public/q/ticker)").option("--time-range <type>", "time range type").action(async (symbol, opts) => {
117
+ const c = ctx.http({ requireAuth: false });
118
+ const data = await c.getPublic(
119
+ "/v2/public/q/ticker",
120
+ prune({ symbol, timeRangeType: opts.timeRange })
121
+ );
122
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
123
+ ctx.stdout(
124
+ render2(data, {
125
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
126
+ isTTY: ctx.isTTY
127
+ })
128
+ );
129
+ });
130
+ }
131
+
132
+ // src/commands/ticker/list.ts
133
+ function prune2(o) {
134
+ const out = {};
135
+ for (const [k, v] of Object.entries(o)) {
136
+ if (v != null && v !== "") out[k] = v;
137
+ }
138
+ return out;
139
+ }
140
+ function registerTickerList(parent, ctx) {
141
+ parent.command("list").description("List all tickers (GET /v2/public/q/tickers)").requiredOption("--time-range <type>", "time range type").action(async (opts) => {
142
+ const c = ctx.http({ requireAuth: false });
143
+ const data = await c.getPublic(
144
+ "/v2/public/q/tickers",
145
+ prune2({ timeRangeType: opts.timeRange })
146
+ );
147
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
148
+ ctx.stdout(
149
+ render2(data, {
150
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
151
+ isTTY: ctx.isTTY
152
+ })
153
+ );
154
+ });
155
+ }
156
+
157
+ // src/commands/ticker/agg.ts
158
+ function prune3(o) {
159
+ const out = {};
160
+ for (const [k, v] of Object.entries(o)) {
161
+ if (v != null && v !== "") out[k] = v;
162
+ }
163
+ return out;
164
+ }
165
+ function registerTickerAgg(parent, ctx) {
166
+ parent.command("agg <symbol>").description("Get aggregated ticker for a symbol (GET /v2/public/q/agg-ticker)").option("--time-range <type>", "time range type").action(async (symbol, opts) => {
167
+ const c = ctx.http({ requireAuth: false });
168
+ const data = await c.getPublic(
169
+ "/v2/public/q/agg-ticker",
170
+ prune3({ symbol, timeRangeType: opts.timeRange })
171
+ );
172
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
173
+ ctx.stdout(
174
+ render2(data, {
175
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
176
+ isTTY: ctx.isTTY
177
+ })
178
+ );
179
+ });
180
+ }
181
+
182
+ // src/commands/ticker/agg-list.ts
183
+ function prune4(o) {
184
+ const out = {};
185
+ for (const [k, v] of Object.entries(o)) {
186
+ if (v != null && v !== "") out[k] = v;
187
+ }
188
+ return out;
189
+ }
190
+ function registerTickerAggList(parent, ctx) {
191
+ parent.command("agg-list").description("List all aggregated tickers (GET /v2/public/q/agg-tickers)").requiredOption("--time-range <type>", "time range type").action(async (opts) => {
192
+ const c = ctx.http({ requireAuth: false });
193
+ const data = await c.getPublic(
194
+ "/v2/public/q/agg-tickers",
195
+ prune4({ timeRangeType: opts.timeRange })
196
+ );
197
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
198
+ ctx.stdout(
199
+ render2(data, {
200
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
201
+ isTTY: ctx.isTTY
202
+ })
203
+ );
204
+ });
205
+ }
206
+
207
+ // src/commands/depth/get.ts
208
+ function prune5(o) {
209
+ const out = {};
210
+ for (const [k, v] of Object.entries(o)) {
211
+ if (v != null && v !== "") out[k] = v;
212
+ }
213
+ return out;
214
+ }
215
+ function registerDepthGet(parent, ctx) {
216
+ parent.command("get <symbol>").description("Get order book depth (GET /v2/public/q/depth)").option("--level <level>", "depth level", parseInt).action(async (symbol, opts) => {
217
+ const c = ctx.http({ requireAuth: false });
218
+ const data = await c.getPublic(
219
+ "/v2/public/q/depth",
220
+ prune5({ symbol, level: opts.level })
221
+ );
222
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
223
+ ctx.stdout(
224
+ render2(data, {
225
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
226
+ isTTY: ctx.isTTY
227
+ })
228
+ );
229
+ });
230
+ }
231
+
232
+ // src/commands/deal/list.ts
233
+ function prune6(o) {
234
+ const out = {};
235
+ for (const [k, v] of Object.entries(o)) {
236
+ if (v != null && v !== "") out[k] = v;
237
+ }
238
+ return out;
239
+ }
240
+ function registerDealList(parent, ctx) {
241
+ parent.command("list <symbol>").description("List recent trades (GET /v2/public/q/deal)").option("--num <num>", "number of trades to return", parseInt).action(async (symbol, opts) => {
242
+ const c = ctx.http({ requireAuth: false });
243
+ const data = await c.getPublic(
244
+ "/v2/public/q/deal",
245
+ prune6({ symbol, num: opts.num })
246
+ );
247
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
248
+ ctx.stdout(
249
+ render2(data, {
250
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
251
+ isTTY: ctx.isTTY
252
+ })
253
+ );
254
+ });
255
+ }
256
+
257
+ // src/commands/kline/list.ts
258
+ function prune7(o) {
259
+ const out = {};
260
+ for (const [k, v] of Object.entries(o)) {
261
+ if (v != null && v !== "") out[k] = v;
262
+ }
263
+ return out;
264
+ }
265
+ function registerKlineList(parent, ctx) {
266
+ parent.command("list <symbol>").description("List candlestick data (GET /v2/public/q/kline)").requiredOption("--interval <interval>", "kline interval (e.g. 1m, 5m, 1h, 1d)").option("--start-time <ms>", "start time in milliseconds", parseInt).option("--end-time <ms>", "end time in milliseconds", parseInt).option("--limit <limit>", "number of records to return", parseInt).action(
267
+ async (symbol, opts) => {
268
+ const c = ctx.http({ requireAuth: false });
269
+ const data = await c.getPublic(
270
+ "/v2/public/q/kline",
271
+ prune7({
272
+ symbol,
273
+ interval: opts.interval,
274
+ startTime: opts.startTime,
275
+ endTime: opts.endTime,
276
+ limit: opts.limit
277
+ })
278
+ );
279
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
280
+ ctx.stdout(
281
+ render2(data, {
282
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
283
+ isTTY: ctx.isTTY
284
+ })
285
+ );
286
+ }
287
+ );
288
+ }
289
+
290
+ // src/commands/mark-price/list.ts
291
+ function prune8(o) {
292
+ const out = {};
293
+ for (const [k, v] of Object.entries(o)) {
294
+ if (v != null && v !== "") out[k] = v;
295
+ }
296
+ return out;
297
+ }
298
+ function registerMarkPriceList(parent, ctx) {
299
+ parent.command("list").description("List mark prices (GET /v2/public/q/mark-price)").option("--symbol <symbol>", "filter by symbol").action(async (opts) => {
300
+ const c = ctx.http({ requireAuth: false });
301
+ const data = await c.getPublic(
302
+ "/v2/public/q/mark-price",
303
+ prune8({ symbol: opts.symbol })
304
+ );
305
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
306
+ ctx.stdout(
307
+ render2(data, {
308
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
309
+ isTTY: ctx.isTTY
310
+ })
311
+ );
312
+ });
313
+ }
314
+
315
+ // src/commands/mark-price/get.ts
316
+ function registerMarkPriceGet(parent, ctx) {
317
+ parent.command("get <symbol>").description("Get mark price for a symbol (GET /v2/public/q/symbol-mark-price)").action(async (symbol) => {
318
+ const c = ctx.http({ requireAuth: false });
319
+ const data = await c.getPublic("/v2/public/q/symbol-mark-price", { symbol });
320
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
321
+ ctx.stdout(
322
+ render2(data, {
323
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
324
+ isTTY: ctx.isTTY
325
+ })
326
+ );
327
+ });
328
+ }
329
+
330
+ // src/commands/index-price/list.ts
331
+ function prune9(o) {
332
+ const out = {};
333
+ for (const [k, v] of Object.entries(o)) {
334
+ if (v != null && v !== "") out[k] = v;
335
+ }
336
+ return out;
337
+ }
338
+ function registerIndexPriceList(parent, ctx) {
339
+ parent.command("list").description("List index prices (GET /v2/public/q/index-price)").option("--symbol <symbol>", "filter by symbol").action(async (opts) => {
340
+ const c = ctx.http({ requireAuth: false });
341
+ const data = await c.getPublic(
342
+ "/v2/public/q/index-price",
343
+ prune9({ symbol: opts.symbol })
344
+ );
345
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
346
+ ctx.stdout(
347
+ render2(data, {
348
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
349
+ isTTY: ctx.isTTY
350
+ })
351
+ );
352
+ });
353
+ }
354
+
355
+ // src/commands/index-price/get.ts
356
+ function registerIndexPriceGet(parent, ctx) {
357
+ parent.command("get <symbol>").description("Get index price for a symbol (GET /v2/public/q/symbol-index-price)").action(async (symbol) => {
358
+ const c = ctx.http({ requireAuth: true });
359
+ const data = await c.getPrivate("/v2/public/q/symbol-index-price", { symbol });
360
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
361
+ ctx.stdout(
362
+ render2(data, {
363
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
364
+ isTTY: ctx.isTTY
365
+ })
366
+ );
367
+ });
368
+ }
369
+
370
+ // src/commands/funding/rate.ts
371
+ function registerFundingRate(parent, ctx) {
372
+ parent.command("rate <symbol>").description("Get funding rate for a symbol (GET /v2/public/q/funding-rate)").action(async (symbol) => {
373
+ const c = ctx.http({ requireAuth: false });
374
+ const data = await c.getPublic("/v2/public/q/funding-rate", { symbol });
375
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
376
+ ctx.stdout(
377
+ render2(data, {
378
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
379
+ isTTY: ctx.isTTY
380
+ })
381
+ );
382
+ });
383
+ }
384
+
385
+ // src/commands/funding/history.ts
386
+ function prune10(o) {
387
+ const out = {};
388
+ for (const [k, v] of Object.entries(o)) {
389
+ if (v != null && v !== "") out[k] = v;
390
+ }
391
+ return out;
392
+ }
393
+ function registerFundingHistory(parent, ctx) {
394
+ parent.command("history <symbol>").description("Get funding rate history (GET /v2/public/q/funding-rate-record)").option("--id <id>", "record id for pagination").option("--direction <direction>", "pagination direction (NEXT or PREV)").option("--limit <limit>", "number of records to return", parseInt).action(
395
+ async (symbol, opts) => {
396
+ const c = ctx.http({ requireAuth: false });
397
+ const data = await c.getPublic(
398
+ "/v2/public/q/funding-rate-record",
399
+ prune10({
400
+ symbol,
401
+ id: opts.id,
402
+ direction: opts.direction,
403
+ limit: opts.limit
404
+ })
405
+ );
406
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
407
+ ctx.stdout(
408
+ render2(data, {
409
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
410
+ isTTY: ctx.isTTY
411
+ })
412
+ );
413
+ }
414
+ );
415
+ }
416
+
417
+ // src/commands/risk-balance/list.ts
418
+ function prune11(o) {
419
+ const out = {};
420
+ for (const [k, v] of Object.entries(o)) {
421
+ if (v != null && v !== "") out[k] = v;
422
+ }
423
+ return out;
424
+ }
425
+ function registerRiskBalanceList(parent, ctx) {
426
+ parent.command("list <symbol>").description("List risk fund balances (GET /v2/public/contract/risk-balance)").option("--id <id>", "record id for pagination").option("--direction <direction>", "pagination direction (NEXT or PREV)").option("--limit <limit>", "number of records to return", parseInt).action(
427
+ async (symbol, opts) => {
428
+ const c = ctx.http({ requireAuth: false });
429
+ const data = await c.getPublic(
430
+ "/v2/public/contract/risk-balance",
431
+ prune11({
432
+ symbol,
433
+ id: opts.id,
434
+ direction: opts.direction,
435
+ limit: opts.limit
436
+ })
437
+ );
438
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
439
+ ctx.stdout(
440
+ render2(data, {
441
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
442
+ isTTY: ctx.isTTY
443
+ })
444
+ );
445
+ }
446
+ );
447
+ }
448
+
449
+ // src/commands/open-interest/get.ts
450
+ function registerOpenInterestGet(parent, ctx) {
451
+ parent.command("get <symbol>").description("Get open interest for a symbol (GET /v2/public/contract/open-interest)").action(async (symbol) => {
452
+ const c = ctx.http({ requireAuth: false });
453
+ const data = await c.getPublic("/v2/public/contract/open-interest", { symbol });
454
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
455
+ ctx.stdout(
456
+ render2(data, {
457
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
458
+ isTTY: ctx.isTTY
459
+ })
460
+ );
461
+ });
462
+ }
463
+
464
+ // src/commands/leverage/brackets-list.ts
465
+ function registerLeverageBracketsList(parent, ctx) {
466
+ parent.command("brackets-list").description("List all leverage brackets (GET /v2/public/leverage/bracket/list)").action(async () => {
467
+ const c = ctx.http({ requireAuth: false });
468
+ const data = await c.getPublic("/v2/public/leverage/bracket/list");
469
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
470
+ ctx.stdout(
471
+ render2(data, {
472
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
473
+ isTTY: ctx.isTTY
474
+ })
475
+ );
476
+ });
477
+ }
478
+
479
+ // src/commands/leverage/brackets-get.ts
480
+ function registerLeverageBracketsGet(parent, ctx) {
481
+ parent.command("brackets-get <symbol>").description("Get leverage bracket detail for a symbol (GET /v2/public/leverage/bracket/detail)").action(async (symbol) => {
482
+ const c = ctx.http({ requireAuth: false });
483
+ const data = await c.getPublic("/v2/public/leverage/bracket/detail", { symbol });
484
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
485
+ ctx.stdout(
486
+ render2(data, {
487
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
488
+ isTTY: ctx.isTTY
489
+ })
490
+ );
491
+ });
492
+ }
493
+
494
+ // src/commands/listen-key/get.ts
495
+ function registerListenKeyGet(parent, ctx) {
496
+ parent.command("get").description("Get user listen key for WebSocket (GET /v2/user/listen-key)").action(async () => {
497
+ const c = ctx.http({ requireAuth: true });
498
+ const data = await c.getPrivate("/v2/user/listen-key");
499
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
500
+ ctx.stdout(
501
+ render2(data, {
502
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
503
+ isTTY: ctx.isTTY
504
+ })
505
+ );
506
+ });
507
+ }
508
+
509
+ // src/commands/balance/list.ts
510
+ function registerBalanceList(parent, ctx) {
511
+ parent.command("list").description("List all coin balances (GET /v2/balance/list)").action(async () => {
512
+ const c = ctx.http({ requireAuth: true });
513
+ const data = await c.getPrivate("/v2/balance/list");
514
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
515
+ ctx.stdout(
516
+ render2(data, {
517
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
518
+ isTTY: ctx.isTTY
519
+ })
520
+ );
521
+ });
522
+ }
523
+
524
+ // src/commands/balance/get.ts
525
+ function registerBalanceGet(parent, ctx) {
526
+ parent.command("get <coin>").description("Get single coin balance (GET /v2/balance/detail)").action(async (coin) => {
527
+ const c = ctx.http({ requireAuth: true });
528
+ const data = await c.getPrivate("/v2/balance/detail", { coin });
529
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
530
+ ctx.stdout(
531
+ render2(data, {
532
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
533
+ isTTY: ctx.isTTY
534
+ })
535
+ );
536
+ });
537
+ }
538
+
539
+ // src/commands/balance/bills.ts
540
+ function prune12(o) {
541
+ const out = {};
542
+ for (const [k, v] of Object.entries(o)) {
543
+ if (v != null && v !== "") out[k] = v;
544
+ }
545
+ return out;
546
+ }
547
+ function registerBalanceBills(parent, ctx) {
548
+ parent.command("bills").description("List balance bill records (GET /v2/balance/bills)").option("--coin <coin>", "filter by coin").option("--type <type>", "bill type").option("--start-time <ms>", "start time in milliseconds", parseInt).option("--end-time <ms>", "end time in milliseconds", parseInt).option("--page <page>", "page number", parseInt).option("--size <size>", "page size", parseInt).action(
549
+ async (opts) => {
550
+ const c = ctx.http({ requireAuth: true });
551
+ const data = await c.getPrivate(
552
+ "/v2/balance/bills",
553
+ prune12({
554
+ coin: opts.coin,
555
+ type: opts.type,
556
+ startTime: opts.startTime,
557
+ endTime: opts.endTime,
558
+ page: opts.page,
559
+ size: opts.size
560
+ })
561
+ );
562
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
563
+ ctx.stdout(
564
+ render2(data, {
565
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
566
+ isTTY: ctx.isTTY
567
+ })
568
+ );
569
+ }
570
+ );
571
+ }
572
+
573
+ // src/commands/order/list-unfinished.ts
574
+ function prune13(o) {
575
+ const out = {};
576
+ for (const [k, v] of Object.entries(o)) {
577
+ if (v != null && v !== "") out[k] = v;
578
+ }
579
+ return out;
580
+ }
581
+ function registerOrderListUnfinished(parent, ctx) {
582
+ parent.command("list-unfinished <symbol>").description("List unfinished orders for a symbol (GET /v2/order/listUnfinished)").option("--direction <direction>", "order direction").action(async (symbol, opts) => {
583
+ const c = ctx.http({ requireAuth: true });
584
+ const data = await c.getPrivate(
585
+ "/v2/order/listUnfinished",
586
+ prune13({ symbol, direction: opts.direction })
587
+ );
588
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
589
+ ctx.stdout(
590
+ render2(data, {
591
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
592
+ isTTY: ctx.isTTY
593
+ })
594
+ );
595
+ });
596
+ }
597
+
598
+ // src/commands/order/list-unfinished-multi.ts
599
+ function registerOrderListUnfinishedMulti(parent, ctx) {
600
+ parent.command("list-unfinished-multi").description("List unfinished orders across multiple symbols (GET /v2/order/all/listUnfinished)").requiredOption("--list <list>", "comma-separated or JSON list of symbols").action(async (opts) => {
601
+ const c = ctx.http({ requireAuth: true });
602
+ const data = await c.getPrivate("/v2/order/all/listUnfinished", { list: opts.list });
603
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
604
+ ctx.stdout(
605
+ render2(data, {
606
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
607
+ isTTY: ctx.isTTY
608
+ })
609
+ );
610
+ });
611
+ }
612
+
613
+ // src/commands/order/list.ts
614
+ function prune14(o) {
615
+ const out = {};
616
+ for (const [k, v] of Object.entries(o)) {
617
+ if (v != null && v !== "") out[k] = v;
618
+ }
619
+ return out;
620
+ }
621
+ function registerOrderList(parent, ctx) {
622
+ parent.command("list").description("List orders (GET /v2/order/list)").option("--symbol <symbol>", "filter by symbol").option("--status <status>", "filter by order status").option("--page <page>", "page number", parseInt).option("--size <size>", "page size", parseInt).action(
623
+ async (opts) => {
624
+ const c = ctx.http({ requireAuth: true });
625
+ const data = await c.getPrivate(
626
+ "/v2/order/list",
627
+ prune14({
628
+ symbol: opts.symbol,
629
+ status: opts.status,
630
+ page: opts.page,
631
+ size: opts.size
632
+ })
633
+ );
634
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
635
+ ctx.stdout(
636
+ render2(data, {
637
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
638
+ isTTY: ctx.isTTY
639
+ })
640
+ );
641
+ }
642
+ );
643
+ }
644
+
645
+ // src/commands/order/list-by-ids.ts
646
+ function registerOrderListByIds(parent, ctx) {
647
+ parent.command("list-by-ids").description("Query orders by ID list (POST /v2/order/list-by-ids)").requiredOption("--ids <jsonArray>", 'JSON array of order IDs, e.g. "[123,456]"').action(async (opts) => {
648
+ const c = ctx.http({ requireAuth: true });
649
+ const data = await c.postPrivate("/v2/order/list-by-ids", { ids: opts.ids });
650
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
651
+ ctx.stdout(
652
+ render2(data, {
653
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
654
+ isTTY: ctx.isTTY
655
+ })
656
+ );
657
+ });
658
+ }
659
+
660
+ // src/commands/order/list-history.ts
661
+ function prune15(o) {
662
+ const out = {};
663
+ for (const [k, v] of Object.entries(o)) {
664
+ if (v != null && v !== "") out[k] = v;
665
+ }
666
+ return out;
667
+ }
668
+ function registerOrderListHistory(parent, ctx) {
669
+ parent.command("list-history").description("List order history (GET /v2/order/list-history)").option("--symbol <symbol>", "filter by symbol").option("--start-time <ms>", "start time in milliseconds", parseInt).option("--end-time <ms>", "end time in milliseconds", parseInt).option("--id <id>", "order ID cursor").option("--direction <direction>", "order direction").option("--limit <limit>", "number of records", parseInt).option("--force-close", "filter force-close orders").action(
670
+ async (opts) => {
671
+ const c = ctx.http({ requireAuth: true });
672
+ const data = await c.getPrivate(
673
+ "/v2/order/list-history",
674
+ prune15({
675
+ symbol: opts.symbol,
676
+ startTime: opts.startTime,
677
+ endTime: opts.endTime,
678
+ id: opts.id,
679
+ direction: opts.direction,
680
+ limit: opts.limit,
681
+ forceClose: opts.forceClose
682
+ })
683
+ );
684
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
685
+ ctx.stdout(
686
+ render2(data, {
687
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
688
+ isTTY: ctx.isTTY
689
+ })
690
+ );
691
+ }
692
+ );
693
+ }
694
+
695
+ // src/commands/order/get.ts
696
+ function registerOrderGet(parent, ctx) {
697
+ parent.command("get <orderId>").description("Get order detail (GET /v2/order/detail)").action(async (orderId) => {
698
+ const c = ctx.http({ requireAuth: true });
699
+ const data = await c.getPrivate("/v2/order/detail", { orderId });
700
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
701
+ ctx.stdout(
702
+ render2(data, {
703
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
704
+ isTTY: ctx.isTTY
705
+ })
706
+ );
707
+ });
708
+ }
709
+
710
+ // src/commands/order/trades.ts
711
+ function prune16(o) {
712
+ const out = {};
713
+ for (const [k, v] of Object.entries(o)) {
714
+ if (v != null && v !== "") out[k] = v;
715
+ }
716
+ return out;
717
+ }
718
+ function registerOrderTrades(parent, ctx) {
719
+ parent.command("trades").description("List order trade records (GET /v2/order/trade-list)").option("--order-id <orderId>", "filter by order ID").option("--symbol <symbol>", "filter by symbol").option("--start-time <ms>", "start time in milliseconds", parseInt).option("--end-time <ms>", "end time in milliseconds", parseInt).option("--page <page>", "page number", parseInt).option("--size <size>", "page size", parseInt).action(
720
+ async (opts) => {
721
+ const c = ctx.http({ requireAuth: true });
722
+ const data = await c.getPrivate(
723
+ "/v2/order/trade-list",
724
+ prune16({
725
+ orderId: opts.orderId,
726
+ symbol: opts.symbol,
727
+ startTime: opts.startTime,
728
+ endTime: opts.endTime,
729
+ page: opts.page,
730
+ size: opts.size
731
+ })
732
+ );
733
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
734
+ ctx.stdout(
735
+ render2(data, {
736
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
737
+ isTTY: ctx.isTTY
738
+ })
739
+ );
740
+ }
741
+ );
742
+ }
743
+
744
+ // src/commands/entrust/plan-list.ts
745
+ function prune17(o) {
746
+ const out = {};
747
+ for (const [k, v] of Object.entries(o)) {
748
+ if (v != null && v !== "") out[k] = v;
749
+ }
750
+ return out;
751
+ }
752
+ function registerEntrustPlanList(parent, ctx) {
753
+ parent.command("plan-list").description("List active plan entrusts (GET /v2/entrust/plan-list)").option("--symbol <symbol>", "filter by symbol").option("--page <page>", "page number", parseInt).option("--size <size>", "page size", parseInt).action(async (opts) => {
754
+ const c = ctx.http({ requireAuth: true });
755
+ const data = await c.getPrivate(
756
+ "/v2/entrust/plan-list",
757
+ prune17({ symbol: opts.symbol, page: opts.page, size: opts.size })
758
+ );
759
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
760
+ ctx.stdout(
761
+ render2(data, {
762
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
763
+ isTTY: ctx.isTTY
764
+ })
765
+ );
766
+ });
767
+ }
768
+
769
+ // src/commands/entrust/plan-history.ts
770
+ function prune18(o) {
771
+ const out = {};
772
+ for (const [k, v] of Object.entries(o)) {
773
+ if (v != null && v !== "") out[k] = v;
774
+ }
775
+ return out;
776
+ }
777
+ function registerEntrustPlanHistory(parent, ctx) {
778
+ parent.command("plan-history").description("List plan entrust history (GET /v2/entrust/plan-list-history)").option("--symbol <symbol>", "filter by symbol").option("--start-time <ms>", "start time in milliseconds", parseInt).option("--end-time <ms>", "end time in milliseconds", parseInt).option("--id <id>", "cursor ID").option("--direction <direction>", "order direction").option("--limit <limit>", "number of records", parseInt).action(
779
+ async (opts) => {
780
+ const c = ctx.http({ requireAuth: true });
781
+ const data = await c.getPrivate(
782
+ "/v2/entrust/plan-list-history",
783
+ prune18({
784
+ symbol: opts.symbol,
785
+ startTime: opts.startTime,
786
+ endTime: opts.endTime,
787
+ id: opts.id,
788
+ direction: opts.direction,
789
+ limit: opts.limit
790
+ })
791
+ );
792
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
793
+ ctx.stdout(
794
+ render2(data, {
795
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
796
+ isTTY: ctx.isTTY
797
+ })
798
+ );
799
+ }
800
+ );
801
+ }
802
+
803
+ // src/commands/entrust/plan-get.ts
804
+ function registerEntrustPlanGet(parent, ctx) {
805
+ parent.command("plan-get <id>").description("Get plan entrust detail (GET /v2/entrust/plan-detail)").action(async (id) => {
806
+ const c = ctx.http({ requireAuth: true });
807
+ const data = await c.getPrivate("/v2/entrust/plan-detail", { entrustId: id });
808
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
809
+ ctx.stdout(
810
+ render2(data, {
811
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
812
+ isTTY: ctx.isTTY
813
+ })
814
+ );
815
+ });
816
+ }
817
+
818
+ // src/commands/entrust/profit-list.ts
819
+ function prune19(o) {
820
+ const out = {};
821
+ for (const [k, v] of Object.entries(o)) {
822
+ if (v != null && v !== "") out[k] = v;
823
+ }
824
+ return out;
825
+ }
826
+ function registerEntrustProfitList(parent, ctx) {
827
+ parent.command("profit-list").description("List TP/SL entrusts (GET /v2/entrust/profit-list)").option("--symbol <symbol>", "filter by symbol").option("--page <page>", "page number", parseInt).option("--size <size>", "page size", parseInt).action(async (opts) => {
828
+ const c = ctx.http({ requireAuth: true });
829
+ const data = await c.getPrivate(
830
+ "/v2/entrust/profit-list",
831
+ prune19({ symbol: opts.symbol, page: opts.page, size: opts.size })
832
+ );
833
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
834
+ ctx.stdout(
835
+ render2(data, {
836
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
837
+ isTTY: ctx.isTTY
838
+ })
839
+ );
840
+ });
841
+ }
842
+
843
+ // src/commands/entrust/profit-get.ts
844
+ function registerEntrustProfitGet(parent, ctx) {
845
+ parent.command("profit-get <id>").description("Get TP/SL entrust detail (GET /v2/entrust/profit-detail)").action(async (id) => {
846
+ const c = ctx.http({ requireAuth: true });
847
+ const data = await c.getPrivate("/v2/entrust/profit-detail", { profitId: id });
848
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
849
+ ctx.stdout(
850
+ render2(data, {
851
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
852
+ isTTY: ctx.isTTY
853
+ })
854
+ );
855
+ });
856
+ }
857
+
858
+ // src/commands/order-entrust/list.ts
859
+ function prune20(o) {
860
+ const out = {};
861
+ for (const [k, v] of Object.entries(o)) {
862
+ if (v != null && v !== "") out[k] = v;
863
+ }
864
+ return out;
865
+ }
866
+ function registerOrderEntrustList(parent, ctx) {
867
+ parent.command("list").description("List combined orders and entrusts (GET /v2/order-entrust/list)").option("--type <type>", "filter by type").option("--symbol <symbol>", "filter by symbol").option("--page <page>", "page number", parseInt).option("--size <size>", "page size", parseInt).action(async (opts) => {
868
+ const c = ctx.http({ requireAuth: true });
869
+ const data = await c.getPrivate(
870
+ "/v2/order-entrust/list",
871
+ prune20({
872
+ type: opts.type,
873
+ symbol: opts.symbol,
874
+ page: opts.page,
875
+ size: opts.size
876
+ })
877
+ );
878
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
879
+ ctx.stdout(
880
+ render2(data, {
881
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
882
+ isTTY: ctx.isTTY
883
+ })
884
+ );
885
+ });
886
+ }
887
+
888
+ // src/commands/position/list.ts
889
+ function prune21(o) {
890
+ const out = {};
891
+ for (const [k, v] of Object.entries(o)) {
892
+ if (v != null && v !== "") out[k] = v;
893
+ }
894
+ return out;
895
+ }
896
+ function registerPositionList(parent, ctx) {
897
+ parent.command("list").description("List positions (GET /v2/position/list)").option("--symbol <symbol>", "filter by symbol").action(async (opts) => {
898
+ const c = ctx.http({ requireAuth: true });
899
+ const data = await c.getPrivate("/v2/position/list", prune21({ symbol: opts.symbol }));
900
+ const { render: render2, effectiveFormat: effectiveFormat2 } = await import("./output-UIZGG7EU.js");
901
+ ctx.stdout(
902
+ render2(data, {
903
+ format: effectiveFormat2(ctx.outputFormat, ctx.isTTY),
904
+ isTTY: ctx.isTTY
905
+ })
906
+ );
907
+ });
908
+ }
909
+
910
+ // src/commands/config/init.ts
911
+ import * as readline from "readline/promises";
912
+ var TEST_BASE_URL = "https://futures-openapi.1bullex.com";
913
+ var PROD_BASE_URL = "https://futures-openapi.1bullex.com";
914
+ async function prompt(rl, q, def) {
915
+ const suffix = def ? ` [${def}]` : "";
916
+ const ans = (await rl.question(`${q}${suffix}: `)).trim();
917
+ return ans.length === 0 && def !== void 0 ? def : ans;
918
+ }
919
+ function registerConfigInit(parent, ctx) {
920
+ parent.command("init").description("Initialize a new profile (interactive)").option("--name <name>", "profile name (skip prompt)").option("--env <env>", "environment: test | prod").option("--base-url <url>", "override base url").option("--api-key <key>", "API key (only allowed with --yes; prefer interactive)").option("--secret <secret>", "API secret (only allowed with --yes; prefer interactive)").option("--identify <id>", "sub-account identify header (optional)").option("--set-default", "mark this profile as default-profile", true).option("--yes", "non-interactive mode (use provided flags only)").action(async (flags) => {
921
+ const path = ctx.getConfigPath();
922
+ let existing = null;
923
+ try {
924
+ existing = readConfigFile(path);
925
+ } catch {
926
+ existing = null;
927
+ }
928
+ let name = flags.name;
929
+ let env = flags.env;
930
+ let baseUrl = flags.baseUrl;
931
+ let apiKey = flags.apiKey;
932
+ let secret = flags.secret;
933
+ let identify = flags.identify;
934
+ if (!flags.yes) {
935
+ const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
936
+ try {
937
+ name ??= await prompt(rl, "Profile name", "default");
938
+ if (!env) {
939
+ const e = (await prompt(rl, "Environment (test|prod)", "test")).toLowerCase();
940
+ if (e !== "test" && e !== "prod") {
941
+ throw new ConfigError(`env must be "test" or "prod"`);
942
+ }
943
+ env = e;
944
+ }
945
+ baseUrl ??= await prompt(
946
+ rl,
947
+ "Base URL",
948
+ env === "prod" ? PROD_BASE_URL : TEST_BASE_URL
949
+ );
950
+ apiKey ??= await prompt(rl, "API key", "");
951
+ secret ??= await prompt(rl, "API secret", "");
952
+ identify ??= await prompt(rl, "Identify (sub-account header, blank to skip)", "");
953
+ } finally {
954
+ rl.close();
955
+ }
956
+ }
957
+ if (!name) name = "default";
958
+ if (!env) env = "test";
959
+ if (!baseUrl) baseUrl = env === "prod" ? PROD_BASE_URL : TEST_BASE_URL;
960
+ const profile = {
961
+ "base-url": baseUrl,
962
+ env,
963
+ ...apiKey && apiKey.length > 0 ? { "api-key": apiKey } : {},
964
+ ...secret && secret.length > 0 ? { secret } : {},
965
+ ...identify && identify.length > 0 ? { identify } : { identify: null }
966
+ };
967
+ const cfg = existing ?? {
968
+ version: 1,
969
+ "default-profile": name,
970
+ profiles: {}
971
+ };
972
+ cfg.profiles[name] = profile;
973
+ if (flags.setDefault !== false) {
974
+ cfg["default-profile"] = name;
975
+ }
976
+ writeConfigFile(path, cfg);
977
+ ctx.stdout(`Wrote profile "${name}" to ${path}`);
978
+ });
979
+ }
980
+
981
+ // src/commands/config/set.ts
982
+ var SETTABLE_KEYS = ["base-url", "api-key", "secret", "identify", "env"];
983
+ var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
984
+ "api-key",
985
+ "secret"
986
+ ]);
987
+ function isSettableKey(k) {
988
+ return SETTABLE_KEYS.includes(k);
989
+ }
990
+ async function readLineFromStdin() {
991
+ return new Promise((resolve, reject) => {
992
+ let data = "";
993
+ process.stdin.setEncoding("utf8");
994
+ const onData = (chunk) => {
995
+ data += chunk;
996
+ const idx = data.indexOf("\n");
997
+ if (idx >= 0) {
998
+ process.stdin.removeListener("data", onData);
999
+ process.stdin.removeListener("end", onEnd);
1000
+ resolve(data.slice(0, idx).replace(/\r$/, ""));
1001
+ }
1002
+ };
1003
+ const onEnd = () => {
1004
+ resolve(data.replace(/\r?\n$/, ""));
1005
+ };
1006
+ process.stdin.on("data", onData);
1007
+ process.stdin.on("end", onEnd);
1008
+ process.stdin.on("error", reject);
1009
+ });
1010
+ }
1011
+ function registerConfigSet(parent, ctx) {
1012
+ parent.command("set <key>").description(`Set a profile field (key: ${SETTABLE_KEYS.join(", ")})`).option("--value <v>", "inline value (NOT allowed for secret/api-key)").option("--stdin", "read value from stdin (required for secret/api-key)").action(
1013
+ async (key, opts) => {
1014
+ if (!isSettableKey(key)) {
1015
+ throw new ConfigError(
1016
+ `Unknown key "${key}". Valid keys: ${SETTABLE_KEYS.join(", ")}`
1017
+ );
1018
+ }
1019
+ const sensitive = SENSITIVE_KEYS.has(key);
1020
+ if (sensitive && !opts.stdin) {
1021
+ throw new ConfigError(
1022
+ `Setting "${key}" must use --stdin (do not pass secrets on the command line)`
1023
+ );
1024
+ }
1025
+ let value;
1026
+ if (opts.stdin) {
1027
+ value = await readLineFromStdin();
1028
+ } else if (opts.value !== void 0) {
1029
+ value = opts.value;
1030
+ } else {
1031
+ throw new ConfigError(`Either --value or --stdin must be provided`);
1032
+ }
1033
+ const path = ctx.getConfigPath();
1034
+ const cfg = readConfigFile(path);
1035
+ const profileName = ctx.flags.profile ?? cfg["default-profile"];
1036
+ const profile = cfg.profiles[profileName];
1037
+ if (!profile) {
1038
+ throw new ConfigError(`Profile "${profileName}" not found in ${path}`);
1039
+ }
1040
+ if (key === "env") {
1041
+ if (value !== "test" && value !== "prod") {
1042
+ throw new ConfigError(`env must be "test" or "prod"`);
1043
+ }
1044
+ profile.env = value;
1045
+ } else {
1046
+ profile[key] = value;
1047
+ }
1048
+ writeConfigFile(path, cfg);
1049
+ ctx.stdout(`Updated profile "${profileName}" \u2192 ${key}`);
1050
+ }
1051
+ );
1052
+ }
1053
+
1054
+ // src/commands/config/show.ts
1055
+ function registerConfigShow(parent, ctx) {
1056
+ parent.command("show").description("Show the active profile (credentials redacted by default)").option("--reveal", "show raw credentials in plaintext (DANGEROUS)").action(async (opts) => {
1057
+ const cfg = readConfigFile(ctx.getConfigPath());
1058
+ const profileName = ctx.flags.profile ?? cfg["default-profile"];
1059
+ const p = cfg.profiles[profileName];
1060
+ if (!p) {
1061
+ throw new ConfigError(`Profile "${profileName}" not found`);
1062
+ }
1063
+ const display = opts.reveal ? p : redactProfile(p);
1064
+ if (opts.reveal) {
1065
+ ctx.stderr("WARN: --reveal exposes raw credentials. Do not paste this output anywhere.");
1066
+ }
1067
+ ctx.stdout(
1068
+ render(
1069
+ { profile: profileName, ...display },
1070
+ {
1071
+ format: effectiveFormat(ctx.outputFormat, ctx.isTTY),
1072
+ isTTY: ctx.isTTY
1073
+ }
1074
+ )
1075
+ );
1076
+ });
1077
+ }
1078
+
1079
+ // src/commands/config/use.ts
1080
+ function registerConfigUse(parent, ctx) {
1081
+ parent.command("use <profile>").description("Switch the default profile").action(async (profile) => {
1082
+ const path = ctx.getConfigPath();
1083
+ const cfg = readConfigFile(path);
1084
+ if (!cfg.profiles[profile]) {
1085
+ throw new ConfigError(`Profile "${profile}" not found in ${path}`);
1086
+ }
1087
+ cfg["default-profile"] = profile;
1088
+ writeConfigFile(path, cfg);
1089
+ ctx.stdout(`Switched default profile to "${profile}"`);
1090
+ });
1091
+ }
1092
+
1093
+ // src/commands/config/list-profiles.ts
1094
+ function registerConfigListProfiles(parent, ctx) {
1095
+ parent.command("list-profiles").description("List all profiles defined in the config file (credentials redacted)").action(async () => {
1096
+ const cfg = readConfigFile(ctx.getConfigPath());
1097
+ const rows = Object.entries(cfg.profiles).map(([name, p]) => ({
1098
+ name,
1099
+ default: name === cfg["default-profile"] ? "*" : "",
1100
+ env: p.env ?? "",
1101
+ "base-url": p["base-url"],
1102
+ "api-key": p["api-key"] ? redactSecret(p["api-key"]) : "",
1103
+ identify: p.identify ?? ""
1104
+ }));
1105
+ ctx.stdout(
1106
+ render(rows, {
1107
+ format: effectiveFormat(ctx.outputFormat, ctx.isTTY),
1108
+ isTTY: ctx.isTTY
1109
+ })
1110
+ );
1111
+ });
1112
+ }
1113
+
1114
+ // src/commands/config/remove.ts
1115
+ function registerConfigRemove(parent, ctx) {
1116
+ parent.command("remove <profile>").description("Delete a profile from the config file").action(async (profile) => {
1117
+ const path = ctx.getConfigPath();
1118
+ const cfg = readConfigFile(path);
1119
+ if (!cfg.profiles[profile]) {
1120
+ throw new ConfigError(`Profile "${profile}" not found in ${path}`);
1121
+ }
1122
+ const remaining = Object.keys(cfg.profiles).filter((k) => k !== profile);
1123
+ if (remaining.length === 0) {
1124
+ throw new ConfigError(
1125
+ `Refusing to remove the last profile "${profile}". Use "config init" to start fresh.`
1126
+ );
1127
+ }
1128
+ delete cfg.profiles[profile];
1129
+ if (cfg["default-profile"] === profile) {
1130
+ cfg["default-profile"] = remaining[0];
1131
+ ctx.stdout(`Default profile reassigned to "${remaining[0]}"`);
1132
+ }
1133
+ writeConfigFile(path, cfg);
1134
+ ctx.stdout(`Removed profile "${profile}"`);
1135
+ });
1136
+ }
1137
+
1138
+ // src/core/dry-run.ts
1139
+ function renderDryRun(p) {
1140
+ const lines = [
1141
+ "--- DRY RUN (no request sent) ---",
1142
+ `${p.method} ${p.url}`
1143
+ ];
1144
+ if (p.body !== void 0) {
1145
+ lines.push("Body:");
1146
+ lines.push(JSON.stringify(p.body, null, 2));
1147
+ }
1148
+ lines.push("");
1149
+ lines.push("To execute, re-run with --confirm.");
1150
+ return lines.join("\n");
1151
+ }
1152
+
1153
+ // src/core/execute-write.ts
1154
+ async function executeWrite(opts) {
1155
+ if (!opts.confirm) {
1156
+ const url = `${opts.config?.baseUrl ?? ""}${opts.path}`;
1157
+ const preview = renderDryRun({ method: opts.method, url, body: opts.body });
1158
+ throw new DryRunInterception(preview);
1159
+ }
1160
+ return opts.send();
1161
+ }
1162
+
1163
+ // src/commands/_write/_helpers.ts
1164
+ function pruneEmpty(o) {
1165
+ const out = {};
1166
+ for (const [k, v] of Object.entries(o)) {
1167
+ if (v != null && v !== "") out[k] = v;
1168
+ }
1169
+ return out;
1170
+ }
1171
+ async function runWrite(ctx, path, body) {
1172
+ const cfg = ctx.resolveConfig({ requireAuth: true });
1173
+ const c = ctx.http({ requireAuth: true });
1174
+ const data = await executeWrite({
1175
+ confirm: ctx.confirm ?? false,
1176
+ method: "POST",
1177
+ path,
1178
+ body,
1179
+ send: () => c.postPrivate(path, body),
1180
+ config: cfg
1181
+ });
1182
+ ctx.stdout(
1183
+ render(data, {
1184
+ format: effectiveFormat(ctx.outputFormat, ctx.isTTY),
1185
+ isTTY: ctx.isTTY
1186
+ })
1187
+ );
1188
+ }
1189
+
1190
+ // src/commands/order/create.ts
1191
+ function registerOrderCreate(parent, ctx) {
1192
+ parent.command("create").description("Place a new order (POST /v2/order/create)").requiredOption("--symbol <symbol>", "trading pair, e.g. btc_usdt").requiredOption("--order-type <type>", "LIMIT | MARKET | STOP_LIMIT | etc.").requiredOption("--order-side <side>", "BUY | SELL").requiredOption("--position-side <side>", "LONG | SHORT | NET").requiredOption("--orig-qty <qty>", "order quantity (string, decimal-safe)").option("--price <price>", "limit price (string)").option("--time-in-force <tif>", "GTC | IOC | FOK | GTX").option("--reduce-only <bool>", "true | false").option("--client-order-id <id>", "client-supplied order id").option("--position-id <id>", "existing position id (for hedge mode)").option("--leverage <lv>", "override leverage").option("--trigger-profit-price <price>", "TP trigger price").option("--trigger-stop-price <price>", "SL trigger price").option("--profit-order-type <type>", "TP child order type").option("--stop-order-type <type>", "SL child order type").option("--profit-order-price <price>", "TP child order price").option("--stop-order-price <price>", "SL child order price").option("--market-order-level <lv>", "market order depth level").action(
1193
+ async (opts) => {
1194
+ const body = pruneEmpty({
1195
+ symbol: opts.symbol,
1196
+ orderType: opts.orderType,
1197
+ orderSide: opts.orderSide,
1198
+ positionSide: opts.positionSide,
1199
+ origQty: opts.origQty,
1200
+ price: opts.price,
1201
+ timeInForce: opts.timeInForce,
1202
+ reduceOnly: opts.reduceOnly,
1203
+ clientOrderId: opts.clientOrderId,
1204
+ positionId: opts.positionId,
1205
+ leverage: opts.leverage,
1206
+ triggerProfitPrice: opts.triggerProfitPrice,
1207
+ triggerStopPrice: opts.triggerStopPrice,
1208
+ profitOrderType: opts.profitOrderType,
1209
+ stopOrderType: opts.stopOrderType,
1210
+ profitOrderPrice: opts.profitOrderPrice,
1211
+ stopOrderPrice: opts.stopOrderPrice,
1212
+ marketOrderLevel: opts.marketOrderLevel
1213
+ });
1214
+ await runWrite(ctx, "/v2/order/create", body);
1215
+ }
1216
+ );
1217
+ }
1218
+
1219
+ // src/commands/order/create-batch.ts
1220
+ function registerOrderCreateBatch(parent, ctx) {
1221
+ parent.command("create-batch").description("Place a batch of orders (POST /v2/order/create-batch)").requiredOption(
1222
+ "--list <jsonArray>",
1223
+ `JSON-encoded array of order objects, e.g. '[{"symbol":"btc_usdt",...}]'`
1224
+ ).action(async (opts) => {
1225
+ await runWrite(ctx, "/v2/order/create-batch", { list: opts.list });
1226
+ });
1227
+ }
1228
+
1229
+ // src/commands/order/cancel.ts
1230
+ function registerOrderCancel(parent, ctx) {
1231
+ parent.command("cancel").description("Cancel an order (POST /v2/order/cancel)").requiredOption("--order-id <id>", "order id to cancel").action(async (opts) => {
1232
+ await runWrite(ctx, "/v2/order/cancel", { orderId: opts.orderId });
1233
+ });
1234
+ }
1235
+
1236
+ // src/commands/order/cancel-batch.ts
1237
+ function registerOrderCancelBatch(parent, ctx) {
1238
+ parent.command("cancel-batch").description("Cancel a batch of orders (POST /v2/order/cancel-batch)").requiredOption(
1239
+ "--order-ids <jsonArray>",
1240
+ 'JSON-encoded array of order ids, e.g. "[123,456]"'
1241
+ ).action(async (opts) => {
1242
+ await runWrite(ctx, "/v2/order/cancel-batch", { orderIds: opts.orderIds });
1243
+ });
1244
+ }
1245
+
1246
+ // src/commands/order/cancel-all.ts
1247
+ function registerOrderCancelAll(parent, ctx) {
1248
+ parent.command("cancel-all").description("Cancel all orders (POST /v2/order/cancel-all)").option("--symbol <symbol>", "restrict to a single trading pair").action(async (opts) => {
1249
+ await runWrite(ctx, "/v2/order/cancel-all", pruneEmpty({ symbol: opts.symbol }));
1250
+ });
1251
+ }
1252
+
1253
+ // src/commands/entrust/create-plan.ts
1254
+ function registerEntrustCreatePlan(parent, ctx) {
1255
+ parent.command("create-plan").description("Create a plan entrust (POST /v2/entrust/create-plan)").requiredOption("--symbol <symbol>", "trading pair").requiredOption("--order-side <side>", "BUY | SELL").requiredOption("--position-side <side>", "LONG | SHORT | NET").requiredOption("--entrust-type <type>", "plan entrust type").requiredOption("--time-in-force <tif>", "time-in-force, e.g. GTC").requiredOption("--trigger-price-type <type>", "INDEX | MARK | LATEST").requiredOption("--orig-qty <qty>", "order quantity (string)").option("--stop-price <price>", "stop price").option("--price <price>", "limit price").option("--position-id <id>", "existing position id").option("--market-order-level <lv>", "market order depth level").option("--expire-time <ms>", "expiration time in ms").action(
1256
+ async (opts) => {
1257
+ const body = pruneEmpty({
1258
+ symbol: opts.symbol,
1259
+ orderSide: opts.orderSide,
1260
+ positionSide: opts.positionSide,
1261
+ entrustType: opts.entrustType,
1262
+ timeInForce: opts.timeInForce,
1263
+ triggerPriceType: opts.triggerPriceType,
1264
+ origQty: opts.origQty,
1265
+ stopPrice: opts.stopPrice,
1266
+ price: opts.price,
1267
+ positionId: opts.positionId,
1268
+ marketOrderLevel: opts.marketOrderLevel,
1269
+ expireTime: opts.expireTime
1270
+ });
1271
+ await runWrite(ctx, "/v2/entrust/create-plan", body);
1272
+ }
1273
+ );
1274
+ }
1275
+
1276
+ // src/commands/entrust/create-profit.ts
1277
+ function registerEntrustCreateProfit(parent, ctx) {
1278
+ parent.command("create-profit").description("Create a TP/SL entrust (POST /v2/entrust/create-profit)").requiredOption("--symbol <symbol>", "trading pair").requiredOption("--orig-qty <qty>", "order quantity (string)").option("--position-side <side>", "LONG | SHORT | NET").option("--order-side <side>", "BUY | SELL").option("--trigger-price-type <type>", "INDEX | MARK | LATEST").option("--trigger-profit-price <price>", "TP trigger price").option("--trigger-stop-price <price>", "SL trigger price").option("--profit-order-type <type>", "TP child order type").option("--stop-order-type <type>", "SL child order type").option("--profit-order-price <price>", "TP child order price").option("--stop-order-price <price>", "SL child order price").option("--position-id <id>", "existing position id").option("--reduce-only <bool>", "true | false").option("--profit-flag <flag>", "profit flag").option("--expire-time <ms>", "expiration time in ms").action(
1279
+ async (opts) => {
1280
+ const body = pruneEmpty({
1281
+ symbol: opts.symbol,
1282
+ origQty: opts.origQty,
1283
+ positionSide: opts.positionSide,
1284
+ orderSide: opts.orderSide,
1285
+ triggerPriceType: opts.triggerPriceType,
1286
+ triggerProfitPrice: opts.triggerProfitPrice,
1287
+ triggerStopPrice: opts.triggerStopPrice,
1288
+ profitOrderType: opts.profitOrderType,
1289
+ stopOrderType: opts.stopOrderType,
1290
+ profitOrderPrice: opts.profitOrderPrice,
1291
+ stopOrderPrice: opts.stopOrderPrice,
1292
+ positionId: opts.positionId,
1293
+ reduceOnly: opts.reduceOnly,
1294
+ profitFlag: opts.profitFlag,
1295
+ expireTime: opts.expireTime
1296
+ });
1297
+ await runWrite(ctx, "/v2/entrust/create-profit", body);
1298
+ }
1299
+ );
1300
+ }
1301
+
1302
+ // src/commands/entrust/cancel-plan.ts
1303
+ function registerEntrustCancelPlan(parent, ctx) {
1304
+ parent.command("cancel-plan").description("Cancel a plan entrust (POST /v2/entrust/cancel-plan)").requiredOption("--entrust-id <id>", "plan entrust id to cancel").action(async (opts) => {
1305
+ await runWrite(ctx, "/v2/entrust/cancel-plan", { entrustId: opts.entrustId });
1306
+ });
1307
+ }
1308
+
1309
+ // src/commands/entrust/cancel-profit.ts
1310
+ function registerEntrustCancelProfit(parent, ctx) {
1311
+ parent.command("cancel-profit").description("Cancel a TP/SL entrust (POST /v2/entrust/cancel-profit-stop)").requiredOption("--profit-id <id>", "TP/SL entrust id to cancel").action(async (opts) => {
1312
+ await runWrite(ctx, "/v2/entrust/cancel-profit-stop", { profitId: opts.profitId });
1313
+ });
1314
+ }
1315
+
1316
+ // src/commands/entrust/update-profit.ts
1317
+ function registerEntrustUpdateProfit(parent, ctx) {
1318
+ parent.command("update-profit").description("Update a TP/SL entrust (POST /v2/entrust/update-profit-stop)").requiredOption("--profit-id <id>", "TP/SL entrust id").option("--trigger-profit-price <price>", "TP trigger price").option("--trigger-stop-price <price>", "SL trigger price").option("--profit-order-price <price>", "TP child order price").option("--stop-order-price <price>", "SL child order price").action(
1319
+ async (opts) => {
1320
+ const body = pruneEmpty({
1321
+ profitId: opts.profitId,
1322
+ triggerProfitPrice: opts.triggerProfitPrice,
1323
+ triggerStopPrice: opts.triggerStopPrice,
1324
+ profitOrderPrice: opts.profitOrderPrice,
1325
+ stopOrderPrice: opts.stopOrderPrice
1326
+ });
1327
+ await runWrite(ctx, "/v2/entrust/update-profit-stop", body);
1328
+ }
1329
+ );
1330
+ }
1331
+
1332
+ // src/commands/entrust/cancel-all-plan.ts
1333
+ function registerEntrustCancelAllPlan(parent, ctx) {
1334
+ parent.command("cancel-all-plan").description("Cancel all plan entrusts (POST /v2/entrust/cancel-all-plan)").option("--symbol <symbol>", "restrict to a single trading pair").action(async (opts) => {
1335
+ await runWrite(
1336
+ ctx,
1337
+ "/v2/entrust/cancel-all-plan",
1338
+ pruneEmpty({ symbol: opts.symbol })
1339
+ );
1340
+ });
1341
+ }
1342
+
1343
+ // src/commands/entrust/cancel-all-profit.ts
1344
+ function registerEntrustCancelAllProfit(parent, ctx) {
1345
+ parent.command("cancel-all-profit").description("Cancel all TP/SL entrusts (POST /v2/entrust/cancel-all-profit-stop)").option("--symbol <symbol>", "restrict to a single trading pair").action(async (opts) => {
1346
+ await runWrite(
1347
+ ctx,
1348
+ "/v2/entrust/cancel-all-profit-stop",
1349
+ pruneEmpty({ symbol: opts.symbol })
1350
+ );
1351
+ });
1352
+ }
1353
+
1354
+ // src/commands/order-entrust/cancel.ts
1355
+ function registerOrderEntrustCancel(parent, ctx) {
1356
+ parent.command("cancel").description("Cancel an order or entrust (POST /v2/order-entrust/cancel)").requiredOption("--type <type>", "ORDER | PLAN | PROFIT_STOP").requiredOption("--id <id>", "target id").action(async (opts) => {
1357
+ await runWrite(ctx, "/v2/order-entrust/cancel", { type: opts.type, id: opts.id });
1358
+ });
1359
+ }
1360
+
1361
+ // src/commands/order-entrust/cancel-all.ts
1362
+ function registerOrderEntrustCancelAll(parent, ctx) {
1363
+ parent.command("cancel-all").description("Cancel all orders and entrusts (POST /v2/order-entrust/cancel-all)").option("--symbol <symbol>", "restrict to a single trading pair").action(async (opts) => {
1364
+ await runWrite(
1365
+ ctx,
1366
+ "/v2/order-entrust/cancel-all",
1367
+ pruneEmpty({ symbol: opts.symbol })
1368
+ );
1369
+ });
1370
+ }
1371
+
1372
+ // src/commands/position/adjust-leverage.ts
1373
+ function registerPositionAdjustLeverage(parent, ctx) {
1374
+ parent.command("adjust-leverage").description("Adjust position leverage (POST /v2/position/adjust-leverage)").requiredOption("--symbol <symbol>", "trading pair").requiredOption("--leverage <lv>", "new leverage").action(async (opts) => {
1375
+ await runWrite(ctx, "/v2/position/adjust-leverage", {
1376
+ symbol: opts.symbol,
1377
+ leverage: opts.leverage
1378
+ });
1379
+ });
1380
+ }
1381
+
1382
+ // src/commands/position/margin.ts
1383
+ function registerPositionMargin(parent, ctx) {
1384
+ parent.command("margin").description("Adjust position margin (POST /v2/position/margin)").requiredOption("--symbol <symbol>", "trading pair").requiredOption("--position-side <side>", "LONG | SHORT").requiredOption("--position-id <id>", "position id").requiredOption("--margin <amount>", "margin amount (string)").requiredOption("--type <type>", "1 = add, 2 = reduce (per V2 docs)").action(
1385
+ async (opts) => {
1386
+ await runWrite(ctx, "/v2/position/margin", {
1387
+ symbol: opts.symbol,
1388
+ positionSide: opts.positionSide,
1389
+ positionId: opts.positionId,
1390
+ margin: opts.margin,
1391
+ type: opts.type
1392
+ });
1393
+ }
1394
+ );
1395
+ }
1396
+
1397
+ // src/commands/position/auto-margin.ts
1398
+ function registerPositionAutoMargin(parent, ctx) {
1399
+ parent.command("auto-margin").description("Toggle auto-margin (POST /v2/position/auto-margin)").requiredOption("--symbol <symbol>", "trading pair").requiredOption("--position-side <side>", "LONG | SHORT").requiredOption("--auto-margin <bool>", "true | false").action(
1400
+ async (opts) => {
1401
+ await runWrite(ctx, "/v2/position/auto-margin", {
1402
+ symbol: opts.symbol,
1403
+ positionSide: opts.positionSide,
1404
+ autoMargin: opts.autoMargin
1405
+ });
1406
+ }
1407
+ );
1408
+ }
1409
+
1410
+ // src/commands/position/close-all.ts
1411
+ function registerPositionCloseAll(parent, ctx) {
1412
+ parent.command("close-all").description("Close all positions (POST /v2/position/close-all)").option("--symbol <symbol>", "restrict to a single trading pair").action(async (opts) => {
1413
+ await runWrite(ctx, "/v2/position/close-all", pruneEmpty({ symbol: opts.symbol }));
1414
+ });
1415
+ }
1416
+
1417
+ // src/commands/position/merge.ts
1418
+ function registerPositionMerge(parent, ctx) {
1419
+ parent.command("merge").description("Merge positions (POST /v2/position/merge)").requiredOption("--symbol <symbol>", "trading pair").action(async (opts) => {
1420
+ await runWrite(ctx, "/v2/position/merge", { symbol: opts.symbol });
1421
+ });
1422
+ }
1423
+
1424
+ // src/commands/position/change-type.ts
1425
+ function registerPositionChangeType(parent, ctx) {
1426
+ parent.command("change-type").description("Change position type (POST /v2/position/change-type)").requiredOption("--symbol <symbol>", "trading pair").requiredOption("--position-type <type>", "CROSS | ISOLATED").requiredOption("--position-model <model>", "NET | HEDGE").action(
1427
+ async (opts) => {
1428
+ await runWrite(ctx, "/v2/position/change-type", {
1429
+ symbol: opts.symbol,
1430
+ positionType: opts.positionType,
1431
+ positionModel: opts.positionModel
1432
+ });
1433
+ }
1434
+ );
1435
+ }
1436
+
1437
+ // src/index.ts
1438
+ function buildProgram(opts) {
1439
+ const stdoutFn = opts?.stdout ?? ((s) => process.stdout.write(s + "\n"));
1440
+ const stderrFn = opts?.stderr ?? ((s) => process.stderr.write(s + "\n"));
1441
+ const env = opts?.env ?? process.env;
1442
+ const cwd = opts?.cwd ?? process.cwd();
1443
+ const isTTY = opts?.isTTY ?? Boolean(process.stdout.isTTY);
1444
+ const getConfigPath = () => {
1445
+ const override = env["ONEBULLEX_CONFIG_PATH"];
1446
+ return override && override.length > 0 ? override : DEFAULT_CONFIG_PATH;
1447
+ };
1448
+ const ctx = {
1449
+ stdout: stdoutFn,
1450
+ stderr: stderrFn,
1451
+ env,
1452
+ cwd,
1453
+ isTTY,
1454
+ outputFormat: void 0,
1455
+ confirm: void 0,
1456
+ getConfigPath,
1457
+ flags: {},
1458
+ resolveConfig: ({ requireAuth: _requireAuth }) => {
1459
+ const flags = program.opts();
1460
+ return resolveConfig({
1461
+ configPath: getConfigPath(),
1462
+ flags: {
1463
+ profile: flags.profile,
1464
+ "base-url": flags.baseUrl,
1465
+ "api-key": flags.apiKey,
1466
+ secret: flags.secret,
1467
+ debug: flags.debug,
1468
+ timeout: flags.timeout
1469
+ },
1470
+ env
1471
+ });
1472
+ },
1473
+ http: ({ requireAuth }) => {
1474
+ const cfg = ctx.resolveConfig({ requireAuth });
1475
+ return new HttpClient(cfg, opts?.fetch);
1476
+ }
1477
+ };
1478
+ const program = new Command("onebullex").version(true ? "1.1.2" : "0.0.0-dev").description("OneBullEx exchange CLI").option("-p, --profile <name>", "config profile to use").option("-o, --output <format>", "output format: table | json").option("--debug", "enable debug logging").option("--timeout <ms>", "request timeout in milliseconds", parseInt).option("--confirm", "confirm write operations (required for non-dry-run writes)").option("--base-url <url>", "override base URL").option("--api-key <key>", "override api key (env: ONEBULLEX_API_KEY)").option("--secret <s>", "override secret (env: ONEBULLEX_SECRET; CLI flag discouraged for security)").exitOverride();
1479
+ program.hook("preAction", (thisCommand, _actionCommand) => {
1480
+ const flags = thisCommand.opts();
1481
+ if (flags.output === "table" || flags.output === "json") {
1482
+ ctx.outputFormat = flags.output;
1483
+ }
1484
+ ctx.confirm = flags.confirm;
1485
+ ctx.flags = {
1486
+ profile: flags.profile,
1487
+ output: ctx.outputFormat,
1488
+ debug: flags.debug,
1489
+ timeout: flags.timeout,
1490
+ confirm: flags.confirm,
1491
+ baseUrl: flags.baseUrl
1492
+ };
1493
+ checkConfigPermissions(getConfigPath(), (msg) => stderrFn(msg));
1494
+ });
1495
+ const publicCmd = program.command("public").description("Public market data endpoints");
1496
+ registerPublicTime(publicCmd, ctx);
1497
+ const symbol = program.command("symbol").description("Trading pair metadata");
1498
+ registerSymbolList(symbol, ctx);
1499
+ registerSymbolGet(symbol, ctx);
1500
+ registerSymbolCoins(symbol, ctx);
1501
+ registerSymbolAll(symbol, ctx);
1502
+ const ticker = program.command("ticker").description("Tickers and aggregated tickers");
1503
+ registerTickerGet(ticker, ctx);
1504
+ registerTickerList(ticker, ctx);
1505
+ registerTickerAgg(ticker, ctx);
1506
+ registerTickerAggList(ticker, ctx);
1507
+ const depth = program.command("depth").description("Order book depth");
1508
+ registerDepthGet(depth, ctx);
1509
+ const deal = program.command("deal").description("Recent trades");
1510
+ registerDealList(deal, ctx);
1511
+ const kline = program.command("kline").description("Candlestick data");
1512
+ registerKlineList(kline, ctx);
1513
+ const markPrice = program.command("mark-price").description("Mark prices");
1514
+ registerMarkPriceList(markPrice, ctx);
1515
+ registerMarkPriceGet(markPrice, ctx);
1516
+ const indexPrice = program.command("index-price").description("Index prices");
1517
+ registerIndexPriceList(indexPrice, ctx);
1518
+ registerIndexPriceGet(indexPrice, ctx);
1519
+ const funding = program.command("funding").description("Funding rates");
1520
+ registerFundingRate(funding, ctx);
1521
+ registerFundingHistory(funding, ctx);
1522
+ const riskBalance = program.command("risk-balance").description("Risk balance");
1523
+ registerRiskBalanceList(riskBalance, ctx);
1524
+ const openInterest = program.command("open-interest").description("Open interest");
1525
+ registerOpenInterestGet(openInterest, ctx);
1526
+ const leverage = program.command("leverage").description("Leverage brackets");
1527
+ registerLeverageBracketsList(leverage, ctx);
1528
+ registerLeverageBracketsGet(leverage, ctx);
1529
+ const listenKey = program.command("listen-key").description("User listen key for WebSocket");
1530
+ registerListenKeyGet(listenKey, ctx);
1531
+ const balance = program.command("balance").description("Account balance");
1532
+ registerBalanceList(balance, ctx);
1533
+ registerBalanceGet(balance, ctx);
1534
+ registerBalanceBills(balance, ctx);
1535
+ const order = program.command("order").description("Orders");
1536
+ registerOrderListUnfinished(order, ctx);
1537
+ registerOrderListUnfinishedMulti(order, ctx);
1538
+ registerOrderList(order, ctx);
1539
+ registerOrderListByIds(order, ctx);
1540
+ registerOrderListHistory(order, ctx);
1541
+ registerOrderGet(order, ctx);
1542
+ registerOrderTrades(order, ctx);
1543
+ registerOrderCreate(order, ctx);
1544
+ registerOrderCreateBatch(order, ctx);
1545
+ registerOrderCancel(order, ctx);
1546
+ registerOrderCancelBatch(order, ctx);
1547
+ registerOrderCancelAll(order, ctx);
1548
+ const entrust = program.command("entrust").description("Plan and TP/SL entrusts");
1549
+ registerEntrustPlanList(entrust, ctx);
1550
+ registerEntrustPlanHistory(entrust, ctx);
1551
+ registerEntrustPlanGet(entrust, ctx);
1552
+ registerEntrustProfitList(entrust, ctx);
1553
+ registerEntrustProfitGet(entrust, ctx);
1554
+ registerEntrustCreatePlan(entrust, ctx);
1555
+ registerEntrustCreateProfit(entrust, ctx);
1556
+ registerEntrustCancelPlan(entrust, ctx);
1557
+ registerEntrustCancelProfit(entrust, ctx);
1558
+ registerEntrustUpdateProfit(entrust, ctx);
1559
+ registerEntrustCancelAllPlan(entrust, ctx);
1560
+ registerEntrustCancelAllProfit(entrust, ctx);
1561
+ const orderEntrust = program.command("order-entrust").description("Combined orders and entrusts");
1562
+ registerOrderEntrustList(orderEntrust, ctx);
1563
+ registerOrderEntrustCancel(orderEntrust, ctx);
1564
+ registerOrderEntrustCancelAll(orderEntrust, ctx);
1565
+ const position = program.command("position").description("Positions");
1566
+ registerPositionList(position, ctx);
1567
+ registerPositionAdjustLeverage(position, ctx);
1568
+ registerPositionMargin(position, ctx);
1569
+ registerPositionAutoMargin(position, ctx);
1570
+ registerPositionCloseAll(position, ctx);
1571
+ registerPositionMerge(position, ctx);
1572
+ registerPositionChangeType(position, ctx);
1573
+ const config = program.command("config").description("Manage CLI configuration");
1574
+ registerConfigInit(config, ctx);
1575
+ registerConfigSet(config, ctx);
1576
+ registerConfigShow(config, ctx);
1577
+ registerConfigUse(config, ctx);
1578
+ registerConfigListProfiles(config, ctx);
1579
+ registerConfigRemove(config, ctx);
1580
+ return program;
1581
+ }
1582
+ async function main(argv) {
1583
+ const program = buildProgram();
1584
+ try {
1585
+ await program.parseAsync(argv);
1586
+ return EXIT.OK;
1587
+ } catch (err) {
1588
+ const stderrFn = (s) => process.stderr.write(s + "\n");
1589
+ if (err && typeof err === "object" && "code" in err && typeof err.code === "string") {
1590
+ const code = err.code;
1591
+ if (code === "commander.helpDisplayed" || code === "commander.version" || code === "commander.help") {
1592
+ return EXIT.OK;
1593
+ }
1594
+ if (code === "commander.unknownCommand" || code === "commander.unknownOption" || code === "commander.missingArgument" || code === "commander.missingMandatoryOptionValue" || code === "commander.invalidArgument") {
1595
+ return EXIT.GENERIC;
1596
+ }
1597
+ }
1598
+ if (err instanceof DryRunInterception) {
1599
+ process.stdout.write(`${String(err.preview)}
1600
+ `);
1601
+ stderrFn(err.message);
1602
+ return EXIT.DRY_RUN;
1603
+ }
1604
+ if (err instanceof ConfigError) {
1605
+ stderrFn(`Config error: ${err.message}`);
1606
+ return EXIT.GENERIC;
1607
+ }
1608
+ if (err instanceof OneBullExError) {
1609
+ stderrFn(`API error [${err.returnCode}]: ${err.message}`);
1610
+ return EXIT.API_ERROR;
1611
+ }
1612
+ if (err instanceof Error && (err.name === "AbortError" || "code" in err && err.code === "ECONNREFUSED")) {
1613
+ stderrFn(`Network error: ${err.message}`);
1614
+ return EXIT.NETWORK;
1615
+ }
1616
+ stderrFn(`Error: ${err instanceof Error ? err.message : String(err)}`);
1617
+ return EXIT.GENERIC;
1618
+ }
1619
+ }
1620
+ var isEntry = process.argv[1] && (process.argv[1].endsWith("/index.ts") || process.argv[1].endsWith("/index.js") || process.argv[1].endsWith("\\index.ts") || process.argv[1].endsWith("\\index.js"));
1621
+ if (isEntry) {
1622
+ void main(process.argv).then((code) => process.exit(code));
1623
+ }
1624
+ export {
1625
+ buildProgram,
1626
+ main
1627
+ };