Amend asset filter matching to be more explicit
This commit is contained in:
@@ -13,44 +13,66 @@ def get_allowed(group, base, quote, side):
|
||||
|
||||
# If our base has allowed == False, we can only short it, or long the quote
|
||||
base_rule = AssetRule.objects.filter(group=group, asset=base).first()
|
||||
if base_rule:
|
||||
mapped_status = update_status_from_mappings(base_rule.status, group)
|
||||
if mapped_status == 6:
|
||||
# Always allow
|
||||
return True
|
||||
elif mapped_status == 7:
|
||||
# Always deny
|
||||
return False
|
||||
elif mapped_status == 3:
|
||||
if side == "long":
|
||||
return False
|
||||
elif mapped_status == 2:
|
||||
if side == "short":
|
||||
return False
|
||||
# If our quote has allowed == False, we can only long it, or short the base
|
||||
quote_rule = AssetRule.objects.filter(group=group, asset=quote).first()
|
||||
if quote_rule:
|
||||
mapped_status = update_status_from_mappings(quote_rule.status, group)
|
||||
if mapped_status == 6:
|
||||
# Always allow
|
||||
return True
|
||||
elif mapped_status == 7:
|
||||
# Always deny
|
||||
return False
|
||||
elif mapped_status == 3:
|
||||
if side == "short":
|
||||
return False
|
||||
elif mapped_status == 2:
|
||||
if side == "long":
|
||||
return False
|
||||
|
||||
if not base_rule and not quote_rule:
|
||||
if all([x is None for x in [base_rule, quote_rule]]):
|
||||
# Neither side has data, we can't check any group statuses
|
||||
if group.when_no_data == 7:
|
||||
# Always deny
|
||||
return False
|
||||
elif group.when_no_data == 6:
|
||||
# Always allow
|
||||
return True
|
||||
|
||||
# Translate statuses, depending on the group's definitions
|
||||
if base_rule:
|
||||
base_mapped_status = update_status_from_mappings(base_rule.status, group)
|
||||
if quote_rule:
|
||||
quote_mapped_status = update_status_from_mappings(quote_rule.status, group)
|
||||
|
||||
# Check for deny first
|
||||
if base_rule:
|
||||
if base_mapped_status == 7:
|
||||
# Always deny
|
||||
return False
|
||||
elif base_mapped_status == 3:
|
||||
if side == "long":
|
||||
return False
|
||||
elif base_mapped_status == 2:
|
||||
if side == "short":
|
||||
return False
|
||||
|
||||
if quote_rule:
|
||||
if quote_mapped_status == 7:
|
||||
# Always deny
|
||||
return False
|
||||
elif quote_mapped_status == 3:
|
||||
if side == "short":
|
||||
return False
|
||||
elif quote_mapped_status == 2:
|
||||
if side == "long":
|
||||
return False
|
||||
|
||||
# Only one side does not have data
|
||||
if any([x is None for x in [base_rule, quote_rule]]):
|
||||
if group.when_no_data == 7:
|
||||
# Always deny
|
||||
return False
|
||||
elif group.when_no_data == 6:
|
||||
# Always allow
|
||||
return True
|
||||
|
||||
# Check for explicit allow
|
||||
if base_rule:
|
||||
if base_mapped_status == 6:
|
||||
# Always allow
|
||||
return True
|
||||
|
||||
if quote_rule:
|
||||
if quote_mapped_status == 6:
|
||||
# Always allow
|
||||
return True
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user