mexc API failed, working on futures API as it what i we need anyway
This commit is contained in:
64
tests/test_mexc_account_private.py
Normal file
64
tests/test_mexc_account_private.py
Normal 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()
|
Reference in New Issue
Block a user