Switched migrations.py check for stake_currency back to open_rate, because stake_currency is no longer a variable

This commit is contained in:
Sam Germain 2021-07-04 23:51:58 -06:00
parent 5fc587c225
commit be3a9390fe
4 changed files with 27 additions and 30 deletions

View File

@ -171,9 +171,8 @@ def check_migrate(engine, decl_base, previous_tables) -> None:
tabs = get_table_names_for_table(inspector, 'trades')
table_back_name = get_backup_name(tabs, 'trades_bak')
# Last added column of trades table
# To determine if migrations need to run
if not has_column(cols, 'collateral_currency'):
# Check for latest column
if not has_column(cols, 'open_trade_value'):
logger.info(f'Running database migration for trades - backup: {table_back_name}')
migrate_trades_table(decl_base, inspector, engine, table_back_name, cols)
# Reread columns - the above recreated the table!

View File

@ -436,33 +436,33 @@ def leverage_trade(fee):
leverage: 5
time-periods: 5 hrs( 5/4 time-period of 4 hours)
interest: borrowed * interest_rate * time-periods
= 60.516 * 0.0005 * 1/24 = 0.0378225 base
open_value: (amount * open_rate) - (amount * open_rate * fee)
= (615.0 * 0.123) - (615.0 * 0.123 * 0.0025)
= 75.4558875
= 60.516 * 0.0005 * 5/4 = 0.0378225 base
open_value: (amount * open_rate) + (amount * open_rate * fee)
= (615.0 * 0.123) + (615.0 * 0.123 * 0.0025)
= 75.83411249999999
close_value: (amount_closed * close_rate) + (amount_closed * close_rate * fee)
= (615.0 * 0.128) + (615.0 * 0.128 * 0.0025)
= 78.9168
total_profit = close_value - open_value - interest
= 78.9168 - 75.4558875 - 0.0378225
= 3.423089999999992
close_value: (amount_closed * close_rate) - (amount_closed * close_rate * fee) - interest
= (615.0 * 0.128) - (615.0 * 0.128 * 0.0025) - 0.0378225
= 78.4853775
total_profit = close_value - open_value
= 78.4853775 - 75.83411249999999
= 2.6512650000000093
total_profit_percentage = total_profit / stake_amount
= 3.423089999999992 / 15.129
= 0.22626016260162551
= 2.6512650000000093 / 15.129
= 0.17524390243902502
"""
trade = Trade(
pair='ETC/BTC',
stake_amount=15.129,
amount=123.0,
leverage=5,
amount_requested=123.0,
amount=615.0,
leverage=5.0,
amount_requested=615.0,
fee_open=fee.return_value,
fee_close=fee.return_value,
open_rate=0.123,
close_rate=0.128,
close_profit=0.22626016260162551,
close_profit_abs=3.423089999999992,
close_profit=0.17524390243902502,
close_profit_abs=2.6512650000000093,
exchange='kraken',
is_open=False,
open_order_id='dry_run_leverage_sell_12345',
@ -471,7 +471,7 @@ def leverage_trade(fee):
sell_reason='sell_signal', # TODO-mg: Update to exit/close reason
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=300),
close_date=datetime.now(tz=timezone.utc),
# borrowed=
interest_rate=0.0005
)
o = Order.parse_from_ccxt_object(leverage_order(), 'ETC/BTC', 'sell')
trade.orders.append(o)

View File

@ -956,7 +956,6 @@ def test_to_json(default_conf, fee):
'strategy': None,
'timeframe': None,
'exchange': 'binance',
'leverage': None,
'interest_rate': None,
'liquidation_price': None,
@ -1026,7 +1025,6 @@ def test_to_json(default_conf, fee):
'strategy': None,
'timeframe': None,
'exchange': 'binance',
'leverage': None,
'interest_rate': None,
'liquidation_price': None,

View File

@ -495,9 +495,9 @@ def test_update_market_order(
assert trade.interest_rate == 0.0005
# TODO: Uncomment the next assert and make it work.
# The logger also has the exact same but there's some spacing in there
# assert log_has_re(r"MARKET_SELL has been fulfilled for Trade\(id=1, "
# r"pair=ETH/BTC, amount=275.97543219, open_rate=0.00004173, open_since=.*\).",
# caplog)
assert log_has_re(r"MARKET_SELL has been fulfilled for Trade\(id=1, "
r"pair=ETH/BTC, amount=275.97543219, open_rate=0.00004173, open_since=.*\).",
caplog)
caplog.clear()
trade.is_open = True
trade.open_order_id = 'something'
@ -509,9 +509,9 @@ def test_update_market_order(
# TODO: The amount should maybe be the opening amount + the interest
# TODO: Uncomment the next assert and make it work.
# The logger also has the exact same but there's some spacing in there
# assert log_has_re(r"MARKET_SELL has been fulfilled for Trade\(id=1, "
# r"pair=ETH/BTC, amount=275.97543219, open_rate=0.00004099, open_since=.*\).",
# caplog)
assert log_has_re(r"MARKET_SELL has been fulfilled for Trade\(id=1, "
r"pair=ETH/BTC, amount=275.97543219, open_rate=0.00004099, open_since=.*\).",
caplog)
@ pytest.mark.usefixtures("init_persistence")
@ -746,4 +746,4 @@ def test_get_best_pair(fee):
res = Trade.get_best_pair()
assert len(res) == 2
assert res[0] == 'ETC/BTC'
assert res[1] == 0.22626016260162551
assert res[1] == 0.17524390243902502