Skip to content

Commit 92c3359

Browse files
committed
move InMemoryOrderBook into paper_client
1 parent e834321 commit 92c3359

7 files changed

Lines changed: 28 additions & 4 deletions

File tree

lighter/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@
206206
from lighter.ws_client import WsClient
207207
from lighter.signer_client import SignerClient, create_api_key
208208
from lighter.paper_client import (
209+
InMemoryOrderBook,
210+
OrderBookLevel,
209211
PaperAccount,
210212
PaperAccountHealth,
211213
PaperClient,

lighter/paper_client/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from lighter.paper_client.client import PaperClient
2+
from lighter.paper_client.order_book import InMemoryOrderBook, OrderBookLevel
23
from lighter.paper_client.types import (
34
MarketConfig,
45
PaperAccount,
@@ -14,7 +15,9 @@
1415
)
1516

1617
__all__ = [
18+
"InMemoryOrderBook",
1719
"MarketConfig",
20+
"OrderBookLevel",
1821
"PaperAccount",
1922
"PaperAccountHealth",
2023
"PaperClient",

lighter/paper_client/client.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from lighter.api_client import ApiClient
66
from lighter.configuration import Configuration
77
from lighter.models.perps_order_book_detail import PerpsOrderBookDetail
8-
from lighter.order_book_runtime import InMemoryOrderBook
8+
from lighter.paper_client.order_book import InMemoryOrderBook
99
from lighter.paper_client.accounting import (
1010
copy_account,
1111
copy_position,
@@ -34,6 +34,20 @@
3434

3535

3636
class PaperClient:
37+
"""Local simulation client for testing trading strategies against real Lighter order book data.
38+
39+
Maintains a virtual account with simulated collateral, executes taker-only fills
40+
against live or snapshot order book state, and tracks positions, PnL, and account
41+
health locally.
42+
43+
Limitations:
44+
- Perp markets only — spot markets are not supported.
45+
- Taker-only — supports MARKET and IOC order types, no resting limit orders.
46+
- Cross-margin only — isolated margin is not simulated.
47+
- No funding simulation — funding rate payments are not applied to positions.
48+
- Read-only simulation — no transactions are submitted to the exchange; all state is local.
49+
"""
50+
3751
def __init__(
3852
self,
3953
api_client: Optional[ApiClient],

lighter/paper_client/matching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from math import fabs, pow
22
from typing import Iterable, List, Tuple
33

4-
from lighter.order_book_runtime import OrderBookLevel
4+
from lighter.paper_client.order_book import OrderBookLevel
55
from lighter.paper_client.types import (
66
MarketConfig,
77
PaperFill,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def to_dict(self) -> Mapping[str, str]:
4949

5050
@dataclass
5151
class InMemoryOrderBook:
52+
"""Sorted in-memory order book built for ``PaperClient`` to simulate
53+
taker fills against order book data. Keeps asks sorted ascending and
54+
bids sorted descending so the best prices are always at index 0.
55+
"""
56+
5257
asks: List[OrderBookLevel] = field(default_factory=list)
5358
bids: List[OrderBookLevel] = field(default_factory=list)
5459
offset: Optional[int] = None

test/paper_client/test_matching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from lighter.order_book_runtime import OrderBookLevel
3+
from lighter.paper_client.order_book import OrderBookLevel
44
from lighter.paper_client.matching import simulate_match, validate_order
55
from lighter.paper_client.types import (
66
PaperOrderRequest,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from lighter.models.order_book_orders import OrderBookOrders
55
from lighter.models.price_level import PriceLevel
66
from lighter.models.simple_order import SimpleOrder
7-
from lighter.order_book_runtime import InMemoryOrderBook
7+
from lighter.paper_client.order_book import InMemoryOrderBook
88

99

1010
def make_runtime() -> InMemoryOrderBook:

0 commit comments

Comments
 (0)