Kraken interest test comes really close to passing
Added more trades to conftest_trades
This commit is contained in:
parent
876386d2db
commit
3a8a9eb255
@ -270,7 +270,7 @@ class LocalTrade():
|
||||
liquidation_price: float = None
|
||||
is_short: bool = False
|
||||
_borrowed: float = 0.0
|
||||
leverage: float = None # * You probably want to use LocalTrade.leverage instead
|
||||
_leverage: float = None # * You probably want to use LocalTrade.leverage instead
|
||||
|
||||
# @property
|
||||
# def base_currency(self) -> str:
|
||||
@ -280,7 +280,7 @@ class LocalTrade():
|
||||
|
||||
@property
|
||||
def amount(self) -> float:
|
||||
if self.leverage is not None:
|
||||
if self._leverage is not None:
|
||||
return self._amount * self.leverage
|
||||
else:
|
||||
return self._amount
|
||||
@ -291,20 +291,29 @@ class LocalTrade():
|
||||
|
||||
@property
|
||||
def borrowed(self) -> float:
|
||||
if self.leverage is not None:
|
||||
if self._leverage is not None:
|
||||
if self.is_short:
|
||||
# If shorting the full amount must be borrowed
|
||||
return self._amount * self.leverage
|
||||
return self._amount * self._leverage
|
||||
else:
|
||||
# If not shorting, then the trader already owns a bit
|
||||
return self._amount * (self.leverage-1)
|
||||
return self._amount * (self._leverage-1)
|
||||
else:
|
||||
return self._borrowed
|
||||
|
||||
@borrowed.setter
|
||||
def borrowed(self, value):
|
||||
self._borrowed = value
|
||||
self.leverage = None
|
||||
self._leverage = None
|
||||
|
||||
@property
|
||||
def leverage(self) -> float:
|
||||
return self._leverage
|
||||
|
||||
@leverage.setter
|
||||
def leverage(self, value):
|
||||
self._leverage = value
|
||||
self._borrowed = None
|
||||
|
||||
# End of margin trading properties
|
||||
|
||||
@ -896,7 +905,7 @@ class Trade(_DECL_BASE, LocalTrade):
|
||||
timeframe = Column(Integer, nullable=True)
|
||||
|
||||
# Margin trading properties
|
||||
leverage: float = None # * You probably want to use LocalTrade.leverage instead
|
||||
_leverage: float = None # * You probably want to use LocalTrade.leverage instead
|
||||
_borrowed = Column(Float, nullable=False, default=0.0)
|
||||
interest_rate = Column(Float, nullable=False, default=0.0)
|
||||
liquidation_price = Column(Float, nullable=True)
|
||||
|
@ -347,13 +347,13 @@ def short_trade(fee):
|
||||
trade = Trade(
|
||||
pair='ETC/BTC',
|
||||
stake_amount=0.001,
|
||||
amount=123.0, # TODO-mg: In BTC?
|
||||
amount=123.0,
|
||||
amount_requested=123.0,
|
||||
fee_open=fee.return_value,
|
||||
fee_close=fee.return_value,
|
||||
open_rate=0.123,
|
||||
close_rate=0.128,
|
||||
close_profit=0.005, # TODO-mg: Would this be -0.005 or -0.025
|
||||
close_profit=0.025,
|
||||
close_profit_abs=0.000584127,
|
||||
exchange='binance',
|
||||
is_open=False,
|
||||
|
@ -502,14 +502,14 @@ def test_interest_kraken(market_short_order, ten_minutes_ago, five_hours_ago, fe
|
||||
interest: borrowed * interest_rate * time-periods
|
||||
= 275.97543219 * 0.0005 * 1 = 0.137987716095 crypto
|
||||
= 275.97543219 * 0.00025 * 5/4 = 0.086242322559375 crypto
|
||||
= 459.95905365 * 0.0005 * 5/4 = 0.17248464511875 crypto
|
||||
= 459.95905365 * 0.00025 * 1 = 0.0689938580475 crypto
|
||||
= 459.95905365 * 0.0005 * 5/4 = 0.28747440853125 crypto
|
||||
= 459.95905365 * 0.00025 * 1 = 0.1149897634125 crypto
|
||||
"""
|
||||
|
||||
trade = Trade(
|
||||
pair='ETH/BTC',
|
||||
stake_amount=0.001,
|
||||
amount=5,
|
||||
amount=91.99181073,
|
||||
open_rate=0.00001099,
|
||||
open_date=ten_minutes_ago,
|
||||
fee_open=fee.return_value,
|
||||
@ -519,19 +519,18 @@ def test_interest_kraken(market_short_order, ten_minutes_ago, five_hours_ago, fe
|
||||
leverage=3.0,
|
||||
interest_rate=0.0005
|
||||
)
|
||||
trade.update(market_short_order) # Buy @ 0.00001099
|
||||
|
||||
assert isclose(float("{:.15f}".format(trade.calculate_interest())), 0.137987716095)
|
||||
assert float(round(trade.calculate_interest(), 8)) == 0.13798772
|
||||
trade.open_date = five_hours_ago
|
||||
assert isclose(float("{:.15f}".format(
|
||||
trade.calculate_interest(interest_rate=0.00025))), 0.086242322559375)
|
||||
assert float(round(trade.calculate_interest(interest_rate=0.00025), 8)
|
||||
) == 0.08624232 # TODO: Fails with 0.08624233
|
||||
|
||||
trade = Trade(
|
||||
pair='ETH/BTC',
|
||||
stake_amount=0.001,
|
||||
amount=5,
|
||||
amount=91.99181073,
|
||||
open_rate=0.00001099,
|
||||
open_date=ten_minutes_ago,
|
||||
open_date=five_hours_ago,
|
||||
fee_open=fee.return_value,
|
||||
fee_close=fee.return_value,
|
||||
exchange='kraken',
|
||||
@ -539,12 +538,10 @@ def test_interest_kraken(market_short_order, ten_minutes_ago, five_hours_ago, fe
|
||||
leverage=5.0,
|
||||
interest_rate=0.0005
|
||||
)
|
||||
trade.update(market_short_order) # Buy @ 0.00001099
|
||||
|
||||
assert isclose(float("{:.15f}".format(trade.calculate_interest())), 0.17248464511875)
|
||||
assert float(round(trade.calculate_interest(), 8)) == 0.28747441 # TODO: Fails with 0.28747445
|
||||
trade.open_date = ten_minutes_ago
|
||||
assert isclose(float("{:.15f}".format(
|
||||
trade.calculate_interest(interest_rate=0.00025))), 0.0689938580475)
|
||||
assert float(round(trade.calculate_interest(interest_rate=0.00025), 8)) == 0.11498976
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
@ -565,50 +562,47 @@ def test_interest_binance(market_short_order, ten_minutes_ago, five_hours_ago, f
|
||||
5 hours = 5/24
|
||||
|
||||
interest: borrowed * interest_rate * time-periods
|
||||
= print(275.97543219 * 0.0005 * 1/24) = 0.005749488170625 crypto
|
||||
= print(275.97543219 * 0.00025 * 5/24) = 0.0143737204265625 crypto
|
||||
= print(459.95905365 * 0.0005 * 5/24) = 0.047912401421875 crypto
|
||||
= print(459.95905365 * 0.00025 * 1/24) = 0.0047912401421875 crypto
|
||||
= 275.97543219 * 0.0005 * 1/24 = 0.005749488170625 crypto
|
||||
= 275.97543219 * 0.00025 * 5/24 = 0.0143737204265625 crypto
|
||||
= 459.95905365 * 0.0005 * 5/24 = 0.047912401421875 crypto
|
||||
= 459.95905365 * 0.00025 * 1/24 = 0.0047912401421875 crypto
|
||||
"""
|
||||
|
||||
trade = Trade(
|
||||
pair='ETH/BTC',
|
||||
stake_amount=0.001,
|
||||
amount=5,
|
||||
amount=275.97543219,
|
||||
open_rate=0.00001099,
|
||||
open_date=ten_minutes_ago,
|
||||
fee_open=fee.return_value,
|
||||
fee_close=fee.return_value,
|
||||
exchange='binance',
|
||||
is_short=True,
|
||||
borrowed=275.97543219,
|
||||
interest_rate=0.0005
|
||||
)
|
||||
trade.update(market_short_order) # Buy @ 0.00001099
|
||||
|
||||
assert isclose(float("{:.15f}".format(trade.calculate_interest())), 0.005749488170625)
|
||||
assert float(round(trade.calculate_interest(), 8)) == 0.00574949
|
||||
trade.open_date = five_hours_ago
|
||||
assert isclose(float("{:.15f}".format(
|
||||
trade.calculate_interest(interest_rate=0.00025))), 0.0143737204265625)
|
||||
assert float(round(trade.calculate_interest(interest_rate=0.00025), 8)) == 0.01437372
|
||||
|
||||
trade = Trade(
|
||||
pair='ETH/BTC',
|
||||
stake_amount=0.001,
|
||||
amount=5,
|
||||
amount=459.95905365,
|
||||
open_rate=0.00001099,
|
||||
open_date=ten_minutes_ago,
|
||||
open_date=five_hours_ago,
|
||||
fee_open=fee.return_value,
|
||||
fee_close=fee.return_value,
|
||||
exchange='binance',
|
||||
is_short=True,
|
||||
leverage=5.0,
|
||||
borrowed=459.95905365,
|
||||
interest_rate=0.0005
|
||||
)
|
||||
trade.update(market_short_order) # Buy @ 0.00001099
|
||||
|
||||
assert isclose(float("{:.15f}".format(trade.calculate_interest())), 0.047912401421875)
|
||||
assert float(round(trade.calculate_interest(), 8)) == 0.04791240
|
||||
trade.open_date = ten_minutes_ago
|
||||
assert isclose(float("{:.15f}".format(
|
||||
trade.calculate_interest(interest_rate=0.00025))), 0.0047912401421875)
|
||||
assert float(round(trade.calculate_interest(interest_rate=0.00025), 8)) == 0.00479124
|
||||
|
||||
|
||||
def test_adjust_stop_loss(fee):
|
||||
|
Loading…
Reference in New Issue
Block a user