Skip to content
Open
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
2 changes: 2 additions & 0 deletions doc/protocol/orderbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ At the end of each batch interval, the matching engine runs a double auction usi

All matched orders execute at the same uniform price. No participant gets a better or worse price based on when their order arrived within the batch.

Market orders do not influence the clearing price — only limit orders at the margin determine it. If the marginal matched order on one side is a market order, the clearing price equals the limit price from the other side alone. If no limit orders were matched at all, the previous batch's clearing price carries over.

### Batch Deadline

The `deadline` parameter in `submitOrder` specifies the latest batch the user wants their order included in. The order can be included in any batch up to and including the deadline batch — so pushing `deadline` further into the future widens the window of batches the order can land in, it does not delay execution.
Expand Down
8 changes: 4 additions & 4 deletions doc/protocol/perpetuals.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ funding_rate = clamp(
interest_rate
+ saturate((impact_bid − oracle_price) / oracle_price)
− saturate((oracle_price − impact_ask) / oracle_price),
0,
−max_funding_rate,
max_funding_rate,
)
```
Expand All @@ -50,11 +50,11 @@ When the perp trades at a premium (`impact_bid` above the oracle) the first `sat

### Per-position payment

Every batch, each open position settles funding into cash:
Every batch, each open position settles funding into cash. Because `interest_rate` and `max_funding_rate` are expressed per `funding_window` (8 hours by default), the payment is prorated to the actual time elapsed since the last batch:

```
funding_payment = funding_rate × oracle_price × position.size
funding_payment = funding_rate × oracle_price × position.size × (elapsed / funding_window)
realized_pnl −= funding_payment
```

`position.size` is signed (long positive, short negative), so a positive `funding_rate` charges longs and credits shorts, and vice versa. After settlement, the position's unrealized PnL is pure price drift: `(mark − entry) × size`.
`position.size` is signed (long positive, short negative), so a positive `funding_rate` charges longs and credits shorts, and vice versa. A position held for exactly one `funding_window` pays `funding_rate × oracle_price × position.size` in total. After settlement, the position's unrealized PnL is pure price drift: `(mark − entry) × size`.
Loading