https://github.com/jango-blockchained/hoox-setup
โก Hoox is a modular, high-performance algorithmic trading and automation framework built entirely on Cloudflare Edge Workers. It uses distributed microservices to process signals, execute trades, and manage state with near-zero latency worldwide.
https://github.com/jango-blockchained/hoox-setup
ai-agent algorithmic-trading bun cloudflare cloudflare-workers crypto-trading-bot edge-computing microservices tradingsignal tradingview-webhooks typescript zero-latency
Last synced: about 1 month ago
JSON representation
โก Hoox is a modular, high-performance algorithmic trading and automation framework built entirely on Cloudflare Edge Workers. It uses distributed microservices to process signals, execute trades, and manage state with near-zero latency worldwide.
- Host: GitHub
- URL: https://github.com/jango-blockchained/hoox-setup
- Owner: jango-blockchained
- License: other
- Created: 2025-03-25T21:17:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-05-10T11:31:38.000Z (about 1 month ago)
- Last Synced: 2026-05-10T11:33:17.226Z (about 1 month ago)
- Topics: ai-agent, algorithmic-trading, bun, cloudflare, cloudflare-workers, crypto-trading-bot, edge-computing, microservices, tradingsignal, tradingview-webhooks, typescript, zero-latency
- Language: TypeScript
- Homepage: https://hoox-dashboard.pages.dev
- Size: 7.64 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
- Agents: AGENTS.md
Awesome Lists containing this project
README
# ๐ Hoox - The Zero-Latency Edge Trading Ecosystem
[](https://www.typescriptlang.org/)
[](https://bun.sh)
[](https://workers.cloudflare.com/)
[](docs/development/testing.md)
[](https://creativecommons.org/licenses/by/4.0/)
[](https://github.com/jango-blockchained/hoox-setup)
**Comprehensive Docs:** **[Documentation Home](docs/home.md)** ยท **[Report a Bug](https://github.com/jango-blockchained/hoox-setup/issues)**
> **Low-latency edge trading.** Hoox is a free and open-source algorithmic trading and automation framework. Built on **Cloudflareยฎ Workers**, Hoox utilizes a globally distributed, microservice edge architecture. Process signals, execute trades, and manage state with **low latency**, directly from the network edge closest to the exchange.
---
## ๐ Required clone mode
This repository uses Git submodules for worker repositories. You must clone it recursively:
```bash
git clone --recursive https://github.com/jango-blockchained/hoox-setup.git hoox-trading
```
## ๐ Why Hoox?
Hoox provides a modern approach to algorithmic trading infrastructure deployment.
- ๐ธ **Cost-Effective & Open Source:** Hoox leverages Cloudflareยฎ's free tiers, allowing you to run your trading infrastructure with minimal or no server costs.
- โก **Edge Execution:** Your code runs on Cloudflareยฎ's Edge, geographically close to exchange API servers (like Binance, Bybit, and MEXC). When a signal fires, Hoox executes with minimal network latency.
- ๐ก๏ธ **Built-in Security:** Hoox inherits Cloudflareยฎ's security features. With a Zero Trust architecture, strict IP Allow-listing, and encrypted internal Service Bindings, your API keys and trading strategies are well-protected.
- ๐ง **Automated Management:** Featuring an embedded risk manager (`agent-worker`), Hoox can monitor your portfolio, manage trailing stops, trigger kill-switches, and send system health summaries.
---
## โ ๏ธ Disclaimer
Hoox is provided "as-is" for educational and research purposes only. The authors, contributors, and copyright holders make no warranties regarding the software and disclaim all liability for any financial losses resulting from its use.
**No Financial Advice.** Nothing in this repository constitutes financial, investment, or trading advice. Users are solely responsible for their own trading decisions and must evaluate all risks independently.
**Risk of Loss.** Algorithmic trading on centralized and decentralized exchanges involves substantial risk. Past performance is not indicative of future results. You may lose some or all of your invested capital.
**Regulatory Compliance.** Users are responsible for ensuring compliance with applicable laws and regulations in their jurisdiction. Trading activities may be subject to licensing requirements, reporting obligations, or restrictions depending on your location.
**No Warranties.** The software is provided under CC BY 4.0 without warranties of any kind, express or implied, including but not limited to merchantability, fitness for a particular purpose, or non-infringement. See the [LICENSE](LICENSE) and [DISCLAIMER](DISCLAIMER.md) for full details.
---
## โจ Enterprise-Grade Features
### Core Platform
| Feature | Description |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ๐ **Service Bindings** | Microsecond inter-worker communicationโno public internet routing, no TLS overhead, no DNS resolution. Workers call each other via internal V8 isolates. |
| ๐จ **Async Queues** | Cloudflareยฎ Queues with exponential backoff retry policy (30s โ 15min). Guaranteed delivery survives exchange downtime, API rate limits, and network partitions. |
| ๐ก๏ธ **Idempotent Execution** | Durable Objects with SQLite-backed state prevent duplicate trades on network retries. Every webhook gets a unique trace ID for end-to-end signal tracking. |
| ๐ค **Multi-Provider AI Gateway** | 5 AI providers (Workers AI, OpenAI, Anthropic, Google AI, Azure OpenAI) with automatic fallback chain, health checks, SSE streaming, vision analysis, reasoning models, and usage tracking. |
| ๐ง **AI Risk Manager** | `agent-worker` runs on a 5-minute cron: monitors open positions, moves trailing stops, scales out of profitable trades, flips the Global Kill Switch on max drawdown, and sends health summaries. |
| โก **Smart Placement** | Zero-config latency optimization โ Workers automatically run on the edge node closest to exchange API servers. 30-60% latency reduction, $0 cost (free on all plans). |
| ๐ **Real DO Idempotency** | Durable Object with SQLite-backed persistence, TTL-based dedup, and automatic alarm cleanup. Prevents duplicate trades on network retries across cold starts. |
### Data & Storage
| Feature | Description |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ๐๏ธ **D1 Edge Database** | Globally distributed SQLite at the edge. Persistent, atomic storage for trade history, positions, and balances. Preserved write limits via R2 log offloading. |
| ๐ฆ **R2 Object Storage** | Zero-egress, S3-compatible storage for trade reports, system logs, and user uploads. No bandwidth charges on retrieval. |
| ๐ **KV Configuration** | Sub-millisecond global key-value store for dynamic routing, IP allowlists, session state, kill-switch toggles, and live settingsโno redeployment required. |
| ๐ **Vectorize RAG Index** | Embedded vector database for retrieval-augmented generation. Powers context-aware AI responses and intelligent Telegram bot conversations. |
| ๐ **Analytics Engine** | Time-series analytics dataset for tracking API call latency, error rates, and trade execution metrics across all workers. Free on all plans. |
### Trading Infrastructure
| Feature | Description |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ๐ **Multi-Exchange Engine** | Execute across Binance, Bybit, and MEXC with dynamic routing via `CONFIG_KV`. Redirect symbols to different exchanges instantly without code deployment. |
| ๐ **DeFi Execution** | On-chain swap execution via `web3-wallet-worker` with secure mnemonic management and browser rendering for DApp interactions. |
| ๐ง **Email Signal Parsing** | Trigger trades from raw email parsing via `email-worker`. Ancillary input channel alongside TradingView webhooks and Telegram commands. |
| โก **Rate Limiting** | KV-backed rate limiter (10 trades/min) survives cold starts. Falls back to in-memory when KV unavailable. Prevents API bans and accidental trade spamming. |
| ๐ **Automated PDF Reports** | Twice-daily PDF portfolio reports via Cloudflare Browser Rendering. Styled HTML โ PDF, stored in R2, delivered via Telegram. Free 10 min/day on all plans. |
### Developer Experience
| Feature | Description |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ๐ **Command Center** | Next.js 16 dashboard deployed to Cloudflare Workers via OpenNext. Real-time portfolio monitoring, win rates, live positions, and risk settingsโno redeployment to change configuration. |
| ๐ฅ๏ธ **Interactive TUI** | Terminal-based process manager (`./hoox-tui`) for local development. Hot-reload all 9 workers simultaneously with one command. |
| ๐ ๏ธ **CLI Workspaces** | Bun workspace monorepo managed via `hoox` CLI (15 command groups, 50+ subcommands, 381 tests). Interactive setup wizard, env config, KV sync, D1 ops, health monitoring, repair, and more. |
| ๐ณ **Docker Support** | Full local dev environment with Docker Compose. `hoox dev start` prompts for Native vs Docker runtime, offers `--runtime` flag override. Profiles: `workers`, `dashboard`, `full`. |
| ๐ **Shared Package** | `@jango-blockchained/hoox-shared` provides a custom router with `:param` path parameter support, `Errors.*` response factories, generic exchange provider factory (`ExchangeRouter`), middleware stack (auth, CORS, logging, rate-limit, validation), and utilities. |
### Security
| Feature | Description |
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| ๐ **Zero Trust Architecture** | Internal workers (`trade-worker`, `d1-worker`) have zero public endpointsโaccessible only via Cloudflareยฎ Service Bindings. |
| ๐ก๏ธ **WAF Integration** | IP allowlisting and rate limiting at the Cloudflare edge. Malicious traffic dropped before hitting the gateway worker. |
| ๐ **Secret Injection** | API keys injected directly into the V8 isolate at runtime. Never stored in plaintext, never logged. Local `.dev.vars` excluded from version control. |
| ๐ด **Global Kill Switch** | Instant trading halt via KV toggle. No redeployment, no downtimeโimmediate effect across all workers on next request cycle. |
| ๐ **Security Headers** | Full CSP, HSTS, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and Permissions-Policy on every response. CORS disabled (same-origin only). |
---
## ๐ Quick Start (Deploy in 5 Minutes)
### Option A: Install from Source (Recommended)
1. **Clone the repository:**
```bash
git clone --recursive https://github.com/jango-blockchained/hoox-setup.git hoox-trading
cd hoox-trading
```
2. **Install dependencies and bootstrap:**
```bash
bun install
hoox init
```
### Deploy
**Deploy your entire trading empire to the Cloudflareยฎ Edge!**
```bash
# Deploy all workers + dashboard (correct dependency order)
hoox deploy all --auto
# Post-deploy: set Telegram webhook
hoox deploy telegram-webhook
# Post-deploy: update dashboard service URLs
hoox deploy update-internal-urls
# Post-deploy: apply KV manifest defaults
hoox deploy kv-config
```
> **Local Development:** Want to test before going live? Run `hoox dev start` to launch all workers โ choose between Native (wrangler) or Docker (compose) runtime. Use `./hoox-tui` for the interactive terminal UI!
---
## ๐ฆ Worker Submodules
Hoox uses Git submodules for each worker, allowing independent development and deployment. All workers are part of the [hoox-setup](https://github.com/jango-blockchained/hoox-setup) monorepo.
| Worker | Description | Repository |
| ------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| ๐ **hoox** (Gateway) | Webhook entrypoint & firewall | [jango-blockchained/hoox](https://github.com/jango-blockchained/hoox) |
| ๐ **trade-worker** | Multi-exchange execution engine | [jango-blockchained/trade-worker](https://github.com/jango-blockchained/trade-worker) |
| ๐ง **agent-worker** | AI risk manager & cron jobs | [jango-blockchained/agent-worker](https://github.com/jango-blockchained/agent-worker) |
| ๐ฌ **telegram-worker** | Telegram notifications & commands | [jango-blockchained/telegram-worker](https://github.com/jango-blockchained/telegram-worker) |
| ๐๏ธ **d1-worker** | D1 database operations | [jango-blockchained/d1-worker](https://github.com/jango-blockchained/d1-worker) |
| ๐ **web3-wallet-worker** | DeFi & on-chain execution | [jango-blockchained/web3-wallet-worker](https://github.com/jango-blockchained/web3-wallet-worker) |
| ๐ง **email-worker** | Email signal parsing | [jango-blockchained/email-worker](https://github.com/jango-blockchained/email-worker) |
| ๐ **analytics-worker** | Analytics & reporting | [jango-blockchained/analytics-worker](https://github.com/jango-blockchained/analytics-worker) |
| ๐ **report-worker** | Automated PDF reports via Browser Rendering | [jango-blockchained/report-worker](https://github.com/jango-blockchained/report-worker) |
> **Note:** Clone with `git clone --recursive` to get all submodules, or run `git submodule update --init --recursive` after cloning.
---
## ๐ ๏ธ The `@jango-blockchained/hoox-cli` & Workspaces
The Hoox setup is managed via a dedicated, locally linked CLI tool at `packages/cli` (15 command groups, 50+ subcommands, 381 tests). By utilizing Bun Workspaces, all management commands are available via the `hoox` binary.
### Complete Command Tree
```
hoox Interactive TUI (no args)
โโโ init Setup wizard with AI provider support
โโโ clone Clone worker repos as submodules
โโโ dev Local development (native/docker)
โโโ deploy Deploy workers, dashboard, webhook, KV
โโโ infra Manage D1, KV, R2, Queues, Vectorize, Analytics
โโโ config Config, env vars, KV keys, secrets
โ โโโ env Declarative 31-key env matrix
โ โโโ kv 16-key manifest + apply-manifest
โโโ check Prerequisites, setup, health
โโโ db D1 schema, migrate, query, export, reset
โโโ monitor Health, trades, logs, kill-switch, backup
โโโ repair System check, repair, guided rebuild
โโโ logs Tail worker logs
โโโ test CI pipeline
โโโ waf WAF rules
โโโ dashboard Dashboard operations
```
### Key Workflows
| Workflow | Commands |
| ----------- | --------------------------------------------------------------------------------------------------- |
| **Setup** | `hoox init` โ `hoox check prerequisites` โ `hoox config env init` โ `hoox config kv apply-manifest` |
| **Deploy** | `hoox deploy all --auto` โ `hoox deploy telegram-webhook` โ `hoox deploy update-internal-urls` |
| **Operate** | `hoox monitor status` โ `hoox monitor trades` โ `hoox monitor kill-switch` |
| **Repair** | `hoox repair check` โ `hoox repair infra` โ `hoox repair secrets` โ `hoox repair rebuild` |
| **Infra** | `hoox infra d1 list` โ `hoox infra vectorize list` โ `hoox infra queues list` |
### Features
- **Interactive Setup**: Guided wizard with AI provider integration (OpenAI, Anthropic, Google AI, Home Assistant)
- **Toolchain Validation**: 7 prerequisites checks (bun, git, node, wrangler, Cloudflare auth, Docker, repository)
- **Declarative Env Config**: 31 environment variables across 8 sections with init/show/validate/generate-dev-vars
- **KV Manifest Sync**: 16-key manifest with one-command apply for CONFIG_KV namespace
- **Database Operations**: Schema apply, tracking migrations, read-only queries, export, reset with --remote support
- **Infrastructure as Code**: Provision D1, KV, R2, Queues, Vectorize, Analytics via `hoox infra`
- **Post-Deploy Automation**: Telegram webhook setup, internal URL updates, KV config sync
- **Operational Monitoring**: Worker health probes, recent trades, system logs, queue depth, D1 backup, kill switch
- **Guided Repair**: 5-step system check, per-component repair, interactive full rebuild
- **Health Checks**: Worker /health endpoint probing for all enabled workers
- **Secret Management**: Sync, check, and rotate Cloudflare secrets
- **All commands** support `--json` (machine output) and `--quiet` (minimal output) global flags
---
## ๐ง
Performance & Tooling: Powered by Bun
Hoox relies on **Bun** as its primary JavaScript runtime and package manager. Bun is designed as a drop-in replacement for Node.js, providing significantly faster execution, immediate startup times, and built-in tooling for testing, running scripts, and managing dependencies.
- **Super Fast Execution**: Native implementations and the JavaScriptCore engine make script execution near instantaneous.
- **Lightning Fast Installs**: Dependency resolution and installation are optimized for speed, caching, and concurrent fetching.
- **Built-in Test Runner**: Hoox uses `bun test`, giving you natively integrated testing without heavy additional dependencies like Jest or Mocha.
- **TypeScript Out-of-the-Box**: Bun compiles TypeScript on the fly, eliminating the need for slow build steps during development.
---
## ๐๏ธ The Microservice Architecture
Hoox is split into distinct, highly specialized micro-workers. If one fails, the others keep running.
```mermaid
graph TB
%% โโ Styling โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
classDef external fill:#f5f5f5,stroke:#999,stroke-width:2,color:#333
classDef waf fill:#fff8e1,stroke:#f9a825,stroke-width:2
classDef worker fill:#e8f5e9,stroke:#43a047,stroke-width:2,color:#1b5e20
classDef storage fill:#e3f2fd,stroke:#1e88e5,stroke-width:2,color:#0d47a1
classDef compute fill:#f3e5f5,stroke:#8e24aa,stroke-width:2,color:#4a148c
classDef cli fill:#fafafa,stroke:#bdbdbd,stroke-width:1,stroke-dasharray: 4
classDef dash fill:#fff3e0,stroke:#ef6c00,stroke-width:2,color:#bf360c
%% โโ Layers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
subgraph "๐ External World"
TV["๐ TradingView Webhooks"]
TG["๐ฌ Telegram Bot Commands"]
EM["๐ง Email Signals"]
subgraph "๐ฑ Exchanges"
BINANCE["Binance API"]
BYBIT["Bybit API"]
MEXC["MEXC API"]
end
end
subgraph "๐ก๏ธ Cloudflareยฎ WAF"
WAF["IP Allowlisting & Rate Limiting"]
end
subgraph "โก Cloudflareยฎ Edge Network โ Workers"
GW["๐ hoox
Gateway & Firewall"]
TW["๐ trade-worker
Execution Engine"]
AW["๐ง agent-worker
AI Risk Manager"]
D1W["๐๏ธ d1-worker
SQL Operations"]
TGW["๐ฌ telegram-worker
Notifications"]
W3W["๐ web3-wallet
DeFi Execution"]
EMW["๐ง email-worker
Email Parser"]
ANW["๐ analytics-worker
Observability"]
RPW["๐ report-worker
PDF Reports"]
DASH["๐ฅ๏ธ Dashboard
Next.js Command Center"]:::dash
end
subgraph "๐พ Cloudflareยฎ Storage Layer"
KV[("KV ยท Config & Kill-Switch
Sub-millisecond reads")]
DB[("D1 ยท Trade Database
Global SQLite")]
R2[("R2 ยท Object Storage
Reports & Logs")]
VEC[("Vectorize ยท RAG Index
AI Embeddings")]
end
subgraph "๐งฎ Cloudflareยฎ Compute Layer"
AI{{"๐ค Workers AI
LLaMA 3 Inference"}}
DO{{"๐ Durable Objects
Idempotency Locks"}}
Q{{"๐จ Queues
Async Delivery ยท Retry"}}
BROWSER{{"๐ Browser Rendering
PDF Generation"}}
AE{{"๐ Analytics Engine
Time-Series Metrics"}}
end
subgraph "๐ง Management Plane โ hoox CLI"
CLI["hoox deploy ยท hoox infra ยท hoox config
hoox db ยท hoox monitor ยท hoox repair
hoox check ยท hoox logs ยท hoox waf"]
end
%% โโ External โ WAF โ Gateway โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
TV -->|"HTTPS + API Key"| WAF
TG -->|"HTTPS + Bot Token"| TGW
EM -->|"SMTP/IMAP"| EMW
WAF -->|"Validated Signals"| GW
%% โโ Dashboard โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
DASH -->|"Service Binding"| GW
DASH -.->|"Read Config"| KV
%% โโ hoox Gateway Routing โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
GW -->|"โก Fast Path ยท Service Binding"| TW
GW -->|"๐จ Fallback ยท Queue"| Q
GW -->|"๐ Idempotency"| DO
GW -->|"๐ฌ Notifications"| TGW
GW -.->|"Config + Rate Limit"| KV
GW -.->|"Track API Calls"| AE
%% โโ agent-worker (Cron: every 5 min) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
AW -->|"Cron */5 ยท Evaluate Positions"| TW
AW -->|"Send Summaries"| TGW
AW -->|"Query History"| D1W
AW -->|"Risk Analysis"| AI
AW -.->|"Portfolio State"| DB
AW -.->|"Market Data
Price Checks"| BINANCE
AW -.->|"Market Data
Price Checks"| BYBIT
AW -.->|"Market Data
Price Checks"| MEXC
%% โโ trade-worker Execution โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
TW -->|"Service Binding"| D1W
TW -->|"Service Binding"| TGW
TW -->|"Service Binding"| ANW
TW -->|"DeFi Execution"| W3W
TW -.->|"Read/Write Trades"| DB
TW -.->|"Read Config"| KV
TW -.->|"RAG Context"| VEC
TW -.->|"Offload Logs"| R2
TW -.->|"Enqueue Retry"| Q
TW -.->|"AI Analysis"| AI
TW -.->|"Render Reports"| BROWSER
TW ==>|"REST ยท REST
Signed Requests"| BINANCE
TW ==>|"REST ยท WebSocket
Signed Requests"| BYBIT
TW ==>|"REST
Signed Requests"| MEXC
%% โโ telegram-worker โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
TGW -->|"Track Events"| ANW
TGW -.->|"AI Chat Responses"| AI
TGW -.->|"Read Config"| KV
%% โโ email-worker โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
EMW -->|"Track Events"| ANW
EMW -.->|"Read Config"| KV
%% โโ report-worker (Cron: 06:00 + 18:00) โโโโโโโโโโโโโโโโโโโโโโโโโโ
RPW -->|"Cron ยท Store PDFs"| R2
RPW -->|"Send Report Links"| TGW
RPW -.->|"REST ยท Render HTMLโPDF"| BROWSER
%% โโ CLI Management Plane (dashed to all managed resources) โโโโโโโ
CLI -.->|"hoox deploy ยท hoox check"| GW
CLI -.->|"hoox deploy ยท hoox repair"| TW
CLI -.->|"hoox deploy ยท hoox repair"| AW
CLI -.->|"hoox deploy"| D1W
CLI -.->|"hoox deploy ยท telegram-webhook"| TGW
CLI -.->|"hoox deploy"| W3W
CLI -.->|"hoox deploy"| EMW
CLI -.->|"hoox deploy"| ANW
CLI -.->|"hoox deploy"| RPW
CLI -.->|"hoox deploy"| DASH
CLI -.->|"hoox db ยท hoox repair db"| DB
CLI -.->|"hoox config kv ยท hoox repair kv"| KV
CLI -.->|"hoox infra r2"| R2
CLI -.->|"hoox infra queues"| Q
CLI -.->|"hoox infra vectorize"| VEC
CLI -.->|"hoox infra analytics"| AE
CLI -.->|"hoox infra d1 ยท hoox repair"| DO
%% โโ Apply styles โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
class TV,TG,EM,BINANCE,BYBIT,MEXC external
class WAF waf
class GW,TW,AW,D1W,TGW,W3W,EMW,ANW,RPW worker
class KV,DB,R2,VEC storage
class AI,DO,Q,BROWSER,AE compute
class CLI cli
```
---
## ๐ The 9 Pillars of Hoox (Workers)
### ๐ hoox (The Gateway)
The main entry point. It validates incoming TradingView webhooks, verifies API keys, and routes valid signals to the execution engine.
- **WAF Integration**: IP allowlisting and rate limiting are handled via Cloudflare WAF to drop malicious traffic before it hits the worker.
- **Fast Path Execution**: Attempts to execute trades instantly via direct Service Bindings, falling back to queues if necessary.
- **Real DO Idempotency**: Prevents duplicate trades using SQLite-backed Durable Objects with TTL-based dedup and automatic alarm cleanup.
- **KV-backed Rate Limiting**: Rate limiter persists across cold starts using CONFIG_KV, with transparent in-memory fallback.
- **Smart Placement**: Worker runs on edge node closest to exchange API servers โ 30-60% latency reduction.
- **Analytics Tracking**: Every API call is tracked via analytics-worker for real-time observability.
- **Trace IDs**: Generates distributed trace IDs for end-to-end signal tracking.
### ๐ trade-worker (The Execution Engine)
The execution module. Routes and executes orders across MEXC, Binance, and Bybit. Handles leverage calculation and size mapping.
- **Dynamic Routing**: Uses an `ExchangeRouter` with `CONFIG_KV` to instantly redirect symbols to different exchanges without code deployment. The `ExchangeRouter` and `IExchangeProvider` types live in the shared package for reusability.
- **Standardized Error Handling**: All error responses use the `Errors.*` factory from `@jango-blockchained/hoox-shared` for consistent JSON error format across every worker.
- **Smart Placement**: Automatically executes on the Cloudflare edge node closest to the exchange's API servers.
- **R2 Log Offloading**: Verbose request and response logs are saved to R2 (`hoox-system-logs`), preserving D1 write limits for critical financial data.
### ๐ง agent-worker (The AI Risk Manager & Multi-Provider AI Gateway)
Runs silently on a 5-minute Cron schedule. It observes open positions, moves trailing stops, scales out of profitable trades, and flips the Global Kill Switch if maximum daily drawdown is reached.
**Enhanced with Multi-Provider AI (Tasks 18-30):**
- **5 AI Providers**: Workers AI, OpenAI, Anthropic, Google AI, Azure OpenAI
- **Automatic Fallback Chain**: Seamless switching between providers on failure
- **Health Checks**: Providers self-report health status for intelligent routing
- **SSE Streaming**: Real-time streaming responses for chat and reasoning
- **Vision Analysis**: Image analysis with URL or base64 input
- **Reasoning Models**: Extended thinking support (OpenAI o1, etc.)
- **Prompt Templates**: Pre-built templates (trading-analyst, risk-assessor, market-scanner)
- **Usage Tracking**: Monitor API usage across all providers
**New Endpoints:**
- `POST /agent/chat` - AI chat with streaming support
- `POST /agent/vision` - Image analysis
- `POST /agent/reasoning` - Extended thinking queries
- `GET /agent/usage` - Usage statistics
- `GET /agent/prompts` - List prompt templates
### ๐ dashboard (The Command Center)
A secure, Cloudflare Workers-powered React dashboard using Next.js 16 + OpenNext. Monitor Win Rates, view live positions, and adjust risk settings on the fly without ever needing to redeploy code.
### ๐ฌ telegram-worker (The Communicator)
Sends instant trade confirmations and AI-generated market summaries straight to your phone.
### ๐๏ธ d1-worker (The Memory)
Handles all heavy SQL operations, aggregating trade histories and system logs to keep the execution workers incredibly lightweight.
### ๐ web3-wallet-worker (The On-Chain Bridge)
Ready for DeFi execution. Securely manages mnemonic phrases to execute swaps on decentralized exchanges.
### ๐ง email-worker
Ancillary plugin allowing you to trigger trades via raw email parsing.
### ๐ report-worker (The Reporter)
Automated PDF portfolio report generation via Cloudflare Browser Rendering.
- **Cron-Triggered**: Generates reports twice daily (06:00 + 18:00 UTC).
- **Styled HTMLโPDF**: Converts portfolio metrics, P&L, win rates, and position data into professional PDF reports.
- **R2 Storage**: Stores all generated PDFs in the `trade-reports` R2 bucket with date-based keys.
- **Telegram Delivery**: Sends report links directly via `telegram-worker` service binding.
- **Free Tier**: Browser Rendering is free at 10 min/day on all Cloudflare plans.
---
## ๐ Security Architecture
Security is a foundational aspect of the Hoox system.
### Implemented Security Features
| Feature | Description |
| ----------------------------- | ----------------------------------------------------------- |
| **CORS** | Disabled - same-origin only |
| **X-Frame-Options** | DENY - prevents iframe embedding |
| **X-Content-Type-Options** | nosniff - prevents MIME sniffing |
| **X-XSS-Protection** | 1; mode=block |
| **Referrer-Policy** | strict-origin-when-cross-origin |
| **Permissions-Policy** | Blocks accelerometer, camera, geolocation, microphone, etc. |
| **Strict-Transport-Security** | max-age=31536000; includeSubDomains |
| **Content-Security-Policy** | default-src 'self' |
| **Idempotent Execution** | Durable Objects prevent duplicate trades |
| **Rate Limiting** | 10 trades/minute protection |
| **IP Allow-listing** | Optional IP filtering via KV |
| **API Key Auth** | Secret binding validation |
| **Kill Switch** | Global trading pause via KV |
### Security Layers
1. **Edge-Level**: Cloudflare's DDoS protection, firewall, and WAF
2. **Worker-Level**: IP allow-listing, API key validation, rate limiting
3. **Execution-Level**: Idempotency keys prevent duplicates, kill switches halt trading
4. **Response-Level**: All responses include security headers
- **No Public APIs:** The `trade-worker` and `d1-worker` literally do not exist on the public internet. They can _only_ be accessed internally by the `hoox` gateway via Cloudflareยฎ Service Bindings.
- **Zero Trust Dashboard:** Your UI is secured with authentication and deployed to Cloudflare Workers using the OpenNext adapter for full Next.js feature support.
- **Hardware-Level Secret Injection:** API keys are injected directly into the V8 isolate at runtime. They are never stored in plaintext or logged.
- **Idempotent Execution:** Durable Objects prevent duplicate trades on network retriesโno lost ETH from double-spending.
- **Rate Limiting:** Built-in throttling prevents accidental trade spamming.
---
## ๐ฏ Async Trade Execution (Queues)
Hoox uses Cloudflareยฎ Queues for guaranteed trade delivery:
| Mode | Description |
| -------------------------- | -------------------------------------------- |
| `queue_failover` (default) | Try direct execution first, queue on failure |
| `queue_everywhere` | Always queue trades asynchronously |
### Configuration
```bash
# Set mode in KV
wrangler kv key put webhooks:queue_mode queue_failover --binding CONFIG_KV --remote
```
### Retry Behavior
- **Attempt 1**: Immediate
- **Attempt 2**: 30 seconds
- **Attempt 3**: 1 minute
- **Attempt 4**: 5 minutes
- **Attempt 5**: 15 minutes
- After max retries: Trade logged to D1 as failed
---
## ๐ธ Free Tier Costs (Everything is Free!)
Hoox runs entirely on Cloudflareยฎ Workers Free tier:
| Service | Free Limit | Notes |
| ---------------------- | ----------------------------- | ----------------------------------- |
| ๐ Workers | 100k req/day | ~3k trades/day |
| ๐ D1 | 5M rows read, 100k writes/day | 5GB storage |
| ๐ KV | 1GB, 1k ops/day | Config + rate limiter state |
| ๐ R2 | 10GB/month | Trade reports, logs, PDFs |
| ๐ Queues | 10k ops/day | ~3k trades/day |
| ๐ Durable Objects | SQLite-backed only | Idempotency locks |
| ๐ Workers AI | 10k neurons/day | AI summaries, risk analysis |
| ๐ Vectorize | 100 indexes | RAG-powered AI responses |
| ๐ Browser Rendering | 10 min/day | PDF portfolio reports |
| ๐ Analytics Engine | Unlimited datasets | Real-time API + trade observability |
| ๐ Smart Placement | Unlimited | 30-60% latency reduction |
| ๐ WAF + Rate Limiting | 1 free rate limit rule | API protection |
---
## ๐งช Testing & Reliability
With money on the line, we test everything.
```bash
# Run the massive test suite powered by Bun
bun test --coverage
```
**Current Test Coverage:**
- **packages/cli**: 381 tests across 26 files โ 0 failures (100% pass rate)
- **workers/hoox**: test suite in progress
- **workers/trade-worker**: test suite in progress
- **workers/agent-worker**: test suite in progress
Built natively on Bun, Hoox features TypeScript type safety with strict mode enabled.
> **Note**: Coverage targets >80% for all critical execution paths. See [Testing Documentation](docs/development/testing.md) for detailed coverage reports.
### ๐ Live Integration Tests
A full live test suite against **real Cloudflare infrastructure** (no mocks) is available at [`tests/live/`](tests/live/). Covers all services used by hoox:
```bash
# Run all live tests (requires credentials in tests/live/.env)
bun test:live
# Run tests for a specific service
bun test tests/live/d1.test.ts # D1 SQL database
bun test tests/live/kv.test.ts # KV namespace
bun test tests/live/r2.test.ts # R2 object storage
bun test tests/live/queues.test.ts # Queue messaging
bun test tests/live/ai.test.ts # Workers AI inference
bun test tests/live/api.test.ts # Cloudflare REST API
bun test tests/live/secrets.test.ts # Secret management
bun test tests/live/durable-objects.test.ts # Durable Objects
```
> โ **Warning:** These tests create and destroy real resources. Use a development/staging account, NOT production. Copy [`tests/live/env.template`](tests/live/env.template) to `tests/live/.env` to configure.
---
## ๐ณ Local Development (Docker)
Hoox supports local development using Docker. While production deployment targets Cloudflare Workers, Docker allows you to run and test the worker logic locally.
### Prerequisites
- [Docker](https://www.docker.com/) & Docker Compose
- Bun runtime (included in our Docker images)
### Development (Hot-Reload)
Spin up all workers locally with hot-reloading enabled. Changes to your code are reflected instantly without rebuilding the container.
```bash
# Build and start the dev environment
bun run docker:dev
# Optional: validate compose file before boot
docker compose config
```
This launches all workers on the following ports:
| Service | Port |
| --------------- | ---- |
| Gateway (hoox) | 8787 |
| Trade Worker | 8789 |
| Telegram Worker | 8791 |
| D1 Worker | 8792 |
| Web3 Wallet | 8793 |
| Dashboard | 8794 |
| Agent | 8795 |
| Email | 8796 |
| Report | 8797 |
To stop local dev cleanly:
```bash
bun run docker:down
```
### Production Build
Build the optimized production image for local testing.
```bash
# Build the production image
bun run docker:prod
```
**Configuration:**
Ensure your `.env.local` or environment variables are set with your Cloudflare API Token and Account ID:
```bash
CLOUDFLARE_API_TOKEN=your_token_here
CLOUDFLARE_ACCOUNT_ID=your_account_id
```
---
## ๐ค Contribute
Traditional algorithmic trading is often complex and difficult to deploy. Hoox aims to simplify this.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/new-strategy`)
3. Commit your changes (`git commit -m 'Add new strategy'`)
4. Push to the branch (`git push origin feature/new-strategy`)
5. Open a Pull Request
---
## โ
Integrated Cloudflare Services
All Cloudflare service integrations are **live** across hoox workers (May 2026):
| Service | Integration | CLI Mgmt | Workers | Cost |
| --------------------------- | :---------------------------------------------: | :--------------------: | :------------------------------: | :--: |
| **Smart Placement** | `placement { mode: "smart" }` | โ | hoox, trade, agent, d1, telegram | Free |
| **Durable Objects** | Real IdempotencyStore w/ SQLite + alarm cleanup | โ | hoox | Free |
| **KV-backed Rate Limiting** | Survives cold starts, in-memory fallback | `hoox config kv` | hoox | Free |
| **Browser Rendering** | Automated PDF portfolio reports | โ | report-worker | Free |
| **Analytics Engine** | Time-series tracking via analytics-worker | `hoox infra analytics` | all workers | Free |
| **Workers AI** | LLaMA 3 risk analysis & summaries | โ | agent, telegram, hoox | Free |
| **Vectorize** | RAG-powered AI responses | `hoox infra vectorize` | telegram, hoox | Free |
| **D1 Database** | Global SQLite at the edge | `hoox db` | trade, d1, agent | Free |
| **KV Config** | Sub-millisecond config store | `hoox config kv` | all workers | Free |
| **Queues** | Async message delivery | `hoox infra queues` | hoox, trade | Free |
| **R2 Storage** | Zero-egress object storage | `hoox infra r2` | trade, report | Free |
| **WAF + Rate Limiting** | CLI-managed IP allowlisting + rate rules | `hoox waf` | zone-level | Free |
All services run on Cloudflare's **Free plan** โ no monthly costs.
---
## ๐ License
Licensed under [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/). See [LICENSE](LICENSE) for the full license text and [DISCLAIMER](DISCLAIMER.md) for legal terms.
---
Built with ๐ฅ on the Cloudflareยฎ Edge.
---
_Cloudflareยฎ and the Cloudflare logo are trademarks and/or registered trademarks of Cloudflare, Inc. in the United States and other jurisdictions._
_Pine Scriptโข and TradingViewยฎ are trademarks of TradingView, Inc. This project is an independent effort and is not affiliated with or endorsed by TradingView, Inc._