mirror of
https://github.com/mauricioabh/arbpulse.git
synced 2026-07-27 15:47:43 +00:00
4ffce9a59e
Kraken WS v2 book channel does not send deletes for levels evicted from its top-N window; without client-side truncation those levels lingered forever as phantom quotes, eventually crossing the local book (bid >= ask) and feeding the engine a fake permanent arbitrage (~$62.9M bogus P&L). - BookSide.truncate() removes levels beyond the best depth prices from the internal map (not just the emitted array) - KrakenConnector uses depth 10 consistently (subscription + LocalBook) and truncates both sides after every update - ExchangeConnector.emit() drops internally crossed books, logs and forces a resync (book reset + reconnect for a fresh snapshot) - Unit tests for truncation and the crossed-book guard - OpenSpec: order-book-integrity spec; change archived (2026-07-19) Refs: Linear WAY-77 Co-authored-by: Cursor <cursoragent@cursor.com>
1.3 KiB
1.3 KiB
Tasks — fix-kraken-phantom-book-levels
1. LocalBook: truncado real
- Añadir
BookSide.truncate()que elimine del Map los niveles fuera de los mejoresdepthprecios del lado - Unit tests de
truncate(): elimina el peor nivel al exceder depth, no toca nada si size <= depth, y el bid fantasma desaparece tras updates sucesivos
2. Conector Kraken
- Hacer
ExchangeConnector.depthsobreescribible por subclase e inicializarLocalBookcon el depth del conector - Fijar depth 10 en
KrakenConnector(igual a la suscripción) y truncar ambos lados tras aplicar cada update
3. Guard de libro cruzado
- En
ExchangeConnector.emit(): sibids[0].price >= asks[0].price, no emitir, log warn, reset del libro y reconexión para re-sync - Unit test del guard: libro cruzado no se emite a listeners y dispara re-sync
4. Documentación
- Actualizar skill
exchange-ws(truncado obligatorio en Kraken v2, guard de cruce en la base, depth por conector) - Revisar README/AGENTS por menciones al manejo del libro que queden desactualizadas
5. Verificación
npm run typecheck+npm testen verde- Arrancar en local con feeds reales y verificar via
/api/stateque Kraken emite libro no cruzado y quotes coherentes con el mercado (matar el proceso al terminar)