# 1.5. Lấy dữ liệu room NĐTNN

Mô tả cách sử dụng thư viện sau khi người dùng đã đăng nhập. Các ví dụ chi tiết được nêu ra ở cuối chương này.

```
data = client.PriceStatistics().get_foreign(
    tickers=tickers,
    time_filter=time_filter,
    from_date=from_date,
    to_date=to_date
).get_data()
```

**Tham số:**

| Tên tham số  | Mô tả                                                                                                                                                        | Kiểu dữ liệu  | Mặc định       | Bắt buộc |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- | -------------- | -------- |
| tickers      | Danh sách mã được viết in hoa.                                                                                                                               | str hoặc list |                | Có       |
| time\_filter | Tần suất lấy dữ liệu, có thể lấy dữ liệu theo Ngày, Tuần, Tháng, Quý, Năm. Truyền vào 1 trong 5 giá trị "Daily", "Weekly", "Monthly", "Quarterly", "Yearly". | str           |                | Có       |
| from\_date   | Mốc thời gian lấy dữ liệu xa nhất.                                                                                                                           | str           |                | Có       |
| to\_date     | Mốc thời gian lấy dữ liệu gần nhất.                                                                                                                          | str           | datetime.now() | Không    |

Class nhận dữ liệu là PriceStatistics và có phương thức nhận dữ liệu là get\_foreign()

```python
data = client.PriceStatistics().get_foreign(
    tickers=tickers,
    time_filter="Daily",
    from_date="2025-08-20",
    to_date="2025-08-27"
)
print(data)
```

Dữ liệu có các thuộc tính:

* time\_filter="Daily"

| Tên thuộc tính           | Mô tả                           | Kiểu dữ liệu |
| ------------------------ | ------------------------------- | ------------ |
| ticker                   | Tên mã.                         | str          |
| timestamp                | Thời gian giao dịch             | str          |
| foreignBuyVolumeTotal    | Khối lượng NĐTNN mua vào        | float        |
| foreignSellVolumeTotal   | Khối lượng NĐTNN bán ra         | float        |
| foreignBuyValueTotal     | Giá trị NĐTNN mua vào           | int          |
| foreignSellValueTotal    | Giá trị NĐTNN bán ra            | int          |
| foreignNetVolumeTotal    | Khối lượng NĐTNN mua/bán ròng   | float        |
| foreignNetValueTotal     | Giá trị NĐTNN mua/bán ròng      | int          |
| foreignBuyVolumeMatched  | Khối lượng NĐTNN mua khớp lệnh  | float        |
| foreignSellVolumeMatched | Khối lượng NĐTNN bán khớp lệnh  | float        |
| foreignBuyValueMatched   | Giá trị NĐTNN mua khớp lệnh     | int          |
| foreignSellValueMatched  | Giá trị NĐTNN bán khớp lệnh     | int          |
| foreignBuyVolumeDeal     | Khối lượng NĐTNN mua thỏa thuận | float        |
| foreignSellVolumeDeal    | Khối lượng NĐTNN bán thỏa thuận | float        |
| foreignBuyValueDeal      | Giá trị NĐTNN mua thỏa thuận    | int          |
| foreignSellValueDeal     | Giá trị NĐTNN bán thỏa thuận    | int          |
| foreignCurrentRoom       | Giá trị room hiện hại của NĐTNN | int          |
| foreignTotalRoom         | Giá trị room tối đa của NĐTNN   | int          |
| percentForeignTotalRoom  | % room hiện tại của NĐTNN       | float        |
| foreignOwned             | Giá trị sở hữu của NĐTNN        | int          |
| percentForeignOwned      | % sở hữu của NĐTNN              | float        |

* time\_filter="Weekly"

| Tên thuộc tính           | Mô tả                           | Kiểu dữ liệu |
| ------------------------ | ------------------------------- | ------------ |
| ticker                   | Tên mã.                         | str          |
| week                     | Tuần trong năm                  | int          |
| year                     | Năm                             | int          |
| foreignBuyVolumeTotal    | Khối lượng NĐTNN mua vào        | float        |
| foreignSellVolumeTotal   | Khối lượng NĐTNN bán ra         | float        |
| foreignBuyValueTotal     | Giá trị NĐTNN mua vào           | int          |
| foreignSellValueTotal    | Giá trị NĐTNN bán ra            | int          |
| foreignNetVolumeTotal    | Khối lượng NĐTNN mua/bán ròng   | float        |
| foreignNetValueTotal     | Giá trị NĐTNN mua/bán ròng      | int          |
| foreignBuyVolumeMatched  | Khối lượng NĐTNN mua khớp lệnh  | float        |
| foreignSellVolumeMatched | Khối lượng NĐTNN bán khớp lệnh  | float        |
| foreignBuyValueMatched   | Giá trị NĐTNN mua khớp lệnh     | int          |
| foreignSellValueMatched  | Giá trị NĐTNN bán khớp lệnh     | int          |
| foreignBuyVolumeDeal     | Khối lượng NĐTNN mua thỏa thuận | float        |
| foreignSellVolumeDeal    | Khối lượng NĐTNN bán thỏa thuận | float        |
| foreignBuyValueDeal      | Giá trị NĐTNN mua thỏa thuận    | int          |
| foreignSellValueDeal     | Giá trị NĐTNN bán thỏa thuận    | int          |
| foreignCurrentRoom       | Giá trị room hiện hại của NĐTNN | int          |
| foreignTotalRoom         | Giá trị room tối đa của NĐTNN   | int          |
| percentForeignTotalRoom  | % room hiện tại của NĐTNN       | float        |
| foreignOwned             | Giá trị sở hữu của NĐTNN        | int          |
| percentForeignOwned      | % sở hữu của NĐTNN              | float        |

* time\_filter="Monthly"

| Tên thuộc tính           | Mô tả                           | Kiểu dữ liệu |
| ------------------------ | ------------------------------- | ------------ |
| ticker                   | Tên mã.                         | str          |
| month                    | Tháng trong năm                 | int          |
| year                     | Năm                             | int          |
| foreignBuyVolumeTotal    | Khối lượng NĐTNN mua vào        | float        |
| foreignSellVolumeTotal   | Khối lượng NĐTNN bán ra         | float        |
| foreignBuyValueTotal     | Giá trị NĐTNN mua vào           | int          |
| foreignSellValueTotal    | Giá trị NĐTNN bán ra            | int          |
| foreignNetVolumeTotal    | Khối lượng NĐTNN mua/bán ròng   | float        |
| foreignNetValueTotal     | Giá trị NĐTNN mua/bán ròng      | int          |
| foreignBuyVolumeMatched  | Khối lượng NĐTNN mua khớp lệnh  | float        |
| foreignSellVolumeMatched | Khối lượng NĐTNN bán khớp lệnh  | float        |
| foreignBuyValueMatched   | Giá trị NĐTNN mua khớp lệnh     | int          |
| foreignSellValueMatched  | Giá trị NĐTNN bán khớp lệnh     | int          |
| foreignBuyVolumeDeal     | Khối lượng NĐTNN mua thỏa thuận | float        |
| foreignSellVolumeDeal    | Khối lượng NĐTNN bán thỏa thuận | float        |
| foreignBuyValueDeal      | Giá trị NĐTNN mua thỏa thuận    | int          |
| foreignSellValueDeal     | Giá trị NĐTNN bán thỏa thuận    | int          |
| foreignCurrentRoom       | Giá trị room hiện hại của NĐTNN | int          |
| foreignTotalRoom         | Giá trị room tối đa của NĐTNN   | int          |
| percentForeignTotalRoom  | % room hiện tại của NĐTNN       | float        |
| foreignOwned             | Giá trị sở hữu của NĐTNN        | int          |
| percentForeignOwned      | % sở hữu của NĐTNN              | float        |

* time\_filter="Quarterly"

| Tên thuộc tính           | Mô tả                           | Kiểu dữ liệu |
| ------------------------ | ------------------------------- | ------------ |
| ticker                   | Tên mã.                         | str          |
| quarter                  | Quý trong năm                   | int          |
| year                     | Năm                             | int          |
| foreignBuyVolumeTotal    | Khối lượng NĐTNN mua vào        | float        |
| foreignSellVolumeTotal   | Khối lượng NĐTNN bán ra         | float        |
| foreignBuyValueTotal     | Giá trị NĐTNN mua vào           | int          |
| foreignSellValueTotal    | Giá trị NĐTNN bán ra            | int          |
| foreignNetVolumeTotal    | Khối lượng NĐTNN mua/bán ròng   | float        |
| foreignNetValueTotal     | Giá trị NĐTNN mua/bán ròng      | int          |
| foreignBuyVolumeMatched  | Khối lượng NĐTNN mua khớp lệnh  | float        |
| foreignSellVolumeMatched | Khối lượng NĐTNN bán khớp lệnh  | float        |
| foreignBuyValueMatched   | Giá trị NĐTNN mua khớp lệnh     | int          |
| foreignSellValueMatched  | Giá trị NĐTNN bán khớp lệnh     | int          |
| foreignBuyVolumeDeal     | Khối lượng NĐTNN mua thỏa thuận | float        |
| foreignSellVolumeDeal    | Khối lượng NĐTNN bán thỏa thuận | float        |
| foreignBuyValueDeal      | Giá trị NĐTNN mua thỏa thuận    | int          |
| foreignSellValueDeal     | Giá trị NĐTNN bán thỏa thuận    | int          |
| foreignCurrentRoom       | Giá trị room hiện hại của NĐTNN | int          |
| foreignTotalRoom         | Giá trị room tối đa của NĐTNN   | int          |
| percentForeignTotalRoom  | % room hiện tại của NĐTNN       | float        |
| foreignOwned             | Giá trị sở hữu của NĐTNN        | int          |
| percentForeignOwned      | % sở hữu của NĐTNN              | float        |

* time\_filter="Yearly"

| Tên thuộc tính           | Mô tả                           | Kiểu dữ liệu |
| ------------------------ | ------------------------------- | ------------ |
| ticker                   | Tên mã.                         | str          |
| year                     | Năm                             | int          |
| foreignBuyVolumeTotal    | Khối lượng NĐTNN mua vào        | float        |
| foreignSellVolumeTotal   | Khối lượng NĐTNN bán ra         | float        |
| foreignBuyValueTotal     | Giá trị NĐTNN mua vào           | int          |
| foreignSellValueTotal    | Giá trị NĐTNN bán ra            | int          |
| foreignNetVolumeTotal    | Khối lượng NĐTNN mua/bán ròng   | float        |
| foreignNetValueTotal     | Giá trị NĐTNN mua/bán ròng      | int          |
| foreignBuyVolumeMatched  | Khối lượng NĐTNN mua khớp lệnh  | float        |
| foreignSellVolumeMatched | Khối lượng NĐTNN bán khớp lệnh  | float        |
| foreignBuyValueMatched   | Giá trị NĐTNN mua khớp lệnh     | int          |
| foreignSellValueMatched  | Giá trị NĐTNN bán khớp lệnh     | int          |
| foreignBuyVolumeDeal     | Khối lượng NĐTNN mua thỏa thuận | float        |
| foreignSellVolumeDeal    | Khối lượng NĐTNN bán thỏa thuận | float        |
| foreignBuyValueDeal      | Giá trị NĐTNN mua thỏa thuận    | int          |
| foreignSellValueDeal     | Giá trị NĐTNN bán thỏa thuận    | int          |
| foreignCurrentRoom       | Giá trị room hiện hại của NĐTNN | int          |
| foreignTotalRoom         | Giá trị room tối đa của NĐTNN   | int          |
| percentForeignTotalRoom  | % room hiện tại của NĐTNN       | float        |
| foreignOwned             | Giá trị sở hữu của NĐTNN        | int          |
| percentForeignOwned      | % sở hữu của NĐTNN              | float        |

Ví dụ:

```python
from FiinQuantX import FiinSession

username = 'REPLACE_WITH_YOUR_USER_NAME'
password = 'REPLACE_WITH_YOUR_PASS_WORD'

client = FiinSession(username=username, password=password).login()

tickers = ["HPG", "MWG"]

data = client.PriceStatistics().get_foreign(
    tickers=tickers,
    time_filter="Daily",
    from_date="2025-08-20",
    to_date="2025-08-27"
)
print(data)
```
