Removed setup leverage and transfer functions from exchange

This commit is contained in:
Sam Germain 2021-08-02 06:14:30 -06:00
parent 2c0077abc7
commit 4ca1d25db1
4 changed files with 4 additions and 173 deletions

View File

@ -1,6 +1,6 @@
""" Binance exchange subclass """
import logging
from typing import Dict, Optional
from typing import Dict
import ccxt
@ -95,103 +95,5 @@ class Binance(Exchange):
except ccxt.BaseError as e:
raise OperationalException(e) from e
def transfer(self, asset: str, amount: float, frm: str, to: str, pair: Optional[str]):
res = self._api.sapi_post_margin_isolated_transfer({
"asset": asset,
"amount": amount,
"transFrom": frm,
"transTo": to,
"symbol": pair
})
logger.info(f"Transfer response: {res}")
def borrow(self, asset: str, amount: float, pair: str):
res = self._api.sapi_post_margin_loan({
"asset": asset,
"isIsolated": True,
"symbol": pair,
"amount": amount
}) # borrow from binance
logger.info(f"Borrow response: {res}")
def repay(self, asset: str, amount: float, pair: str):
res = self._api.sapi_post_margin_repay({
"asset": asset,
"isIsolated": True,
"symbol": pair,
"amount": amount
}) # borrow from binance
logger.info(f"Borrow response: {res}")
def setup_leveraged_enter(
self,
pair: str,
leverage: float,
amount: float,
quote_currency: Optional[str],
is_short: Optional[bool]
):
if not quote_currency or not is_short:
raise OperationalException(
"quote_currency and is_short are required arguments to setup_leveraged_enter"
" when trading with leverage on binance"
)
open_rate = 2 # TODO-mg: get the real open_rate, or real stake_amount
stake_amount = amount * open_rate
if is_short:
borrowed = stake_amount * ((leverage-1)/leverage)
else:
borrowed = amount
self.transfer( # Transfer to isolated margin
asset=quote_currency,
amount=stake_amount,
frm='SPOT',
to='ISOLATED_MARGIN',
pair=pair
)
self.borrow(
asset=quote_currency,
amount=borrowed,
pair=pair
) # borrow from binance
def complete_leveraged_exit(
self,
pair: str,
leverage: float,
amount: float,
quote_currency: Optional[str],
is_short: Optional[bool]
):
if not quote_currency or not is_short:
raise OperationalException(
"quote_currency and is_short are required arguments to setup_leveraged_enter"
" when trading with leverage on binance"
)
open_rate = 2 # TODO-mg: get the real open_rate, or real stake_amount
stake_amount = amount * open_rate
if is_short:
borrowed = stake_amount * ((leverage-1)/leverage)
else:
borrowed = amount
self.repay(
asset=quote_currency,
amount=borrowed,
pair=pair
) # repay binance
self.transfer( # Transfer to isolated margin
asset=quote_currency,
amount=stake_amount,
frm='ISOLATED_MARGIN',
to='SPOT',
pair=pair
)
def apply_leverage_to_stake_amount(self, stake_amount: float, leverage: float):
return stake_amount / leverage

View File

@ -1,9 +1,8 @@
""" Bittrex exchange subclass """
import logging
from typing import Dict, Optional
from typing import Dict
from freqtrade.exchange import Exchange
from freqtrade.exceptions import OperationalException
logger = logging.getLogger(__name__)
@ -24,23 +23,3 @@ class Bittrex(Exchange):
},
"l2_limit_range": [1, 25, 500],
}
def setup_leveraged_enter(
self,
pair: str,
leverage: float,
amount: float,
quote_currency: Optional[str],
is_short: Optional[bool]
):
raise OperationalException("Bittrex does not support leveraged trading")
def complete_leveraged_exit(
self,
pair: str,
leverage: float,
amount: float,
quote_currency: Optional[str],
is_short: Optional[bool]
):
raise OperationalException("Bittrex does not support leveraged trading")

View File

@ -703,8 +703,7 @@ class Exchange:
def get_max_leverage(self, pair: str, stake_amount: float, price: float) -> float:
"""
Gets the maximum leverage available on this pair that is below the config leverage
but higher than the config min_leverage
Gets the maximum leverage available on this pair
"""
raise OperationalException(f"Leverage is not available on {self.name} using freqtrade")
@ -754,26 +753,6 @@ class Exchange:
except ccxt.BaseError as e:
raise OperationalException(e) from e
def setup_leveraged_enter(
self,
pair: str,
leverage: float,
amount: float,
quote_currency: Optional[str],
is_short: Optional[bool]
):
raise OperationalException(f"Leverage is not available on {self.name} using freqtrade")
def complete_leveraged_exit(
self,
pair: str,
leverage: float,
amount: float,
quote_currency: Optional[str],
is_short: Optional[bool]
):
raise OperationalException(f"Leverage is not available on {self.name} using freqtrade")
def stoploss_adjust(self, stop_loss: float, order: Dict, side: str) -> bool:
"""
Verify stop_loss against stoploss-order value (limit or price)
@ -1538,15 +1517,6 @@ class Exchange:
self._async_get_trade_history(pair=pair, since=since,
until=until, from_id=from_id))
def transfer(self, asset: str, amount: float, frm: str, to: str, pair: Optional[str]):
self._api.transfer(asset, amount, frm, to)
def get_isolated_liq(self, pair: str, open_rate: float,
amount: float, leverage: float, is_short: bool) -> float:
raise OperationalException(
f"Isolated margin is not available on {self.name} using freqtrade"
)
def get_interest_rate(self, pair: str, open_rate: float, is_short: bool) -> float:
# TODO-mg: implement
return 0.0005

View File

@ -1,6 +1,6 @@
""" Kraken exchange subclass """
import logging
from typing import Any, Dict, Optional
from typing import Any, Dict
import ccxt
@ -127,23 +127,3 @@ class Kraken(Exchange):
f'Could not place sell order due to {e.__class__.__name__}. Message: {e}') from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
def setup_leveraged_enter(
self,
pair: str,
leverage: float,
amount: float,
quote_currency: Optional[str],
is_short: Optional[bool]
):
return
def complete_leveraged_exit(
self,
pair: str,
leverage: float,
amount: float,
quote_currency: Optional[str],
is_short: Optional[bool]
):
return