Skip to content

ArthurOnWeb/lighter-grid-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lighter Grid Bot Trading Application

This project is a grid bot trading application developed for Lighter.xyz using the Lighter Python SDK. The application implements a grid trading strategy that allows for automated trading based on predefined parameters.

Features

  • Grid Trading Strategy: Automatically places buy and sell orders at calculated price levels
  • Real-time Market Data: Fetches order book data from Lighter.xyz
  • Configurable Parameters: Easy configuration of grid size, order size, trading pair, etc.
  • Logging: Comprehensive logging for monitoring and debugging
  • Error Handling: Robust error handling and recovery mechanisms

Project Structure

lighter-grid-bot
├── src
│   ├── main.py                # Entry point of the application
│   ├── bot                    # Contains bot-related logic
│   │   ├── __init__.py
│   │   ├── grid_bot.py        # Implements the GridBot class
│   │   └── strategy.py        # Defines trading strategies
│   ├── lighter                # Contains Lighter SDK interactions
│   │   ├── __init__.py
│   │   ├── client.py          # Client class for Lighter SDK
│   │   └── models.py          # Data models for trading actions
│   ├── utils                  # Utility functions and configurations
│   │   ├── __init__.py
│   │   ├── config.py          # Configuration handling
│   │   └── logger.py          # Logging setup
│   └── tests                  # Unit tests for the application
│       ├── __init__.py
│       ├── test_bot.py        # Tests for the GridBot class
│       └── test_client.py     # Tests for the Client class
├── requirements.txt           # Project dependencies
├── config.yaml                # Configuration settings for the grid bot
├── .env.example               # Example environment variables
├── .gitignore                 # Files to ignore in version control
└── README.md                  # Project documentation

Setup Instructions

1. Clone and Setup Environment

git clone <repository-url>
cd lighter-grid-bot

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows use `.venv\\Scripts\\activate`

# Install dependencies
pip install -r requirements.txt

2. Configure the Application

Update config.yaml

Edit config.yaml with your trading parameters:

trading:
  enabled: true
  grid_size: 10              # Number of grid levels
  take_profit: 0.02          # 2% take profit
  stop_loss: 0.01            # 1% stop loss
  api_key: "YOUR_ACTUAL_API_KEY"
  api_secret: "YOUR_ACTUAL_API_SECRET"
  trading_pair: "BTC/USD"    # Trading pair
  order_size: 0.01           # Order size in base currency
  max_orders: 5              # Maximum active orders

logging:
  level: "INFO"
  file: "logs/trading.log"

database:
  uri: "sqlite:///trading.db"

Get API Credentials

  1. Create an account on Lighter.xyz
  2. Generate API keys from your account settings
  3. Copy .env.example to .env and update with your credentials:
    cp .env.example .env
  4. Edit .env with your actual API credentials:
    PUBLIC_KEY=your_actual_public_key
    PRIVATE_KEY=your_actual_private_key
    KEY_ID=your_key_id
    BASE_URL=mainnet.zklighter.elliot.ai

Configuration

The bot uses two configuration files:

  1. .env - For sensitive API credentials (gitignored)

    • PUBLIC_KEY: Your Lighter API public key
    • PRIVATE_KEY: Your Lighter API private key
    • KEY_ID: Your API key ID
    • BASE_URL: Lighter API endpoint (mainnet.zklighter.elliot.ai)
  2. config.yaml - For trading parameters

    • market_id: Market to trade on
    • grid_levels: Number of grid levels
    • grid_spacing: Price spacing between grid levels
    • order_size: Size of each grid order
    • min_price: Minimum price for grid
    • max_price: Maximum price for grid

Example config.yaml:

market_id: "ETH-USDC"
grid_levels: 10
grid_spacing: 50.0
order_size: 0.1
min_price: 2500.0
max_price: 3500.0

3. Test the Setup

Run the test script to verify everything works:

python test_bot.py

4. Start Trading

python src/main.py

How It Works

Grid Trading Strategy

The grid bot works by:

  1. Calculating Grid Levels: Based on current market price and configured grid size
  2. Placing Orders: Buy orders below current price, sell orders above current price
  3. Managing Orders: Continuously monitoring and adjusting orders as market moves
  4. Profit Taking: Closing positions when profit targets are reached

Example Scenario

  • Current BTC price: $50,000
  • Grid size: 10 levels
  • Price step: 1% ($500)
  • Buy orders at: $49,500, $49,000, $48,500, etc.
  • Sell orders at: $50,500, $51,000, $51,500, etc.

Configuration Options

Parameter Description Default
grid_size Number of grid levels 10
take_profit Profit target percentage 0.02 (2%)
stop_loss Stop loss percentage 0.01 (1%)
trading_pair Trading pair (e.g., BTC/USD) BTC/USD
order_size Size of each order 0.01
max_orders Maximum active orders 5

Risk Management

  • Start with small order sizes
  • Use stop-loss to limit potential losses
  • Monitor the bot regularly, especially during high volatility
  • Test with paper trading/simulated environment first

Troubleshooting

Common Issues

  1. API Connection Issues: Check your API credentials and internet connection
  2. Order Placement Errors: Verify you have sufficient balance
  3. Market Data Errors: Check if the trading pair is available on Lighter

Logs

Check the log file for detailed information:

tail -f logs/trading.log

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Disclaimer

This software is for educational purposes only. Use at your own risk. Cryptocurrency trading involves significant risk and may not be suitable for all investors. Always test with small amounts first and never invest more than you can afford to lose.

Usage

  1. Setup Environment:

    cp .env.example .env
    # Edit .env with your actual API credentials
  2. Configure Trading Parameters:

    # Edit config.yaml with your trading strategy
    nano config.yaml
  3. Run the Bot:

    python src/main.py

The bot will:

  • Load configuration from .env and config.yaml
  • Connect to Lighter API
  • Place grid orders based on your parameters
  • Monitor and manage orders automatically

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages