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:
# Install via Winget (Windows Package Manager)
winget install Cloudflare.cloudflaredNote: 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.
Open your Tradeboard folder in VS Code.
Open the
.envfile.Locate the
HOST_SERVERvariable and update it with your intended domain:dotenvHOST_SERVER = 'https://demo.tradeboard.in'Update
REDIRECT_URLto match, for examplehttps://demo.tradeboard.in/<broker>/callback, and register that same URL with your broker.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)
Option A: Custom Domain (Recommended for Production)
This keeps your Webhook URL permanent.
Login to Cloudflare:
powershellcloudflared tunnel loginA browser window will open. Select your domain to authorize.
Create the Tunnel:
powershellcloudflared tunnel create tradeboardThis generates a JSON credentials file. Note the path provided in the terminal.
Configure
config.yml: In your Tradeboard project, locate or create.cloudflared/config.ymland fill it:yamltunnel: <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:404Route DNS:
powershellcloudflared tunnel route dns tradeboard demo.tradeboard.inRun the Tunnel:
powershellcloudflared 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.
Run the command:
powershellcloudflared tunnel --url http://127.0.0.1:5000Cloudflare will generate a URL like
https://random-words-generated.trycloudflare.com.Warning: Every time you restart this tunnel, the URL will change. You will have to update your TradingView Webhook URL and
.envfile accordingly.
5. Integrating with TradingView
Once the tunnel is "Active" in your terminal:
- Get Webhook URL: Your URL will be
https://yourdomain.com/api/v1/placeorder. - 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.
- 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
serviceURL inconfig.ymlmatches the port Tradeboard is running on (default is5000). - HTTPS Requirement: TradingView requires an
httpsURL. Ensure you use the Cloudflare provided link and not your local IP. - Tunnel Fails to Start: Check if another instance of
cloudflaredis running in the background.
