This is page 1 of 2. Use http://codebase.md/donmorr/alphavantagemcpserver?lines=true&page={x} to view the full context. # Directory Structure ``` ├── .gitignore ├── LICENSE ├── pyproject.toml ├── README.md └── src └── mcp_server_alphavantage ├── __init__.py ├── api.py └── server.py ``` # Files -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- ``` 1 | src/mcp_server_alphavantage/__pycache__/ 2 | uv.lock 3 | .venv 4 | .DS_Store 5 | src/.DS_Store 6 | src/mcp_server_alphavantage/.DS_Store ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- ```markdown 1 | # Overview 2 | 3 | This is a fork of Cesar Alvernaz's "Alphavantage MCP server". It fixes a few bugs which were preventing the server from working correctly. 4 | 5 | # Alphavantage MCP Server 6 | 7 | A MCP server for the stock market data API, Alphavantage API. 8 | 9 | ## Configuration 10 | 11 | ### Getting an API Key 12 | 1. Sign up for a [Free Alphavantage API key](https://www.alphavantage.co/support/#api-key) 13 | 2. Add the API key to your environment variables as `ALPHAVANTAGE_API_KEY` 14 | 15 | 16 | ### Usage with Claude Desktop 17 | Add this to your `claude_desktop_config.json`: 18 | 19 | ``` 20 | { 21 | "mcpServers": { 22 | "alphavantage": { 23 | "command": "uv", 24 | "args": [ 25 | "--directory", 26 | "<DIRECTORY>/alphavantage", 27 | "run", 28 | "alphavantage" 29 | ], 30 | "env": { 31 | "ALPHAVANTAGE_API_KEY": "YOUR_API_KEY_HERE" 32 | } 33 | } 34 | } 35 | } 36 | ``` 37 | ``` -------------------------------------------------------------------------------- /src/mcp_server_alphavantage/__init__.py: -------------------------------------------------------------------------------- ```python 1 | from . import server 2 | import asyncio 3 | 4 | 5 | def main(): 6 | """Main entry point for the package.""" 7 | asyncio.run(server.main()) 8 | 9 | 10 | # Optionally expose other important items at package level 11 | __all__ = ['main', 'server'] 12 | ``` -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- ```toml 1 | [project] 2 | name = "alphavantage" 3 | version = "0.1.0" 4 | description = "Alphavantage MCP server" 5 | readme = "README.md" 6 | requires-python = ">=3.12" 7 | dependencies = [ 8 | "load-dotenv>=0.1.0", 9 | "mcp>=1.0.0", 10 | ] 11 | [[project.authors]] 12 | name = "Cesar Alvernaz" 13 | email = "[email protected]" 14 | 15 | [build-system] 16 | requires = ["hatchling"] 17 | build-backend = "hatchling.build" 18 | 19 | [tool.hatch.build.targets.wheel] 20 | packages = ["src/mcp_server_alphavantage"] 21 | 22 | [project.scripts] 23 | alphavantage = "mcp_server_alphavantage.server:run_main" ``` -------------------------------------------------------------------------------- /src/mcp_server_alphavantage/api.py: -------------------------------------------------------------------------------- ```python 1 | import os 2 | 3 | import httpx 4 | from dotenv import load_dotenv 5 | 6 | load_dotenv() 7 | 8 | API_KEY = os.getenv("ALPHAVANTAGE_API_KEY") 9 | if not API_KEY: 10 | raise ValueError("ALPHAVANTAGE_API_KEY environment variable required") 11 | 12 | API_BASE_URL = "https://www.alphavantage.co/query" 13 | 14 | 15 | ##### 16 | # Core Stock APIs 17 | ##### 18 | async def fetch_intraday( 19 | symbol: str, 20 | interval: str = "60min", 21 | datatype: str = "json", 22 | adjusted: bool = True, 23 | extended_hours: bool = True, 24 | outputsize: str = "compact", 25 | month: str = None, 26 | ) -> dict[str, str] | str: 27 | """ 28 | Fetch intraday stock data from the Alpha Vantage API. 29 | 30 | :argument: symbol (str): The stock symbol to fetch. 31 | :argument: interval (str): The time interval for the data (default: "5min"). 32 | :argument: datatype (str): The response data type (default: "json"). 33 | :argument: adjusted (bool): The adjusted data flag (default: True). 34 | :argument: extended_hours (bool): The extended hours flag (default: True). 35 | :argument: outputsize (str): The output size for the data (default: "compact"). 36 | :argument: month (str): The month of the data (default: None). 37 | 38 | :returns: The intraday stock data. 39 | """ 40 | 41 | https_params = { 42 | "function": "TIME_SERIES_INTRADAY", 43 | "symbol": symbol, 44 | "interval": interval, 45 | "datatype": datatype, 46 | "adjusted": adjusted, 47 | "outputsize": outputsize, 48 | "extended_hours": extended_hours, 49 | "month": month, 50 | "apikey": API_KEY, 51 | } 52 | 53 | async with httpx.AsyncClient() as client: 54 | response = await client.get(API_BASE_URL, params=https_params) 55 | response.raise_for_status() 56 | return response.text if datatype == "csv" else response.json() 57 | 58 | 59 | async def fetch_time_series_daily( 60 | symbol: str, datatype: str = "json", outputsize: str = "compact" 61 | ) -> dict[str, str] | str: 62 | """ 63 | Fetch daily stock data from the Alpha Vantage API. 64 | 65 | :argument: symbol (str): The stock symbol to fetch. 66 | :argument: datatype (str): The response data type (default: "json"). 67 | 68 | :returns: The daily stock data. 69 | """ 70 | 71 | https_params = { 72 | "function": "TIME_SERIES_DAILY", 73 | "symbol": symbol, 74 | "datatype": datatype, 75 | "outputsize": outputsize, 76 | "apikey": API_KEY, 77 | } 78 | async with httpx.AsyncClient() as client: 79 | response = await client.get(API_BASE_URL, params=https_params) 80 | response.raise_for_status() 81 | return response.text if datatype == "csv" else response.json() 82 | 83 | 84 | async def fetch_time_series_daily_adjusted( 85 | symbol: str, datatype: str = "json", outputsize: str = "compact" 86 | ) -> dict[str, str] | str: 87 | """ 88 | Fetch daily adjusted stock data from the Alpha Vantage API. 89 | 90 | :argument: symbol (str): The stock symbol to fetch. 91 | :argument: datatype (str): The response data type (default: "json"). 92 | 93 | :returns: The daily adjusted stock data. 94 | """ 95 | 96 | https_params = { 97 | "function": "TIME_SERIES_DAILY_ADJUSTED", 98 | "symbol": symbol, 99 | "datatype": datatype, 100 | "outputsize": outputsize, 101 | "apikey": API_KEY, 102 | } 103 | async with httpx.AsyncClient() as client: 104 | response = await client.get(API_BASE_URL, params=https_params) 105 | response.raise_for_status() 106 | return response.text if datatype == "csv" else response.json() 107 | 108 | 109 | async def fetch_time_series_weekly( 110 | symbol: str, datatype: str = "json" 111 | ) -> dict[str, str] | str: 112 | """ 113 | Fetch weekly stock data from the Alpha Vantage API. 114 | 115 | :argument: symbol (str): The stock symbol to fetch. 116 | :argument: datatype (str): The response data type (default: "json"). 117 | 118 | :returns: The weekly stock data. 119 | """ 120 | 121 | https_params = { 122 | "function": "TIME_SERIES_WEEKLY", 123 | "symbol": symbol, 124 | "datatype": datatype, 125 | "apikey": API_KEY, 126 | } 127 | async with httpx.AsyncClient() as client: 128 | response = await client.get(API_BASE_URL, params=https_params) 129 | response.raise_for_status() 130 | return response.text if datatype == "csv" else response.json() 131 | 132 | 133 | async def fetch_time_series_weekly_adjusted( 134 | symbol: str, datatype: str = "json" 135 | ) -> dict[str, str] | str: 136 | """ 137 | Fetch weekly adjusted stock data from the Alpha Vantage API. 138 | 139 | :argument: symbol (str): The stock symbol to fetch. 140 | :argument: datatype (str): The response data type (default: "json"). 141 | 142 | :returns: The weekly adjusted stock data. 143 | """ 144 | 145 | https_params = { 146 | "function": "TIME_SERIES_WEEKLY_ADJUSTED", 147 | "symbol": symbol, 148 | "datatype": datatype, 149 | "apikey": API_KEY, 150 | } 151 | async with httpx.AsyncClient() as client: 152 | response = await client.get(API_BASE_URL, params=https_params) 153 | response.raise_for_status() 154 | return response.text if datatype == "csv" else response.json() 155 | 156 | 157 | async def fetch_time_series_monthly( 158 | symbol: str, datatype: str = "json" 159 | ) -> dict[str, str] | str: 160 | """ 161 | Fetch monthly stock data from the Alpha Vantage API. 162 | 163 | :argument: symbol (str): The stock symbol to fetch. 164 | :argument: datatype (str): The response data type (default: "json"). 165 | 166 | :returns: The monthly stock data. 167 | """ 168 | 169 | https_params = { 170 | "function": "TIME_SERIES_MONTHLY", 171 | "symbol": symbol, 172 | "datatype": datatype, 173 | "apikey": API_KEY, 174 | } 175 | async with httpx.AsyncClient() as client: 176 | response = await client.get(API_BASE_URL, params=https_params) 177 | response.raise_for_status() 178 | return response.text if datatype == "csv" else response.json() 179 | 180 | 181 | async def fetch_time_series_monthly_adjusted( 182 | symbol: str, datatype: str = "json" 183 | ) -> dict[str, str] | str: 184 | """ 185 | Fetch monthly adjusted stock data from the Alpha Vantage API. 186 | 187 | :argument: symbol (str): The stock symbol to fetch. 188 | :argument: datatype (str): The response data type (default: "json"). 189 | 190 | :returns: The monthly adjusted stock data. 191 | """ 192 | 193 | https_params = { 194 | "function": "TIME_SERIES_MONTHLY_ADJUSTED", 195 | "symbol": symbol, 196 | "datatype": datatype, 197 | "apikey": API_KEY, 198 | } 199 | async with httpx.AsyncClient() as client: 200 | response = await client.get(API_BASE_URL, params=https_params) 201 | response.raise_for_status() 202 | return response.text if datatype == "csv" else response.json() 203 | 204 | 205 | async def fetch_quote(symbol: str, datatype: str = "json") -> dict[str, str] | str: 206 | """ 207 | Fetch a stock quote from the Alpha Vantage API. 208 | 209 | :argument: symbol (str): The stock symbol to fetch. 210 | :argument: datatype (str): The response data type (default: "json"). 211 | 212 | :returns: The stock quote data. 213 | """ 214 | 215 | https_params = { 216 | "function": "GLOBAL_QUOTE", 217 | "symbol": symbol, 218 | "datatype": datatype, 219 | "apikey": API_KEY, 220 | } 221 | async with httpx.AsyncClient() as client: 222 | response = await client.get(API_BASE_URL, params=https_params) 223 | response.raise_for_status() 224 | return response.text if datatype == "csv" else response.json() 225 | 226 | 227 | async def fetch_realtime_bulk_quotes( 228 | symbols: list[str], datatype: str = "json" 229 | ) -> dict[str, str] | str: 230 | """ 231 | Fetch real-time bulk stock quotes from the Alpha Vantage API. 232 | 233 | :argument: symbols (list[str]): The stock symbols to fetch. 234 | :argument: datatype (str): The response data type (default: "json"). 235 | 236 | :returns: The real-time bulk stock quotes. 237 | """ 238 | 239 | https_params = { 240 | "function": "REALTIME_BULK_QUOTES", 241 | "symbols": ",".join(symbols[:100]), 242 | "datatype": datatype, 243 | "apikey": API_KEY, 244 | } 245 | async with httpx.AsyncClient() as client: 246 | response = await client.get(API_BASE_URL, params=https_params) 247 | response.raise_for_status() 248 | return response.text if datatype == "csv" else response.json() 249 | 250 | 251 | async def search_endpoint( 252 | keywords: str, datatype: str = "json" 253 | ) -> dict[str, str] | str: 254 | """ 255 | Search for endpoints from the Alpha Vantage API. 256 | 257 | :argument: keywords (str): The search keywords. 258 | :argument: datatype (str): The response data type (default: "json"). 259 | 260 | :returns: The search results. 261 | """ 262 | 263 | https_params = { 264 | "function": "SYMBOL_SEARCH", 265 | "keywords": keywords, 266 | "datatype": datatype, 267 | "apikey": API_KEY, 268 | } 269 | async with httpx.AsyncClient() as client: 270 | response = await client.get(API_BASE_URL, params=https_params) 271 | response.raise_for_status() 272 | return response.text if datatype == "csv" else response.json() 273 | 274 | 275 | async def fetch_market_status() -> dict[str, str] | str: 276 | """ 277 | Fetch the market status from the Alpha Vantage API. 278 | 279 | :returns: The market status. 280 | """ 281 | 282 | https_params = {"function": "MARKET_STATUS", "apikey": API_KEY} 283 | async with httpx.AsyncClient() as client: 284 | response = await client.get(API_BASE_URL, params=https_params) 285 | response.raise_for_status() 286 | return response.json() 287 | 288 | 289 | ##### 290 | # Options data APIs 291 | ##### 292 | 293 | 294 | async def fetch_realtime_options( 295 | symbol: str, datatype: str = "json", contract: str = None 296 | ) -> dict[str, str] | str: 297 | """ 298 | Fetch real-time options data from the Alpha Vantage API. 299 | 300 | :argument: symbol (str): The stock symbol to fetch. 301 | :argument: datatype (str): The response data type (default: "json"). 302 | :argument: contract (str): The contract ID (default: None) 303 | 304 | :returns: The real-time options' data. 305 | """ 306 | 307 | https_params = { 308 | "function": "REALTIME_OPTIONS", 309 | "symbol": symbol, 310 | "datatype": datatype, 311 | "contract": contract, 312 | "apikey": API_KEY, 313 | } 314 | async with httpx.AsyncClient() as client: 315 | response = await client.get(API_BASE_URL, params=https_params) 316 | response.raise_for_status() 317 | return response.text if datatype == "csv" else response.json() 318 | 319 | 320 | async def fetch_historical_options( 321 | symbol: str, datatype: str = "json", date: str = None 322 | ) -> dict[str, str] | str: 323 | """ 324 | Fetch historical options data from the Alpha Vantage API. 325 | 326 | :argument: symbol (str): The stock symbol to fetch. 327 | :argument: datatype (str): The response data type (default: "json"). 328 | :argument: date (str): The date of the historical options (default: None) 329 | """ 330 | 331 | https_params = { 332 | "function": "HISTORICAL_OPTIONS", 333 | "symbol": symbol, 334 | "datatype": datatype, 335 | "date": date, 336 | "apikey": API_KEY, 337 | } 338 | async with httpx.AsyncClient() as client: 339 | response = await client.get(API_BASE_URL, params=https_params) 340 | response.raise_for_status() 341 | return response.text if datatype == "csv" else response.json() 342 | 343 | 344 | ##### 345 | # Alpha Intelligence APIs 346 | ##### 347 | 348 | async def fetch_news_sentiment( 349 | tickers: list[str] | str, 350 | datatype: str = "json", 351 | topics: str | None = None, 352 | time_from: str | None = None, 353 | time_to: str | None = None, 354 | sort: str = "LATEST", 355 | limit: int = 50, 356 | ) -> dict[str, str] | str: 357 | """ 358 | Fetch news sentiment data from the Alpha Vantage API. 359 | 360 | The API finds articles that simultaneously mention ALL specified tickers. 361 | 362 | Args: 363 | tickers (Union[list[str], str]): Single ticker as string or list of tickers to search for simultaneously 364 | Examples: 365 | - "AAPL" 366 | - ["COIN", "CRYPTO:BTC", "FOREX:USD"] 367 | datatype (str, optional): The response data type ("json" or "csv"). Defaults to "json" 368 | topics (str, optional): Comma-separated news topics to filter by 369 | time_from (str, optional): Start time in YYYYMMDDTHHMM format. Example: "20220410T0130" 370 | time_to (str, optional): End time in YYYYMMDDTHHMM format 371 | sort (str, optional): Sort order ("LATEST", "EARLIEST", "RELEVANCE"). Defaults to "LATEST" 372 | limit (int, optional): Maximum number of results (1-1000). Defaults to 50 373 | 374 | Returns: 375 | Union[dict, str]: News sentiment data 376 | """ 377 | # Convert tickers to string parameter 378 | tickers_param = tickers if isinstance(tickers, str) else ",".join(tickers) 379 | 380 | # Construct request parameters 381 | https_params = { 382 | "function": "NEWS_SENTIMENT", 383 | "tickers": tickers_param, 384 | "apikey": API_KEY, 385 | "datatype": datatype, 386 | "limit": limit, 387 | "sort": sort 388 | } 389 | 390 | # Add optional parameters only if they have values 391 | if topics: 392 | https_params["topics"] = topics 393 | if time_from: 394 | https_params["time_from"] = time_from 395 | if time_to: 396 | https_params["time_to"] = time_to 397 | 398 | async with httpx.AsyncClient() as client: 399 | response = await client.get(API_BASE_URL, params=https_params) 400 | response.raise_for_status() 401 | return response.text if datatype == "csv" else response.json() 402 | 403 | 404 | async def fetch_top_gainer_losers() -> dict[str, str]: 405 | """ 406 | Fetch the top gainers or losers from the Alpha Vantage API. 407 | 408 | :returns: The top gainers or losers data. 409 | """ 410 | 411 | https_params = { 412 | "function": "TOP_GAINERS_LOSERS", 413 | "apikey": API_KEY, 414 | } 415 | async with httpx.AsyncClient() as client: 416 | response = await client.get(API_BASE_URL, params=https_params) 417 | response.raise_for_status() 418 | return response.json() 419 | 420 | 421 | async def fetch_insider_transactions(symbol: str) -> dict[str, str]: 422 | """ 423 | Fetch insider transactions from the Alpha Vantage API. 424 | 425 | :argument: symbol (str): The stock symbol to fetch. 426 | 427 | :returns: insider transactions' data. 428 | """ 429 | 430 | https_params = { 431 | "function": "INSIDER_TRANSACTIONS", 432 | "symbol": symbol, 433 | "apikey": API_KEY, 434 | } 435 | async with httpx.AsyncClient() as client: 436 | response = await client.get(API_BASE_URL, params=https_params) 437 | response.raise_for_status() 438 | return response.json() 439 | 440 | 441 | async def fetch_analytics_fixed_window( 442 | symbols: list[str], 443 | interval: str, 444 | series_range: str = "full", 445 | ohlc: str = "close", 446 | calculations: list[str] = None, 447 | ) -> dict[str, str]: 448 | """ 449 | Fetch analytics data from the Alpha Vantage API. 450 | 451 | :argument: symbol (list[str]): The stock symbols to fetch. 452 | :argument: range (str): The range of the data (default: "full"). 453 | :argument: interval (str): The time interval for the data. 454 | :argument: ohlc (str): The OHLC data type (default: "close"). 455 | :argument: calculations (list[str]): The analytics calculations (default: None). 456 | 457 | :returns: The analytics data. 458 | """ 459 | 460 | https_params = { 461 | "function": "ANALYTICS_FIXED_WINDOW", 462 | "symbol": ",".join(symbols), 463 | "range": series_range, 464 | "interval": interval, 465 | "ohlc": ohlc, 466 | "calculations": ",".join(calculations) if calculations else None, 467 | "apikey": API_KEY, 468 | } 469 | async with httpx.AsyncClient() as client: 470 | response = await client.get(API_BASE_URL, params=https_params) 471 | response.raise_for_status() 472 | return response.json() 473 | 474 | 475 | async def fetch_analytics_sliding_window( 476 | symbols: list[str], 477 | series_range: str = "full", 478 | ohlc: str = "close", 479 | interval: str = None, 480 | window_size: int = 10, 481 | calculations: list[str] = None, 482 | ) -> dict[str, str]: 483 | """ 484 | Fetch analytics data from the Alpha Vantage API. 485 | 486 | :argument: symbol (list[str]): The stock symbols to fetch. 487 | 488 | :returns: The analytics data. 489 | """ 490 | 491 | https_params = { 492 | "function": "ANALYTICS_SLIDING_WINDOW", 493 | "symbols": ",".join(symbols), 494 | "range": series_range, 495 | "ohlc": ohlc, 496 | "interval": interval, 497 | "window_size": window_size, 498 | "calculations": ",".join(calculations) if calculations else None, 499 | "apikey": API_KEY, 500 | } 501 | async with httpx.AsyncClient() as client: 502 | response = await client.get(API_BASE_URL, params=https_params) 503 | response.raise_for_status() 504 | return response.json() 505 | 506 | 507 | ##### 508 | # Fundamental data APIs 509 | ##### 510 | 511 | 512 | async def fetch_company_overview(symbol: str) -> dict[str, str]: 513 | """ 514 | Fetch company overview data from the Alpha Vantage API. 515 | 516 | :argument: symbol (str): The stock symbol to fetch. 517 | 518 | :returns: The company overview data. 519 | """ 520 | 521 | https_params = { 522 | "function": "OVERVIEW", 523 | "symbol": symbol, 524 | "apikey": API_KEY, 525 | } 526 | async with httpx.AsyncClient() as client: 527 | response = await client.get(API_BASE_URL, params=https_params) 528 | response.raise_for_status() 529 | return response.json() 530 | 531 | 532 | async def fetch_etf_profile(symbol: str) -> dict[str, str]: 533 | """ 534 | Fetch ETC profile from Alpha Vantage API. 535 | 536 | :argument: symbol (str): The stock symbol to fetch. 537 | 538 | :returns: The company overview data. 539 | """ 540 | 541 | https_params = { 542 | "function": "ETF_PROFILE", 543 | "symbol": symbol, 544 | "apikey": API_KEY, 545 | } 546 | async with httpx.AsyncClient() as client: 547 | response = await client.get(API_BASE_URL, params=https_params) 548 | response.raise_for_status() 549 | return response.json() 550 | 551 | 552 | async def company_dividends(symbol: str) -> dict[str, str]: 553 | """ 554 | Fetch company dividends data from the Alpha Vantage API. 555 | 556 | :argument: symbol (str): The stock symbol to fetch. 557 | 558 | :returns: The company dividends data. 559 | """ 560 | 561 | https_params = { 562 | "function": "DIVIDENDS", 563 | "symbol": symbol, 564 | "apikey": API_KEY, 565 | } 566 | async with httpx.AsyncClient() as client: 567 | response = await client.get(API_BASE_URL, params=https_params) 568 | response.raise_for_status() 569 | return response.json() 570 | 571 | 572 | async def fetch_company_splits(symbol: str) -> dict[str, str]: 573 | """ 574 | Fetch company splits data from the Alpha Vantage API. 575 | 576 | :argument: symbol (str): The stock symbol to fetch. 577 | 578 | :returns: The company splits data. 579 | """ 580 | 581 | https_params = { 582 | "function": "SPLITS", 583 | "symbol": symbol, 584 | "apikey": API_KEY, 585 | } 586 | async with httpx.AsyncClient() as client: 587 | response = await client.get(API_BASE_URL, params=https_params) 588 | response.raise_for_status() 589 | return response.json() 590 | 591 | 592 | async def fetch_income_statement(symbol: str) -> dict[str, str]: 593 | """ 594 | Fetch company income statement data from the Alpha Vantage API. 595 | 596 | :argument: symbol (str): The stock symbol to fetch. 597 | 598 | :returns: The company income statement data. 599 | """ 600 | 601 | https_params = { 602 | "function": "INCOME_STATEMENT", 603 | "symbol": symbol, 604 | "apikey": API_KEY, 605 | } 606 | async with httpx.AsyncClient() as client: 607 | response = await client.get(API_BASE_URL, params=https_params) 608 | response.raise_for_status() 609 | return response.json() 610 | 611 | 612 | async def fetch_balance_sheet(symbol: str) -> dict[str, str]: 613 | """ 614 | Fetch company balance sheet data from the Alpha Vantage API. 615 | 616 | :argument: symbol (str): The stock symbol to fetch. 617 | 618 | :returns: The company balance sheet data. 619 | """ 620 | 621 | https_params = { 622 | "function": "BALANCE_SHEET", 623 | "symbol": symbol, 624 | "apikey": API_KEY, 625 | } 626 | async with httpx.AsyncClient() as client: 627 | response = await client.get(API_BASE_URL, params=https_params) 628 | response.raise_for_status() 629 | return response.json() 630 | 631 | 632 | async def fetch_cash_flow(symbol: str) -> dict[str, str]: 633 | """ 634 | Fetch company cash flow data from the Alpha Vantage API. 635 | 636 | :argument: symbol (str): The stock symbol to fetch. 637 | 638 | :returns: The company cash flow data. 639 | """ 640 | 641 | https_params = { 642 | "function": "CASH_FLOW", 643 | "symbol": symbol, 644 | "apikey": API_KEY, 645 | } 646 | async with httpx.AsyncClient() as client: 647 | response = await client.get(API_BASE_URL, params=https_params) 648 | response.raise_for_status() 649 | return response.json() 650 | 651 | 652 | async def fetch_earnings(symbol: str) -> dict[str, str]: 653 | """ 654 | Fetch company earnings data from the Alpha Vantage API. 655 | 656 | :argument: symbol (str): The stock symbol to fetch. 657 | 658 | :returns: The company earnings data. 659 | """ 660 | 661 | https_params = { 662 | "function": "EARNINGS", 663 | "symbol": symbol, 664 | "apikey": API_KEY, 665 | } 666 | async with httpx.AsyncClient() as client: 667 | response = await client.get(API_BASE_URL, params=https_params) 668 | response.raise_for_status() 669 | return response.json() 670 | 671 | 672 | async def fetch_listing_status( 673 | symbol: str, date: str = None, state: str = "active" 674 | ) -> dict[str, str]: 675 | """ 676 | Fetch company listing status data from the Alpha Vantage API. 677 | 678 | :argument: symbol (str): The stock symbol to fetch. 679 | :argument: date (str): The date of the listing status (default: None). 680 | :argument: state (str): The listing status state (default: "active"). 681 | 682 | :returns: The company listing status data. 683 | """ 684 | 685 | https_params = { 686 | "function": "LISTING_STATUS", 687 | "symbol": symbol, 688 | "date": date, 689 | "state": state, 690 | "apikey": API_KEY, 691 | } 692 | async with httpx.AsyncClient() as client: 693 | response = await client.get(API_BASE_URL, params=https_params) 694 | response.raise_for_status() 695 | return response.json() 696 | 697 | 698 | async def fetch_earnings_calendar( 699 | symbol: str, horizon: str = "3month" 700 | ) -> dict[str, str]: 701 | """ 702 | Fetch company earning calendar data from the Alpha Vantage API. 703 | 704 | :argument: symbol (str): The stock symbol to fetch. 705 | :argument: horizon (str): The earning calendar horizon (default: "3month"). 706 | 707 | :returns: The company earning calendar data. 708 | """ 709 | 710 | https_params = { 711 | "function": "EARNINGS_CALENDAR", 712 | "symbol": symbol, 713 | "horizon": horizon, 714 | "apikey": API_KEY, 715 | } 716 | async with httpx.AsyncClient() as client: 717 | response = await client.get(API_BASE_URL, params=https_params) 718 | response.raise_for_status() 719 | return response.json() 720 | 721 | 722 | async def fetch_ipo_calendar() -> str: 723 | """ 724 | Fetch IPO calendar data from the Alpha Vantage API. 725 | 726 | :returns: The IPO calendar data. 727 | """ 728 | 729 | https_params = { 730 | "function": "IPO_CALENDAR", 731 | "apikey": API_KEY, 732 | } 733 | async with httpx.AsyncClient() as client: 734 | response = await client.get(API_BASE_URL, params=https_params) 735 | response.raise_for_status() 736 | return response.text 737 | 738 | 739 | ##### 740 | # Forex data APIs 741 | ##### 742 | 743 | 744 | async def fetch_exchange_rate( 745 | from_currency: str, to_currency: str 746 | ) -> dict[str, str] | str: 747 | """ 748 | Fetch exchange rate data from the Alpha Vantage API. 749 | 750 | :argument: from_currency (str): The source currency. 751 | :argument: to_currency (str): The destination currency. 752 | 753 | :returns: The exchange rate data. 754 | """ 755 | 756 | https_params = { 757 | "function": "CURRENCY_EXCHANGE_RATE", 758 | "from_currency": from_currency, 759 | "to_currency": to_currency, 760 | "apikey": API_KEY, 761 | } 762 | 763 | async with httpx.AsyncClient() as client: 764 | response = await client.get(API_BASE_URL, params=https_params) 765 | response.raise_for_status() 766 | return response.json() 767 | 768 | 769 | async def fetch_fx_intraday( 770 | from_symbol: str, 771 | to_symbol: str, 772 | interval: str = None, 773 | outputsize: str = "compact", 774 | datatype: str = "json", 775 | ) -> dict[str, str] | str: 776 | """ 777 | Fetch intraday forex data from the Alpha Vantage API. 778 | 779 | :argument: from_symbol (str): The source currency. 780 | :argument: to_symbol (str): The destination currency. 781 | :argument: interval (str): The time interval for the data (default: None). 782 | :argument: outputsize (str): The output size for the data (default: "compact"). 783 | :argument: datatype (str): The response data type (default: "json"). 784 | 785 | :returns: The intraday forex data. 786 | """ 787 | 788 | https_params = { 789 | "function": "FX_INTRADAY", 790 | "from_symbol": from_symbol, 791 | "to_symbol": to_symbol, 792 | "interval": interval, 793 | "datatype": datatype, 794 | "outputsize": outputsize, 795 | "apikey": API_KEY, 796 | } 797 | 798 | async with httpx.AsyncClient() as client: 799 | response = await client.get(API_BASE_URL, params=https_params) 800 | response.raise_for_status() 801 | return response.text if datatype == "csv" else response.json() 802 | 803 | 804 | async def fetch_fx_daily( 805 | from_symbol: str, 806 | to_symbol: str, 807 | datatype: str = "json", 808 | outputsize: str = "compact", 809 | ) -> dict[str, str] | str: 810 | """ 811 | Fetch daily forex data from the Alpha Vantage API. 812 | 813 | :argument: from_symbol (str): The source currency. 814 | :argument: to_symbol (str): The destination currency. 815 | :argument: datatype (str): The response data type (default: "json"). 816 | :argument: outputsize (str): The output size for the data (default: "compact"). 817 | 818 | :returns: The daily forex data. 819 | """ 820 | 821 | https_params = { 822 | "function": "FX_DAILY", 823 | "from_symbol": from_symbol, 824 | "to_symbol": to_symbol, 825 | "datatype": datatype, 826 | "outputsize": outputsize, 827 | "apikey": API_KEY, 828 | } 829 | async with httpx.AsyncClient() as client: 830 | response = await client.get(API_BASE_URL, params=https_params) 831 | response.raise_for_status() 832 | return response.text if datatype == "csv" else response.json() 833 | 834 | 835 | async def fetch_fx_weekly( 836 | from_symbol: str, to_symbol: str, datatype: str = "json" 837 | ) -> dict[str, str] | str: 838 | """ 839 | Fetch weekly forex data from the Alpha Vantage API. 840 | 841 | :argument: from_symbol (str): The source currency. 842 | :argument: to_symbol (str): The destination currency. 843 | :argument: datatype (str): The response data type (default: "json"). 844 | 845 | :returns: The weekly forex data. 846 | """ 847 | 848 | https_params = { 849 | "function": "FX_WEEKLY", 850 | "from_symbol": from_symbol, 851 | "to_symbol": to_symbol, 852 | "datatype": datatype, 853 | "apikey": API_KEY, 854 | } 855 | async with httpx.AsyncClient() as client: 856 | response = await client.get(API_BASE_URL, params=https_params) 857 | response.raise_for_status() 858 | return response.text if datatype == "csv" else response.json() 859 | 860 | 861 | async def fetch_fx_monthly( 862 | from_symbol: str, to_symbol: str, datatype: str = "json" 863 | ) -> dict[str, str] | str: 864 | """ 865 | Fetch monthly forex data from the Alpha Vantage API. 866 | 867 | :argument: from_symbol (str): The source currency. 868 | :argument: to_symbol (str): The destination currency. 869 | :argument: datatype (str): The response data type (default: "json"). 870 | 871 | :returns: The monthly forex data. 872 | """ 873 | 874 | https_params = { 875 | "function": "FX_MONTHLY", 876 | "from_symbol": from_symbol, 877 | "to_symbol": to_symbol, 878 | "datatype": datatype, 879 | "apikey": API_KEY, 880 | } 881 | async with httpx.AsyncClient() as client: 882 | response = await client.get(API_BASE_URL, params=https_params) 883 | response.raise_for_status() 884 | return response.text if datatype == "csv" else response.json() 885 | 886 | 887 | ##### 888 | # Crypto data APIs 889 | ##### 890 | 891 | 892 | async def fetch_digital_currency_intraday( 893 | symbol: str, 894 | market: str, 895 | interval: str = None, 896 | datatype: str = "json", 897 | outputsize: str = "compact", 898 | ) -> dict[str, str] | str: 899 | """ 900 | Fetch intraday digital currency data from the Alpha Vantage API. 901 | 902 | :argument: symbol (str): The digital currency symbol to fetch. 903 | :argument: market (str): The market symbol to fetch. 904 | :argument: interval (str): The time interval for the data (default: "5min"). 905 | :argument: datatype (str): The response data type (default: "json"). 906 | 907 | :returns: The intraday digital currency data. 908 | """ 909 | 910 | https_params = { 911 | "function": "CRYPTO_INTRADAY", 912 | "symbol": symbol, 913 | "market": market, 914 | "interval": interval, 915 | "datatype": datatype, 916 | "outputsize": outputsize, 917 | "apikey": API_KEY, 918 | } 919 | 920 | async with httpx.AsyncClient() as client: 921 | response = await client.get(API_BASE_URL, params=https_params) 922 | response.raise_for_status() 923 | return response.text if datatype == "csv" else response.json() 924 | 925 | 926 | async def fetch_digital_currency_daily(symbol: str, market: str) -> str: 927 | """ 928 | Fetch daily digital currency data from the Alpha Vantage API. 929 | 930 | :argument: symbol (str): The digital currency symbol to fetch. 931 | :argument: market (str): The market symbol to fetch. 932 | :argument: datatype (str): The response data type (default: "json"). 933 | 934 | :returns: The daily digital currency data. 935 | """ 936 | 937 | https_params = { 938 | "function": "DIGITAL_CURRENCY_DAILY", 939 | "symbol": symbol, 940 | "market": market, 941 | "apikey": API_KEY, 942 | } 943 | async with httpx.AsyncClient() as client: 944 | response = await client.get(API_BASE_URL, params=https_params) 945 | response.raise_for_status() 946 | return response.text 947 | 948 | 949 | async def fetch_digital_currency_weekly(symbol: str, market: str) -> str: 950 | """ 951 | Fetch weekly digital currency data from the Alpha Vantage API. 952 | 953 | :argument: symbol (str): The digital currency symbol to fetch. 954 | :argument: market (str): The market symbol to fetch. 955 | :argument: datatype (str): The response data type (default: "json"). 956 | 957 | :returns: The weekly digital currency data. 958 | """ 959 | 960 | https_params = { 961 | "function": "DIGITAL_CURRENCY_WEEKLY", 962 | "symbol": symbol, 963 | "market": market, 964 | "apikey": API_KEY, 965 | } 966 | async with httpx.AsyncClient() as client: 967 | response = await client.get(API_BASE_URL, params=https_params) 968 | response.raise_for_status() 969 | return response.text 970 | 971 | 972 | async def fetch_digital_currency_monthly(symbol: str, market: str) -> str: 973 | """ 974 | Fetch monthly digital currency data from the Alpha Vantage API. 975 | 976 | :argument: symbol (str): The digital currency symbol to fetch. 977 | :argument: market (str): The market symbol to fetch. 978 | :argument: datatype (str): The response data type (default: "json"). 979 | 980 | :returns: The monthly digital currency data. 981 | """ 982 | 983 | https_params = { 984 | "function": "DIGITAL_CURRENCY_MONTHLY", 985 | "symbol": symbol, 986 | "market": market, 987 | "apikey": API_KEY, 988 | } 989 | async with httpx.AsyncClient() as client: 990 | response = await client.get(API_BASE_URL, params=https_params) 991 | response.raise_for_status() 992 | return response.text 993 | 994 | 995 | ##### 996 | # Commodities data APIs 997 | ##### 998 | 999 | 1000 | async def fetch_wti_crude( 1001 | interval: str = "monthly", datatype: str = "json" 1002 | ) -> dict[str, str] | str: 1003 | """ 1004 | Fetch crude oil (WTI) data from the Alpha Vantage API. 1005 | 1006 | :argument: interval (str): The time interval for the data (default: "monthly"). 1007 | :argument: datatype (str): The response data type (default: "json"). 1008 | 1009 | :returns: The intraday crude oil (WTI) data. 1010 | """ 1011 | 1012 | https_params = { 1013 | "function": "WTI", 1014 | "interval": interval, 1015 | "datatype": datatype, 1016 | "apikey": API_KEY, 1017 | } 1018 | 1019 | async with httpx.AsyncClient() as client: 1020 | response = await client.get(API_BASE_URL, params=https_params) 1021 | response.raise_for_status() 1022 | return response.text if datatype == "csv" else response.json() 1023 | 1024 | 1025 | async def fetch_brent_crude( 1026 | interval: str = "monthly", datatype: str = "json" 1027 | ) -> dict[str, str] | str: 1028 | """ 1029 | Fetch Brent crude oil data from the Alpha Vantage API. 1030 | 1031 | :argument: interval (str): The time interval for the data (default: "monthly"). 1032 | :argument: datatype (str): The response data type (default: "json"). 1033 | 1034 | :returns: The intraday Brent crude oil data. 1035 | """ 1036 | 1037 | https_params = { 1038 | "function": "BRENT", 1039 | "interval": interval, 1040 | "datatype": datatype, 1041 | "apikey": API_KEY, 1042 | } 1043 | 1044 | async with httpx.AsyncClient() as client: 1045 | response = await client.get(API_BASE_URL, params=https_params) 1046 | response.raise_for_status() 1047 | return response.text if datatype == "csv" else response.json() 1048 | 1049 | 1050 | async def fetch_natural_gas( 1051 | interval: str = "monthly", datatype: str = "json" 1052 | ) -> dict[str, str] | str: 1053 | """ 1054 | Fetch Henry Hub natural gas data from the Alpha Vantage API. 1055 | 1056 | :argument: interval (str): The time interval for the data (default: "monthly"). 1057 | :argument: datatype (str): The response data type (default: "json"). 1058 | 1059 | :returns: The intraday natural gas data. 1060 | """ 1061 | 1062 | https_params = { 1063 | "function": "NATURAL_GAS", 1064 | "interval": interval, 1065 | "datatype": datatype, 1066 | "apikey": API_KEY, 1067 | } 1068 | 1069 | async with httpx.AsyncClient() as client: 1070 | response = await client.get(API_BASE_URL, params=https_params) 1071 | response.raise_for_status() 1072 | return response.text if datatype == "csv" else response.json() 1073 | 1074 | 1075 | async def fetch_copper( 1076 | interval: str = "monthly", datatype: str = "json" 1077 | ) -> dict[str, str] | str: 1078 | """ 1079 | Fetch global copper data from the Alpha Vantage API. 1080 | 1081 | :argument: interval (str): The time interval for the data (default: "monthly"). 1082 | :argument: datatype (str): The response data type (default: "json"). 1083 | 1084 | :returns: The intraday copper data. 1085 | """ 1086 | 1087 | https_params = { 1088 | "function": "COPPER", 1089 | "interval": interval, 1090 | "datatype": datatype, 1091 | "apikey": API_KEY, 1092 | } 1093 | 1094 | async with httpx.AsyncClient() as client: 1095 | response = await client.get(API_BASE_URL, params=https_params) 1096 | response.raise_for_status() 1097 | return response.text if datatype == "csv" else response.json() 1098 | 1099 | 1100 | async def fetch_aluminum( 1101 | interval: str = "monthly", datatype: str = "json" 1102 | ) -> dict[str, str] | str: 1103 | """ 1104 | Fetch global aluminum data from the Alpha Vantage API. 1105 | 1106 | :argument: interval (str): The time interval for the data (default: "monthly"). 1107 | :argument: datatype (str): The response data type (default: "json"). 1108 | 1109 | :returns: The intraday aluminum data. 1110 | """ 1111 | 1112 | https_params = { 1113 | "function": "ALUMINUM", 1114 | "interval": interval, 1115 | "datatype": datatype, 1116 | "apikey": API_KEY, 1117 | } 1118 | 1119 | async with httpx.AsyncClient() as client: 1120 | response = await client.get(API_BASE_URL, params=https_params) 1121 | response.raise_for_status() 1122 | return response.text if datatype == "csv" else response.json() 1123 | 1124 | 1125 | async def fetch_wheat( 1126 | interval: str = "monthly", datatype: str = "json" 1127 | ) -> dict[str, str] | str: 1128 | """ 1129 | Fetch global wheat data from the Alpha Vantage API. 1130 | 1131 | :argument: interval (str): The time interval for the data (default: "monthly"). 1132 | :argument: datatype (str): The response data type (default: "json"). 1133 | 1134 | :returns: The intraday wheat data. 1135 | """ 1136 | 1137 | https_params = { 1138 | "function": "WHEAT", 1139 | "interval": interval, 1140 | "datatype": datatype, 1141 | "apikey": API_KEY, 1142 | } 1143 | 1144 | async with httpx.AsyncClient() as client: 1145 | response = await client.get(API_BASE_URL, params=https_params) 1146 | response.raise_for_status() 1147 | return response.text if datatype == "csv" else response.json() 1148 | 1149 | 1150 | async def fetch_corn( 1151 | interval: str = "monthly", datatype: str = "json" 1152 | ) -> dict[str, str] | str: 1153 | """ 1154 | Fetch global corn data from the Alpha Vantage API. 1155 | 1156 | :argument: interval (str): The time interval for the data (default: "monthly"). 1157 | :argument: datatype (str): The response data type (default: "json"). 1158 | 1159 | :returns: The intraday corn data. 1160 | """ 1161 | 1162 | https_params = { 1163 | "function": "CORN", 1164 | "interval": interval, 1165 | "datatype": datatype, 1166 | "apikey": API_KEY, 1167 | } 1168 | 1169 | async with httpx.AsyncClient() as client: 1170 | response = await client.get(API_BASE_URL, params=https_params) 1171 | response.raise_for_status() 1172 | return response.text if datatype == "csv" else response.json() 1173 | 1174 | 1175 | async def fetch_cotton( 1176 | interval: str = "monthly", datatype: str = "json" 1177 | ) -> dict[str, str] | str: 1178 | """ 1179 | Fetch global cotton data from the Alpha Vantage API. 1180 | 1181 | :argument: interval (str): The time interval for the data (default: "monthly"). 1182 | :argument: datatype (str): The response data type (default: "json"). 1183 | 1184 | :returns: The intraday cotton data. 1185 | """ 1186 | 1187 | https_params = { 1188 | "function": "COTTON", 1189 | "interval": interval, 1190 | "datatype": datatype, 1191 | "apikey": API_KEY, 1192 | } 1193 | 1194 | async with httpx.AsyncClient() as client: 1195 | response = await client.get(API_BASE_URL, params=https_params) 1196 | response.raise_for_status() 1197 | return response.text if datatype == "csv" else response.json() 1198 | 1199 | 1200 | async def fetch_sugar( 1201 | interval: str = "monthly", datatype: str = "json" 1202 | ) -> dict[str, str] | str: 1203 | """ 1204 | Fetch global sugar data from the Alpha Vantage API. 1205 | 1206 | :argument: interval (str): The time interval for the data (default: "monthly"). 1207 | :argument: datatype (str): The response data type (default: "json"). 1208 | 1209 | :returns: The intraday sugar data. 1210 | """ 1211 | 1212 | https_params = { 1213 | "function": "SUGAR", 1214 | "interval": interval, 1215 | "datatype": datatype, 1216 | "apikey": API_KEY, 1217 | } 1218 | 1219 | async with httpx.AsyncClient() as client: 1220 | response = await client.get(API_BASE_URL, params=https_params) 1221 | response.raise_for_status() 1222 | return response.text if datatype == "csv" else response.json() 1223 | 1224 | 1225 | async def fetch_coffee( 1226 | interval: str = "monthly", datatype: str = "json" 1227 | ) -> dict[str, str] | str: 1228 | """ 1229 | Fetch global coffee data from the Alpha Vantage API. 1230 | 1231 | :argument: interval (str): The time interval for the data (default: "monthly"). 1232 | :argument: datatype (str): The response data type (default: "json"). 1233 | 1234 | :returns: The intraday coffee data. 1235 | """ 1236 | 1237 | https_params = { 1238 | "function": "COFFEE", 1239 | "interval": interval, 1240 | "datatype": datatype, 1241 | "apikey": API_KEY, 1242 | } 1243 | 1244 | async with httpx.AsyncClient() as client: 1245 | response = await client.get(API_BASE_URL, params=https_params) 1246 | response.raise_for_status() 1247 | return response.text if datatype == "csv" else response.json() 1248 | 1249 | 1250 | async def fetch_all_commodities( 1251 | interval: str = "monthly", datatype: str = "json" 1252 | ) -> dict[str, str] | str: 1253 | """ 1254 | Fetch global commodities data from the Alpha Vantage API. 1255 | 1256 | :argument: interval (str): The time interval for the data (default: "monthly"). 1257 | :argument: datatype (str): The response data type (default: "json"). 1258 | 1259 | :returns: Global commodities data. 1260 | """ 1261 | 1262 | https_params = { 1263 | "function": "ALL_COMMODITIES", 1264 | "interval": interval, 1265 | "datatype": datatype, 1266 | "apikey": API_KEY, 1267 | } 1268 | 1269 | async with httpx.AsyncClient() as client: 1270 | response = await client.get(API_BASE_URL, params=https_params) 1271 | response.raise_for_status() 1272 | return response.text if datatype == "csv" else response.json() 1273 | 1274 | 1275 | ##### 1276 | # Economic data APIs 1277 | ##### 1278 | 1279 | 1280 | async def fetch_real_gdp( 1281 | interval: str = "monthly", datatype: str = "json" 1282 | ) -> dict[str, str] | str: 1283 | """ 1284 | Fetch real GDP data from the Alpha Vantage API. 1285 | 1286 | :argument: interval (str): The time interval for the data (default: "monthly"). 1287 | :argument: datatype (str): The response data type (default: "json"). 1288 | 1289 | :returns: The real GDP data. 1290 | """ 1291 | 1292 | https_params = { 1293 | "function": "REAL_GDP", 1294 | "interval": interval, 1295 | "datatype": datatype, 1296 | "apikey": API_KEY, 1297 | } 1298 | 1299 | async with httpx.AsyncClient() as client: 1300 | response = await client.get(API_BASE_URL, params=https_params) 1301 | response.raise_for_status() 1302 | return response.text if datatype == "csv" else response.json() 1303 | 1304 | 1305 | async def fetch_real_gdp_per_capita(datatype: str = "json") -> dict[str, str] | str: 1306 | """ 1307 | Fetch real GDP per capita data from the Alpha Vantage API. 1308 | 1309 | :argument: interval (str): The time interval for the data (default: "monthly"). 1310 | :argument: datatype (str): The response data type (default: "json"). 1311 | 1312 | :returns: The real GDP per capita data. 1313 | """ 1314 | 1315 | https_params = { 1316 | "function": "REAL_GDP_PER_CAPITA", 1317 | "datatype": datatype, 1318 | "apikey": API_KEY, 1319 | } 1320 | 1321 | async with httpx.AsyncClient() as client: 1322 | response = await client.get(API_BASE_URL, params=https_params) 1323 | response.raise_for_status() 1324 | return response.text if datatype == "csv" else response.json() 1325 | 1326 | 1327 | async def fetch_treasury_yield( 1328 | interval: str = "monthly", maturity: str = "10year", datatype: str = "json" 1329 | ) -> dict[str, str] | str: 1330 | """ 1331 | Fetch treasure yield data from the Alpha Vantage API. 1332 | 1333 | :argument: interval (str): The time interval for the data (default: "monthly"). 1334 | :argument: maturity (str): The maturity period for the data (default: "monthly"). 1335 | :argument: datatype (str): The response data type (default: "json"). 1336 | 1337 | :returns: The treasure yield data. 1338 | """ 1339 | 1340 | https_params = { 1341 | "function": "TREASURY_YIELD", 1342 | "interval": interval, 1343 | "maturity": maturity, 1344 | "datatype": datatype, 1345 | "apikey": API_KEY, 1346 | } 1347 | 1348 | async with httpx.AsyncClient() as client: 1349 | response = await client.get(API_BASE_URL, params=https_params) 1350 | response.raise_for_status() 1351 | return response.text if datatype == "csv" else response.json() 1352 | 1353 | 1354 | async def fetch_federal_funds_rate( 1355 | interval: str = "monthly", datatype: str = "json" 1356 | ) -> dict[str, str] | str: 1357 | """ 1358 | Fetch federal funds rate data from the Alpha Vantage API. 1359 | 1360 | :argument: interval (str): The time interval for the data (default: "monthly"). 1361 | :argument: datatype (str): The response data type (default: "json"). 1362 | 1363 | :returns: The federal funds rate data. 1364 | """ 1365 | 1366 | https_params = { 1367 | "function": "FEDERAL_FUNDS_RATE", 1368 | "interval": interval, 1369 | "datatype": datatype, 1370 | "apikey": API_KEY, 1371 | } 1372 | 1373 | async with httpx.AsyncClient() as client: 1374 | response = await client.get(API_BASE_URL, params=https_params) 1375 | response.raise_for_status() 1376 | return response.text if datatype == "csv" else response.json() 1377 | 1378 | 1379 | async def fetch_cpi( 1380 | interval: str = "monthly", datatype: str = "json" 1381 | ) -> dict[str, str] | str: 1382 | """ 1383 | Fetch consumer price index (CPI) data from the Alpha Vantage API. 1384 | 1385 | :argument: interval (str): The time interval for the data (default: "monthly"). 1386 | :argument: datatype (str): The response data type (default: "json"). 1387 | 1388 | :returns: The consumer price index (CPI) data. 1389 | """ 1390 | 1391 | https_params = { 1392 | "function": "CPI", 1393 | "interval": interval, 1394 | "datatype": datatype, 1395 | "apikey": API_KEY, 1396 | } 1397 | 1398 | async with httpx.AsyncClient() as client: 1399 | response = await client.get(API_BASE_URL, params=https_params) 1400 | response.raise_for_status() 1401 | return response.text if datatype == "csv" else response.json() 1402 | 1403 | 1404 | async def fetch_inflation(datatype: str = "json") -> dict[str, str] | str: 1405 | """ 1406 | Fetch inflation data from the Alpha Vantage API. 1407 | 1408 | :argument: datatype (str): The response data type (default: "json"). 1409 | 1410 | :returns: The inflation data. 1411 | """ 1412 | 1413 | https_params = { 1414 | "function": "INFLATION", 1415 | "datatype": datatype, 1416 | "apikey": API_KEY, 1417 | } 1418 | 1419 | async with httpx.AsyncClient() as client: 1420 | response = await client.get(API_BASE_URL, params=https_params) 1421 | response.raise_for_status() 1422 | return response.text if datatype == "csv" else response.json() 1423 | 1424 | 1425 | async def fetch_retail_sales(datatype: str = "json") -> dict[str, str] | str: 1426 | """ 1427 | Fetch retail sales data from the Alpha Vantage API. 1428 | 1429 | :argument: datatype (str): The response data type (default: "json"). 1430 | 1431 | :returns: The retail sales data. 1432 | """ 1433 | 1434 | https_params = { 1435 | "function": "RETAIL_SALES", 1436 | "datatype": datatype, 1437 | "apikey": API_KEY, 1438 | } 1439 | 1440 | async with httpx.AsyncClient() as client: 1441 | response = await client.get(API_BASE_URL, params=https_params) 1442 | response.raise_for_status() 1443 | return response.text if datatype == "csv" else response.json() 1444 | 1445 | 1446 | async def fetch_durables(datatype: str = "json") -> dict[str, str] | str: 1447 | """ 1448 | Fetch durable goods data from the Alpha Vantage API. 1449 | 1450 | :argument: datatype (str): The response data type (default: "json"). 1451 | 1452 | :returns: The durable goods data. 1453 | """ 1454 | 1455 | https_params = { 1456 | "function": "DURABLES", 1457 | "datatype": datatype, 1458 | "apikey": API_KEY, 1459 | } 1460 | 1461 | async with httpx.AsyncClient() as client: 1462 | response = await client.get(API_BASE_URL, params=https_params) 1463 | response.raise_for_status() 1464 | return response.text if datatype == "csv" else response.json() 1465 | 1466 | 1467 | async def fetch_unemployment(datatype: str = "json") -> dict[str, str] | str: 1468 | """ 1469 | Fetch unemployment data from the Alpha Vantage API. 1470 | 1471 | :argument: datatype (str): The response data type (default: "json"). 1472 | 1473 | :returns: The unemployment data. 1474 | """ 1475 | 1476 | https_params = { 1477 | "function": "UNEMPLOYMENT", 1478 | "datatype": datatype, 1479 | "apikey": API_KEY, 1480 | } 1481 | 1482 | async with httpx.AsyncClient() as client: 1483 | response = await client.get(API_BASE_URL, params=https_params) 1484 | response.raise_for_status() 1485 | return response.text if datatype == "csv" else response.json() 1486 | 1487 | 1488 | async def fetch_nonfarm_payrolls(datatype: str = "json") -> dict[str, str] | str: 1489 | """ 1490 | Fetch nonfarm payrolls data from the Alpha Vantage API. 1491 | 1492 | :argument: datatype (str): The response data type (default: "json"). 1493 | 1494 | :returns: The nonfarm payrolls' data. 1495 | """ 1496 | 1497 | https_params = { 1498 | "function": "NONFARM_PAYROLL", 1499 | "datatype": datatype, 1500 | "apikey": API_KEY, 1501 | } 1502 | 1503 | async with httpx.AsyncClient() as client: 1504 | response = await client.get(API_BASE_URL, params=https_params) 1505 | response.raise_for_status() 1506 | return response.text if datatype == "csv" else response.json() 1507 | 1508 | 1509 | ##### 1510 | # Technical indicators APIs 1511 | ##### 1512 | 1513 | 1514 | async def fetch_sma( 1515 | symbol: str, 1516 | interval: str = None, 1517 | month: str = None, 1518 | time_period: int = None, 1519 | series_type: str = None, 1520 | datatype: str = "json", 1521 | ) -> dict[str, str] | str: 1522 | """ 1523 | Fetch simple moving average (SMA) data from the Alpha Vantage API. 1524 | 1525 | :argument: symbol (str): The stock symbol to fetch. 1526 | :argument: interval (str): The time interval for the data. 1527 | :argument: month (str): The month for the data. 1528 | :argument: time_period (int): The time period for the data. 1529 | :argument: series_type (str): The series type for the data. 1530 | :argument: datatype (str): The response data type (default: "json"). 1531 | 1532 | :returns: The simple moving average (SMA) data. 1533 | """ 1534 | 1535 | https_params = { 1536 | "function": "SMA", 1537 | "symbol": symbol, 1538 | "interval": interval, 1539 | "month": month, 1540 | "time_period": time_period, 1541 | "series_type": series_type, 1542 | "datatype": datatype, 1543 | "apikey": API_KEY, 1544 | } 1545 | 1546 | async with httpx.AsyncClient() as client: 1547 | response = await client.get(API_BASE_URL, params=https_params) 1548 | response.raise_for_status() 1549 | return response.text if datatype == "csv" else response.json() 1550 | 1551 | 1552 | async def fetch_ema( 1553 | symbol: str, 1554 | interval: str = None, 1555 | month: str = None, 1556 | time_period: int = None, 1557 | series_type: str = None, 1558 | datatype: str = "json", 1559 | ) -> dict[str, str] | str: 1560 | """ 1561 | Fetch exponential moving average (EMA) data from the Alpha Vantage API. 1562 | 1563 | :argument: symbol (str): The stock symbol to fetch. 1564 | :argument: interval (str): The time interval for the data. 1565 | :argument: month (str): The month for the data. 1566 | :argument: time_period (int): The time period for the data. 1567 | :argument: series_type (str): The series type for the data. 1568 | :argument: datatype (str): The response data type (default: "json"). 1569 | 1570 | :returns: The exponential moving average (EMA) data. 1571 | """ 1572 | 1573 | https_params = { 1574 | "function": "EMA", 1575 | "symbol": symbol, 1576 | "interval": interval, 1577 | "month": month, 1578 | "time_period": time_period, 1579 | "series_type": series_type, 1580 | "datatype": datatype, 1581 | "apikey": API_KEY, 1582 | } 1583 | 1584 | async with httpx.AsyncClient() as client: 1585 | response = await client.get(API_BASE_URL, params=https_params) 1586 | response.raise_for_status() 1587 | return response.text if datatype == "csv" else response.json() 1588 | 1589 | 1590 | async def fetch_wma( 1591 | symbol: str, 1592 | interval: str = None, 1593 | month: str = None, 1594 | time_period: int = None, 1595 | series_type: str = None, 1596 | datatype: str = "json", 1597 | ) -> dict[str, str] | str: 1598 | """ 1599 | Fetch weighted moving average (WMA) data from the Alpha Vantage API. 1600 | 1601 | :argument: symbol (str): The stock symbol to fetch. 1602 | :argument: interval (str): The time interval for the data. 1603 | :argument: month (str): The month for the data. 1604 | :argument: time_period (int): The time period for the data. 1605 | :argument: series_type (str): The series type for the data. 1606 | :argument: datatype (str): The response data type (default: "json"). 1607 | 1608 | :returns: The weighted moving average (WMA) data. 1609 | """ 1610 | 1611 | https_params = { 1612 | "function": "WMA", 1613 | "symbol": symbol, 1614 | "interval": interval, 1615 | "month": month, 1616 | "time_period": time_period, 1617 | "series_type": series_type, 1618 | "datatype": datatype, 1619 | "apikey": API_KEY, 1620 | } 1621 | 1622 | async with httpx.AsyncClient() as client: 1623 | response = await client.get(API_BASE_URL, params=https_params) 1624 | response.raise_for_status() 1625 | return response.text if datatype == "csv" else response.json() 1626 | 1627 | 1628 | async def fetch_dema( 1629 | symbol: str, 1630 | interval: str = None, 1631 | month: str = None, 1632 | time_period: int = None, 1633 | series_type: str = None, 1634 | datatype: str = "json", 1635 | ) -> dict[str, str] | str: 1636 | """ 1637 | Fetch double exponential moving average (DEMA) data from the Alpha Vantage API. 1638 | 1639 | :argument: symbol (str): The stock symbol to fetch. 1640 | :argument: interval (str): The time interval for the data. 1641 | :argument: month (str): The month for the data. 1642 | :argument: time_period (int): The time period for the data. 1643 | :argument: series_type (str): The series type for the data. 1644 | :argument: datatype (str): The response data type (default: "json"). 1645 | 1646 | :returns: The double exponential moving average (DEMA) data. 1647 | """ 1648 | 1649 | https_params = { 1650 | "function": "DEMA", 1651 | "symbol": symbol, 1652 | "interval": interval, 1653 | "month": month, 1654 | "time_period": time_period, 1655 | "series_type": series_type, 1656 | "datatype": datatype, 1657 | "apikey": API_KEY, 1658 | } 1659 | 1660 | async with httpx.AsyncClient() as client: 1661 | response = await client.get(API_BASE_URL, params=https_params) 1662 | response.raise_for_status() 1663 | return response.text if datatype == "csv" else response.json() 1664 | 1665 | 1666 | async def fetch_tema( 1667 | symbol: str, 1668 | interval: str = None, 1669 | month: str = None, 1670 | time_period: int = None, 1671 | series_type: str = None, 1672 | datatype: str = "json", 1673 | ) -> dict[str, str] | str: 1674 | """ 1675 | Fetch triple exponential moving average (TEMA) data from the Alpha Vantage API. 1676 | 1677 | :argument: symbol (str): The stock symbol to fetch. 1678 | :argument: interval (str): The time interval for the data. 1679 | :argument: month (str): The month for the data. 1680 | :argument: time_period (int): The time period for the data. 1681 | :argument: series_type (str): The series type for the data. 1682 | :argument: datatype (str): The response data type (default: "json"). 1683 | 1684 | :returns: The triple exponential moving average (TEMA) data. 1685 | """ 1686 | 1687 | https_params = { 1688 | "function": "TEMA", 1689 | "symbol": symbol, 1690 | "interval": interval, 1691 | "month": month, 1692 | "time_period": time_period, 1693 | "series_type": series_type, 1694 | "datatype": datatype, 1695 | "apikey": API_KEY, 1696 | } 1697 | 1698 | async with httpx.AsyncClient() as client: 1699 | response = await client.get(API_BASE_URL, params=https_params) 1700 | response.raise_for_status() 1701 | return response.text if datatype == "csv" else response.json() 1702 | 1703 | 1704 | async def fetch_trima( 1705 | symbol: str, 1706 | interval: str = None, 1707 | month: str = None, 1708 | time_period: int = None, 1709 | series_type: str = None, 1710 | datatype: str = "json", 1711 | ) -> dict[str, str] | str: 1712 | """ 1713 | Fetch triangular moving average (TRIMA) data from the Alpha Vantage API. 1714 | 1715 | :argument: symbol (str): The stock symbol to fetch. 1716 | :argument: interval (str): The time interval for the data. 1717 | :argument: month (str): The month for the data. 1718 | :argument: time_period (int): The time period for the data. 1719 | :argument: series_type (str): The series type for the data. 1720 | :argument: datatype (str): The response data type (default: "json"). 1721 | 1722 | :returns: The triangular moving average (TRIMA) data. 1723 | """ 1724 | 1725 | https_params = { 1726 | "function": "TRIMA", 1727 | "symbol": symbol, 1728 | "interval": interval, 1729 | "month": month, 1730 | "time_period": time_period, 1731 | "series_type": series_type, 1732 | "datatype": datatype, 1733 | "apikey": API_KEY, 1734 | } 1735 | 1736 | async with httpx.AsyncClient() as client: 1737 | response = await client.get(API_BASE_URL, params=https_params) 1738 | response.raise_for_status() 1739 | return response.text if datatype == "csv" else response.json() 1740 | 1741 | 1742 | async def fetch_kama( 1743 | symbol: str, 1744 | interval: str = None, 1745 | month: str = None, 1746 | time_period: int = None, 1747 | series_type: str = None, 1748 | datatype: str = "json", 1749 | ) -> dict[str, str] | str: 1750 | """ 1751 | Fetch Kaufman adaptive moving average (KAMA) data from the Alpha Vantage API. 1752 | 1753 | :argument: symbol (str): The stock symbol to fetch. 1754 | :argument: interval (str): The time interval for the data. 1755 | :argument: month (str): The month for the data. 1756 | :argument: time_period (int): The time period for the data. 1757 | :argument: series_type (str): The series type for the data. 1758 | :argument: datatype (str): The response data type (default: "json"). 1759 | 1760 | :returns: The Kaufman adaptive moving average (KAMA) data. 1761 | """ 1762 | 1763 | https_params = { 1764 | "function": "KAMA", 1765 | "symbol": symbol, 1766 | "interval": interval, 1767 | "month": month, 1768 | "time_period": time_period, 1769 | "series_type": series_type, 1770 | "datatype": datatype, 1771 | "apikey": API_KEY, 1772 | } 1773 | 1774 | async with httpx.AsyncClient() as client: 1775 | response = await client.get(API_BASE_URL, params=https_params) 1776 | response.raise_for_status() 1777 | return response.text if datatype == "csv" else response.json() 1778 | 1779 | 1780 | async def fetch_mama( 1781 | symbol: str, 1782 | interval: str = None, 1783 | month: str = None, 1784 | series_type: str = None, 1785 | fastlimit: float = 0.01, 1786 | slowlimit: float = 0.01, 1787 | datatype: str = "json", 1788 | ) -> dict[str, str] | str: 1789 | """ 1790 | Fetch MESA adaptive moving average (MAMA) data from the Alpha Vantage API. 1791 | 1792 | :argument: symbol (str): The stock symbol to fetch. 1793 | :argument: interval (str): The time interval for the data. 1794 | :argument: month (str): The month for the data. 1795 | :argument: series_type (str): The series type for the data. 1796 | :argument: fastlimit (float): The fast limit for the data. 1797 | :argument: slowlimit (float): The slow limit for the data. 1798 | :argument: datatype (str): The response data type (default: "json"). 1799 | 1800 | :returns: The MESA adaptive moving average (MAMA) data. 1801 | """ 1802 | 1803 | https_params = { 1804 | "function": "MAMA", 1805 | "symbol": symbol, 1806 | "interval": interval, 1807 | "month": month, 1808 | "series_type": series_type, 1809 | "fastlimit": fastlimit, 1810 | "slowlimit": slowlimit, 1811 | "datatype": datatype, 1812 | "apikey": API_KEY, 1813 | } 1814 | 1815 | async with httpx.AsyncClient() as client: 1816 | response = await client.get(API_BASE_URL, params=https_params) 1817 | response.raise_for_status() 1818 | return response.text if datatype == "csv" else response.json() 1819 | 1820 | 1821 | async def fetch_vwap( 1822 | symbol: str, 1823 | interval: str = None, 1824 | month: str = None, 1825 | datatype: str = "json", 1826 | ) -> dict[str, str] | str: 1827 | """ 1828 | Fetch volume weighted average price (VWAP) data from the Alpha Vantage API. 1829 | 1830 | :argument: symbol (str): The stock symbol to fetch. 1831 | :argument: interval (str): The time interval for the data. 1832 | :argument: month (str): The month for the data. 1833 | :argument: datatype (str): The response data type (default: "json"). 1834 | 1835 | :returns: The volume weighted average price (VWAP) data. 1836 | """ 1837 | 1838 | https_params = { 1839 | "function": "VWAP", 1840 | "symbol": symbol, 1841 | "interval": interval, 1842 | "month": month, 1843 | "datatype": datatype, 1844 | "apikey": API_KEY, 1845 | } 1846 | 1847 | async with httpx.AsyncClient() as client: 1848 | response = await client.get(API_BASE_URL, params=https_params) 1849 | response.raise_for_status() 1850 | return response.text if datatype == "csv" else response.json() 1851 | 1852 | 1853 | async def fetch_t3( 1854 | symbol: str, 1855 | interval: str = None, 1856 | month: str = None, 1857 | time_period: int = None, 1858 | series_type: str = None, 1859 | datatype: str = "json", 1860 | ) -> dict[str, str] | str: 1861 | """ 1862 | Fetch triple exponential moving average (T3) data from the Alpha Vantage API. 1863 | 1864 | :argument: symbol (str): The stock symbol to fetch. 1865 | :argument: interval (str): The time interval for the data. 1866 | :argument: month (str): The month for the data. 1867 | :argument: time_period (int): The time period for the data. 1868 | :argument: series_type (str): The series type for the data. 1869 | :argument: datatype (str): The response data type (default: "json"). 1870 | 1871 | :returns: The triple exponential moving average (T3) data. 1872 | """ 1873 | 1874 | https_params = { 1875 | "function": "T3", 1876 | "symbol": symbol, 1877 | "interval": interval, 1878 | "month": month, 1879 | "time_period": time_period, 1880 | "series_type": series_type, 1881 | "datatype": datatype, 1882 | "apikey": API_KEY, 1883 | } 1884 | 1885 | async with httpx.AsyncClient() as client: 1886 | response = await client.get(API_BASE_URL, params=https_params) 1887 | response.raise_for_status() 1888 | return response.text if datatype == "csv" else response.json() 1889 | 1890 | 1891 | async def fetch_macd( 1892 | symbol: str, 1893 | interval: str = None, 1894 | month: str = None, 1895 | series_type: str = None, 1896 | fastperiod: int = 12, 1897 | slowperiod: int = 26, 1898 | signalperiod: int = 9, 1899 | datatype: str = "json", 1900 | ) -> dict[str, str] | str: 1901 | """ 1902 | Fetch moving average convergence divergence (MACD) data from the Alpha Vantage API. 1903 | 1904 | :argument: symbol (str): The stock symbol to fetch. 1905 | :argument: interval (str): The time interval for the data. 1906 | :argument: month (str): The month for the data. 1907 | :argument: series_type (str): The series type for the data. 1908 | :argument: fastperiod (int): The fast period for the data. 1909 | :argument: slowperiod (int): The slow period for the data. 1910 | :argument: signalperiod (int): The signal period for the data. 1911 | :argument: datatype (str): The response data type (default: "json"). 1912 | 1913 | :returns: The moving average convergence divergence (MACD) data. 1914 | """ 1915 | 1916 | https_params = { 1917 | "function": "MACD", 1918 | "symbol": symbol, 1919 | "interval": interval, 1920 | "month": month, 1921 | "series_type": series_type, 1922 | "fastperiod": fastperiod, 1923 | "slowperiod": slowperiod, 1924 | "signalperiod": signalperiod, 1925 | "datatype": datatype, 1926 | "apikey": API_KEY, 1927 | } 1928 | 1929 | async with httpx.AsyncClient() as client: 1930 | response = await client.get(API_BASE_URL, params=https_params) 1931 | response.raise_for_status() 1932 | return response.text if datatype == "csv" else response.json() 1933 | 1934 | 1935 | async def fetch_macdext( 1936 | symbol: str, 1937 | interval: str = None, 1938 | month: str = None, 1939 | series_type: str = None, 1940 | fastperiod: int = 12, 1941 | slowperiod: int = 26, 1942 | signalperiod: int = 9, 1943 | fastmatype: int = 0, 1944 | slowmatype: int = 0, 1945 | signalmatype: int = 0, 1946 | datatype: str = "json", 1947 | ) -> dict[str, str] | str: 1948 | """ 1949 | Fetch moving average convergence divergence with controllable moving average type (MACDEXT) data from the Alpha Vantage API. 1950 | 1951 | :argument: symbol (str): The stock symbol to fetch. 1952 | :argument: interval (str): The time interval for the data. 1953 | :argument: month (str): The month for the data. 1954 | :argument: series_type (str): The series type for the data. 1955 | :argument: fastperiod (int): The fast period for the data. 1956 | :argument: slowperiod (int): The slow period for the data. 1957 | :argument: signalperiod (int): The signal period for the data. 1958 | :argument: fastmatype (int): The fast moving average type for the data. 1959 | :argument: slowmatype (int): The slow moving average type for the data. 1960 | :argument: signalmatype (int): The signal moving average type for the data. 1961 | :argument: datatype (str): The response data type (default: "json"). 1962 | 1963 | :returns: The moving average convergence divergence with controllable moving average type (MACDEXT) data. 1964 | """ 1965 | 1966 | https_params = { 1967 | "function": "MACDEXT", 1968 | "symbol": symbol, 1969 | "interval": interval, 1970 | "month": month, 1971 | "series_type": series_type, 1972 | "fastperiod": fastperiod, 1973 | "slowperiod": slowperiod, 1974 | "signalperiod": signalperiod, 1975 | "fastmatype": fastmatype, 1976 | "slowmatype": slowmatype, 1977 | "signalmatype": signalmatype, 1978 | "datatype": datatype, 1979 | "apikey": API_KEY, 1980 | } 1981 | 1982 | async with httpx.AsyncClient() as client: 1983 | response = await client.get(API_BASE_URL, params=https_params) 1984 | response.raise_for_status() 1985 | return response.text if datatype == "csv" else response.json() 1986 | 1987 | 1988 | async def fetch_stoch( 1989 | symbol: str, 1990 | interval: str = None, 1991 | month: str = None, 1992 | fastkperiod: int = 5, 1993 | slowkperiod: int = 3, 1994 | slowdperiod: int = 3, 1995 | slowkmatype: int = 0, 1996 | slowdmatype: int = 0, 1997 | datatype: str = "json", 1998 | ) -> dict[str, str] | str: 1999 | """ 2000 | Fetch stochastic oscillator (STOCH) data from the Alpha Vantage API. 2001 | 2002 | :argument: symbol (str): The stock symbol to fetch. 2003 | :argument: interval (str): The time interval for the data. 2004 | :argument: month (str): The month for the data. 2005 | :argument: fastkperiod (int): The fast K period for the data. 2006 | :argument: slowkperiod (int): The slow K period for the data. 2007 | :argument: slowdperiod (int): The slow D period for the data. 2008 | :argument: slowkmatype (int): The slow K moving average type for the data. 2009 | :argument: slowdmatype (int): The slow D moving average type for the data. 2010 | :argument: datatype (str): The response data type (default: "json"). 2011 | 2012 | :returns: The stochastic oscillator (STOCH) data. 2013 | """ 2014 | 2015 | https_params = { 2016 | "function": "STOCH", 2017 | "symbol": symbol, 2018 | "interval": interval, 2019 | "month": month, 2020 | "fastkperiod": fastkperiod, 2021 | "slowkperiod": slowkperiod, 2022 | "slowdperiod": slowdperiod, 2023 | "slowkmatype": slowkmatype, 2024 | "slowdmatype": slowdmatype, 2025 | "datatype": datatype, 2026 | "apikey": API_KEY, 2027 | } 2028 | 2029 | async with httpx.AsyncClient() as client: 2030 | response = await client.get(API_BASE_URL, params=https_params) 2031 | response.raise_for_status() 2032 | return response.text if datatype == "csv" else response.json() 2033 | 2034 | 2035 | async def fetch_stochf( 2036 | symbol: str, 2037 | interval: str = None, 2038 | month: str = None, 2039 | fastkperiod: int = 5, 2040 | fastdperiod: int = 3, 2041 | fastdmatype: int = 0, 2042 | datatype: str = "json", 2043 | ) -> dict[str, str] | str: 2044 | """ 2045 | Fetch stochastic oscillator fast (STOCHF) data from the Alpha Vantage API. 2046 | 2047 | :argument: symbol (str): The stock symbol to fetch. 2048 | :argument: interval (str): The time interval for the data. 2049 | :argument: month (str): The month for the data. 2050 | :argument: fastkperiod (int): The fast K period for the data. 2051 | :argument: fastdperiod (int): The fast D period for the data. 2052 | :argument: fastdmatype (int): The fast D moving average type for the data. 2053 | :argument: datatype (str): The response data type (default: "json"). 2054 | 2055 | :returns: The stochastic oscillator fast (STOCHF) data. 2056 | """ 2057 | 2058 | https_params = { 2059 | "function": "STOCHF", 2060 | "symbol": symbol, 2061 | "interval": interval, 2062 | "month": month, 2063 | "fastkperiod": fastkperiod, 2064 | "fastdperiod": fastdperiod, 2065 | "fastdmatype": fastdmatype, 2066 | "datatype": datatype, 2067 | "apikey": API_KEY, 2068 | } 2069 | 2070 | async with httpx.AsyncClient() as client: 2071 | response = await client.get(API_BASE_URL, params=https_params) 2072 | response.raise_for_status() 2073 | return response.text if datatype == "csv" else response.json() 2074 | 2075 | 2076 | async def fetch_rsi( 2077 | symbol: str, 2078 | interval: str = None, 2079 | month: str = None, 2080 | time_period: int = 14, 2081 | series_type: str = None, 2082 | datatype: str = "json", 2083 | ) -> dict[str, str] | str: 2084 | """ 2085 | Fetch relative strength index (RSI) data from the Alpha Vantage API. 2086 | 2087 | :argument: symbol (str): The stock symbol to fetch. 2088 | :argument: interval (str): The time interval for the data. 2089 | :argument: month (str): The month for the data. 2090 | :argument: time_period (int): The time period for the data. 2091 | :argument: series_type (str): The series type for the data. 2092 | :argument: datatype (str): The response data type (default: "json"). 2093 | 2094 | :returns: The relative strength index (RSI) data. 2095 | """ 2096 | 2097 | https_params = { 2098 | "function": "RSI", 2099 | "symbol": symbol, 2100 | "interval": interval, 2101 | "month": month, 2102 | "time_period": time_period, 2103 | "series_type": series_type, 2104 | "datatype": datatype, 2105 | "apikey": API_KEY, 2106 | } 2107 | 2108 | async with httpx.AsyncClient() as client: 2109 | response = await client.get(API_BASE_URL, params=https_params) 2110 | response.raise_for_status() 2111 | return response.text if datatype == "csv" else response.json() 2112 | 2113 | 2114 | async def fetch_stochrsi( 2115 | symbol: str, 2116 | interval: str = None, 2117 | month: str = None, 2118 | time_period: int = 14, 2119 | series_type: str = None, 2120 | fastkperiod: int = 5, 2121 | fastdperiod: int = 3, 2122 | fastdmatype: int = 0, 2123 | datatype: str = "json", 2124 | ) -> dict[str, str] | str: 2125 | """ 2126 | Fetch stochastic relative strength index (STOCHRSI) data from the Alpha Vantage API. 2127 | 2128 | :argument: symbol (str): The stock symbol to fetch. 2129 | :argument: interval (str): The time interval for the data. 2130 | :argument: month (str): The month for the data. 2131 | :argument: time_period (int): The time period for the data. 2132 | :argument: series_type (str): The series type for the data. 2133 | :argument: fastkperiod (int): The fast K period for the data. 2134 | :argument: fastdperiod (int): The fast D period for the data. 2135 | :argument: fastdmatype (int): The fast D moving average type for the data. 2136 | :argument: datatype (str): The response data type (default: "json"). 2137 | 2138 | :returns: The stochastic relative strength index (STOCHRSI) data. 2139 | """ 2140 | 2141 | https_params = { 2142 | "function": "STOCHRSI", 2143 | "symbol": symbol, 2144 | "interval": interval, 2145 | "month": month, 2146 | "time_period": time_period, 2147 | "series_type": series_type, 2148 | "fastkperiod": fastkperiod, 2149 | "fastdperiod": fastdperiod, 2150 | "fastdmatype": fastdmatype, 2151 | "datatype": datatype, 2152 | "apikey": API_KEY, 2153 | } 2154 | 2155 | async with httpx.AsyncClient() as client: 2156 | response = await client.get(API_BASE_URL, params=https_params) 2157 | response.raise_for_status() 2158 | return response.text if datatype == "csv" else response.json() 2159 | 2160 | 2161 | async def fetch_willr( 2162 | symbol: str, 2163 | interval: str = None, 2164 | month: str = None, 2165 | time_period: int = 14, 2166 | datatype: str = "json", 2167 | ) -> dict[str, str] | str: 2168 | """ 2169 | Fetch Williams' %R (WILLR) data from the Alpha Vantage API. 2170 | 2171 | :argument: symbol (str): The stock symbol to fetch. 2172 | :argument: interval (str): The time interval for the data. 2173 | :argument: month (str): The month for the data. 2174 | :argument: time_period (int): The time period for the data. 2175 | :argument: datatype (str): The response data type (default: "json"). 2176 | 2177 | :returns: Williams' %R (WILLR) data. 2178 | """ 2179 | 2180 | https_params = { 2181 | "function": "WILLR", 2182 | "symbol": symbol, 2183 | "interval": interval, 2184 | "month": month, 2185 | "time_period": time_period, 2186 | "datatype": datatype, 2187 | "apikey": API_KEY, 2188 | } 2189 | 2190 | async with httpx.AsyncClient() as client: 2191 | response = await client.get(API_BASE_URL, params=https_params) 2192 | response.raise_for_status() 2193 | return response.text if datatype == "csv" else response.json() 2194 | 2195 | 2196 | async def fetch_adx( 2197 | symbol: str, 2198 | interval: str = None, 2199 | month: str = None, 2200 | time_period: int = 14, 2201 | datatype: str = "json", 2202 | ) -> dict[str, str] | str: 2203 | """ 2204 | Fetch average directional movement index (ADX) data from the Alpha Vantage API. 2205 | 2206 | :argument: symbol (str): The stock symbol to fetch. 2207 | :argument: interval (str): The time interval for the data. 2208 | :argument: month (str): The month for the data. 2209 | :argument: time_period (int): The time period for the data. 2210 | :argument: datatype (str): The response data type (default: "json"). 2211 | 2212 | :returns: Average directional movement index (ADX) data. 2213 | """ 2214 | 2215 | https_params = { 2216 | "function": "ADX", 2217 | "symbol": symbol, 2218 | "interval": interval, 2219 | "month": month, 2220 | "time_period": time_period, 2221 | "datatype": datatype, 2222 | "apikey": API_KEY, 2223 | } 2224 | 2225 | async with httpx.AsyncClient() as client: 2226 | response = await client.get(API_BASE_URL, params=https_params) 2227 | response.raise_for_status() 2228 | return response.text if datatype == "csv" else response.json() 2229 | 2230 | 2231 | async def fetch_adxr( 2232 | symbol: str, 2233 | interval: str = None, 2234 | month: str = None, 2235 | time_period: int = 14, 2236 | datatype: str = "json", 2237 | ) -> dict[str, str] | str: 2238 | """ 2239 | Fetch average directional movement index rating (ADXR) data from the Alpha Vantage API. 2240 | 2241 | :argument: symbol (str): The stock symbol to fetch. 2242 | :argument: interval (str): The time interval for the data. 2243 | :argument: month (str): The month for the data. 2244 | :argument: time_period (int): The time period for the data. 2245 | :argument: datatype (str): The response data type (default: "json"). 2246 | 2247 | :returns: Average directional movement index rating (ADXR) data. 2248 | """ 2249 | 2250 | https_params = { 2251 | "function": "ADXR", 2252 | "symbol": symbol, 2253 | "interval": interval, 2254 | "month": month, 2255 | "time_period": time_period, 2256 | "datatype": datatype, 2257 | "apikey": API_KEY, 2258 | } 2259 | 2260 | async with httpx.AsyncClient() as client: 2261 | response = await client.get(API_BASE_URL, params=https_params) 2262 | response.raise_for_status() 2263 | return response.text if datatype == "csv" else response.json() 2264 | 2265 | 2266 | async def fetch_apo( 2267 | symbol: str, 2268 | interval: str = None, 2269 | month: str = None, 2270 | series_type: str = None, 2271 | fastperiod: int = 12, 2272 | slowperiod: int = 26, 2273 | matype: int = 0, 2274 | datatype: str = "json", 2275 | ) -> dict[str, str] | str: 2276 | """ 2277 | Fetch absolute price oscillator (APO) data from the Alpha Vantage API. 2278 | 2279 | :argument: symbol (str): The stock symbol to fetch. 2280 | :argument: interval (str): The time interval for the data. 2281 | :argument: month (str): The month for the data. 2282 | :argument: series_type (str): The series type for the data. 2283 | :argument: fastperiod (int): The fast period for the data. 2284 | :argument: slowperiod (int): The slow period for the data. 2285 | :argument: matype (int): The moving average type for the data. 2286 | :argument: datatype (str): The response data type (default: "json"). 2287 | 2288 | :returns: Absolute price oscillator (APO) data. 2289 | """ 2290 | 2291 | https_params = { 2292 | "function": "APO", 2293 | "symbol": symbol, 2294 | "interval": interval, 2295 | "month": month, 2296 | "series_type": series_type, 2297 | "fastperiod": fastperiod, 2298 | "slowperiod": slowperiod, 2299 | "matype": matype, 2300 | "datatype": datatype, 2301 | "apikey": API_KEY, 2302 | } 2303 | 2304 | async with httpx.AsyncClient() as client: 2305 | response = await client.get(API_BASE_URL, params=https_params) 2306 | response.raise_for_status() 2307 | return response.text if datatype == "csv" else response.json() 2308 | 2309 | 2310 | async def fetch_ppo( 2311 | symbol: str, 2312 | interval: str = None, 2313 | month: str = None, 2314 | series_type: str = None, 2315 | fastperiod: int = 12, 2316 | slowperiod: int = 26, 2317 | matype: int = 0, 2318 | datatype: str = "json", 2319 | ) -> dict[str, str] | str: 2320 | """ 2321 | Fetch percentage price oscillator (PPO) data from the Alpha Vantage API. 2322 | 2323 | :argument: symbol (str): The stock symbol to fetch. 2324 | :argument: interval (str): The time interval for the data. 2325 | :argument: month (str): The month for the data. 2326 | :argument: series_type (str): The series type for the data. 2327 | :argument: fastperiod (int): The fast period for the data. 2328 | :argument: slowperiod (int): The slow period for the data. 2329 | :argument: matype (int): The moving average type for the data. 2330 | :argument: datatype (str): The response data type (default: "json"). 2331 | 2332 | :returns: Percentage price oscillator (PPO) data. 2333 | """ 2334 | 2335 | https_params = { 2336 | "function": "PPO", 2337 | "symbol": symbol, 2338 | "interval": interval, 2339 | "month": month, 2340 | "series_type": series_type, 2341 | "fastperiod": fastperiod, 2342 | "slowperiod": slowperiod, 2343 | "matype": matype, 2344 | "datatype": datatype, 2345 | "apikey": API_KEY, 2346 | } 2347 | 2348 | async with httpx.AsyncClient() as client: 2349 | response = await client.get(API_BASE_URL, params=https_params) 2350 | response.raise_for_status() 2351 | return response.text if datatype == "csv" else response.json() 2352 | 2353 | 2354 | async def fetch_mom( 2355 | symbol: str, 2356 | interval: str = None, 2357 | month: str = None, 2358 | time_period: int = 10, 2359 | series_type: str = None, 2360 | datatype: str = "json", 2361 | ) -> dict[str, str] | str: 2362 | """ 2363 | Fetch momentum (MOM) data from the Alpha Vantage API. 2364 | 2365 | :argument: symbol (str): The stock symbol to fetch. 2366 | :argument: interval (str): The time interval for the data. 2367 | :argument: month (str): The month for the data. 2368 | :argument: time_period (int): The time period for the data. 2369 | :argument: series_type (str): The series type for the data. 2370 | :argument: datatype (str): The response data type (default: "json"). 2371 | 2372 | :returns: Momentum (MOM) data. 2373 | """ 2374 | 2375 | https_params = { 2376 | "function": "MOM", 2377 | "symbol": symbol, 2378 | "interval": interval, 2379 | "month": month, 2380 | "time_period": time_period, 2381 | "series_type": series_type, 2382 | "datatype": datatype, 2383 | "apikey": API_KEY, 2384 | } 2385 | 2386 | async with httpx.AsyncClient() as client: 2387 | response = await client.get(API_BASE_URL, params=https_params) 2388 | response.raise_for_status() 2389 | return response.text if datatype == "csv" else response.json() 2390 | 2391 | 2392 | async def fetch_bop( 2393 | symbol: str, 2394 | interval: str = None, 2395 | month: str = None, 2396 | datatype: str = "json", 2397 | ) -> dict[str, str] | str: 2398 | """ 2399 | Fetch balance of power (BOP) data from the Alpha Vantage API. 2400 | 2401 | :argument: symbol (str): The stock symbol to fetch. 2402 | :argument: interval (str): The time interval for the data. 2403 | :argument: month (str): The month for the data. 2404 | :argument: datatype (str): The response data type (default: "json"). 2405 | 2406 | :returns: Balance of power (BOP) data. 2407 | """ 2408 | 2409 | https_params = { 2410 | "function": "BOP", 2411 | "symbol": symbol, 2412 | "interval": interval, 2413 | "month": month, 2414 | "datatype": datatype, 2415 | "apikey": API_KEY, 2416 | } 2417 | 2418 | async with httpx.AsyncClient() as client: 2419 | response = await client.get(API_BASE_URL, params=https_params) 2420 | response.raise_for_status() 2421 | return response.text if datatype == "csv" else response.json() 2422 | 2423 | 2424 | async def fetch_cci( 2425 | symbol: str, 2426 | interval: str = None, 2427 | month: str = None, 2428 | time_period: int = 20, 2429 | datatype: str = "json", 2430 | ) -> dict[str, str] | str: 2431 | """ 2432 | Fetch commodity channel index (CCI) data from the Alpha Vantage API. 2433 | 2434 | :argument: symbol (str): The stock symbol to fetch. 2435 | :argument: interval (str): The time interval for the data. 2436 | :argument: month (str): The month for the data. 2437 | :argument: time_period (int): The time period for the data. 2438 | :argument: datatype (str): The response data type (default: "json"). 2439 | 2440 | :returns: Commodity channel index (CCI) data. 2441 | """ 2442 | 2443 | https_params = { 2444 | "function": "CCI", 2445 | "symbol": symbol, 2446 | "interval": interval, 2447 | "month": month, 2448 | "time_period": time_period, 2449 | "datatype": datatype, 2450 | "apikey": API_KEY, 2451 | } 2452 | 2453 | async with httpx.AsyncClient() as client: 2454 | response = await client.get(API_BASE_URL, params=https_params) 2455 | response.raise_for_status() 2456 | return response.text if datatype == "csv" else response.json() 2457 | 2458 | 2459 | async def fetch_cmo( 2460 | symbol: str, 2461 | interval: str = None, 2462 | month: str = None, 2463 | time_period: int = 14, 2464 | series_type: str = None, 2465 | datatype: str = "json", 2466 | ) -> dict[str, str] | str: 2467 | """ 2468 | Fetch Chande momentum oscillator (CMO) data from the Alpha Vantage API. 2469 | 2470 | :argument: symbol (str): The stock symbol to fetch. 2471 | :argument: interval (str): The time interval for the data. 2472 | :argument: month (str): The month for the data. 2473 | :argument: time_period (int): The time period for the data. 2474 | :argument: series_type (str): The series type for the data. 2475 | :argument: datatype (str): The response data type (default: "json"). 2476 | 2477 | :returns: Chande momentum oscillator (CMO) data. 2478 | """ 2479 | 2480 | https_params = { 2481 | "function": "CMO", 2482 | "symbol": symbol, 2483 | "interval": interval, 2484 | "month": month, 2485 | "time_period": time_period, 2486 | "series_type": series_type, 2487 | "datatype": datatype, 2488 | "apikey": API_KEY, 2489 | } 2490 | 2491 | async with httpx.AsyncClient() as client: 2492 | response = await client.get(API_BASE_URL, params=https_params) 2493 | response.raise_for_status() 2494 | return response.text if datatype == "csv" else response.json() 2495 | 2496 | 2497 | async def fetch_roc( 2498 | symbol: str, 2499 | interval: str = None, 2500 | month: str = None, 2501 | time_period: int = 10, 2502 | series_type: str = None, 2503 | datatype: str = "json", 2504 | ) -> dict[str, str] | str: 2505 | """ 2506 | Fetch rate of change (ROC) data from the Alpha Vantage API. 2507 | 2508 | :argument: symbol (str): The stock symbol to fetch. 2509 | :argument: interval (str): The time interval for the data. 2510 | :argument: month (str): The month for the data. 2511 | :argument: time_period (int): The time period for the data. 2512 | :argument: series_type (str): The series type for the data. 2513 | :argument: datatype (str): The response data type (default: "json"). 2514 | 2515 | :returns: Rate of change (ROC) data. 2516 | """ 2517 | 2518 | https_params = { 2519 | "function": "ROC", 2520 | "symbol": symbol, 2521 | "interval": interval, 2522 | "month": month, 2523 | "time_period": time_period, 2524 | "series_type": series_type, 2525 | "datatype": datatype, 2526 | "apikey": API_KEY, 2527 | } 2528 | 2529 | async with httpx.AsyncClient() as client: 2530 | response = await client.get(API_BASE_URL, params=https_params) 2531 | response.raise_for_status() 2532 | return response.text if datatype == "csv" else response.json() 2533 | 2534 | 2535 | async def fetch_rocr( 2536 | symbol: str, 2537 | interval: str = None, 2538 | month: str = None, 2539 | time_period: int = 10, 2540 | series_type: str = None, 2541 | datatype: str = "json", 2542 | ) -> dict[str, str] | str: 2543 | """ 2544 | Fetch rate of change ratio (ROCR) data from the Alpha Vantage API. 2545 | 2546 | :argument: symbol (str): The stock symbol to fetch. 2547 | :argument: interval (str): The time interval for the data. 2548 | :argument: month (str): The month for the data. 2549 | :argument: time_period (int): The time period for the data. 2550 | :argument: series_type (str): The series type for the data. 2551 | :argument: datatype (str): The response data type (default: "json"). 2552 | 2553 | :returns: Rate of change ratio (ROCR) data. 2554 | """ 2555 | 2556 | https_params = { 2557 | "function": "ROCR", 2558 | "symbol": symbol, 2559 | "interval": interval, 2560 | "month": month, 2561 | "time_period": time_period, 2562 | "series_type": series_type, 2563 | "datatype": datatype, 2564 | "apikey": API_KEY, 2565 | } 2566 | 2567 | async with httpx.AsyncClient() as client: 2568 | response = await client.get(API_BASE_URL, params=https_params) 2569 | response.raise_for_status() 2570 | return response.text if datatype == "csv" else response.json() 2571 | 2572 | 2573 | async def fetch_aroon( 2574 | symbol: str, 2575 | interval: str = None, 2576 | month: str = None, 2577 | time_period: int = 14, 2578 | datatype: str = "json", 2579 | ) -> dict[str, str] | str: 2580 | """ 2581 | Fetch aroon (AROON) data from the Alpha Vantage API. 2582 | 2583 | :argument: symbol (str): The stock symbol to fetch. 2584 | :argument: interval (str): The time interval for the data. 2585 | :argument: month (str): The month for the data. 2586 | :argument: time_period (int): The time period for the data. 2587 | :argument: datatype (str): The response data type (default: "json"). 2588 | 2589 | :returns: Aroon (AROON) data. 2590 | """ 2591 | 2592 | https_params = { 2593 | "function": "AROON", 2594 | "symbol": symbol, 2595 | "interval": interval, 2596 | "month": month, 2597 | "time_period": time_period, 2598 | "datatype": datatype, 2599 | "apikey": API_KEY, 2600 | } 2601 | 2602 | async with httpx.AsyncClient() as client: 2603 | response = await client.get(API_BASE_URL, params=https_params) 2604 | response.raise_for_status() 2605 | return response.text if datatype == "csv" else response.json() 2606 | 2607 | 2608 | async def fetch_aroonosc( 2609 | symbol: str, 2610 | interval: str = None, 2611 | month: str = None, 2612 | time_period: int = 14, 2613 | datatype: str = "json", 2614 | ) -> dict[str, str] | str: 2615 | """ 2616 | Fetch aroon oscillator (AROONOSC) data from the Alpha Vantage API. 2617 | 2618 | :argument: symbol (str): The stock symbol to fetch. 2619 | :argument: interval (str): The time interval for the data. 2620 | :argument: month (str): The month for the data. 2621 | :argument: time_period (int): The time period for the data. 2622 | :argument: datatype (str): The response data type (default: "json"). 2623 | 2624 | :returns: Aroon oscillator (AROONOSC) data. 2625 | """ 2626 | 2627 | https_params = { 2628 | "function": "AROONOSC", 2629 | "symbol": symbol, 2630 | "interval": interval, 2631 | "month": month, 2632 | "time_period": time_period, 2633 | "datatype": datatype, 2634 | "apikey": API_KEY, 2635 | } 2636 | 2637 | async with httpx.AsyncClient() as client: 2638 | response = await client.get(API_BASE_URL, params=https_params) 2639 | response.raise_for_status() 2640 | return response.text if datatype == "csv" else response.json() 2641 | 2642 | 2643 | async def fetch_mfi( 2644 | symbol: str, 2645 | interval: str = None, 2646 | month: str = None, 2647 | time_period: int = 14, 2648 | datatype: str = "json", 2649 | ) -> dict[str, str] | str: 2650 | """ 2651 | Fetch money flow index (MFI) data from the Alpha Vantage API. 2652 | 2653 | :argument: symbol (str): The stock symbol to fetch. 2654 | :argument: interval (str): The time interval for the data. 2655 | :argument: month (str): The month for the data. 2656 | :argument: time_period (int): The time period for the data. 2657 | :argument: datatype (str): The response data type (default: "json"). 2658 | 2659 | :returns: Money flow index (MFI) data. 2660 | """ 2661 | 2662 | https_params = { 2663 | "function": "MFI", 2664 | "symbol": symbol, 2665 | "interval": interval, 2666 | "month": month, 2667 | "time_period": time_period, 2668 | "datatype": datatype, 2669 | "apikey": API_KEY, 2670 | } 2671 | 2672 | async with httpx.AsyncClient() as client: 2673 | response = await client.get(API_BASE_URL, params=https_params) 2674 | response.raise_for_status() 2675 | return response.text if datatype == "csv" else response.json() 2676 | 2677 | 2678 | async def fetch_trix( 2679 | symbol: str, 2680 | interval: str = None, 2681 | month: str = None, 2682 | time_period: int = 30, 2683 | series_type: str = None, 2684 | datatype: str = "json", 2685 | ) -> dict[str, str] | str: 2686 | """ 2687 | Fetch triple exponential average (TRIX) data from the Alpha Vantage API. 2688 | 2689 | :argument: symbol (str): The stock symbol to fetch. 2690 | :argument: interval (str): The time interval for the data. 2691 | :argument: month (str): The month for the data. 2692 | :argument: time_period (int): The time period for the data. 2693 | :argument: series_type (str): The series type for the data. 2694 | :argument: datatype (str): The response data type (default: "json"). 2695 | 2696 | :returns: Triple exponential average (TRIX) data. 2697 | """ 2698 | 2699 | https_params = { 2700 | "function": "TRIX", 2701 | "symbol": symbol, 2702 | "interval": interval, 2703 | "month": month, 2704 | "time_period": time_period, 2705 | "series_type": series_type, 2706 | "datatype": datatype, 2707 | "apikey": API_KEY, 2708 | } 2709 | 2710 | async with httpx.AsyncClient() as client: 2711 | response = await client.get(API_BASE_URL, params=https_params) 2712 | response.raise_for_status() 2713 | return response.text if datatype == "csv" else response.json() 2714 | 2715 | 2716 | async def fetch_ultosc( 2717 | symbol: str, 2718 | interval: str = None, 2719 | month: str = None, 2720 | timeperiod1: int = 7, 2721 | timeperiod2: int = 14, 2722 | timeperiod3: int = 28, 2723 | datatype: str = "json", 2724 | ) -> dict[str, str] | str: 2725 | """ 2726 | Fetch ultimate oscillator (ULTOSC) data from the Alpha Vantage API. 2727 | 2728 | :argument: symbol (str): The stock symbol to fetch. 2729 | :argument: interval (str): The time interval for the data. 2730 | :argument: month (str): The month for the data. 2731 | :argument: timeperiod1 (int): The time period for the first calculation. 2732 | :argument: timeperiod2 (int): The time period for the second calculation. 2733 | :argument: timeperiod3 (int): The time period for the third calculation. 2734 | :argument: datatype (str): The response data type (default: "json"). 2735 | 2736 | :returns: Ultimate oscillator (ULTOSC) data. 2737 | """ 2738 | 2739 | https_params = { 2740 | "function": "ULTOSC", 2741 | "symbol": symbol, 2742 | "interval": interval, 2743 | "month": month, 2744 | "timeperiod1": timeperiod1, 2745 | "timeperiod2": timeperiod2, 2746 | "timeperiod3": timeperiod3, 2747 | "datatype": datatype, 2748 | "apikey": API_KEY, 2749 | } 2750 | 2751 | async with httpx.AsyncClient() as client: 2752 | response = await client.get(API_BASE_URL, params=https_params) 2753 | response.raise_for_status() 2754 | return response.text if datatype == "csv" else response.json() 2755 | 2756 | 2757 | async def fetch_dx( 2758 | symbol: str, 2759 | interval: str = None, 2760 | month: str = None, 2761 | time_period: int = 14, 2762 | datatype: str = "json", 2763 | ) -> dict[str, str] | str: 2764 | """ 2765 | Fetch directional movement index (DX) data from the Alpha Vantage API. 2766 | 2767 | :argument: symbol (str): The stock symbol to fetch. 2768 | :argument: interval (str): The time interval for the data. 2769 | :argument: month (str): The month for the data. 2770 | :argument: time_period (int): The time period for the data. 2771 | :argument: datatype (str): The response data type (default: "json"). 2772 | 2773 | :returns: Directional movement index (DX) data. 2774 | """ 2775 | 2776 | https_params = { 2777 | "function": "DX", 2778 | "symbol": symbol, 2779 | "interval": interval, 2780 | "month": month, 2781 | "time_period": time_period, 2782 | "datatype": datatype, 2783 | "apikey": API_KEY, 2784 | } 2785 | 2786 | async with httpx.AsyncClient() as client: 2787 | response = await client.get(API_BASE_URL, params=https_params) 2788 | response.raise_for_status() 2789 | return response.text if datatype == "csv" else response.json() 2790 | 2791 | 2792 | async def fetch_minus_di( 2793 | symbol: str, 2794 | interval: str = None, 2795 | month: str = None, 2796 | time_period: int = 14, 2797 | datatype: str = "json", 2798 | ) -> dict[str, str] | str: 2799 | """ 2800 | Fetch minus directional indicator (MINUS_DI) data from the Alpha Vantage API. 2801 | 2802 | :argument: symbol (str): The stock symbol to fetch. 2803 | :argument: interval (str): The time interval for the data. 2804 | :argument: month (str): The month for the data. 2805 | :argument: time_period (int): The time period for the data. 2806 | :argument: datatype (str): The response data type (default: "json"). 2807 | 2808 | :returns: Minus directional indicator (MINUS_DI) data. 2809 | """ 2810 | 2811 | https_params = { 2812 | "function": "MINUS_DI", 2813 | "symbol": symbol, 2814 | "interval": interval, 2815 | "month": month, 2816 | "time_period": time_period, 2817 | "datatype": datatype, 2818 | "apikey": API_KEY, 2819 | } 2820 | 2821 | async with httpx.AsyncClient() as client: 2822 | response = await client.get(API_BASE_URL, params=https_params) 2823 | response.raise_for_status() 2824 | return response.text if datatype == "csv" else response.json() 2825 | 2826 | 2827 | async def fetch_plus_di( 2828 | symbol: str, 2829 | interval: str = None, 2830 | month: str = None, 2831 | time_period: int = 14, 2832 | datatype: str = "json", 2833 | ) -> dict[str, str] | str: 2834 | """ 2835 | Fetch plus directional indicator (PLUS_DI) data from the Alpha Vantage API. 2836 | 2837 | :argument: symbol (str): The stock symbol to fetch. 2838 | :argument: interval (str): The time interval for the data. 2839 | :argument: month (str): The month for the data. 2840 | :argument: time_period (int): The time period for the data. 2841 | :argument: datatype (str): The response data type (default: "json"). 2842 | 2843 | :returns: Plus directional indicator (PLUS_DI) data. 2844 | """ 2845 | 2846 | https_params = { 2847 | "function": "PLUS_DI", 2848 | "symbol": symbol, 2849 | "interval": interval, 2850 | "month": month, 2851 | "time_period": time_period, 2852 | "datatype": datatype, 2853 | "apikey": API_KEY, 2854 | } 2855 | 2856 | async with httpx.AsyncClient() as client: 2857 | response = await client.get(API_BASE_URL, params=https_params) 2858 | response.raise_for_status() 2859 | return response.text if datatype == "csv" else response.json() 2860 | 2861 | 2862 | async def fetch_minus_dm( 2863 | symbol: str, 2864 | interval: str = None, 2865 | month: str = None, 2866 | time_period: int = 14, 2867 | datatype: str = "json", 2868 | ) -> dict[str, str] | str: 2869 | """ 2870 | Fetch minus directional movement (MINUS_DM) data from the Alpha Vantage API. 2871 | 2872 | :argument: symbol (str): The stock symbol to fetch. 2873 | :argument: interval (str): The time interval for the data. 2874 | :argument: month (str): The month for the data. 2875 | :argument: time_period (int): The time period for the data. 2876 | :argument: datatype (str): The response data type (default: "json"). 2877 | 2878 | :returns: Minus directional movement (MINUS_DM) data. 2879 | """ 2880 | 2881 | https_params = { 2882 | "function": "MINUS_DM", 2883 | "symbol": symbol, 2884 | "interval": interval, 2885 | "month": month, 2886 | "time_period": time_period, 2887 | "datatype": datatype, 2888 | "apikey": API_KEY, 2889 | } 2890 | 2891 | async with httpx.AsyncClient() as client: 2892 | response = await client.get(API_BASE_URL, params=https_params) 2893 | response.raise_for_status() 2894 | return response.text if datatype == "csv" else response.json() 2895 | 2896 | 2897 | async def fetch_plus_dm( 2898 | symbol: str, 2899 | interval: str = None, 2900 | month: str = None, 2901 | time_period: int = 14, 2902 | datatype: str = "json", 2903 | ) -> dict[str, str] | str: 2904 | """ 2905 | Fetch plus directional movement (PLUS_DM) data from the Alpha Vantage API. 2906 | 2907 | :argument: symbol (str): The stock symbol to fetch. 2908 | :argument: interval (str): The time interval for the data. 2909 | :argument: month (str): The month for the data. 2910 | :argument: time_period (int): The time period for the data. 2911 | :argument: datatype (str): The response data type (default: "json"). 2912 | 2913 | :returns: Plus directional movement (PLUS_DM) data. 2914 | """ 2915 | 2916 | https_params = { 2917 | "function": "PLUS_DM", 2918 | "symbol": symbol, 2919 | "interval": interval, 2920 | "month": month, 2921 | "time_period": time_period, 2922 | "datatype": datatype, 2923 | "apikey": API_KEY, 2924 | } 2925 | 2926 | async with httpx.AsyncClient() as client: 2927 | response = await client.get(API_BASE_URL, params=https_params) 2928 | response.raise_for_status() 2929 | return response.text if datatype == "csv" else response.json() 2930 | 2931 | 2932 | async def fetch_bbands( 2933 | symbol: str, 2934 | interval: str = None, 2935 | month: str = None, 2936 | time_period: int = 5, 2937 | series_type: str = "close", 2938 | nbdevup: int = 2, 2939 | nbdevdn: int = 2, 2940 | matype: int = 0, 2941 | datatype: str = "json", 2942 | ) -> dict[str, str] | str: 2943 | """ 2944 | Fetch bollinger bands (BBANDS) data from the Alpha Vantage API. 2945 | 2946 | :argument: symbol (str): The stock symbol to fetch. 2947 | :argument: interval (str): The time interval for the data. 2948 | :argument: month (str): The month for the data. 2949 | :argument: time_period (int): The time period for the data. 2950 | :argument: series_type (str): The series type for the data. 2951 | :argument: nbdevup (int): The standard deviation multiplier for the upper band. 2952 | :argument: nbdevdn (int): The standard deviation multiplier for the lower band. 2953 | :argument: matype (int): The moving average type for the data. 2954 | :argument: datatype (str): The response data type (default: "json"). 2955 | 2956 | :returns: Bollinger bands (BBANDS) data. 2957 | """ 2958 | 2959 | https_params = { 2960 | "function": "BBANDS", 2961 | "symbol": symbol, 2962 | "interval": interval, 2963 | "month": month, 2964 | "time_period": time_period, 2965 | "series_type": series_type, 2966 | "nbdevup": nbdevup, 2967 | "nbdevdn": nbdevdn, 2968 | "matype": matype, 2969 | "datatype": datatype, 2970 | "apikey": API_KEY, 2971 | } 2972 | 2973 | async with httpx.AsyncClient() as client: 2974 | response = await client.get(API_BASE_URL, params=https_params) 2975 | response.raise_for_status() 2976 | return response.text if datatype == "csv" else response.json() 2977 | 2978 | 2979 | async def fetch_midpoint( 2980 | symbol: str, 2981 | interval: str = None, 2982 | month: str = None, 2983 | time_period: int = 14, 2984 | series_type: str = "close", 2985 | datatype: str = "json", 2986 | ) -> dict[str, str] | str: 2987 | """ 2988 | Fetch midpoint (MIDPOINT) data from the Alpha Vantage API. 2989 | 2990 | :argument: symbol (str): The stock symbol to fetch. 2991 | :argument: interval (str): The time interval for the data. 2992 | :argument: month (str): The month for the data. 2993 | :argument: time_period (int): The time period for the data. 2994 | :argument: series_type (str): The series type for the data. 2995 | :argument: datatype (str): The response data type (default: "json"). 2996 | 2997 | :returns: Midpoint (MIDPOINT) data. 2998 | """ 2999 | 3000 | https_params = { 3001 | "function": "MIDPOINT", 3002 | "symbol": symbol, 3003 | "interval": interval, 3004 | "month": month, 3005 | "time_period": time_period, 3006 | "series_type": series_type, 3007 | "datatype": datatype, 3008 | "apikey": API_KEY, 3009 | } 3010 | 3011 | async with httpx.AsyncClient() as client: 3012 | response = await client.get(API_BASE_URL, params=https_params) 3013 | response.raise_for_status() 3014 | return response.text if datatype == "csv" else response.json() 3015 | 3016 | 3017 | async def fetch_midprice( 3018 | symbol: str, 3019 | interval: str = None, 3020 | month: str = None, 3021 | time_period: int = 14, 3022 | datatype: str = "json", 3023 | ) -> dict[str, str] | str: 3024 | """ 3025 | Fetch midprice (MIDPRICE) data from the Alpha Vantage API. 3026 | 3027 | :argument: symbol (str): The stock symbol to fetch. 3028 | :argument: interval (str): The time interval for the data. 3029 | :argument: month (str): The month for the data. 3030 | :argument: time_period (int): The time period for the data. 3031 | :argument: datatype (str): The response data type (default: "json"). 3032 | 3033 | :returns: Midprice (MIDPRICE) data. 3034 | """ 3035 | 3036 | https_params = { 3037 | "function": "MIDPRICE", 3038 | "symbol": symbol, 3039 | "interval": interval, 3040 | "month": month, 3041 | "time_period": time_period, 3042 | "datatype": datatype, 3043 | "apikey": API_KEY, 3044 | } 3045 | 3046 | async with httpx.AsyncClient() as client: 3047 | response = await client.get(API_BASE_URL, params=https_params) 3048 | response.raise_for_status() 3049 | return response.text if datatype == "csv" else response.json() 3050 | 3051 | 3052 | async def fetch_sar( 3053 | symbol: str, 3054 | interval: str = None, 3055 | month: str = None, 3056 | acceleration: float = 0.02, 3057 | maximum: float = 0.2, 3058 | datatype: str = "json", 3059 | ) -> dict[str, str] | str: 3060 | """ 3061 | Fetch parabolic SAR (SAR) data from the Alpha Vantage API. 3062 | 3063 | :argument: symbol (str): The stock symbol to fetch. 3064 | :argument: interval (str): The time interval for the data. 3065 | :argument: month (str): The month for the data. 3066 | :argument: acceleration (float): The acceleration factor for the data. 3067 | :argument: maximum (float): The maximum factor for the data. 3068 | :argument: datatype (str): The response data type (default: "json"). 3069 | 3070 | :returns: Parabolic SAR (SAR) data. 3071 | """ 3072 | 3073 | https_params = { 3074 | "function": "SAR", 3075 | "symbol": symbol, 3076 | "interval": interval, 3077 | "month": month, 3078 | "acceleration": acceleration, 3079 | "maximum": maximum, 3080 | "datatype": datatype, 3081 | "apikey": API_KEY, 3082 | } 3083 | 3084 | async with httpx.AsyncClient() as client: 3085 | response = await client.get(API_BASE_URL, params=https_params) 3086 | response.raise_for_status() 3087 | return response.text if datatype == "csv" else response.json() 3088 | 3089 | 3090 | async def fetch_trange( 3091 | symbol: str, 3092 | interval: str = None, 3093 | month: str = None, 3094 | datatype: str = "json", 3095 | ) -> dict[str, str] | str: 3096 | """ 3097 | Fetch true range (TRANGE) data from the Alpha Vantage API. 3098 | 3099 | :argument: symbol (str): The stock symbol to fetch. 3100 | :argument: interval (str): The time interval for the data. 3101 | :argument: month (str): The month for the data. 3102 | :argument: datatype (str): The response data type (default: "json"). 3103 | 3104 | :returns: True range (TRANGE) data. 3105 | """ 3106 | 3107 | https_params = { 3108 | "function": "TRANGE", 3109 | "symbol": symbol, 3110 | "interval": interval, 3111 | "month": month, 3112 | "datatype": datatype, 3113 | "apikey": API_KEY, 3114 | } 3115 | 3116 | async with httpx.AsyncClient() as client: 3117 | response = await client.get(API_BASE_URL, params=https_params) 3118 | response.raise_for_status() 3119 | return response.text if datatype == "csv" else response.json() 3120 | 3121 | 3122 | async def fetch_atr( 3123 | symbol: str, 3124 | interval: str = None, 3125 | month: str = None, 3126 | time_period: int = 14, 3127 | datatype: str = "json", 3128 | ) -> dict[str, str] | str: 3129 | """ 3130 | Fetch average true range (ATR) data from the Alpha Vantage API. 3131 | 3132 | :argument: symbol (str): The stock symbol to fetch. 3133 | :argument: interval (str): The time interval for the data. 3134 | :argument: month (str): The month for the data. 3135 | :argument: time_period (int): The time period for the data. 3136 | :argument: datatype (str): The response data type (default: "json"). 3137 | 3138 | :returns: Average true range (ATR) data. 3139 | """ 3140 | 3141 | https_params = { 3142 | "function": "ATR", 3143 | "symbol": symbol, 3144 | "interval": interval, 3145 | "month": month, 3146 | "time_period": time_period, 3147 | "datatype": datatype, 3148 | "apikey": API_KEY, 3149 | } 3150 | 3151 | async with httpx.AsyncClient() as client: 3152 | response = await client.get(API_BASE_URL, params=https_params) 3153 | response.raise_for_status() 3154 | return response.text if datatype == "csv" else response.json() 3155 | 3156 | 3157 | async def fetch_natr( 3158 | symbol: str, 3159 | interval: str = None, 3160 | month: str = None, 3161 | time_period: int = 14, 3162 | datatype: str = "json", 3163 | ) -> dict[str, str] | str: 3164 | """ 3165 | Fetch normalized average true range (NATR) data from the Alpha Vantage API. 3166 | 3167 | :argument: symbol (str): The stock symbol to fetch. 3168 | :argument: interval (str): The time interval for the data. 3169 | :argument: month (str): The month for the data. 3170 | :argument: time_period (int): The time period for the data. 3171 | :argument: datatype (str): The response data type (default: "json"). 3172 | 3173 | :returns: Normalized average true range (NATR) data. 3174 | """ 3175 | 3176 | https_params = { 3177 | "function": "NATR", 3178 | "symbol": symbol, 3179 | "interval": interval, 3180 | "month": month, 3181 | "time_period": time_period, 3182 | "datatype": datatype, 3183 | "apikey": API_KEY, 3184 | } 3185 | 3186 | async with httpx.AsyncClient() as client: 3187 | response = await client.get(API_BASE_URL, params=https_params) 3188 | response.raise_for_status() 3189 | return response.text if datatype == "csv" else response.json() 3190 | 3191 | 3192 | async def fetch_ad( 3193 | symbol: str, 3194 | interval: str = None, 3195 | month: str = None, 3196 | datatype: str = "json", 3197 | ) -> dict[str, str] | str: 3198 | """ 3199 | Fetch accumulation/distribution (AD) data from the Alpha Vantage API. 3200 | 3201 | :argument: symbol (str): The stock symbol to fetch. 3202 | :argument: interval (str): The time interval for the data. 3203 | :argument: month (str): The month for the data. 3204 | :argument: datatype (str): The response data type (default: "json"). 3205 | 3206 | :returns: Accumulation/distribution (AD) data. 3207 | """ 3208 | 3209 | https_params = { 3210 | "function": "AD", 3211 | "symbol": symbol, 3212 | "interval": interval, 3213 | "month": month, 3214 | "datatype": datatype, 3215 | "apikey": API_KEY, 3216 | } 3217 | 3218 | async with httpx.AsyncClient() as client: 3219 | response = await client.get(API_BASE_URL, params=https_params) 3220 | response.raise_for_status() 3221 | return response.text if datatype == "csv" else response.json() 3222 | 3223 | 3224 | async def fetch_adosc( 3225 | symbol: str, 3226 | interval: str = None, 3227 | month: str = None, 3228 | fastperiod: int = 3, 3229 | slowperiod: int = 10, 3230 | datatype: str = "json", 3231 | ) -> dict[str, str] | str: 3232 | """ 3233 | Fetch accumulation/distribution oscillator (ADOSC) data from the Alpha Vantage API. 3234 | 3235 | :argument: symbol (str): The stock symbol to fetch. 3236 | :argument: interval (str): The time interval for the data. 3237 | :argument: month (str): The month for the data. 3238 | :argument: fastperiod (int): The fast period for the data. 3239 | :argument: slowperiod (int): The slow period for the data. 3240 | :argument: datatype (str): The response data type (default: "json"). 3241 | 3242 | :returns: Accumulation/distribution oscillator (ADOSC) data. 3243 | """ 3244 | 3245 | https_params = { 3246 | "function": "ADOSC", 3247 | "symbol": symbol, 3248 | "interval": interval, 3249 | "month": month, 3250 | "fastperiod": fastperiod, 3251 | "slowperiod": slowperiod, 3252 | "datatype": datatype, 3253 | "apikey": API_KEY, 3254 | } 3255 | 3256 | async with httpx.AsyncClient() as client: 3257 | response = await client.get(API_BASE_URL, params=https_params) 3258 | response.raise_for_status() 3259 | return response.text if datatype == "csv" else response.json() 3260 | 3261 | 3262 | async def fetch_obv( 3263 | symbol: str, 3264 | interval: str = None, 3265 | month: str = None, 3266 | datatype: str = "json", 3267 | ) -> dict[str, str] | str: 3268 | """ 3269 | Fetch on balance volume (OBV) data from the Alpha Vantage API. 3270 | 3271 | :argument: symbol (str): The stock symbol to fetch. 3272 | :argument: interval (str): The time interval for the data. 3273 | :argument: month (str): The month for the data. 3274 | :argument: datatype (str): The response data type (default: "json"). 3275 | 3276 | :returns: On balance volume (OBV) data. 3277 | """ 3278 | 3279 | https_params = { 3280 | "function": "OBV", 3281 | "symbol": symbol, 3282 | "interval": interval, 3283 | "month": month, 3284 | "datatype": datatype, 3285 | "apikey": API_KEY, 3286 | } 3287 | 3288 | async with httpx.AsyncClient() as client: 3289 | response = await client.get(API_BASE_URL, params=https_params) 3290 | response.raise_for_status() 3291 | return response.text if datatype == "csv" else response.json() 3292 | 3293 | 3294 | async def fetch_ht_trendline( 3295 | symbol: str, 3296 | interval: str = None, 3297 | month: str = None, 3298 | series_type: str = "close", 3299 | datatype: str = "json", 3300 | ) -> dict[str, str] | str: 3301 | """ 3302 | Fetch Hilbert transform - instantaneous trendline (HT_TRENDLINE) data from the Alpha Vantage API. 3303 | 3304 | :argument: symbol (str): The stock symbol to fetch. 3305 | :argument: interval (str): The time interval for the data. 3306 | :argument: month (str): The month for the data. 3307 | :argument: series_type (str): The series type for the data. 3308 | :argument: datatype (str): The response data type (default: "json"). 3309 | 3310 | :returns: Hilbert transform - instantaneous trendline (HT_TRENDLINE) data. 3311 | """ 3312 | 3313 | https_params = { 3314 | "function": "HT_TRENDLINE", 3315 | "symbol": symbol, 3316 | "interval": interval, 3317 | "month": month, 3318 | "series_type": series_type, 3319 | "datatype": datatype, 3320 | "apikey": API_KEY, 3321 | } 3322 | 3323 | async with httpx.AsyncClient() as client: 3324 | response = await client.get(API_BASE_URL, params=https_params) 3325 | response.raise_for_status() 3326 | return response.text if datatype == "csv" else response.json() 3327 | 3328 | 3329 | async def fetch_ht_sine( 3330 | symbol: str, 3331 | interval: str = None, 3332 | month: str = None, 3333 | series_type: str = "close", 3334 | datatype: str = "json", 3335 | ) -> dict[str, str] | str: 3336 | """ 3337 | Fetch Hilbert transform - sine wave (HT_SINE) data from the Alpha Vantage API. 3338 | 3339 | :argument: symbol (str): The stock symbol to fetch. 3340 | :argument: interval (str): The time interval for the data. 3341 | :argument: month (str): The month for the data. 3342 | :argument: series_type (str): The series type for the data. 3343 | :argument: datatype (str): The response data type (default: "json"). 3344 | 3345 | :returns: Hilbert transform - sine wave (HT_SINE) data. 3346 | """ 3347 | 3348 | https_params = { 3349 | "function": "HT_SINE", 3350 | "symbol": symbol, 3351 | "interval": interval, 3352 | "month": month, 3353 | "series_type": series_type, 3354 | "datatype": datatype, 3355 | "apikey": API_KEY, 3356 | } 3357 | 3358 | async with httpx.AsyncClient() as client: 3359 | response = await client.get(API_BASE_URL, params=https_params) 3360 | response.raise_for_status() 3361 | return response.text if datatype == "csv" else response.json() 3362 | 3363 | 3364 | async def fetch_ht_trendmode( 3365 | symbol: str, 3366 | interval: str = None, 3367 | month: str = None, 3368 | datatype: str = "json", 3369 | ) -> dict[str, str] | str: 3370 | """ 3371 | Fetch Hilbert transform - trend vs cycle mode (HT_TRENDMODE) data from the Alpha Vantage API. 3372 | 3373 | :argument: symbol (str): The stock symbol to fetch. 3374 | :argument: interval (str): The time interval for the data. 3375 | :argument: month (str): The month for the data. 3376 | :argument: datatype (str): The response data type (default: "json"). 3377 | 3378 | :returns: Hilbert transform - trend vs cycle mode (HT_TRENDMODE) data. 3379 | """ 3380 | 3381 | https_params = { 3382 | "function": "HT_TRENDMODE", 3383 | "symbol": symbol, 3384 | "interval": interval, 3385 | "month": month, 3386 | "datatype": datatype, 3387 | "apikey": API_KEY, 3388 | } 3389 | 3390 | async with httpx.AsyncClient() as client: 3391 | response = await client.get(API_BASE_URL, params=https_params) 3392 | response.raise_for_status() 3393 | return response.text if datatype == "csv" else response.json() 3394 | 3395 | 3396 | async def fetch_ht_dcperiod( 3397 | symbol: str, 3398 | interval: str = None, 3399 | month: str = None, 3400 | series_type: str = None, 3401 | datatype: str = "json", 3402 | ) -> dict[str, str] | str: 3403 | """ 3404 | Fetch Hil bert transform - dominant cycle period (HT_DCPERIOD) data from the Alpha Vantage API. 3405 | 3406 | :argument: symbol (str): The stock symbol to fetch. 3407 | :argument: interval (str): The time interval for the data. 3408 | :argument: month (str): The month for the data. 3409 | :argument: series_type (str): The series type for the data. 3410 | :argument: datatype (str): The response data type (default: "json"). 3411 | 3412 | :returns: Hilbert transform - dominant cycle period (HT_DCPERIOD) data. 3413 | """ 3414 | 3415 | https_params = { 3416 | "function": "HT_DCPERIOD", 3417 | "symbol": symbol, 3418 | "interval": interval, 3419 | "month": month, 3420 | "series_type": series_type, 3421 | "datatype": datatype, 3422 | "apikey": API_KEY, 3423 | } 3424 | 3425 | async with httpx.AsyncClient() as client: 3426 | response = await client.get(API_BASE_URL, params=https_params) 3427 | response.raise_for_status() 3428 | return response.text if datatype == "csv" else response.json() 3429 | 3430 | 3431 | async def fetch_ht_dcphase( 3432 | symbol: str, 3433 | interval: str = None, 3434 | month: str = None, 3435 | series_type: str = None, 3436 | datatype: str = "json", 3437 | ) -> dict[str, str] | str: 3438 | """ 3439 | Fetch Hilbert transform - dominant cycle phase (HT_DCPHASE) data from the Alpha Vantage API. 3440 | 3441 | :argument: symbol (str): The stock symbol to fetch. 3442 | :argument: interval (str): The time interval for the data. 3443 | :argument: month (str): The month for the data. 3444 | :argument: series_type (str): The series type for the data. 3445 | :argument: datatype (str): The response data type (default: "json"). 3446 | 3447 | :returns: Hilbert transform - dominant cycle phase (HT_DCPHASE) data. 3448 | """ 3449 | 3450 | https_params = { 3451 | "function": "HT_DCPHASE", 3452 | "symbol": symbol, 3453 | "interval": interval, 3454 | "month": month, 3455 | "series_type": series_type, 3456 | "datatype": datatype, 3457 | "apikey": API_KEY, 3458 | } 3459 | 3460 | async with httpx.AsyncClient() as client: 3461 | response = await client.get(API_BASE_URL, params=https_params) 3462 | response.raise_for_status() 3463 | return response.text if datatype == "csv" else response.json() 3464 | 3465 | 3466 | async def fetch_ht_phasor( 3467 | symbol: str, 3468 | interval: str = None, 3469 | month: str = None, 3470 | series_type: str = "close", 3471 | datatype: str = "json", 3472 | ) -> dict[str, str] | str: 3473 | """ 3474 | Fetch Hilbert transform - phasor components (HT_PHASOR) data from the Alpha Vantage API. 3475 | 3476 | :argument: symbol (str): The stock symbol to fetch. 3477 | :argument: interval (str): The time interval for the data. 3478 | :argument: month (str): The month for the data. 3479 | :argument: series_type (str): The series type for the data. 3480 | :argument: datatype (str): The response data type (default: "json"). 3481 | 3482 | :returns: Hilbert transform - phasor components (HT_PHASOR) data. 3483 | """ 3484 | 3485 | https_params = { 3486 | "function": "HT_PHASOR", 3487 | "symbol": symbol, 3488 | "interval": interval, 3489 | "month": month, 3490 | "series_type": series_type, 3491 | "datatype": datatype, 3492 | "apikey": API_KEY, 3493 | } 3494 | 3495 | async with httpx.AsyncClient() as client: 3496 | response = await client.get(API_BASE_URL, params=https_params) 3497 | response.raise_for_status() 3498 | return response.text if datatype == "csv" else response.json() 3499 | ```