3.6 KiB
3.6 KiB
MEXC CAPTCHA Handling Documentation
Overview
This document outlines the mechanism implemented in the gogo2
trading dashboard project to handle CAPTCHA challenges encountered during automated trading on the MEXC platform. The goal is to enable seamless trading operations without manual intervention by capturing and integrating CAPTCHA tokens.
CAPTCHA Handling Mechanism
1. Browser Automation with MEXCBrowserAutomation
- The
MEXCBrowserAutomation
class incore/mexc_webclient/auto_browser.py
is responsible for launching a browser session using Selenium WebDriver. - It navigates to the MEXC futures trading page and captures HTTP requests and responses, including those related to CAPTCHA challenges.
- When a CAPTCHA request is detected (e.g., requests to
gcaptcha4.geetest.com
or specific MEXC CAPTCHA endpoints), the relevant token is extracted from the request headers or response data. - These tokens are saved to JSON files named
mexc_captcha_tokens_YYYYMMDD_HHMMSS.json
in the project root directory for later use.
2. Integration with MEXCFuturesWebClient
- The
MEXCFuturesWebClient
class incore/mexc_webclient/mexc_futures_client.py
is updated to handle CAPTCHA challenges during API requests. - A
MEXCSessionManager
class manages session data, including cookies and CAPTCHA tokens, by reading the latest token from the saved JSON files. - When a request fails due to a CAPTCHA challenge, the client retrieves the latest token and includes it in the request headers under
captcha-token
.
3. Manual Testing and Data Capture
- The script
run_mexc_browser.py
provides an interactive way to test theMEXCFuturesWebClient
and capture CAPTCHA tokens. - Users can run this script to perform test trades, monitor requests, and save captured data, including tokens, to files.
- The captured tokens are used in subsequent API calls to authenticate trading actions like opening or closing positions.
Usage Instructions
Running Browser Automation
- Execute
python run_mexc_browser.py
to start the browser automation. - Choose options like 'Perform test trade (manual)' to simulate trading actions and capture CAPTCHA tokens.
- The script saves tokens to a JSON file, which can be used by
MEXCFuturesWebClient
for automated trading.
Automated Trading with CAPTCHA Tokens
- Ensure that the
MEXCFuturesWebClient
is configured to use the latest CAPTCHA token file. This is handled automatically by theMEXCSessionManager
class, which looks for the most recent file matching the patternmexc_captcha_tokens_*.json
. - If a CAPTCHA challenge is encountered during trading, the client will attempt to use the saved token to proceed with the request.
Limitations and Notes
- Token Validity: CAPTCHA tokens have a limited validity period. If the saved token is outdated, a new browser session may be required to capture fresh tokens.
- Automation: Currently, token capture requires manual initiation via
run_mexc_browser.py
. Future enhancements may include background automation for continuous token updates. - Windows Compatibility: All scripts and file operations are designed to work on Windows systems, adhering to project rules for compatibility.
Troubleshooting
- If trades fail due to CAPTCHA issues, check if a recent token file exists and contains valid tokens.
- Run
run_mexc_browser.py
to capture new tokens if necessary. - Verify that file paths and permissions are correct for reading/writing token files on Windows.
For further assistance or to report issues, refer to the project's main documentation or contact the development team.