|
|
|
def get_allowed(group, base, quote, direction):
|
|
|
|
"""
|
|
|
|
Determine whether the trade is allowed according to the group.
|
|
|
|
See tests for examples. The logic requires trading knowledge.
|
|
|
|
:param group: The group to check
|
|
|
|
:param base: The base currency
|
|
|
|
:param quote: The quote currency
|
|
|
|
:param direction: The direction of the trade
|
|
|
|
"""
|
|
|
|
|
|
|
|
allowed = group.allowed
|
|
|
|
if not isinstance(allowed, dict):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# If our base has allowed == False, we can only short it, or long the quote
|
|
|
|
if base in allowed:
|
|
|
|
if not allowed[base]:
|
|
|
|
if direction == "long":
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
if direction == "short":
|
|
|
|
return False
|
|
|
|
|
|
|
|
# If our quote has allowed == False, we can only long it, or short the base
|
|
|
|
if quote in allowed:
|
|
|
|
if not allowed[quote]:
|
|
|
|
if direction == "short":
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
if direction == "long":
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def check_asset_aggregation(value, trigger_above, trigger_below):
|
|
|
|
"""
|
|
|
|
Check if the value is within the bounds of the aggregation.
|
|
|
|
:param value: The value to check
|
|
|
|
:param trigger_above: Only trigger if the value is above this
|
|
|
|
:param trigger_below: Only trigger if the value is below this
|
|
|
|
"""
|
|
|
|
# If both are defined
|
|
|
|
if trigger_above is not None and trigger_below is not None:
|
|
|
|
if value > trigger_above and value < trigger_below:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
if trigger_below is not None:
|
|
|
|
if value < trigger_below:
|
|
|
|
# Value is less than lower bound, match
|
|
|
|
return True
|
|
|
|
if trigger_above is not None:
|
|
|
|
if value > trigger_above:
|
|
|
|
return True
|
|
|
|
return False
|