Rename open_trade_price to "open_trade_value"

This commit is contained in:
Matthias 2020-12-10 19:21:20 +01:00
parent d9a86158f4
commit 201cc67e05
5 changed files with 30 additions and 30 deletions

View File

@ -1396,7 +1396,7 @@ class FreqtradeBot:
abs_tol=constants.MATH_CLOSE_PREC): abs_tol=constants.MATH_CLOSE_PREC):
order['amount'] = new_amount order['amount'] = new_amount
order.pop('filled', None) order.pop('filled', None)
trade.recalc_open_trade_price() trade.recalc_open_trade_value()
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)

View File

@ -217,7 +217,7 @@ class Trade(_DECL_BASE):
fee_close_currency = Column(String, nullable=True) fee_close_currency = Column(String, nullable=True)
open_rate = Column(Float) open_rate = Column(Float)
open_rate_requested = Column(Float) open_rate_requested = Column(Float)
# open_trade_price - calculated via _calc_open_trade_price # open_trade_price - calculated via _calc_open_trade_value
open_trade_price = Column(Float) open_trade_price = Column(Float)
close_rate = Column(Float) close_rate = Column(Float)
close_rate_requested = Column(Float) close_rate_requested = Column(Float)
@ -252,7 +252,7 @@ class Trade(_DECL_BASE):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.recalc_open_trade_price() self.recalc_open_trade_value()
def __repr__(self): def __repr__(self):
open_since = self.open_date.strftime(DATETIME_PRINT_FORMAT) if self.is_open else 'closed' open_since = self.open_date.strftime(DATETIME_PRINT_FORMAT) if self.is_open else 'closed'
@ -284,7 +284,7 @@ class Trade(_DECL_BASE):
'open_timestamp': int(self.open_date.replace(tzinfo=timezone.utc).timestamp() * 1000), 'open_timestamp': int(self.open_date.replace(tzinfo=timezone.utc).timestamp() * 1000),
'open_rate': self.open_rate, 'open_rate': self.open_rate,
'open_rate_requested': self.open_rate_requested, 'open_rate_requested': self.open_rate_requested,
'open_trade_price': round(self.open_trade_price, 8), 'open_trade_value': round(self.open_trade_price, 8),
'close_date_hum': (arrow.get(self.close_date).humanize() 'close_date_hum': (arrow.get(self.close_date).humanize()
if self.close_date else None), if self.close_date else None),
@ -389,7 +389,7 @@ class Trade(_DECL_BASE):
# Update open rate and actual amount # Update open rate and actual amount
self.open_rate = Decimal(safe_value_fallback(order, 'average', 'price')) self.open_rate = Decimal(safe_value_fallback(order, 'average', 'price'))
self.amount = Decimal(safe_value_fallback(order, 'filled', 'amount')) self.amount = Decimal(safe_value_fallback(order, 'filled', 'amount'))
self.recalc_open_trade_price() self.recalc_open_trade_value()
if self.is_open: if self.is_open:
logger.info(f'{order_type.upper()}_BUY has been fulfilled for {self}.') logger.info(f'{order_type.upper()}_BUY has been fulfilled for {self}.')
self.open_order_id = None self.open_order_id = None
@ -464,7 +464,7 @@ class Trade(_DECL_BASE):
Trade.session.delete(self) Trade.session.delete(self)
Trade.session.flush() Trade.session.flush()
def _calc_open_trade_price(self) -> float: def _calc_open_trade_value(self) -> float:
""" """
Calculate the open_rate including open_fee. Calculate the open_rate including open_fee.
:return: Price in of the open trade incl. Fees :return: Price in of the open trade incl. Fees
@ -473,14 +473,14 @@ class Trade(_DECL_BASE):
fees = buy_trade * Decimal(self.fee_open) fees = buy_trade * Decimal(self.fee_open)
return float(buy_trade + fees) return float(buy_trade + fees)
def recalc_open_trade_price(self) -> None: def recalc_open_trade_value(self) -> None:
""" """
Recalculate open_trade_price. Recalculate open_trade_value.
Must be called whenever open_rate or fee_open is changed. Must be called whenever open_rate or fee_open is changed.
""" """
self.open_trade_price = self._calc_open_trade_price() self.open_trade_price = self._calc_open_trade_value()
def calc_close_trade_price(self, rate: Optional[float] = None, def calc_close_trade_value(self, rate: Optional[float] = None,
fee: Optional[float] = None) -> float: fee: Optional[float] = None) -> float:
""" """
Calculate the close_rate including fee Calculate the close_rate including fee
@ -507,7 +507,7 @@ class Trade(_DECL_BASE):
If rate is not set self.close_rate will be used If rate is not set self.close_rate will be used
:return: profit in stake currency as float :return: profit in stake currency as float
""" """
close_trade_price = self.calc_close_trade_price( close_trade_price = self.calc_close_trade_value(
rate=(rate or self.close_rate), rate=(rate or self.close_rate),
fee=(fee or self.fee_close) fee=(fee or self.fee_close)
) )
@ -523,7 +523,7 @@ class Trade(_DECL_BASE):
:param fee: fee to use on the close rate (optional). :param fee: fee to use on the close rate (optional).
:return: profit ratio as float :return: profit ratio as float
""" """
close_trade_price = self.calc_close_trade_price( close_trade_price = self.calc_close_trade_value(
rate=(rate or self.close_rate), rate=(rate or self.close_rate),
fee=(fee or self.fee_close) fee=(fee or self.fee_close)
) )

View File

@ -62,7 +62,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'fee_close_cost': ANY, 'fee_close_cost': ANY,
'fee_close_currency': ANY, 'fee_close_currency': ANY,
'open_rate_requested': ANY, 'open_rate_requested': ANY,
'open_trade_price': 0.0010025, 'open_trade_value': 0.0010025,
'close_rate_requested': ANY, 'close_rate_requested': ANY,
'sell_reason': ANY, 'sell_reason': ANY,
'sell_order_status': ANY, 'sell_order_status': ANY,
@ -127,7 +127,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'fee_close_cost': ANY, 'fee_close_cost': ANY,
'fee_close_currency': ANY, 'fee_close_currency': ANY,
'open_rate_requested': ANY, 'open_rate_requested': ANY,
'open_trade_price': ANY, 'open_trade_value': ANY,
'close_rate_requested': ANY, 'close_rate_requested': ANY,
'sell_reason': ANY, 'sell_reason': ANY,
'sell_order_status': ANY, 'sell_order_status': ANY,

View File

@ -678,7 +678,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
'min_rate': 1.098e-05, 'min_rate': 1.098e-05,
'open_order_id': None, 'open_order_id': None,
'open_rate_requested': 1.098e-05, 'open_rate_requested': 1.098e-05,
'open_trade_price': 0.0010025, 'open_trade_value': 0.0010025,
'sell_reason': None, 'sell_reason': None,
'sell_order_status': None, 'sell_order_status': None,
'strategy': 'DefaultStrategy', 'strategy': 'DefaultStrategy',
@ -805,7 +805,7 @@ def test_api_forcebuy(botclient, mocker, fee):
'min_rate': None, 'min_rate': None,
'open_order_id': '123456', 'open_order_id': '123456',
'open_rate_requested': None, 'open_rate_requested': None,
'open_trade_price': 0.24605460, 'open_trade_value': 0.24605460,
'sell_reason': None, 'sell_reason': None,
'sell_order_status': None, 'sell_order_status': None,
'strategy': None, 'strategy': None,

View File

@ -177,10 +177,10 @@ def test_calc_open_close_trade_price(limit_buy_order, limit_sell_order, fee):
trade.open_order_id = 'something' trade.open_order_id = 'something'
trade.update(limit_buy_order) trade.update(limit_buy_order)
assert trade._calc_open_trade_price() == 0.0010024999999225068 assert trade._calc_open_trade_value() == 0.0010024999999225068
trade.update(limit_sell_order) trade.update(limit_sell_order)
assert trade.calc_close_trade_price() == 0.0010646656050132426 assert trade.calc_close_trade_value() == 0.0010646656050132426
# Profit in BTC # Profit in BTC
assert trade.calc_profit() == 0.00006217 assert trade.calc_profit() == 0.00006217
@ -233,7 +233,7 @@ def test_calc_close_trade_price_exception(limit_buy_order, fee):
trade.open_order_id = 'something' trade.open_order_id = 'something'
trade.update(limit_buy_order) trade.update(limit_buy_order)
assert trade.calc_close_trade_price() == 0.0 assert trade.calc_close_trade_value() == 0.0
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
@ -277,7 +277,7 @@ def test_update_invalid_order(limit_buy_order):
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
def test_calc_open_trade_price(limit_buy_order, fee): def test_calc_open_trade_value(limit_buy_order, fee):
trade = Trade( trade = Trade(
pair='ETH/BTC', pair='ETH/BTC',
stake_amount=0.001, stake_amount=0.001,
@ -291,10 +291,10 @@ def test_calc_open_trade_price(limit_buy_order, fee):
trade.update(limit_buy_order) # Buy @ 0.00001099 trade.update(limit_buy_order) # Buy @ 0.00001099
# Get the open rate price with the standard fee rate # Get the open rate price with the standard fee rate
assert trade._calc_open_trade_price() == 0.0010024999999225068 assert trade._calc_open_trade_value() == 0.0010024999999225068
trade.fee_open = 0.003 trade.fee_open = 0.003
# Get the open rate price with a custom fee rate # Get the open rate price with a custom fee rate
assert trade._calc_open_trade_price() == 0.001002999999922468 assert trade._calc_open_trade_value() == 0.001002999999922468
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
@ -312,14 +312,14 @@ def test_calc_close_trade_price(limit_buy_order, limit_sell_order, fee):
trade.update(limit_buy_order) # Buy @ 0.00001099 trade.update(limit_buy_order) # Buy @ 0.00001099
# Get the close rate price with a custom close rate and a regular fee rate # Get the close rate price with a custom close rate and a regular fee rate
assert trade.calc_close_trade_price(rate=0.00001234) == 0.0011200318470471794 assert trade.calc_close_trade_value(rate=0.00001234) == 0.0011200318470471794
# Get the close rate price with a custom close rate and a custom fee rate # Get the close rate price with a custom close rate and a custom fee rate
assert trade.calc_close_trade_price(rate=0.00001234, fee=0.003) == 0.0011194704275749754 assert trade.calc_close_trade_value(rate=0.00001234, fee=0.003) == 0.0011194704275749754
# Test when we apply a Sell order, and ask price with a custom fee rate # Test when we apply a Sell order, and ask price with a custom fee rate
trade.update(limit_sell_order) trade.update(limit_sell_order)
assert trade.calc_close_trade_price(fee=0.005) == 0.0010619972701635854 assert trade.calc_close_trade_value(fee=0.005) == 0.0010619972701635854
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
@ -499,7 +499,7 @@ def test_migrate_old(mocker, default_conf, fee):
assert trade.max_rate == 0.0 assert trade.max_rate == 0.0
assert trade.stop_loss == 0.0 assert trade.stop_loss == 0.0
assert trade.initial_stop_loss == 0.0 assert trade.initial_stop_loss == 0.0
assert trade.open_trade_price == trade._calc_open_trade_price() assert trade.open_trade_price == trade._calc_open_trade_value()
assert trade.close_profit_abs is None assert trade.close_profit_abs is None
assert trade.fee_open_cost is None assert trade.fee_open_cost is None
assert trade.fee_open_currency is None assert trade.fee_open_currency is None
@ -607,7 +607,7 @@ def test_migrate_new(mocker, default_conf, fee, caplog):
assert log_has("trying trades_bak1", caplog) assert log_has("trying trades_bak1", caplog)
assert log_has("trying trades_bak2", caplog) assert log_has("trying trades_bak2", caplog)
assert log_has("Running database migration for trades - backup: trades_bak2", caplog) assert log_has("Running database migration for trades - backup: trades_bak2", caplog)
assert trade.open_trade_price == trade._calc_open_trade_price() assert trade.open_trade_price == trade._calc_open_trade_value()
assert trade.close_profit_abs is None assert trade.close_profit_abs is None
assert log_has("Moving open orders to Orders table.", caplog) assert log_has("Moving open orders to Orders table.", caplog)
@ -677,7 +677,7 @@ def test_migrate_mid_state(mocker, default_conf, fee, caplog):
assert trade.max_rate == 0.0 assert trade.max_rate == 0.0
assert trade.stop_loss == 0.0 assert trade.stop_loss == 0.0
assert trade.initial_stop_loss == 0.0 assert trade.initial_stop_loss == 0.0
assert trade.open_trade_price == trade._calc_open_trade_price() assert trade.open_trade_price == trade._calc_open_trade_value()
assert log_has("trying trades_bak0", caplog) assert log_has("trying trades_bak0", caplog)
assert log_has("Running database migration for trades - backup: trades_bak0", caplog) assert log_has("Running database migration for trades - backup: trades_bak0", caplog)
@ -803,7 +803,7 @@ def test_to_json(default_conf, fee):
'close_timestamp': None, 'close_timestamp': None,
'open_rate': 0.123, 'open_rate': 0.123,
'open_rate_requested': None, 'open_rate_requested': None,
'open_trade_price': 15.1668225, 'open_trade_value': 15.1668225,
'fee_close': 0.0025, 'fee_close': 0.0025,
'fee_close_cost': None, 'fee_close_cost': None,
'fee_close_currency': None, 'fee_close_currency': None,
@ -896,7 +896,7 @@ def test_to_json(default_conf, fee):
'min_rate': None, 'min_rate': None,
'open_order_id': None, 'open_order_id': None,
'open_rate_requested': None, 'open_rate_requested': None,
'open_trade_price': 12.33075, 'open_trade_value': 12.33075,
'sell_reason': None, 'sell_reason': None,
'sell_order_status': None, 'sell_order_status': None,
'strategy': None, 'strategy': None,