Files
gogo2/tests/test_mexc_account_privte.py

59 lines
2.0 KiB
Python

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=api_key,
api_secret=api_secret,
trading_mode='simulation'
)
print('MEXC Interface created successfully')
# Test signature generation
import time
timestamp = int(time.time() * 1000)
test_params = 'quantity=1&price=11&symbol=BTCUSDT&side=BUY&type=LIMIT&timestamp=' + str(timestamp)
signature = mexc._generate_signature(timestamp, test_params)
print(f'Generated signature: {signature}')
# Test account info
print('Testing account info...')
account_info = mexc.get_account_info()
print(f'Account info result: {account_info}')
# Test ticker data
print('Testing ticker data...')
ticker = mexc.get_ticker('ETH/USDT')
print(f'ETH/USDT ticker: {ticker}')
# Test balance retrieval
print('Testing balance retrieval...')
usdt_balance = mexc.get_balance('USDT')
print(f'USDT balance: {usdt_balance}')
# Test a small order placement (simulation mode)
print('Testing order placement in simulation mode...')
order_result = mexc.place_order('ETH/USDT', 'buy', 'market', 0.001)
print(f'Order result: {order_result}')