Made borrowed a computed property
This commit is contained in:
parent
68d3699c19
commit
df360fb281
@ -269,8 +269,8 @@ class LocalTrade():
|
|||||||
interest_rate: float = 0.0
|
interest_rate: float = 0.0
|
||||||
liquidation_price: float = None
|
liquidation_price: float = None
|
||||||
is_short: bool = False
|
is_short: bool = False
|
||||||
borrowed: float = 0.0
|
_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
|
# @property
|
||||||
# def base_currency(self) -> str:
|
# def base_currency(self) -> str:
|
||||||
@ -280,7 +280,7 @@ class LocalTrade():
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def amount(self) -> float:
|
def amount(self) -> float:
|
||||||
if self._leverage is not None:
|
if self.leverage is not None:
|
||||||
return self._amount * self.leverage
|
return self._amount * self.leverage
|
||||||
else:
|
else:
|
||||||
return self._amount
|
return self._amount
|
||||||
@ -290,22 +290,21 @@ class LocalTrade():
|
|||||||
self._amount = value
|
self._amount = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def leverage(self) -> float:
|
def borrowed(self) -> float:
|
||||||
return self._leverage
|
if self.leverage is not None:
|
||||||
|
if self.is_short:
|
||||||
@leverage.setter
|
# If shorting the full amount must be borrowed
|
||||||
def leverage(self, value):
|
return self._amount * self.leverage
|
||||||
if self.is_short is None or self.amount is None:
|
else:
|
||||||
raise OperationalException(
|
# If not shorting, then the trader already owns a bit
|
||||||
'LocalTrade.amount and LocalTrade.is_short must be assigned before assigning leverage')
|
return self._amount * (self.leverage-1)
|
||||||
|
|
||||||
self._leverage = value
|
|
||||||
if self.is_short:
|
|
||||||
# If shorting the full amount must be borrowed
|
|
||||||
self.borrowed = self._amount * value
|
|
||||||
else:
|
else:
|
||||||
# If not shorting, then the trader already owns a bit
|
return self._borrowed
|
||||||
self.borrowed = self._amount * (value-1)
|
|
||||||
|
@borrowed.setter
|
||||||
|
def borrowed(self, value):
|
||||||
|
self._borrowed = value
|
||||||
|
self.leverage = None
|
||||||
|
|
||||||
# End of margin trading properties
|
# End of margin trading properties
|
||||||
|
|
||||||
@ -897,8 +896,8 @@ class Trade(_DECL_BASE, LocalTrade):
|
|||||||
timeframe = Column(Integer, nullable=True)
|
timeframe = Column(Integer, nullable=True)
|
||||||
|
|
||||||
# Margin trading properties
|
# 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)
|
_borrowed = Column(Float, nullable=False, default=0.0)
|
||||||
interest_rate = Column(Float, nullable=False, default=0.0)
|
interest_rate = Column(Float, nullable=False, default=0.0)
|
||||||
liquidation_price = Column(Float, nullable=True)
|
liquidation_price = Column(Float, nullable=True)
|
||||||
is_short = Column(Boolean, nullable=False, default=False)
|
is_short = Column(Boolean, nullable=False, default=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user