implement mark_price, funding_rate, next_funding_timestamp properties

This commit is contained in:
Saleh Mir
2021-05-23 18:03:51 +04:30
parent ae111e5c37
commit f4c377ee40
4 changed files with 58 additions and 1 deletions

View File

@@ -20,6 +20,8 @@ class Position:
self.opened_at = None
self.closed_at = None
self._mark_price = None
self._funding_rate = None
self._next_funding_timestamp = None
if attributes is None:
attributes = {}
@@ -35,11 +37,25 @@ class Position:
@property
def mark_price(self):
if not jh.is_livetrading():
if not jh.is_live():
return self.current_price
return self._mark_price
@property
def funding_rate(self):
if not jh.is_live():
return 0
return self._funding_rate
@property
def next_funding_timestamp(self):
if not jh.is_live():
return None
return self._next_funding_timestamp
@property
def value(self) -> float:
"""

View File

@@ -1252,3 +1252,15 @@ class Strategy(ABC):
return self.position.exchange.futures_leverage
else:
raise ValueError('exchange type not supported!')
@property
def mark_price(self):
return self.position.mark_price
@property
def funding_rate(self):
return self.position.funding_rate
@property
def next_funding_timestamp(self):
return self.position.next_funding_timestamp

View File

@@ -0,0 +1,24 @@
from jesse.strategies import Strategy
class TestMarkPrice(Strategy):
def before(self):
if self.index < 10:
assert self.price == self.mark_price
assert self.funding_rate == 0
assert self.next_funding_timestamp is None
def should_long(self) -> bool:
return False
def should_short(self) -> bool:
return False
def go_long(self):
pass
def go_short(self):
pass
def should_cancel(self):
return False

View File

@@ -911,6 +911,11 @@ def test_liquidation_in_isolated_mode_for_long_trades():
)
def test_mark_price():
single_route_backtest(
'TestMarkPrice', is_futures_trading=True,
)
# TODO: implement liquidation in backtest mode for cross mode
# def test_liquidation_in_cross_mode_for_short_trades():
# single_route_backtest(