Skip to content

Paper Trading#145

Merged
kutay25 merged 13 commits intomainfrom
paper-trading
Apr 21, 2026
Merged

Paper Trading#145
kutay25 merged 13 commits intomainfrom
paper-trading

Conversation

@kutay25
Copy link
Copy Markdown
Contributor

@kutay25 kutay25 commented Apr 16, 2026

Summary

  • Implements paper trading client to lighter-python
  • Taker-only simulated trading against live or snapshot Lighter order books, no real transactions
  • Perps only, cross-margin only, no funding simulation

What's included

  • lighter/paper_client/ package: types, matching engine, accounting, risk/liquidation, order book runtime
  • Snapshot mode: fetch order book via REST, simulate trades against it
  • Live mode: private websocket connection per market, continuous book updates, automatic liquidation checks
  • Matching is read-only and never mutates the tracked book
  • Position accounting mirrors backend semantics (open/reduce/flip/close, proportional entry quote)
  • Risk engine: TAV, IMR, MMR, closeout margin, leverage, margin usage, liquidation price
  • Market scoped liquidation

Testing and Examples

  • 3 example scripts under examples/
  • 61 unit tests to cover various behaviours.

Open with Devin

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 18 additional findings in Devin Review.

Open in Devin Review

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

🐛 1 issue in files not directly in the diff

🐛 Duplicate field names in Candle model destroy 5 of 12 data fields (lighter/models/candle.py:34-39)

The revert commit renamed the uppercase Pydantic field names (O, H, L, C, V) to lowercase (o, h, l, c, v), creating duplicates with the existing lowercase fields on lines 30–33 and 38. In Pydantic v2, the second definition silently overrides the first, so the model collapses from 12 fields to 7. The plain o (open), h (high), l (low), c (close), and v (volume0) fields are completely lost — their definitions are replaced by the aliased raw variants.

Verified impact via runtime test

Confirmed via Candle.model_fields: only 7 fields remain (t, o (alias=O), h (alias=H), l (alias=L), c (alias=C), v (alias=V), i). When validating {"o": 100, "O": 99, ...}, accessing candle.o returns 99 (the raw value) not 100 (the open value). model_dump(by_alias=True) produces only 7 keys, omitting o, h, l, c, v entirely.

View 18 additional findings in Devin Review.

Open in Devin Review

kutay25 added 2 commits April 20, 2026 15:11
Mirrors the real SignerClient shape where order submission returns only
fill/tx info and post-order state is queried separately. Callers detect
liquidation via get_position() returning None or get_health().has_been_liquidated.

Fixes AttributeError in paper_trading_health.py when an aggressive order
is liquidated on the same tick as the fill and get_position(0) returns None.
@kutay25 kutay25 merged commit 6c0ed95 into main Apr 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant