Merge branch 'feat/short' into funding-fee-dry-run

This commit is contained in:
Sam Germain 2021-11-09 14:45:10 -06:00
commit 45e4354906
7 changed files with 41 additions and 41 deletions

View File

@ -3,9 +3,9 @@ from enum import Enum
class Collateral(Enum): class Collateral(Enum):
""" """
Enum to distinguish between Enum to distinguish between
cross margin/futures collateral and cross margin/futures collateral and
isolated margin/futures collateral isolated margin/futures collateral
""" """
CROSS = "cross" CROSS = "cross"
ISOLATED = "isolated" ISOLATED = "isolated"

View File

@ -3,8 +3,8 @@ from enum import Enum
class TradingMode(Enum): class TradingMode(Enum):
""" """
Enum to distinguish between Enum to distinguish between
spot, margin, futures or any other trading method spot, margin, futures or any other trading method
""" """
SPOT = "spot" SPOT = "spot"
MARGIN = "margin" MARGIN = "margin"

View File

@ -140,8 +140,8 @@ class Binance(Exchange):
@retrier @retrier
def fill_leverage_brackets(self): def fill_leverage_brackets(self):
""" """
Assigns property _leverage_brackets to a dictionary of information about the leverage Assigns property _leverage_brackets to a dictionary of information about the leverage
allowed on each pair allowed on each pair
""" """
if self.trading_mode == TradingMode.FUTURES: if self.trading_mode == TradingMode.FUTURES:
try: try:
@ -175,9 +175,9 @@ class Binance(Exchange):
def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float: def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float:
""" """
Returns the maximum leverage that a pair can be traded at Returns the maximum leverage that a pair can be traded at
:param pair: The base/quote currency pair being traded :param pair: The base/quote currency pair being traded
:nominal_value: The total value of the trade in quote currency (collateral + debt) :nominal_value: The total value of the trade in quote currency (collateral + debt)
""" """
pair_brackets = self._leverage_brackets[pair] pair_brackets = self._leverage_brackets[pair]
max_lev = 1.0 max_lev = 1.0
@ -194,8 +194,8 @@ class Binance(Exchange):
trading_mode: Optional[TradingMode] = None trading_mode: Optional[TradingMode] = None
): ):
""" """
Set's the leverage before making a trade, in order to not Set's the leverage before making a trade, in order to not
have the same leverage on every trade have the same leverage on every trade
""" """
trading_mode = trading_mode or self.trading_mode trading_mode = trading_mode or self.trading_mode

View File

@ -516,10 +516,10 @@ class Exchange:
collateral: Optional[Collateral] # Only None when trading_mode = TradingMode.SPOT collateral: Optional[Collateral] # Only None when trading_mode = TradingMode.SPOT
): ):
""" """
Checks if freqtrade can perform trades using the configured Checks if freqtrade can perform trades using the configured
trading mode(Margin, Futures) and Collateral(Cross, Isolated) trading mode(Margin, Futures) and Collateral(Cross, Isolated)
Throws OperationalException: Throws OperationalException:
If the trading_mode/collateral type are not supported by freqtrade on this exchange If the trading_mode/collateral type are not supported by freqtrade on this exchange
""" """
if trading_mode != TradingMode.SPOT and ( if trading_mode != TradingMode.SPOT and (
(trading_mode, collateral) not in self._supported_trading_mode_collateral_pairs (trading_mode, collateral) not in self._supported_trading_mode_collateral_pairs
@ -1648,7 +1648,7 @@ class Exchange:
""" """
Returns the maximum leverage that a pair can be traded at Returns the maximum leverage that a pair can be traded at
:param pair: The base/quote currency pair being traded :param pair: The base/quote currency pair being traded
:nominal_value: The total value of the trade in quote currency (collateral + debt) :param nominal_value: The total value of the trade in quote currency (collateral + debt)
""" """
market = self.markets[pair] market = self.markets[pair]
if ( if (
@ -1728,10 +1728,10 @@ class Exchange:
@retrier @retrier
def set_margin_mode(self, pair: str, collateral: Collateral, params: dict = {}): def set_margin_mode(self, pair: str, collateral: Collateral, params: dict = {}):
''' """
Set's the margin mode on the exchange to cross or isolated for a specific pair Set's the margin mode on the exchange to cross or isolated for a specific pair
:param pair: base/quote currency pair (e.g. "ADA/USDT") :param pair: base/quote currency pair (e.g. "ADA/USDT")
''' """
if self._config['dry_run'] or not self.exchange_has("setMarginMode"): if self._config['dry_run'] or not self.exchange_has("setMarginMode"):
# Some exchanges only support one collateral type # Some exchanges only support one collateral type
return return

View File

@ -146,8 +146,8 @@ class Kraken(Exchange):
trading_mode: Optional[TradingMode] = None trading_mode: Optional[TradingMode] = None
): ):
""" """
Kraken set's the leverage as an option in the order object, so we need to Kraken set's the leverage as an option in the order object, so we need to
add it to params add it to params
""" """
return return

View File

@ -16,18 +16,18 @@ def interest(
hours: Decimal hours: Decimal
) -> Decimal: ) -> Decimal:
""" """
Equation to calculate interest on margin trades Equation to calculate interest on margin trades
:param exchange_name: The exchanged being trading on :param exchange_name: The exchanged being trading on
:param borrowed: The amount of currency being borrowed :param borrowed: The amount of currency being borrowed
:param rate: The rate of interest (i.e daily interest rate) :param rate: The rate of interest (i.e daily interest rate)
:param hours: The time in hours that the currency has been borrowed for :param hours: The time in hours that the currency has been borrowed for
Raises: Raises:
OperationalException: Raised if freqtrade does OperationalException: Raised if freqtrade does
not support margin trading for this exchange not support margin trading for this exchange
Returns: The amount of interest owed (currency matches borrowed) Returns: The amount of interest owed (currency matches borrowed)
""" """
exchange_name = exchange_name.lower() exchange_name = exchange_name.lower()
if exchange_name == "binance": if exchange_name == "binance":

View File

@ -30,13 +30,13 @@ _SQL_DOCS_URL = 'http://docs.sqlalchemy.org/en/latest/core/engines.html#database
def init_db(db_url: str, clean_open_orders: bool = False) -> None: def init_db(db_url: str, clean_open_orders: bool = False) -> None:
""" """
Initializes this module with the given config, Initializes this module with the given config,
registers all known command handlers registers all known command handlers
and starts polling for message updates and starts polling for message updates
:param db_url: Database to use :param db_url: Database to use
:param clean_open_orders: Remove open orders from the database. :param clean_open_orders: Remove open orders from the database.
Useful for dry-run or if all orders have been reset on the exchange. Useful for dry-run or if all orders have been reset on the exchange.
:return: None :return: None
""" """
kwargs = {} kwargs = {}
@ -329,8 +329,8 @@ class LocalTrade():
def _set_stop_loss(self, stop_loss: float, percent: float): def _set_stop_loss(self, stop_loss: float, percent: float):
""" """
Method you should use to set self.stop_loss. Method you should use to set self.stop_loss.
Assures stop_loss is not passed the liquidation price Assures stop_loss is not passed the liquidation price
""" """
if self.isolated_liq is not None: if self.isolated_liq is not None:
if self.is_short: if self.is_short:
@ -352,8 +352,8 @@ class LocalTrade():
def set_isolated_liq(self, isolated_liq: float): def set_isolated_liq(self, isolated_liq: float):
""" """
Method you should use to set self.liquidation price. Method you should use to set self.liquidation price.
Assures stop_loss is not passed the liquidation price Assures stop_loss is not passed the liquidation price
""" """
if self.stop_loss is not None: if self.stop_loss is not None:
if self.is_short: if self.is_short: