Skip to content

Cloudflared with Custom Domain

This documentation outlines how to set up a Cloudflare Tunnel (cloudflared) with Tradeboard to receive TradingView alerts securely on your local machine

1. Overview

A Cloudflare Tunnel creates a secure, outbound-only connection between your local Tradeboard server and the Cloudflare network. This allows TradingView (which is on the public web) to send HTTP POST requests (Webhooks) to your local machine (localhost:5000) securely.


2. Installation

Install cloudflared on your windows machine using powershell:

powershell
# Install via Winget (Windows Package Manager)
winget install Cloudflare.cloudflared

Note: After installation, restart your terminal to ensure the command is recognized.


3. Configuration in Tradeboard

Before starting the tunnel, you must tell Tradeboard what its public address will be.

  1. Open your Tradeboard folder in VS Code.

  2. Open the .env file.

  3. Locate the HOST_SERVER variable and update it with your intended domain:

    dotenv
    HOST_SERVER = 'https://demo.tradeboard.in'

    Update REDIRECT_URL to match, for example https://demo.tradeboard.in/<broker>/callback, and register that same URL with your broker.

  4. Save the file and start Tradeboard with uv run app.py. It listens on port 5000, and the WebSocket proxy on port 8765.


4. Setting Up the Tunnel (Two Options)

This keeps your Webhook URL permanent.

  1. Login to Cloudflare:

    powershell
    cloudflared tunnel login

    A browser window will open. Select your domain to authorize.

  2. Create the Tunnel:

    powershell
    cloudflared tunnel create tradeboard

    This generates a JSON credentials file. Note the path provided in the terminal.

  3. Configure config.yml: In your Tradeboard project, locate or create .cloudflared/config.yml and fill it:

    yaml
    tunnel: <YOUR-TUNNEL-ID>
    credentials-file: C:\Users\<Name>\.cloudflared\<TUNNEL-ID>.json
    
    ingress:
      - hostname: demo.tradeboard.in
        service: http://127.0.0.1:5000
      - service: http_status:404
  4. Route DNS:

    powershell
    cloudflared tunnel route dns tradeboard demo.tradeboard.in
  5. Run the Tunnel:

    powershell
    cloudflared tunnel --config .\.cloudflared\config.yml run tradeboard

Option B: Free Temporary Tunnel (Quick Testing)

If you don't own a domain, you can generate a random public URL.

  1. Run the command:

    powershell
    cloudflared tunnel --url http://127.0.0.1:5000
  2. Cloudflare will generate a URL like https://random-words-generated.trycloudflare.com.

  3. Warning: Every time you restart this tunnel, the URL will change. You will have to update your TradingView Webhook URL and .env file accordingly.


5. Integrating with TradingView

Once the tunnel is "Active" in your terminal:

  1. Get Webhook URL: Your URL will be https://yourdomain.com/api/v1/placeorder.
  2. Generate Payload:
    • Go to Tradeboard Local Dashboard -> Platforms -> TradingView.
    • Configure your symbol (e.g., SILVERMARFUT), action (BUY), and quantity.
    • Click Generate JSON and Copy the code.
  3. Create Alert in TradingView:
    • Set your Condition (e.g., Price Crossing).
    • Under Notifications, check Webhook URL and paste your tunnel URL.
    • Under Message, paste the JSON payload generated by Tradeboard.

6. Verification & Performance

  • Order Book: When the alert triggers, check the Order Book tab in Tradeboard to see the executed trade.
  • Latency Monitor: Go to Logs -> Latency Monitor.
    • Cloudflare Tunnels typically offer latency between 150ms to 300ms, which is faster than Ngrok or Pagekite in many regions.
  • Security: Because the tunnel is outbound-only, your local IP address remains hidden from the public internet.

7. Troubleshooting

  • 404 Error: Ensure the service URL in config.yml matches the port Tradeboard is running on (default is 5000).
  • HTTPS Requirement: TradingView requires an https URL. Ensure you use the Cloudflare provided link and not your local IP.
  • Tunnel Fails to Start: Check if another instance of cloudflared is running in the background.