Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

For CJs: ignore makers with overlapping offer ranges #710

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions joinmarket/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def pick_order(orders, n):
def choose_orders(db, cj_amount, n, chooseOrdersBy, ignored_makers=None):
if ignored_makers is None:
ignored_makers = []
remove_invalid_makers_from_db(db)
sqlorders = db.execute(
'SELECT * FROM orderbook WHERE minsize <= :cja AND :cja <= maxsize;',
{'cja': cj_amount}).fetchall()
Expand Down Expand Up @@ -318,6 +319,7 @@ def choose_sweep_orders(db,

if ignored_makers is None:
ignored_makers = []
remove_invalid_makers_from_db(db)

def calc_zero_change_cj_amount(ordercombo):
sumabsfee = 0
Expand Down Expand Up @@ -381,6 +383,44 @@ def calc_zero_change_cj_amount(ordercombo):
return result, cj_amount, total_fee


def remove_invalid_makers_from_db(db):
# checks if the combination of offers from a makers is valid
# note that individual offers have already been checked
# for validity before they were entered into the DB
crows = db.execute(
'SELECT DISTINCT counterparty FROM orderbook WHERE oid > 1;').fetchall()

for row in crows:
nick = row["counterparty"]
if maker_offers_are_invalid(db, nick):
db.execute('DELETE FROM orderbook WHERE counterparty=?;', (nick,))
log.info('The following maker had malformed offers and was removed: ' + nick)


def maker_offers_are_invalid(db, makernick):
# checks for overlapping offer ranges

this_maker_offers = db.execute(
'SELECT minsize, maxsize FROM orderbook WHERE counterparty=?;', (makernick,)).fetchall()

cur_lowest_min = this_maker_offers[0]['minsize']
cur_highest_max = this_maker_offers[0]['maxsize']
cur_combined_range = 0

for offer in this_maker_offers:
if offer['minsize'] < cur_lowest_min:
cur_lowest_min = offer['minsize']
if offer['maxsize'] > cur_highest_max:
cur_highest_max = offer['maxsize']
cur_combined_range += offer['maxsize'] - offer['minsize']
if cur_combined_range > cur_highest_max - cur_lowest_min:
# there must be overlapping offer ranges
log.info('This maker has overlapping offer ranges: ' + makernick)
return True

return False


def debug_dump_object(obj, skip_fields=None):
if skip_fields is None:
skip_fields = []
Expand Down