swapped maintenancemarginformula for liqformula

This commit is contained in:
Sam Germain 2021-07-30 23:18:27 -06:00
parent f1c580dcb8
commit c49a64ea59
7 changed files with 15 additions and 39 deletions

View File

@ -1,26 +0,0 @@
from enum import Enum
from freqtrade.exceptions import OperationalException
class MaintenanceMarginFormula(Enum):
"""Equations to calculate maintenance margin"""
BINANCE = "BINANCE"
FTX = "FTX"
KRAKEN = "KRAKEN"
# TODO: Add arguments
def __call__(self):
if self.name == "BINANCE":
raise OperationalException("Cross margin not available on this exchange with freqtrade")
# TODO: return This formula
# https://www.binance.com/en/support/faq/f6b010588e55413aa58b7d63ee0125ed
elif self.name == "FTX":
# TODO: Implement
raise OperationalException("Cross margin not available on this exchange with freqtrade")
elif self.name == "KRAKEN":
# TODO: Implement
raise OperationalException("Cross margin not available on this exchange with freqtrade")
# https://support.kraken.com/hc/en-us/articles/203325763-Margin-Call-Level-and-Margin-Liquidation-Level
else:
raise OperationalException("Cross margin not available on this exchange with freqtrade")

View File

@ -3,7 +3,8 @@ import logging
from typing import Dict from typing import Dict
import ccxt import ccxt
from freqtrade.enums import MaintenanceMarginFormula
from freqtrade.enums import LiqFormula
from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException, from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException,
OperationalException, TemporaryError) OperationalException, TemporaryError)
from freqtrade.exchange import Exchange from freqtrade.exchange import Exchange
@ -24,7 +25,7 @@ class Binance(Exchange):
"l2_limit_range": [5, 10, 20, 50, 100, 500, 1000], "l2_limit_range": [5, 10, 20, 50, 100, 500, 1000],
} }
maintenance_margin_formula = MaintenanceMarginFormula.BINANCE maintenance_margin_formula = LiqFormula.BINANCE
def stoploss_adjust(self, stop_loss: float, order: Dict) -> bool: def stoploss_adjust(self, stop_loss: float, order: Dict) -> bool:
""" """

View File

@ -21,7 +21,7 @@ from pandas import DataFrame
from freqtrade.constants import DEFAULT_AMOUNT_RESERVE_PERCENT, ListPairsWithTimeframes from freqtrade.constants import DEFAULT_AMOUNT_RESERVE_PERCENT, ListPairsWithTimeframes
from freqtrade.data.converter import ohlcv_to_dataframe, trades_dict_to_list from freqtrade.data.converter import ohlcv_to_dataframe, trades_dict_to_list
from freqtrade.enums import MaintenanceMarginFormula from freqtrade.enums import LiqFormula
from freqtrade.exceptions import (DDosProtection, ExchangeError, InsufficientFundsError, from freqtrade.exceptions import (DDosProtection, ExchangeError, InsufficientFundsError,
InvalidOrderException, OperationalException, PricingError, InvalidOrderException, OperationalException, PricingError,
RetryableOrderError, TemporaryError) RetryableOrderError, TemporaryError)
@ -69,7 +69,7 @@ class Exchange:
"l2_limit_range_required": True, # Allow Empty L2 limit (kucoin) "l2_limit_range_required": True, # Allow Empty L2 limit (kucoin)
} }
_ft_has: Dict = {} _ft_has: Dict = {}
maintenance_margin_formula: MaintenanceMarginFormula liq_formula: LiqFormula
def __init__(self, config: Dict[str, Any], validate: bool = True) -> None: def __init__(self, config: Dict[str, Any], validate: bool = True) -> None:
""" """

View File

@ -4,7 +4,7 @@ from typing import Any, Dict
import ccxt import ccxt
from freqtrade.enums import MaintenanceMarginFormula from freqtrade.enums import LiqFormula
from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException, from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException,
OperationalException, TemporaryError) OperationalException, TemporaryError)
from freqtrade.exchange import Exchange from freqtrade.exchange import Exchange
@ -22,7 +22,7 @@ class Ftx(Exchange):
"ohlcv_candle_limit": 1500, "ohlcv_candle_limit": 1500,
} }
maintenance_margin_formula = MaintenanceMarginFormula.FTX maintenance_margin_formula = LiqFormula.FTX
def market_is_tradable(self, market: Dict[str, Any]) -> bool: def market_is_tradable(self, market: Dict[str, Any]) -> bool:
""" """

View File

@ -4,7 +4,7 @@ from typing import Any, Dict
import ccxt import ccxt
from freqtrade.enums import MaintenanceMarginFormula from freqtrade.enums import LiqFormula
from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException, from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException,
OperationalException, TemporaryError) OperationalException, TemporaryError)
from freqtrade.exchange import Exchange from freqtrade.exchange import Exchange
@ -24,7 +24,7 @@ class Kraken(Exchange):
"trades_pagination_arg": "since", "trades_pagination_arg": "since",
} }
maintenance_margin_formula = MaintenanceMarginFormula.KRAKEN maintenance_margin_formula = LiqFormula.KRAKEN
def market_is_tradable(self, market: Dict[str, Any]) -> bool: def market_is_tradable(self, market: Dict[str, Any]) -> bool:
""" """

View File

@ -105,8 +105,9 @@ class FreqtradeBot(LoggingMixin):
# Start calculating maintenance margin if on cross margin # Start calculating maintenance margin if on cross margin
# TODO: Add margin_mode to freqtrade.configuration? # TODO: Add margin_mode to freqtrade.configuration?
if self.config.get('margin_mode') == "cross": if self.config.get('leverage_type') == "cross" or \
self.maintenance_margin = MaintenanceMargin(self.exchange.maintenance_margin_formula) self.config.get('leverage_type') == "cross_futures":
self.maintenance_margin = MaintenanceMargin(self.exchange.liq_formula)
self.maintenance_margin.run self.maintenance_margin.run
def notify_status(self, msg: str) -> None: def notify_status(self, msg: str) -> None:

View File

@ -1,11 +1,11 @@
from freqtrade.enums import MaintenanceMarginFormula from freqtrade.enums import LiqFormula
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
class MaintenanceMargin: class MaintenanceMargin:
trades: list[Trade] trades: list[Trade]
formula: MaintenanceMarginFormula formula: LiqFormula
@property @property
def margin_level(self): def margin_level(self):
@ -15,7 +15,7 @@ class MaintenanceMargin:
def liq_level(self): # This may be a constant value and may not need a function def liq_level(self): # This may be a constant value and may not need a function
return return
def __init__(self, formula: MaintenanceMarginFormula): def __init__(self, formula: LiqFormula):
return return
def add_new_trade(self, trade): def add_new_trade(self, trade):