Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/binance-orderbook-trade-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Every Binance UI automation change must report the evidence used: live DOM or st

Do not auto-confirm destructive Binance dialogs. The script may open Binance's native cancel confirmation, but final confirmation remains manual.

USDT account rebalancing is a manual action, not an automatic post-close side effect. The inline `再平衡` action becomes available only after the account-order widget has continuously reported zero positions and zero open orders for three seconds, and a fresh all-symbol futures-position response also confirms that every position is flat. Starting any script trade or cancel task invalidates that eligibility immediately.
USDT account rebalancing is a manual action, not an automatic post-close side effect. The inline `账户再平衡` action becomes available only after the account-order widget has continuously reported zero positions and zero open orders for three seconds, and a fresh all-symbol futures-position response also confirms that every position is flat. Starting any script trade or cancel task invalidates that eligibility immediately.

The rebalance path is pinned to the current Binance page bundle contract instead of automating the native transfer dialog. It reads Spot and Funding available USDT from `/bapi/asset/v2/private/asset-service/wallet/balance`, reads the U-M Futures transferable amount from `/bapi/futures/v1/private/future/user-data/getMaxWithdrawAmount`, and submits at most two sequential transfers through `/bapi/asset/v1/private/asset-service/wallet/transfer` with `{ asset, amount, kindType }`. Wallet rows are identified by the stable `accountType` values `MAIN`, `CARD`, and `FUTURE`; `walletName` is localized and must not be used as an identifier. The private transfer BAPI uses those same account codes; do not substitute the public SAPI names `FUNDING` or `UMFUTURE`. It does not save an API key and does not fall back to DOM clicking if this private BAPI contract changes.

Expand Down
16 changes: 8 additions & 8 deletions scripts/binance-orderbook-trade.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @namespace binance.orderbook.trade
// @icon data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2064%2064%22%3E%3Crect%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%2214%22%20fill%3D%22%23f0b90b%22%2F%3E%3Ctext%20x%3D%2232%22%20y%3D%2249%22%20text-anchor%3D%22middle%22%20font-family%3D%22Arial%2C%20sans-serif%22%20font-size%3D%2242%22%20font-weight%3D%22800%22%20fill%3D%22%23111827%22%3EJ%3C%2Ftext%3E%3C%2Fsvg%3E
// @icon64 data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2064%2064%22%3E%3Crect%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%2214%22%20fill%3D%22%23f0b90b%22%2F%3E%3Ctext%20x%3D%2232%22%20y%3D%2249%22%20text-anchor%3D%22middle%22%20font-family%3D%22Arial%2C%20sans-serif%22%20font-size%3D%2242%22%20font-weight%3D%22800%22%20fill%3D%22%23111827%22%3EJ%3C%2Ftext%3E%3C%2Fsvg%3E
// @version 2.7.166
// @version 2.7.167
// @author jackhai9
// @description 单击订单簿价格,按当前开仓/平仓 tab 自动填数量并执行下单,内置数量倍率面板
// @match https://www.binance.com/*/futures/*
Expand Down Expand Up @@ -7406,7 +7406,7 @@
async function runUsdtRebalance() {
let plan = null;
let completed = 0;
setLadderStatus("正在读取再平衡计划");
setLadderStatus("正在读取账户再平衡计划");
try {
await assertUsdtRebalanceTradingState();
const initialBalances = await readCurrentUsdtRebalanceBalances();
Expand All @@ -7417,28 +7417,28 @@
return { status: "already_balanced", plan };
}
if (!window.confirm(formatUsdtRebalanceConfirmation(plan))) {
setLadderStatus("再平衡已取消");
setLadderStatus("账户再平衡已取消");
return { status: "cancelled", plan };
}
let expectedBalances = initialBalances;
for (const transfer of plan.transfers) {
await assertUsdtRebalanceTradingState();
const currentBalances = await readCurrentUsdtRebalanceBalances();
if (!areUsdtBalancesEqual(currentBalances, expectedBalances)) {
throw new Error("账户余额已变化,已停止再平衡");
throw new Error("账户余额已变化,已停止账户再平衡");
}
setLadderStatus(`再平衡中 · ${completed + 1}/${plan.transfers.length} 笔`);
setLadderStatus(`账户再平衡中 · ${completed + 1}/${plan.transfers.length} 笔`);
await submitUsdtRebalanceTransfer(transfer);
completed += 1;
expectedBalances = applyUsdtTransferToBalances(expectedBalances, transfer);
await waitForUsdtRebalanceBalances(expectedBalances);
}
usdtRebalanceEligible = false;
setLadderStatus(`再平衡已完成 · ${completed}/${plan.transfers.length} 笔`);
setLadderStatus(`账户再平衡已完成 · ${completed}/${plan.transfers.length} 笔`);
return { status: "completed", plan, completed };
} catch (error) {
const message = error?.name === "AbortError" ? "Binance 请求超时" : error?.message || String(error);
const prefix = completed > 0 && plan ? `再平衡部分完成 · ${completed}/${plan.transfers.length} 笔` : "再平衡失败";
const prefix = completed > 0 && plan ? `账户再平衡部分完成 · ${completed}/${plan.transfers.length} 笔` : "账户再平衡失败";
setLadderStatus(`${prefix} · ${message}`, message);
throw error;
}
Expand Down Expand Up @@ -8385,7 +8385,7 @@
"</div>",
`<div id="${LADDER_STATUS_ROW_ID}" style="display:flex;align-items:center;height:18px;margin-top:6px;visibility:visible;color:${MUTED_TEXT_COLOR};font-size:13px;line-height:18px;white-space:nowrap;overflow:hidden;">`,
`<span id="${LADDER_STATUS_ID}" title="空闲" style="flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;">空闲</span>`,
`<button id="${USDT_REBALANCE_ACTION_ID}" type="button" data-usdt-rebalance="true" hidden style="flex:0 0 auto;height:18px;margin-left:8px;padding:0;border:0;background:transparent;color:var(--color-PrimaryYellow);font-size:13px;font-weight:500;line-height:18px;cursor:pointer;">再平衡</button>`,
`<button id="${USDT_REBALANCE_ACTION_ID}" type="button" data-usdt-rebalance="true" hidden title="将资金、现货和 U 本位账户的 USDT 按 5:4:1 分配" style="flex:0 0 auto;height:18px;margin-left:8px;padding:0;border:0;background:transparent;color:var(--color-PrimaryYellow);font-size:13px;font-weight:500;line-height:18px;cursor:pointer;">账户再平衡</button>`,
"</div>"
].join("");
panelPositionInvalidated = true;
Expand Down
18 changes: 9 additions & 9 deletions src/binance-orderbook-trade/index.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @namespace binance.orderbook.trade
// @icon data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2064%2064%22%3E%3Crect%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%2214%22%20fill%3D%22%23f0b90b%22%2F%3E%3Ctext%20x%3D%2232%22%20y%3D%2249%22%20text-anchor%3D%22middle%22%20font-family%3D%22Arial%2C%20sans-serif%22%20font-size%3D%2242%22%20font-weight%3D%22800%22%20fill%3D%22%23111827%22%3EJ%3C%2Ftext%3E%3C%2Fsvg%3E
// @icon64 data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2064%2064%22%3E%3Crect%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%2214%22%20fill%3D%22%23f0b90b%22%2F%3E%3Ctext%20x%3D%2232%22%20y%3D%2249%22%20text-anchor%3D%22middle%22%20font-family%3D%22Arial%2C%20sans-serif%22%20font-size%3D%2242%22%20font-weight%3D%22800%22%20fill%3D%22%23111827%22%3EJ%3C%2Ftext%3E%3C%2Fsvg%3E
// @version 2.7.166
// @version 2.7.167
// @author jackhai9
// @description 单击订单簿价格,按当前开仓/平仓 tab 自动填数量并执行下单,内置数量倍率面板
// @match https://www.binance.com/*/futures/*
Expand Down Expand Up @@ -5574,7 +5574,7 @@ import {
async function runUsdtRebalance() {
let plan = null;
let completed = 0;
setLadderStatus('正在读取再平衡计划');
setLadderStatus('正在读取账户再平衡计划');
try {
await assertUsdtRebalanceTradingState();
const initialBalances = await readCurrentUsdtRebalanceBalances();
Expand All @@ -5585,7 +5585,7 @@ import {
return { status: 'already_balanced', plan };
}
if (!window.confirm(formatUsdtRebalanceConfirmation(plan))) {
setLadderStatus('再平衡已取消');
setLadderStatus('账户再平衡已取消');
return { status: 'cancelled', plan };
}

Expand All @@ -5594,24 +5594,24 @@ import {
await assertUsdtRebalanceTradingState();
const currentBalances = await readCurrentUsdtRebalanceBalances();
if (!areUsdtBalancesEqual(currentBalances, expectedBalances)) {
throw new Error('账户余额已变化,已停止再平衡');
throw new Error('账户余额已变化,已停止账户再平衡');
}
setLadderStatus(`再平衡中 · ${completed + 1}/${plan.transfers.length} 笔`);
setLadderStatus(`账户再平衡中 · ${completed + 1}/${plan.transfers.length} 笔`);
await submitUsdtRebalanceTransfer(transfer);
completed += 1;
expectedBalances = applyUsdtTransferToBalances(expectedBalances, transfer);
await waitForUsdtRebalanceBalances(expectedBalances);
}
usdtRebalanceEligible = false;
setLadderStatus(`再平衡已完成 · ${completed}/${plan.transfers.length} 笔`);
setLadderStatus(`账户再平衡已完成 · ${completed}/${plan.transfers.length} 笔`);
return { status: 'completed', plan, completed };
} catch (error) {
const message = error?.name === 'AbortError'
? 'Binance 请求超时'
: (error?.message || String(error));
const prefix = completed > 0 && plan
? `再平衡部分完成 · ${completed}/${plan.transfers.length} 笔`
: '再平衡失败';
? `账户再平衡部分完成 · ${completed}/${plan.transfers.length} 笔`
: '账户再平衡失败';
setLadderStatus(`${prefix} · ${message}`, message);
throw error;
}
Expand Down Expand Up @@ -6710,7 +6710,7 @@ import {
'</div>',
`<div id="${LADDER_STATUS_ROW_ID}" style="display:flex;align-items:center;height:18px;margin-top:6px;visibility:visible;color:${MUTED_TEXT_COLOR};font-size:13px;line-height:18px;white-space:nowrap;overflow:hidden;">`,
`<span id="${LADDER_STATUS_ID}" title="空闲" style="flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;">空闲</span>`,
`<button id="${USDT_REBALANCE_ACTION_ID}" type="button" data-usdt-rebalance="true" hidden style="flex:0 0 auto;height:18px;margin-left:8px;padding:0;border:0;background:transparent;color:var(--color-PrimaryYellow);font-size:13px;font-weight:500;line-height:18px;cursor:pointer;">再平衡</button>`,
`<button id="${USDT_REBALANCE_ACTION_ID}" type="button" data-usdt-rebalance="true" hidden title="将资金、现货和 U 本位账户的 USDT 按 5:4:1 分配" style="flex:0 0 auto;height:18px;margin-left:8px;padding:0;border:0;background:transparent;color:var(--color-PrimaryYellow);font-size:13px;font-weight:500;line-height:18px;cursor:pointer;">账户再平衡</button>`,
'</div>',
].join('');
panelPositionInvalidated = true;
Expand Down
Loading