Perpetuals
Last updated
Last updated
Perpetual Trading Explained:
The Elys Network's perpetual trading is a system designed to facilitate leveraged trading on various assets within the blockchain.
This system integrates several components, including the module itself, the keeper, specification, and types, to ensure seamless operation and high-level security across all transactions.
The core integration point of the perpetual trading module is responsible for managing the state of the perpetual contracts, processing transactions, and interfacing with other modules in the network. It acts as the backbone of the perpetual trading system, ensuring that all actions taken by users are securely recorded and executed according to the defined logic.
The specific responsibility for initializing the perpetual trading logic is handled by the BeginBlocker function within the Keeper. This function is triggered at the beginning of each block and performs critical operations, such as
checking whether a new epoch has begun
Computing borrow interest rates
Updating the health of margin trading positions (MTPs)
and processing funding fees.
This ensures that the system remains up-to-date and responsive to changes in the market.
Transactions within the perpetual trading module follow a well-defined lifecycle, ensuring network protocol compliance and system integrity.
When a transaction is initiated, it undergoes validation to ensure that it meets all necessary conditions, such as having sufficient collateral and being authorized (if whitelisting is enabled).
Once validated, the Keeper executes the transaction, which updates the state of the involved positions and pools accordingly.
Queries are handled by the Keeper as well, providing users and system administrators with real-time information about the status of their positions, system health, and other key metrics.
The business logic of the perpetual trading module is intricately designed to oversee risk management, risk assessments, and collateral tracking.
The module ensures that all open positions are adequately collateralized through a margin system.
It continuously monitors the health of each position and automatically triggers liquidations when necessary to protect the platform and its users. The module also implements a funding rate mechanism to maintain the alignment of perpetual contract prices with the underlying spot prices, balancing long and short exposures in the market.
The code specifications from the keeper, spec, and types define the blueprint for how the perpetual trading system operates. These include
The Keeper's methods for managing positions, pools, and transactions
The Spec that outlines the module's configuration and key parameters
The Types that define the data structures used throughout the module.
These components create a flexible and secure environment for perpetual trading, allowing users to leverage their positions, manage risks, and interact with the system efficiently.
In summary, the blueprint provided by the code specifications ensures that the module operates seamlessly, offering a reliable platform for users to engage in perpetual trading.
The Elys Perpectual Trading system shares several common features with other platforms:
Leverage Trading: Users can increase their exposure to certain assets by borrowing funds.
Risk Management: The system includes measures like margin requirements and automatic liquidation to protect users.
Elys stands out due to its deep integration within the Cosmos ecosystem, which enables superior interoperability and scalability.
By leveraging the Cosmos SDK and Tendermint, Elys ensures lower transaction costs and faster processing times while seamlessly connecting with other Cosmos-based networks. Elys places a strong emphasis on decentralized risk management, incorporating features like dynamic interest rate adjustments and real-time pool health monitoring. These tools provide traders with granular control over their positions, offering enhanced flexibility and security.
This focus on dynamic, decentralized management tools makes Elys an optimal choice for traders looking to refine their strategies in a multi-chain environment.
Choosing the Elys Perpetual Trading System offers several compelling advantages, particularly for experienced traders. The platform's foundation on the Cosmos SDK and Tendermint provides a robust security framework, ensuring that your trades are safeguarded within a highly secure network. Unlike traditional platforms, Elys leverages blockchain technology to deliver complete transparency, allowing you to trust in the fairness and security of every transaction. Furthermore, Elys offers unparalleled flexibility by allowing you to hold positions indefinitely, giving you the freedom to tailor your investment strategies without the pressure of expiration dates. The platform's advanced features, including decentralized oracles and smart contracts, integrate cutting-edge technology into your trading experience, offering a modern and efficient environment that enhances your trading capabilities.
Order Types Supported: Limit orders, market orders, and stop-loss orders are processed differently, each with specific logic paths in the system. These orders are essential for flexible and strategic trading, allowing users to manage their positions effectively.
Decentralized Oracles: Prices are updated by fetching data from decentralized oracles, which aggregate price feeds from multiple sources to mitigate the risk of price manipulation. This ensures that the prices of perpetual contracts and spot assets remain aligned, maintaining fair and accurate market conditions.
Leverage Calculation: Leverage is applied based on user account settings and the asset being traded. Users can select leverage levels, which determine the amount of borrowed capital relative to their own investment.
Margin Requirements: The system dynamically calculates margin requirements to prevent undercollateralization, ensuring users maintain sufficient collateral to cover potential losses. This calculation is crucial for protecting both the user and the platform from excessive risk.
Open Interest Management: Open interest is managed by tracking the total number of outstanding contracts held by market participants. The system ensures that the net open interest is balanced to prevent excessive exposure in one direction, utilizing funding rates to incentivize traders to take opposing positions.
Funding Calculation: The primary purpose of the funding rate is to balance the open interest (OI) rather than to converge the prices of spot and perpetual contracts. Since we use oracle prices, the prices of perpetual contracts and spot assets are always aligned. If the net position of all traders is long on an asset, it means the pool is short on that asset. To encourage traders to take the opposite position and balance the pool, the funding rate incentivizes traders accordingly. For instance, if the net OI is long, long position holders will pay a funding rate to short position holders, and vice versa.
Scalability Beyond Pool Liquidity: The architecture scales beyond the pool liquidity by dynamically adjusting leverage and margin requirements based on pool health. This approach ensures that the system can handle large trading volumes without compromising liquidity. Additionally, the use of decentralized oracles ensures that the pricing mechanism remains robust even under high load.
Health Calculation: The health of a position is continuously monitored by the system, which evaluates the collateral against the required margin. The system uses real-time data to assess the risk and adjust the leverage and margin requirements accordingly. This ongoing assessment helps prevent undercollateralization and ensures the stability of the trading environment.
Stop Loss Trigger: A stop-loss order is triggered when the market price of an asset reaches a specified level, automatically closing the position to prevent further losses. This mechanism protects traders from significant downside risk.
Liquidation Trigger: Positions that fall below margin requirements are automatically liquidated to ensure the system remains solvent and users do not incur more losses than their collateral can cover. The system continuously monitors each position's collateral and required margin, triggering liquidation if the collateral is insufficient.
Open interest is managed through funding rates that incentivize traders to take opposing positions. If the net position of all traders is long, the pool is short, and funding rates are adjusted to encourage short positions, balancing the open interest.
Funding rates are calculated based on the net open interest. If the net position is long, long position holders pay a funding rate to short position holders, and vice versa. This is designed to balance the open interest and ensure the pool's neutrality.
The architecture scales by dynamically adjusting leverage and margin requirements based on the pool's liquidity. This ensures that the pool can handle larger positions without compromising stability. Additionally, decentralized oracles ensure accurate pricing and real-time adjustments.
Pool health is calculated using a function H(X)H(X)H(X), which takes into account the pool's assets, liabilities, and overall liquidity. This ensures that the pool remains solvent and can cover all positions.
Stop loss is triggered when the market price reaches a predefined level set by the trader. The system monitors the market in real-time and executes the stop-loss order to limit potential losses.
Liquidation is triggered when a position's collateral falls below the required margin. The system continuously monitors the position's health and automatically liquidates it if the collateral is insufficient to cover potential losses.
When a user wants to open a position on the Elys platform:
Initiating a Trade:
The user navigates to the trading interface where they can select the asset they want to trade.
They choose whether to go long (expecting the price to rise) or short (expecting the price to fall) and specify the leverage they want to use.
Entering Trade Details:
The user inputs the amount of collateral they want to use for the trade. The system will automatically calculate the potential position size based on the chosen leverage.
If the user is satisfied with the details, they can proceed to execute the trade.
Trade Execution:
Once the trade is executed, the system performs all the necessary backend operations, such as calculating the required swap amounts, updating the pool balances, and setting up the MTP (Margin Trading Position).
The system uses decentralized oracles to fetch the latest price data and ensure that the trade is executed at a fair market price.
Monitoring the Position:
After the position is open, the user can monitor it through the dashboard. They can see all the critical information, such as the current value of the position, collateral, liabilities, and health metrics.
The platform provides real-time updates, allowing the user to track how their position is performing relative to market movements.
Adjusting or Closing a Position:
If the market conditions change or the user wants to take profits, they can easily adjust their position by adding more collateral, reducing leverage, or setting stop-loss and take-profit levels.
To close a position, the user simply clicks on the "Close Position" button, which initiates the closing process. The system calculates the necessary swaps and updates the pool and MTP accordingly.
Handling Liquidations:
If the position’s health falls below a certain threshold, the system will automatically initiate a liquidation process to protect the user and the platform from further losses. This is done seamlessly without requiring user intervention, but the user is notified and can monitor the liquidation process.
Dashboard Overview:
The dashboard provides a comprehensive view of all open positions, showing real-time data on profits/losses, funding rates, and more.
Users can also view their whitelisted status and any system notifications that might affect their trading strategy.
This flow ensures that users, especially those already familiar with perpetual trading platforms, can intuitively understand how to operate on Elys. The seamless integration of decentralized technologies, real-time data, and advanced trading tools provides a robust platform that meets the needs of sophisticated traders while maintaining ease of use.