DEV Community

crow
crow

Posted on

Building a Local AI Assistant on Linux — Recent Progress on Echo

Building a Local AI Assistant on Linux — Recent Progress on Echo

Introduction

Over the past few months, I’ve been working on Echo, a local AI assistant running on my Ubuntu machine. Echo is designed to assist me in trading financial markets using various machine learning models. Today, I’ll share my recent progress, challenges, and plans for the future.

Recent Progress

Trading Brain

In the latest update, I made significant progress in the trading brain module. I integrated the Relative Strength Index (RSI) and Moving Average (MA) analysis to detect trading signals. The core/trade_brain.py script now handles signal detection and executes trades based on these signals. Here’s a snippet of how the RSI and MA analysis are implemented:

import pandas as pd
from ta import RSIIndicator, SMAIndicator

def analyze_ticker(ticker_data):
    rsi = RSIIndicator(ticker_data['close'], window=14)
    ma = SMAIndicator(ticker_data['close'], window=50)

    rsi_indicator = rsi.rsi()
    ma_indicator = ma.sma_indicator()

    # Trading signals
    if rsi_indicator[-1] > 70 and ma_indicator[-1] > 100:
        return 'SELL'
    elif rsi_indicator[-1] < 30 and ma_indicator[-1] < 50:
        return 'BUY'
    else:
        return 'HOLD'
Enter fullscreen mode Exit fullscreen mode

Scheduling Trades

I’ve set up a systemd timer to run the trading script at specific times during the trading day. The echo-trader.timer file is configured to execute the echo-trader.service at 9:30 AM, 1:30 PM, and 3:30 PM on weekdays. Here’s the echo-trader.timer configuration:

[Timer]
OnCalendar=*-*-* 09:30:00,13:30:00,15:30:00
Persistent=true
Enter fullscreen mode Exit fullscreen mode

And the echo-trader.service file:

[Unit]
Description=Echo Trader Service
After=network.target

[Service]
ExecStart=/usr/local/bin/python3 /path/to/trade_brain.py
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

Alpaca Integration

I successfully connected my Alpaca account to the trading script, and the first paper trade was executed. The account connected with the paper trading API credentials (PA34X7SLPSXZ, $100k paper). The trade was a buy order for 7 SPY ETF shares at $689.30. Here’s the Python code for the buy order:

from alpaca_trade_api import REST

api = REST('YOUR_API_KEY', 'YOUR_SECRET_KEY', base_url='https://paper-api.alpaca.markets')

response = api.submit_order(
    symbol='SPY',
    qty=7,
    side='buy',
    type='market',
    time_in_force='gtc'
)
print(response)
Enter fullscreen mode Exit fullscreen mode

Known Issues

There are still a few issues that need to be addressed. The first is the handling of crypto symbols. The Alpaca API requires BTCUSD and ETHUSD formats for crypto symbols, which is different from the standard BTC and ETH. I fixed this by updating the trading script to use the correct symbol formats. The second issue is the vastai CLI, which is broken due to conflicts with urllib3 and python-dateutil from the Alpaca installation. I’m currently working on a virtual environment solution to resolve this conflict.

Next Steps

  • Fix Crypto Symbols: Ensure all crypto trades use the correct symbol formats (BTCUSD, ETHUSD).
  • Wire Trade Outcomes into Regret Index Scoring: Integrate the trading outcomes into the regret index scoring mechanism to improve trading decisions.
  • Add Position Exit Logic: Implement take profit and stop loss mechanisms to manage trades more effectively.
  • Fix vastai CLI Dependency Conflicts: Use a virtual environment to resolve the dependency conflicts.

Recent Session

Trading Brain Session Complete

On March 25, I completed the trading brain session. The crypto symbol issue was resolved, and the IEX feed was configured to work after hours and with the free tier. The analysis loop ran clean, and the echo-trader.timer was set to fire tomorrow at 9:30 AM CDT. The vast.ai upload speed issue persists, but I’m waiting on automated rechecks.

Auto-Act Cycle

For the past few days, the auto-act cycle evaluated one suggestion but acted on none. The analytics handler was added to fix false -1 scores, and the regret index was reset. The publish_tuesday.sh script was also fixed to use the correct file, and the echo-publish-weekly.service was updated to use the correct file as well.

Conclusion

Echo is making steady progress, and I’m excited about the future. The trading brain is functioning well, and the scheduling and Alpaca integration are in place. I’m looking forward to adding more features and improving the system’s decision-making capabilities. If you’re interested in building your own local AI assistant, stay tuned for more updates!

Top comments (0)