No description
- PHP 47.5%
- HTML 29.4%
- JavaScript 17.1%
- Hack 4%
- CSS 2%
| api | ||
| assets | ||
| css | ||
| includes | ||
| .env.example | ||
| .gitignore | ||
| config.php | ||
| cron.php | ||
| DATABASE.html | ||
| doc.html | ||
| index.php | ||
| init-db.php | ||
| logs.php | ||
| memory.md | ||
| PRD.html | ||
| PRD.md | ||
| README.md | ||
Trading Gate Dashboard
Custom trading dashboard untuk Gate.io dengan strategi 2-Level DCA + Fixed Target Take Profit.
Tech Stack
- PHP Native (8.x)
- SQLite Database
- cURL
- Tailwind CSS (CDN)
- ApexCharts
- Vanilla JavaScript
- Mermaid.js (documentation)
Features
- Dashboard - Balance cards, profit chart, stats panel, open orders counter, token validity
- Smart Order (2-Level DCA) - Beli di level 1, DCA di level 2, take profit otomatis
- Recent Orders Table - Order ID, Total, TP Target (editable), format tanggal Indonesia
- Take Profit Editor - Edit profit % langsung di tabel orders, auto-calculate target price
- Cancel Cascade - Cancel L1 → L2 ikut di-cancel otomatis
- Auto-Sync - Orders sync otomatis dari Gate.io saat load
- Webhook Monitoring - Network resilience, circuit breaker, latency logging
- Logs Viewer - Halaman web untuk lihat logs secara visual
- Coin Watchlist - Search token dari Gate.io atau paste contract address
- Custom Token Alias - Mapping nama alternatif ke kode resmi Gate.io
- Multi-chain Support - BSC, ETH, SOLANA, TRON, DOGE
- Loading Effects - Spinner, skeleton, overlay
- Responsive Design - Mobile-friendly
Instalasi
1. Clone Repository
git clone https://git.pi.interka.my.id/alfatha/gate-trade.git
cd gate-trade
2. Setup Environment
cp .env.example .env
Edit .env dan isi credentials Gate.io:
GATE_API_KEY=your_api_key_here
GATE_API_SECRET=your_api_secret_here
3. Inisialisasi Database
php init-db.php
4. Jalankan Server
php -S localhost:8000
Buka http://localhost:8000 di browser.
Struktur Project
trading-gate/
├── config.php # Load .env, konstanta
├── index.php # Dashboard UI
├── cron.php # Background poller
├── init-db.php # Inisialisasi SQLite
├── PRD.html # Dokumentasi PRD
├── DATABASE.html # Dokumentasi database
├── .env.example # Template environment
├── .env # API keys (gitignored)
├── database.sqlite # SQLite database (gitignored)
├── includes/
│ ├── database.php # DB functions
│ └── gate-api.php # Gate.io API class
├── api/
│ ├── balance.php # GET saldo USDT
│ ├── orders.php # GET orders + auto-sync
│ ├── execute.php # POST place order
│ ├── cancel-order.php # POST cancel order + cascade
│ ├── coins.php # CRUD watchlist
│ ├── stats.php # GET statistik
│ ├── ticker.php # GET harga real-time
│ ├── token.php # Search/detect token
│ └── custom-tokens.php # CRUD alias
└── assets/
└── js/app.js # Frontend logic
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/balance.php |
Get USDT balance |
| GET | /api/orders.php?sync=true |
List orders + auto-sync dari Gate.io |
| POST | /api/execute.php |
Place smart order (L1, L2, TP) |
| POST | /api/cancel-order.php |
Cancel order + cascade L1→L2 |
| GET/POST/DELETE | /api/coins.php |
Manage watchlist |
| GET | /api/ticker.php?pair=BTC_USDT |
Get real-time price |
| GET | /api/token.php?action=search&q=doge |
Search token |
| GET/POST/DELETE | /api/custom-tokens.php |
Manage aliases |
2-Level DCA Strategy
Level 1: Beli di harga X
Level 2: DCA di harga X - (X × reduction%)
Take Profit: Jual di X + (X × profit%)
Contoh:
- L1 Price: $0.001
- L2 Reduction: 50% → DCA @ $0.0005
- Target Profit: 100% → Sell @ $0.002
Custom Token Alias
Untuk token yang tidak mudah ditemukan, buat alias mapping:
curl -X POST http://localhost:8000/api/custom-tokens.php \
-H "Content-Type: application/json" \
-d '{"alias":"MYCOIN","currency":"COIN","name":"My Coin Token","chain":"BSC"}'
Cron Job & Webhook (Optional)
Cron Job (2-Level DCA Logic)
* * * * * php /path/to/cron.php >> /var/log/trading-gate.log 2>&1
Webhook for Order Status
# Check orders every minute
* * * * * curl -s http://localhost:9090/api/webhook.php?action=check-orders >> /var/log/webhook.log 2>&1
# Trigger take profit auto-sell (via CLI)
* * * * * php /path/to/gate-trade/api/webhook.php trigger-tp >> /var/log/tp-trigger.log 2>&1
Webhook Actions
| Action | Description |
|---|---|
check-orders |
Check & update order status dari Gate.io |
sync-all |
Sync semua orders dari Gate.io |
status |
Get system status |
trigger-tp |
Auto-detect TP tercapai → simulasi jual gabungan L1+L2 |
execute-tp&pair=X |
Konversi simulasi → jual real di Gate.io |
cancel-expired |
Cancel orders yang sudah expired |
Take Profit Auto-Sell Flow
1. L1 + L2 filled → gabung jadi 1 order jual (total koin)
2. Hitung avg cost = (L1 cost + L2 cost) / total koin
3. Harga market ≥ target TP? → trigger simulasi sell
4. Status order → 'simulated'
5. Notifikasi Telegram otomatis
Logs Viewer
Halaman web untuk melihat logs secara visual:
URL: http://localhost:9090/logs.php
Menu: Klik "Logs" di navbar
Features:
- Circuit Breaker Status - Monitor network health
- Webhook Logs - Order status changes & errors
- Network Latency - Koneksi performance monitoring
- Auto-refresh - Update otomatis setiap 30 detik
- Clear Logs - Hapus semua logs
Order History
Setiap aksi order tercatat di tabel order_history dan tampil di dashboard (section 📜 Order History):
- Order dibuat, pending, di-cancel, status berubah, TP dikonfigurasi/diubah/trigger
- Endpoint:
GET /api/history.php
Dokumentasi
- PRD.html - Product Requirements Document
- DATABASE.html - Database Schema
- doc.html - Webhook & Kondisi Documentation
Catatan Penting
- Minimum order di Gate.io = 3 USDT
- API signature menggunakan format
M\nP\nQ\nH\nT .envdandatabase.sqlitetidak di-commit ke git
License
Private - Internal Use Only