Interest Rates
Relevant source files
The following files were used as context for generating this wiki page:
The Interest Rates module in the MBBank library provides the functionality to query and retrieve current interest rate information for various banking products, primarily focused on savings accounts. This feature allows users to programmatically access the yield data that the bank offers for different currencies and periods.
Within the project, interest rate data is used to inform users about potential returns on Savings Accounts and is integrated into both the synchronous and asynchronous client implementations. The module ensures that data returned from the MBBank API is validated and structured into predictable Python objects using Pydantic models.
Sources: mbbank/modals/interest_rate.py, mbbank/sync/mbbank.py:241-262, mbbank/aio/mbbank.py:270-291
Architecture and Data Flow
The retrieval of interest rates follows a standard request-response pattern where the client authenticates with the MBBank retail web API and requests data for a specific product code.
Request Logic
The system targets the TIENGUI.KHN.EMB product code by default when querying the interest rate endpoint. The request requires a currency parameter (defaulting to "VND").
The diagram shows the logic flow from the client call to the final structured modal return.
Sources: mbbank/sync/mbbank.py:241-262, mbbank/aio/mbbank.py:270-291
API Integration
The interest rate functionality is exposed through two primary methods:
MBBank.getInterestRate()(Synchronous)MBBankAsync.getInterestRate()(Asynchronous)
Both methods interface with the endpoint: https://online.mbbank.com.vn/api/retail_web/saving/getInterestRate.
Sources: mbbank/sync/mbbank.py:259, mbbank/aio/mbbank.py:288
Data Models
The library uses Pydantic to define the structure of the interest rate data. This ensures type safety and easy attribute access for developers.
InterestRate Model
This model represents an individual interest rate entry for a specific product and duration.
| Field | Type | Description |
|---|---|---|
productCode | str | Internal code for the banking product |
productName | str | Human-readable name of the product |
currency | str | Currency (e.g., VND, USD) |
period | str | The duration/term for the rate |
amountMin | str | Minimum amount required for this rate |
amountMax | str | Maximum amount allowed for this rate |
interestRate | str | The actual percentage rate |
region | str | Geographical or branch region applicable |
Sources: mbbank/modals/interest_rate.py:7-18
InterestRateResponseModal
The top-level response container that wraps the list of rates returned by the API.
| Field | Type | Description |
|---|---|---|
interestRateList | List[InterestRate] | A collection of interest rate entries |
Sources: mbbank/modals/interest_rate.py:21-25
Implementation Details
The following code demonstrates how the interest rate is fetched within the library's core logic.
# mbbank/sync/mbbank.py:241-262
def getInterestRate(self, currency: str = "VND") -> InterestRateResponseModal:
"""
Get saving interest rate
"""
json_data = {
"productCode": "TIENGUI.KHN.EMB",
"currency": currency,
}
data_out = self._req(
"https://online.mbbank.com.vn/api/retail_web/saving/getInterestRate",
json=json_data,
)
return InterestRateResponseModal.model_validate(data_out, strict=True)
Sources: mbbank/sync/mbbank.py:241-262
Relationship with Savings
Interest rates are closely linked to the savings sub-system. While getInterestRate provides a general table of available rates, specific saving accounts carry their own assigned rates.
This diagram illustrates how interest rate data concepts are shared across different modals in the system.
Sources: mbbank/modals/interest_rate.py, mbbank/modals/saving_list.py:34, mbbank/modals/saving_detail.py:17
Summary
The Interest Rates feature provides a structured way to query MBBank's savings yield data. By utilizing InterestRateResponseModal, the library abstracts the raw API JSON into a set of validated objects containing product codes, periods, and rates. It supports both synchronous and asynchronous workflows, making it versatile for different application architectures.