Removed setup leverage and transfer functions from exchange
This commit is contained in:
parent
f4e26a616f
commit
d262af35ca
@ -1,6 +1,6 @@
|
|||||||
""" Binance exchange subclass """
|
""" Binance exchange subclass """
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict, Optional
|
from typing import Dict
|
||||||
|
|
||||||
import ccxt
|
import ccxt
|
||||||
|
|
||||||
@ -96,103 +96,5 @@ class Binance(Exchange):
|
|||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from 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):
|
def apply_leverage_to_stake_amount(self, stake_amount: float, leverage: float):
|
||||||
return stake_amount / leverage
|
return stake_amount / leverage
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
""" Bittrex exchange subclass """
|
""" Bittrex exchange subclass """
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict, Optional
|
from typing import Dict
|
||||||
|
|
||||||
from freqtrade.exchange import Exchange
|
from freqtrade.exchange import Exchange
|
||||||
from freqtrade.exceptions import OperationalException
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -24,23 +23,3 @@ class Bittrex(Exchange):
|
|||||||
},
|
},
|
||||||
"l2_limit_range": [1, 25, 500],
|
"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")
|
|
||||||
|
@ -730,8 +730,7 @@ class Exchange:
|
|||||||
|
|
||||||
def get_max_leverage(self, pair: str, stake_amount: float, price: float) -> float:
|
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
|
Gets the maximum leverage available on this pair
|
||||||
but higher than the config min_leverage
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise OperationalException(f"Leverage is not available on {self.name} using freqtrade")
|
raise OperationalException(f"Leverage is not available on {self.name} using freqtrade")
|
||||||
@ -782,26 +781,6 @@ class Exchange:
|
|||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from 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:
|
def stoploss_adjust(self, stop_loss: float, order: Dict, side: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Verify stop_loss against stoploss-order value (limit or price)
|
Verify stop_loss against stoploss-order value (limit or price)
|
||||||
@ -1571,15 +1550,6 @@ class Exchange:
|
|||||||
self._async_get_trade_history(pair=pair, since=since,
|
self._async_get_trade_history(pair=pair, since=since,
|
||||||
until=until, from_id=from_id))
|
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:
|
def get_interest_rate(self, pair: str, open_rate: float, is_short: bool) -> float:
|
||||||
# TODO-mg: implement
|
# TODO-mg: implement
|
||||||
return 0.0005
|
return 0.0005
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
""" Kraken exchange subclass """
|
""" Kraken exchange subclass """
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict
|
||||||
|
|
||||||
import ccxt
|
import ccxt
|
||||||
|
|
||||||
@ -127,23 +127,3 @@ class Kraken(Exchange):
|
|||||||
f'Could not place sell order due to {e.__class__.__name__}. Message: {e}') from e
|
f'Could not place sell order due to {e.__class__.__name__}. Message: {e}') from e
|
||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from 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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user