No description
  • PHP 47.5%
  • HTML 29.4%
  • JavaScript 17.1%
  • Hack 4%
  • CSS 2%
Find a file
2026-09-30 13:50:21 +07:00
api fix(takeprofit): update price/amount/total on TP row when target sell price edited 2026-09-30 13:50:21 +07:00
assets fix(tp-modal): bind calculateTpPrice via JS too, works even with cached old index.php 2026-09-30 13:47:03 +07:00
css feat: add unknown status handling, auto-cleanup, and status badge styling 2026-09-28 21:33:46 +07:00
includes fix(gate-api): formatDecimal prevents scientific notation for tiny prices (SHIB 4.76E-6 rejected) 2026-09-30 13:29:52 +07:00
.env.example Add webhook system, Telegram notifications, order history, take profit auto-sell & dashboard improvements 2026-09-25 17:14:48 +07:00
.gitignore Add webhook system, Telegram notifications, order history, take profit auto-sell & dashboard improvements 2026-09-25 17:14:48 +07:00
config.php chore: PHP 8.5 - suppress deprecation notices from API output, log them instead 2026-09-28 23:28:37 +07:00
cron.php feat: add custom token aliases, 2-level DCA, profit simulation, UI improvements 2026-09-21 03:17:19 +07:00
DATABASE.html fix: responsive mobile layout - grid stack, smaller padding, heading sizes 2026-09-28 11:07:55 +07:00
doc.html fix: add overflow-x-auto to telegram events table 2026-09-28 11:15:38 +07:00
index.php fix(tp-modal): live update Target Sell Price while typing profit % (oninput) 2026-09-30 13:44:50 +07:00
init-db.php feat: add custom token aliases, 2-level DCA, profit simulation, UI improvements 2026-09-21 03:17:19 +07:00
logs.php style: standardize navbar across all pages to match index.php 2026-09-25 17:46:01 +07:00
memory.md feat: check-orders runs full pipeline - auto-sell on TP target + place TP order + telegram notify 2026-09-25 17:30:14 +07:00
PRD.html fix: responsive mobile layout - grid stack, smaller padding, heading sizes 2026-09-28 11:07:55 +07:00
PRD.md Remove USDC, clean up form UI, add total cost calculator 2026-09-21 16:04:07 +07:00
README.md Add webhook system, Telegram notifications, order history, take profit auto-sell & dashboard improvements 2026-09-25 17:14:48 +07:00

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

Catatan Penting

  • Minimum order di Gate.io = 3 USDT
  • API signature menggunakan format M\nP\nQ\nH\nT
  • .env dan database.sqlite tidak di-commit ke git

License

Private - Internal Use Only