try to improve captcha support
This commit is contained in:
@ -13,6 +13,7 @@ import sys
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
import uuid
|
||||
|
||||
# Add the project root to path
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
@ -81,7 +82,16 @@ def test_basic_connection():
|
||||
logger.warning("Extracted cookies may be incomplete")
|
||||
|
||||
# Initialize the web client
|
||||
client = MEXCFuturesWebClient(cookies)
|
||||
client = MEXCFuturesWebClient(session_cookies=cookies)
|
||||
|
||||
# Update headers to include additional parameters from captured requests
|
||||
client.session.headers.update({
|
||||
'trochilus-trace-id': f"{uuid.uuid4()}-{int(time.time() * 1000) % 10000:04d}",
|
||||
'trochilus-uid': cookies.get('u_id', ''),
|
||||
'Referer': 'https://www.mexc.com/en-GB/futures/ETH_USDT?type=linear_swap',
|
||||
'Language': 'English',
|
||||
'X-Language': 'en-GB'
|
||||
})
|
||||
|
||||
if not client.is_authenticated:
|
||||
logger.error("Failed to authenticate with extracted cookies")
|
||||
@ -136,6 +146,20 @@ def test_position_opening(client: MEXCFuturesWebClient, dry_run: bool = True):
|
||||
# Test just the captcha verification part
|
||||
return client.verify_captcha(symbol, 'openlong', f'{leverage}X')
|
||||
|
||||
def test_position_opening_live(client):
|
||||
symbol = "ETH_USDT"
|
||||
volume = 1 # Small volume for testing
|
||||
leverage = 200
|
||||
|
||||
logger.info(f"LIVE TRADING: Opening actual position!")
|
||||
logger.info(f"Attempting to open long position: {symbol}, Volume: {volume}, Leverage: {leverage}x")
|
||||
|
||||
result = client.open_long_position(symbol, volume, leverage)
|
||||
if result.get('success'):
|
||||
logger.info(f"Successfully opened position: {result}")
|
||||
else:
|
||||
logger.error(f"Failed to open position: {result.get('error', 'Unknown error')}")
|
||||
|
||||
def interactive_menu(client: MEXCFuturesWebClient):
|
||||
"""Interactive menu for testing different functions"""
|
||||
while True:
|
||||
@ -159,12 +183,8 @@ def interactive_menu(client: MEXCFuturesWebClient):
|
||||
test_position_opening(client, dry_run=True)
|
||||
|
||||
elif choice == "3":
|
||||
confirm = input("Are you sure you want to open a LIVE position? (type 'YES' to confirm): ")
|
||||
if confirm == "YES":
|
||||
test_position_opening(client, dry_run=False)
|
||||
else:
|
||||
print("Cancelled live trading")
|
||||
|
||||
test_position_opening_live(client)
|
||||
|
||||
elif choice == "4":
|
||||
logger.info("DRY RUN: Position closing test")
|
||||
success = client.verify_captcha('ETH_USDT', 'closelong', '200X')
|
||||
@ -226,7 +246,7 @@ def main():
|
||||
logger.error("No valid session available")
|
||||
return
|
||||
|
||||
client = MEXCFuturesWebClient(cookies)
|
||||
client = MEXCFuturesWebClient(session_cookies=cookies)
|
||||
|
||||
if not client.is_authenticated:
|
||||
logger.error("Failed to authenticate with MEXC")
|
||||
|
Reference in New Issue
Block a user