data-tools
spoon_toolkits.crypto.crypto_data_tools is SpoonAI’s Bitquery-centric toolbox for price discovery, liquidity intelligence, lending-rate aggregation, and wallet forensics. Every class in this package plugs directly into the Spoon tool runtime, so agents can reuse the same BaseTool lifecycle (validation, structured outputs, telemetry) without additional glue code.
Environment & Dependencies
export BITQUERY_API_KEY=your_rest_key # reserved for future REST helpers
export BITQUERY_CLIENT_ID=your_oauth_client_id # required by Bitquery OAuth
export BITQUERY_CLIENT_SECRET=your_oauth_secret
export RPC_URL=https://eth.llamarpc.com
Get*price tools pull the RPC URL from the environment automatically; alert helpers default to a bundled Alchemy mainnet URL unless you pass a custom endpoint when instantiating them.PredictPricerequirespandas,scikit-learn, andnumpy. Install toolkit extras viapip install -r requirements.txtat the project root or install modules individually.LendingRateMonitorToolperforms concurrent HTTP requests usingaiohttp; event loops must be active (usenest_asyncioin notebooks if necessary).SuddenPriceIncreaseToolcurrently relies exclusively on CoinGecko’s REST feed; the Bitquery enrichment hook exists in code but is not wired up yet, so providingBITQUERY_API_KEYhas no effect today.
Tool Catalog
Spot & Historical Pricing
GetTokenPriceToolresolves supported ERC-20 pairs (ETH, USDC, USDT, DAI, WBTC by default) to the canonical Uniswap v3 pool, fetches slot0, and converts ticks into human prices.Get24hStatsTooluses the same provider stack for downstream analytics, whileGetKlineDataToolis currently a placeholder that returns an empty list until a Graph/event-log integration ships.
Alerting & Monitoring
PriceThresholdAlertToolcompares live prices with a configurable ±% drift versus prior day.LpRangeCheckToolreads Uniswap positions, current ticks, and warns when LPs approach range boundaries (buffer_ticks).SuddenPriceIncreaseToolfilters CoinGecko’s REST feed for large-cap, high-volume tokens with rapid appreciation; Bitquery enrichment is planned but not enabled.CryptoMarketMonitorPOSTs well-formed payloads to the monitoring daemon bundled athttp://localhost:8888/monitoring/tasks(blockchain_monitor.py). Change the URL in that module if your scheduler lives elsewhere.
Wallet Intelligence
WalletAnalysis,TokenHolders, andTradingHistoryshare the Bitquery GraphQL templates embedded in their modules so you always know the dataset (combinedvsarchive) and filters before execution.- Pagination and filters live directly inside each template string (e.g.,
TokenHoldersenforcesAmount >= 10,000,000). Edit the template if you need a different threshold or window; no exposed class constants exist today. These helpers return the Bitquery JSON fragments directly rather than wrapping results inToolResult.
DeFi Rates & Liquidity
LendingRateMonitorToolmerges DeFiLlama pools with first-party Aave subgraphs today (Compound/Morpho data arrives via DeFiLlama’s feed only), derives utilization, and wraps the result inToolResult. Every response also includes anarbitrage_opportunitiesarray summarizing large APY spreads.UniswapLiquidityemits the latest Mint/Burn events so you can approximate real-time liquidity deltas without running a listener yourself.PredictPriceis intentionally heavyweight (builds a RandomForest and scaler); cache the fitted estimator in your application if you call it frequently.
Usage Patterns
Synchronous price lookup
from spoon_toolkits.crypto.crypto_data_tools import GetTokenPriceTool
tool = GetTokenPriceTool()
result = await tool.execute(symbol="ETH-USDC")
print(result.output["price"]) # structured response
Long-running alert inside an agent
import asyncio
from spoon_toolkits.crypto.crypto_data_tools import PriceThresholdAlertTool
alerts = PriceThresholdAlertTool()
async def monitor():
while True:
tool_result = await alerts.execute(symbol="ETH-USDC", threshold_percent=7)
if tool_result.output.get("exceeded"):
await send_notification(tool_result.output["message"])
await asyncio.sleep(60)
asyncio.run(monitor())
Tips:
- Synchronous price tools return dictionaries nested inside
ToolResult.output, whereas the Bitquery GraphQL helpers (WalletAnalysis,TokenHolders,TradingHistory,UniswapLiquidity) currently return the raw template output. - Async utilities (
PriceThresholdAlertTool,LendingRateMonitorTool) already shield you from rate spikes with short sleeps; avoid spawning excessive parallel loops unless you also raise Bitquery limits.
Operational Notes
- Centralize credential management: add the Bitquery OAuth keys to your
.envand load them before instantiating tools to prevent runtimeValueErrors fromDexBaseTool.oAuth(). - Because Uniswap calls hit your RPC, failures there do not imply Bitquery downtime—inspect the
errorstring insideToolResult.outputor the returned dictionary to isolate the failure domain. - The monitoring helper in
blockchain_monitor.pyassumes a scheduler reachable athttp://localhost:8888/monitoring/tasks. Overrideapi_urlin the module before deploying if your infra differs. PredictPricefetches up to ~1000 rows per query. If Bitquery throttles you, lower the template limit or use a paid API plan.