A Python-based automated grid trading bot for Bybit cryptocurrency exchange with real-time web dashboard. Supports both spot and futures trading with customizable grid parameters.
- Grid Trading Strategy: Automatically places buy and sell orders at predetermined price levels
- Spot & Futures Support: Trade on both spot and futures (perpetual) markets
- Auto-Rebalancing: Automatically rebalances grid when orders are filled
- Risk Management: Configurable grid levels and order sizes
- Testnet Support: Test your strategies safely on Bybit testnet
- Detailed Logging: Comprehensive logging to both console and file
- Real-Time Monitoring: Live WebSocket updates every 2 seconds
- Performance Charts: Interactive charts showing cumulative profits
- Grid Visualization: Visual representation of all grid levels
- Trade History: Complete log of all executed trades
- Order Tracking: Real-time active order monitoring
- Beautiful UI: Modern dark-themed responsive interface
Grid trading is a strategy that profits from market volatility:
- The bot divides a price range into equal levels (grid)
- Places buy orders below the current price
- Places sell orders above the current price
- When a buy order fills, it places a sell order at the next grid level above
- When a sell order fills, it places a buy order at the next grid level below
- Profits are made from the price spread between grid levels
- Python 3.8 or higher
- Bybit account with API credentials
- pip (Python package manager)
-
Clone or download this repository
-
Install dependencies:
pip install -r requirements.txt
-
Create your configuration file:
cp .env.example .env
-
Edit
.envfile with your settings:# Bybit API Credentials (get from https://www.bybit.com/app/user/api-management) BYBIT_API_KEY=your_api_key_here BYBIT_API_SECRET=your_api_secret_here # Use testnet for testing (recommended for first time) BYBIT_TESTNET=true # Trading Configuration TRADING_SYMBOL=BTCUSDT GRID_LEVELS=10 GRID_LOWER_PRICE=40000 GRID_UPPER_PRICE=50000 ORDER_AMOUNT=0.001 MARKET_TYPE=spot # 'spot' or 'linear' (futures)
- BYBIT_API_KEY: Your Bybit API key
- BYBIT_API_SECRET: Your Bybit API secret
- TRADING_SYMBOL: Trading pair (e.g., BTCUSDT, ETHUSDT)
- GRID_LEVELS: Number of grid levels (min: 2, recommended: 10-20)
- GRID_LOWER_PRICE: Lower bound of the grid
- GRID_UPPER_PRICE: Upper bound of the grid
- ORDER_AMOUNT: Amount per order (in base currency)
- BYBIT_TESTNET: Use testnet (true) or mainnet (false)
- MARKET_TYPE: 'spot' for spot trading, 'linear' for futures
- CHECK_INTERVAL: How often to check for filled orders (seconds, default: 10)
- MAX_OPEN_ORDERS: Maximum number of open orders (default: 20)
- Log in to your Bybit account
- Go to API Management: https://www.bybit.com/app/user/api-management
- Create a new API key
- Important: Enable the following permissions:
- For Spot trading: "Spot" read and write
- For Futures trading: "Contract" read and write
- Security: Use IP whitelist for added security
- Save your API key and secret (you won't be able to see the secret again)
For testing, create testnet credentials:
- Go to testnet: https://testnet.bybit.com/
- Register/login to testnet account
- Get testnet API credentials from API Management
- Fund your testnet account with fake USDT
python main.pyThe bot will run in your terminal with console logging.
Run all three components:
Terminal 1 - Trading Bot:
python main.pyTerminal 2 - API Server:
python api_server.pyTerminal 3 - Web Dashboard:
cd frontend
npm install # First time only
npm run devThen open http://localhost:3000 in your browser to see the live dashboard!
π Detailed web setup guide: See WEB_SETUP.md
Press Ctrl+C in each terminal to stop. All open orders will be cancelled automatically.
The bot will:
- Display configuration on startup
- Show current price and verify connection
- Log all order placements and fills
- Display periodic status updates
- Save detailed logs to timestamped log files
GRID_LEVELS=20
GRID_LOWER_PRICE=30000
GRID_UPPER_PRICE=70000
ORDER_AMOUNT=0.001GRID_LEVELS=5
GRID_LOWER_PRICE=45000
GRID_UPPER_PRICE=48000
ORDER_AMOUNT=0.01- Start with Testnet: Always test your configuration on testnet first
- Use Small Amounts: Start with small order amounts
- Monitor Regularly: Check the bot's performance regularly
- Price Range: Ensure the grid range matches current market conditions
- Funding: Ensure you have sufficient balance for all grid orders
- Market Volatility: Grid trading works best in ranging markets
- API Security: Keep your API keys secure, never share them
- Check your API credentials
- Verify API permissions (Spot/Contract read/write)
- Check if you're using the correct testnet/mainnet setting
- Adjust GRID_LOWER_PRICE and GRID_UPPER_PRICE to include current price
- Or wait for price to return to grid range
- Ensure you have enough USDT/base currency
- Calculate required balance: GRID_LEVELS Γ ORDER_AMOUNT Γ price
- Check if grid range is too wide
- Verify market has enough volatility
- Ensure order amounts meet minimum requirements
greedbot/
βββ main.py # Main bot entry point
βββ api_server.py # FastAPI backend server
βββ database.py # SQLite database manager
βββ bybit_client.py # Bybit API wrapper
βββ grid_strategy.py # Grid trading logic
βββ config.py # Configuration management
βββ logger.py # Logging setup
βββ check_balance.py # Utility to check API connection
βββ requirements.txt # Python dependencies
βββ .env # Your configuration (not in git)
βββ .env.example # Example configuration
βββ README.md # This file
βββ WEB_SETUP.md # Web interface setup guide
βββ QUICKSTART.md # 5-minute quick start
βββ FEATURES.md # Complete feature list
βββ frontend/ # React web dashboard
βββ src/
β βββ App.jsx
β βββ components/
β β βββ Dashboard.jsx
β β βββ TradesTable.jsx
β β βββ OrdersTable.jsx
β β βββ PerformanceChart.jsx
β β βββ GridVisualization.jsx
β βββ App.css
βββ package.json
βββ vite.config.js
You can run multiple instances with different configurations:
# Terminal 1
python main.py
# Terminal 2 - edit .env with different symbol first
python main.pyThe code is modular - you can modify grid_strategy.py to implement:
- Different grid spacing (arithmetic vs geometric)
- Dynamic grid adjustment
- Custom rebalancing logic
- Integration with technical indicators
This bot is for educational purposes. Cryptocurrency trading carries risk of loss. Always:
- Test thoroughly on testnet
- Start with small amounts
- Never invest more than you can afford to lose
- Understand the strategy before using
- Monitor your bot regularly
The developers are not responsible for any financial losses incurred while using this software.
MIT License - feel free to modify and use as you wish.
For issues or questions:
- Check the troubleshooting section above
- Review Bybit API documentation: https://bybit-exchange.github.io/docs/
- Test on testnet first
- Initial release
- Grid trading strategy for spot and futures
- Bybit API integration
- Configurable grid parameters
- Auto-rebalancing
- Testnet support