Skip to content

Commit 26a05d8

Browse files
committed
Change percent value type
1 parent 36afaf8 commit 26a05d8

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

shkeeper/api_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def autopayout(crypto_name):
289289
if w.prespolicy == PayoutReservePolicy.AMOUNT:
290290
w.presamount = req["prespolicyValue"]
291291
elif w.prespolicy == PayoutReservePolicy.PERCENT:
292-
w.presamount = int(req["prespolicyValue"]) / 100 # make it float
292+
w.presamount = int(req["prespolicyValue"]) # store percent as integer
293293
else:
294294
w.presamount = None
295295
w.pcond = req["policyValue"]

shkeeper/models.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,22 @@ def do_payout(self):
109109
)
110110
elif crypto.wallet.prespolicy == PayoutReservePolicy.AMOUNT:
111111
should_payout = balance - Decimal(crypto.wallet.presamount)
112-
if should_payout < 0:
113-
raise Exception(f"Unable to autopayout, reserved amount is bigger than balance: {balance} < {crypto.wallet.presamount}")
112+
if should_payout <= 0:
113+
raise Exception(f"Unable to autopayout, reserved amount is bigger or equal to balance: {balance} < {crypto.wallet.presamount}")
114114
else:
115115
res = crypto.mkpayout(
116116
self.pdest, should_payout, self.pfee, subtract_fee_from_amount=True
117117
)
118118
elif crypto.wallet.prespolicy == PayoutReservePolicy.PERCENT:
119-
should_payout = balance * (1 - Decimal(crypto.wallet.presamount))
119+
should_payout = balance * (1 - (Decimal(crypto.wallet.presamount) / 100)) # presamount is stored as integer percent
120120
res = crypto.mkpayout(
121121
self.pdest, should_payout, self.pfee, subtract_fee_from_amount=True
122122
)
123123
else:
124-
raise Exception(f"Unexpected Autopayout Reservation Policy : {crypto.wallet.prespolicy}")
124+
app.logger.info(f"Unexpected Autopayout Reservation Policy : {crypto.wallet.prespolicy}, possibly after upgrading, running without reservation")
125+
res = crypto.mkpayout(
126+
self.pdest, balance, self.pfee, subtract_fee_from_amount=True
127+
)
125128

126129
if "result" in res and res["result"]:
127130
idtxs = (

0 commit comments

Comments
 (0)