This document describes how to use the Zarban SDK to create loans. The SDK provides functionality for creating new loans and monitoring their status through a simple Python interface.
- Python 3.x
- Zarban SDK (
zarban.wallet
) - Valid API access token
- Child user credentials (if applicable)
pip install zarban
The SDK requires two forms of authentication:
- An API access token
- A child user header (optional, depending on use case)
cfg = wallet.Configuration(host="https://testwapi.zarban.io")
cfg.access_token = ACCESS_TOKEN
api_client = wallet.ApiClient(cfg)
api_client.default_headers['X-Child-User'] = "your_child_username"
Creates a new loan using the specified parameters.
Parameters:
loans_api
: LoansApi instanceplan_name
: str - Name of the loan plan (Currently supports "DAIA" and "DAIB")collateral
: str - Amount of collateraldebt
: str - Amount of debtsymbol
: str - Coin symbol (e.g., "USDT")loan_to_value_option
: str - Risk level ("Safe", "Normal", or "Risky")
Important Notes:
- Either
collateral
ordebt
must be empty - Returns the loan ID if successful, None if failed
Example:
loan_id = create_loan(
loans_api,
plan_name="DAIA",
collateral="1000",
debt="",
symbol="USDT",
loan_to_value_option="Safe"
)
Retrieves and displays the current state of a loan.
Parameters:
loans_api
: LoansApi instanceloan_id
: str - The ID of the loan to check
Returns: Loan details object containing:
- State
- Collateral amount
- Debt amount
- Interest rate
- Creation date
Example:
loan_details = loan_Status(loans_api, loan_id)
Creates a new vault/loan.
Request Body:
{
"intent": "Create",
"planName": "DAIA",
"collateral": "1000",
"debt": "",
"symbol": "USDT",
"loanToValueOption": "Safe"
}
Response (200 OK):
{
"id": "1234567890"
}
Retrieves loan details.
Path Parameters:
id
: Loan identifier
Response (200 OK): Returns loan details including status, collateral, debt, and other relevant information.
The SDK uses ApiException
for error handling. Common errors include:
- 400: Bad Request
- 401: Unauthorized
- 500: Internal Server Error
Example error handling:
try:
loan_details = loans_api.get_loan_details(loan_id)
except wallet.ApiException as e:
print(f"Error: {e}")
def main():
# Replace with your actual access token
ACCESS_TOKEN = "your_child_username"
# Setup API client
cfg = wallet.Configuration(host="https://testwapi.zarban.io")
cfg.access_token = ACCESS_TOKEN
api_client = wallet.ApiClient(cfg)
loans_api = wallet.LoansApi(api_client)
# Set the X-Child-User header in the api_client's default headers
api_client.default_headers['X-Child-User'] = "your_child_username"
# Create loan
loan_id = create_loan(
loans_api,
"DAIA", # plan name
"1000", # collateral
"", # debt
"USDT", # symbol
"Safe" # loan to value option
)
# Check status
if loan_id:
loan_details = loan_status(loans_api, loan_id)
- Always remove the X-Child-User header after use:
api_client.default_headers.pop('X-Child-User', None)
- Implement proper error handling for all API calls
- Validate input parameters before making API calls
- Store sensitive information (like access tokens) in environment variables
- Only "DAIA" and "DAIB" plans are currently supported
- Either collateral or debt must be empty when creating a loan
- API access tokens should be kept secure and not hardcoded
For additional support or bug reports, please contact the Zarban support team.