🏦 USDT/BOB Price Data Flow - CotizacionesBolivia.com

📊 Average Pricing System: This diagram shows how average USDT prices in Bolivianos are calculated and displayed, using real-time data from Binance's P2P marketplace.
PHASE 1: DATA COLLECTION
Every 15min
🌐 Binance P2P API
Official source for BUY/SELL offers
https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search Payload: {"fiat": "BOB", "asset": "USDT", "tradeType": "SELL"}
→
⚙️ AWS Lambda
Automated serverless processing
fetch_data.py runs every 15 minutes: 1. Fetch SELL offers (USDT sellers) 2. Fetch BUY offers (USDT buyers) 3. Parse and validate offer data
→
🎯 Median Absolute Deviation Outlier Filter
Adaptive statistical filtering
Dynamic threshold using linear interpolation: - Low amount of offers: MAD = 6.0 (lenient) - High amount of offers: MAD = 3.0 (strict) - Between: interpolated value Removes: |price - median| / mad > threshold
→
📊 VWAP Calculation
Volume-Weighted Average Price
VWAP = Σ(price × volume) / Σ(volume) - Applied to filtered offers only - Sell VWAP: For USDT buyers - Buy VWAP: For USDT sellers
PHASE 2: DATA STORAGE
🗄️ DynamoDB
AWS NoSQL Database
Table: crypto_exchange_rates - ID: 'current' (current rate) - ID: 'history_[timestamp]' (historical) - sell_vwap, buy_vwap, timestamp
→
📈 Historical Data
Storage for temporal analysis
- Retention: Permanent historical data - Queries: By time range - Analysis: Hourly/daily variations
PHASE 3: API LAYER
🔗 API Gateway
Public REST endpoints
GET /current - Current rate GET /historical - Historical data Base URL: z5l1y3luja.execute-api.us-east-2.amazonaws.com/prod
→
⚡ Cache TTL
CloudFront caching
TTL: 5 minutes - Reduces latency - Minimizes AWS costs - Improves user experience
PHASE 4: USER INTERFACE
Every 1min
🌐 Website
Frontend JavaScript
script.js: - fetch('/current') every minute - Updates DOM elements - Calculates variations
→
📱 UI Elements
Visual elements in index.html
#buy-exchange-rate → Buy price #sell-exchange-rate → Sell price #last-update → Last update timestamp
→
📊 Variation Calculation
Frontend temporal analysis
Hourly variation: vs price 1 hour ago Daily variation: vs previous day average Indicators: ↑ ↓ = with colors
PHASE 5: USER EXPERIENCE
💰 Displayed Prices
Final information to user
BUY: 13.25 Bs (price to buy USDT) SELL: 13.22 Bs (price to sell USDT) Last updated: 3 minutes ago
→
🔄 Calculator
Conversion tool
converter.js: - Uses current rates for conversion - Bs ↔ USDT in real-time - Automatic updates
→
📈 Indicators
Trend analysis
Variations: - ↑ +0.15% (last hour) - ↓ -0.23% (last day) - Tooltips with previous prices
Data Source
Processing
Storage
API Layer
Frontend/UI
🔧 Technical Notes: