{{TEMPLATE_IMPORTS}} import { ap2 } from '@lucid-agents/ap2'; import { createAgent } from '@lucid-agents/core'; import { http } from '@lucid-agents/http'; import { payments, paymentsFromEnv } from '@lucid-agents/payments'; const paymentConfig = paymentsFromEnv(); {{TEMPLATE_PRE_SETUP}} const agent = await createAgent({ name: process.env.AGENT_NAME ?? 'trading-data-agent', version: process.env.AGENT_VERSION ?? '0.1.0', description: process.env.AGENT_DESCRIPTION ?? 'Trading data provider agent', }) .use(http()) .use(payments({ config: paymentConfig })) .use(ap2({ roles: ['merchant'], required: true })) .build(); {{TEMPLATE_POST_SETUP}} /** * Trading Data Agent - Provides mock trading data * * This agent sells trading data through Lucid's Agent Card and HTTP profile. * Entrypoints are priced and require payment. */ addEntrypoint({ key: 'getMarketData', description: 'Get mock market data for a symbol', input: z.object({ symbol: z.string(), timeframe: z.enum(['1h', '4h', '1d']).optional(), }), output: z.object({ symbol: z.string(), price: z.number(), volume: z.number(), timestamp: z.string(), data: z.array( z.object({ time: z.string(), open: z.number(), high: z.number(), low: z.number(), close: z.number(), volume: z.number(), }) ), }), price: '0.005', // USD decimal price for historical data handler: async ctx => { const { symbol, timeframe = '1h' } = ctx.input; // Generate mock trading data const basePrice = 100 + Math.random() * 50; const dataPoints = timeframe === '1d' ? 30 : timeframe === '4h' ? 6 : 24; const data = Array.from({ length: dataPoints }, (_, i) => { const variation = (Math.random() - 0.5) * 10; const price = basePrice + variation; return { time: new Date(Date.now() - (dataPoints - i) * 3600000).toISOString(), open: price, high: price + Math.random() * 5, low: price - Math.random() * 5, close: price + (Math.random() - 0.5) * 2, volume: Math.floor(Math.random() * 1000000), }; }); return { output: { symbol, price: basePrice, volume: data.reduce((sum, d) => sum + d.volume, 0), timestamp: new Date().toISOString(), data, }, usage: { total_tokens: 0 }, }; }, }); addEntrypoint({ key: 'getPrice', description: 'Get current price for a symbol', input: z.object({ symbol: z.string(), }), output: z.object({ symbol: z.string(), price: z.number(), timestamp: z.string(), }), price: '0.001', // USD decimal price for a simple query handler: async ctx => { const { symbol } = ctx.input; // Generate mock price const price = 100 + Math.random() * 50; return { output: { symbol, price, timestamp: new Date().toISOString(), }, usage: { total_tokens: 0 }, }; }, });