Skip to content

Commit 06379cf

Browse files
committed
Initial commit of RustForge terminal and AI components
0 parents  commit 06379cf

73 files changed

Lines changed: 3120 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cargo/config.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[build]
2+
rustflags = ["-C", "target-cpu=native"]
3+
4+
[profile.release]
5+
opt-level = 3
6+
lto = "fat"
7+
codegen-units = 1
8+
panic = "abort"
9+
debug = false
10+
incremental = false
11+
overflow-checks = false

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
on: [push, pull_request]
3+
4+
env:
5+
CARGO_TERM_COLOR: always
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Install Rust
13+
uses: dtolnay/rust-toolchain@stable
14+
with:
15+
components: clippy, rustfmt
16+
- name: Cache cargo
17+
uses: actions/cache@v4
18+
with:
19+
path: |
20+
~/.cargo/registry
21+
~/.cargo/git
22+
target
23+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
24+
- name: Cargo fmt
25+
run: cargo fmt --all -- --check
26+
- name: Clippy
27+
run: cargo clippy --all-targets --all-features -- -D warnings
28+
- name: Build
29+
run: cargo build --workspace --release
30+
- name: Run tests
31+
run: cargo test --workspace

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/target
2+
/C:\rust-target
3+
**/*.rs.bk
4+
.env
5+
.idea
6+
.vscode
7+
/Cargo.lock

BUILD_INSTRUCTIONS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 🛑 CRITICAL: Windows SDK Missing
2+
3+
The project cannot build because the **Windows 10 SDK** (or Windows 11 SDK) is missing from your Visual Studio installation. This component contains `kernel32.lib`, which is required for linking.
4+
5+
## 🛠️ Step-by-Step Fix
6+
7+
1. **Open Visual Studio Installer** (search in Start Menu).
8+
2. Click **"Modify"** next to "Visual Studio Build Tools 2022".
9+
3. Go to the **"Individual components"** tab at the top.
10+
4. Search for **"Windows 10 SDK"** (e.g. `Windows 10 SDK (10.0.19041.0)`).
11+
5. **Check the box** next to it.
12+
6. Click **"Modify"** in the bottom right corner.
13+
7. **Restart your computer** after installation.
14+
15+
## 🏃 Run the Bot
16+
After fixing the SDK, simply run:
17+
```powershell
18+
run_bot.bat
19+
```

Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"crates/common",
5+
"crates/ingestion",
6+
"crates/parser",
7+
"crates/feature",
8+
"crates/strategy",
9+
"crates/model",
10+
"crates/risk",
11+
"crates/executor",
12+
"crates/signer",
13+
"crates/relay",
14+
"crates/daemon",
15+
"crates/event_bus",
16+
"crates/cli",
17+
"crates/tui",
18+
"crates/web",
19+
"crates/tests",
20+
"crates/persistence",
21+
"crates/web-dashboard",
22+
"crates/ai",
23+
"crates/dashboard"
24+
]
25+
26+
[profile.release]
27+
opt-level = 3
28+
lto = true
29+
codegen-units = 1
30+
panic = "abort"
31+
strip = true

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# RustForge Terminal (rust-finance)
2+
3+
<div align="center">
4+
<img src="https://img.shields.io/badge/Rust-000000?style=for-the-badge&logo=rust&logoColor=white" alt="Rust" />
5+
<img src="https://img.shields.io/badge/Tokio-1A2421?style=for-the-badge&logo=Rust&logoColor=white" alt="Tokio" />
6+
<img src="https://img.shields.io/badge/Solana-14F195?style=for-the-badge&logo=Solana&logoColor=white" alt="Solana" />
7+
<img src="https://img.shields.io/badge/Anthropic-FF7F50?style=for-the-badge&logo=Anthropic&logoColor=white" alt="Anthropic" />
8+
<img src="https://img.shields.io/badge/Ratatui-0A0C0F?style=for-the-badge&logo=Linux&logoColor=white" alt="Ratatui" />
9+
<img src="https://img.shields.io/badge/WebSocket-010101?style=for-the-badge&logo=socket.io&logoColor=white" alt="WebSocket" />
10+
</div>
11+
12+
A high-performance, low-latency trading terminal and daemon built completely in Rust. Engineered for direct connection to market data streams (Finnhub, Alpaca), real-time AI signal analysis, and Solana-based trade execution.
13+
14+
## System Architecture
15+
16+
```mermaid
17+
graph TD;
18+
subgraph External Sources
19+
NYSE[Market Exchanges]
20+
NASDAQ[Market Exchanges]
21+
Crypto[Crypto WSS]
22+
end
23+
24+
subgraph Data Pipeline
25+
Ingestion(Ingestion Crate)
26+
Normalizer(Normalizer)
27+
Ingestion --> Normalizer
28+
end
29+
30+
NYSE --> Ingestion
31+
NASDAQ --> Ingestion
32+
Crypto --> Ingestion
33+
34+
subgraph Core Infrastructure
35+
EventBus[TCP Event Bus]
36+
Daemon((Core Daemon Engine))
37+
DB[(Persistence Layer)]
38+
39+
Normalizer -- Market Events --> EventBus
40+
EventBus <--> Daemon
41+
Daemon --> DB
42+
end
43+
44+
subgraph Intelligence & Execution
45+
AI_Dexter(Dexter Analyst AI)
46+
AI_Miro(MiroFish Swarm AI)
47+
AnthropicAPI[Anthropic Claude 3.5]
48+
49+
Relay(Network Relay & Node Selector)
50+
RPC[Solana Mainnet RPC Nodes]
51+
52+
Daemon <--> AI_Dexter
53+
Daemon <--> AI_Miro
54+
AI_Dexter <--> AnthropicAPI
55+
AI_Miro <--> AnthropicAPI
56+
57+
Daemon --> Relay
58+
Relay --> RPC
59+
end
60+
61+
subgraph Interfaces
62+
TUI[Terminal User Interface - Ratatui]
63+
Web[Web Dashboard]
64+
65+
EventBus --> TUI
66+
EventBus --> Web
67+
end
68+
```
69+
70+
## Workspace Crates
71+
72+
The workspace is organized into discrete, highly decoupled crates:
73+
74+
* **`daemon`**: The central orchestrator. It manages the Tokio asynchronous runtime, spawns the EventBus, starts ingestion pipelines, controls the AI analyst intervals, and routes signals to the execution engine.
75+
* **`tui`**: A standalone Ratatui application featuring an advanced 3-column layout mimicking professional desktop terminals. It subscribes to the `event_bus` to render watchlists, deep order books, high-res braille charts, and live AI intelligence.
76+
* **`ai`**: Contains `DexterAnalyst` and `MiroFishSimulator`. Interacts natively with Anthropic APIs to detect catalysts, perform fundamental analysis, and run swarm probability algorithms on market feeds.
77+
* **`ingestion`**: Connects to `Finnhub` and `Alpaca` WebSockets. Normalizes trade and quote data into a standard `MarketEvent` format and pumps it into the system at extremely low latency.
78+
* **`relay`**: Handles network routing and edge measurement. Specifically benchmarks multiple RPC nodes (Helius, Triton, QuickNode) and routes transactions through the lowest-latency path available.
79+
* **`event_bus`**: A custom-built, lightweight TCP broadcasting system that decouples producers and consumers. Allows the TUI and Web Dashboards to run in entirely separate processes from the Daemon.
80+
* **`persistence`**: Storage layer designed to record transactional records, system P&L tracking, and order history.
81+
* **`common`**: Shared models, structs, commands, and `BotEvent` enumerations used across all systems to guarantee strict typing on inter-process communications.
82+
83+
## Configuration & Usage
84+
85+
The system expects several environment variables to be set for external API integrations:
86+
87+
```sh
88+
export ANTHROPIC_API_KEY="..."
89+
export FINNHUB_API_KEY="..."
90+
export ALPACA_API_KEY="..."
91+
export ALPACA_SECRET_KEY="..."
92+
export USE_MOCK="1" # Enables mocked market generation for UI testing
93+
```
94+
95+
### Running the System
96+
97+
Start the background daemon process first:
98+
```sh
99+
cargo run -p daemon --release
100+
```
101+
102+
In a separate terminal, launch the Terminal User Interface:
103+
```sh
104+
cargo run -p tui --release
105+
```
106+
107+
## UI and Visual Constraints
108+
109+
The TUI utilizes `Constraint::Length` and custom Ratatui widget styling to enforce a strict immutable grid layout. Custom hex colors have been applied globally to match a proprietary theme design.

assets/config.example.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example Configuration
2+
3+
[network]
4+
rpc_url = "https://api.mainnet-beta.solana.com"
5+
ws_url = "wss://api.mainnet-beta.solana.com"
6+
7+
[trading]
8+
program_id = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
9+
max_position_size = 0.5 # SOL
10+
min_confidence = 0.85
11+
12+
[strategy]
13+
type = "simple"
14+
volume_threshold = 5000000 # lamports
15+
16+
[logging]
17+
level = "info"
18+
format = "pretty"

check_env.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Write-Host "Checking RL Trading Bot Prerequisites..." -ForegroundColor Cyan
2+
3+
# 1. Check Rust
4+
if (Get-Command cargo -ErrorAction SilentlyContinue) {
5+
Write-Host "✅ Rust/Cargo detected" -ForegroundColor Green
6+
cargo --version
7+
} else {
8+
Write-Host "❌ Rust not found. Install from rustup.rs" -ForegroundColor Red
9+
}
10+
11+
# 2. Check VS Build Tools
12+
$vcvars = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
13+
if (Test-Path $vcvars) {
14+
Write-Host "✅ VS Build Tools detected" -ForegroundColor Green
15+
} else {
16+
Write-Host "❌ VS Build Tools NOT found at standard path." -ForegroundColor Red
17+
Write-Host " Path checked: $vcvars" -ForegroundColor Gray
18+
}
19+
20+
# 3. Check Windows SDK (kernel32.lib)
21+
$kits10 = "C:\Program Files (x86)\Windows Kits\10\Lib"
22+
if (Test-Path $kits10) {
23+
Write-Host "✅ Windows SDK Libs folder detected" -ForegroundColor Green
24+
25+
$kernel32 = Get-ChildItem -Path $kits10 -Filter "kernel32.lib" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
26+
if ($kernel32) {
27+
Write-Host "✅ kernel32.lib found at: $($kernel32.FullName)" -ForegroundColor Green
28+
} else {
29+
Write-Host "❌ kernel32.lib NOT found in Windows Kits folder." -ForegroundColor Red
30+
Write-Host " Please Modify VS Build Tools -> Individual Components -> Windows 10 SDK" -ForegroundColor Yellow
31+
}
32+
} else {
33+
Write-Host "❌ Windows Kits\10\Lib folder NOT found." -ForegroundColor Red
34+
Write-Host " Is the Windows 10/11 SDK installed?" -ForegroundColor Yellow
35+
}
36+
37+
Write-Host "`nTo fix missing components, run the Visual Studio Installer and modify 'Visual Studio Build Tools 2022'." -ForegroundColor Cyan

crates/ai/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "ai"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
common = { path = "../common" }
8+
tokio = { version = "1.0", features = ["full"] }
9+
serde = { version = "1.0", features = ["derive"] }
10+
serde_json = "1.0"
11+
reqwest = { version = "0.11", features = ["json"] }
12+
tracing = "0.1"
13+
anyhow = "1.0"
14+
chumsky = "0.9" # Optional depending on parsing needs
15+
event_bus = { path = "../event_bus" }

crates/ai/src/analyst.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use anyhow::Result;
2+
use common::events::{BotEvent, ControlCommand};
3+
use tokio::sync::mpsc;
4+
use tracing::{info, error};
5+
6+
pub struct DexterAnalyst {
7+
// API logic to come
8+
}
9+
10+
impl DexterAnalyst {
11+
pub fn new() -> Self {
12+
Self {}
13+
}
14+
15+
pub async fn run(&self) -> Result<()> {
16+
info!("Dexter Analyst started - waiting for data...");
17+
// This will listen for MarketEvents and periodically ping Claude
18+
Ok(())
19+
}
20+
}

0 commit comments

Comments
 (0)