Multi-source AI trading platform with GOAP, SAFLA, and AgentDB vector learning
npm install -g @agentdb/neural-tradingnpx @agentdb/neural-trading init my-trading-bot
cd my-trading-bot
npx @agentdb/neural-trading start- GOAP Planning: Goal-Oriented Action Planning with A* search
- SAFLA Learning: Self-Aware Feedback Loop Algorithm for continuous improvement
- AgentDB Vector DB: SQLite-based vector database with 150x faster pattern search
- Multi-Source Data: Stock market, social sentiment, and prediction markets
- Swarm Coordination: Multi-agent orchestration with Claude Flow
- Real-time Streaming: Powered by Midstreamer
- Web UI: Beautiful React dashboard with real-time updates
- CLI Interface: Command-line tools for automation
βββββββββββββββββββββββββββββββββββββββββββ
β Client Layer β
β CLI β Web UI β REST API β WebSocket β
βββββββββββββββββ¬ββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββββββββββββ
β Coordination Layer β
β Swarm Coordinator β Task Orchestrator β
βββββββββββββββββ¬ββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββββββββββββ
β Agent Layer β
β GOAP β SAFLA β Strategies β Risk Mgmt β
βββββββββββββββββ¬ββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββββββββββββ
β Core Layer β
β Trading Engine β Portfolio β Executor β
βββββββββββββββββ¬ββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββββββββββββ
β Data Layer β
β AgentDB β Market Data β Sentiment β
βββββββββββββββββββββββββββββββββββββββββββ
# Start web server with dashboard
neural-trading start
# Opens at http://localhost:3000
# - Real-time dashboard
# - WebSocket updates
# - Configuration UI
# - Performance charts# Run headless trading bot
neural-trading cli --config config.yaml
# With specific symbols
neural-trading cli --symbols AAPL,GOOGL,TSLA
# Paper trading mode
neural-trading cli --mode paper --capital 100000# Deploy trading swarm with 5 agents
neural-trading swarm --agents 5 --strategy adaptive
# With specific topology
neural-trading swarm --topology hierarchical --agents 8# Use lean-agentic for resource efficiency
neural-trading lean --agents trading,analysis,risk
# With shared memory
neural-trading lean --coordination distributed --memory shared# Stream real-time data
neural-trading stream --sources alpaca,polygon,twitter
# With buffering
neural-trading stream --buffer 1000 --realtimeCreate config.yaml:
# Trading Configuration
mode: paper # paper | live | backtest
initial_capital: 100000
symbols:
- AAPL
- GOOGL
- MSFT
- NVDA
- TSLA
# Risk Management
risk_management:
max_position_size: 0.2 # 20% of portfolio
max_portfolio_risk: 0.5 # 50% of capital
stop_loss: 0.05 # 5% loss limit
take_profit: 0.15 # 15% profit target
max_drawdown: 0.25 # 25% drawdown limit
# GOAP Configuration
goap:
enabled: true
planning_horizon: 10
search_depth: 5
# SAFLA Learning
safla:
enabled: true
learning_rate: 0.01
exploration_rate: 0.1
discount_factor: 0.95
feedback_window: 20
adaptation_threshold: 0.7
# AgentDB Configuration
agentdb:
path: ./data/agentdb.db
quantization: uint8 # none | uint8 | uint4
enable_hnsw: true # 150x faster search
indexing:
M: 16
ef_construction: 200
ef_search: 100
# Data Feeds
data_feeds:
alpaca:
enabled: true
api_key: ${ALPACA_KEY}
api_secret: ${ALPACA_SECRET}
paper: true
sentiment:
enabled: true
twitter_token: ${TWITTER_TOKEN}
gemini_key: ${GEMINI_KEY}
polymarket:
enabled: false
# Swarm Coordination
swarm:
enabled: false
topology: hierarchical # mesh | hierarchical | star | ring
max_agents: 10
strategy: adaptive # balanced | specialized | adaptiveBuilt-in actions:
// Trading actions
- buy(symbol, quantity)
- sell(symbol, quantity)
- hold()
- rebalance()
// Analysis actions
- analyzeMarket()
- checkSentiment()
- evaluateRisk()
- updateStrategy()
// Learning actions
- recordPattern()
- adaptStrategy()
- optimizePortfolio()// src/custom-actions/my-action.ts
export class MyCustomAction implements GOAPAction {
name = 'myAction';
cost = 1;
preconditions = {
cash: (val) => val > 1000,
marketCondition: 'bullish'
};
effects = {
hasPosition: true,
cash: (val, state) => val - 1000
};
async execute(state: State): Promise<State> {
// Your logic here
return newState;
}
}The system continuously learns from trading outcomes:
// Automatic pattern learning
trader.on('trade', (trade) => {
// SAFLA automatically:
// 1. Records state before trade
// 2. Measures outcome (profit/loss)
// 3. Stores pattern in AgentDB
// 4. Adapts strategy
// 5. Updates exploration rate
});# View learning progress
neural-trading metrics --learning
Output:
Learning Rate: 0.01
Exploration Rate: 0.15
Success Rate: 67.3%
Avg Reward: +$234
Pattern Count: 1,247neural-trading/
βββ src/
β βββ core/ # Core trading engine
β β βββ TradingEngine.ts
β β βββ NeuralTrader.ts
β β βββ MemoryManager.ts
β βββ agents/ # GOAP & SAFLA agents
β β βββ GOAPPlanner.ts
β β βββ SAFLALearning.ts
β β βββ TradingAgent.ts
β βββ data/ # Data feeds
β β βββ DataFeedManager.ts
β β βββ AlpacaFeed.ts
β β βββ SentimentFeed.ts
β βββ strategies/ # Trading strategies
β β βββ MomentumStrategy.ts
β β βββ MeanReversionStrategy.ts
β βββ api/ # Express / NeuralTrading API
β βββ index.ts # Main entry point
βββ bin/
β βββ cli.js # CLI executable
βββ plans/ # Implementation plans
β βββ 00-MASTER-PLAN.md
β βββ 01-ARCHITECTURE.md
β βββ 02-CORE-SYSTEM.md
β βββ 03-AGENTS.md
β βββ 04-DATA-FEEDS.md
β βββ 05-STRATEGIES.md
β βββ 06-SWARM-COORDINATION.md
β βββ 07-TESTING.md
β βββ 08-DEPLOYMENT.md
β βββ 09-MODIFICATION-GUIDE.md
βββ config/ # Configuration templates
βββ docs/ # Documentation
βββ examples/ # Example configurations
βββ tests/ # Test suite
βββ app/ # Next.js frontend (Clerk + dashboard)
git clone https://github.com/ruvnet/agentdb-site.git
cd agentdb-site/neural-trading
npm install
npm run build
# Run locally
npm start
# Run in development mode
npm run dev# Run all tests
npm test
# Run with coverage
npm test -- --coverage
# Run specific test suite
npm test -- agents# Research and planning
npx claude-flow swarm "analyze trading opportunities" \
--strategy research \
--mode mesh \
--agents 6
# Development and implementation
npx claude-flow swarm "build trading strategies" \
--strategy development \
--mode hierarchical \
--agents 8
# Testing and validation
npx claude-flow swarm "test trading system" \
--strategy testing \
--mode star \
--agents 5Mesh (Peer-to-peer)
- Best for research and analysis
- All agents communicate directly
- Decentralized decision making
Hierarchical (Queen + Workers)
- Best for development
- Central coordinator delegates tasks
- Efficient for complex workflows
Star (Hub and Spoke)
- Best for testing
- Central hub manages all coordination
- Fast synchronization
Ring (Sequential)
- Best for pipelines
- Data flows sequentially
- Ordered processing
Access at http://localhost:3000 when running in web mode.
Features:
- Portfolio value chart
- Win/loss ratio
- Position tracking
- Learning metrics
- Activity log
- Performance stats
# Monitor trading in terminal
neural-trading monitor --interval 5s
# View swarm status
neural-trading swarm status --detailed
# Check agent metrics
neural-trading agents metrics --live
# Export metrics
neural-trading metrics export --format csv- Position size limits
- Stop-loss enforcement
- Portfolio risk caps
- Drawdown limits
- Emergency shutdown
- Paper trading mode (default)
# Store API keys securely
export ALPACA_KEY=your_key
export ALPACA_SECRET=your_secret
export TWITTER_TOKEN=your_token
export GEMINI_KEY=your_key
# Or use .env file
cp .env.example .env
# Edit .env with your keys- Architecture Guide
- Core System
- Agent Implementation
- Data Feeds
- Strategies
- Swarm Coordination
- Testing
- Deployment
- Modification Guide
- GitHub: https://github.com/ruvnet/agentdb-site
- Discord: https://discord.gg/agentdb
- Documentation: https://agentdb.ruv.io/docs
We welcome contributions! See CONTRIBUTING.md.
MIT License - see LICENSE
This software is for educational and research purposes. Trading involves substantial risk of loss. Always test thoroughly in paper trading mode before using real capital.
Version: 1.0.0 Author: @ruvnet Powered by: AgentDB, Claude Flow, Lean-Agentic, Midstreamer