Files
rapira-market-widget/crypto/PreviewData.swift
T
2026-08-12 07:06:01 +07:00

45 lines
2.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
/// Демо-данные для плейсхолдера, галереи виджетов и превью.
/// Плейсхолдер нужен и в релизе, поэтому файл не под `#if DEBUG`.
enum PreviewData {
static var entry: CryptoEntry {
CryptoEntry(
date: .now,
quotes: thumbs.map { thumb in
Quote(thumb: thumb, series: series(for: thumb), icon: nil)
}
)
}
static let thumbs: [SymbolThumb] = [
SymbolThumb(symbol: "BTC/USDT", open: 71000, high: 71381.5, low: 68894.5,
close: 70324, chg: 0.0234, change: 1676, volume: 223.9,
turnover: 41_930_552, quoteCurrencyName: "Bitcoin",
baseCurrency: "USDT", quoteCurrency: "BTC"),
SymbolThumb(symbol: "ETH/USDT", open: 2152.9, high: 2177.4, low: 2105,
close: 2143.5, chg: -0.00446, change: -9.4, volume: 27226,
turnover: 119_347_435, quoteCurrencyName: "Ethereum",
baseCurrency: "USDT", quoteCurrency: "ETH"),
SymbolThumb(symbol: "SOL/USDT", open: 91.77, high: 92.29, low: 88.3,
close: 90.08, chg: -0.01913, change: -1.69, volume: 349_968,
turnover: 71_024_390, quoteCurrencyName: "Solana",
baseCurrency: "USDT", quoteCurrency: "SOL"),
SymbolThumb(symbol: "TON/USDT", open: 1.31, high: 1.35, low: 1.29,
close: 1.3382, chg: 0.0223, change: 0.0282, volume: 5_200_000,
turnover: 6_958_640, quoteCurrencyName: "Toncoin",
baseCurrency: "USDT", quoteCurrency: "TON"),
]
/// Синтетический ряд, похожий на дневной график.
private static func series(for thumb: SymbolThumb, points: Int = 48) -> [Double] {
var values = (0..<points).map { index -> Double in
let t = Double(index) / Double(points - 1)
let wave = sin(t * 7) * 0.4 + sin(t * 17 + 1.2) * 0.18 + sin(t * 3.3) * 0.5
return thumb.open + (thumb.close - thumb.open) * t + wave * (thumb.high - thumb.low) * 0.35
}
values.append(thumb.close)
return values
}
}