quant-agent 0.3.0__tar.gz → 0.3.1__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.
Files changed (29) hide show
  1. {quant_agent-0.3.0 → quant_agent-0.3.1}/PKG-INFO +25 -9
  2. {quant_agent-0.3.0 → quant_agent-0.3.1}/README.md +20 -7
  3. {quant_agent-0.3.0 → quant_agent-0.3.1}/pyproject.toml +7 -2
  4. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/__init__.py +2 -1
  5. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/fundamental.py +5 -5
  6. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/technical.py +36 -9
  7. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/trading.py +4 -1
  8. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent.egg-info/PKG-INFO +25 -9
  9. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/broker/__init__.py +0 -0
  10. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/broker/dnse.py +0 -0
  11. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/chart.py +0 -0
  12. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/config.py +0 -0
  13. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/economics.py +0 -0
  14. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/funds.py +0 -0
  15. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/integration.py +0 -0
  16. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/sources/__init__.py +0 -0
  17. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/sources/dnse.py +0 -0
  18. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/sources/fmarket.py +0 -0
  19. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/sources/http_client.py +0 -0
  20. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/sources/ssi.py +0 -0
  21. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/sources/vci.py +0 -0
  22. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/sources/vps.py +0 -0
  23. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent/utils.py +0 -0
  24. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent.egg-info/SOURCES.txt +0 -0
  25. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent.egg-info/dependency_links.txt +0 -0
  26. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent.egg-info/requires.txt +0 -0
  27. {quant_agent-0.3.0 → quant_agent-0.3.1}/quant_agent.egg-info/top_level.txt +0 -0
  28. {quant_agent-0.3.0 → quant_agent-0.3.1}/setup.cfg +0 -0
  29. {quant_agent-0.3.0 → quant_agent-0.3.1}/tests/test_smoke.py +0 -0
@@ -1,9 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quant-agent
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Vietnam Quantitative Trading and Market Data Agent
5
- Author: quant-agent
5
+ Author-email: Tom Tran <thangtran.com@gmail.com>
6
6
  License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/tomtranai/quant-agent
8
+ Project-URL: Repository, https://github.com/tomtranai/quant-agent
9
+ Project-URL: Bug Tracker, https://github.com/tomtranai/quant-agent/issues
7
10
  Keywords: vietnam,stock,quant,trading,agent,finance,algorithmic-trading
8
11
  Classifier: Programming Language :: Python :: 3
9
12
  Classifier: Operating System :: OS Independent
@@ -18,6 +21,7 @@ Requires-Dist: python-dateutil>=2.8.0
18
21
 
19
22
  # quant-agent: Thư viện Phân tích Dữ liệu Chứng khoán & Giao dịch Việt Nam
20
23
 
24
+ [![PyPI version](https://img.shields.io/pypi/v/quant-agent.svg)](https://pypi.org/project/quant-agent/)
21
25
  [![Python](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org/)
22
26
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
23
27
  [![Market Data: Free](https://img.shields.io/badge/Market%20Data-Free%20%2F%20No%20Key-brightgreen.svg)]()
@@ -86,18 +90,27 @@ Hệ thống đã được tái cấu trúc và phân lập tầng nguồn dữ
86
90
  - Python >= 3.10
87
91
  - Kết nối Internet ổn định
88
92
 
89
- ### Cài đặt thư viện
90
- Clone repository và cài đặt ở chế độ editable hoặc build trực tiếp:
93
+ ### 1. Cài đặt trực tiếp từ PyPI (Khuyến nghị)
94
+ Bạn có thể cài đặt trực tiếp bản phát hành chính thức thông qua `pip`:
95
+
96
+ ```bash
97
+ pip install quant-agent
98
+ ```
99
+
100
+ Để nâng cấp lên phiên bản mới nhất bất kỳ lúc nào:
101
+ ```bash
102
+ pip install -U quant-agent
103
+ ```
104
+
105
+ ### 2. Cài đặt từ mã nguồn (Dành cho nhà phát triển / Đóng góp mã nguồn)
106
+ Clone repository và cài đặt ở chế độ editable:
91
107
 
92
108
  ```bash
93
109
  # Clone repository
94
- git clone https://github.com/quant-agent/quant-agent.git
110
+ git clone https://github.com/tomtranai/quant-agent.git
95
111
  cd quant-agent
96
112
 
97
- # Cài đặt các gói phụ thuộc
98
- pip install -r requirements.txt
99
-
100
- # Hoặc cài đặt trực tiếp dạng package
113
+ # Cài đặt các gói phụ thuộc & editable mode
101
114
  pip install -e .
102
115
  ```
103
116
 
@@ -184,6 +197,9 @@ graph TD
184
197
 
185
198
  ```python
186
199
  import quant_agent as qa
200
+
201
+ # Kiểm tra phiên bản
202
+ print(qa.__version__) # 0.3.1
187
203
  ```
188
204
 
189
205
  ### 1. Danh sách mã niêm yết
@@ -1,5 +1,6 @@
1
1
  # quant-agent: Thư viện Phân tích Dữ liệu Chứng khoán & Giao dịch Việt Nam
2
2
 
3
+ [![PyPI version](https://img.shields.io/pypi/v/quant-agent.svg)](https://pypi.org/project/quant-agent/)
3
4
  [![Python](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org/)
4
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
5
6
  [![Market Data: Free](https://img.shields.io/badge/Market%20Data-Free%20%2F%20No%20Key-brightgreen.svg)]()
@@ -68,18 +69,27 @@ Hệ thống đã được tái cấu trúc và phân lập tầng nguồn dữ
68
69
  - Python >= 3.10
69
70
  - Kết nối Internet ổn định
70
71
 
71
- ### Cài đặt thư viện
72
- Clone repository và cài đặt ở chế độ editable hoặc build trực tiếp:
72
+ ### 1. Cài đặt trực tiếp từ PyPI (Khuyến nghị)
73
+ Bạn có thể cài đặt trực tiếp bản phát hành chính thức thông qua `pip`:
74
+
75
+ ```bash
76
+ pip install quant-agent
77
+ ```
78
+
79
+ Để nâng cấp lên phiên bản mới nhất bất kỳ lúc nào:
80
+ ```bash
81
+ pip install -U quant-agent
82
+ ```
83
+
84
+ ### 2. Cài đặt từ mã nguồn (Dành cho nhà phát triển / Đóng góp mã nguồn)
85
+ Clone repository và cài đặt ở chế độ editable:
73
86
 
74
87
  ```bash
75
88
  # Clone repository
76
- git clone https://github.com/quant-agent/quant-agent.git
89
+ git clone https://github.com/tomtranai/quant-agent.git
77
90
  cd quant-agent
78
91
 
79
- # Cài đặt các gói phụ thuộc
80
- pip install -r requirements.txt
81
-
82
- # Hoặc cài đặt trực tiếp dạng package
92
+ # Cài đặt các gói phụ thuộc & editable mode
83
93
  pip install -e .
84
94
  ```
85
95
 
@@ -166,6 +176,9 @@ graph TD
166
176
 
167
177
  ```python
168
178
  import quant_agent as qa
179
+
180
+ # Kiểm tra phiên bản
181
+ print(qa.__version__) # 0.3.1
169
182
  ```
170
183
 
171
184
  ### 1. Danh sách mã niêm yết
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "quant-agent"
7
- version = "0.3.0"
7
+ version = "0.3.1"
8
8
  description = "Vietnam Quantitative Trading and Market Data Agent"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  license = "MIT"
12
12
  authors = [
13
- { name = "quant-agent" }
13
+ { name = "Tom Tran", email = "thangtran.com@gmail.com" }
14
14
  ]
15
15
  keywords = ["vietnam", "stock", "quant", "trading", "agent", "finance", "algorithmic-trading"]
16
16
  classifiers = [
@@ -26,6 +26,11 @@ dependencies = [
26
26
  "python-dateutil>=2.8.0",
27
27
  ]
28
28
 
29
+ [project.urls]
30
+ Homepage = "https://github.com/tomtranai/quant-agent"
31
+ Repository = "https://github.com/tomtranai/quant-agent"
32
+ "Bug Tracker" = "https://github.com/tomtranai/quant-agent/issues"
33
+
29
34
  [tool.setuptools.packages.find]
30
35
  where = ["."]
31
36
  include = ["quant_agent*"]
@@ -12,7 +12,8 @@ this read-only library. It's re-exported here too for backward
12
12
  compatibility, but see `broker/__init__.py` before using it.
13
13
  """
14
14
 
15
- __author__ = "quant-agent"
15
+ __version__ = "0.3.1"
16
+ __author__ = "Tom Tran"
16
17
 
17
18
  from .config import * # date helpers + re-exports the `sources` subpackage
18
19
  from .utils import *
@@ -263,7 +263,7 @@ def company_insider_deals (symbol='TCB', page_size=20, page=0, headers=None):
263
263
  payload = fetch_json('GET', url, headers=vci_headers, source='VCI')
264
264
  if payload is None:
265
265
  return None
266
- content = payload.get('data', {}).get('content', [])
266
+ content = (payload.get('data') or {}).get('content', [])
267
267
  if not content:
268
268
  print(f'No insider dealing data returned by VCI for {symbol}.')
269
269
  return None
@@ -339,7 +339,7 @@ def company_events (symbol='TPB', page_size=15, page=0, headers=None):
339
339
  payload = fetch_json('GET', url, headers=vci_headers, source='VCI')
340
340
  if payload is None:
341
341
  return None
342
- content = payload.get('data', {}).get('content', [])
342
+ content = (payload.get('data') or {}).get('content', [])
343
343
  if not content:
344
344
  print(f'No events returned by VCI for {symbol}.')
345
345
  return None
@@ -362,7 +362,7 @@ def company_news (symbol='TCB', page_size=15, page=0, headers=None):
362
362
  payload = fetch_json('GET', url, headers=vci_headers, source='VCI')
363
363
  if payload is None:
364
364
  return None
365
- content = payload.get('data', {}).get('content', [])
365
+ content = (payload.get('data') or {}).get('content', [])
366
366
  if not content:
367
367
  print(f'No news returned by VCI for {symbol}.')
368
368
  return None
@@ -392,7 +392,7 @@ def _vci_financial_statement(symbol, report_type, frequency):
392
392
  payload = fetch_json('GET', url, headers=headers, params={'section': section}, source='VCI')
393
393
  if payload is None:
394
394
  return None
395
- data = payload.get('data', {})
395
+ data = payload.get('data') or {}
396
396
  key = 'years' if frequency.lower().startswith('year') else 'quarters'
397
397
  records = data.get(key, [])
398
398
  if not records:
@@ -539,7 +539,7 @@ def dividend_history (symbol):
539
539
  payload = fetch_json('GET', url, headers=vci_headers, source='VCI')
540
540
  if payload is None:
541
541
  return None
542
- content = payload.get('data', {}).get('content', [])
542
+ content = (payload.get('data') or {}).get('content', [])
543
543
  if not content:
544
544
  print(f'No dividend history returned by VCI for {symbol}.')
545
545
  return None
@@ -27,10 +27,7 @@ def stock_historical_data (symbol='TCB', start_date='2023-06-01', end_date='2023
27
27
  if source.upper() == 'DNSE':
28
28
  df = ohlc_data(symbol, start_date, end_date, resolution, type, headers=entrade_headers)
29
29
  elif source.upper() == 'VCI':
30
- if resolution != '1D':
31
- print("VCI only supports longterm daily data. Please set resolution to '1D'")
32
- return None
33
- df = longterm_ohlc_data(symbol, start_date, end_date, 'D', type)
30
+ df = longterm_ohlc_data(symbol, start_date, end_date, resolution, type)
34
31
  else:
35
32
  print(f"Unknown source '{source}'. Use 'DNSE' or 'VCI'.")
36
33
  return None
@@ -46,7 +43,13 @@ def stock_historical_data (symbol='TCB', start_date='2023-06-01', end_date='2023
46
43
  return df
47
44
 
48
45
 
49
- _VCI_TIMEFRAME_MAP = {'D': 'ONE_DAY', '1D': 'ONE_DAY', 'H': 'ONE_HOUR', '1H': 'ONE_HOUR', '1': 'ONE_MINUTE'}
46
+ _VCI_TIMEFRAME_MAP = {
47
+ 'D': 'ONE_DAY', '1D': 'ONE_DAY',
48
+ 'H': 'ONE_HOUR', '1H': 'ONE_HOUR',
49
+ '1': 'ONE_MINUTE', '1M': 'ONE_MINUTE', '1m': 'ONE_MINUTE',
50
+ '15': 'FIFTEEN_MINUTES', '15m': 'FIFTEEN_MINUTES',
51
+ '30': 'THIRTY_MINUTES', '30m': 'THIRTY_MINUTES',
52
+ }
50
53
 
51
54
  def longterm_ohlc_data (symbol='REE', start_date='2022-01-01', end_date='2023-10-31', resolution='D', type='stock', headers=None):
52
55
  """
@@ -63,8 +66,22 @@ def longterm_ohlc_data (symbol='REE', start_date='2022-01-01', end_date='2023-10
63
66
  timeframe = _VCI_TIMEFRAME_MAP.get(resolution, 'ONE_DAY')
64
67
  start_dt = datetime.strptime(start_date, '%Y-%m-%d')
65
68
  end_dt = datetime.strptime(end_date, '%Y-%m-%d')
66
- count_back = (end_dt - start_dt).days + 5 # small buffer for non-trading days
67
- to_timestamp = int(end_dt.timestamp())
69
+
70
+ days = max((end_dt - start_dt).days + 1, 1)
71
+ if timeframe == 'ONE_MINUTE':
72
+ count_back = min(max(days * 250, 300), 1000)
73
+ elif timeframe in ['FIFTEEN_MINUTES', 'THIRTY_MINUTES']:
74
+ count_back = min(max(days * 20, 100), 1000)
75
+ elif timeframe == 'ONE_HOUR':
76
+ count_back = min(max(days * 6, 50), 1000)
77
+ else:
78
+ count_back = min(days + 5, 1000)
79
+
80
+ today_str = datetime.now().strftime('%Y-%m-%d')
81
+ if end_date >= today_str:
82
+ to_timestamp = int(datetime.now().timestamp())
83
+ else:
84
+ to_timestamp = int((end_dt + timedelta(days=1)).timestamp())
68
85
 
69
86
  url = 'https://trading.vietcap.com.vn/api/chart/OHLCChart/gap-chart'
70
87
  payload = {'timeFrame': timeframe, 'symbols': [symbol], 'to': to_timestamp, 'countBack': count_back}
@@ -74,12 +91,22 @@ def longterm_ohlc_data (symbol='REE', start_date='2022-01-01', end_date='2023-10
74
91
  return None
75
92
 
76
93
  bars = data[0]
94
+ dt_series = pd.to_datetime([int(t) for t in bars['t']], unit='s').tz_localize('UTC').tz_convert('Asia/Ho_Chi_Minh')
95
+ if timeframe in ['ONE_MINUTE', 'FIFTEEN_MINUTES', 'THIRTY_MINUTES', 'ONE_HOUR']:
96
+ time_vals = dt_series.strftime('%Y-%m-%d %H:%M:%S')
97
+ else:
98
+ time_vals = dt_series.strftime('%Y-%m-%d')
99
+
77
100
  df = pd.DataFrame({
78
- 'time': pd.to_datetime([int(t) for t in bars['t']], unit='s').strftime('%Y-%m-%d'),
101
+ 'time': time_vals,
79
102
  'open': bars['o'], 'high': bars['h'], 'low': bars['l'], 'close': bars['c'], 'volume': bars['v'],
80
103
  })
81
104
  df['ticker'] = symbol
82
- df = df[(df['time'] >= start_date) & (df['time'] <= end_date)]
105
+
106
+ start_cmp = start_date if timeframe not in ['ONE_MINUTE', 'FIFTEEN_MINUTES', 'THIRTY_MINUTES', 'ONE_HOUR'] else f"{start_date} 00:00:00"
107
+ end_cmp = end_date if timeframe not in ['ONE_MINUTE', 'FIFTEEN_MINUTES', 'THIRTY_MINUTES', 'ONE_HOUR'] else f"{end_date} 23:59:59"
108
+ df = df[(df['time'] >= start_cmp) & (df['time'] <= end_cmp)]
109
+
83
110
  if type == 'stock':
84
111
  df[['open', 'high', 'low', 'close']] = round(df[['open', 'high', 'low', 'close']] / 1000, 2)
85
112
  df[['open', 'high', 'low', 'close']] = df[['open', 'high', 'low', 'close']].astype(float)
@@ -67,11 +67,14 @@ def price_board (symbol_ls):
67
67
  for item in data:
68
68
  row = {}
69
69
  listing = item.get('listingInfo', {}) or {}
70
- row['ticker'] = listing.get('ticker')
70
+ row['ticker'] = listing.get('ticker') or listing.get('symbol') or item.get('symbol')
71
+ row['mappingSymbol'] = listing.get('mappingSymbol')
71
72
  row['exchange'] = listing.get('board')
72
73
  match = item.get('matchPrice', {}) or {}
73
74
  row['matchPrice'] = match.get('matchPrice')
74
75
  row['matchVolume'] = match.get('matchVol')
76
+ row['accumulatedVolume'] = match.get('accumulatedVolume')
77
+ row['openInterest'] = match.get('openInterest')
75
78
  bid_ask = item.get('bidAsk', {}) or {}
76
79
  for i, level in enumerate(bid_ask.get('bidPrices', [])[:3], start=1):
77
80
  row[f'bidPrice{i}'] = level.get('price')
@@ -1,9 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quant-agent
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Vietnam Quantitative Trading and Market Data Agent
5
- Author: quant-agent
5
+ Author-email: Tom Tran <thangtran.com@gmail.com>
6
6
  License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/tomtranai/quant-agent
8
+ Project-URL: Repository, https://github.com/tomtranai/quant-agent
9
+ Project-URL: Bug Tracker, https://github.com/tomtranai/quant-agent/issues
7
10
  Keywords: vietnam,stock,quant,trading,agent,finance,algorithmic-trading
8
11
  Classifier: Programming Language :: Python :: 3
9
12
  Classifier: Operating System :: OS Independent
@@ -18,6 +21,7 @@ Requires-Dist: python-dateutil>=2.8.0
18
21
 
19
22
  # quant-agent: Thư viện Phân tích Dữ liệu Chứng khoán & Giao dịch Việt Nam
20
23
 
24
+ [![PyPI version](https://img.shields.io/pypi/v/quant-agent.svg)](https://pypi.org/project/quant-agent/)
21
25
  [![Python](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org/)
22
26
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
23
27
  [![Market Data: Free](https://img.shields.io/badge/Market%20Data-Free%20%2F%20No%20Key-brightgreen.svg)]()
@@ -86,18 +90,27 @@ Hệ thống đã được tái cấu trúc và phân lập tầng nguồn dữ
86
90
  - Python >= 3.10
87
91
  - Kết nối Internet ổn định
88
92
 
89
- ### Cài đặt thư viện
90
- Clone repository và cài đặt ở chế độ editable hoặc build trực tiếp:
93
+ ### 1. Cài đặt trực tiếp từ PyPI (Khuyến nghị)
94
+ Bạn có thể cài đặt trực tiếp bản phát hành chính thức thông qua `pip`:
95
+
96
+ ```bash
97
+ pip install quant-agent
98
+ ```
99
+
100
+ Để nâng cấp lên phiên bản mới nhất bất kỳ lúc nào:
101
+ ```bash
102
+ pip install -U quant-agent
103
+ ```
104
+
105
+ ### 2. Cài đặt từ mã nguồn (Dành cho nhà phát triển / Đóng góp mã nguồn)
106
+ Clone repository và cài đặt ở chế độ editable:
91
107
 
92
108
  ```bash
93
109
  # Clone repository
94
- git clone https://github.com/quant-agent/quant-agent.git
110
+ git clone https://github.com/tomtranai/quant-agent.git
95
111
  cd quant-agent
96
112
 
97
- # Cài đặt các gói phụ thuộc
98
- pip install -r requirements.txt
99
-
100
- # Hoặc cài đặt trực tiếp dạng package
113
+ # Cài đặt các gói phụ thuộc & editable mode
101
114
  pip install -e .
102
115
  ```
103
116
 
@@ -184,6 +197,9 @@ graph TD
184
197
 
185
198
  ```python
186
199
  import quant_agent as qa
200
+
201
+ # Kiểm tra phiên bản
202
+ print(qa.__version__) # 0.3.1
187
203
  ```
188
204
 
189
205
  ### 1. Danh sách mã niêm yết
File without changes