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
15 changes: 9 additions & 6 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.153
// @version 2.7.154
// @author jackhai9
// @description 单击订单簿价格,按当前开仓/平仓 tab 自动填数量并执行下单,内置数量倍率面板
// @match https://www.binance.com/*/futures/*
Expand Down Expand Up @@ -906,7 +906,9 @@
function formatFailedLadderProgress(label, message, progress) {
assertLadderLabel(label);
assertLadderMessage(message);
return appendLadderProgressCounts(`${label}失败:${message}`, progress);
const counts = formatLadderProgressCounts(progress);
const details = counts.length > 0 ? `${counts.join(" · ")} · ${message}` : message;
return `${label}失败:${details}`;
}
function formatCompletedLadderProgress(label, completedOrders, totalOrders, progress) {
assertLadderLabel(label);
Expand Down Expand Up @@ -2504,7 +2506,8 @@
const LADDER_CONTROL_BUTTON_FONT_SIZE = 14;
const PANEL_BOTTOM_TOOLTIP_GAP = 12;
const TRADE_UI_STATE_TIMEOUT_MS = 1e3;
const TRADE_ACTION_BUTTON_READY_TIMEOUT_MS = 2e3;
const TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS = 3;
const TRADE_ACTION_BUTTON_READY_TIMEOUT_MS = TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS * 1e3;
const ROUTE_WATCHDOG_MS = 5e3;
let lastTs = 0;
let isEditingMultiplier = false;
Expand Down Expand Up @@ -4177,12 +4180,12 @@
if (button) return button;
const currentButton = plan.spec.buttonGetter();
if (!currentButton || !currentButton.isConnected || !isVisibleElement(currentButton)) {
throw new Error(`${plan.spec.label}按钮尚未渲染完成,已停止`);
throw new Error(`下单按钮 ${TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS} 秒内未渲染完成`);
}
if (isSubmitButtonBusy(currentButton)) {
throw new Error(`${plan.spec.label}按钮持续处理中,已停止`);
throw new Error(`下单按钮 ${TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS} 秒内未恢复可点击`);
}
throw new Error(`${plan.spec.label}按钮当前不可点击,已停止`);
throw new Error(`下单按钮 ${TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS} 秒内未达到可点击状态`);
}
function readVisibleOrderFeedbackEntries() {
const selectors = [
Expand Down
4 changes: 3 additions & 1 deletion src/binance-orderbook-trade/core/ladder-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export function formatInterruptedLadderProgress(label, reason, progress) {
export function formatFailedLadderProgress(label, message, progress) {
assertLadderLabel(label);
assertLadderMessage(message);
return appendLadderProgressCounts(`${label}失败:${message}`, progress);
const counts = formatLadderProgressCounts(progress);
const details = counts.length > 0 ? `${counts.join(' · ')} · ${message}` : message;
return `${label}失败:${details}`;
}

export function formatCompletedLadderProgress(label, completedOrders, totalOrders, progress) {
Expand Down
11 changes: 6 additions & 5 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.153
// @version 2.7.154
// @author jackhai9
// @description 单击订单簿价格,按当前开仓/平仓 tab 自动填数量并执行下单,内置数量倍率面板
// @match https://www.binance.com/*/futures/*
Expand Down Expand Up @@ -339,7 +339,8 @@ import {
const LADDER_CONTROL_BUTTON_FONT_SIZE = 14;
const PANEL_BOTTOM_TOOLTIP_GAP = 12;
const TRADE_UI_STATE_TIMEOUT_MS = 1000;
const TRADE_ACTION_BUTTON_READY_TIMEOUT_MS = 2000;
const TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS = 3;
const TRADE_ACTION_BUTTON_READY_TIMEOUT_MS = TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS * 1000;
const ROUTE_WATCHDOG_MS = 5000;

let lastTs = 0;
Expand Down Expand Up @@ -2416,12 +2417,12 @@ import {

const currentButton = plan.spec.buttonGetter();
if (!currentButton || !currentButton.isConnected || !isVisibleElement(currentButton)) {
throw new Error(`${plan.spec.label}按钮尚未渲染完成,已停止`);
throw new Error(`下单按钮 ${TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS} 秒内未渲染完成`);
}
if (isSubmitButtonBusy(currentButton)) {
throw new Error(`${plan.spec.label}按钮持续处理中,已停止`);
throw new Error(`下单按钮 ${TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS} 秒内未恢复可点击`);
}
throw new Error(`${plan.spec.label}按钮当前不可点击,已停止`);
throw new Error(`下单按钮 ${TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS} 秒内未达到可点击状态`);
}

function readVisibleOrderFeedbackEntries() {
Expand Down
14 changes: 13 additions & 1 deletion test/unit/binance-orderbook-trade/ladder-progress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('failed and interrupted ladder statuses retain confirmed progress', () => {

assert.equal(
formatFailedLadderProgress('阶梯开多', '数量框状态未稳定', progress),
'阶梯开多失败:数量框状态未稳定 · 已挂 1/5 笔 · 已撤 1 笔',
'阶梯开多失败:已挂 1/5 笔 · 已撤 1 笔 · 数量框状态未稳定',
);
assert.equal(
formatInterruptedLadderProgress('阶梯开多', '交易对已切换', progress),
Expand All @@ -104,6 +104,18 @@ test('failed and interrupted ladder statuses retain confirmed progress', () => {
formatInterruptedLadderProgress('阶梯平多', '交易对已切换', createLadderProgress()),
'阶梯平多已中止:交易对已切换',
);

const buttonNotReady = createLadderProgress();
setLadderPlannedOrders(buttonNotReady, 2);
recordLadderSubmittedOrder(buttonNotReady);
assert.equal(
formatFailedLadderProgress(
'阶梯开空',
'下单按钮 3 秒内未恢复可点击',
buttonNotReady,
),
'阶梯开空失败:已挂 1/2 笔 · 下单按钮 3 秒内未恢复可点击',
);
});

test('ladder progress rejects invalid counters instead of masking them', () => {
Expand Down
4 changes: 4 additions & 0 deletions test/unit/binance-orderbook-trade/source-regressions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ test('ladder execution waits for the current semantic action button before every

assert.match(readyButtonBody, /await waitForTradeActionButtonFrameState/);
assert.match(readyButtonBody, /plan\.spec\.buttonGetter/);
assert.match(source, /const TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS = 3;/);
assert.match(source, /const TRADE_ACTION_BUTTON_READY_TIMEOUT_MS = TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS \* 1000;/);
assert.match(readyButtonBody, /下单按钮 \$\{TRADE_ACTION_BUTTON_READY_TIMEOUT_SECONDS\} 秒内未恢复可点击/);
assert.doesNotMatch(readyButtonBody, /持续处理中/);
assert.doesNotMatch(executeBody, /const button = plan\.spec\.buttonGetter\(\);\s*if/);
assert.match(readyButtonBody, /isSubmitButtonBusy/);
assert.doesNotMatch(source, /LADDER_ORDER_DELAY_MS/);
Expand Down
Loading