Support partially cancelled orders for fee calculation
This commit is contained in:
parent
737fc6d198
commit
021e2b58ca
@ -1095,7 +1095,8 @@ class Exchange:
|
|||||||
# Calculate fee based on order details
|
# Calculate fee based on order details
|
||||||
if fee_curr in self.get_pair_base_currency(order['symbol']):
|
if fee_curr in self.get_pair_base_currency(order['symbol']):
|
||||||
# Base currency - divide by amount
|
# Base currency - divide by amount
|
||||||
return round(order['fee']['cost'] / order['amount'], 8)
|
return round(
|
||||||
|
order['fee']['cost'] / safe_value_fallback(order, order, 'filled', 'amount'), 8)
|
||||||
elif fee_curr in self.get_pair_quote_currency(order['symbol']):
|
elif fee_curr in self.get_pair_quote_currency(order['symbol']):
|
||||||
# Quote currency - divide by cost
|
# Quote currency - divide by cost
|
||||||
return round(order['fee']['cost'] / order['cost'], 8)
|
return round(order['fee']['cost'] / order['cost'], 8)
|
||||||
|
@ -1144,8 +1144,6 @@ class FreqtradeBot:
|
|||||||
if not isclose(order['amount'], new_amount, abs_tol=constants.MATH_CLOSE_PREC):
|
if not isclose(order['amount'], new_amount, abs_tol=constants.MATH_CLOSE_PREC):
|
||||||
order['amount'] = new_amount
|
order['amount'] = new_amount
|
||||||
order.pop('filled', None)
|
order.pop('filled', None)
|
||||||
# Fee was applied, so set to 0
|
|
||||||
trade.fee_open = 0
|
|
||||||
trade.recalc_open_trade_price()
|
trade.recalc_open_trade_price()
|
||||||
except DependencyException as exception:
|
except DependencyException as exception:
|
||||||
logger.warning("Could not update trade amount: %s", exception)
|
logger.warning("Could not update trade amount: %s", exception)
|
||||||
|
@ -377,7 +377,7 @@ class Trade(_DECL_BASE):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def update_fee(self, fee_cost: float, fee_currency: Optional[str], fee_rate: Optional[float],
|
def update_fee(self, fee_cost: float, fee_currency: Optional[str], fee_rate: Optional[float],
|
||||||
side: str) -> None:
|
side) -> None:
|
||||||
"""
|
"""
|
||||||
Update Fee parameters. Only acts once per side
|
Update Fee parameters. Only acts once per side
|
||||||
"""
|
"""
|
||||||
|
@ -873,7 +873,7 @@ def limit_buy_order_old_partial():
|
|||||||
def limit_buy_order_old_partial_canceled(limit_buy_order_old_partial):
|
def limit_buy_order_old_partial_canceled(limit_buy_order_old_partial):
|
||||||
res = deepcopy(limit_buy_order_old_partial)
|
res = deepcopy(limit_buy_order_old_partial)
|
||||||
res['status'] = 'canceled'
|
res['status'] = 'canceled'
|
||||||
res['fee'] = {'cost': 0.0001, 'currency': 'ETH'}
|
res['fee'] = {'cost': 0.023, 'currency': 'ETH'}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
@ -2229,9 +2229,10 @@ def test_check_handle_timedout_partial_fee(default_conf, ticker, open_trade, cap
|
|||||||
assert len(trades) == 1
|
assert len(trades) == 1
|
||||||
# Verify that trade has been updated
|
# Verify that trade has been updated
|
||||||
assert trades[0].amount == (limit_buy_order_old_partial['amount'] -
|
assert trades[0].amount == (limit_buy_order_old_partial['amount'] -
|
||||||
limit_buy_order_old_partial['remaining']) - 0.0001
|
limit_buy_order_old_partial['remaining']) - 0.023
|
||||||
assert trades[0].open_order_id is None
|
assert trades[0].open_order_id is None
|
||||||
assert trades[0].fee_open == 0
|
assert trades[0].fee_updated('buy')
|
||||||
|
assert pytest.approx(trades[0].fee_open) == 0.001
|
||||||
|
|
||||||
|
|
||||||
def test_check_handle_timedout_partial_except(default_conf, ticker, open_trade, caplog, fee,
|
def test_check_handle_timedout_partial_except(default_conf, ticker, open_trade, caplog, fee,
|
||||||
|
Loading…
Reference in New Issue
Block a user