Skip to main content

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:

TypeDescription
deepbook_margin_loan_updates_loan_borrowedNew loan taken out
deepbook_margin_loan_updates_loan_repaidLoan partially or fully repaid
deepbook_margin_loan_updates_liquidationPosition liquidated

Endpoint

GET /deepbook-margin/{marginPoolId}/loan-updates

Parameters

ParameterTypeRequiredDescription
marginPoolIdstringYesMargin pool ID to stream events from
api-keystringYesYour Surflux API key (query parameter)
last-idstringNoResume from events after this ID

Last-ID Options

ValueDescription
<event-id>Resume from events after this specific ID
0Consume 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

FieldTypeDescription
margin_manager_idstringMargin manager that took the loan
margin_pool_idstringMargin pool borrowed from
loan_amountnumberAmount borrowed (in smallest units)
loan_sharesnumberLoan shares assigned
timestampnumberOn-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

FieldTypeDescription
margin_manager_idstringMargin manager that repaid
margin_pool_idstringMargin pool repaid to
repay_amountnumberAmount repaid (in smallest units)
repay_sharesnumberLoan shares repaid
timestampnumberOn-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

FieldTypeDescription
margin_manager_idstringLiquidated margin manager
margin_pool_idstringMargin pool the debt was in
liquidation_amountnumberAmount of debt liquidated
pool_rewardnumberReward retained by the pool
pool_defaultnumberBad debt absorbed by pool (if any)
risk_rationumberRisk ratio at liquidation (× 1,000,000)
remaining_base_assetnumberRemaining base collateral
remaining_quote_assetnumberRemaining quote collateral
timestampnumberOn-chain timestamp in milliseconds