เอกสาร API ตัวชี้วัดทางเศรษฐกิจ

ระบบ API สำหรับดึงข้อมูลตัวชี้วัดเศรษฐกิจแบบเรียลไทม์และการวิเคราะห์สถิติอย่างมีประสิทธิภาพ

📊

ภาพรวมระบบ

API หลัก 2 ตัวที่ทำงานร่วมกันเพื่อให้บริการข้อมูลตัวชี้วัดเศรษฐกิจที่แม่นยำสูง

ระบบทำงานปกติ - อัพเดทข้อมูลสด
🚀 API ข้อมูลสด
ดึงข้อมูลตัวชี้วัดเศรษฐกิจวันนี้จาก Finnhub API พร้อมจัดเรียงและกรองตามระดับความสำคัญ
  • กรองตามระดับความสำคัญ
  • ตรวจจับผลต่างจากคาดการณ์
  • เรียงลำดับตามเวลา
📈 API วิเคราะห์สถิติ
การวิเคราะห์สถิติขั้นสูงและการจำลองสถานการณ์จากข้อมูลย้อนหลัง 5 ปี
  • การพยากรณ์ผลกระทบต่อราคา
  • การวิเคราะห์ความน่าจะเป็น
  • การแนะนำกลยุทธ์การเทรด

API ตัวชี้วัดเศรษฐกิจแบบเรียลไทม์

indicators.php - ดึงข้อมูลตัวชี้วัดเศรษฐกิจของวันนี้แบบเรียลไทม์

GET https://signupexpert.co.th/analysis/api/indicators.php

ส่งคืนรายการตัวชี้วัดเศรษฐกิจที่ประกาศหรือกำลังจะประกาศในวันนี้ ข้อมูลทั้งหมดจะถูกเก็บลงฐานข้อมูลโดยอัตโนมัติ

📋 รายการ Parameter

พารามิเตอร์ ประเภท คำอธิบาย
debug string เพิ่มเติม - โหมด Debug
1: Response พร้อมข้อมูล Debug
raw: ส่งคืนข้อมูลดิบจาก Finnhub API
db: แสดงสถานะฐานข้อมูลและข้อมูล 5 รายการล่าสุด
test string เพิ่มเติม - ระบุ finnhub เพื่อทดสอบการเชื่อมต่อ

📤 รูปแบบ Response

ตัวอย่าง JSON Response
{ "success": true, "source": "finnhub_api_realtime_display_simple_logic_fixed", "indicators": [ { "id": "us_md5hashstring", "date": "08/07 (วันนี้)", "time": "12:30", "country": "US", "name": "การจ้างงานนอกภาคการเกษตร", "importance": "high", "forecast": "185.0K", "previous": "210.0K", "actual": "-", "surprise_type": "none", "has_actual": false, "status": "upcoming", "is_ended": false, "sort_time": 1723033800 } ], "next_indicator": { "name": "การจ้างงานนอกภาคการเกษตร", "time": "12:30", "country": "US", "importance": "high", "unix_time": 1723033800 }, "recent_results": [ { "name": "ดัชนี PMI การผลิต", "country": "JP", "time": "08:30", "forecast": "50.5", "actual": "51.0", "impact": "positive" } ], "timestamp": 1723001041, "last_update": "2025-08-07 08:24:01 GMT" }

🔍 รายละเอียด Field หลัก

indicators[]
อาเรย์ตัวชี้วัดเศรษฐกิจ แต่ละรายการประกอบด้วยเวลาประกาศ ระดับความสำคัญ ค่าพยากรณ์ และค่าจริง
next_indicator
ข้อมูลตัวชี้วัดสำคัญที่จะประกาศต่อไป (สำหรับการแจ้งเตือนเทรดเดอร์)
recent_results
ผลลัพธ์ตัวชี้วัดที่ประกาศล่าสุดและผลกระทบต่อตลาด
💡 ตัวอย่าง: การติดตามตัวชี้วัดสำคัญ
ตัวอย่างการใช้งานด้วย JavaScript
// ติดตามเฉพาะตัวชี้วัดความสำคัญสูง fetch('/api/indicators.php') .then(response => response.json()) .then(data => { const highImportanceIndicators = data.indicators .filter(indicator => indicator.importance === 'high') .filter(indicator => !indicator.has_actual); console.log('ตัวชี้วัดสำคัญที่ควรติดตาม:', highImportanceIndicators); // คำนวณเวลาที่เหลือจนถึงตัวชี้วัดสำคัญถัดไป if (data.next_indicator) { const timeUntilNext = data.next_indicator.unix_time * 1000 - Date.now(); console.log(`เวลาที่เหลือถึงตัวชี้วัดสำคัญถัดไป: ${Math.round(timeUntilNext / 1000 / 60)} นาที`); } });
📊

API วิเคราะห์สถิติ

indicators_statistics.php - การวิเคราะห์ขั้นสูงและการจำลองสถานการณ์จากข้อมูลย้อนหลัง

ใช้ข้อมูลตัวชี้วัดเศรษฐกิจที่สะสมมา 5 ปีในการวิเคราะห์สถิติ พยากรณ์ผลกระทบต่อราคา และแนะนำกลยุทธ์การเทรด

GET https://signupexpert.co.th/analysis/api/indicators_statistics.php?action={ชื่อ Action}

ใช้พารามิเตอร์ action เพื่อเลือกฟังก์ชันที่ต้องการ แต่ละ Action จะมีการวิเคราะห์เฉพาะด้าน

🎯 Action ที่ใช้ได้

📈 ดึงข้อมูลย้อนหลัง (historical_data)
ดึงข้อมูล 5 ปีย้อนหลังของตัวชี้วัดที่ระบุ พร้อมข้อมูลสถิติ
พารามิเตอร์ ประเภท คำอธิบาย
indicator string จำเป็น - ชื่อตัวชี้วัดที่ค้นหา (ค้นหาบางส่วนได้) เช่น "CPI", "การจ้างงาน"
country string จำเป็น - รหัสประเทศ (US, EU, JP เป็นต้น)
💡 ตัวอย่างการใช้งาน
ดึงข้อมูลย้อนหลัง CPI สหรัฐ
GET https://signupexpert.co.th/analysis/api/indicators_statistics?action=historical_data&indicator=CPI&country=US // ตัวอย่าง Response { "success": true, "indicator_info": { "name": "ดัชนีราคาผู้บริโภค", "country": "US", "importance": "high" }, "historical_data": [...], // ข้อมูล 5 ปีย้อนหลัง "statistics_summary": { "positive_surprise_rate": 0.45, "negative_surprise_rate": 0.35, "neutral_rate": 0.20 } }
🎲 การจำลองสถานการณ์วันนี้ (today_simulation)
พยากรณ์การเปลี่ยนแปลงราคาในสถานการณ์ 3 แบบ (สูงกว่าคาด-ตรงคาด-ต่ำกว่าคาด) สำหรับตัวชี้วัดสำคัญของวันที่ระบุ
พารามิเตอร์ ประเภท คำอธิบาย
date string เพิ่มเติม - รูปแบบ YYYY-MM-DD หากไม่ระบุจะใช้วันนี้
country string เพิ่มเติม - กรองเฉพาะประเทศที่ต้องการ
💡 ตัวอย่างกลยุทธ์การเทรด
เรียกใช้การจำลองสถานการณ์วันนี้
GET https://signupexpert.co.th/analysis/api/indicators_statistics?action=today_simulation&country=US // ตัวอย่าง Response (ตัดตอนมา) { "simulations": [ { "indicator_name": "การจ้างงานนอกภาคการเกษตร", "patterns": { "below_forecast": { "probability": 0.35, "price_impact": { "5min_after": {"up_probability": 0.25, "avg_pips": -12}, "30min_after": {"up_probability": 0.30, "avg_pips": -8}, "1hour_after": {"up_probability": 0.40, "avg_pips": -5} }, "trading_strategy": "แนะนำ short gold" }, "meets_forecast": { "probability": 0.30, "trading_strategy": "รอดูสถานการณ์" }, "exceeds_forecast": { "probability": 0.35, "price_impact": { "5min_after": {"up_probability": 0.75, "avg_pips": 15} }, "trading_strategy": "แนะนำ long gold" } } } ] }
🔧 ตรวจสอบฐานข้อมูล (debug_data)
ตรวจสอบความถูกต้องของฐานข้อมูลและแสดงข้อมูลสถิติ (สำหรับผู้พัฒนา)
📖 แสดงคำแนะนำการใช้งาน (usage)
แสดงรายละเอียดการใช้งานฟีเจอร์ทั้งหมด (Action เริ่มต้น)
💻

ตัวอย่างการใช้งานจริง

วิธีการประยุกต์ใช้ในระบบการเทรดจริง

🚨 ระบบติดตามแบบเรียลไทม์
การติดตามตัวชี้วัดสำคัญแบบอัตโนมัติ
class EconomicIndicatorMonitor { constructor() { this.checkInterval = 30000; // ทุก 30 วินาที this.importantCountries = ['US', 'EU', 'JP']; this.apiBase = 'https://signupexpert.co.th/analysis/api'; } async startMonitoring() { setInterval(async () => { try { const response = await fetch(`${this.apiBase}/indicators`); const data = await response.json(); // ตรวจสอบตัวชี้วัดความสำคัญสูงที่ยังไม่ประกาศ const upcomingHighImpact = data.indicators .filter(ind => ind.importance === 'high' && !ind.has_actual) .filter(ind => this.importantCountries.includes(ind.country)); // ส่งการแจ้งเตือน upcomingHighImpact.forEach(indicator => { const timeUntil = indicator.sort_time * 1000 - Date.now(); if (timeUntil <= 300000) { // 5 นาทีก่อนประกาศ this.sendAlert(indicator); } }); // ตรวจสอบผลต่างจากคาดการณ์ของตัวชี้วัดที่ประกาศแล้ว const recentSurprises = data.recent_results .filter(result => result.impact !== 'neutral'); if (recentSurprises.length > 0) { this.analyzePriceImpact(recentSurprises); } } catch (error) { console.error('เกิดข้อผิดพลาดในการติดตาม:', error); } }, this.checkInterval); } sendAlert(indicator) { console.log(`🚨 แจ้งเตือน: ${indicator.name} (${indicator.country}) เหลือเวลาประกาศไม่ถึง 5 นาที - คาดการณ์: ${indicator.forecast}`); } }
📊 การวิเคราะห์กลยุทธ์การเทรด
การวางแผนกลยุทธ์จากข้อมูลย้อนหลัง
class TradingStrategyAnalyzer { constructor() { this.apiBase = 'https://signupexpert.co.th/analysis/api'; } async analyzeIndicatorImpact(indicatorName, country) { // ดึงข้อมูลย้อนหลัง const historyUrl = `${this.apiBase}/indicators_statistics?action=historical_data&indicator=${indicatorName}&country=${country}`; const historyData = await fetch(historyUrl).then(r => r.json()); // การจำลองสถานการณ์วันนี้ const simUrl = `${this.apiBase}/indicators_statistics?action=today_simulation&country=${country}`; const simData = await fetch(simUrl).then(r => r.json()); // สร้างคำแนะนำกลยุทธ์ const strategy = this.generateStrategy(historyData, simData); return strategy; } generateStrategy(history, simulation) { const stats = history.statistics_summary; const currentSim = simulation.simulations[0]; return { recommendation: this.getRecommendation(stats, currentSim), confidence: this.calculateConfidence(stats), riskLevel: this.assessRisk(currentSim), entry_points: this.suggestEntryPoints(currentSim.patterns), stop_loss: this.calculateStopLoss(currentSim.patterns) }; } getRecommendation(stats, simulation) { // กลยุทธ์สำหรับตัวชี้วัดที่มีผลต่างจากคาดการณ์บ่อย if (stats.positive_surprise_rate > 0.4) { return { primary: "กลยุทธ์ความผันผวน", description: "แนะนำการเทรดแบบเรนจ์โดยคาดหวังความผันผวนสูง" }; } // ตัวชี้วัดที่มีเสถียรภาพ return { primary: "กลยุทธ์ตามเทรนด์", description: "ใช้กลยุทธ์ตามเทรนด์เป็นหลัก" }; } }
🛟

ฝ่ายสนับสนุน - การแก้ไขปัญหา

ปัญหาที่พบบ่อยและวิธีแก้ไข

⚠️ ข้อจำกัดสำคัญ
API วิเคราะห์สถิติจำเป็นต้องระบุทั้ง indicator_name และ country_code เพราะตัวชี้วัดชื่อเดียวกันในแต่ละประเทศอาจมีข้อมูลต่างกัน จึงต้องระบุรหัสประเทศให้ครบถ้วนเสมอ

🔍 การแก้ไขปัญหา

ดึงข้อมูลไม่ได้
1. ตรวจสอบความถูกต้องของ API Key
2. ตรวจสอบรูปแบบพารามิเตอร์
3. ใช้ debug=1 เพื่อดูข้อมูล Debug
การวิเคราะห์สถิติไม่มีผลลัพธ์
1. ลองค้นหาด้วยชื่อตัวชี้วัดบางส่วน
2. ตรวจสอบรหัสประเทศให้ถูกต้อง
3. ตรวจสอบสถานะข้อมูลย้อนหลังในระบบ
Response ช้า
1. ปรับความถี่ในการ Request
2. ขอเฉพาะข้อมูลที่จำเป็น
3. พิจารณาใช้ระบบ Cache