Cryptocurrency Rate Aggregator Development

A DeFi protocol lost $600,000 due to price manipulation via a [flash loan](https://en.wikipedia.org/wiki/Flash_loan). The cause—a single oracle. We develop a cryptocurrency rate aggregator that solves this problem: it collects data from 5+ sources (Binance, OKX, Bybit, Kraken, Uniswap) and applies T

Blockchain Development Services

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1450
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1309
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    1003
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1269
  • image_logo-advance_0.webp
    B2B Advance company logo design
    719
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    1009

A DeFi protocol lost $600,000 due to price manipulation via a flash loan. The cause—a single oracle. We develop a cryptocurrency rate aggregator that solves this problem: it collects data from 5+ sources (Binance, OKX, Bybit, Kraken, Uniswap) and applies TWAP filtering. BTC/USDT on Binance differs from Bybit, OKX, Kraken, and the on-chain price in the Uniswap pool. The aggregator calculates a single 'fair' rate or shows the spread for pricing in payment systems, display in wallets, arbitrage strategies, risk management, and DeFi oracles. Our cryptocurrency rate aggregator processes dozens of trading pairs with updates every 100 ms—critical for arbitrage and liquidity. Development cost starts at $15,000 for a turnkey aggregator with 3 sources, and we have 10+ years in blockchain development with 50+ crypto projects completed.

Aggregator developer: "TWAP filtering prevents manipulations that cost millions."

How Is the Cryptocurrency Rate Aggregator Developed?

Our aggregator is 2x more robust than single-oracle solutions because it combines multiple independent sources. A single oracle is a single point of failure. Our cryptocurrency rate aggregator reduces manipulation risks by combining CEX and DEX data with verification via TWAP. This prevents losses that can amount to millions of dollars, as in famous flash loan attacks.

Key challenges: synchronizing data with different latencies (10 ms for CEX, 12-15 sec for DEX), protecting against flash loan attacks on pools, and detecting price anomalies. We solve these with a combination of VWAP and median with dynamic outlier rejection.

How Is Data Collected from Different Exchanges?

Each exchange is a separate collector with reconnection on disconnection. We use TypeScript and an event-driven model on Node.js.

import WebSocket from 'ws'; import { EventEmitter } from 'events'; interface PriceEvent { source: string; pair: string; // 'BTC/USDT' price: number; volume24h: number; timestamp: number; // ms } class BinanceCollector extends EventEmitter { private ws: WebSocket | null = null; private pairs: string[]; private reconnectTimer: NodeJS.Timeout | null = null; constructor(pairs: string[]) { super(); this.pairs = pairs; } connect() { const streams = this.pairs .map(p => `${p.replace('/', '').toLowerCase()}@ticker`) .join('/'); this.ws = new WebSocket(`wss://stream.binance.com:9443/stream?streams=${streams}`); this.ws.on('message', (data: string) => { const msg = JSON.parse(data); if (msg.stream && msg.data) { const ticker = msg.data; this.emit('price', { source: 'binance', pair: this.normalizePair(ticker.s), price: parseFloat(ticker.c), volume24h: parseFloat(ticker.v) * parseFloat(ticker.c), timestamp: ticker.E, } as PriceEvent); } }); this.ws.on('close', () => { this.reconnectTimer = setTimeout(() => this.connect(), 5000); }); this.ws.on('error', (err) => { console.error('Binance WS error:', err.message); }); } private normalizePair(symbol: string): string { const quoteAssets = ['USDT', 'USDC', 'BTC', 'ETH', 'BNB']; for (const quote of quoteAssets) { if (symbol.endsWith(quote)) { return `${symbol.slice(0, -quote.length)}/${quote}`; } } return symbol; } } 

Similar collectors for OKX, Bybit, Kraken. Auto-reconnection and error logging are configured for each source.

On-chain Prices from Uniswap V3

Spot price from the pool—sqrtPriceX96. Decoding using viem:

import { createPublicClient, http } from 'viem'; import { mainnet } from 'viem/chains'; const UNISWAP_V3_POOL_ABI = [ { name: 'slot0', type: 'function', inputs: [], outputs: [ { name: 'sqrtPriceX96', type: 'uint160' }, { name: 'tick', type: 'int24' }, ], stateMutability: 'view', } ] as const; async function getUniswapPrice(poolAddress: string): Promise<number> { const slot0 = await client.readContract({ address: poolAddress as `0x${string}`, abi: UNISWAP_V3_POOL_ABI, functionName: 'slot0', }); const sqrtPriceX96 = BigInt(slot0.sqrtPriceX96); // price = (sqrtPriceX96 / 2^96)^2 * (10^token0Decimals / 10^token1Decimals) const price = Number((sqrtPriceX96 ** 2n * BigInt(1e18)) / (2n ** 192n)) / 1e18; return price; } 

TWAP from Uniswap V3 is more reliable than spot price—manipulation requires holding a large volume in the pool for multiple blocks. For oracles we use TWAP with a 30-minute window.

Which Aggregation Methods Do We Use?

A simple average is a poor aggregator: one source with an erroneous price drags the average in its direction. We use a combination:

  • VWAP (volume-weighted): medium outlier robustness, applied to high-liquidity pairs from CEX.
  • Median: high outlier robustness, used with 5+ sources for DeFi analytics.
  • Outlier rejection + median: very high robustness, always used as a base filter.

VWAP is calculated as the sum of prices weighted by volume. The median is robust to outliers. Anomaly detection is mandatory: we discard prices that deviate from the median by more than 2%.

import statistics def filter_outliers(prices: list[float], threshold: float = 0.02) -> list[float]: median = statistics.median(prices) return [p for p in prices if abs(p - median) / median <= threshold] def vwap(prices: list[dict]) -> float: total_volume = sum(p['volume24h'] for p in prices) if total_volume == 0: return sum(p['price'] for p in prices) / len(prices) return sum(p['price'] * p['volume24h'] for p in prices) / total_volume 

Comparing CEX and DEX: CEX sources like Binance and OKX offer low latency (~10-50 ms) and high volume, but are susceptible to API outages. DEX sources like Uniswap V3 have higher latency (~12-15 sec due to block time) but are harder to manipulate, especially when using TWAP. For real-time trading, CEX data is preferred; for DeFi oracles, DEX with TWAP is better.

How Do We Ensure Fault Tolerance?

  • Circuit breaker: if a source returns errors more than 5 times in 30 seconds—disable for 60 seconds.
  • Staleness check: if data hasn't been updated for >30 seconds—exclude from aggregation.
  • Minimum sources: if active sources <2, return an error instead of an incorrect rate.
  • Prometheus metrics: price_sources_active, price_update_latency_ms, price_deviation_percent—alert on anomalies.

All components are containerized (Docker) and orchestrated via Docker Compose or Kubernetes. Each collector runs in a separate container, the aggregator in a single instance with horizontal scaling support via Redis Pub/Sub. For monitoring we use Prometheus and Grafana. Deployment is automated via CI/CD (GitLab CI).

Development Process: From Design to Production

  1. Design (2-3 days): agree on pair list and sources, latency requirements, storage schema.
  2. Collectors (3-4 days): develop and test each source, normalize format.
  3. Aggregation (2-3 days): choose weighting algorithm, outlier detection, Redis storage.
  4. API (2-3 days): REST + WebSocket, documentation, rate limiting.
  5. Load testing (1-2 days): 100+ pairs simultaneously, behavior under source loss.

Total 1-2 weeks for an aggregator with 3-5 sources and 50+ trading pairs.

What's Included

  • Architectural documentation (diagrams, flow descriptions)
  • Source code repository (collectors, aggregator, API)
  • API documentation (Swagger/OpenAPI)
  • Load test report
  • Deployment scripts (Docker Compose/K8s manifests)
  • Run and monitoring guide
  • Team training (1-2 hours)

Typical Mistakes When Developing an Aggregator

  • Using only spot price instead of TWAP—vulnerable to flash loan attacks.
  • Lack of outlier detection—one erroneous price skews the entire average.
  • No circuit breaker—when an exchange API goes down, the aggregator hangs.
  • Too small a source pool (<3)—reduces reliability.

Avoiding these mistakes yields a manipulation-resistant cryptocurrency rate aggregator. Our experience: 10+ years in blockchain development, 50+ crypto projects, 5 years on the market. We guarantee stable operation.

Contact us for a project evaluation. Get an engineer consultation and order development of a cryptocurrency rate aggregator that will protect your project.