29 - Ngrok Configuration

Overview

Ngrok creates secure tunnels to expose your local OpenAlgo instance to the internet, enabling webhook integrations from TradingView, Chartink, and other external services.

Architecture Diagram

┌──────────────────────────────────────────────────────────────────────────────┐
│                          Ngrok Tunnel Architecture                           │
└──────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│                        External Services                                     │
│                                                                              │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐             │
│  │  TradingView    │  │   Chartink      │  │   GoCharting    │             │
│  │   Webhooks      │  │   Webhooks      │  │   Webhooks      │             │
│  └────────┬────────┘  └────────┬────────┘  └────────┬────────┘             │
│           │                    │                    │                       │
│           └────────────────────┼────────────────────┘                       │
│                                │                                             │
│                                ▼                                             │
│               https://your-domain.ngrok.io                                  │
└─────────────────────────────────────────────────────────────────────────────┘

                                 │ Secure Tunnel

┌─────────────────────────────────────────────────────────────────────────────┐
│                          Ngrok Client                                        │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │  ngrok http 5000                                                     │   │
│  │                                                                      │   │
│  │  - Encrypted tunnel                                                  │   │
│  │  - HTTPS termination                                                 │   │
│  │  - Request inspection                                                │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────────────┐
│                       OpenAlgo (localhost:5000)                              │
│                                                                              │
│  POST /api/v1/placeorder                                                    │
│  POST /api/v1/webhook/{strategy_id}                                         │
└─────────────────────────────────────────────────────────────────────────────┘

Configuration

Environment Variables

Setup Steps

1. Create Ngrok Account

  1. Go to https://ngrok.com

  2. Sign up for free account

  3. Copy your auth token

2. Configure OpenAlgo

3. Start OpenAlgo

Ngrok starts automatically and displays the public URL:

Custom Domain (Paid Feature)

Configuration

Benefits

  • Consistent URL (doesn't change on restart)

  • Professional appearance

  • Better for production webhooks

Implementation

Manager Class

Cleanup Handling

Webhook Configuration

TradingView Webhook URL

Webhook Payload

Troubleshooting

Common Issues

Issue
Solution

Tunnel not starting

Check NGROK_AUTH_TOKEN

Connection refused

Ensure OpenAlgo is running

URL changes on restart

Use custom domain

Rate limiting

Upgrade ngrok plan

Debug Mode

Security Considerations

HTTPS Only

Ngrok provides HTTPS by default. Always use the https:// URL for webhooks.

API Key Validation

All webhook requests must include valid API key:

IP Filtering (Optional)

For additional security, whitelist TradingView IPs:

Platform Support

Windows

macOS/Linux

Key Files Reference

File
Purpose

utils/ngrok_manager.py

Ngrok management

.env

Configuration

app.py

Startup integration

Last updated