-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_intelligence_api.py
More file actions
97 lines (79 loc) ยท 2.75 KB
/
debug_intelligence_api.py
File metadata and controls
97 lines (79 loc) ยท 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python3
"""
Alpha Vantage Intelligence API ์์ ์๋ต ๋๋ฒ๊ทธ
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import requests
import json
from datetime import datetime, timedelta
# Alpha Vantage API ํค (ํ๊ฒฝ๋ณ์์์ ๊ฐ์ ธ์ค๊ธฐ)
API_KEY = os.getenv('ALPHA_VANTAGE_API_KEY', 'demo')
def debug_api_call(function, **params):
"""API ํธ์ถ ๋๋ฒ๊ทธ"""
base_url = "https://www.alphavantage.co/query"
# ๊ธฐ๋ณธ ํ๋ผ๋ฏธํฐ
params.update({
'function': function,
'apikey': API_KEY
})
print(f"\n๐ Testing {function}")
print(f"๐ก URL: {base_url}")
print(f"๐ Params: {params}")
try:
response = requests.get(base_url, params=params, timeout=30)
print(f"๐ Status Code: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"๐ Response Keys: {list(data.keys())}")
# ์๋ต ๋ด์ฉ ์์ฝ
if isinstance(data, dict):
for key, value in data.items():
if isinstance(value, list):
print(f" {key}: {len(value)} items")
if value: # ์ฒซ ๋ฒ์งธ ํญ๋ชฉ ์ํ
print(f" Sample: {json.dumps(value[0], indent=2)[:200]}...")
elif isinstance(value, dict):
print(f" {key}: {len(value)} keys")
if value:
sample_key = list(value.keys())[0]
print(f" Sample key: {sample_key}")
else:
print(f" {key}: {value}")
return data
else:
print(f"โ Error: {response.text}")
return None
except Exception as e:
print(f"โ Exception: {e}")
return None
def main():
print("๐ง Alpha Vantage Intelligence API ์์ ์๋ต ๋๋ฒ๊ทธ")
print("=" * 60)
# 1. Market Status
debug_api_call('MARKET_STATUS')
# 2. News Sentiment
yesterday = (datetime.now() - timedelta(days=1)).strftime("%Y%m%dT%H%M")
debug_api_call(
'NEWS_SENTIMENT',
tickers='AAPL,MSFT',
time_from=yesterday,
limit=5
)
# 3. Top Gainers Losers
debug_api_call('TOP_GAINERS_LOSERS')
# 4. Insider Transactions
debug_api_call('INSIDER_TRANSACTIONS')
# 5. Analytics Sliding Window
debug_api_call(
'ANALYTICS_SLIDING_WINDOW',
SYMBOLS='AAPL,MSFT',
RANGE='1month',
INTERVAL='daily',
OHLC='close',
WINDOW_SIZE=10,
CALCULATIONS='MEAN,STDDEV'
)
if __name__ == "__main__":
main()