News-Driven Trading Agent: Powered by Polygon MCP & 1inch APIs
Cryptocurrency markets are highly responsive to social media statements from influential figures like Vitalik Buterin or Donald Trump. For instance, on April 3, 2025, when Justin Sun criticized FUSDT, it triggered significant de-pegging. However, once the FUSDT team provided clarification, the price quickly returned to its pegged value. This volatility creates substantial arbitrage opportunities for traders who can quickly react to news and statements from media outlets and key opinion leaders (KOLs).
The challenge is that a single person cannot effectively monitor all relevant news sources and KOLs across various platforms, leading to missed trading opportunities.
NewsQuantar is a sophisticated solution that leverages AI agents to monitor news and statements from media outlets and influential figures on social media and automatically execute trading decisions on the Polygon blockchain. By combining natural language processing with blockchain technology, the system can identify market-moving information and execute trades faster than human traders.
A TypeScript implementation of the Polygon Model Context Protocol that enables:
A Python SDK for Farcaster event monitoring that provides:
A standalone interactive CLI for blockchain operations that:
The core trading engine that:
Our News Quantar project is built on a three-tier architecture that combines blockchain interaction capabilities with natural language processing and social media monitoring:
We forked the official Polygon MCP and made several critical enhancements. The Polygon MCP serves as the essential execution layer for our agent - functioning as its "hands and feet" in the blockchain world. Without this component, our intelligent agent would be unable to interact with the blockchain or execute trades, making it the foundational element that enables the entire system to function effectively.
1inch Swap Integration: We implemented a comprehensive swap handler (inchSwapHandler
) that connects to the 1inch API for optimal trading routes and best execution prices. The integration includes:
Token Management Tools: We added specialized handlers for:
checkAllowanceHandler
: Verifies if sufficient token approvals existapproveTokenHandler
: Streamlines the token approval processgetTokenDecimalsHandler
: Ensures accurate decimal handling across different tokensWe built our agent using the Fast-Agent framework, which provides a clean abstraction for LLM-powered applications. Our implementation includes:
Dual-mode Operation:
chat.py
: A direct interface for manual blockchain interactions through natural languagequantar.py
: An automated trading agent that processes Farcaster messages and executes trades based on social signalsPrompt Engineering: We carefully crafted system instructions that:
Claude 3.7 Sonnet Integration: We integrated with Claude's API for advanced natural language understanding, using the endpoint at https://chat.cloudapi.vip/v1
We developed a lightweight but robust webhook service using FastAPI that:
/webhook
endpoint to receive Farcaster eventsWe implemented a comprehensive security approach:
.env
files and excluded from gitfastagent.config.yaml
for non-sensitive configuration and load sensitive data from environment variablesTOKEN_ADDRESSES
dictionary with verified addresses to prevent using incorrect or deprecated tokensUSDC.e Protection: We implemented multiple safeguards to prevent the use of USDC.e, including:
DO_NOT_USE
in the token dictionaryWebhook Event Deduplication: We created a simple but effective event ID generation system using event_type_created_at
to prevent duplicate processing without needing a database
Decimal Precision Handling: We added explicit reminders about token decimal differences in agent instructions and implemented a dedicated tool to verify token decimals before calculations
The combination of these components creates a system that can monitor social media for trading signals, analyze them using advanced AI, and execute trades automatically with built-in safety mechanisms.