API Keys Setup
This page explains how to configure credentials for authenticated spot and futures requests.
Create API Credentials
Create API credentials from the MEXC API management page:
https://www.mexc.com/user/openapi
Before using them in production:
- Enable only the permissions you actually need.
- Restrict IPs when the provider supports it.
- Keep trading and withdrawal permissions separate when possible.
Environment Variables
The recommended setup is environment variables:
Those are the only credential variables used by MEXC.new(), Spot.new(), and Futures.new().
MEXC uses access key + secret key only. There is no passphrase in the current client model.
Direct Usage
You can also pass credentials directly:
from mexc import MEXC
async with MEXC.new(
api_key="your_access_key",
api_secret="your_secret_key",
) as client:
account = await client.spot.account.info()
print(account['accountType'])
Security Notes
- Never commit credentials to git, issue trackers, logs, notebooks, or shared terminals.
- Prefer read-only keys for development and documentation examples.
- Use separate keys for production automation, manual trading, and local experiments.
- Keep withdrawal permission disabled unless the exact workflow requires it.
- Keep futures trading permission separate from spot read access where your account setup allows it.
- Restrict production keys by IP before enabling trading permission.
- Rotate credentials after any suspected leak or after using them on an untrusted machine.
- Keys without an IP whitelist expire after 90 days on MEXC.
Troubleshooting
If authenticated requests fail:
- Confirm the key has the required permissions.
- Confirm your environment variables are loaded.
- Confirm your IP whitelist configuration on the MEXC side.
- Check Error Handling for the client error model.