Building an AI Oil Trading System on Hyperliquid

We built a system that monitors geopolitical events in real time, scores them with AI, and executes WTI crude oil trades on Hyperliquid's xyz dex — all within seconds. Here is how the entire pipeline works, from signal detection to trade execution.

Why Oil on Hyperliquid

CME crude oil futures trade Sunday 5pm to Friday 4pm CT. Outside those hours, you cannot trade. You cannot even get a reliable price. Yahoo Finance returns the last closing price, which during a volatile weekend can be dollars away from reality.

Hyperliquid's xyz dex lists WTI crude as a perpetual contract (xyz:CL) that trades 24/7. The spread is tight, the oracle tracks CME during market hours and crypto-native pricing outside them, and you can enter or exit a position at 3am on a Saturday if a geopolitical event breaks. For a system that monitors presidential posts around the clock, this is critical.

We use Hyperliquid for everything: live pricing for the dashboard, price capture at signal time, trade execution, and position management. Yahoo Finance is only used for historical daily candles to feed the forecast model.

The Signal Pipeline

The system has four stages: detect, score, broadcast, and execute. Each stage is designed to minimize latency while maintaining accuracy.

1. Detection — Truth Social Monitoring

A Playwright-based poller checks Truth Social every few seconds. When a new presidential post appears, it is captured with full text and metadata within 3-5 seconds of publication. This replaced a previous Apify-based approach that cost $900/month and had significantly higher latency.

We also run a Hormuz vessel congestion monitor using AIS (Automatic Identification System) data via WebSocket. If vessel traffic patterns in the Strait of Hormuz deviate from baseline — congestion, blockade signals, military activity — that generates its own signal independent of social media.

2. Scoring — LLM Analysis

Each captured post is analyzed by a language model that understands oil market dynamics. The model scores posts on a scale from -5 (strongly bearish) to +5 (strongly bullish) based on several factors: direct mentions of oil or energy policy, references to Iran or OPEC states, tariff language affecting import costs, and threats related to shipping lanes.

The model also classifies posts by theme — IRAN_MILITARY, HORMUZ_BLOCKADE, TARIFF_ENERGY, OPEC_POLICY — and assigns a confidence level. Posts scored at zero (no oil relevance) are filtered out. Only actionable signals with a non-zero score are broadcast.

Beyond single-market scoring, the system runs multi-market analysis. A post about Iran sanctions does not just affect WTI — it impacts Brent, natural gas, Bitcoin (risk-off flows), and the S&P 500. Each market gets its own directional score and confidence level.

3. Broadcast — SSE Stream

Scored signals are pushed to connected clients via Server-Sent Events (SSE). The stream endpoint is open and free — no API key required. Traders connect with a single curl command or a few lines of Python and receive structured JSON payloads containing the score, direction, confidence, price at alert, rationale, and post theme.

The SSE architecture means traders receive signals before Telegram users. The stream pushes first, then the bot formats and sends to Telegram channels. This gives programmatic traders a structural latency advantage.

Filters are available on the stream: minimum score threshold, direction filter (BULLISH/BEARISH only), and post theme filter. A trader only interested in Hormuz-related signals with a score of +3 or higher can subscribe to exactly that.

4. Execution — Hyperliquid Auto-Trader

Our auto-trader connects to the SSE stream and listens for signals with an absolute score of 3 or higher. When a qualifying signal arrives, it executes a trade on Hyperliquid's xyz:CL perpetual within seconds.

The trader uses fixed position sizing ($20 per trade), 3x leverage, and maintains stop-loss (2%) and take-profit (3%) levels. A background thread monitors open positions every 30 seconds and closes them if SL/TP is hit. If a new signal arrives in the opposite direction, the trader flips the position automatically.

Order signing uses Hyperliquid's Python SDK with an API wallet. The API wallet signs trades while the master account holds funds — this separation means the signing key never has withdrawal access.

The Forecast Model: Migas-1.5

Alongside reactive signals, the system runs a probabilistic forecast model called Migas-1.5. It takes 60 days of daily WTI price history (a post-war regime window) and generates 16-day forward scenarios: base case, bullish, and bearish.

The model injects geopolitical context — recent signal scores, active themes, headline sentiment — as conditioning variables. This means the forecast adapts to the current geopolitical environment rather than relying purely on price patterns. During the Hormuz blockade period, for example, the model naturally shifts its base case upward to reflect sustained supply risk.

Forecasts are generated every 12 hours on a rolling basis and are available on the dashboard and via the Telegram bot. Users can run on-demand forecasts for both WTI and Brent.

Accuracy Tracking

Every signal is tracked against actual price movements at 5-minute, 15-minute, 1-hour, and 24-hour intervals. The system records the Hyperliquid price at signal time, then checks whether the price moved in the predicted direction at each window.

This is not backtested accuracy — it is live, forward-looking performance measured on real signals as they fire. The accuracy report is available to all bot users via the /stats command, and the data feeds into the dashboard for transparency.

Early results show Trump-related signals hitting at 75% accuracy at the 1-hour window. Auto-forecast signals (generated when a high-scoring post triggers an automatic forecast) run at approximately 60-70% at 1-hour. These numbers update continuously as new signals fire and resolve.

Pricing: Why Hyperliquid Over Yahoo

One of the harder problems we solved was pricing accuracy. CME-based data from Yahoo Finance is delayed, unavailable on weekends, and returns stale closing prices during the daily 4-5pm CT maintenance break. For a system that fires signals 24/7, this created a serious problem: signals scored against stale prices would show incorrect accuracy.

We switched all pricing to Hyperliquid as the primary source. The xyz:CL mid price is fetched via a simple POST request to Hyperliquid's info endpoint. It updates continuously, reflects real trading activity, and is available around the clock. Yahoo data is only used for historical daily candles (60-day lookback) that the forecast model needs.

Architecture

The system runs across two environments. The Telegram bot, SSE server, Truth Social poller, Hormuz monitor, and auto-trader run on a dedicated GPU pod (RunPod). The web dashboard, API endpoints, signal storage, and blog generation run on Vercel with Upstash Redis for persistence.

Signal data flows in one direction: detection → scoring → SSE broadcast → Telegram delivery → dashboard storage → accuracy scoring. Each step is independent and fails gracefully. If Telegram goes down, the SSE stream still works. If the dashboard is unreachable, signals still fire and trades still execute.

Connecting to the Stream

The signal stream is open and free during the current beta period. Connect with:

curl -N https://api.usoil.ai/stream/OIL

Or in Python:

import requests, json resp = requests.get( "https://api.usoil.ai/stream/OIL", stream=True ) for line in resp.iter_lines(): line = line.decode() if line.startswith("data: "): signal = json.loads(line[6:]) print(signal["data"]["direction"], signal["data"]["score"])

Events include connected on initial connection, signal when a new scored signal fires, and heartbeat every 25 seconds to keep the connection alive. You can filter with ?min_score=3&direction=BULLISH to only receive high-conviction bullish signals.

What We Are Building Next

The current system handles WTI crude, but the multi-market scoring engine already analyzes impacts on Brent, natural gas, Bitcoin, and the S&P 500. Expanding trade execution to these markets on Hyperliquid is a natural next step.

We are also working on a premium API tier with historical signal data, webhook delivery, and configurable position sizing for traders who want to run their own execution logic against our signal feed.

If you trade oil on Hyperliquid or are building on top of geopolitical signal data, connect to the stream and see what the system catches in real time.

Get Started