Spaces:
Sleeping
Sleeping
Naufal Arhab
feat(sniper): implement dual-horizon (15m-1D) sniper engine, forward outcome evaluator, auto-breakeven SL, and UI surfacing
740fcec |
Download README.md from agus1111/Perps-Terminal: direct link, hf CLI and curl.
- Browser
- Download file 5.8 kB
-
https://huggingface.co/spaces/agus1111/Perps-Terminal/resolve/main/README.md
- Command line
-
hf download hf://spaces/agus1111/Perps-Terminal/README.md
-
curl -L -o README.md https://huggingface.co/spaces/agus1111/Perps-Terminal/resolve/main/README.md
5.8 kB
| title: Perps Institutional Quant Terminal | |
| emoji: ⚡ | |
| colorFrom: purple | |
| colorTo: blue | |
| sdk: gradio | |
| sdk_version: 4.44.1 | |
| app_file: app.py | |
| pinned: false | |
| # ⚡ PerpsAI — Institutional Multi-Exchange Signal Intelligence, Execution & AI Co-Pilot | |
| Engine analisis posisi Perpetual Futures (Long/Short) berbasis **konfluensi multi-sinyal real-time** dari **5 Bursa (Binance, Bybit, OKX, Bitget, dan Hyperliquid DEX)**, dilengkapi **Causal Historical Backtester**, eksekusi bracket order **Bybit V5 (Demo / Testnet / Real)** secara **stateless & fail-closed**, penyimpanan **Neon PostgreSQL** (dengan **in-memory fallback otomatis** saat `DATABASE_URL` kosong), serta **Tanya AI** (Vikey, Gemini, OpenAI). | |
| --- | |
| ## 🚀 Fitur Utama | |
| 1. **Anti-ISP Block Bawaan & TLS Verified:** | |
| - Modul **DNS-over-HTTPS (DoH)** internal untuk mem-bypass DNS filtering tanpa menonaktifkan verifikasi sertifikat TLS (`verify=True`). | |
| - Endpoint redundan lintas **Binance, Bybit (`api.bybit.biz`), OKX, Bitget, dan Hyperliquid on-chain DEX**. | |
| 2. **5-Way Quantitative Confluence Triangulation (Threshold `±4`):** | |
| - Triangulasi OI-weighted lintas 5 venue (`funding_rate`, `oi_divergence`, `basis`, `ls_ratio` contrarian) dengan klaster Order Flow (`cvd`, `spot_futures_cvd`, `whale_order_flow`) yang dibatasi di `[-3, +3]` dan deduplikasi DEX-vs-CEX spread pada Hyperliquid. | |
| - Circuit Breakers & `FakeDetector` (1m OHLCV + wick/spoof/divergence) men-veto arah secara ketat menjadi `NEUTRAL` dengan `trade_levels = None`. | |
| 3. **Bybit V5 Execution (Stateless & Fail-Closed Security):** | |
| - Route sensitif (`/api/execution/*`, `/api/pairs*`, `/api/journal*`, `/api/cron/refresh`) wajib Bearer token `PERPS_API_TOKEN` (`503` jika belum dikonfigurasi, `401` jika token salah/kosong). | |
| - Kredensial Bybit tidak disimpan global di memori server, melainkan dikirim per-request (`body` / header `X-Bybit-*` dari `sessionStorage` browser) atau `.env` server. | |
| - Limit order dengan split TP1/TP2 otomatis meluncurkan background post-fill reconciliation pada server stateful, atau melaporkan status jujur `STATELESS_MANUAL_TP2` di serverless. | |
| 4. **Causal Historical Replay Backtester:** | |
| - Mensimulasikan `SignalEngine` bar-by-bar tanpa *lookahead bias* (`backend/engine/backtester.py`), dilengkapi eksekusi *next-bar-open*, resolusi *SL-first* intra-bar, biaya taker, slippage, dan funding 8-jam (`backend/scripts/run_backtest.py`). | |
| 5. **Cloud PostgreSQL + Zero-Config In-Memory Fallback:** | |
| - Menggunakan Neon PostgreSQL (`DATABASE_URL`) untuk persistensi penuh, atau otomatis fallback ke `InMemoryDatabaseStore` saat dijalankan lokal/CI tanpa database eksternal. | |
| 6. **🤖 Tanya AI & Modern Real-Time UI:** | |
| - React 18 + Vite + TypeScript + Tailwind CSS + Capacitor Android support, terhubung melalui WebSocket streaming dan pengaturan `PERPS_API_TOKEN` di *Server Settings*. | |
| --- | |
| ## 📁 Struktur Direktori | |
| ``` | |
| perps/ | |
| ├── app.py # Entrypoint Hugging Face Spaces (Gradio proxy) | |
| ├── start_all.bat # 1-Click launcher Windows (Backend + Frontend) | |
| ├── start_all.ps1 # PowerShell launcher | |
| ├── backend/ # FastAPI + Quantitative Engines | |
| │ ├── config.py # Konfigurasi & env loader (PERPS_API_TOKEN, DATABASE_URL) | |
| │ ├── security.py # Fail-closed Bearer token & Cron secret verification | |
| │ ├── main.py # Entrypoint FastAPI + WebSocket + Background loop | |
| │ ├── database/ # Neon PostgreSQL pool + InMemoryDatabaseStore fallback | |
| │ ├── engine/ # SignalEngine, MTFAnalyzer, FakeDetector, Confluence, Predictive, CausalBacktester | |
| │ ├── exchanges/ # Async httpx adapters: Binance, Bybit, OKX, Bitget, Hyperliquid | |
| │ ├── routers/ # Endpoint pairs, signals, market, ai, journal, execution, websocket | |
| │ └── scripts/ # run_backtest.py (CLI causal historical replay) | |
| └── frontend/ # React + Vite + Capacitor Dashboard | |
| └── src/ | |
| ``` | |
| --- | |
| ## ⚡ Cara Menjalankan | |
| ### Backend + Frontend Lokal | |
| 1. Salin env dan isi `PERPS_API_TOKEN` (wajib untuk aksi eksekusi/pairs/jurnal): | |
| ```bash | |
| cp backend/.env.example backend/.env | |
| ``` | |
| 2. Jalankan Backend: | |
| ```bash | |
| cd backend | |
| pip install -r requirements.txt | |
| python -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload | |
| ``` | |
| 3. Jalankan Frontend: | |
| ```bash | |
| cd frontend | |
| npm install | |
| npm run dev | |
| ``` | |
| ### Causal Historical Backtester CLI | |
| ```bash | |
| # Offline JSON fixture replay | |
| python backend/scripts/run_backtest.py --fixture path/to/history.json --json | |
| # Live Binance 1H OHLCV + Funding History replay | |
| python backend/scripts/run_backtest.py --symbol BTCUSDT --days 14 | |
| ``` | |
| ### Menjalankan Test Suite | |
| ```bash | |
| python -m pytest -q | |
| ``` | |
| --- | |
| ## 🔑 Konfigurasi Environment (`.env`) | |
| Salin `backend/.env.example` menjadi `backend/.env`: | |
| ```env | |
| PERPS_API_TOKEN=ganti-dengan-token-rahasia-panjang | |
| CRON_SECRET=opsional-secret-cron-vercel | |
| DATABASE_URL= # Kosongkan untuk In-Memory fallback, atau isi URL Neon PostgreSQL | |
| UPDATE_INTERVAL=60 | |
| ``` | |
| --- | |
| ## ☁️ Panduan Deploy ke Vercel (Multi-Service Project) | |
| Projek ini dikonfigurasi untuk **Vercel Multi-Services** via [`vercel.json`](file:///c:/Users/ASUS/OneDrive/Desktop/perps/vercel.json) dengan layanan `frontend` (Vite SPA) dan `backend` (FastAPI Python). | |
| ### Environment Variables Wajib di Vercel: | |
| - `PERPS_API_TOKEN`: Token Bearer rahasia untuk mengamankan endpoint `/api/execution/*`, `/api/pairs*`, `/api/journal*`, dan `/api/cron/refresh` (lalu masukkan token ini via modal **Server Settings** di browser). | |
| - `DATABASE_URL`: URL koneksi Neon PostgreSQL Anda. | |
| - `CRON_SECRET` *(opsional)*: Secret untuk Vercel Cron Jobs pada `/api/cron/refresh`. | |