# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: unCoded Trading Bot
spec:
    description: Professional self-hosted crypto trading bot. Keep full control over your API keys — no custodial risk, no shared data. Deploy in minutes with 150+ indicators, Trailing Stop Loss, Automatic DIP Rebuying. Telegram control and TradingView webhook support included. Built for serious traders who want automation without sacrificing sovereignty.
    coverImage: https://uncoded.ch/og-image.png
    icon: https://raw.githubusercontent.com/UnCodedTradingBot/unCoded/refs/heads/main/CICD_unCoded/unCoded_Logo_New/unCoded_Ohne_Schrift.svg
    variables:
        - key: API_KEY
          type: STRING
          name: Exchange API Key
          description: Exchange API Key - from your exchange's API management (enable Spot and Margin trading)
        - key: API_SECRET
          type: STRING
          name: Exchange API Secret
          description: Exchange API Secret - keep confidential, never share or commit to Git
        - key: APP_PASSWORD
          type: STRING
          name: Dashboard App Password
          description: Dashboard App Password - master password for full dashboard access
        - key: VIEWER_PASSWORD
          type: STRING
          name: Dashboard Viewer Password
          description: Dashboard Viewer Password - read-only password, use any placeholder if not needed
        - key: TELEGRAM_BOT_TOKEN
          type: STRING
          name: Telegram Bot Token
          description: Telegram Bot Token - from BotFather on Telegram, set to 0 to disable
        - key: TELEGRAM_GROUP_ID
          type: STRING
          name: Telegram Group ID
          description: Telegram Group ID - from userinfobot, set to 0 to disable
        - key: TRADINGVIEW_WEBHOOK_SECRET
          type: STRING
          name: TradingView Webhook Secret
          description: TradingView Webhook Secret - random secret string for authenticating TradingView alerts
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Dashboard Domain
          description: Dashboard Domain - public domain for the unCoded dashboard (e.g. dashboard-xyz.zeabur.app)
        - key: SIGNAL_DOMAIN
          type: DOMAIN
          name: Signal Bot Domain
          description: Signal Bot Domain - public domain for TradingView webhooks (e.g. signal-xyz.zeabur.app)
    tags:
        - crypto trading bot
        - trading bot
        - tool
        - automation
    readme: |
        # unCoded Trading Bot

        Professional self-hosted crypto trading bot. Non-custodial by design — your API keys stay in your deployment, your funds stay on your exchange, and you retain full control over every trade decision.

        Built for traders who want institutional-grade automation without handing their capital or keys to a third party.

        ## Why unCoded

        - **Non-custodial** — API keys live only in your deployment, never touch our servers
        - **Self-hosted** — your infrastructure, your data, your rules
        - **Production-tested** — running live on real capital by real traders since 2020
        - **Transparent** — you see every trade, every indicator, every decision in your own dashboard
        - **No subscriptions to our cloud** — you pay for hosting, not for access

        ## Core Features

        ### Trading Engine
        - 150+ technical indicators including RSI, MACD, Bollinger Bands, Stochastic, Ichimoku, ADX, VWAP, and dozens of custom derivatives
        - Multi-symbol trading with per-pair configuration
        - Spot and margin support
        - Configurable order types — market, limit, and hybrid execution
        - Fee-aware profit calculation with exchange-specific adjustments

        ### Risk Management
        - **Trailing Stop Loss** with custom activation curves — tighten as profit grows
        - **Automatic DIP Rebuying** — accumulate more at lower prices, reduce average entry
        - **Sell Time Curves** — time-weighted exit logic based on how long a position has been open
        - **Kelly Criterion position sizing** — mathematically optimal capital allocation per trade
        - Hard stop-loss and take-profit overrides
        - Maximum concurrent position limits

        ### Signal Integration
        - **TradingView webhook support** — connect any Pine Script alert to your bot
        - Webhook secret authentication to prevent unauthorized signals
        - Signal filtering and validation before execution
        - Compatible with popular indicator sets and custom strategies

        ### Monitoring and Control
        - **Web dashboard** with real-time position view, P&L tracking, and trade history
        - **Telegram bot** for notifications and remote control — start, stop, and query from your phone
        - Detailed logging for every action, retry, and exchange response
        - Tax export for your jurisdiction's reporting requirements

        ## Services Deployed

        This template deploys five integrated services:

        | Service | Purpose |
        |---------|---------|
        | unCodedDatabase | PostgreSQL 18 — trade history, config, and state |
        | unCodedTradingBot | Core trading engine, executes orders |
        | unCodedDashboard | Web UI for monitoring and configuration |
        | unCodedTelegramBot | Telegram notifications and remote commands |
        | unCodedSignalBot | TradingView webhook receiver |

        All services are pre-wired with dependencies, networking, and environment variables. Postgres password is auto-generated securely.

        ## Recommended Resources

        - **Minimum**: 2 vCPU / 4 GB RAM
        - **Recommended**: 4 vCPU / 8 GB RAM

        Heavier workloads — multi-symbol setups, high indicator counts, or tight trading intervals — benefit from more RAM.

        ## Setup in 3 Minutes

        1. **Create your exchange API key**
           Enable Spot and Margin trading permissions. For security, restrict by IP where supported. Never enable withdrawal permissions.

        2. **Optional — Create a Telegram bot**
           Message BotFather on Telegram with `/newbot`, save the token. Use `/myid` via userinfobot to get your group ID. Set tokens to `0` if you want to skip Telegram entirely.

        3. **Set strong dashboard passwords**
           App Password for full access, Viewer Password for read-only monitoring (share safely with accountability partners).

        4. **Deploy**
           Fill in the variables, pick a region close to your exchange's servers for lowest latency, and click Deploy. All five services start in sequence automatically.

        5. **Access your dashboard**
           Once deployed, check the Instructions tab on the Dashboard service for your login URL, or open the Dashboard Domain URL directly.

        6. **Configure TradingView webhooks** (optional)
           Check the Instructions tab on the Signal Bot service for your webhook URL and secret. Paste these into your TradingView alert configuration.

        ## Recommended Regions

        Low latency to the exchange matters for execution quality. Choose a region geographically close to your exchange's matching engine:

        - **Asia-based exchanges** — Tokyo, Singapore, Hong Kong
        - **US-based exchanges** — Virginia, N. California
        - **EU-based exchanges** — Frankfurt, Amsterdam

        ## Security Notes

        - API keys are stored as environment variables, visible only inside your own Zeabur account
        - PostgreSQL is reachable only through the internal private network
        - The Dashboard is protected by your App Password, served over HTTPS automatically
        - The Signal Bot authenticates incoming webhooks via a shared secret
        - Never commit your API keys, tokens, or passwords to Git or share them in screenshots

        ## Version and Updates

        This template pins image version `:10` for stability. To upgrade, change the image tag in the service's Settings → Image Source, not by switching to `:latest` which may introduce breaking changes.

        ## Documentation and Support

        - Full documentation, indicator reference, and strategy guides: **https://uncoded.ch/docs**
        - Platform and community: **https://uncoded.ch**
        - unCoded backtesting: **https://uncoded.ch/backtesting**

        ## Disclaimer

        Automated trading involves financial risk. Past performance does not guarantee future results. Run the bot in paper-trading or with small capital until you fully understand its behavior. You are responsible for your own trades, taxes, and compliance with your local regulations.

        ---

        Deploy once, trade automated forever. Welcome to sovereign-grade crypto automation.
    resourceRequirement:
        minConfig:
            cpu: 4
            ram: 8
        recommendedConfig:
            cpu: 8
            ram: 16
    services:
        - name: unCodedDatabase
          icon: https://cdn.zeabur.com/marketplace/postgresql.svg
          template: PREBUILT_V2
          spec:
            id: postgresql
            source:
                image: postgres:18
                command:
                    - docker-entrypoint.sh
                    - -c
                    - config_file=/etc/postgresql/postgresql.conf
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/18/docker
            instructions:
                - title: Connection String
                  content: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}
                - title: PostgreSQL Host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: PostgreSQL Port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
                - title: PostgreSQL Database
                  content: ${POSTGRES_DATABASE}
                - title: PostgreSQL Username
                  content: ${POSTGRES_USERNAME}
                - title: PostgreSQL Password
                  content: ${POSTGRES_PASSWORD}
            env:
                PGDATA:
                    default: /var/lib/postgresql/18/docker/pgdata
                    expose: false
                POSTGRES_CONNECTION_STRING:
                    default: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                    expose: true
                POSTGRES_DATABASE:
                    default: ${POSTGRES_DB}
                    expose: true
                POSTGRES_DB:
                    default: uncoded_db
                    expose: false
                POSTGRES_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                POSTGRES_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                POSTGRES_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                POSTGRES_URI:
                    default: ${POSTGRES_CONNECTION_STRING}
                    expose: true
                POSTGRES_USER:
                    default: postgres
                    expose: false
                POSTGRES_USERNAME:
                    default: ${POSTGRES_USER}
                    expose: true
            configs:
                - path: /etc/postgresql/postgresql.conf
                  template: |
                    listen_addresses = '*'
                    max_connections = 256
                    shared_buffers = 256MB
                    dynamic_shared_memory_type = posix
                    max_wal_size = 1GB
                    min_wal_size = 80MB
                    log_timezone = 'UTC'
                    datestyle = 'iso, mdy'
                    timezone = 'UTC'
                    lc_messages = 'en_US.UTF-8'
                    lc_monetary = 'en_US.UTF-8'
                    lc_numeric = 'en_US.UTF-8'
                    lc_time = 'en_US.UTF-8'
                    default_text_search_config = 'pg_catalog.english'
                  permission: null
                  envsubst: null
            portForwarding:
                enabled: true
        - name: unCodedTradingBot
          icon: https://cdn.zeabur.com/prebuilt.svg
          dependencies:
            - unCodedDatabase
          template: PREBUILT_V2
          spec:
            id: uncodedtradingbot
            source:
                image: docker.io/aureumvictoria/uncoded-trading-bot:10
            instructions:
                - title: Trading Bot Status
                  content: Running in background - check Logs tab for trading activity
                - title: Database Connection
                  content: Uses internal private network to unCodedDatabase service
            configs: []
            portForwarding:
                enabled: false
        - name: unCodedDashboard
          icon: https://cdn.zeabur.com/prebuilt.svg
          dependencies:
            - unCodedDatabase
          template: PREBUILT_V2
          spec:
            id: uncodeddashboard
            source:
                image: docker.io/tbotteam/uncoded-js-frontend:cloud
            ports:
                - id: port-4000
                  port: 4000
                  type: HTTP
            instructions:
                - title: Dashboard URL
                  content: https://${PUBLIC_DOMAIN}
                - title: App Password
                  content: ${APP_PASSWORD}
                - title: Viewer Password
                  content: ${VIEWER_PASSWORD}
            env:
                PORT:
                    default: "4000"
                    expose: false
            configs: []
            portForwarding:
                enabled: false
          domainKey: PUBLIC_DOMAIN
        - name: unCodedTelegramBot
          icon: https://cdn.zeabur.com/prebuilt.svg
          dependencies:
            - unCodedDatabase
            - unCodedTradingBot
          template: PREBUILT_V2
          spec:
            id: uncodedtelegrambot
            source:
                image: docker.io/aureumvictoria/uncoded-telegram-bot:10
            instructions:
                - title: Telegram Bot Token
                  content: ${TELEGRAM_BOT_TOKEN}
                - title: Telegram Group ID
                  content: ${TELEGRAM_GROUP_ID}
                - title: Setup Guide
                  content: Message your bot with /start in Telegram to verify connection
            env:
                TELEGRAM_OWNER_ID:
                    default: "0"
                    expose: false
            configs: []
        - name: unCodedSignalBot
          icon: https://cdn.zeabur.com/prebuilt.svg
          dependencies:
            - unCodedDatabase
          template: PREBUILT_V2
          spec:
            id: uncodedsignalbot
            source:
                image: docker.io/aureumvictoria/uncoded-signal-bot:10
            ports:
                - id: port-3000
                  port: 3000
                  type: HTTP
            instructions:
                - title: TradingView Webhook URL
                  content: https://${SIGNAL_DOMAIN}/webhook
                - title: Webhook Secret
                  content: ${TRADINGVIEW_WEBHOOK_SECRET}
                - title: TradingView Alert Setup
                  content: Paste the Webhook URL into TradingView Alert Webhook field, include the secret in your JSON payload
            configs: []
            portForwarding:
                enabled: false
          domainKey: SIGNAL_DOMAIN
