DEV Community

Anders
Anders

Posted on

How to add pre-trade risk scoring to your LangChain crypto agent in 2 lines

If you're building a crypto trading agent with LangChain, your agent probably makes buy/sell decisions based on price data, sentiment, or technical indicators. But does it check if the token is about to structurally collapse?

The problem

In 2024-2025, 113 tokens experienced structural collapse (>50% drawdown). Many showed clear warning signs in their on-chain and market microstructure data — but most trading agents don't check for this.

The solution: 2 lines

from zarq_langchain import ZARQRiskCheck

tools = [ZARQRiskCheck()]  # Add to your agent's tool list
Enter fullscreen mode Exit fullscreen mode

Your agent now has access to ZARQ's risk intelligence for 205 tokens:

  • Verdict: SAFE / WARNING / CRITICAL
  • Trust Score: 0-100 (Moody's-style Aaa-D rating)
  • Crash Probability (calibrated on 22 months out-of-sample data)
  • Distance to Default (Merton structural credit model)

What's under the hood?

ZARQ rates tokens using 7 structural signals:

  1. Liquidity stress — is trading volume drying up?
  2. Holder concentration — are whales dumping?
  3. Resilience decay — does the token recover from drawdowns?
  4. Fundamental weakness — development activity, TVL trends
  5. Contagion risk — correlated token failures
  6. Structural fragility — market microstructure breakdown
  7. Relative weakness — underperforming sector peers

When 3+ signals fire simultaneously, ZARQ issues a Structural Collapse warning. Out-of-sample: 113/113 token deaths caught, 98% precision.

Full example

from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from zarq_langchain import ZARQRiskCheck

llm = ChatOpenAI(model="gpt-4")
tools = [ZARQRiskCheck()]
agent = initialize_agent(tools, llm, agent=AgentType.OPENAI_FUNCTIONS)

result = agent.run("Should I buy solana? Check the risk first.")
print(result)
Enter fullscreen mode Exit fullscreen mode

Also available as

  • MCP Server (11 tools): Smithery
  • ElizaOS plugin: npm install @zarq/elizaos-plugin
  • Raw API: curl https://zarq.ai/v1/check/bitcoin (free, no auth)

Links

Top comments (0)