Skip to content

Commit

Permalink
fixed bug that allowed to buy over limit
Browse files Browse the repository at this point in the history
  • Loading branch information
parruc committed Nov 22, 2017
1 parent 6949801 commit 802cd15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/investhor/scripts/invest_secondary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/investhor/scripts/sell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 802cd15

Please # to comment.