DEV Community

Lucas Gragg
Lucas Gragg

Posted on

My 8-bot autonomous trading fleet (open source components)

I've been experimenting with autonomous trading bots for a while now, and I recently decided to take it to the next level by building an 8-bot fleet. The idea was to have each bot focus on a specific market or strategy, and then use a master script to manage and monitor them all. I started by setting up each bot as a separate Python process, using a combination of libraries like CCXT and Pandas to handle the trading logic.

Building the Bots

The first step was to define the trading logic for each bot. I used a simple moving average crossover strategy for a few of them, while others were based on more complex indicators like the RSI and Bollinger Bands. I also experimented with different market data feeds, including WebSocket connections to various exchanges. Here's an example of how I implemented the moving average crossover strategy in one of the bots:

import ccxt
import pandas as pd

exchange = ccxt.binance({
    'apiKey': 'YOUR_API_KEY',
    'apiSecret': 'YOUR_API_SECRET',
})

def fetch_data(symbol, timeframe):
    bars = exchange.fetch_ohlcv(symbol, timeframe=timeframe)
    df = pd.DataFrame(bars, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
    return df

def calculate_ma(df, short_window, long_window):
    df['short_ma'] = df['close'].rolling(window=short_window).mean()
    df['long_ma'] = df['close'].rolling(window=long_window).mean()
    return df

def check_crossover(df):
    if df['short_ma'].iloc[-1] > df['long_ma'].iloc[-1] and df['short_ma'].iloc[-2] < df['long_ma'].iloc[-2]:
        return True
    elif df['short_ma'].iloc[-1] < df['long_ma'].iloc[-1] and df['short_ma'].iloc[-2] > df['long_ma'].iloc[-2]:
        return False
    else:
        return None

symbol = 'BTC/USDT'
timeframe = '1m'
short_window = 50
long_window = 200

df = fetch_data(symbol, timeframe)
df = calculate_ma(df, short_window, long_window)
crossover = check_crossover(df)

if crossover:
    print('Buy signal')
elif not crossover:
    print('Sell signal')
Enter fullscreen mode Exit fullscreen mode

Managing the Fleet

Once I had all the bots up and running, I needed a way to manage and monitor them. I wrote a master script that would periodically check the status of each bot, restart any that had crashed, and send me notifications if anything went wrong. I also built a simple dashboard to display the performance of each bot, using a combination of metrics like profit/loss, drawdown, and Sharpe ratio.

Putting it all Together

I actually packaged this into a tool called Complete Trading Bot Suite if you want the full working version. It includes all the trading bots, a Telegram management agent, and a master dashboard to monitor everything from your phone. I've found it to be a huge time-saver, and it's allowed me to focus on refining my trading strategies rather than worrying about the underlying infrastructure. You can check it out at https://lukegraggster.gumroad.com/l/full-trading-suite?utm_source=devto&utm_medium=blog&utm_campaign=traffic_bot. I'm still actively developing and refining the suite, but it's already saved me a significant amount of time and hassle.

Top comments (0)