If you're new to programmatic trading on LMEX, this tutorial gets you from "nothing installed" to "placed your first authenticated order" in under 30 minutes. It assumes basic Python familiarity but no prior trading API experience.
Log into your LMEX account, navigate to Account → API Management, and create a new key.
A few decisions to make at this step:
**Permissions:** Start with Read-only. Don't enable Trading until you've verified the read-only access works. Enabling Wallet permission lets the bot check balances; that's needed for almost any strategy.
**IP restrictions:** If you're running from a fixed server, restrict the key to that IP. If you're testing locally, you can skip this initially but should enable it before going live.
**Withdrawal permission:** Never enable this for a trading bot. There's no legitimate reason a trading bot needs to withdraw funds, and enabling it dramatically increases the impact of a compromised key.
Save both the API key and secret somewhere safe. The secret is shown only once.
Use a fresh Python environment to avoid version conflicts:
CCXT is the standard library for connecting to crypto exchanges. As of this year, LMEX is fully supported in CCXT.
Create a `.env` file in your project folder:
Add `.env` to your `.gitignore` immediately. Credentials in source control is the most common way bots get hacked.
Then load them in Python:
A minimal connection test:
If the first line prints a price, you're connected. If the second prints your balance, authentication works.
Common errors at this step:
The most common operations:
These methods work without API keys (public endpoints) so they're a good place to verify before doing anything authenticated.
Once read-only access works, enable Trading permission on your API key and try a small order:
If this works end-to-end, you can place, query, and cancel orders. That's the foundation of every trading strategy.
The complete toolkit:
These cover 90% of what most strategies need.
**Symbol format.** LMEX uses `BTC-PERP` (with hyphen). Some exchanges use `BTC/USDT:USDT` (CCXT's unified format). For LMEX, both work but `BTC-PERP` is canonical.
Quantity precision. LMEX has minimum order sizes and precision limits per symbol. Use `exchange.amount_to_precision('BTC-PERP', 0.0123456)` to round correctly.
**Price precision.** Same — `exchange.price_to_precision('BTC-PERP', 60123.456)`.
**Rate limits.** LMEX limits API calls per second/minute. Use `enableRateLimit: True` in your config; CCXT will automatically throttle.
**Testnet vs mainnet.** Add `'options': {'testnet': True}` to test with testnet. Switch to `False` for live trading.
After this tutorial, you have working connection code. The next steps:
1. Run your read-only code for a few days to make sure it stays connected
2. Plan a strategy and write its logic in a separate file
3. Test the strategy on testnet for at least 2 weeks
4. Add risk management (see our portfolio risk article)
5. Go live with the smallest possible size
6. Scale up only after weeks of stable operation
The rush to "deploy live with real money" is the #1 cause of bot failures. Take your time at each step.
Q: Should I use the LMEX native Python SDK or CCXT?
CCXT is easier to learn and supports more strategies portable across exchanges. The native SDK gives slightly better feature coverage. Start with CCXT.
Q: How do I get historical data for backtesting?
`exchange.fetch_ohlcv('BTC-PERP', '1h', limit=1000)` gets the last 1000 hourly candles. For longer histories, paginate using the `since` parameter. For very long histories, consider third-party data providers.
Q: What rate limit should I worry about?
LMEX allows several hundred requests per second per IP. Most retail bots stay well under this. If you're hitting limits, you're probably polling too aggressively — use WebSocket for streaming data instead.
Q: How do I keep my API keys safe?
Use environment variables or a secrets manager. Never put them in code. Never commit them. Restrict by IP. Use Read-only or Wallet+Trading only — never enable Withdrawal. Rotate keys every few months.