mexc debug files
This commit is contained in:
130
NN/exchanges/mexc/debug/test_mexc_interface_debug.py
Normal file
130
NN/exchanges/mexc/debug/test_mexc_interface_debug.py
Normal file
@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Debug MEXC Interface vs Manual
|
||||
|
||||
Compare what the interface sends vs what works manually
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import hmac
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
|
||||
# Add project root to path
|
||||
project_root = Path(__file__).parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
def debug_interface():
|
||||
"""Debug the interface signature generation"""
|
||||
print("MEXC Interface vs Manual Debug")
|
||||
print("=" * 50)
|
||||
|
||||
# Get API credentials
|
||||
api_key = os.getenv('MEXC_API_KEY', '')
|
||||
api_secret = os.getenv('MEXC_SECRET_KEY', '')
|
||||
|
||||
if not api_key or not api_secret:
|
||||
print("❌ No MEXC API credentials found")
|
||||
return False
|
||||
|
||||
from NN.exchanges.mexc_interface import MEXCInterface
|
||||
|
||||
mexc = MEXCInterface(api_key=api_key, api_secret=api_secret, test_mode=False, trading_mode='live')
|
||||
|
||||
# Test parameters exactly like the interface would use
|
||||
symbol = 'ETH/USDT'
|
||||
formatted_symbol = mexc._format_spot_symbol(symbol)
|
||||
quantity = 0.003
|
||||
price = 2900.0
|
||||
|
||||
print(f"Symbol: {symbol} -> {formatted_symbol}")
|
||||
print(f"Quantity: {quantity}")
|
||||
print(f"Price: {price}")
|
||||
|
||||
# Interface parameters (what place_order would create)
|
||||
interface_params = {
|
||||
'symbol': formatted_symbol,
|
||||
'side': 'BUY',
|
||||
'type': 'LIMIT',
|
||||
'quantity': str(quantity), # Interface converts to string
|
||||
'price': str(price), # Interface converts to string
|
||||
'timeInForce': 'GTC' # Interface adds this
|
||||
}
|
||||
|
||||
print(f"\nInterface params (before timestamp/recvWindow): {interface_params}")
|
||||
|
||||
# Add timestamp and recvWindow like _send_private_request does
|
||||
timestamp = str(int(time.time() * 1000))
|
||||
interface_params['timestamp'] = timestamp
|
||||
interface_params['recvWindow'] = str(mexc.recv_window)
|
||||
|
||||
print(f"Interface params (complete): {interface_params}")
|
||||
|
||||
# Generate signature using interface method
|
||||
interface_signature = mexc._generate_signature(interface_params)
|
||||
print(f"Interface signature: {interface_signature}")
|
||||
|
||||
# Manual signature (what we tested successfully)
|
||||
manual_params = {
|
||||
'symbol': 'ETHUSDC',
|
||||
'side': 'BUY',
|
||||
'type': 'LIMIT',
|
||||
'quantity': '0.003',
|
||||
'price': '2900',
|
||||
'timestamp': timestamp,
|
||||
'recvWindow': '5000'
|
||||
}
|
||||
|
||||
print(f"\nManual params: {manual_params}")
|
||||
|
||||
# Generate signature manually (working method)
|
||||
mexc_order = ['symbol', 'side', 'type', 'quantity', 'price', 'timestamp', 'recvWindow']
|
||||
param_list = []
|
||||
for key in mexc_order:
|
||||
if key in manual_params:
|
||||
param_list.append(f"{key}={manual_params[key]}")
|
||||
|
||||
manual_params_string = '&'.join(param_list)
|
||||
manual_signature = hmac.new(
|
||||
api_secret.encode('utf-8'),
|
||||
manual_params_string.encode('utf-8'),
|
||||
hashlib.sha256
|
||||
).hexdigest()
|
||||
|
||||
print(f"Manual params string: {manual_params_string}")
|
||||
print(f"Manual signature: {manual_signature}")
|
||||
|
||||
# Compare parameters
|
||||
print(f"\n📊 COMPARISON:")
|
||||
print(f"symbol: Interface='{interface_params['symbol']}', Manual='{manual_params['symbol']}' {'✅' if interface_params['symbol'] == manual_params['symbol'] else '❌'}")
|
||||
print(f"side: Interface='{interface_params['side']}', Manual='{manual_params['side']}' {'✅' if interface_params['side'] == manual_params['side'] else '❌'}")
|
||||
print(f"type: Interface='{interface_params['type']}', Manual='{manual_params['type']}' {'✅' if interface_params['type'] == manual_params['type'] else '❌'}")
|
||||
print(f"quantity: Interface='{interface_params['quantity']}', Manual='{manual_params['quantity']}' {'✅' if interface_params['quantity'] == manual_params['quantity'] else '❌'}")
|
||||
print(f"price: Interface='{interface_params['price']}', Manual='{manual_params['price']}' {'✅' if interface_params['price'] == manual_params['price'] else '❌'}")
|
||||
print(f"timestamp: Interface='{interface_params['timestamp']}', Manual='{manual_params['timestamp']}' {'✅' if interface_params['timestamp'] == manual_params['timestamp'] else '❌'}")
|
||||
print(f"recvWindow: Interface='{interface_params['recvWindow']}', Manual='{manual_params['recvWindow']}' {'✅' if interface_params['recvWindow'] == manual_params['recvWindow'] else '❌'}")
|
||||
|
||||
# Check for timeInForce difference
|
||||
if 'timeInForce' in interface_params:
|
||||
print(f"timeInForce: Interface='{interface_params['timeInForce']}', Manual=None ❌ (EXTRA PARAMETER)")
|
||||
|
||||
# Test without timeInForce
|
||||
print(f"\n🔧 TESTING WITHOUT timeInForce:")
|
||||
interface_params_minimal = interface_params.copy()
|
||||
del interface_params_minimal['timeInForce']
|
||||
|
||||
interface_signature_minimal = mexc._generate_signature(interface_params_minimal)
|
||||
print(f"Interface signature (no timeInForce): {interface_signature_minimal}")
|
||||
|
||||
if interface_signature_minimal == manual_signature:
|
||||
print("✅ Signatures match when timeInForce is removed!")
|
||||
return True
|
||||
else:
|
||||
print("❌ Still don't match")
|
||||
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
debug_interface()
|
Reference in New Issue
Block a user