mexc API failed, working on futures API as it what i we need anyway

This commit is contained in:
Dobromir Popov
2025-07-03 00:56:02 +03:00
parent 568ec049db
commit 118c34b990
8 changed files with 17370 additions and 714 deletions

View File

@ -0,0 +1,64 @@
import os
import logging
import sys
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# Add project root to path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from NN.exchanges.mexc_interface import MEXCInterface
from core.config import get_config
def test_mexc_private_api():
"""Test MEXC private API endpoints"""
# Load configuration
config = get_config('config.yaml')
mexc_config = config.get('mexc_trading', {})
# Get API credentials
api_key = os.getenv('MEXC_API_KEY', mexc_config.get('api_key', ''))
api_secret = os.getenv('MEXC_SECRET_KEY', mexc_config.get('api_secret', ''))
if not api_key or not api_secret:
logger.error("API key or secret not found. Please set MEXC_API_KEY and MEXC_SECRET_KEY environment variables.")
return
# Initialize MEXC interface in test mode
mexc = MEXCInterface(api_key=api_key, api_secret=api_secret, test_mode=True, trading_mode='simulation')
# Test connection
if not mexc.connect():
logger.error("Failed to connect to MEXC API")
return
# Test getting account information
logger.info("Testing account information retrieval...")
account_info = mexc.get_account_info()
if account_info:
logger.info(f"Account info retrieved: {account_info}")
else:
logger.error("Failed to retrieve account info")
# Test getting balance for a specific asset
asset = "USDT"
logger.info(f"Testing balance retrieval for {asset}...")
balance = mexc.get_balance(asset)
logger.info(f"Balance for {asset}: {balance}")
# Test placing a simulated order (in test mode)
symbol = "ETH/USDT"
side = "buy"
order_type = "market"
quantity = 0.01 # Small quantity for testing
logger.info(f"Testing order placement for {symbol} ({side}, {order_type}, qty: {quantity})...")
order_result = mexc.place_order(symbol=symbol, side=side, order_type=order_type, quantity=quantity)
if order_result:
logger.info(f"Order placed successfully: {order_result}")
else:
logger.error("Failed to place order")
if __name__ == "__main__":
test_mexc_private_api()

View File

@ -1,13 +1,31 @@
from NN.exchanges.mexc_interface import MEXCInterface
import logging
import os
from NN.exchanges.mexc_interface import MEXCInterface
# Set up logging to see debug info
logging.basicConfig(level=logging.INFO)
# Load API credentials from environment variables or a configuration file
# For testing, prioritize environment variables for CI/CD or sensitive data
# Fallback to a placeholder or configuration reading if env vars are not set
api_key = os.getenv('MEXC_API_KEY', '')
api_secret = os.getenv('MEXC_SECRET_KEY', '')
# If using a config file, you might do something like:
# from core.config import get_config
# config = get_config('config.yaml')
# mexc_config = config.get('mexc_trading', {})
# api_key = mexc_config.get('api_key', api_key)
# api_secret = mexc_config.get('api_secret', api_secret)
if not api_key or not api_secret:
logging.error("API keys are not set. Please set MEXC_API_KEY and MEXC_SECRET_KEY environment variables or configure config.yaml")
exit(1)
# Create interface with API credentials
mexc = MEXCInterface(
api_key='mx0aBYs33eIilxBWC5',
api_secret='45d0b3c26f2644f19bfb98b07741b2f5',
api_key=api_key,
api_secret=api_secret,
trading_mode='simulation'
)