From 802cd1517d7f7375f0bf2d3a78c643faf7908ecc Mon Sep 17 00:00:00 2001 From: Backup Cron Date: Wed, 22 Nov 2017 18:28:53 +0100 Subject: [PATCH] fixed bug that allowed to buy over limit --- src/investhor/scripts/invest_secondary.py | 7 +++++-- src/investhor/scripts/sell.py | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/investhor/scripts/invest_secondary.py b/src/investhor/scripts/invest_secondary.py index 2a953e1..af1e9bc 100755 --- a/src/investhor/scripts/invest_secondary.py +++ b/src/investhor/scripts/invest_secondary.py @@ -37,14 +37,17 @@ def buy_secondary(secondary_api, results, params): messages = [] min_gain = params.get("min_percentage_overhead", 6) max_investment_per_loan = params.get("max_investment_per_loan", 50) + user_invested_amounts = {} for res in results: target_discount = calculate_selling_discount(res) if target_discount - res.desired_discount_rate < min_gain: continue if res.next_payment_nr > 1: continue - user_invested_amount = get_investment_size_per_user(res.user_name) - if user_invested_amount >= max_investment_per_loan: + if res.user_name not in user_invested_amounts: + user_invested_amounts[res.user_name] = get_investment_size_per_user(res.user_name) + user_invested_amounts[res.user_name] += res.amount + if user_invested_amounts[res.user_name] >= max_investment_per_loan: continue to_buy.append(res) if to_buy: diff --git a/src/investhor/scripts/sell.py b/src/investhor/scripts/sell.py index ecbeee1..e6ff019 100755 --- a/src/investhor/scripts/sell.py +++ b/src/investhor/scripts/sell.py @@ -28,6 +28,9 @@ def sell_items(secondary_api, results, on_sale, discount): for res in results.payload: is_on_sale = False rate = calculate_selling_discount(res, discount=discount) + if rate is None: + logger.warning("RATE IS NULL WITH res=%s and discount=%d", res, discount) + continue for sale in on_sale.payload: if sale.loan_part_id == res.loan_part_id: is_on_sale = True