The Lightning Trading Bot is a high-performance Bitcoin Futures trading bot built in Rust, designed to interact with the LN Markets API. This bot leverages various market indicators such as Moving Averages (MA), Exponential Moving Averages (EMA), Bollinger Bands (BB), Relative Strength Index (RSI), and Average True Range (ATR) to analyze and execute trades on Bitcoin Futures markets.
Currently under active development, this bot is a proof-of-concept and is not yet suitable for production environments. It is intended for educational and experimental purposes only.
- 📈 Real-Time Market Data: Connects to LN Markets WebSocket to stream live market prices.
- ⚙️ Customizable Trading Strategy: Implements indicators like MA, EMA, BB, RSI, and ATR to calculate trading signals.
- 🛠️ Stop-Loss and Take-Profit Calculation: Dynamically calculates stop-loss and take-profit levels for each trade based on ATR and other parameters.
- 🧮 Trade Quantity Calculation: Automatically determines the optimal quantity for trades, taking account balance, leverage, and risk management into consideration.
- 🔄 Signal Processing: Evaluates buy, sell, hold, and strong buy/strong sell signals using a combination of price indicators.
- ⚖️ Configurable Parameters: Offers flexibility to adjust trading parameters, including technical indicators, leverage, stop-loss, take-profit settings, etc.
- 🚀 Real-Time Trade Execution: Executes trades based on generated signals using LN Markets API.
- 🔄 Multi-Tasking: Uses Tokio's async runtime to handle multiple tasks concurrently, including price data updates, indicator calculations, signal processing, and trade execution.
- 🦀 Rust: Install Rust if you haven’t already. Follow the instructions here.
- ⚙️ Cargo: Cargo is the package manager and build tool for Rust. It is installed automatically with Rust.
-
Clone the repository:
git clone https://github.com/RayRizzling/lightning-trading-bot.git cd lightning-trading-bot -
Set up your environment:
Create a
.envfile in the root directory of the project with the following content:# Account API SECRETS LN_API_KEY=<> LN_API_SECRET=<> LN_API_PASSPHRASE=<> # REST API URL (V2) LN_MAINNET_API_URL=https://api.lnmarkets.com/v2 LN_TESTNET_API_URL=https://api.testnet.lnmarkets.com/v2 # WEBSOCKET API ENDPOINTS LN_MAINNET_API_WS_ENDPOINT=wss://api.lnmarkets.com LN_TESTNET_API_WS_ENDPOINT=wss://api.testnet.lnmarkets.com # METHOD FOR WEBSOCKET PRICE FEED LN_PRICE_METHOD=v1/public/subscribe
-
Install dependencies:
Run the following command to install dependencies:
cargo build --release
-
Run the bot:
After building the project, you can start the bot with:
cargo run
The bot will stream real-time price data, process signals, and execute trades based on the configured strategy.
The bot's behavior can be customized by modifying the config.rs file. You can set various parameters such as:
- ⏱️ Trade Interval: Interval for fetching market data and calculating indicators.
- 📊 Technical Indicators: Set the periods for MA, EMA, BB, RSI, and ATR.
- ⚙️ Other Settings: Configure other important parameters, including leverage, risk per trade, and risk-to-reward ratio.
Important: OHLC history data and live spot prices are used for signal derivation. The bot continuously updates parameters in real-time.
pub struct BotConfig {
pub api_url: String, // URL for the API endpoint (loaded from environment variables)
pub range: String, // Time range for data (e.g., 1 minute, 1 hour)
pub from: Option<i64>, // Starting timestamp for data fetching (optional)
pub to: Option<i64>, // Ending timestamp for data fetching (optional)
pub formatted_from: String, // Formatted 'from' timestamp for API calls
pub formatted_to: String, // Formatted 'to' timestamp for API calls
pub ma_period: usize, // Period for the moving average (MA) calculation
pub ema_period: usize, // Period for the exponential moving average (EMA) calculation
pub bb_period: usize, // Period for the Bollinger Bands calculation
pub bb_std_dev_multiplier: f64, // Multiplier for standard deviation in Bollinger Bands
pub rsi_period: usize, // Period for the relative strength index (RSI) calculation
pub atr_period: usize, // Period for the average true range (ATR) calculation
pub trade_type: String, // Defines the trade type: "running", "open", or "closed"
//price and index data not integrated in trade execution and signal derivation in v0.1.0
pub include_price_data: bool, // Whether to include price data (might slow down the bot)
pub include_index_data: bool, // Whether to include index data (might slow down the bot)
//
pub interval: Duration, // The interval for data fetching (calculated based on range)
pub risk_per_trade_percent: f64, // Risk handling for trade quantity
pub risk_to_reward_ratio: f64, // Risk handling for takeprofit
pub risk_to_loss_ratio: f64, // Risk handling for stoploss
pub trade_gap_seconds: u64 // Min gap bewtween opening two trades in seconds
}Modify these values in the BotConfig struct to adjust the bot’s trading parameters.
This bot is currently under active development. The core trading logic, including trade execution, stop-loss/take-profit calculations, and quantity optimization, is operational. Future improvements include enhanced error handling, better configuration options, and more robust trade management.
🚨 Disclaimer: This bot is not yet refined or suitable for production use. It is a raw development version, and you should use it at your own risk, especially with real funds.
🤝 Contributions are welcome! If you would like to improve the bot or add new features, please follow the steps below:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature). - Make your changes and commit them (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature/your-feature). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
LN Markets API: The bot integrates with the LN Markets API for fetching price data and executing trades. For more information, please refer to the official documentation. Rust Community: Special thanks to the Rust community for providing the tools and libraries that make this bot possible.