26 lines
981 B
Python
26 lines
981 B
Python
def balance_accounts(spot_balance, earn_balance, lower_limit, step_size, percentage):
|
|
spot_balance+=earn_balance
|
|
earn_balance=0
|
|
|
|
#target_spot_balance = (spot_balance + earn_balance) * percentage
|
|
target_spot_balance = spot_balance * percentage
|
|
|
|
while abs(spot_balance - target_spot_balance) >= step_size:
|
|
if spot_balance < target_spot_balance:
|
|
spot_balance += step_size
|
|
earn_balance -= step_size
|
|
elif spot_balance > target_spot_balance:
|
|
spot_balance -= step_size
|
|
earn_balance += step_size
|
|
|
|
# Ensure spot_balance is above lower_limit
|
|
while spot_balance < lower_limit and earn_balance >= step_size:
|
|
spot_balance += step_size
|
|
earn_balance -= step_size
|
|
|
|
# If earn_balance is not enough, transfer the remaining amount
|
|
if spot_balance < lower_limit:
|
|
spot_balance += earn_balance
|
|
earn_balance = 0
|
|
|
|
return [spot_balance, earn_balance] |