py-yfinance 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py_yfinance-0.1.0/.github/workflows/ci.yml +34 -0
- py_yfinance-0.1.0/.github/workflows/publish.yml +31 -0
- py_yfinance-0.1.0/.gitignore +10 -0
- py_yfinance-0.1.0/LICENSE +21 -0
- py_yfinance-0.1.0/MANIFEST.in +2 -0
- py_yfinance-0.1.0/PKG-INFO +120 -0
- py_yfinance-0.1.0/README.md +93 -0
- py_yfinance-0.1.0/examples/demo_resolve.py +34 -0
- py_yfinance-0.1.0/examples/portseido_parser.py +67 -0
- py_yfinance-0.1.0/py_yfinance/__init__.py +3 -0
- py_yfinance-0.1.0/py_yfinance/cli.py +71 -0
- py_yfinance-0.1.0/py_yfinance/py.typed +0 -0
- py_yfinance-0.1.0/py_yfinance/source.py +303 -0
- py_yfinance-0.1.0/pyproject.toml +58 -0
- py_yfinance-0.1.0/tests/smoke_test.py +9 -0
- py_yfinance-0.1.0/tests/test_integration.py +41 -0
- py_yfinance-0.1.0/tests/test_resolve.py +94 -0
- py_yfinance-0.1.0/uv.lock +1153 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: Test Python ${{ matrix.python-version }}
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v5
|
|
23
|
+
|
|
24
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
25
|
+
run: uv python install ${{ matrix.python-version }}
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: uv sync --all-extras --dev
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: uv run pytest
|
|
32
|
+
|
|
33
|
+
- name: Lint with Ruff
|
|
34
|
+
run: uv run ruff check .
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
name: Publish to PyPI
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment:
|
|
13
|
+
name: pypi
|
|
14
|
+
url: https://pypi.org/p/py-yfinance
|
|
15
|
+
permissions:
|
|
16
|
+
id-token: write
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v5
|
|
23
|
+
|
|
24
|
+
- name: Set up Python
|
|
25
|
+
run: uv python install 3.13
|
|
26
|
+
|
|
27
|
+
- name: Build package
|
|
28
|
+
run: uv build
|
|
29
|
+
|
|
30
|
+
- name: Publish to PyPI
|
|
31
|
+
run: uv publish
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Roman Medvedev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-yfinance
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A structured Python interface for retrieving and validating market data using yfinance
|
|
5
|
+
Project-URL: Homepage, https://github.com/romamo/py-yfinance
|
|
6
|
+
Project-URL: Repository, https://github.com/romamo/py-yfinance
|
|
7
|
+
Project-URL: Issues, https://github.com/romamo/py-yfinance/issues
|
|
8
|
+
Author-email: Roman Medvedev <pypi@romavm.dev>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: pycountry>=24.6.1
|
|
22
|
+
Requires-Dist: pydantic-market-data>=0.1.0
|
|
23
|
+
Requires-Dist: yfinance>=1.0
|
|
24
|
+
Provides-Extra: cli
|
|
25
|
+
Requires-Dist: typer; extra == 'cli'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# py-yfinance
|
|
29
|
+
|
|
30
|
+
A structured Python interface for retrieving and validating market data using `yfinance`.
|
|
31
|
+
Implements the `DataSource` protocol from `pydantic-market-data` to provide type-safe security resolution and historical data fetching.
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- **Protocol-Oriented**: Implements `DataSource` interface.
|
|
36
|
+
- **Security Resolution**: Resolve ISINs and Symbols to valid `yfinance` tickers.
|
|
37
|
+
- **Validation**:
|
|
38
|
+
- **Exchanges**: Map exchanges (e.g., `IBIS`, `AEB`) to Yahoo suffixes (`.DE`, `.AS`).
|
|
39
|
+
- **Price Validation**: Verify tickers against a known target price with **strict 1% tolerance**.
|
|
40
|
+
- **Date Validation**: Validate prices on specific historical dates.
|
|
41
|
+
- **Typer CLI**: Optional command-line interface for lookup and history.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Basic installation
|
|
47
|
+
uv pip install py-yfinance
|
|
48
|
+
|
|
49
|
+
# With CLI support
|
|
50
|
+
uv pip install "py-yfinance[cli]"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
### As a Library
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from py_yfinance.source import YFinanceDataSource
|
|
59
|
+
from pydantic_market_data.models import SecurityCriteria
|
|
60
|
+
|
|
61
|
+
source = YFinanceDataSource()
|
|
62
|
+
|
|
63
|
+
# 1. Simple Lookup by Symbol
|
|
64
|
+
criteria = SecurityCriteria(symbol="AAPL", preferred_exchanges=["NASDAQ"])
|
|
65
|
+
result = source.resolve(criteria)
|
|
66
|
+
print(result)
|
|
67
|
+
# Symbol(ticker='AAPL', name='Apple Inc.', exchange='NMS', currency='USD', ...)
|
|
68
|
+
|
|
69
|
+
# 2. Strict Validation using Date & Price
|
|
70
|
+
# Useful for verifying ISIN mappings or ensuring data quality
|
|
71
|
+
criteria = SecurityCriteria(
|
|
72
|
+
isin="NL0010273215",
|
|
73
|
+
target_date="2025-12-15",
|
|
74
|
+
target_price=923.4 # Validates against history with 1% tolerance
|
|
75
|
+
)
|
|
76
|
+
match = source.resolve(criteria)
|
|
77
|
+
if match:
|
|
78
|
+
print(f"Verified: {match.ticker}")
|
|
79
|
+
else:
|
|
80
|
+
print("Validation failed: Price mismatch or symbol not found")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### CLI Usage
|
|
84
|
+
|
|
85
|
+
Requires `[cli]` extra.
|
|
86
|
+
|
|
87
|
+
#### Lookup
|
|
88
|
+
Resolve a security by Symbol or ISIN.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Basic Lookup
|
|
92
|
+
uv run py-yfinance lookup --symbol AAPL
|
|
93
|
+
|
|
94
|
+
# ISIN Lookup with Strict Validation
|
|
95
|
+
# Verifies that NL0010273215 commanded a price of ~923.4 on 2025-12-15
|
|
96
|
+
uv run py-yfinance lookup --isin NL0010273215 --date 2025-12-15 --price 923.4
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### History
|
|
100
|
+
Fetch historical candles.
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
uv run py-yfinance history AAPL --period 5d
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
This project uses `uv` for dependency management.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Sync dependencies
|
|
112
|
+
uv sync --extra cli
|
|
113
|
+
|
|
114
|
+
# Run Tests
|
|
115
|
+
uv run pytest
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# py-yfinance
|
|
2
|
+
|
|
3
|
+
A structured Python interface for retrieving and validating market data using `yfinance`.
|
|
4
|
+
Implements the `DataSource` protocol from `pydantic-market-data` to provide type-safe security resolution and historical data fetching.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- **Protocol-Oriented**: Implements `DataSource` interface.
|
|
9
|
+
- **Security Resolution**: Resolve ISINs and Symbols to valid `yfinance` tickers.
|
|
10
|
+
- **Validation**:
|
|
11
|
+
- **Exchanges**: Map exchanges (e.g., `IBIS`, `AEB`) to Yahoo suffixes (`.DE`, `.AS`).
|
|
12
|
+
- **Price Validation**: Verify tickers against a known target price with **strict 1% tolerance**.
|
|
13
|
+
- **Date Validation**: Validate prices on specific historical dates.
|
|
14
|
+
- **Typer CLI**: Optional command-line interface for lookup and history.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# Basic installation
|
|
20
|
+
uv pip install py-yfinance
|
|
21
|
+
|
|
22
|
+
# With CLI support
|
|
23
|
+
uv pip install "py-yfinance[cli]"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### As a Library
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from py_yfinance.source import YFinanceDataSource
|
|
32
|
+
from pydantic_market_data.models import SecurityCriteria
|
|
33
|
+
|
|
34
|
+
source = YFinanceDataSource()
|
|
35
|
+
|
|
36
|
+
# 1. Simple Lookup by Symbol
|
|
37
|
+
criteria = SecurityCriteria(symbol="AAPL", preferred_exchanges=["NASDAQ"])
|
|
38
|
+
result = source.resolve(criteria)
|
|
39
|
+
print(result)
|
|
40
|
+
# Symbol(ticker='AAPL', name='Apple Inc.', exchange='NMS', currency='USD', ...)
|
|
41
|
+
|
|
42
|
+
# 2. Strict Validation using Date & Price
|
|
43
|
+
# Useful for verifying ISIN mappings or ensuring data quality
|
|
44
|
+
criteria = SecurityCriteria(
|
|
45
|
+
isin="NL0010273215",
|
|
46
|
+
target_date="2025-12-15",
|
|
47
|
+
target_price=923.4 # Validates against history with 1% tolerance
|
|
48
|
+
)
|
|
49
|
+
match = source.resolve(criteria)
|
|
50
|
+
if match:
|
|
51
|
+
print(f"Verified: {match.ticker}")
|
|
52
|
+
else:
|
|
53
|
+
print("Validation failed: Price mismatch or symbol not found")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### CLI Usage
|
|
57
|
+
|
|
58
|
+
Requires `[cli]` extra.
|
|
59
|
+
|
|
60
|
+
#### Lookup
|
|
61
|
+
Resolve a security by Symbol or ISIN.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Basic Lookup
|
|
65
|
+
uv run py-yfinance lookup --symbol AAPL
|
|
66
|
+
|
|
67
|
+
# ISIN Lookup with Strict Validation
|
|
68
|
+
# Verifies that NL0010273215 commanded a price of ~923.4 on 2025-12-15
|
|
69
|
+
uv run py-yfinance lookup --isin NL0010273215 --date 2025-12-15 --price 923.4
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### History
|
|
73
|
+
Fetch historical candles.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
uv run py-yfinance history AAPL --period 5d
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
This project uses `uv` for dependency management.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Sync dependencies
|
|
85
|
+
uv sync --extra cli
|
|
86
|
+
|
|
87
|
+
# Run Tests
|
|
88
|
+
uv run pytest
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from pydantic_market_data.models import SecurityCriteria
|
|
2
|
+
|
|
3
|
+
from py_yfinance.source import YFinanceDataSource
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
source = YFinanceDataSource()
|
|
8
|
+
|
|
9
|
+
scenarios = [
|
|
10
|
+
{"symbol": "AAPL", "desc": "Simple US Stock"},
|
|
11
|
+
{"symbol": "4GLD", "exchanges": ["IBIS"], "desc": "German ETF (needs .DE suffix)"},
|
|
12
|
+
{"symbol": "ASML", "exchanges": ["AEB"], "desc": "Dutch Stock"},
|
|
13
|
+
{"symbol": "INVALID123", "desc": "Non-existent ticker"},
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
print(f"{'Description':<30} | {'Input':<15} | {'Resolved Ticker':<15} | {'Name'}")
|
|
17
|
+
print("-" * 90)
|
|
18
|
+
|
|
19
|
+
for s in scenarios:
|
|
20
|
+
criteria = SecurityCriteria(symbol=s["symbol"], preferred_exchanges=s.get("exchanges"))
|
|
21
|
+
result = source.resolve(criteria)
|
|
22
|
+
|
|
23
|
+
input_str = s["symbol"]
|
|
24
|
+
if s.get("exchanges"):
|
|
25
|
+
input_str += f" ({s['exchanges'][0]})"
|
|
26
|
+
|
|
27
|
+
ticker = result.ticker if result else "N/A"
|
|
28
|
+
name = result.name if result else "-"
|
|
29
|
+
|
|
30
|
+
print(f"{s['desc']:<30} | {input_str:<15} | {ticker:<15} | {name}")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
main()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import xml.etree.ElementTree as ET
|
|
3
|
+
|
|
4
|
+
from pydantic_market_data.models import SecurityCriteria
|
|
5
|
+
|
|
6
|
+
from py_yfinance.source import YFinanceDataSource
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_portseido_xml(xml_path):
|
|
10
|
+
print(f"Parsing {xml_path}...")
|
|
11
|
+
try:
|
|
12
|
+
tree = ET.parse(xml_path)
|
|
13
|
+
root = tree.getroot()
|
|
14
|
+
except Exception as e:
|
|
15
|
+
print(f"Failed to parse XML: {e}")
|
|
16
|
+
return
|
|
17
|
+
|
|
18
|
+
source = YFinanceDataSource()
|
|
19
|
+
|
|
20
|
+
trades = root.findall(".//Trade")
|
|
21
|
+
print(f"Found {len(trades)} trades.")
|
|
22
|
+
|
|
23
|
+
unique_resolutions = {}
|
|
24
|
+
|
|
25
|
+
for trade in trades:
|
|
26
|
+
symbol = trade.get("symbol")
|
|
27
|
+
isin = trade.get("isin")
|
|
28
|
+
exchange = trade.get("exchange")
|
|
29
|
+
description = trade.get("description")
|
|
30
|
+
listing_exchange = trade.get("listingExchange")
|
|
31
|
+
|
|
32
|
+
# Create a key for unique check
|
|
33
|
+
key = (symbol, isin, exchange)
|
|
34
|
+
if key in unique_resolutions:
|
|
35
|
+
continue
|
|
36
|
+
|
|
37
|
+
print(
|
|
38
|
+
f"Resolving: Symbol={symbol}, ISIN={isin}, "
|
|
39
|
+
f"Exch={exchange}, ListingExch={listing_exchange}"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# Prepare preferred exchanges
|
|
43
|
+
preferred = []
|
|
44
|
+
if exchange:
|
|
45
|
+
preferred.append(exchange)
|
|
46
|
+
if listing_exchange and listing_exchange != exchange:
|
|
47
|
+
preferred.append(listing_exchange)
|
|
48
|
+
|
|
49
|
+
criteria = SecurityCriteria(
|
|
50
|
+
isin=isin, symbol=symbol, description=description, preferred_exchanges=preferred
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
resolved = source.resolve(criteria)
|
|
54
|
+
unique_resolutions[key] = resolved
|
|
55
|
+
|
|
56
|
+
if resolved:
|
|
57
|
+
print(f" -> FOUND: {resolved.ticker} ({resolved.name})")
|
|
58
|
+
else:
|
|
59
|
+
print(" -> NOT FOUND")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if __name__ == "__main__":
|
|
63
|
+
if len(sys.argv) < 2:
|
|
64
|
+
print("Usage: python test_portseido.py <path_to_xml>")
|
|
65
|
+
sys.exit(1)
|
|
66
|
+
|
|
67
|
+
test_portseido_xml(sys.argv[1])
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
import typer
|
|
5
|
+
except ImportError:
|
|
6
|
+
print("Typer not installed. Please install with 'cli' extra: uv sync --extra cli")
|
|
7
|
+
sys.exit(1)
|
|
8
|
+
|
|
9
|
+
from typing import List, Optional
|
|
10
|
+
|
|
11
|
+
from pydantic_market_data.models import SecurityCriteria
|
|
12
|
+
|
|
13
|
+
from py_yfinance.source import YFinanceDataSource
|
|
14
|
+
|
|
15
|
+
app = typer.Typer(help="py-yfinance CLI")
|
|
16
|
+
source = YFinanceDataSource()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@app.command()
|
|
20
|
+
def lookup(
|
|
21
|
+
symbol: Optional[str] = typer.Option(None, help="Symbol to search for"),
|
|
22
|
+
isin: Optional[str] = typer.Option(None, help="ISIN to search for"),
|
|
23
|
+
exchange: Optional[List[str]] = typer.Option(None, help="Preferred exchanges"),
|
|
24
|
+
price: Optional[float] = typer.Option(None, help="Target price for validation"),
|
|
25
|
+
date: Optional[str] = typer.Option(
|
|
26
|
+
None, help="Target date for validation (YYYY-MM-DD or similar)"
|
|
27
|
+
),
|
|
28
|
+
):
|
|
29
|
+
"""
|
|
30
|
+
Lookup a security by Symbol or ISIN.
|
|
31
|
+
"""
|
|
32
|
+
criteria = SecurityCriteria(
|
|
33
|
+
isin=isin, symbol=symbol, preferred_exchanges=exchange, target_price=price, target_date=date
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
result = source.resolve(criteria)
|
|
37
|
+
|
|
38
|
+
if result:
|
|
39
|
+
print(f"Ticker: {result.ticker}")
|
|
40
|
+
print(f"Name: {result.name}")
|
|
41
|
+
print(f"Exchange: {result.exchange}")
|
|
42
|
+
print(f"Currency: {result.currency}")
|
|
43
|
+
else:
|
|
44
|
+
print("Not found.")
|
|
45
|
+
raise typer.Exit(code=1)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@app.command()
|
|
49
|
+
def history(
|
|
50
|
+
ticker: str = typer.Argument(..., help="Ticker symbol"),
|
|
51
|
+
period: str = typer.Option("1mo", help="Period (e.g. 1d, 5d, 1mo, 1y)"),
|
|
52
|
+
):
|
|
53
|
+
"""
|
|
54
|
+
Get historical data for a ticker.
|
|
55
|
+
"""
|
|
56
|
+
try:
|
|
57
|
+
hist = source.history(ticker, period=period)
|
|
58
|
+
print(f"Symbol: {hist.symbol.ticker}")
|
|
59
|
+
print(f"Candles: {len(hist.candles)}")
|
|
60
|
+
|
|
61
|
+
if hist.candles:
|
|
62
|
+
last = hist.candles[-1]
|
|
63
|
+
print(f"Last Candle ({last.date}): Close=${last.close}")
|
|
64
|
+
|
|
65
|
+
except Exception as e:
|
|
66
|
+
print(f"Error: {e}")
|
|
67
|
+
raise typer.Exit(code=1)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__":
|
|
71
|
+
app()
|
|
File without changes
|