Guides
Run a Python crypto bot safely
Install Python 3.11 or later, create a virtual environment in the bot's folder, install the requirements (ccxt, pandas and python-dotenv by default), put your exchange API keys in a .env file on your own machine, and start the bot with python bot.py on the exchange's testnet or in paper mode, which is how every Edgoro bot is written to start. Stop it with Ctrl+C. Your keys never leave your machine: Edgoro never asks for them and doesn't run the bot.
On this page
Before you start
- The two files from the answer, in one folder: the
pythonblock saved asbot.py, and the requirements block saved asrequirements.txt. - An exchange account, and a testnet (or demo trading) account if the exchange has one. Testnet keys are separate from live keys.
- A terminal: Terminal on macOS, PowerShell or Command Prompt on Windows.
1. Check Python
The bots are written for Python 3.11 or later. Check the version:
python3 --versionOn Windows, use py --version. If Python is missing or older than 3.11, install a current version from python.org or your system's package manager; on Windows, the installer offers to add Python to PATH (the wording varies by version).
2. Create a virtual environment and install the libraries
A virtual environment keeps the bot's libraries apart from the rest of your system. In the bot's folder, on macOS or Linux:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtOn Windows, in PowerShell:
py -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txtIn Command Prompt, activate with .venv\Scripts\activate.bat instead. The requirements are ccxt, pandas and python-dotenv unless the bot needed more; indicators are computed with pandas, so there's no TA-Lib to install. Activate the environment again each time you open a new terminal, and leave it with deactivate.
3. Create the API key and the .env file
- On the exchange (or its testnet), create an API key with trading permission only: withdrawals disabled, and an IP whitelist if the exchange offers one. Some exchanges, such as OKX, also require a passphrase that you set when you create the key.
- Create a file named
.envnext tobot.pyand put the keys in it, under the names the bot reads (search foros.getenvinbot.py). For example:
API_KEY=paste-your-key-here
API_SECRET=paste-your-secret-hereThe bot loads this file with python-dotenv; the keys are never written in the code. Don't paste keys into the Edgoro chat or anywhere else, and if you use git, add .env to .gitignore. Edgoro never asks for your exchange keys.
4. Start on the testnet or in paper mode
Every bot is written with PAPER = True (orders are logged instead of sent) and calls exchange.set_sandbox_mode(True) when the exchange has a testnet. Check both near the top of bot.py, then start it:
python bot.pyWatch the log: the bot acts once per closed candle, so on a 1-hour timeframe nothing may happen for an hour. A testnet has its own order book and prices, which can differ a lot from the real market: use it to test the plumbing (orders, balances, precision, errors), not the strategy.
5. Stop it, and go live only on purpose
- Stop: press Ctrl+C. The bot is written to exit cleanly on it. Stopping the script doesn't cancel orders already on the exchange: check open orders and positions there.
- Go live: set
PAPER = Falseyourself, turn off sandbox mode and use live keys. Start with a small amount. - Keep it running: the bot runs only while that terminal and computer are on. For around-the-clock use, people run it on a VPS.
If it doesn't work
The syntax check under the answer ("Python syntax checked: 0 errors") means the file parses. It doesn't install anything or connect to the exchange, so these errors only show up when you run the bot:
| Error | Likely cause | Fix |
|---|---|---|
ModuleNotFoundError: No module named 'ccxt' | The virtual environment isn't active, or the requirements aren't installed | Activate .venv and run pip install -r requirements.txt |
python or python3 not found | Python missing from PATH | Install Python 3.11+, or use py on Windows |
ccxt.AuthenticationError | Wrong key or secret, a missing passphrase, or testnet keys on the live exchange (or the reverse) | Check .env, the variable names and the sandbox setting |
ccxt.PermissionDenied, or Binance's "Invalid API-key, IP, or permissions for action" | Trading not enabled on the key, or your IP isn't on its whitelist | Edit the key's permissions or IP list on the exchange |
ccxt.InsufficientFunds | Balance too low for the order and its fees, or funds in another wallet (spot or futures) | Move funds, or lower RISK_PCT |
ccxt.InvalidOrder | Order below the exchange's minimum amount or value | Use a larger balance or risk; the bot reads the market's limits |
ccxt.RateLimitExceeded or ccxt.DDoSProtection | Too many requests | Keep enableRateLimit on, poll less often, one bot per key |
ccxt.InvalidNonce, or Binance's "Timestamp for this request is outside of the recvWindow" | Your computer's clock has drifted | Turn on automatic time sync; for Binance, ccxt also accepts options: {"adjustForTimeDifference": True} |
ccxt.BadSymbol | The pair isn't listed on that exchange, or isn't written like BTC/USDT | Check the exchange's markets |
ccxt.NetworkError or ccxt.ExchangeNotAvailable | Connection drop or exchange maintenance | The bot retries on network errors; check the exchange's status page |
For anything else, paste the last lines of the traceback (never your keys) into the same Edgoro conversation. The troubleshooting page covers account issues too.
Related pages
- Python crypto bots: defaults and checks
- Python crypto bot with ccxt
- Crypto trading bot generator
- Crypto position calculator
- Trading fee calculator
- Security and data
Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.
Something wrong or missing? Email contact@edgoro.com