📈 Monitor DeFi liquidation risk with OpenAI GPT-4.1 and Slack alerts

⚡ 13 views · 📈 Crypto Trading & Stock Market

Description

Quick overview

This workflow runs every 10 minutes to monitor a DeFi lending position by fetching position and price data via HTTP, calculating liquidation risk metrics, logging results to Google Sheets, and sending AI-written Slack alerts (via OpenAI) when the risk level changes or escalates.

How it works

  1. Runs every 10 minutes on a schedule.
  2. Loads the monitoring configuration, including the lending position API URL and the asset price API URL.
  3. Fetches the current lending position via HTTP and continues only if collateral amount, debt amount, and liquidation threshold are greater than zero.
  4. Fetches the live collateral asset price via HTTP and continues only if the USD price is greater than zero.
  5. Calculates health factor, estimated liquidation price, and distance to liquidation, then classifies the position risk level and determines whether an alert is required based on the previous risk level.
  6. Appends each monitoring result to a Google Sheets “Monitoring History” worksheet.
  7. When an alert is required, OpenAI generates a concise risk summary which is posted to a Slack channel and recorded in a Google Sheets “Alert History” worksheet.

Setup

  1. Provide reachable HTTP endpoints for the lending position API and the asset price API, then update the two URLs (and any threshold values) in the configuration step.
  2. Add Google Sheets credentials and select the target spreadsheet and worksheets for “Monitoring History” and “Alert History.”
  3. Add an OpenAI API credential and ensure the selected model is available in your OpenAI account.
  4. Add Slack credentials and set the destination channel for liquidation risk alerts.
  5. Adjust the schedule interval if you want a different monitoring cadence.

Additional info

How To Customize Nodes

Add-ons

The following are optional extensions and are not part of the current workflow:

Use Case Examples

  1. Collateral Monitoring: Track an ETH-backed lending position and identify declining health factor levels.
  2. Risk Escalation Alerts: Notify a Slack channel when a position moves from a safe state into a warning or higher-risk state.
  3. Liquidation Distance Tracking: Store current price, estimated liquidation price, and liquidation distance for historical review.
  4. Operational Risk History: Maintain a Google Sheets record of every monitoring cycle for later analysis.
  5. AI Risk Summaries: Convert calculated risk metrics into concise, human-readable alert messages.

Additional use cases may be possible through customization.

Troubleshooting Guide

IssuePossible CauseSolution
No lending position dataThe configured position API endpoint is unavailable or returns an unexpected structureVerify position_api_url and confirm the response contains collateral amount, debt amount, and liquidation threshold
Market price validation failsThe price response does not contain a positive price_usd valueVerify the configured price API and its response structure
Health factor is incorrectPosition fields or liquidation threshold do not match the expected data formatReview the response fields used by Calculate Risk Metrics
No Slack notificationalert_required is false or Slack credentials/channel configuration is incorrectCheck the risk classification and verify Slack configuration
AI message is not normalizedThe OpenAI response does not contain the expected text structureReview the OpenAI output and the parsing logic in Normalize AI Risk Alert
Google Sheets logging failsSpreadsheet credentials, sheet selection, or column mappings are incorrectVerify Google Sheets credentials, selected sheets, and required column names

Need Help?

WeblineIndia can assist with workflow setup, API and credential configuration, Google Sheets and Slack integration, workflow customization, troubleshooting, optional add-ons and development of similar n8n automation workflows.

🔗 Nodes Used

Google Sheets, HTTP Request, Slack, Schedule Trigger, OpenAI

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup