Skip to content

neosun100/tradingview-api-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TradingView API - Python FastAPI Edition

GitHub stars GitHub forks License Python Node.js FastAPI

Real-time market data and technical analysis API service based on TradingView

English | 简体中文 | 繁體中文 | 日本語


🌟 Features

Core Features

  • Real-time market data (K-line/Candlestick data)
  • Multi-market support (Crypto, Stocks, Forex, Futures)
  • Flexible timeframes (1 minute to monthly)
  • Technical analysis indicators
  • Market and indicator search
  • Interactive Swagger documentation

Advanced Features (Requires Token Authentication)

  • Unlimited indicators support
  • Custom/Private indicators retrieval
  • Chart drawings data
  • Invitation-only indicators
  • Backtesting mode
  • Date range data retrieval

🚀 Quick Start

Prerequisites

  • Docker 20.10+ & Docker Compose 2.0+
  • Or: Python 3.11+ and Node.js 18+

Installation

Method 1: Docker Compose (Recommended)

# 1. Clone the repository
git clone https://github.com/Mathieu2301/TradingView-API.git
cd TradingView-API/tradingview-api-python

# 2. Create .env file (optional, for advanced features)
cp .env.example .env
# Edit .env and add your SESSION and SIGNATURE

# 3. Start services
docker-compose up -d

# 4. Access services
# - Swagger Docs: http://localhost:6688/docs
# - Token Manager: http://localhost:6688/

Method 2: Manual Installation

# Install Python dependencies
pip install -r requirements.txt

# Install Node.js dependencies
npm install

# Start Node.js service (Terminal 1)
npm run server

# Start Python service (Terminal 2)
python3 main.py

📚 Documentation

🔌 API Endpoints

Market Data

  • GET /api/search?q={query} - Search markets
  • GET /api/market/{symbol}?timeframe={tf}&bars={n} - Get K-line data
  • GET /api/ta/{symbol} - Get technical analysis

Indicators

  • GET /api/indicators?q={query} - Search indicators
  • GET /api/indicators/{id} - Get indicator details
  • GET /api/indicators/private - Get private indicators (requires auth)
  • POST /api/indicators/values - Get indicator values (requires auth)

Token Management

  • POST /api/token/verify - Verify token
  • POST /api/token/update - Update token
  • GET /api/token/current - Get current token

🐳 Docker Architecture

┌─────────────────────────────────────┐
│  Python FastAPI (Port 6688)        │
│  - Main API Service                 │
│  - Swagger Documentation            │
└──────────────┬──────────────────────┘
               │ HTTP
               ▼
┌─────────────────────────────────────┐
│  Node.js Express (Port 3000)        │
│  - WebSocket Data Source            │
│  - TradingView Connection           │
└─────────────────────────────────────┘

📦 Project Structure

tradingview-api-python/
├── main.py              # FastAPI application entry
├── server.js             # Node.js Express server
├── docker-compose.yml    # Docker orchestration
├── requirements.txt      # Python dependencies
├── package.json         # Node.js dependencies
├── src/                 # Source code
│   ├── api/            # API routes
│   ├── core/           # Core business logic
│   └── utils/          # Utilities
└── token_manager.html   # Token management UI

🔐 Token Management

How to Get Token

  1. Login to TradingView
  2. Open Developer Tools (F12)
  3. Go to Application/Storage → Cookies
  4. Copy sessionidSESSION
  5. Copy sessionid_signSIGNATURE

Token Usage

Option 1: Environment Variables

# .env file
SESSION=your_sessionid
SIGNATURE=your_sessionid_sign

Option 2: Web Interface Visit http://localhost:6688/ for token management UI.

💡 Usage Examples

Python Example

import requests

# Search markets
response = requests.get("http://localhost:6688/api/search", params={"q": "BTCUSDT"})
data = response.json()
print(data)

# Get K-line data
response = requests.get(
    "http://localhost:6688/api/market/BINANCE:BTCUSDT",
    params={"timeframe": "D", "bars": 100}
)
kline_data = response.json()
print(f"Retrieved {len(kline_data['data']['periods'])} candles")

cURL Example

# Search market
curl "http://localhost:6688/api/search?q=BTCUSDT"

# Get K-line data
curl "http://localhost:6688/api/market/BINANCE:BTCUSDT?timeframe=D&bars=100"

🔒 Security

⚠️ Important Security Notes:

  • Never commit .env file to Git (already in .gitignore)
  • Don't hardcode tokens or secrets in code
  • Don't expose real tokens in README, Issues, or PRs
  • Use environment variables or secret management services
  • Regularly rotate tokens and keys

See Security Documentation for more details.

❓ FAQ

Q: How to verify services are running?

docker-compose ps
curl http://localhost:6688/api/search?q=BTCUSDT

Q: Token verification failed?

  • Check .env file contains correct SESSION and SIGNATURE
  • Verify token hasn't expired at http://localhost:6688/
  • Re-fetch token from browser

Q: Can't get private indicators?

  • Ensure valid token is set in .env
  • Verify token at http://localhost:6688/
  • Check Node.js service: docker-compose logs tradingview-nodejs

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Thanks to Mathieu2301 for creating the original TradingView-API project
  • Thanks to all contributors and the community

📞 Support


Made with ❤️ by the community

⬆ Back to Top

About

TradingView API - Python FastAPI version with Docker support, multi-language README, and Swagger documentation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors