Skip to content

JVSCHANDRADITHYA/Low-Latency-HFT-Data-Engine-with-Oracle-Aggregation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Oracle Price Feed Service

A real-time oracle price feed system built for low-latency trading, analytics, and risk engines. It ingests live market prices, normalizes them, caches them for ultra-fast access, stores full history, and exposes clean APIs for downstream consumption.


Why I Built This

Most trading systems fail at the price layer — slow updates, stale data, no confidence metrics, and zero observability.
I built this to design a production-grade pricing backbone focused on:

  • Deterministic price normalization
  • Sub-second freshness guarantees
  • Historical traceability
  • Health-based automation
  • Zero-trust oracle design (on-chain ready)

This system is meant to be the single source of truth for mark price, funding, and liquidation logic.


What This Does

  • Live oracle price ingestion
  • Confidence-aware normalization
  • Ultra-low latency caching
  • Time-series persistence
  • Health & freshness checks
  • Prometheus metrics for observability
  • Designed on-chain oracle consensus (outlier rejection + median aggregation)

Core Data Model

struct PriceResponse {
    symbol: String,
    source: String,
    price: f64,
    confidence: f64,
    timestamp: i64,
}

API Endpoints

GET /oracle/price/{symbol}      # Latest price (cache)
GET /oracle/prices             # All active prices
GET /oracle/history/{symbol}  # Historical data
GET /oracle/health             # Data freshness
GET /metrics                   # Prometheus metrics

Database Schema

CREATE TABLE price_history (
    id SERIAL PRIMARY KEY,
    symbol TEXT NOT NULL,
    timestamp BIGINT NOT NULL,
    price DOUBLE PRECISION NOT NULL,
    confidence DOUBLE PRECISION NOT NULL,
    source TEXT NOT NULL
);

Price Ingestion Logic (Simplified)

loop {
    let raw = fetch_price().await?;
    let price = raw.price * 10f64.powi(raw.expo);
    let conf  = raw.conf  * 10f64.powi(raw.expo);

    let payload = PriceResponse {
        symbol: "BTC".into(),
        source: "oracle".into(),
        price,
        confidence: conf,
        timestamp: now(),
    };

    redis.set(key, to_json(&payload))?;
    db.insert(payload)?;
}

Caching Strategy

  • Redis is used as the single-read source
  • Database is used only for historical analysis
  • No live system ever blocks on database reads

Monitoring

  • Oracle fetch count
  • API request volume
  • Fetch latency histogram

All exposed via the /metrics endpoint.


On-Chain Ready (Designed)

  • Multi-oracle validation
  • Median-based aggregation
  • Staleness & confidence filtering
  • Outlier & manipulation rejection

Final Note

This project is built as a real oracle infrastructure layer, not a demo application — designed for:

  • Exchanges
  • Perpetual futures
  • Risk engines
  • Quant research
  • Backtesting systems

About

Low-latency trading data engine exploring institutional market-making, oracle aggregation, and execution-oriented system design.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors