Error Handling
MEXC distinguishes transport failures, authentication failures, validation failures, and API-level failures.
Common Error Categories
Error: base package exception.NetworkError: connection failures, timeouts, and transport errors.AuthError: missing credentials, invalid signatures, or rejected authentication.BadRequest: invalid request parameters or malformed payloads rejected locally or remotely.RateLimited: provider-side rate limiting.ApiError: the remote API returned an error payload or unsuccessful response.ValidationError: the response shape did not match the expected schema.LogicError: incorrect local usage of the client.
Recommended Pattern
from mexc import ApiError, AuthError, NetworkError, RateLimited, ValidationError
from mexc import MEXC
async with MEXC.new() as client:
try:
positions = await client.futures.position.open()
except ValidationError:
...
except AuthError:
...
except RateLimited:
...
except ApiError:
...
except NetworkError:
...
Operational Guidance
- Retry transient network failures carefully.
- Do not blindly retry authentication failures.
- Back off on rate limits according to the provider's documented policy.
- Log validation failures because they often signal upstream API changes.
- Inspect the original request context when debugging inconsistent symbol or timestamp errors.