Added minor changes from lev-exchange review

This commit is contained in:
Sam Germain
2021-09-10 13:39:42 -06:00
parent 1fa318c52a
commit b0e05b92d3
6 changed files with 51 additions and 38 deletions

View File

@@ -41,8 +41,8 @@ class Binance(Exchange):
"""
return order['type'] == 'stop_loss_limit' and (
side == "sell" and stop_loss > float(order['info']['stopPrice']) or
side == "buy" and stop_loss < float(order['info']['stopPrice'])
(side == "sell" and stop_loss > float(order['info']['stopPrice'])) or
(side == "buy" and stop_loss < float(order['info']['stopPrice']))
)
@retrier(retries=0)
@@ -55,11 +55,12 @@ class Binance(Exchange):
:param side: "buy" or "sell"
"""
# Limit price threshold: As limit price should always be below stop-price
limit_price_pct = order_types.get(
'stoploss_on_exchange_limit_ratio',
0.99 if side == 'sell' else 1.01
)
rate = stop_price * limit_price_pct
limit_price_pct = order_types.get('stoploss_on_exchange_limit_ratio', 0.99)
if side == "sell":
# TODO: Name limit_rate in other exchange subclasses
rate = stop_price * limit_price_pct
else:
rate = stop_price * (2 - limit_price_pct)
ordertype = "stop_loss_limit"

View File

@@ -1597,8 +1597,7 @@ class Exchange:
:param pair: The base/quote currency pair being traded
:nominal_value: The total value of the trade in quote currency (collateral + debt)
"""
raise OperationalException(
f"{self.name.capitalize()}.get_max_leverage has not been implemented.")
return 1.0
@retrier
def set_leverage(self, leverage: float, pair: Optional[str]):
@@ -1606,6 +1605,10 @@ class Exchange:
Set's the leverage before making a trade, in order to not
have the same leverage on every trade
"""
if not self.exchange_has("setLeverage"):
# Some exchanges only support one collateral type
return
try:
self._api.set_leverage(symbol=pair, leverage=leverage)
except ccxt.DDoSProtection as e:

View File

@@ -57,11 +57,11 @@ class Ftx(Exchange):
Limit orders are defined by having orderPrice set, otherwise a market order is used.
"""
limit_price_pct = order_types.get(
'stoploss_on_exchange_limit_ratio',
0.99 if side == "sell" else 1.01
)
limit_rate = stop_price * limit_price_pct
limit_price_pct = order_types.get('stoploss_on_exchange_limit_ratio', 0.99)
if side == "sell":
limit_rate = stop_price * limit_price_pct
else:
limit_rate = stop_price * (2 - limit_price_pct)
ordertype = "stop"

View File

@@ -55,8 +55,8 @@ class Kraken(Exchange):
orders = self._api.fetch_open_orders()
order_list = [(x["symbol"].split("/")[0 if x["side"] == "sell" else 1],
x["remaining"] if x["side"] == "sell" else x["remaining"] * x["price"],
# Don't remove the below comment, this can be important for debugging
x["remaining"] if x["side"] == "sell" else x["remaining"] * x["price"],
# Don't remove the below comment, this can be important for debugging
# x["side"], x["amount"],
) for x in orders]
for bal in balances:
@@ -96,7 +96,10 @@ class Kraken(Exchange):
if order_types.get('stoploss', 'market') == 'limit':
ordertype = "stop-loss-limit"
limit_price_pct = order_types.get('stoploss_on_exchange_limit_ratio', 0.99)
limit_rate = stop_price * limit_price_pct
if side == "sell":
limit_rate = stop_price * limit_price_pct
else:
limit_rate = stop_price * (2 - limit_price_pct)
params['price2'] = self.price_to_precision(pair, limit_rate)
else:
ordertype = "stop-loss"
@@ -144,13 +147,13 @@ class Kraken(Exchange):
for pair, market in self.markets.items():
info = market['info']
leverage_buy = info['leverage_buy'] if 'leverage_buy' in info else []
leverage_sell = info['leverage_sell'] if 'leverage_sell' in info else []
leverage_buy = info.get('leverage_buy', [])
leverage_sell = info.get('leverage_sell', [])
if len(leverage_buy) > 0 or len(leverage_sell) > 0:
if leverage_buy != leverage_sell:
logger.warning(
f"The buy({leverage_buy}) and sell({leverage_sell}) leverage are not equal"
"{pair}. Please let freqtrade know because this has never happened before"
"for {pair}. Please notify freqtrade because this has never happened before"
)
if max(leverage_buy) < max(leverage_sell):
leverages[pair] = leverage_buy