### ApeX Protocol Limit Order Execution Flow Source: https://docs.apex.exchange/apex/limit-order Details the process of creating and executing limit orders on ApeX Protocol, including user actions, bot interactions, and smart contract verifications. This covers the core API interactions and logic. ```APIDOC ApeX Protocol Limit Order Execution: Process Overview: Users create limit orders by signing them with their wallet. These orders are submitted to the Order Svc, then forwarded to bots for task distribution. Bots monitor market prices via the PriceOracle contract. When market conditions meet the order's criteria (price, slippage), the bot calls the Order Book contract to execute the order. Key Actions & Verifications: 1. **Approve Token Spend**: User must approve the ApeX Protocol smart contract to spend their tokens. - *Description*: Grants permission for the contract to transfer tokens from the user's wallet. - *Prerequisite*: Required before placing an order. 2. **Sign Limit Order**: User signs the order details with their wallet. - *Description*: Creates a cryptographic signature to authenticate the order. - *Input*: Order parameters (e.g., asset, amount, price, expiry). - *Output*: Digital signature. 3. **Order Submission**: Signed order is sent to Order Svc, then to Bot for task queuing. 4. **Bot Monitoring**: Bots check order conditions against real-time market data from PriceOracle. 5. **Order Execution Trigger**: When market price matches order price and slippage conditions are met. 6. **Order Book Contract Execution**: Bot calls the Order Book contract with the signed order. - **`executeOpen(orderData, signature)`**: Function to execute an open limit order. - *Parameters*: - `orderData`: Contains details of the limit order (e.g., user address, token pair, amount, limit price, expiry, slippage tolerance). - `signature`: The digital signature provided by the user. - *Internal Verifications by Order Book Contract*: 1. **Signature Validity**: Verifies the user's signature against the order data. 2. **Order Expiry**: Checks if the order has expired. 3. **Execution Status**: Ensures the order has not been executed previously. 4. **Correct Price**: Confirms the execution price is within the specified limits (considering slippage). 5. **Execution Feasibility**: Checks if the order can be executed (e.g., sufficient liquidity). - *Return Value*: Transaction status (success/reverted). - *Reversion Conditions*: If any verification fails (invalid signature, expired, already executed, price outside slippage, insufficient funds/liquidity). - **`executeClose(orderData, signature)`**: Function to execute a close limit order (e.g., closing a position). - *Parameters*: - `orderData`: Contains details of the limit order for closing. - `signature`: The digital signature provided by the user. - *Internal Verifications*: Similar to `executeOpen`, ensuring validity and correct execution conditions. - *Return Value*: Transaction status. Fees: - **Trading Fee**: Fixed 0.1% on filled orders. - **Gas Fee**: Paid by the user upon order execution (not creation). ``` -------------------------------- ### ApeX Protocol Liquidity Removal Calculation Source: https://docs.apex.exchange/guides/add-remove-liquidity This API documentation describes the calculation for the maximum amount of liquidity a provider can remove from a pool. It is influenced by the ratio of net position (quote asset) to pool liquidity (quote token), acting as a risk control parameter. The calculation involves several key metrics related to the user's positions and the overall pool state. ```APIDOC APIDOC: QueryMaxLiquidityToRemove: description: Retrieves the maximum amount of liquidity a provider can remove from a pool, subject to risk control parameters. parameters: - name: Q_net type: number description: The net value of the quote assets, calculated as the difference between long and short position sizes in quote assets. - name: B_net type: number description: The net value of the base assets, calculated as the difference between long and short position sizes in base assets. - name: B type: number description: The current number of base assets in the pool. - name: Q type: number description: The current number of quote assets in the pool. - name: totalSupply type: number description: The total liquidity (supply) in the pool. calculation_formula: description: The formula used to determine the maximum liquidity that can be removed. This is a risk-controlled value. formula: "MaxLiquidityToRemove = f(Q_net, B_net, B, Q, totalSupply)" notes: - The ApeX protocol uses the ratio of net position (quote asset) to pool liquidity (quote token) as a risk control parameter. - This parameter is configurable and defaults to 0.1. - If the number of short and long positions deviates significantly, this cap will be applied, potentially reducing the amount of liquidity that can be removed. - If the net position size is zero (Q_net = 0) and/or positions are fully balanced (B_net = 0), all liquidity in the pool can be removed. returns: type: number description: The maximum amount of liquidity that can be removed by the LP. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.