Skip to content

Commit

Permalink
add get index data functions
Browse files Browse the repository at this point in the history
  • Loading branch information
thinh-vu committed Jan 26, 2023
1 parent 708a088 commit 79e08a8
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 24 deletions.
Binary file modified .DS_Store
Binary file not shown.
127 changes: 106 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ You can download the price board of a target list of stocks to analyze with ease
<details>
<summary>Price Board</summary>

![price_board](./src/tcbs_trading_board_sector.png)
![price_board](https://raw.githubusercontent.com/thinh-vu/vnstock/main/src/tcbs_trading_board_sector.png)

</details>

Expand All @@ -140,8 +140,8 @@ price_board('TCB,SSI,VND')
<details>
<summary>Intraday view on TCBS</summary>

![intraday](./src/tcbs_intraday_screen1.png)
![intraday](./src/tcbs_intraday_screen2.png)
![intraday](https://raw.githubusercontent.com/thinh-vu/vnstock/main/src/tcbs_intraday_screen1.png)
![intraday](https://raw.githubusercontent.com/thinh-vu/vnstock/main/src/tcbs_intraday_screen2.png)

</details>
vnstock allows the user to **download intraday real-time/historical data**. In
Expand All @@ -150,7 +150,7 @@ the example presented below, you can see the intraday historical data from the l
```python
df = stock_intraday_data(symbol='GMD',
page_num=0,
page_size=5000))
page_size=5000)
print(df.head())
```

Expand Down Expand Up @@ -302,7 +302,7 @@ financial_report (symbol='SSI', report_type='BalanceSheet', frequency='Quarterly

##### 📄 Income Statement

![income_statement](./src/financial_income_statement.png)
![income_statement](https://raw.githubusercontent.com/thinh-vu/vnstock/main/src/financial_income_statement.png)
```python
financial_flow(symbol="TCB", report_type='incomestatement', report_range='quarterly')
```
Expand All @@ -323,7 +323,7 @@ index

##### 🧾Balance Sheet

![balance_sheet](./src/financial_balancesheet.png)
![balance_sheet](https://raw.githubusercontent.com/thinh-vu/vnstock/main/src/financial_balancesheet.png)
```python
financial_flow(symbol="TCB", report_type='balancesheet', report_range='quarterly')
```
Expand All @@ -342,7 +342,7 @@ index
```
</details>

##### 💶Cashflow Report
##### 💶 Cashflow Report

```python
financial_flow(symbol="TCB", report_type='cashflow', report_range='quarterly')
Expand Down Expand Up @@ -478,7 +478,6 @@ Top New High > Top Foreign Trading > Top New Low

</details>

Input one of these following names to get your report: Breakout, Gainers, Losers, Value, Volume, ForeignTrading, NewLow, NewHigh
```python
market_top_mover('ForeignTrading')
```
Expand All @@ -503,22 +502,108 @@ fr_trade_heatmap ('All', 'FrBuyVol')
<details>
<summary>Output</summary>

```
organCode name value percentPriceChange ... ceilingPrice floorPrice industry_name rate
0 PVD PVD 1433300.0 0.068627 ... 16350.0 14250.0 Dầu khí 0.040308
1 PVS PVS 370100.0 0.096154 ... 22800.0 18800.0 Dầu khí 0.040308
2 PETRO PLX 249700.0 0.014516 ... 33150.0 28850.0 Dầu khí 0.040308
3 PETECHIM PTV 4000.0 0.064000 ... 5400.0 4000.0 Dầu khí 0.040308
4 BSRC BSR 3800.0 0.002000 ... 17200.0 12800.0 Dầu khí 0.040308
.. ... ... ... ... ... ... ... ... ...
10 None Khác 210200.0 0.027762 ... 0.0 0.0 Ngân hàng 0.050653
0 CMG CMG 74400.0 0.024390 ... 43850.0 38150.0 Công nghệ Thông tin 0.034816
1 SAM SAM 35700.0 0.020833 ... 7700.0 6700.0 Công nghệ Thông tin 0.034816
2 ELC ELC 4100.0 0.049197 ... 10650.0 9270.0 Công nghệ Thông tin 0.034816
3 ITD ITD 2000.0 0.068548 ... 13250.0 11550.0 Công nghệ Thông tin 0.034816
[92 rows x 10 columns]
```
</details>

### 2.15.3. Market latest indices & values
![latest_indices](https://raw.githubusercontent.com/thinh-vu/vnstock/main/src/get_latest_indices.png)

Retrieve the latest indices values & brief insights

```python
get_latest_indices()
```
organCode name value percentPriceChange ... ceilingPrice floorPrice industry_name rate
0 PVD PVD 1433300.0 0.068627 ... 16350.0 14250.0 Dầu khí 0.040308
1 PVS PVS 370100.0 0.096154 ... 22800.0 18800.0 Dầu khí 0.040308
2 PETRO PLX 249700.0 0.014516 ... 33150.0 28850.0 Dầu khí 0.040308
3 PETECHIM PTV 4000.0 0.064000 ... 5400.0 4000.0 Dầu khí 0.040308
4 BSRC BSR 3800.0 0.002000 ... 17200.0 12800.0 Dầu khí 0.040308
.. ... ... ... ... ... ... ... ... ...
10 None Khác 210200.0 0.027762 ... 0.0 0.0 Ngân hàng 0.050653
0 CMG CMG 74400.0 0.024390 ... 43850.0 38150.0 Công nghệ Thông tin 0.034816
1 SAM SAM 35700.0 0.020833 ... 7700.0 6700.0 Công nghệ Thông tin 0.034816
2 ELC ELC 4100.0 0.049197 ... 10650.0 9270.0 Công nghệ Thông tin 0.034816
3 ITD ITD 2000.0 0.068548 ... 13250.0 11550.0 Công nghệ Thông tin 0.034816

[92 rows x 10 columns]
<details>
<summary>Output</summary>

```
>>> get_latest_indices()
indexId comGroupCode indexValue tradingDate ... matchValue ceiling floor marketStatus
0 0 VNINDEX 1108.08 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
1 0 VN30 1121.92 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
2 0 HNXIndex 219.87 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
3 0 HNX30 378.94 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
4 0 UpcomIndex 73.98 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
5 0 VNXALL 1707.39 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
6 0 VN100 1063.59 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
7 0 VNALL 1066.54 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
8 0 VNCOND 1537.34 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
9 0 VNCONS 793.25 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
10 0 VNDIAMOND 1689.15 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
11 0 VNENE 541.51 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
12 0 VNFIN 1252.54 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
13 0 VNFINLEAD 1631.16 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
14 0 VNFINSELECT 1676.21 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
15 0 VNHEAL 1552.19 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
16 0 VNIND 628.34 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
17 0 VNIT 2631.82 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
18 0 VNMAT 1534.50 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
19 0 VNMID 1394.75 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
20 0 VNREAL 981.94 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
21 0 VNSI 1715.37 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
22 0 VNSML 1140.40 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
23 0 VNUTI 874.84 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
24 0 VNX50 1805.33 2023-01-19T00:00:00 ... 0.0 0.0 0.0 None
```
</details>

### 2.15.4. Market latest indices in depth data
![index_series_data](https://raw.githubusercontent.com/thinh-vu/vnstock/main/src/get_index_series_data.png)

```python
get_index_series(index_code='VNINDEX', time_range='OneYear')
```
- Data provider: FiinTrade on SSI iBoard
- Use one of the following index code:

```
'VNINDEX', 'VN30', 'HNXIndex', 'HNX30', 'UpcomIndex', 'VNXALL',
'VN100','VNALL', 'VNCOND', 'VNCONS','VNDIAMOND', 'VNENE', 'VNFIN',
'VNFINLEAD', 'VNFINSELECT', 'VNHEAL', 'VNIND', 'VNIT', 'VNMAT', 'VNMID',
'VNREAL', 'VNSI', 'VNSML', 'VNUTI', 'VNX50'
```
You can get the complete list of the latest indices from `get_latest_indices()` function

- `time_range`: Use one of the following values:
```
'OneDay', 'OneWeek', 'OneMonth', 'ThreeMonth', 'SixMonths', 'YearToDate', 'OneYear', 'ThreeYears', 'FiveYears'
```
<details>
<summary>Output</summary>

```
>>> get_index_series(index_code='VNINDEX', time_range='OneYear')
comGroupCode indexValue tradingDate ... matchValue totalMatchVolume totalMatchValue
0 VNINDEX 1470.76 2022-01-27T00:00:00 ... 1.554536e+13 498256400.0 1.554536e+13
1 VNINDEX 1478.96 2022-01-28T00:00:00 ... 1.913215e+13 634887600.0 1.913215e+13
2 VNINDEX 1497.66 2022-02-07T00:00:00 ... 1.710999e+13 516533800.0 1.710999e+13
3 VNINDEX 1500.99 2022-02-08T00:00:00 ... 2.106676e+13 660158600.0 2.106676e+13
4 VNINDEX 1505.38 2022-02-09T00:00:00 ... 2.360041e+13 722161500.0 2.360041e+13
.. ... ... ... ... ... ... ...
241 VNINDEX 1060.17 2023-01-13T00:00:00 ... 7.884840e+12 459494342.0 7.884840e+12
242 VNINDEX 1066.68 2023-01-16T00:00:00 ... 6.724499e+12 391079501.0 6.724499e+12
243 VNINDEX 1088.29 2023-01-17T00:00:00 ... 1.016031e+13 566247477.0 1.016031e+13
244 VNINDEX 1098.28 2023-01-18T00:00:00 ... 9.377296e+12 531786150.0 9.377296e+12
245 VNINDEX 1108.08 2023-01-19T00:00:00 ... 1.054607e+13 556193050.0 1.054607e+13
[246 rows x 14 columns]
```
</details>

# III. 🙋‍♂️ Contact Information
Expand Down
Binary file added src/get_index_series_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/get_latest_indices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 30 additions & 3 deletions vnstock/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ def financial_report (symbol, report_type, frequency, headers=headers): # Quarte
df = pd.read_excel(BytesIO(r.content), skiprows=7).dropna()
return df

# Need attention!
def financial_ratio_compare (symbol_ls, industry_comparison, frequency, start_year):
def financial_ratio_compare (symbol_ls, industry_comparison, frequency, start_year, headers=headers):
"""
This function returns the balance sheet of a stock symbol by a Quarterly or Yearly range.
Args:
Expand All @@ -194,7 +193,7 @@ def financial_ratio_compare (symbol_ls, industry_comparison, frequency, start_ye
elif i > 0:
company_join = '&'.join([company_join, 'CompareToCompanies={}'.format(symbol_ls[i])])
url = 'https://fiin-fundamental.ssi.com.vn/FinancialAnalysis/DownloadFinancialRatio2?language=vi&OrganCode={}&CompareToIndustry={}{}&Frequency={}&Ratios=ryd21&Ratios=ryd25&Ratios=ryd14&Ratios=ryd7&Ratios=rev&Ratios=isa22&Ratios=ryq44&Ratios=ryq14&Ratios=ryq12&Ratios=rtq51&Ratios=rtq50&Ratios=ryq48&Ratios=ryq47&Ratios=ryq45&Ratios=ryq46&Ratios=ryq54&Ratios=ryq55&Ratios=ryq56&Ratios=ryq57&Ratios=nob151&Ratios=casa&Ratios=ryq58&Ratios=ryq59&Ratios=ryq60&Ratios=ryq61&Ratios=ryd11&Ratios=ryd3&TimeLineFrom=2017_5'.format(symbol_ls[i], industry_comparison, company_join, frequency, timeline)
r = api_request(url)
r = requests.get(url, headers=headers)
df = pd.read_excel(BytesIO(r.content), skiprows=7)
return df

Expand Down Expand Up @@ -387,6 +386,34 @@ def fr_trade_heatmap (exchange, report_type):
combine_df = pd.concat(concat_ls)
return combine_df

# GET MARKET IN DEPT DATA - INDEX SERIES

def get_index_series(index_code='VNINDEX', time_range='OneYear', headers=headers):
"""
Retrieve the Stock market index series, maximum in 5 years
Args:
index_code (:obj:`str`, required): Use one of the following code'VNINDEX', 'VN30', 'HNXIndex', 'HNX30', 'UpcomIndex', 'VNXALL',
'VN100','VNALL', 'VNCOND', 'VNCONS','VNDIAMOND', 'VNENE', 'VNFIN',
'VNFINLEAD', 'VNFINSELECT', 'VNHEAL', 'VNIND', 'VNIT', 'VNMAT', 'VNMID',
'VNREAL', 'VNSI', 'VNSML', 'VNUTI', 'VNX50'. You can get the complete list of the latest indices from `get_latest_indices()` function
time_range (:obj: `str`, required): Use one of the following values 'OneDay', 'OneWeek', 'OneMonth', 'ThreeMonth', 'SixMonths', 'YearToDate', 'OneYear', 'ThreeYears', 'FiveYears'
"""
url = f"https://fiin-market.ssi.com.vn/MarketInDepth/GetIndexSeries?language=vi&ComGroupCode={index_code}&TimeRange={time_range}&id=1"
payload={}
response = requests.request("GET", url, headers=headers, data=payload)
result = json_normalize(response.json()['items'])
return result

def get_latest_indices(headers=headers):
"""
Retrieve the latest indices values
"""
url = "https://fiin-market.ssi.com.vn/MarketInDepth/GetLatestIndices?language=vi&pageSize=999999&status=1"
payload={}
response = requests.request("GET", url, headers=headers, data=payload)
result = json_normalize(response.json()['items'])
return result




0 comments on commit 79e08a8

Please sign in to comment.