Set leverage and borowed to computed properties
This commit is contained in:
@@ -2132,6 +2132,40 @@ def limit_exit_short_order(limit_exit_short_order_open):
|
||||
order['status'] = 'closed'
|
||||
return order
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def market_short_order():
|
||||
return {
|
||||
'id': 'mocked_market_buy',
|
||||
'type': 'market',
|
||||
'side': 'buy',
|
||||
'symbol': 'mocked',
|
||||
'datetime': arrow.utcnow().isoformat(),
|
||||
'price': 0.00004173,
|
||||
'amount': 91.99181073,
|
||||
'filled': 91.99181073,
|
||||
'remaining': 0.0,
|
||||
'status': 'closed',
|
||||
'is_short': True,
|
||||
'leverage': 3
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def market_exit_short_order():
|
||||
return {
|
||||
'id': 'mocked_limit_sell',
|
||||
'type': 'market',
|
||||
'side': 'sell',
|
||||
'symbol': 'mocked',
|
||||
'datetime': arrow.utcnow().isoformat(),
|
||||
'price': 0.00004099,
|
||||
'amount': 91.99181073,
|
||||
'filled': 91.99181073,
|
||||
'remaining': 0.0,
|
||||
'status': 'closed'
|
||||
}
|
||||
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def interest_rate():
|
||||
|
@@ -659,12 +659,13 @@ def test_migrate_new(mocker, default_conf, fee, caplog):
|
||||
order_date DATETIME,
|
||||
order_filled_date DATETIME,
|
||||
order_update_date DATETIME,
|
||||
leverage FLOAT,
|
||||
PRIMARY KEY (id),
|
||||
CONSTRAINT _order_pair_order_id UNIQUE (ft_pair, order_id),
|
||||
FOREIGN KEY(ft_trade_id) REFERENCES trades (id)
|
||||
)
|
||||
"""))
|
||||
|
||||
# TODO-mg @xmatthias: Had to add field leverage to this table, check that this is correct
|
||||
connection.execute(text("""
|
||||
insert into orders ( id, ft_trade_id, ft_order_side, ft_pair, ft_is_open, order_id, status,
|
||||
symbol, order_type, side, price, amount, filled, remaining, cost, order_date,
|
||||
@@ -912,6 +913,14 @@ def test_to_json(default_conf, fee):
|
||||
'strategy': None,
|
||||
'timeframe': None,
|
||||
'exchange': 'binance',
|
||||
|
||||
'leverage': None,
|
||||
'borrowed': None,
|
||||
'borrowed_currency': None,
|
||||
'collateral_currency': None,
|
||||
'interest_rate': None,
|
||||
'liquidation_price': None,
|
||||
'is_short': None,
|
||||
}
|
||||
|
||||
# Simulate dry_run entries
|
||||
@@ -977,6 +986,14 @@ def test_to_json(default_conf, fee):
|
||||
'strategy': None,
|
||||
'timeframe': None,
|
||||
'exchange': 'binance',
|
||||
|
||||
'leverage': None,
|
||||
'borrowed': None,
|
||||
'borrowed_currency': None,
|
||||
'collateral_currency': None,
|
||||
'interest_rate': None,
|
||||
'liquidation_price': None,
|
||||
'is_short': None,
|
||||
}
|
||||
|
||||
|
||||
@@ -1315,7 +1332,7 @@ def test_Trade_object_idem():
|
||||
'get_overall_performance',
|
||||
'get_total_closed_profit',
|
||||
'total_open_trades_stakes',
|
||||
'get_sold_trades_without_assigned_fees',
|
||||
'get_closed_trades_without_assigned_fees',
|
||||
'get_open_trades_without_assigned_fees',
|
||||
'get_open_order_trades',
|
||||
'get_trades',
|
||||
|
@@ -58,19 +58,22 @@ def test_update_with_binance(limit_short_order, limit_exit_short_order, fee, int
|
||||
fee_open=fee.return_value,
|
||||
fee_close=fee.return_value,
|
||||
interest_rate=interest_rate.return_value,
|
||||
borrowed=90.99181073,
|
||||
exchange='binance',
|
||||
is_short=True
|
||||
# borrowed=90.99181073,
|
||||
exchange='binance'
|
||||
)
|
||||
#assert trade.open_order_id is None
|
||||
assert trade.close_profit is None
|
||||
assert trade.close_date is None
|
||||
assert trade.borrowed is None
|
||||
assert trade.is_short is None
|
||||
#trade.open_order_id = 'something'
|
||||
trade.update(limit_short_order)
|
||||
#assert trade.open_order_id is None
|
||||
assert trade.open_rate == 0.00001173
|
||||
assert trade.close_profit is None
|
||||
assert trade.close_date is None
|
||||
assert trade.borrowed == 90.99181073
|
||||
assert trade.is_short is True
|
||||
assert log_has_re(r"LIMIT_SELL has been fulfilled for Trade\(id=2, "
|
||||
r"pair=ETH/BTC, amount=90.99181073, open_rate=0.00001173, open_since=.*\).",
|
||||
caplog)
|
||||
@@ -89,7 +92,18 @@ def test_update_with_binance(limit_short_order, limit_exit_short_order, fee, int
|
||||
|
||||
|
||||
# @pytest.mark.usefixtures("init_persistence")
|
||||
# def test_update_market_order(market_buy_order, market_sell_order, fee, caplog):
|
||||
# def test_update_market_order(
|
||||
# market_buy_order,
|
||||
# market_sell_order,
|
||||
# fee,
|
||||
# interest_rate,
|
||||
# ten_minutes_ago,
|
||||
# caplog
|
||||
# ):
|
||||
# """Test Kraken and leverage arguments as well as update market order
|
||||
|
||||
|
||||
# """
|
||||
# trade = Trade(
|
||||
# id=1,
|
||||
# pair='ETH/BTC',
|
||||
@@ -99,11 +113,15 @@ def test_update_with_binance(limit_short_order, limit_exit_short_order, fee, int
|
||||
# is_open=True,
|
||||
# fee_open=fee.return_value,
|
||||
# fee_close=fee.return_value,
|
||||
# open_date=arrow.utcnow().datetime,
|
||||
# exchange='binance',
|
||||
# open_date=ten_minutes_ago,
|
||||
# exchange='kraken',
|
||||
# interest_rate=interest_rate.return_value
|
||||
# )
|
||||
# trade.open_order_id = 'something'
|
||||
# trade.update(market_buy_order)
|
||||
# assert trade.leverage is 3
|
||||
# assert trade.is_short is true
|
||||
# assert trade.leverage is 3
|
||||
# assert trade.open_order_id is None
|
||||
# assert trade.open_rate == 0.00004099
|
||||
# assert trade.close_profit is None
|
||||
@@ -122,8 +140,6 @@ def test_update_with_binance(limit_short_order, limit_exit_short_order, fee, int
|
||||
# assert log_has_re(r"MARKET_SELL has been fulfilled for Trade\(id=1, "
|
||||
# r"pair=ETH/BTC, amount=91.99181073, open_rate=0.00004099, open_since=.*\).",
|
||||
# caplog)
|
||||
# # TODO-mg: market short
|
||||
# # TODO-mg: market leveraged long
|
||||
|
||||
|
||||
# @pytest.mark.usefixtures("init_persistence")
|
||||
|
Reference in New Issue
Block a user