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
5 changes: 5 additions & 0 deletions docs/binance-strategy27-events-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ removed and visualization stops with an alignment error.
`trigger_snapshot.bucket_start_ms` to equal it; the bucket end remains the
exclusive end of that same measurement interval.

For a closed event, `latest_snapshot` is the last eligible event bucket retained
before closure. `event_closed.event_time_ms` carries `active_end_at_ms` and can
be later than that snapshot's end when an ineligible bucket advances the event
to its lifecycle deadline without joining the event.

The script stores only its own returned entity IDs. Route, symbol, interval,
epoch, cursor, or sequence discontinuities abort the request and remove only
those transient entities. Event count and age are bounded in memory and on the
Expand Down
3 changes: 1 addition & 2 deletions scripts/binance-strategy27-events.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @namespace binance.strategy27.events
// @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 0.1.1
// @version 0.1.2
// @author jackhai9
// @description 在 Binance 一秒图表标注 VPS Strategy 27 的实时订单流事件和后续结果
// @match https://www.binance.com/*/futures/*
Expand Down Expand Up @@ -165,7 +165,6 @@
"universe_removed",
"monitor_stopped"
].includes(value.close_reason), "closed event close_reason is invalid");
assertCondition(value.latest_snapshot.bucket_end_ms === value.active_end_at_ms, "closed latest snapshot must end at active_end_at_ms");
}
}
function validateOutcome(value) {
Expand Down
1 change: 0 additions & 1 deletion src/binance-strategy27-events/core/live-event-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ function validateEvent(value) {
'universe_removed',
'monitor_stopped',
].includes(value.close_reason), 'closed event close_reason is invalid');
assertCondition(value.latest_snapshot.bucket_end_ms === value.active_end_at_ms, 'closed latest snapshot must end at active_end_at_ms');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/binance-strategy27-events/index.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @namespace binance.strategy27.events
// @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 0.1.1
// @version 0.1.2
// @author jackhai9
// @description 在 Binance 一秒图表标注 VPS Strategy 27 的实时订单流事件和后续结果
// @match https://www.binance.com/*/futures/*
Expand Down
19 changes: 19 additions & 0 deletions test/unit/binance-strategy27-events/live-event-contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,25 @@ test('validates live envelopes without coercing decimal strings or extra keys',
);
});

test('allows a closed event to retain the last eligible snapshot before its lifecycle boundary', () => {
const closedEvent = {
...event({ status: 'complete', activeEnd: 2_000 }),
latest_snapshot: snapshot({ start: 1_500, end: 1_750 }),
};
const closedEnvelope = envelope({
kind: 'event_closed',
payload: { event: closedEvent },
status: 'complete',
eventTime: 2_000,
});

assert.equal(validateLiveEnvelope(closedEnvelope), closedEnvelope);
assert.throws(
() => validateLiveEnvelope({ ...closedEnvelope, event_time_ms: 1_999 }),
/event_closed time is invalid/,
);
});

test('tracks exact sequence and event lifecycle while allowing reset rehydration', () => {
const lifecycle = new LiveEventLifecycle('BTR/USDT:USDT', lifecycleOptions);
const opened = lifecycle.apply(envelope());
Expand Down
2 changes: 1 addition & 1 deletion test/unit/userscript-release-contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test('release contract identifies the generated Strategy 27 annotation artifact'

assert.equal(contract.name, '【自写】Binance Strategy 27 事件标注');
assert.equal(contract.namespace, 'binance.strategy27.events');
assert.equal(contract.version, '0.1.1');
assert.equal(contract.version, '0.1.2');
assert.equal(contract.runAt, 'document-idle');
assert.equal(contract.updateURL, contract.downloadURL);
assert.deepEqual(contract.matches, [
Expand Down
Loading