0
# Lending
1
2
KuCoin Lending Market V3 operations for earning interest on cryptocurrency holdings. Provides subscription and redemption services for various lending products with flexible terms and competitive rates.
3
4
## Capabilities
5
6
### Currency Information
7
8
Access detailed information about lending currencies and their parameters.
9
10
```python { .api }
11
def get_currency_information(currency: str):
12
"""
13
Get detailed currency information for lending.
14
15
Args:
16
currency (str): Currency code (e.g., 'USDT', 'BTC')
17
18
Returns:
19
dict: Currency lending parameters including minimum amounts, rates, and terms
20
"""
21
```
22
23
### Interest Rates
24
25
Current and historical interest rate information.
26
27
```python { .api }
28
def get_interest_rates(currency: str):
29
"""
30
Get current interest rates for lending currency.
31
32
Args:
33
currency (str): Currency code
34
35
Returns:
36
dict: Interest rate information with current rates and historical data
37
"""
38
```
39
40
### Subscription Operations
41
42
Subscribe to lending products to start earning interest.
43
44
```python { .api }
45
def subscription(currency: str, interest_rate: str, size: str):
46
"""
47
Subscribe to a lending product.
48
49
Args:
50
currency (str): Currency to lend (e.g., 'USDT')
51
size (str): Amount to lend
52
interestRate (str): Expected interest rate
53
54
Returns:
55
dict: Subscription order information with order ID
56
"""
57
58
def modify_subscription_orders(currency: str, purchaseOrderNo: str, interestRate: str):
59
"""
60
Modify existing subscription order interest rate.
61
62
Args:
63
currency (str): Currency code
64
purchaseOrderNo (str): Purchase order number to modify
65
interestRate (str): New interest rate
66
67
Returns:
68
dict: Modification result
69
"""
70
71
def get_subscription_orders(currency: str, **kwargs):
72
"""
73
Get subscription order history.
74
75
Args:
76
currency (str): Currency code
77
status (str, optional): Order status filter
78
currentPage (int, optional): Page number
79
pageSize (int, optional): Page size
80
81
Returns:
82
dict: Paginated subscription orders
83
"""
84
```
85
86
### Redemption Operations
87
88
Redeem funds from lending products.
89
90
```python { .api }
91
def redemption(currency: str, purchase_order_no: str, size: str):
92
"""
93
Redeem funds from a lending subscription.
94
95
Args:
96
currency (str): Currency to redeem
97
size (str): Amount to redeem
98
purchaseOrderNo (str): Purchase order number for redemption
99
100
Returns:
101
dict: Redemption order information
102
"""
103
104
def get_redemption_orders(currency: str, **kwargs):
105
"""
106
Get redemption order history.
107
108
Args:
109
currency (str): Currency code
110
status (str, optional): Order status filter
111
redeemOrderNo (str, optional): Specific redemption order number
112
currentPage (int, optional): Page number
113
pageSize (int, optional): Page size
114
115
Returns:
116
dict: Paginated redemption orders
117
"""
118
```
119
120
## Usage Examples
121
122
### Basic Lending Operations
123
124
```python
125
from kucoin.client import Lending
126
127
# Initialize lending client
128
lending = Lending(api_key, api_secret, api_passphrase, is_sandbox=False)
129
130
# Get currency information for USDT lending
131
currency_info = lending.get_currency_info('USDT')
132
print(f"Min lending amount: {currency_info['minPurchaseSize']}")
133
print(f"Currency precision: {currency_info['precision']}")
134
135
# Check current interest rates
136
rates = lending.get_interest_rates('USDT')
137
print(f"Current rate: {rates['currentAnnualRate']}% annual")
138
```
139
140
### Lending Subscription
141
142
```python
143
# Subscribe to USDT lending
144
subscription = lending.post_subscription(
145
currency='USDT',
146
size='1000',
147
interestRate='0.05' # 5% annual rate
148
)
149
print(f"Subscription order: {subscription['orderNo']}")
150
151
# Check subscription orders
152
subscriptions = lending.get_subscription_orders('USDT')
153
for order in subscriptions['items']:
154
print(f"Order {order['orderNo']}: {order['size']} USDT at {order['interestRate']}% rate")
155
print(f"Status: {order['status']}, Interest earned: {order['interestAmount']}")
156
```
157
158
### Modifying Subscriptions
159
160
```python
161
# Modify interest rate for existing subscription
162
modify_result = lending.modify_subscription_orders(
163
currency='USDT',
164
purchaseOrderNo='order-123456',
165
interestRate='0.06' # Change to 6% annual rate
166
)
167
print(f"Modification result: {modify_result}")
168
```
169
170
### Redemption Operations
171
172
```python
173
# Redeem funds from lending
174
redemption = lending.post_redemption(
175
currency='USDT',
176
size='500', # Redeem 500 USDT
177
purchaseOrderNo='order-123456'
178
)
179
print(f"Redemption order: {redemption['orderNo']}")
180
181
# Check redemption history
182
redemptions = lending.get_redemption_orders('USDT')
183
for order in redemptions['items']:
184
print(f"Redemption {order['redeemOrderNo']}: {order['size']} USDT")
185
print(f"Status: {order['status']}, Processing time: {order['updatedAt']}")
186
```
187
188
### Portfolio Management
189
190
```python
191
# Monitor all active lending positions
192
active_subscriptions = lending.get_subscription_orders('USDT', status='ACTIVE')
193
total_lent = sum(float(order['size']) for order in active_subscriptions['items'])
194
total_interest = sum(float(order['interestAmount']) for order in active_subscriptions['items'])
195
196
print(f"Total amount lent: {total_lent} USDT")
197
print(f"Total interest earned: {total_interest} USDT")
198
print(f"Average return: {(total_interest / total_lent * 100):.2f}%")
199
200
# Diversify across different currencies
201
currencies = ['USDT', 'BTC', 'ETH']
202
for currency in currencies:
203
try:
204
info = lending.get_currency_info(currency)
205
rates = lending.get_interest_rates(currency)
206
print(f"{currency}: Min amount {info['minPurchaseSize']}, Current rate {rates['currentAnnualRate']}%")
207
except Exception as e:
208
print(f"Error getting {currency} info: {e}")
209
```
210
211
### Advanced Rate Monitoring
212
213
```python
214
# Compare rates across time periods
215
import time
216
217
def monitor_rates(currency, duration_minutes=60):
218
"""Monitor interest rates for a currency over time."""
219
rates_history = []
220
end_time = time.time() + (duration_minutes * 60)
221
222
while time.time() < end_time:
223
try:
224
rates = lending.get_interest_rates(currency)
225
current_rate = float(rates['currentAnnualRate'])
226
rates_history.append({
227
'timestamp': time.time(),
228
'rate': current_rate
229
})
230
print(f"{currency} rate: {current_rate}%")
231
time.sleep(300) # Check every 5 minutes
232
except Exception as e:
233
print(f"Error monitoring rates: {e}")
234
break
235
236
return rates_history
237
238
# Monitor USDT rates for 1 hour
239
# usdt_rates = monitor_rates('USDT', 60)
240
```
241
242
## Types
243
244
```python { .api }
245
CurrencyInfo = dict
246
# {
247
# "currency": str, # Currency code
248
# "purchaseEnable": bool, # Subscription enabled
249
# "redeemEnable": bool, # Redemption enabled
250
# "increment": str, # Amount increment
251
# "minPurchaseSize": str, # Minimum subscription amount
252
# "minInterestRate": str, # Minimum interest rate
253
# "maxInterestRate": str, # Maximum interest rate
254
# "interestIncrement": str, # Interest rate increment
255
# "maxPurchaseSize": str, # Maximum subscription amount
256
# "marketInterestRate": str, # Market interest rate
257
# "autoPurchaseEnable": bool, # Auto-purchase enabled
258
# "precision": int # Currency precision
259
# }
260
261
InterestRateInfo = dict
262
# {
263
# "currentAnnualRate": str, # Current annual interest rate
264
# "currency": str, # Currency code
265
# "marketInterestRate": str, # Market interest rate
266
# "basicInterestRate": str, # Basic interest rate
267
# "floatingInterestRate": str, # Floating interest rate
268
# "annualInterestRate": str # Annual interest rate
269
# }
270
271
SubscriptionOrder = dict
272
# {
273
# "orderNo": str, # Order number
274
# "currency": str, # Currency
275
# "size": str, # Subscription amount
276
# "lentAmount": str, # Actually lent amount
277
# "interestRate": str, # Interest rate
278
# "interestAmount": str, # Interest earned
279
# "incomeAmount": str, # Total income
280
# "applyTime": int, # Application time
281
# "status": str # Order status ('PENDING', 'ACTIVE', 'DONE', 'CANCELED')
282
# }
283
284
RedemptionOrder = dict
285
# {
286
# "redeemOrderNo": str, # Redemption order number
287
# "currency": str, # Currency
288
# "size": str, # Redemption amount
289
# "principal": str, # Principal amount
290
# "interestAmount": str, # Interest amount
291
# "applyTime": int, # Application time
292
# "status": str, # Redemption status
293
# "updatedAt": int # Last update time
294
# }
295
296
SubscriptionResponse = dict
297
# {
298
# "orderNo": str # Subscription order number
299
# }
300
301
RedemptionResponse = dict
302
# {
303
# "orderNo": str # Redemption order number
304
# }
305
```