System Idea: Stop-Loss Orders #380
Closed
dangell7
started this conversation in
Ideas (pre standard proposal)
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Stop-Loss Orders
1. Abstract
This specification introduces a stop-loss order system for the XRP Ledger, allowing users to submit pre-signed transactions that are stored off-chain on individual nodes and executed automatically when specified price conditions are met. The system supports four order types: stop-loss sells, stop-loss buys, take-profit sells, and take-profit buys. Orders must use tickets for execution to avoid sequence number conflicts.
Important: Stop-loss orders are stored locally on individual nodes and are not replicated across the network. Users must submit orders to specific nodes they trust to monitor and execute their orders.
2. Motivation
Current XRPL trading requires active monitoring and manual order submission. Traders cannot protect positions or automate entry/exit strategies without constant oversight or third-party services. This creates disadvantages for retail traders and increases systemic risk during volatile market conditions.
Stop-loss orders are a fundamental trading tool in traditional markets, providing:
3. Specification
3.1. System Architecture
3.1.1. Node-Local Storage
Stop-loss orders are stored locally on individual rippled nodes using LMDB (Lightning Memory-Mapped Database). This design means:
The database maintains:
3.1.2. Order Types
Four distinct stop order types are supported:
3.2. Order Lifecycle
3.2.1. Submission
Users create and sign an OfferCreate transaction using a ticket, then submit it via the
submit_passiveRPC with stop parameters. The node validates the transaction structure, verifies ticket usage, and stores the order in its local database indexed by market and price.3.2.2. Monitoring
After each validated ledger, the system checks current market prices by examining the order book tops for markets with stored orders. The system uses BookDirs to efficiently iterate through order book offers and calculate market prices from the best available offers.
3.2.3. Execution
When market conditions meet trigger criteria, the pre-signed transactions are submitted to the network through the standard transaction processing pipeline. Successfully submitted orders are removed from the database to prevent re-submission.
3.3. Price Determination
Market prices are calculated from actual order book data:
This ensures orders trigger based on executable prices rather than theoretical values.
3.4. API Specification
3.4.1. submit_passive RPC
Accepts pre-signed OfferCreate transactions with stop conditions.
Request Parameters:
tx_blob(required): Hex-encoded signed transactionstop_price(required): Numeric trigger pricestop_type(required): One of "stop_loss_sell", "stop_loss_buy", "take_profit_sell", "take_profit_buy"Response:
engine_result: "tesSUCCESS" if stored, "tecDUPLICATE" if order already existstx_hash: Transaction hash of the stored order4. Rationale
4.1. Node-Local Design
Stop orders are stored locally rather than on-ledger because:
4.2. Ticket Requirement
Tickets are mandatory because orders may trigger simultaneously when market conditions change rapidly. Regular sequence numbers would cause transaction failures when orders execute out of sequence.
4.3. Market-Based Organization
Orders are indexed by market (currency pairs) to avoid checking irrelevant order books. Only markets with active stop orders are monitored, improving efficiency.
4.4. Trust Model
This design requires users to trust their chosen node operator to:
This mirrors traditional finance where traders trust brokers with stop-loss orders.
5. Backwards Compatibility
This feature is fully backwards compatible:
6. Security Considerations
6.1. Node Operator Risks
6.2. Database Security
6.3. Transaction Security
6.4. Market Integrity
7. Future Considerations
7.1. Potential Enhancements
7.2. Network-Wide Implementation
A future amendment could move stop orders on-chain with:
8. Appendix
8.1. FAQ
Q: Why aren't stop orders visible to all nodes?
A: They're stored locally to prevent ledger bloat and maintain trading privacy.
Q: What happens if my node goes offline?
A: Orders won't be monitored while offline. Monitoring resumes when the node restarts.
Q: Can I submit the same order to multiple nodes?
A: Technically possible but risks double-execution if both nodes trigger simultaneously.
Q: How do I know which nodes support stop orders?
A: Node operators would advertise this feature. No on-chain discovery mechanism exists.
Q: What's the performance impact?
A: Minimal - order checking happens after ledger validation using efficient indexed lookups.
8.2. Reference Implementation
A current implementation exists here: https://github.com/Transia-RnD/rippled/tree/stop-loss
Beta Was this translation helpful? Give feedback.
All reactions