Skip to main content

3 posts tagged with "python"

View all tags

Structured Concurrency for AI Pipelines: Why asyncio.gather() Isn't Enough

· 9 min read
Tian Pan
Software Engineer

When an LLM returns three tool calls in a single response, the obvious thing is to run them in parallel. You reach for asyncio.gather(), fan the calls out, collect the results, return them to the model. The code works in testing. It works in staging. Six weeks into production, you start noticing your application holding open HTTP connections it should have released. Token quota is draining faster than usage metrics suggest. Occasionally, a tool that sends an email fires twice.

The underlying issue is not the LLM or the tool — it's the concurrency primitive. asyncio.gather() was not designed for the failure modes that multi-step agent pipelines produce, and using it as the backbone of parallel tool execution creates problems that are invisible until they compound.

Why Your Agent Should Write Code, Not JSON

· 10 min read
Tian Pan
Software Engineer

Most agent frameworks default to the same action model: the LLM emits a JSON blob, the host system parses it, calls a tool, returns the result. Repeat. It's clean, auditable, and almost universally used — which is exactly the problem. For anything beyond a single tool call, this architecture forces you to write scaffolding code that solves problems the agent could solve itself, if only it were allowed to write code.

There's a different approach: give the agent a Python interpreter and let it emit executable code as its action. One published benchmark shows a 20% higher task success rate over JSON tool-calling. An internal benchmark shows 30% fewer LLM round-trips on average. A framework built around this idea hit #1 on the GAIA leaderboard (44.2% on validation) shortly after release. The tradeoff is a more complex execution environment — but the engineering required is tractable, and the behavioral gains are real.

TradingView vs. Build-Your-Own: A Software Engineer’s Guide to Algorithmic Trading Tools

· 6 min read

For a software engineer, the world of algorithmic trading is a natural fit—a domain where logic, data, and automation reign supreme. But before you can build the next great trading bot, you face a crucial first choice: which tools do you use? Do you opt for a sleek, all-in-one platform like TradingView, or do you dive into the deep, flexible universe of Python?

This post breaks down the core trade-offs from an engineer's perspective, helping you choose the right path for your trading ambitions.

🚀 The "All-in-One" Powerhouse: TradingView & Pine Script

TradingView is famous for its world-class interactive charts and massive social community. At its heart is Pine Script, a proprietary, domain-specific language (DSL) purpose-built for creating trading indicators and strategies.

Key Strengths:

  • Painless Onboarding: Pine Script is designed for time-series analysis. Its syntax is simple, allowing you to implement complex indicators like a moving average with a single line: ta.sma(close, 14).
  • Instant Visualization: This is TradingView's killer feature. You write code in the Pine Editor, click "Add to Chart," and instantly see your strategy's buy/sell signals visualized on the data. This tight feedback loop makes for incredibly rapid prototyping and visual validation.
  • Massive Community & Codebase: With over 150,000 community-published scripts, you can find, study, and adapt a vast library of indicators and strategies. It's a goldmine for learning and inspiration.
  • Built-in Backtesting & Alerts: By declaring a script as a strategy(), you unlock a built-in backtester that provides a detailed performance report (net profit, max drawdown, win rate, etc.). The powerful alert system can send signals via webhooks, forming a bridge to semi-automated trading.

The Catch:

  • Limited Extensibility: Pine Script is a sandboxed environment. You cannot import external libraries, make network requests, or read local files. This makes integrating machine learning models, alternative data, or other complex logic nearly impossible.
  • No Native Autotrading: This is the most critical limitation. TradingView does not natively execute your strategy's signals with a broker. The common workaround is to use alerts and webhooks to trigger an external service (which you have to build or subscribe to) that places orders via your broker's API.

The Insight: TradingView is the ultimate on-ramp to algorithmic trading. It’s built for speed of iteration and visualization. It’s the perfect environment for developing and validating ideas, especially those based on technical analysis.

🐍 The "Build-Your-Own" Universe: The Python Ecosystem (Backtrader & Qlib)

For engineers who demand ultimate control and flexibility, the Python ecosystem is the logical destination. Open-source frameworks like Backtrader and Qlib give you the power to build a completely custom trading infrastructure from the ground up.

Key Strengths:

  • Infinite Flexibility: You can leverage the entire Python universe. Use Pandas for data manipulation, NumPy for high-speed calculations, and Scikit-learn or PyTorch to generate signals from machine learning models.
  • Total Data Control: Bring your own data. Whether from CSV files, a custom database, or an alternative data API, you are not confined to the platform's offerings. This is crucial for testing unconventional strategies.
  • Granular Backtesting & Live Trading:
    • Backtrader: A mature, event-driven framework that supports portfolio-level backtesting across multiple assets and timeframes. Critically, it can connect directly to brokers like Interactive Brokers for fully automated live trading.
    • Qlib: An AI-focused platform from Microsoft designed for end-to-end quantitative research. It excels at data management, feature engineering, and evaluating complex ML-driven portfolio strategies.
  • Free & Open Source: These frameworks are free, with no licensing fees. You have full access to the source code and can modify the core engine to fit your exact needs.

The Challenge:

  • Steep Learning Curve: You are responsible for everything—data sourcing and cleaning, indicator logic, backtesting engine setup, visualization, and the live trading infrastructure. This requires a significant investment of time and effort.
  • Reinventing the Wheel: The beautiful charts and performance reports that TradingView provides with one click might require you to write dozens of lines of matplotlib or Plotly code in Python.

The Insight: Python gives you absolute power, but with it comes total responsibility. It's the right choice for serious traders and researchers whose needs have outgrown off-the-shelf platforms and who require deep customization.

📊 How to Choose: A Clear Path Forward

So, which path should you take? The answer depends entirely on your goals and resources.

1. For Initial Exploration → Start with TradingView

If you are new to algorithmic trading or simply want to validate ideas quickly: Start with TradingView. Its instant feedback and visual nature are unparalleled. You can focus purely on strategy logic without getting bogged down in building infrastructure. It's the fastest way to learn what works and what doesn't.

2. For Automation and Customization → Graduate to Python

It's time to move to Python when you find that:

  • Your strategy requires external data or a machine learning model.
  • You want fully automated, hands-off live trading, not a webhook-based workaround.
  • You need to run complex, portfolio-level backtests across many assets.
  • You're hitting the platform's limits on historical data, alerts, or script complexity.

3. For the Best of Both Worlds → The Hybrid Approach

This is a highly effective and popular workflow used by many practitioners:

  • Research & Prototype in TradingView: Use its superior charting tools and massive script library to rapidly develop and validate your initial strategy idea.
  • Execute in Python: Once a strategy proves promising, re-implement its logic in Python. Then, use TradingView's webhook alerts to send signals to a Python script running on a server, which then places trades via your broker's API.

This approach combines the development speed of TradingView with the execution power and flexibility of Python.

Conclusion

TradingView and Python are not mutually exclusive competitors; they are tools for different stages of the algorithmic trading journey.

  • TradingView is a fantastic all-in-one platform that integrates data, charting, development, and community. It’s the perfect starting point and a powerful analysis tool.
  • Python is an ecosystem of limitless potential. It’s the foundation for building professional, complex, and truly automated trading systems.

As an engineer, the best approach is to understand the core trade-off—convenience versus control. Start with TradingView for its speed, and when your ambitions outgrow its walls, you'll be well-equipped to graduate to the power of Python, perhaps even using them together to create your optimal trading system.