@okx_ai/okx-trade-cli 1.2.5-beta.2 → 1.2.5-beta.3
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 +18 -459
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6482,223 +6482,6 @@ function registerSpotTradeTools() {
|
|
|
6482
6482
|
}
|
|
6483
6483
|
];
|
|
6484
6484
|
}
|
|
6485
|
-
var BASE2 = "/api/v5/copytrading";
|
|
6486
|
-
var LAST_DAYS_30 = "2";
|
|
6487
|
-
var INST_TYPE_SWAP = "SWAP";
|
|
6488
|
-
var COPY_MODE_SMART = "smart_copy";
|
|
6489
|
-
var COPY_MODE_FIXED = "fixed_amount";
|
|
6490
|
-
var COPY_MODE_RATIO = "ratio_copy";
|
|
6491
|
-
var COPY_INST_ID_TYPE_COPY = "copy";
|
|
6492
|
-
var COPY_INST_ID_TYPE_CUSTOM = "custom";
|
|
6493
|
-
var COPY_MGN_MODE_COPY = "copy";
|
|
6494
|
-
var COPY_MGN_MODE_ISOLATED = "isolated";
|
|
6495
|
-
var INST_TYPE_SPOT = "SPOT";
|
|
6496
|
-
var SUB_POS_CLOSE_COPY = "copy_close";
|
|
6497
|
-
function registerCopyTradeTools() {
|
|
6498
|
-
return [
|
|
6499
|
-
{
|
|
6500
|
-
name: "copytrading_get_lead_traders",
|
|
6501
|
-
module: "copytrading",
|
|
6502
|
-
description: "Get top lead traders ranking. Public endpoint, no auth required. Use for: \u4EA4\u6613\u5458\u6392\u884C, \u5E26\u5355\u5458\u63A8\u8350, top traders.",
|
|
6503
|
-
isWrite: false,
|
|
6504
|
-
inputSchema: {
|
|
6505
|
-
type: "object",
|
|
6506
|
-
properties: {
|
|
6507
|
-
instType: { type: "string", enum: ["SWAP", "SPOT"], description: "Instrument type: SPOT for spot copy traders (\u73B0\u8D27\u5E26\u5355\u5458), SWAP for contract copy traders (\u5408\u7EA6\u5E26\u5355\u5458). Defaults to SWAP \u2014 always pass explicitly." },
|
|
6508
|
-
sortType: { type: "string", enum: ["overview", "pnl", "aum", "win_ratio", "pnl_ratio", "current_copy_trader_pnl"], description: "Sort by: overview (default), pnl, aum, win_ratio, pnl_ratio, current_copy_trader_pnl" },
|
|
6509
|
-
state: { type: "string", enum: ["0", "1"], description: "0=all traders (default), 1=only traders with open slots" },
|
|
6510
|
-
minLeadDays: { type: "string", enum: ["1", "2", "3", "4"], description: "Min lead trading days: 1=7d, 2=30d, 3=90d, 4=180d" },
|
|
6511
|
-
minAssets: { type: "string", description: "Min trader assets (USDT)" },
|
|
6512
|
-
maxAssets: { type: "string", description: "Max trader assets (USDT)" },
|
|
6513
|
-
minAum: { type: "string", description: "Min AUM / copy trading scale (USDT)" },
|
|
6514
|
-
maxAum: { type: "string", description: "Max AUM / copy trading scale (USDT)" },
|
|
6515
|
-
page: { type: "string", description: "Page number for pagination" },
|
|
6516
|
-
dataVer: { type: "string", description: "Ranking data version (14-digit, e.g. 20231010182400). Use when paginating to keep consistent results." },
|
|
6517
|
-
limit: { type: "number", description: "Max results per page (default 10, max 20)" }
|
|
6518
|
-
}
|
|
6519
|
-
},
|
|
6520
|
-
handler: async (rawArgs, context) => {
|
|
6521
|
-
const args = asRecord(rawArgs);
|
|
6522
|
-
const response = await context.client.publicGet(
|
|
6523
|
-
`${BASE2}/public-lead-traders`,
|
|
6524
|
-
compactObject({
|
|
6525
|
-
instType: readString(args, "instType") ?? INST_TYPE_SWAP,
|
|
6526
|
-
sortType: readString(args, "sortType") ?? "overview",
|
|
6527
|
-
state: readString(args, "state"),
|
|
6528
|
-
minLeadDays: readString(args, "minLeadDays"),
|
|
6529
|
-
minAssets: readString(args, "minAssets"),
|
|
6530
|
-
maxAssets: readString(args, "maxAssets"),
|
|
6531
|
-
minAum: readString(args, "minAum"),
|
|
6532
|
-
maxAum: readString(args, "maxAum"),
|
|
6533
|
-
page: readString(args, "page"),
|
|
6534
|
-
dataVer: readString(args, "dataVer"),
|
|
6535
|
-
limit: String(readNumber(args, "limit") ?? 10)
|
|
6536
|
-
})
|
|
6537
|
-
);
|
|
6538
|
-
const raw = response;
|
|
6539
|
-
const dataArr = Array.isArray(raw.data) ? raw.data : [];
|
|
6540
|
-
const first = dataArr[0] ?? {};
|
|
6541
|
-
return {
|
|
6542
|
-
endpoint: response.endpoint,
|
|
6543
|
-
requestTime: response.requestTime,
|
|
6544
|
-
dataVer: String(first["dataVer"] ?? ""),
|
|
6545
|
-
totalPage: String(first["totalPage"] ?? ""),
|
|
6546
|
-
data: first["ranks"] ?? []
|
|
6547
|
-
};
|
|
6548
|
-
}
|
|
6549
|
-
},
|
|
6550
|
-
{
|
|
6551
|
-
name: "copytrading_get_trader_details",
|
|
6552
|
-
module: "copytrading",
|
|
6553
|
-
description: "Get full profile of a specific lead trader: daily P&L, statistics (win rate, position stats, follower P&L), and preferred trading currencies. All returned together. Public endpoint, no auth required.",
|
|
6554
|
-
isWrite: false,
|
|
6555
|
-
inputSchema: {
|
|
6556
|
-
type: "object",
|
|
6557
|
-
properties: {
|
|
6558
|
-
uniqueCode: { type: "string", description: "Lead trader unique code (16 chars)" },
|
|
6559
|
-
instType: { type: "string", enum: ["SWAP", "SPOT"], description: "Instrument type: SPOT for spot copy traders (\u73B0\u8D27\u5E26\u5355\u5458), SWAP for contract copy traders (\u5408\u7EA6\u5E26\u5355\u5458). Defaults to SWAP \u2014 always pass explicitly." },
|
|
6560
|
-
lastDays: { type: "string", enum: ["1", "2", "3", "4"], description: "Time range for pnl and stats: 1=7d 2=30d 3=90d 4=365d (default: 2)" }
|
|
6561
|
-
},
|
|
6562
|
-
required: ["uniqueCode"]
|
|
6563
|
-
},
|
|
6564
|
-
handler: async (rawArgs, context) => {
|
|
6565
|
-
const args = asRecord(rawArgs);
|
|
6566
|
-
const uniqueCode = requireString(args, "uniqueCode");
|
|
6567
|
-
const instType = readString(args, "instType") ?? INST_TYPE_SWAP;
|
|
6568
|
-
const lastDays = readString(args, "lastDays") ?? LAST_DAYS_30;
|
|
6569
|
-
const [pnlRes, statsRes, preferenceRes] = await Promise.all([
|
|
6570
|
-
context.client.publicGet(
|
|
6571
|
-
`${BASE2}/public-pnl`,
|
|
6572
|
-
compactObject({ uniqueCode, instType, lastDays })
|
|
6573
|
-
),
|
|
6574
|
-
context.client.publicGet(
|
|
6575
|
-
`${BASE2}/public-stats`,
|
|
6576
|
-
compactObject({ uniqueCode, instType, lastDays })
|
|
6577
|
-
),
|
|
6578
|
-
context.client.publicGet(
|
|
6579
|
-
`${BASE2}/public-preference-currency`,
|
|
6580
|
-
compactObject({ uniqueCode, instType })
|
|
6581
|
-
)
|
|
6582
|
-
]);
|
|
6583
|
-
return {
|
|
6584
|
-
pnl: normalizeResponse(pnlRes).data,
|
|
6585
|
-
stats: normalizeResponse(statsRes).data,
|
|
6586
|
-
preference: normalizeResponse(preferenceRes).data
|
|
6587
|
-
};
|
|
6588
|
-
}
|
|
6589
|
-
},
|
|
6590
|
-
{
|
|
6591
|
-
name: "copytrading_get_my_details",
|
|
6592
|
-
module: "copytrading",
|
|
6593
|
-
description: "Query the lead traders I am currently copying (cumulative P&L per trader). Private. Rate limit: 5/2s.",
|
|
6594
|
-
isWrite: false,
|
|
6595
|
-
inputSchema: {
|
|
6596
|
-
type: "object",
|
|
6597
|
-
properties: {
|
|
6598
|
-
instType: { type: "string", enum: ["SWAP", "SPOT"], description: "Instrument type. Must match what was used when following: SPOT for spot copy trades (\u73B0\u8D27\u8DDF\u5355), SWAP for contract copy trades. Defaults to SWAP \u2014 always pass explicitly to query the correct list." }
|
|
6599
|
-
}
|
|
6600
|
-
},
|
|
6601
|
-
handler: async (rawArgs, context) => {
|
|
6602
|
-
const args = asRecord(rawArgs);
|
|
6603
|
-
const response = await context.client.privateGet(
|
|
6604
|
-
`${BASE2}/current-lead-traders`,
|
|
6605
|
-
compactObject({ instType: readString(args, "instType") ?? INST_TYPE_SWAP }),
|
|
6606
|
-
privateRateLimit("copytrading_get_my_details", 5)
|
|
6607
|
-
);
|
|
6608
|
-
return normalizeResponse(response);
|
|
6609
|
-
}
|
|
6610
|
-
},
|
|
6611
|
-
{
|
|
6612
|
-
name: "copytrading_set_copytrading",
|
|
6613
|
-
module: "copytrading",
|
|
6614
|
-
description: "Start copy trading a lead trader. copyMode: smart_copy (default), fixed_amount, ratio_copy. [CAUTION] Allocates real funds unless running in demo/simulated mode (x-simulated-trading). Private. Rate limit: 5/2s.",
|
|
6615
|
-
isWrite: true,
|
|
6616
|
-
inputSchema: {
|
|
6617
|
-
type: "object",
|
|
6618
|
-
properties: {
|
|
6619
|
-
uniqueCode: { type: "string", description: "Lead trader unique code (16 chars)" },
|
|
6620
|
-
instType: { type: "string", enum: ["SWAP", "SPOT"], description: "Instrument type. MUST be set explicitly: use SPOT for spot copy trading (\u73B0\u8D27\u8DDF\u5355), SWAP for perpetual/contract copy trading (\u5408\u7EA6\u8DDF\u5355). Defaults to SWAP if omitted \u2014 always pass this field to avoid silently creating the wrong type of copy trade." },
|
|
6621
|
-
copyMode: { type: "string", enum: ["smart_copy", "fixed_amount", "ratio_copy"], description: "Copy mode: smart_copy=smart copy, initialAmount+replicationRequired required (default); fixed_amount=fixed USDT per order, copyAmt required; ratio_copy=proportional copy, copyRatio required" },
|
|
6622
|
-
copyMgnMode: { type: "string", enum: ["cross", "isolated", "copy"], description: "Margin mode (non-smart_copy only): copy=follow trader (default), isolated, cross. For smart_copy: auto-set by instType (SWAP\u2192copy, SPOT\u2192isolated), user input ignored." },
|
|
6623
|
-
copyInstIdType: { type: "string", enum: ["copy", "custom"], description: "copy=follow trader's instruments (default); custom=user-defined (instId required)" },
|
|
6624
|
-
instId: { type: "string", description: "Comma-separated instrument IDs, required when copyInstIdType=custom" },
|
|
6625
|
-
copyTotalAmt: { type: "string", description: "Max total USDT to allocate for this trader. [REQUIRED when copyMode=fixed_amount or ratio_copy; auto-filled from initialAmount when copyMode=smart_copy]" },
|
|
6626
|
-
copyAmt: { type: "string", description: "Fixed USDT per order. [REQUIRED when copyMode=fixed_amount]" },
|
|
6627
|
-
copyRatio: { type: "string", description: "Copy ratio (e.g. 0.1 = 10%). [REQUIRED when copyMode=ratio_copy]" },
|
|
6628
|
-
initialAmount: { type: "string", description: "Initial investment amount in USDT. [REQUIRED when copyMode=smart_copy; automatically assigned to copyTotalAmt]" },
|
|
6629
|
-
replicationRequired: { type: "string", enum: ["0", "1"], description: "Whether to replicate existing positions: 0=no, 1=yes. Only applicable to smart_copy mode." },
|
|
6630
|
-
tpRatio: { type: "string", description: "Take-profit ratio per order, e.g. 0.1 = 10%" },
|
|
6631
|
-
slRatio: { type: "string", description: "Stop-loss ratio per order, e.g. 0.1 = 10%" },
|
|
6632
|
-
subPosCloseType: { type: "string", enum: ["copy_close", "market_close", "manual_close"], description: "How to close sub-positions when you stop copying: copy_close=follow trader (default), market_close=close all immediately, manual_close=keep open" },
|
|
6633
|
-
slTotalAmt: { type: "string", description: "Total stop-loss amount (USDT). Auto-stop when net loss reaches this amount" }
|
|
6634
|
-
},
|
|
6635
|
-
required: ["uniqueCode"]
|
|
6636
|
-
},
|
|
6637
|
-
handler: async (rawArgs, context) => {
|
|
6638
|
-
const args = asRecord(rawArgs);
|
|
6639
|
-
const copyMode = readString(args, "copyMode") ?? COPY_MODE_SMART;
|
|
6640
|
-
const instType = readString(args, "instType") ?? INST_TYPE_SWAP;
|
|
6641
|
-
const copyInstIdType = readString(args, "copyInstIdType") ?? COPY_INST_ID_TYPE_COPY;
|
|
6642
|
-
const smartMgnMode = instType === INST_TYPE_SPOT ? COPY_MGN_MODE_ISOLATED : COPY_MGN_MODE_COPY;
|
|
6643
|
-
const copyMgnMode = copyMode === COPY_MODE_SMART ? smartMgnMode : readString(args, "copyMgnMode") ?? COPY_MGN_MODE_COPY;
|
|
6644
|
-
const initialAmount = copyMode === COPY_MODE_SMART ? requireString(args, "initialAmount") : readString(args, "initialAmount");
|
|
6645
|
-
const replicationRequired = copyMode === COPY_MODE_SMART ? requireString(args, "replicationRequired") : void 0;
|
|
6646
|
-
const copyTotalAmt = copyMode === COPY_MODE_SMART ? initialAmount : requireString(args, "copyTotalAmt");
|
|
6647
|
-
const response = await context.client.privatePost(
|
|
6648
|
-
`${BASE2}/first-copy-settings`,
|
|
6649
|
-
compactObject({
|
|
6650
|
-
instType,
|
|
6651
|
-
uniqueCode: requireString(args, "uniqueCode"),
|
|
6652
|
-
copyMode,
|
|
6653
|
-
copyMgnMode,
|
|
6654
|
-
copyInstIdType,
|
|
6655
|
-
instId: copyInstIdType === COPY_INST_ID_TYPE_CUSTOM ? requireString(args, "instId") : readString(args, "instId"),
|
|
6656
|
-
copyTotalAmt,
|
|
6657
|
-
copyAmt: copyMode === COPY_MODE_FIXED ? requireString(args, "copyAmt") : readString(args, "copyAmt"),
|
|
6658
|
-
copyRatio: copyMode === COPY_MODE_RATIO ? requireString(args, "copyRatio") : readString(args, "copyRatio"),
|
|
6659
|
-
initialAmount: copyMode === COPY_MODE_SMART ? initialAmount : void 0,
|
|
6660
|
-
replicationRequired: copyMode === COPY_MODE_SMART ? replicationRequired : void 0,
|
|
6661
|
-
tpRatio: readString(args, "tpRatio"),
|
|
6662
|
-
slRatio: readString(args, "slRatio"),
|
|
6663
|
-
subPosCloseType: readString(args, "subPosCloseType") ?? SUB_POS_CLOSE_COPY,
|
|
6664
|
-
slTotalAmt: readString(args, "slTotalAmt"),
|
|
6665
|
-
tag: context.config.sourceTag
|
|
6666
|
-
}),
|
|
6667
|
-
privateRateLimit("copytrading_set_copytrading", 5)
|
|
6668
|
-
);
|
|
6669
|
-
return normalizeResponse(response);
|
|
6670
|
-
}
|
|
6671
|
-
},
|
|
6672
|
-
{
|
|
6673
|
-
name: "copytrading_stop_copy_trader",
|
|
6674
|
-
module: "copytrading",
|
|
6675
|
-
description: "Stop copy trading a lead trader. [CAUTION] Can close all positions (no effect in demo/simulated mode). Private. Rate limit: 5/2s.",
|
|
6676
|
-
isWrite: true,
|
|
6677
|
-
inputSchema: {
|
|
6678
|
-
type: "object",
|
|
6679
|
-
properties: {
|
|
6680
|
-
uniqueCode: { type: "string", description: "Lead trader unique code" },
|
|
6681
|
-
subPosCloseType: { type: "string", enum: ["copy_close", "market_close", "manual_close"], description: "How to handle positions when stopping: copy_close=follow trader (default), market_close=close all immediately, manual_close=keep open" },
|
|
6682
|
-
instType: { type: "string", enum: ["SWAP", "SPOT"], description: "Instrument type. Must match the type used when the copy trade was created: SPOT for spot copy trades, SWAP for contract copy trades. Defaults to SWAP \u2014 always pass explicitly." }
|
|
6683
|
-
},
|
|
6684
|
-
required: ["uniqueCode"]
|
|
6685
|
-
},
|
|
6686
|
-
handler: async (rawArgs, context) => {
|
|
6687
|
-
const args = asRecord(rawArgs);
|
|
6688
|
-
const response = await context.client.privatePost(
|
|
6689
|
-
`${BASE2}/stop-copy-trading`,
|
|
6690
|
-
compactObject({
|
|
6691
|
-
instType: readString(args, "instType") ?? INST_TYPE_SWAP,
|
|
6692
|
-
uniqueCode: requireString(args, "uniqueCode"),
|
|
6693
|
-
subPosCloseType: readString(args, "subPosCloseType") ?? SUB_POS_CLOSE_COPY
|
|
6694
|
-
}),
|
|
6695
|
-
privateRateLimit("copytrading_stop_copy_trader", 5)
|
|
6696
|
-
);
|
|
6697
|
-
return normalizeResponse(response);
|
|
6698
|
-
}
|
|
6699
|
-
}
|
|
6700
|
-
];
|
|
6701
|
-
}
|
|
6702
6485
|
function registerSwapTradeTools() {
|
|
6703
6486
|
const common = buildContractTradeTools({
|
|
6704
6487
|
prefix: "swap",
|
|
@@ -6823,9 +6606,7 @@ function allToolSpecs() {
|
|
|
6823
6606
|
...registerAccountTools(),
|
|
6824
6607
|
...registerBotTools(),
|
|
6825
6608
|
...registerAllEarnTools(),
|
|
6826
|
-
...registerAuditTools()
|
|
6827
|
-
// copytrading: included for CLI use only; not exposed via MCP (module removed from MODULES)
|
|
6828
|
-
...registerCopyTradeTools()
|
|
6609
|
+
...registerAuditTools()
|
|
6829
6610
|
];
|
|
6830
6611
|
}
|
|
6831
6612
|
function createToolRunner(client, config) {
|
|
@@ -7628,7 +7409,7 @@ async function cmdDiagnoseMcp(options = {}) {
|
|
|
7628
7409
|
|
|
7629
7410
|
// src/commands/diagnose.ts
|
|
7630
7411
|
var CLI_VERSION = readCliVersion();
|
|
7631
|
-
var GIT_HASH = true ? "
|
|
7412
|
+
var GIT_HASH = true ? "a8b36d0" : "dev";
|
|
7632
7413
|
function maskKey2(key) {
|
|
7633
7414
|
if (!key) return "(not set)";
|
|
7634
7415
|
if (key.length <= 8) return "****";
|
|
@@ -8580,31 +8361,6 @@ var HELP_TREE = {
|
|
|
8580
8361
|
}
|
|
8581
8362
|
}
|
|
8582
8363
|
},
|
|
8583
|
-
"copytrading": {
|
|
8584
|
-
description: "Copy trading \u2014 follow lead traders and manage copy positions",
|
|
8585
|
-
commands: {
|
|
8586
|
-
traders: {
|
|
8587
|
-
usage: "okx copytrading traders [--instType <SWAP|SPOT>] [--sortType <overview|pnl|aum|win_ratio|pnl_ratio|current_copy_trader_pnl>]\n [--state <0|1>] [--minLeadDays <1|2|3|4>]\n [--minAssets <n>] [--maxAssets <n>] [--minAum <n>] [--maxAum <n>]\n [--page <n>] [--dataVer <14-digit>] [--limit <n>]",
|
|
8588
|
-
description: "List top lead traders by ranking (default instType: SWAP, sortType: overview)"
|
|
8589
|
-
},
|
|
8590
|
-
status: {
|
|
8591
|
-
usage: "okx --profile <name> copytrading status [--instType <SWAP|SPOT>]",
|
|
8592
|
-
description: "Get your currently followed lead traders and their cumulative P&L (default instType: SWAP). Requires --profile."
|
|
8593
|
-
},
|
|
8594
|
-
follow: {
|
|
8595
|
-
usage: "okx --profile <name> copytrading follow --uniqueCode <code>\n [--instType <SWAP|SPOT>]\n [--copyMode <smart_copy|fixed_amount|ratio_copy>]\n smart_copy (default): --initialAmount <n> --replicationRequired <0|1>\n fixed_amount: --copyTotalAmt <n> --copyAmt <n>\n ratio_copy: --copyTotalAmt <n> --copyRatio <n>\n [--copyMgnMode <copy|isolated|cross>]\n [--copyInstIdType <copy|custom>] [--instId <id,...>] (instId required when copyInstIdType=custom)\n [--subPosCloseType <copy_close|market_close|manual_close>]\n [--tpRatio <ratio>] [--slRatio <ratio>] [--slTotalAmt <n>]",
|
|
8596
|
-
description: "Start following a lead trader (default instType: SWAP). Requires --profile."
|
|
8597
|
-
},
|
|
8598
|
-
unfollow: {
|
|
8599
|
-
usage: "okx --profile <name> copytrading unfollow --uniqueCode <code> [--instType <SWAP|SPOT>] [--subPosCloseType <copy_close|market_close|manual_close>]",
|
|
8600
|
-
description: "Stop following a lead trader (default instType: SWAP). Default subPosCloseType: copy_close. Requires --profile."
|
|
8601
|
-
},
|
|
8602
|
-
"trader-detail": {
|
|
8603
|
-
usage: "okx copytrading trader-detail --uniqueCode <code> [--instType <SWAP|SPOT>] [--lastDays <1|2|3|4>]",
|
|
8604
|
-
description: "Get stats, daily P&L, and currency preference of a lead trader (default instType: SWAP). lastDays: 1=7d, 2=30d (default), 3=90d, 4=365d"
|
|
8605
|
-
}
|
|
8606
|
-
}
|
|
8607
|
-
},
|
|
8608
8364
|
config: {
|
|
8609
8365
|
description: "Manage CLI configuration profiles",
|
|
8610
8366
|
commands: {
|
|
@@ -8932,29 +8688,8 @@ var CLI_OPTIONS = {
|
|
|
8932
8688
|
// diagnose --cli only: CLI/general checks (explicit alias for default)
|
|
8933
8689
|
all: { type: "boolean", default: false },
|
|
8934
8690
|
// diagnose --all: run both CLI and MCP checks
|
|
8935
|
-
output: { type: "string" }
|
|
8691
|
+
output: { type: "string" }
|
|
8936
8692
|
// diagnose --output only: save report to file
|
|
8937
|
-
// copytrading
|
|
8938
|
-
uniqueCode: { type: "string" },
|
|
8939
|
-
lastDays: { type: "string" },
|
|
8940
|
-
sortType: { type: "string" },
|
|
8941
|
-
minLeadDays: { type: "string" },
|
|
8942
|
-
minAssets: { type: "string" },
|
|
8943
|
-
maxAssets: { type: "string" },
|
|
8944
|
-
minAum: { type: "string" },
|
|
8945
|
-
maxAum: { type: "string" },
|
|
8946
|
-
page: { type: "string" },
|
|
8947
|
-
dataVer: { type: "string" },
|
|
8948
|
-
copyMode: { type: "string" },
|
|
8949
|
-
copyRatio: { type: "string" },
|
|
8950
|
-
copyTotalAmt: { type: "string" },
|
|
8951
|
-
copyAmt: { type: "string" },
|
|
8952
|
-
copyMgnMode: { type: "string" },
|
|
8953
|
-
copyInstIdType: { type: "string" },
|
|
8954
|
-
subPosCloseType: { type: "string" },
|
|
8955
|
-
initialAmount: { type: "string" },
|
|
8956
|
-
replicationRequired: { type: "string" },
|
|
8957
|
-
slTotalAmt: { type: "string" }
|
|
8958
8693
|
};
|
|
8959
8694
|
function parseCli(argv) {
|
|
8960
8695
|
const negated = /* @__PURE__ */ new Set();
|
|
@@ -11520,7 +11255,7 @@ async function cmdGridMaxQuantity(client, opts) {
|
|
|
11520
11255
|
}
|
|
11521
11256
|
|
|
11522
11257
|
// src/commands/bot-dca-ext.ts
|
|
11523
|
-
var
|
|
11258
|
+
var BASE2 = "/api/v5/tradingBot/dca";
|
|
11524
11259
|
function getDataArray2(result) {
|
|
11525
11260
|
return result.data ?? [];
|
|
11526
11261
|
}
|
|
@@ -11541,7 +11276,7 @@ function printWriteResult2(data, successMsg) {
|
|
|
11541
11276
|
}
|
|
11542
11277
|
async function cmdDcaMarginAdd(client, opts) {
|
|
11543
11278
|
const response = await client.privatePost(
|
|
11544
|
-
`${
|
|
11279
|
+
`${BASE2}/margin/add`,
|
|
11545
11280
|
{ algoId: opts.algoId, amt: opts.amt },
|
|
11546
11281
|
privateRateLimit("dca_margin_add", 20)
|
|
11547
11282
|
);
|
|
@@ -11551,7 +11286,7 @@ async function cmdDcaMarginAdd(client, opts) {
|
|
|
11551
11286
|
}
|
|
11552
11287
|
async function cmdDcaMarginReduce(client, opts) {
|
|
11553
11288
|
const response = await client.privatePost(
|
|
11554
|
-
`${
|
|
11289
|
+
`${BASE2}/margin/reduce`,
|
|
11555
11290
|
{ algoId: opts.algoId, amt: opts.amt },
|
|
11556
11291
|
privateRateLimit("dca_margin_reduce", 20)
|
|
11557
11292
|
);
|
|
@@ -11561,7 +11296,7 @@ async function cmdDcaMarginReduce(client, opts) {
|
|
|
11561
11296
|
}
|
|
11562
11297
|
async function cmdDcaSetTakeProfit(client, opts) {
|
|
11563
11298
|
const response = await client.privatePost(
|
|
11564
|
-
`${
|
|
11299
|
+
`${BASE2}/settings/take-profit`,
|
|
11565
11300
|
{ algoId: opts.algoId, algoOrdType: "contract_dca", tpPrice: opts.tpPrice },
|
|
11566
11301
|
privateRateLimit("dca_set_take_profit", 20)
|
|
11567
11302
|
);
|
|
@@ -11571,7 +11306,7 @@ async function cmdDcaSetTakeProfit(client, opts) {
|
|
|
11571
11306
|
}
|
|
11572
11307
|
async function cmdDcaSetReinvestment(client, opts) {
|
|
11573
11308
|
const response = await client.privatePost(
|
|
11574
|
-
`${
|
|
11309
|
+
`${BASE2}/settings/reinvestment`,
|
|
11575
11310
|
{ algoId: opts.algoId, algoOrdType: "contract_dca", allowReinvest: opts.allowReinvest },
|
|
11576
11311
|
privateRateLimit("dca_set_reinvestment", 20)
|
|
11577
11312
|
);
|
|
@@ -11582,7 +11317,7 @@ async function cmdDcaSetReinvestment(client, opts) {
|
|
|
11582
11317
|
}
|
|
11583
11318
|
async function cmdDcaManualBuy(client, opts) {
|
|
11584
11319
|
const response = await client.privatePost(
|
|
11585
|
-
`${
|
|
11320
|
+
`${BASE2}/orders/manual-buy`,
|
|
11586
11321
|
{
|
|
11587
11322
|
algoId: opts.algoId,
|
|
11588
11323
|
algoOrdType: "contract_dca",
|
|
@@ -11597,7 +11332,7 @@ async function cmdDcaManualBuy(client, opts) {
|
|
|
11597
11332
|
}
|
|
11598
11333
|
|
|
11599
11334
|
// src/commands/bot-recurring-ext.ts
|
|
11600
|
-
var
|
|
11335
|
+
var BASE3 = "/api/v5/tradingBot/recurring";
|
|
11601
11336
|
function getDataArray3(result) {
|
|
11602
11337
|
return result.data ?? [];
|
|
11603
11338
|
}
|
|
@@ -11630,7 +11365,7 @@ async function cmdRecurringCreate(client, opts) {
|
|
|
11630
11365
|
tag: DEFAULT_SOURCE_TAG
|
|
11631
11366
|
});
|
|
11632
11367
|
const response = await client.privatePost(
|
|
11633
|
-
`${
|
|
11368
|
+
`${BASE3}/order-algo`,
|
|
11634
11369
|
body,
|
|
11635
11370
|
privateRateLimit("recurring_create", 20)
|
|
11636
11371
|
);
|
|
@@ -11644,7 +11379,7 @@ async function cmdRecurringCreate(client, opts) {
|
|
|
11644
11379
|
}
|
|
11645
11380
|
async function cmdRecurringAmend(client, opts) {
|
|
11646
11381
|
const response = await client.privatePost(
|
|
11647
|
-
`${
|
|
11382
|
+
`${BASE3}/amend-order-algo`,
|
|
11648
11383
|
{ algoId: opts.algoId, stgyName: opts.stgyName },
|
|
11649
11384
|
privateRateLimit("recurring_amend", 20)
|
|
11650
11385
|
);
|
|
@@ -11658,7 +11393,7 @@ async function cmdRecurringAmend(client, opts) {
|
|
|
11658
11393
|
}
|
|
11659
11394
|
async function cmdRecurringStop(client, opts) {
|
|
11660
11395
|
const response = await client.privatePost(
|
|
11661
|
-
`${
|
|
11396
|
+
`${BASE3}/stop-order-algo`,
|
|
11662
11397
|
[{ algoId: opts.algoId }],
|
|
11663
11398
|
privateRateLimit("recurring_stop", 20)
|
|
11664
11399
|
);
|
|
@@ -11671,7 +11406,7 @@ async function cmdRecurringStop(client, opts) {
|
|
|
11671
11406
|
);
|
|
11672
11407
|
}
|
|
11673
11408
|
async function cmdRecurringOrders(client, opts) {
|
|
11674
|
-
const endpoint = opts.history ? `${
|
|
11409
|
+
const endpoint = opts.history ? `${BASE3}/orders-algo-history` : `${BASE3}/orders-algo-pending`;
|
|
11675
11410
|
const params = compactObject({ algoId: opts.algoId });
|
|
11676
11411
|
const response = await client.privateGet(
|
|
11677
11412
|
endpoint,
|
|
@@ -11698,7 +11433,7 @@ async function cmdRecurringOrders(client, opts) {
|
|
|
11698
11433
|
}
|
|
11699
11434
|
async function cmdRecurringDetails(client, opts) {
|
|
11700
11435
|
const response = await client.privateGet(
|
|
11701
|
-
`${
|
|
11436
|
+
`${BASE3}/orders-algo-details`,
|
|
11702
11437
|
{ algoId: opts.algoId },
|
|
11703
11438
|
privateRateLimit("recurring_details", 20)
|
|
11704
11439
|
);
|
|
@@ -11725,7 +11460,7 @@ async function cmdRecurringDetails(client, opts) {
|
|
|
11725
11460
|
}
|
|
11726
11461
|
async function cmdRecurringSubOrders(client, opts) {
|
|
11727
11462
|
const response = await client.privateGet(
|
|
11728
|
-
`${
|
|
11463
|
+
`${BASE3}/sub-orders`,
|
|
11729
11464
|
{ algoId: opts.algoId },
|
|
11730
11465
|
privateRateLimit("recurring_sub_orders", 20)
|
|
11731
11466
|
);
|
|
@@ -12172,135 +11907,10 @@ async function cmdDcdQuoteAndBuy(run, opts) {
|
|
|
12172
11907
|
}
|
|
12173
11908
|
}
|
|
12174
11909
|
|
|
12175
|
-
// src/commands/copytrading.ts
|
|
12176
|
-
function asRaw(result) {
|
|
12177
|
-
return result;
|
|
12178
|
-
}
|
|
12179
|
-
async function cmdCopyTradeTraders(run, opts) {
|
|
12180
|
-
const result = await run("copytrading_get_lead_traders", {
|
|
12181
|
-
instType: opts.instType,
|
|
12182
|
-
sortType: opts.sortType,
|
|
12183
|
-
state: opts.state,
|
|
12184
|
-
minLeadDays: opts.minLeadDays,
|
|
12185
|
-
minAssets: opts.minAssets,
|
|
12186
|
-
maxAssets: opts.maxAssets,
|
|
12187
|
-
minAum: opts.minAum,
|
|
12188
|
-
maxAum: opts.maxAum,
|
|
12189
|
-
page: opts.page,
|
|
12190
|
-
dataVer: opts.dataVer,
|
|
12191
|
-
limit: opts.limit
|
|
12192
|
-
});
|
|
12193
|
-
const raw = asRaw(result);
|
|
12194
|
-
const data = raw["data"] ?? [];
|
|
12195
|
-
if (opts.json) return printJson(data);
|
|
12196
|
-
printTable(
|
|
12197
|
-
(data ?? []).map((t) => ({
|
|
12198
|
-
uniqueCode: t["uniqueCode"],
|
|
12199
|
-
nickName: t["nickName"],
|
|
12200
|
-
pnl: t["pnl"],
|
|
12201
|
-
winRatio: t["winRatio"],
|
|
12202
|
-
copyTraderNum: t["copyTraderNum"],
|
|
12203
|
-
leadDays: t["leadDays"]
|
|
12204
|
-
}))
|
|
12205
|
-
);
|
|
12206
|
-
}
|
|
12207
|
-
async function cmdCopyTradeMyStatus(run, opts) {
|
|
12208
|
-
const result = await run("copytrading_get_my_details", { instType: opts.instType });
|
|
12209
|
-
const raw = result;
|
|
12210
|
-
const traders = raw.data ?? [];
|
|
12211
|
-
if (opts.json) return printJson(raw);
|
|
12212
|
-
if (!traders.length) {
|
|
12213
|
-
process.stdout.write("No active copy traders\n");
|
|
12214
|
-
return;
|
|
12215
|
-
}
|
|
12216
|
-
printTable(
|
|
12217
|
-
traders.map((t) => ({
|
|
12218
|
-
uniqueCode: t["uniqueCode"],
|
|
12219
|
-
nickName: t["nickName"],
|
|
12220
|
-
copyTotalPnl: t["copyTotalPnl"],
|
|
12221
|
-
todayPnl: t["todayPnl"],
|
|
12222
|
-
upl: t["upl"],
|
|
12223
|
-
margin: t["margin"]
|
|
12224
|
-
}))
|
|
12225
|
-
);
|
|
12226
|
-
}
|
|
12227
|
-
async function cmdCopyTradeFollow(run, opts) {
|
|
12228
|
-
const result = await run("copytrading_set_copytrading", {
|
|
12229
|
-
uniqueCode: opts.uniqueCode,
|
|
12230
|
-
copyTotalAmt: opts.copyTotalAmt,
|
|
12231
|
-
copyMgnMode: opts.copyMgnMode,
|
|
12232
|
-
copyInstIdType: opts.copyInstIdType,
|
|
12233
|
-
instId: opts.instId,
|
|
12234
|
-
copyMode: opts.copyMode,
|
|
12235
|
-
copyAmt: opts.copyAmt,
|
|
12236
|
-
copyRatio: opts.copyRatio,
|
|
12237
|
-
initialAmount: opts.initialAmount,
|
|
12238
|
-
replicationRequired: opts.replicationRequired,
|
|
12239
|
-
subPosCloseType: opts.subPosCloseType,
|
|
12240
|
-
instType: opts.instType,
|
|
12241
|
-
tpRatio: opts.tpRatio,
|
|
12242
|
-
slRatio: opts.slRatio,
|
|
12243
|
-
slTotalAmt: opts.slTotalAmt
|
|
12244
|
-
});
|
|
12245
|
-
const data = asRaw(result)["data"];
|
|
12246
|
-
if (opts.json) return printJson(data);
|
|
12247
|
-
process.stdout.write(`Following trader: ${opts.uniqueCode}
|
|
12248
|
-
`);
|
|
12249
|
-
}
|
|
12250
|
-
async function cmdCopyTradeUnfollow(run, opts) {
|
|
12251
|
-
const result = await run("copytrading_stop_copy_trader", {
|
|
12252
|
-
uniqueCode: opts.uniqueCode,
|
|
12253
|
-
subPosCloseType: opts.subPosCloseType,
|
|
12254
|
-
instType: opts.instType
|
|
12255
|
-
});
|
|
12256
|
-
const data = asRaw(result)["data"];
|
|
12257
|
-
if (opts.json) return printJson(data);
|
|
12258
|
-
process.stdout.write(`Stopped copying: ${opts.uniqueCode}
|
|
12259
|
-
`);
|
|
12260
|
-
}
|
|
12261
|
-
async function cmdCopyTradeTraderDetail(run, opts) {
|
|
12262
|
-
const result = await run("copytrading_get_trader_details", {
|
|
12263
|
-
uniqueCode: opts.uniqueCode,
|
|
12264
|
-
lastDays: opts.lastDays,
|
|
12265
|
-
instType: opts.instType
|
|
12266
|
-
});
|
|
12267
|
-
const raw = result;
|
|
12268
|
-
if (opts.json) return printJson(raw);
|
|
12269
|
-
const stats = (raw.stats ?? [])[0];
|
|
12270
|
-
if (stats) {
|
|
12271
|
-
process.stdout.write([
|
|
12272
|
-
`Win Rate: ${stats["winRatio"]}`,
|
|
12273
|
-
`Profit Days: ${stats["profitDays"]}`,
|
|
12274
|
-
`Loss Days: ${stats["lossDays"]}`,
|
|
12275
|
-
`Follower PnL: ${stats["curCopyTraderPnl"]} USDT`,
|
|
12276
|
-
`Avg Position: ${stats["avgSubPosNotional"]} USDT`,
|
|
12277
|
-
`Invested: ${stats["investAmt"]} USDT`
|
|
12278
|
-
].join("\n") + "\n\n");
|
|
12279
|
-
}
|
|
12280
|
-
const pnl = raw.pnl ?? [];
|
|
12281
|
-
if (pnl.length) {
|
|
12282
|
-
process.stdout.write("Daily P&L:\n");
|
|
12283
|
-
printTable(pnl.map((d) => ({
|
|
12284
|
-
date: new Date(Number(d["beginTs"])).toLocaleDateString(),
|
|
12285
|
-
pnl: d["pnl"],
|
|
12286
|
-
pnlRatio: d["pnlRatio"]
|
|
12287
|
-
})));
|
|
12288
|
-
process.stdout.write("\n");
|
|
12289
|
-
}
|
|
12290
|
-
const preference = raw.preference ?? [];
|
|
12291
|
-
if (preference.length) {
|
|
12292
|
-
process.stdout.write("Currency Preference:\n");
|
|
12293
|
-
printTable(preference.map((d) => ({
|
|
12294
|
-
currency: d["ccy"],
|
|
12295
|
-
ratio: `${(Number(d["ratio"]) * 100).toFixed(1)}%`
|
|
12296
|
-
})));
|
|
12297
|
-
}
|
|
12298
|
-
}
|
|
12299
|
-
|
|
12300
11910
|
// src/index.ts
|
|
12301
11911
|
var _require3 = createRequire3(import.meta.url);
|
|
12302
11912
|
var CLI_VERSION2 = _require3("../package.json").version;
|
|
12303
|
-
var GIT_HASH2 = true ? "
|
|
11913
|
+
var GIT_HASH2 = true ? "a8b36d0" : "dev";
|
|
12304
11914
|
function handleConfigCommand(action, rest, json, lang, force) {
|
|
12305
11915
|
if (action === "init") return cmdConfigInit(lang === "zh" ? "zh" : "en");
|
|
12306
11916
|
if (action === "show") return cmdConfigShow(json);
|
|
@@ -13103,53 +12713,6 @@ function handleBotRecurringCommand(client, subAction, v, json) {
|
|
|
13103
12713
|
if (subAction === "stop")
|
|
13104
12714
|
return cmdRecurringStop(client, { algoId: v.algoId, json });
|
|
13105
12715
|
}
|
|
13106
|
-
function handleCopyTradeCommand(run, action, _rest, v, json) {
|
|
13107
|
-
const limit = v.limit !== void 0 ? Number(v.limit) : void 0;
|
|
13108
|
-
if (action === "traders")
|
|
13109
|
-
return cmdCopyTradeTraders(run, {
|
|
13110
|
-
instType: v.instType,
|
|
13111
|
-
sortType: v.sortType,
|
|
13112
|
-
state: v.state,
|
|
13113
|
-
minLeadDays: v.minLeadDays,
|
|
13114
|
-
minAssets: v.minAssets,
|
|
13115
|
-
maxAssets: v.maxAssets,
|
|
13116
|
-
minAum: v.minAum,
|
|
13117
|
-
maxAum: v.maxAum,
|
|
13118
|
-
page: v.page,
|
|
13119
|
-
dataVer: v.dataVer,
|
|
13120
|
-
limit,
|
|
13121
|
-
json
|
|
13122
|
-
});
|
|
13123
|
-
if (action === "status")
|
|
13124
|
-
return cmdCopyTradeMyStatus(run, { instType: v.instType, json });
|
|
13125
|
-
if (action === "follow")
|
|
13126
|
-
return cmdCopyTradeFollow(run, {
|
|
13127
|
-
uniqueCode: v.uniqueCode,
|
|
13128
|
-
copyTotalAmt: v.copyTotalAmt,
|
|
13129
|
-
copyMgnMode: v.copyMgnMode,
|
|
13130
|
-
copyInstIdType: v.copyInstIdType,
|
|
13131
|
-
instId: v.instId,
|
|
13132
|
-
copyMode: v.copyMode,
|
|
13133
|
-
copyAmt: v.copyAmt,
|
|
13134
|
-
copyRatio: v.copyRatio,
|
|
13135
|
-
initialAmount: v.initialAmount,
|
|
13136
|
-
replicationRequired: v.replicationRequired,
|
|
13137
|
-
subPosCloseType: v.subPosCloseType,
|
|
13138
|
-
instType: v.instType,
|
|
13139
|
-
tpRatio: v.tpRatio,
|
|
13140
|
-
slRatio: v.slRatio,
|
|
13141
|
-
slTotalAmt: v.slTotalAmt,
|
|
13142
|
-
json
|
|
13143
|
-
});
|
|
13144
|
-
if (action === "unfollow")
|
|
13145
|
-
return cmdCopyTradeUnfollow(run, { uniqueCode: v.uniqueCode, subPosCloseType: v.subPosCloseType, instType: v.instType, json });
|
|
13146
|
-
if (action === "trader-detail")
|
|
13147
|
-
return cmdCopyTradeTraderDetail(run, { uniqueCode: v.uniqueCode, lastDays: v.lastDays, instType: v.instType, json });
|
|
13148
|
-
process.stderr.write(`Unknown copytrading command: ${action}
|
|
13149
|
-
Valid: traders, status, follow, unfollow, trader-detail
|
|
13150
|
-
`);
|
|
13151
|
-
process.exitCode = 1;
|
|
13152
|
-
}
|
|
13153
12716
|
function handleBotCommand(run, client, action, rest, v, json) {
|
|
13154
12717
|
if (action === "grid") return handleBotGridCommand(run, client, v, rest, json);
|
|
13155
12718
|
if (action === "dca") return handleBotDcaCommand(run, client, rest[0], v, json);
|
|
@@ -13303,8 +12866,7 @@ async function main() {
|
|
|
13303
12866
|
futures: () => handleFuturesCommand(run, action, rest, v, json),
|
|
13304
12867
|
option: () => handleOptionCommand(run, action, rest, v, json),
|
|
13305
12868
|
bot: () => handleBotCommand(run, client, action, rest, v, json),
|
|
13306
|
-
earn: () => handleEarnCommand(run, action, rest, v, json)
|
|
13307
|
-
copytrading: () => handleCopyTradeCommand(run, action, rest, v, json)
|
|
12869
|
+
earn: () => handleEarnCommand(run, action, rest, v, json)
|
|
13308
12870
|
};
|
|
13309
12871
|
const handler = moduleHandlers[module];
|
|
13310
12872
|
if (handler) return handler();
|
|
@@ -13315,8 +12877,6 @@ async function main() {
|
|
|
13315
12877
|
main().catch((error) => {
|
|
13316
12878
|
const payload = toToolErrorPayload(error);
|
|
13317
12879
|
process.stderr.write(`Error: ${payload.message}
|
|
13318
|
-
`);
|
|
13319
|
-
if (payload.code) process.stderr.write(`Code: ${payload.code}
|
|
13320
12880
|
`);
|
|
13321
12881
|
if (payload.traceId) process.stderr.write(`TraceId: ${payload.traceId}
|
|
13322
12882
|
`);
|
|
@@ -13334,7 +12894,6 @@ export {
|
|
|
13334
12894
|
handleBotRecurringCommand,
|
|
13335
12895
|
handleBotTwapCommand,
|
|
13336
12896
|
handleConfigCommand,
|
|
13337
|
-
handleCopyTradeCommand,
|
|
13338
12897
|
handleEarnCommand,
|
|
13339
12898
|
handleFuturesAlgoCommand,
|
|
13340
12899
|
handleFuturesCommand,
|