Loan Updates
Stream real-time loan events from a specific DeepBook Margin pool. This stream delivers loan borrowed events, loan repaid events, and liquidations as they occur on-chain.
Event Types
This stream emits three event types:
| Type | Description |
|---|---|
deepbook_margin_loan_updates_loan_borrowed | New loan taken out |
deepbook_margin_loan_updates_loan_repaid | Loan partially or fully repaid |
deepbook_margin_loan_updates_liquidation | Position liquidated |
Endpoint
GET /deepbook-margin/{marginPoolId}/loan-updates
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
marginPoolId | string | Yes | Margin pool ID to stream events from |
api-key | string | Yes | Your Surflux API key (query parameter) |
last-id | string | No | Resume from events after this ID |
Last-ID Options
| Value | Description |
|---|---|
<event-id> | Resume from events after this specific ID |
0 | Consume from the beginning (server retention limits apply) |
$ | Consume only real-time events (skip historical) |
Event Structures
Loan Borrowed
Emitted when a new loan is taken out from the margin pool.
{
"type": "deepbook_margin_loan_updates_loan_borrowed",
"timestamp_ms": 1758629823918,
"checkpoint_id": 193054501,
"tx_hash": "FgUfRsYpC6ynW3pRvtgCLaa4WniBZYdsSLP94jrZ3pj7",
"data": {
"margin_manager_id": "0xabc123def456789abc123def456789abc123def456789abc123def456789abc1",
"margin_pool_id": "0x4405b50d791fd3346754e8171aaab6bc2ed26c2c46efdd033c14b30ae507ac33",
"loan_amount": 1000000000000,
"loan_shares": 1000000000000,
"timestamp": 1758629823805
}
}
Loan Borrowed Fields
| Field | Type | Description |
|---|---|---|
margin_manager_id | string | Margin manager that took the loan |
margin_pool_id | string | Margin pool borrowed from |
loan_amount | number | Amount borrowed (in smallest units) |
loan_shares | number | Loan shares assigned |
timestamp | number | On-chain timestamp in milliseconds |
Loan Repaid
Emitted when a loan is partially or fully repaid.
{
"type": "deepbook_margin_loan_updates_loan_repaid",
"timestamp_ms": 1758629923918,
"checkpoint_id": 193054601,
"tx_hash": "GhVgStZqD7zoX4qSwuhDMbb5XoCjCaBttMQ95ksA4Sk8",
"data": {
"margin_manager_id": "0xabc123def456789abc123def456789abc123def456789abc123def456789abc1",
"margin_pool_id": "0x4405b50d791fd3346754e8171aaab6bc2ed26c2c46efdd033c14b30ae507ac33",
"repay_amount": 200000000000,
"repay_shares": 200000000000,
"timestamp": 1758629923805
}
}
Loan Repaid Fields
| Field | Type | Description |
|---|---|---|
margin_manager_id | string | Margin manager that repaid |
margin_pool_id | string | Margin pool repaid to |
repay_amount | number | Amount repaid (in smallest units) |
repay_shares | number | Loan shares repaid |
timestamp | number | On-chain timestamp in milliseconds |
Liquidation
Emitted when a margin position is liquidated.
{
"type": "deepbook_margin_loan_updates_liquidation",
"timestamp_ms": 1758630023918,
"checkpoint_id": 193054701,
"tx_hash": "HiWgTuArE8apY5rTxviEOcc6YpDkDbCuuNR06ltB5Tl9",
"data": {
"margin_manager_id": "0xabc123def456789abc123def456789abc123def456789abc123def456789abc1",
"margin_pool_id": "0x4405b50d791fd3346754e8171aaab6bc2ed26c2c46efdd033c14b30ae507ac33",
"liquidation_amount": 200000000000,
"pool_reward": 5000000000,
"pool_default": 0,
"risk_ratio": 1120000,
"remaining_base_asset": 500000000000,
"remaining_quote_asset": 100000000,
"timestamp": 1758630023805
}
}
Liquidation Fields
| Field | Type | Description |
|---|---|---|
margin_manager_id | string | Liquidated margin manager |
margin_pool_id | string | Margin pool the debt was in |
liquidation_amount | number | Amount of debt liquidated |
pool_reward | number | Reward retained by the pool |
pool_default | number | Bad debt absorbed by pool (if any) |
risk_ratio | number | Risk ratio at liquidation (× 1,000,000) |
remaining_base_asset | number | Remaining base collateral |
remaining_quote_asset | number | Remaining quote collateral |
timestamp | number | On-chain timestamp in milliseconds |