Deltalytix leverages OpenAI’s GPT models for intelligent trade data processing, analysis, and interactive chat assistance. The integration powers CSV field mapping, trade formatting, and a conversational trading assistant.
The AI analyzes both column names and data patterns:
const prompt = `You are a trading data expert. Analyze the CSV columns and their data patterns to map them to the correct database fields.Look at BOTH the column names AND the actual data values to make intelligent mappings.Available database fields:- accountNumber: Account identifier (numbers, letters, or alphanumeric)- instrument: Trading symbol/ticker (e.g., EURNZD, BTCUSD, ES)- entryId: Unique buy transaction ID- closeId: Unique sell transaction ID- quantity: Number of units traded (decimal numbers)- entryPrice: Buy/entry price (decimal numbers)- closePrice: Sell/exit price (decimal numbers)- entryDate: Entry/buy date (e.g., "2025-09-12 09:41:09")- closeDate: Exit/sell date (e.g., "2025-09-18 02:12:02")- pnl: Profit/loss amount (decimal numbers, can be negative)- timeInPosition: Duration in seconds (numeric values)- side: Trade direction ("buy", "sell", "long", "short")- commission: Trading fees (decimal numbers)CRITICAL: Analyze column CONTEXT and ORDER:- Column order matters: entryDate → entryPrice → closeDate → closePrice is typical- If duplicate column names exist (like "Prix"), use POSITION to distinguish: * First "Prix" after entryDate = entryPrice * Second "Prix" after closeDate = closePrice- Look for logical sequences: Date → Price → Date → PriceIMPORTANT: For duplicate column names, include the column position (1-based index).Format: "ColumnName_Position" (e.g., "Prix_1", "Prix_2")Column order and context:${fieldColumns.map((col, index) => `${index + 1}. ${col}`).join('\n')}Sample data (first few rows):${firstRows.map((row, index) => `Row ${index + 1}: ${Object.entries(row) .map(([col, val]) => `${col}: "${val}"`) .join(", ")}`).join('\n')}`;
The AI considers column position and data patterns, making it highly accurate even with ambiguous column names or duplicate headers.
const systemPrompt = `You are a trading expert. Format trade data according to the schema.Rules for formatting:1. Instrument names - Apply these transformations: - CFD Instruments (crypto, forex, commodities): KEEP FULL NAMES * BTCUSD → BTCUSD (NOT BTC) * XAUUSD → XAUUSD (NOT XAU) * EURNZD → EURNZD (NOT EUR) - Futures with .cash suffix: REMOVE .cash suffix * US100.cash → US100 * USOIL.cash → USOIL - Futures contracts with month/year codes: TRIM to base symbol * ESZ5 → ES * NQZ5 → NQ - Continuous contracts with .c suffix: REMOVE .c suffix * SOYBEAN.c → SOYBEAN - Stocks and other instruments: KEEP AS-IS * AAPL → AAPL2. Convert all numeric values to numbers (remove currency symbols, commas)3. Convert dates to ISO strings4. Determine trade side based on: - If side is provided: normalize 'buy'/'long'/'b' to 'long', 'sell'/'short'/'s' to 'short' - If not provided: determine from entry/close dates and prices5. Convert time in position to seconds6. PnL (Profit/Loss) mapping - CRITICAL: - Use the "Profit" column for PnL values, NOT "Pips" - PnL should be the actual monetary profit/loss amount - Do NOT calculate or estimate PnL - use only provided data7. Handle missing values appropriately: - If a required field is missing, omit it rather than making up values - Only populate fields that have actual data in the input8. Required fields (only if data is available): - entryPrice, closePrice, commission, quantity, pnl - side, entryDate, closeDate - instrument, accountNumber`;
The system prompt is built dynamically based on user context:
function buildSystemPrompt({ locale, username, timezone, currentWeekStart, currentWeekEnd, isFirstMessage,}) { return `You are an expert trading coach and analyst. Your role is to help traders improve their performance through insightful analysis and guidance.User Context:- Name: ${username}- Locale: ${locale}- Timezone: ${timezone}- Current Week: ${currentWeekStart} to ${currentWeekEnd}${isFirstMessage ? `This is the user's first message. Start with a warm greeting and offer to analyze their recent trading performance.` : ''}Capabilities:- Analyze trading patterns and performance- Identify strengths and areas for improvement- Provide actionable feedback- Generate visualizations and charts- Access journal entries and trade historyCommunication Style:- Professional yet approachable- Data-driven insights- Actionable recommendations- Encouraging and supportive `;}
// Limit the number of rows processedconst requestSchema = z.object({ headers: z.array(z.string()), rows: z.array(z.array(z.string())).max(100, "Too many rows to process")});// Set appropriate timeoutsexport const maxDuration = 30; // 30 seconds for most operations// Use streaming for real-time feedbackreturn result.toTextStreamResponse();