vfinance 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.
- vfinance-0.1.0/LICENSE.md +21 -0
- vfinance-0.1.0/PKG-INFO +194 -0
- vfinance-0.1.0/README.md +168 -0
- vfinance-0.1.0/docs/development.md +543 -0
- vfinance-0.1.0/docs/roadmap.md +20 -0
- vfinance-0.1.0/docs/todo.md +159 -0
- vfinance-0.1.0/pyproject.toml +81 -0
- vfinance-0.1.0/pyproject.toml.orig +66 -0
- vfinance-0.1.0/src/vfinance/__init__.py +7 -0
- vfinance-0.1.0/src/vfinance/_cache.py +246 -0
- vfinance-0.1.0/src/vfinance/_dnse.py +360 -0
- vfinance-0.1.0/src/vfinance/_utils.py +302 -0
- vfinance-0.1.0/src/vfinance/models.py +110 -0
- vfinance-0.1.0/src/vfinance/py.typed +0 -0
- vfinance-0.1.0/src/vfinance/stocks.py +198 -0
- vfinance-0.1.0/src/vfinance/utils.py +44 -0
- vfinance-0.1.0/tests/test_cache.py +255 -0
- vfinance-0.1.0/tests/test_dnse.py +1010 -0
- vfinance-0.1.0/tests/test_package.py +318 -0
- vfinance-0.1.0/tests/test_stocks.py +651 -0
- vfinance-0.1.0/tests/test_ticker_utils.py +58 -0
- vfinance-0.1.0/tests/test_utils.py +743 -0
- vfinance-0.1.0/uv.lock +756 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thanh Ba Nguyen
|
|
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.
|
vfinance-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vfinance
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fetch Vietnam stock market data from public sources
|
|
5
|
+
Author: Thanh Ba Nguyen
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE.md
|
|
8
|
+
Classifier: Development Status :: 1 - Planning
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
17
|
+
Requires-Dist: beautifulsoup4>=4.15.0,<5
|
|
18
|
+
Requires-Dist: cachetools>=8.0.0,<9
|
|
19
|
+
Requires-Dist: cloudscraper>=1.2.0,<2
|
|
20
|
+
Requires-Dist: playwright>=1.62.0,<2
|
|
21
|
+
Requires-Dist: pydantic>=2.14.0,<3
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Project-URL: Repository, https://github.com/btnguyen2k/vfinance
|
|
24
|
+
Project-URL: Issues, https://github.com/btnguyen2k/vfinance/issues
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
[](https://opensource.org/licenses/MIT)
|
|
28
|
+
[](https://github.com/btnguyen2k/vfinance/actions)
|
|
29
|
+
[](RELEASE-NOTES.md)
|
|
30
|
+
|
|
31
|
+
Fetch Vietnam stock market data from public sources.
|
|
32
|
+
|
|
33
|
+
## Core features
|
|
34
|
+
|
|
35
|
+
| Feature | Business impact |
|
|
36
|
+
|------------------------|-----------------------------------------------------------------------------------------------|
|
|
37
|
+
| **Symbol information** | Research stocks and ETFs with profiles, exchanges, instrument types, indices, and industries. |
|
|
38
|
+
| **Ticker quotes** | Fetch a ticker's quote to support market monitoring and pricing views. |
|
|
39
|
+
| **Ticker history** | Fetch historical market data for trend analysis, investment research, and backtesting. |
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
Stock lookups are asynchronous. Tickers can be written as `BID`, `HOSE:BID`, or
|
|
44
|
+
`BID.VN`; case and surrounding whitespace are ignored.
|
|
45
|
+
|
|
46
|
+
By default, missing data and stock lookup failures return `None`. To receive
|
|
47
|
+
lookup exceptions instead, pass `raise_on_error=True`.
|
|
48
|
+
|
|
49
|
+
### Research a company's profile
|
|
50
|
+
|
|
51
|
+
Use `stocks.get_info` to retrieve the company name, listing exchange, and
|
|
52
|
+
available industry classifications.
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import asyncio
|
|
56
|
+
|
|
57
|
+
from vfinance import stocks
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async def main() -> None:
|
|
61
|
+
info = await stocks.get_info("HOSE:BID")
|
|
62
|
+
if info is None:
|
|
63
|
+
print("Company profile is unavailable.")
|
|
64
|
+
else:
|
|
65
|
+
print(f"{info.symbol} ({info.exchange}): {info.name}")
|
|
66
|
+
if info.industry is not None:
|
|
67
|
+
print(f"Industry: {info.industry}")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
asyncio.run(main())
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### View the latest available quote
|
|
74
|
+
|
|
75
|
+
Use `stocks.get_quote` to view the latest available market price, OHLC prices,
|
|
76
|
+
and traded volume.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import asyncio
|
|
80
|
+
|
|
81
|
+
from vfinance import stocks
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
async def main() -> None:
|
|
85
|
+
quote = await stocks.get_quote("BID")
|
|
86
|
+
if quote is None:
|
|
87
|
+
print("Quote is unavailable.")
|
|
88
|
+
else:
|
|
89
|
+
print(f"Market price: {quote.market_price:,.0f} VND")
|
|
90
|
+
print(f"As of: {quote.timestamp_str}")
|
|
91
|
+
print("OHLC:", quote.open, quote.high, quote.low, quote.close)
|
|
92
|
+
print(f"Volume: {quote.volume:,} traded units")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
asyncio.run(main())
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Prices are in VND per traded unit; volume counts traded units. A closing price can
|
|
99
|
+
be `None` if it has not been finalized.
|
|
100
|
+
|
|
101
|
+
### Analyze daily price history
|
|
102
|
+
|
|
103
|
+
Use `stocks.get_history` to retrieve daily quotes for a calendar-day window.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import asyncio
|
|
107
|
+
|
|
108
|
+
from vfinance import stocks
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
async def main() -> None:
|
|
112
|
+
history = await stocks.get_history("BID.VN", num_days=30)
|
|
113
|
+
if history is None:
|
|
114
|
+
print("History is unavailable.")
|
|
115
|
+
elif not history:
|
|
116
|
+
print("No daily quotes in this period.")
|
|
117
|
+
else:
|
|
118
|
+
for day in history:
|
|
119
|
+
print(day.timestamp.date(), day.close, day.volume)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
asyncio.run(main())
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
History is ordered oldest to newest and covers calendar days, not a fixed number
|
|
126
|
+
of trading sessions. The default window is 30 days, ending before today's
|
|
127
|
+
midnight in Asia/Ho_Chi_Minh; requests are limited to the last five years. A
|
|
128
|
+
successful lookup with no quotes in the selected period returns `[]`.
|
|
129
|
+
|
|
130
|
+
### Keep ticker identifiers consistent across datasets
|
|
131
|
+
|
|
132
|
+
Use `utils.normalize_ticker` to turn supported ticker formats into a consistent
|
|
133
|
+
bare symbol.
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from vfinance.utils import normalize_ticker
|
|
137
|
+
|
|
138
|
+
print(normalize_ticker("BID"))
|
|
139
|
+
print(normalize_ticker("HOSE:BID"))
|
|
140
|
+
print(normalize_ticker("BID.VN"))
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Each call returns `BID`.
|
|
144
|
+
|
|
145
|
+
### Export results as JSON
|
|
146
|
+
|
|
147
|
+
Profiles and quotes can be exported as JSON, including ISO-formatted timestamps
|
|
148
|
+
for quotes. For example, export BID's latest available quote:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
import asyncio
|
|
152
|
+
|
|
153
|
+
from vfinance import stocks
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
async def main() -> None:
|
|
157
|
+
quote = await stocks.get_quote("BID")
|
|
158
|
+
if quote is not None:
|
|
159
|
+
print(quote.model_dump_json(indent=2))
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
asyncio.run(main())
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Data Coverage, Limitations and Disclaimer
|
|
166
|
+
|
|
167
|
+
### Data coverage
|
|
168
|
+
|
|
169
|
+
`vfinance` covers stocks traded on Vietnam's **HOSE**, **HNX**, and **UPCOM**
|
|
170
|
+
markets.
|
|
171
|
+
|
|
172
|
+
### Limitations
|
|
173
|
+
|
|
174
|
+
- Data is fetched from public sources/APIs, and availability depends on those
|
|
175
|
+
providers.
|
|
176
|
+
- Results are cached for a limited period to reduce repeated requests and help
|
|
177
|
+
avoid overloading public sources/APIs.
|
|
178
|
+
- Quotes are not guaranteed to be real-time and may be delayed. Their freshness
|
|
179
|
+
depends on the underlying sources and their update frequency.
|
|
180
|
+
|
|
181
|
+
### Disclaimer
|
|
182
|
+
|
|
183
|
+
Data is provided **"as is"**. `vfinance` and its maintainers make no guarantees
|
|
184
|
+
about its quality, accuracy, completeness, or timeliness, and accept no
|
|
185
|
+
responsibility for the quality or correctness of the data. Verify data
|
|
186
|
+
independently before relying on it.
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
This package is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
|
|
191
|
+
|
|
192
|
+
## Contributing & Support
|
|
193
|
+
|
|
194
|
+
Feel free to create [pull requests](https://github.com/btnguyen2k/vfinance/compare/contrib_wait_to_merge...) or [issues](https://github.com/btnguyen2k/vfinance/issues) to report bugs or suggest new features.
|
vfinance-0.1.0/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
[](https://opensource.org/licenses/MIT)
|
|
2
|
+
[](https://github.com/btnguyen2k/vfinance/actions)
|
|
3
|
+
[](RELEASE-NOTES.md)
|
|
4
|
+
|
|
5
|
+
Fetch Vietnam stock market data from public sources.
|
|
6
|
+
|
|
7
|
+
## Core features
|
|
8
|
+
|
|
9
|
+
| Feature | Business impact |
|
|
10
|
+
|------------------------|-----------------------------------------------------------------------------------------------|
|
|
11
|
+
| **Symbol information** | Research stocks and ETFs with profiles, exchanges, instrument types, indices, and industries. |
|
|
12
|
+
| **Ticker quotes** | Fetch a ticker's quote to support market monitoring and pricing views. |
|
|
13
|
+
| **Ticker history** | Fetch historical market data for trend analysis, investment research, and backtesting. |
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Stock lookups are asynchronous. Tickers can be written as `BID`, `HOSE:BID`, or
|
|
18
|
+
`BID.VN`; case and surrounding whitespace are ignored.
|
|
19
|
+
|
|
20
|
+
By default, missing data and stock lookup failures return `None`. To receive
|
|
21
|
+
lookup exceptions instead, pass `raise_on_error=True`.
|
|
22
|
+
|
|
23
|
+
### Research a company's profile
|
|
24
|
+
|
|
25
|
+
Use `stocks.get_info` to retrieve the company name, listing exchange, and
|
|
26
|
+
available industry classifications.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import asyncio
|
|
30
|
+
|
|
31
|
+
from vfinance import stocks
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
async def main() -> None:
|
|
35
|
+
info = await stocks.get_info("HOSE:BID")
|
|
36
|
+
if info is None:
|
|
37
|
+
print("Company profile is unavailable.")
|
|
38
|
+
else:
|
|
39
|
+
print(f"{info.symbol} ({info.exchange}): {info.name}")
|
|
40
|
+
if info.industry is not None:
|
|
41
|
+
print(f"Industry: {info.industry}")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
asyncio.run(main())
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### View the latest available quote
|
|
48
|
+
|
|
49
|
+
Use `stocks.get_quote` to view the latest available market price, OHLC prices,
|
|
50
|
+
and traded volume.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import asyncio
|
|
54
|
+
|
|
55
|
+
from vfinance import stocks
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def main() -> None:
|
|
59
|
+
quote = await stocks.get_quote("BID")
|
|
60
|
+
if quote is None:
|
|
61
|
+
print("Quote is unavailable.")
|
|
62
|
+
else:
|
|
63
|
+
print(f"Market price: {quote.market_price:,.0f} VND")
|
|
64
|
+
print(f"As of: {quote.timestamp_str}")
|
|
65
|
+
print("OHLC:", quote.open, quote.high, quote.low, quote.close)
|
|
66
|
+
print(f"Volume: {quote.volume:,} traded units")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
asyncio.run(main())
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Prices are in VND per traded unit; volume counts traded units. A closing price can
|
|
73
|
+
be `None` if it has not been finalized.
|
|
74
|
+
|
|
75
|
+
### Analyze daily price history
|
|
76
|
+
|
|
77
|
+
Use `stocks.get_history` to retrieve daily quotes for a calendar-day window.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import asyncio
|
|
81
|
+
|
|
82
|
+
from vfinance import stocks
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
async def main() -> None:
|
|
86
|
+
history = await stocks.get_history("BID.VN", num_days=30)
|
|
87
|
+
if history is None:
|
|
88
|
+
print("History is unavailable.")
|
|
89
|
+
elif not history:
|
|
90
|
+
print("No daily quotes in this period.")
|
|
91
|
+
else:
|
|
92
|
+
for day in history:
|
|
93
|
+
print(day.timestamp.date(), day.close, day.volume)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
asyncio.run(main())
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
History is ordered oldest to newest and covers calendar days, not a fixed number
|
|
100
|
+
of trading sessions. The default window is 30 days, ending before today's
|
|
101
|
+
midnight in Asia/Ho_Chi_Minh; requests are limited to the last five years. A
|
|
102
|
+
successful lookup with no quotes in the selected period returns `[]`.
|
|
103
|
+
|
|
104
|
+
### Keep ticker identifiers consistent across datasets
|
|
105
|
+
|
|
106
|
+
Use `utils.normalize_ticker` to turn supported ticker formats into a consistent
|
|
107
|
+
bare symbol.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from vfinance.utils import normalize_ticker
|
|
111
|
+
|
|
112
|
+
print(normalize_ticker("BID"))
|
|
113
|
+
print(normalize_ticker("HOSE:BID"))
|
|
114
|
+
print(normalize_ticker("BID.VN"))
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Each call returns `BID`.
|
|
118
|
+
|
|
119
|
+
### Export results as JSON
|
|
120
|
+
|
|
121
|
+
Profiles and quotes can be exported as JSON, including ISO-formatted timestamps
|
|
122
|
+
for quotes. For example, export BID's latest available quote:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
import asyncio
|
|
126
|
+
|
|
127
|
+
from vfinance import stocks
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
async def main() -> None:
|
|
131
|
+
quote = await stocks.get_quote("BID")
|
|
132
|
+
if quote is not None:
|
|
133
|
+
print(quote.model_dump_json(indent=2))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
asyncio.run(main())
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Data Coverage, Limitations and Disclaimer
|
|
140
|
+
|
|
141
|
+
### Data coverage
|
|
142
|
+
|
|
143
|
+
`vfinance` covers stocks traded on Vietnam's **HOSE**, **HNX**, and **UPCOM**
|
|
144
|
+
markets.
|
|
145
|
+
|
|
146
|
+
### Limitations
|
|
147
|
+
|
|
148
|
+
- Data is fetched from public sources/APIs, and availability depends on those
|
|
149
|
+
providers.
|
|
150
|
+
- Results are cached for a limited period to reduce repeated requests and help
|
|
151
|
+
avoid overloading public sources/APIs.
|
|
152
|
+
- Quotes are not guaranteed to be real-time and may be delayed. Their freshness
|
|
153
|
+
depends on the underlying sources and their update frequency.
|
|
154
|
+
|
|
155
|
+
### Disclaimer
|
|
156
|
+
|
|
157
|
+
Data is provided **"as is"**. `vfinance` and its maintainers make no guarantees
|
|
158
|
+
about its quality, accuracy, completeness, or timeliness, and accept no
|
|
159
|
+
responsibility for the quality or correctness of the data. Verify data
|
|
160
|
+
independently before relying on it.
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
This package is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
|
|
165
|
+
|
|
166
|
+
## Contributing & Support
|
|
167
|
+
|
|
168
|
+
Feel free to create [pull requests](https://github.com/btnguyen2k/vfinance/compare/contrib_wait_to_merge...) or [issues](https://github.com/btnguyen2k/vfinance/issues) to report bugs or suggest new features.
|