Examples Guide
Relevant source files
The following files were used as context for generating this wiki page:
The Examples Guide provides a comprehensive overview of the demonstration scripts available in the mbbank-lib repository. These examples illustrate how to interact with the MBBank API using both synchronous and asynchronous clients to perform common banking operations such as checking balances, viewing transaction history, managing saving accounts, and transferring funds.
The scripts are designed to be standalone utilities that prompt for user credentials and execute specific API calls, serving as a reference for developers integrating the library into their own applications.
Sources: examples/readme.md:1-21, mbbank/init.py:1-115
Core Initialization and Authentication
All example scripts follow a consistent initialization pattern. They require an MBBank username and password, which are used to instantiate the MBBank (synchronous) or MBBankAsync (asynchronous) class. Authentication is handled automatically by the library during the first API call, which includes a CAPCHA challenge-response flow.
The diagram above shows the general lifecycle of an example script execution, highlighting the underlying automated authentication process.
Sources: mbbank/sync/mbbank.py:73-108, examples/transfer_money.py:7-13
Transferring Funds
The transfer money example demonstrates a multi-step process for moving funds between accounts. This involves selecting a source account, identifying a destination bank, and handling authentication methods.
Key Components of the Transfer Flow
- Account Selection: Retrieving the balance to list available accounts for the user to select as a source.
- Bank Identification: Fetching a list of supported banks to identify the recipient's bank code.
- Context Creation: Using
makeTransferAccountToAccountto initialize aTransferContext. - Authorization: Selecting an authentication method (e.g., Digital OTP) and confirming the transaction.
| Step | Function/Method | Description |
|---|---|---|
| 1 | getBalance() | Lists source accounts and current balances. |
| 2 | getBankList() | Provides a list of bank codes (e.g., 'MB'). |
| 3 | makeTransferAccountToAccount() | Prepares the transfer context with amount and message. |
| 4 | get_auth_list() | Retrieves available authentication methods for the transfer. |
| 5 | transfer() | Executes the final transfer with the provided OTP. |
Sources: examples/transfer_money.py:16-86, mbbank/sync/mbbank.py:440-466
Account and History Retrieval
Examples such as transaction_history.py and saving_list.py focus on data retrieval and formatting for end-user display.
Transaction History Logic
The script retrieves the history for a specific account over a defined time range (usually the last 30 days).
The sequence diagram illustrates the flow for fetching transaction history, starting from account discovery to final data display.
Sources: examples/transaction_history.py:11-30, mbbank/sync/mbbank.py:162-185
Saving Accounts Management
The saving_list.py example demonstrates how to access the SavingListResponseModal to display information regarding online fixed savings and branch savings.
- Logic: It accesses the
savingListattribute (or nestedSavingDatain the latest modals) to extract account numbers, principal amounts, interest rates, and maturity dates. - Data Structure: Information is categorized into
onlineFixedSavingandbranchSavingsections within the response.
Sources: examples/saving_list.py:10-44, mbbank/aio/mbbank.py:270-282
Summary Table of API Methods in Examples
The following table summarizes the primary methods utilized across the example scripts.
| Method | Source File | Purpose |
|---|---|---|
getBalance | mbbank/sync/mbbank.py | Retrieves account numbers and current balances. |
getTransactionAccountHistory | mbbank/sync/mbbank.py | Fetches historical transactions for a date range. |
getSavingList | mbbank/aio/mbbank.py | Returns details on all saving accounts. |
getCardList | mbbank/sync/mbbank.py | Returns a list of all cards associated with the user. |
getBankList | mbbank/sync/mbbank.py | Retrieves a list of banks for inter-bank transfers. |
Sources: mbbank/sync/mbbank.py:187-353, mbbank/init.py:22-105
The examples provided in the library serve as practical implementation references, demonstrating the transition from raw API responses to structured data models suitable for terminal display or further application logic.