Extract more logic into order-has_fee
This commit is contained in:
parent
b125dd3728
commit
6d7a3a0cc9
@ -1164,14 +1164,18 @@ class FreqtradeBot:
|
|||||||
|
|
||||||
def _order_has_fee(self, order: Dict) -> bool:
|
def _order_has_fee(self, order: Dict) -> bool:
|
||||||
"""
|
"""
|
||||||
Verifies if the passed in order dict has the needed keys to extract fees
|
Verifies if the passed in order dict has the needed keys to extract fees,
|
||||||
|
and that these keys (currency, cost) are not empty.
|
||||||
:param order: Order or trade (one trade) dict
|
:param order: Order or trade (one trade) dict
|
||||||
:return: True if the fee substructure contains currency and cost, false otherwise
|
:return: True if the fee substructure contains currency and cost, false otherwise
|
||||||
"""
|
"""
|
||||||
if not isinstance(order, dict):
|
if not isinstance(order, dict):
|
||||||
return False
|
return False
|
||||||
return ('fee' in order and order['fee'] is not None and
|
return ('fee' in order and order['fee'] is not None
|
||||||
(order['fee'].keys() >= {'currency', 'cost'}))
|
and (order['fee'].keys() >= {'currency', 'cost'})
|
||||||
|
and order['fee']['currency'] is not None
|
||||||
|
and order['fee']['cost'] is not None
|
||||||
|
)
|
||||||
|
|
||||||
def get_real_amount(self, trade: Trade, order: Dict, order_amount: float = None) -> float:
|
def get_real_amount(self, trade: Trade, order: Dict, order_amount: float = None) -> float:
|
||||||
"""
|
"""
|
||||||
@ -1187,9 +1191,7 @@ class FreqtradeBot:
|
|||||||
trade_base_currency = self.exchange.get_pair_base_currency(trade.pair)
|
trade_base_currency = self.exchange.get_pair_base_currency(trade.pair)
|
||||||
# use fee from order-dict if possible
|
# use fee from order-dict if possible
|
||||||
if self._order_has_fee(order):
|
if self._order_has_fee(order):
|
||||||
if (order['fee']['currency'] is not None and
|
if trade_base_currency == order['fee']['currency']:
|
||||||
order['fee']['cost'] is not None and
|
|
||||||
trade_base_currency == order['fee']['currency']):
|
|
||||||
new_amount = order_amount - order['fee']['cost']
|
new_amount = order_amount - order['fee']['cost']
|
||||||
logger.info("Applying fee on amount for %s (from %s to %s) from Order",
|
logger.info("Applying fee on amount for %s (from %s to %s) from Order",
|
||||||
trade, order['amount'], new_amount)
|
trade, order['amount'], new_amount)
|
||||||
@ -1208,9 +1210,7 @@ class FreqtradeBot:
|
|||||||
amount += exectrade['amount']
|
amount += exectrade['amount']
|
||||||
if self._order_has_fee(exectrade):
|
if self._order_has_fee(exectrade):
|
||||||
# only applies if fee is in quote currency!
|
# only applies if fee is in quote currency!
|
||||||
if (exectrade['fee']['currency'] is not None and
|
if trade_base_currency == exectrade['fee']['currency']:
|
||||||
exectrade['fee']['cost'] is not None and
|
|
||||||
trade_base_currency == exectrade['fee']['currency']):
|
|
||||||
fee_abs += exectrade['fee']['cost']
|
fee_abs += exectrade['fee']['cost']
|
||||||
|
|
||||||
if not isclose(amount, order_amount, abs_tol=constants.MATH_CLOSE_PREC):
|
if not isclose(amount, order_amount, abs_tol=constants.MATH_CLOSE_PREC):
|
||||||
|
Loading…
Reference in New Issue
Block a user