Added is_short and leverage to __repr__

This commit is contained in:
Sam Germain 2021-07-26 22:41:45 -06:00
parent 4fcae0d927
commit 10d214ccad
3 changed files with 65 additions and 21 deletions

View File

@ -357,9 +357,14 @@ class LocalTrade():
def __repr__(self):
open_since = self.open_date.strftime(DATETIME_PRINT_FORMAT) if self.is_open else 'closed'
leverage = self.leverage or 1.0
is_short = self.is_short or False
return (f'Trade(id={self.id}, pair={self.pair}, amount={self.amount:.8f}, '
f'open_rate={self.open_rate:.8f}, open_since={open_since})')
return (
f'Trade(id={self.id}, pair={self.pair}, amount={self.amount:.8f}, '
f'is_short={is_short}, leverage={leverage}, '
f'open_rate={self.open_rate:.8f}, open_since={open_since})'
)
def to_json(self) -> Dict[str, Any]:
return {

View File

@ -2401,6 +2401,7 @@ def test_check_handle_timedout_exception(default_conf, ticker, open_trade, mocke
freqtrade.check_handle_timedout()
assert log_has_re(r"Cannot query order for Trade\(id=1, pair=ETH/BTC, amount=90.99181073, "
r"is_short=False, leverage=1.0, "
r"open_rate=0.00001099, open_since="
f"{open_trade.open_date.strftime('%Y-%m-%d %H:%M:%S')}"
r"\) due to Traceback \(most recent call last\):\n*",
@ -3549,9 +3550,11 @@ def test_get_real_amount_quote(default_conf, trades_for_order, buy_order_fee, fe
# Amount is reduced by "fee"
assert freqtrade.get_real_amount(trade, buy_order_fee) == amount - (amount * 0.001)
assert log_has('Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, '
'open_rate=0.24544100, open_since=closed) (from 8.0 to 7.992).',
caplog)
assert log_has(
'Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, is_short=False,'
' leverage=1.0, open_rate=0.24544100, open_since=closed) (from 8.0 to 7.992).',
caplog
)
def test_get_real_amount_quote_dust(default_conf, trades_for_order, buy_order_fee, fee,
@ -3596,9 +3599,12 @@ def test_get_real_amount_no_trade(default_conf, buy_order_fee, caplog, mocker, f
# Amount is reduced by "fee"
assert freqtrade.get_real_amount(trade, buy_order_fee) == amount
assert log_has('Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, '
'open_rate=0.24544100, open_since=closed) failed: myTrade-Dict empty found',
caplog)
assert log_has(
'Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, '
'is_short=False, leverage=1.0, open_rate=0.24544100, open_since=closed) failed: '
'myTrade-Dict empty found',
caplog
)
def test_get_real_amount_stake(default_conf, trades_for_order, buy_order_fee, fee, mocker):
@ -3682,9 +3688,11 @@ def test_get_real_amount_multi(default_conf, trades_for_order2, buy_order_fee, c
# Amount is reduced by "fee"
assert freqtrade.get_real_amount(trade, buy_order_fee) == amount - (amount * 0.001)
assert log_has('Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, '
'open_rate=0.24544100, open_since=closed) (from 8.0 to 7.992).',
caplog)
assert log_has(
'Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, is_short=False,'
' leverage=1.0, open_rate=0.24544100, open_since=closed) (from 8.0 to 7.992).',
caplog
)
assert trade.fee_open == 0.001
assert trade.fee_close == 0.001
@ -3718,9 +3726,11 @@ def test_get_real_amount_multi2(default_conf, trades_for_order3, buy_order_fee,
# Amount is reduced by "fee"
assert freqtrade.get_real_amount(trade, buy_order_fee) == amount - (amount * 0.0005)
assert log_has('Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, '
'open_rate=0.24544100, open_since=closed) (from 8.0 to 7.996).',
caplog)
assert log_has(
'Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, is_short=False,'
' leverage=1.0, open_rate=0.24544100, open_since=closed) (from 8.0 to 7.996).',
caplog
)
# Overall fee is average of both trade's fee
assert trade.fee_open == 0.001518575
assert trade.fee_open_cost is not None
@ -3752,9 +3762,11 @@ def test_get_real_amount_fromorder(default_conf, trades_for_order, buy_order_fee
# Amount is reduced by "fee"
assert freqtrade.get_real_amount(trade, limit_buy_order) == amount - 0.004
assert log_has('Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, '
'open_rate=0.24544100, open_since=closed) (from 8.0 to 7.996).',
caplog)
assert log_has(
'Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, is_short=False,'
' leverage=1.0, open_rate=0.24544100, open_since=closed) (from 8.0 to 7.996).',
caplog
)
def test_get_real_amount_invalid_order(default_conf, trades_for_order, buy_order_fee, fee, mocker):

View File

@ -520,7 +520,8 @@ def test_update_limit_order(limit_buy_order_usdt, limit_sell_order_usdt, fee, ca
assert trade.close_profit is None
assert trade.close_date is None
assert log_has_re(r"LIMIT_BUY has been fulfilled for Trade\(id=2, "
r"pair=ETH/BTC, amount=30.00000000, open_rate=2.00000000, open_since=.*\).",
r'pair=ETH/BTC, amount=30.00000000, '
r"is_short=False, leverage=1.0, open_rate=2.00000000, open_since=.*\).",
caplog)
caplog.clear()
@ -531,7 +532,31 @@ def test_update_limit_order(limit_buy_order_usdt, limit_sell_order_usdt, fee, ca
assert trade.close_profit == round(0.0945137157107232, 8)
assert trade.close_date is not None
assert log_has_re(r"LIMIT_SELL has been fulfilled for Trade\(id=2, "
r"pair=ETH/BTC, amount=30.00000000, open_rate=2.00000000, open_since=.*\).",
r"pair=ETH/BTC, amount=30.00000000, "
r"is_short=False, leverage=1.0, open_rate=2.00000000, open_since=.*\).",
caplog)
caplog.clear()
trade = Trade(
id=226531,
pair='ETH/BTC',
stake_amount=60.0,
open_rate=2.0,
amount=30.0,
is_open=True,
open_date=arrow.utcnow().datetime,
fee_open=fee.return_value,
fee_close=fee.return_value,
exchange='binance',
is_short=True,
leverage=3.0,
interest_rate=0.0005,
interest_mode=InterestMode.HOURSPERDAY
)
trade.update(limit_buy_order_usdt)
assert log_has_re(r"LIMIT_BUY has been fulfilled for Trade\(id=226531, "
r"pair=ETH/BTC, amount=30.00000000, "
r"is_short=True, leverage=3.0, open_rate=2.00000000, open_since=.*\).",
caplog)
@ -557,7 +582,8 @@ def test_update_market_order(market_buy_order_usdt, market_sell_order_usdt, fee,
assert trade.close_profit is None
assert trade.close_date is None
assert log_has_re(r"MARKET_BUY has been fulfilled for Trade\(id=1, "
r"pair=ETH/BTC, amount=30.00000000, open_rate=2.00000000, open_since=.*\).",
r"pair=ETH/BTC, amount=30.00000000, is_short=False, leverage=1.0, "
r"open_rate=2.00000000, open_since=.*\).",
caplog)
caplog.clear()
@ -569,7 +595,8 @@ def test_update_market_order(market_buy_order_usdt, market_sell_order_usdt, fee,
assert trade.close_profit == round(0.0945137157107232, 8)
assert trade.close_date is not None
assert log_has_re(r"MARKET_SELL has been fulfilled for Trade\(id=1, "
r"pair=ETH/BTC, amount=30.00000000, open_rate=2.00000000, open_since=.*\).",
r"pair=ETH/BTC, amount=30.00000000, is_short=False, leverage=1.0, "
r"open_rate=2.00000000, open_since=.*\).",
caplog)