๐ํ๋ก๊ทธ๋๋ฐ/Next.js
[Next.js] CNN ๊ณตํฌ ํ์ ์ง์ ๊ณต์ api (feat. TypeScript)
TwoIceFish
2024. 8. 3. 18:31
CNN์์ ์ฌ์ฉํ๋ ๊ณต์ ๋ฐ์ดํฐ ํธ์ถ ๋ก์ง์ ๋๋ค. ๋ธ๋ผ์ฐ์ ๋ก ์ ์์ ๋ฐ์ดํฐ ํ์ธ ๊ฐ๋ฅํ๋ฉฐ, ํฌ๋กค๋ง์ ๋ฐฉ์งํ๊ธฐ ์ํด์ 418 I'm a teapot์ ๋์ฐ๊ธฐ ๋๋ฌธ์ User-Agent๋ฅผ ์ถ๊ฐํ์ฌ ํธ์ถํ์ต๋๋ค.
const data = await fetch("https://production.dataviz.cnn.io/index/fearandgreed/graphdata",
{
headers: {
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}
}
)
interface FearAndGreedData {
score: number;
rating: string;
timestamp: string;
previous_close: number;
previous_1_week: number;
previous_1_month: number;
previous_1_year: number;
}
interface HistoricalData {
timestamp: number;
score: number;
rating: string;
data: {
x: number;
y: number;
rating: string;
}[];
}
interface MarketMomentumData {
timestamp: number;
score: number;
rating: string;
data: Array<Record<string, any>>;
}
interface StockPriceData {
timestamp: number;
score: number;
rating: string;
data: Array<Record<string, any>>;
}
interface PutCallOptionsData {
timestamp: number;
score: number;
rating: string;
data: Array<Record<string, any>>;
}
interface MarketVolatilityData {
timestamp: number;
score: number;
rating: string;
data: Array<Record<string, any>>;
}
interface JunkBondDemandData {
timestamp: number;
score: number;
rating: string;
data: Array<Record<string, any>>;
}
interface SafeHavenDemandData {
timestamp: number;
score: number;
rating: string;
data: Array<Record<string, any>>;
}
interface FearAndGreedIndex {
fear_and_greed: FearAndGreedData;
fear_and_greed_historical: HistoricalData;
market_momentum_sp500: MarketMomentumData;
market_momentum_sp125: MarketMomentumData;
stock_price_strength: StockPriceData;
stock_price_breadth: StockPriceData;
put_call_options: PutCallOptionsData;
market_volatility_vix: MarketVolatilityData;
market_volatility_vix_50: MarketVolatilityData;
junk_bond_demand: JunkBondDemandData;
safe_haven_demand: SafeHavenDemandData;
}