Switched migrations.py check for stake_currency back to open_rate, because stake_currency is no longer a variable
This commit is contained in:
parent
5fc587c225
commit
be3a9390fe
@ -171,9 +171,8 @@ def check_migrate(engine, decl_base, previous_tables) -> None:
|
|||||||
tabs = get_table_names_for_table(inspector, 'trades')
|
tabs = get_table_names_for_table(inspector, 'trades')
|
||||||
table_back_name = get_backup_name(tabs, 'trades_bak')
|
table_back_name = get_backup_name(tabs, 'trades_bak')
|
||||||
|
|
||||||
# Last added column of trades table
|
# Check for latest column
|
||||||
# To determine if migrations need to run
|
if not has_column(cols, 'open_trade_value'):
|
||||||
if not has_column(cols, 'collateral_currency'):
|
|
||||||
logger.info(f'Running database migration for trades - backup: {table_back_name}')
|
logger.info(f'Running database migration for trades - backup: {table_back_name}')
|
||||||
migrate_trades_table(decl_base, inspector, engine, table_back_name, cols)
|
migrate_trades_table(decl_base, inspector, engine, table_back_name, cols)
|
||||||
# Reread columns - the above recreated the table!
|
# Reread columns - the above recreated the table!
|
||||||
|
@ -436,33 +436,33 @@ def leverage_trade(fee):
|
|||||||
leverage: 5
|
leverage: 5
|
||||||
time-periods: 5 hrs( 5/4 time-period of 4 hours)
|
time-periods: 5 hrs( 5/4 time-period of 4 hours)
|
||||||
interest: borrowed * interest_rate * time-periods
|
interest: borrowed * interest_rate * time-periods
|
||||||
= 60.516 * 0.0005 * 1/24 = 0.0378225 base
|
= 60.516 * 0.0005 * 5/4 = 0.0378225 base
|
||||||
open_value: (amount * open_rate) - (amount * open_rate * fee)
|
open_value: (amount * open_rate) + (amount * open_rate * fee)
|
||||||
= (615.0 * 0.123) - (615.0 * 0.123 * 0.0025)
|
= (615.0 * 0.123) + (615.0 * 0.123 * 0.0025)
|
||||||
= 75.4558875
|
= 75.83411249999999
|
||||||
|
|
||||||
close_value: (amount_closed * close_rate) + (amount_closed * close_rate * fee)
|
close_value: (amount_closed * close_rate) - (amount_closed * close_rate * fee) - interest
|
||||||
= (615.0 * 0.128) + (615.0 * 0.128 * 0.0025)
|
= (615.0 * 0.128) - (615.0 * 0.128 * 0.0025) - 0.0378225
|
||||||
= 78.9168
|
= 78.4853775
|
||||||
total_profit = close_value - open_value - interest
|
total_profit = close_value - open_value
|
||||||
= 78.9168 - 75.4558875 - 0.0378225
|
= 78.4853775 - 75.83411249999999
|
||||||
= 3.423089999999992
|
= 2.6512650000000093
|
||||||
total_profit_percentage = total_profit / stake_amount
|
total_profit_percentage = total_profit / stake_amount
|
||||||
= 3.423089999999992 / 15.129
|
= 2.6512650000000093 / 15.129
|
||||||
= 0.22626016260162551
|
= 0.17524390243902502
|
||||||
"""
|
"""
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='ETC/BTC',
|
pair='ETC/BTC',
|
||||||
stake_amount=15.129,
|
stake_amount=15.129,
|
||||||
amount=123.0,
|
amount=615.0,
|
||||||
leverage=5,
|
leverage=5.0,
|
||||||
amount_requested=123.0,
|
amount_requested=615.0,
|
||||||
fee_open=fee.return_value,
|
fee_open=fee.return_value,
|
||||||
fee_close=fee.return_value,
|
fee_close=fee.return_value,
|
||||||
open_rate=0.123,
|
open_rate=0.123,
|
||||||
close_rate=0.128,
|
close_rate=0.128,
|
||||||
close_profit=0.22626016260162551,
|
close_profit=0.17524390243902502,
|
||||||
close_profit_abs=3.423089999999992,
|
close_profit_abs=2.6512650000000093,
|
||||||
exchange='kraken',
|
exchange='kraken',
|
||||||
is_open=False,
|
is_open=False,
|
||||||
open_order_id='dry_run_leverage_sell_12345',
|
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
|
sell_reason='sell_signal', # TODO-mg: Update to exit/close reason
|
||||||
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=300),
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=300),
|
||||||
close_date=datetime.now(tz=timezone.utc),
|
close_date=datetime.now(tz=timezone.utc),
|
||||||
# borrowed=
|
interest_rate=0.0005
|
||||||
)
|
)
|
||||||
o = Order.parse_from_ccxt_object(leverage_order(), 'ETC/BTC', 'sell')
|
o = Order.parse_from_ccxt_object(leverage_order(), 'ETC/BTC', 'sell')
|
||||||
trade.orders.append(o)
|
trade.orders.append(o)
|
||||||
|
@ -956,7 +956,6 @@ def test_to_json(default_conf, fee):
|
|||||||
'strategy': None,
|
'strategy': None,
|
||||||
'timeframe': None,
|
'timeframe': None,
|
||||||
'exchange': 'binance',
|
'exchange': 'binance',
|
||||||
|
|
||||||
'leverage': None,
|
'leverage': None,
|
||||||
'interest_rate': None,
|
'interest_rate': None,
|
||||||
'liquidation_price': None,
|
'liquidation_price': None,
|
||||||
@ -1026,7 +1025,6 @@ def test_to_json(default_conf, fee):
|
|||||||
'strategy': None,
|
'strategy': None,
|
||||||
'timeframe': None,
|
'timeframe': None,
|
||||||
'exchange': 'binance',
|
'exchange': 'binance',
|
||||||
|
|
||||||
'leverage': None,
|
'leverage': None,
|
||||||
'interest_rate': None,
|
'interest_rate': None,
|
||||||
'liquidation_price': None,
|
'liquidation_price': None,
|
||||||
|
@ -495,9 +495,9 @@ def test_update_market_order(
|
|||||||
assert trade.interest_rate == 0.0005
|
assert trade.interest_rate == 0.0005
|
||||||
# TODO: Uncomment the next assert and make it work.
|
# TODO: Uncomment the next assert and make it work.
|
||||||
# The logger also has the exact same but there's some spacing in there
|
# 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, "
|
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=.*\).",
|
r"pair=ETH/BTC, amount=275.97543219, open_rate=0.00004173, open_since=.*\).",
|
||||||
# caplog)
|
caplog)
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
trade.is_open = True
|
trade.is_open = True
|
||||||
trade.open_order_id = 'something'
|
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: The amount should maybe be the opening amount + the interest
|
||||||
# TODO: Uncomment the next assert and make it work.
|
# TODO: Uncomment the next assert and make it work.
|
||||||
# The logger also has the exact same but there's some spacing in there
|
# 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, "
|
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=.*\).",
|
r"pair=ETH/BTC, amount=275.97543219, open_rate=0.00004099, open_since=.*\).",
|
||||||
# caplog)
|
caplog)
|
||||||
|
|
||||||
|
|
||||||
@ pytest.mark.usefixtures("init_persistence")
|
@ pytest.mark.usefixtures("init_persistence")
|
||||||
@ -746,4 +746,4 @@ def test_get_best_pair(fee):
|
|||||||
res = Trade.get_best_pair()
|
res = Trade.get_best_pair()
|
||||||
assert len(res) == 2
|
assert len(res) == 2
|
||||||
assert res[0] == 'ETC/BTC'
|
assert res[0] == 'ETC/BTC'
|
||||||
assert res[1] == 0.22626016260162551
|
assert res[1] == 0.17524390243902502
|
||||||
|
Loading…
Reference in New Issue
Block a user