5.6 KiB
5.6 KiB
Session Summary
Date: 2025-12-11
Objective(s): Fix API errors, enhance bot functionality with safety features (auto-close), and add leverage/funding monitoring.
Key Accomplishments:
- Fixed API Price Error: Implemented
round_to_sig_figsto ensure limit prices meet Hyperliquid's 5 significant figure requirement, resolving the "Order has invalid price" error. - Safety Shutdown: Added
close_all_positionsmethod and linked it toKeyboardInterrupt. The bot now automatically closes its hedge position when stopped manually. - Leverage Management: Configured the bot to automatically set leverage to 4x Cross (
LEVERAGE = 4) upon initialization. - Market Monitoring: Added real-time Funding Rate display to the main logging loop using
meta_and_asset_ctxs.
Key Files Modified:
clp_hedger.py
Decisions Made:
- Used
math.log10based calculation for significant figures to ensure broad compatibility with asset price ranges. - Implemented
close_all_positionsas a blocking call during shutdown to prioritize safety over an immediate exit. - Hardcoded
LEVERAGEin configuration for now, with a plan to potentially move to a config file later if needed.
Session Summary
Date: 2025-12-11
Objective(s): Implement a dynamic gap recovery strategy to neutralize initial losses from delayed hedging.
Key Accomplishments:
- Implemented "Gap Recovery" logic to dynamically adjust hedging based on current price relative to CLP
ENTRY_PRICEand initialSTART_PRICE. - Defined three distinct hedging zones:
- NORMAL (below Entry): 100% hedge for safety.
- RECOVERY (between Entry and Recovery Target): 0% hedge (naked long) to maximize recovery.
- NORMAL (above Recovery Target): 100% hedge after gap is neutralized.
- Introduced
PRICE_BUFFER_PCTandTIME_BUFFER_SECONDSto prevent trade churn around zone boundaries.
Key Files Modified:
clp_hedger.py
Decisions Made:
- Chosen a dynamic
START_PRICEcapture at bot initialization to calculate theGAP. - Opted for 0% hedge in the recovery zone for faster loss neutralization, acknowledging higher short-term risk.
- Implemented price and time buffers for robust mode switching.
Session Summary
Date: 2025-12-12
Objective(s): Develop a Uniswap V3 position manager script (formerly monitor) for Arbitrum, including fee collection, closing positions, and automated opening of new positions with auto-swapping. Refine hedging architecture for multi-position management.
Key Accomplishments:
uniswap_manager.py(Unified Lifecycle Manager):- Transformed into a continuous lifecycle manager for AUTOMATIC positions.
- Features:
- Manages "AUTOMATIC" CLP positions (Open, Monitor, Close, Collect Fees).
- Reads/Writes state to
hedge_status.json. - Implemented auto-wrapping of native ETH to WETH when needed.
- Includes robust auto-swapping (WETH <-> USDC) to balance tokens before minting.
- Implemented robust event parsing using
process_receiptto extract exactamount0andamount1from mint transactions. - Fixed
web3.pyv7raw_transactionaccess across all transaction types. - Fixed Uniswap V3 Math precision in
calculate_mint_amountsfor accurate token splits.
- Troubleshooting & Resolution:
- Address Validation: Replaced hardcoded factory address with dynamic lookup.
- ABI Mismatch: Updated NPM ABI with event definitions for
IncreaseLiquidityandTransfer. - Typo/Indentation Errors: Resolved multiple
NameError(target_tick_lower,w3_instance,position_details) andIndentationErrorissues during script refactoring. - JSON Update Failure: Fixed
mint_new_position's log parsing for Token ID to correctly updatehedge_status.jsonafter successful mint.
clp_scalper_hedger.py(Dedicated Automatic Hedger):- Created as a new script to hedge
type: "AUTOMATIC"positions defined inhedge_status.json. - Uses
SCALPER_AGENT_PKfrom.env. - Accurate L Calculation: Calculates Uniswap V3 liquidity (
L) usingamount0_initialoramount1_initialfromhedge_status.json, falling back to a heuristic based ontarget_valueif amounts are missing. - Dynamic Rebalance Threshold: Threshold adapts to 5% of the position's maximum ETH risk (
max_potential_eth). - Minimum Order Value: Enforces a minimum order size of $10 to prevent dust trades and API errors.
- Created as a new script to hedge
clp_hedger.py(Updated Manual Hedger):- Modified to load its configuration entirely from the
type: "MANUAL"entry inhedge_status.json. - Respects the
hedge_enabledflag from the JSON. - Idles if hedging is disabled or no manual position is found.
- Modified to load its configuration entirely from the
hedge_status.json:- Becomes the central source of truth for all (MANUAL and AUTOMATIC) CLP positions, including their type, status, ranges,
entry_price,target_value(for automatic), andhedge_enabledflag.
- Becomes the central source of truth for all (MANUAL and AUTOMATIC) CLP positions, including their type, status, ranges,
- .env File Location: All scripts updated to load
.envfrom the current working directory (clp_hedger/).
Decisions Made:
- Adopted a multi-script architecture for clarity and separation of concerns (Manager vs. Hedgers).
- Used
hedge_status.jsonas the centralized state manager for all CLP positions. - Implemented robust error handling and debugging throughout the development process.
- Ensured
clp_scalper_hedger.pyis resilient to missing initial amount data inhedge_status.jsonby implementing fallbackLcalculation methods.