Merge branch 'feat/short' into leverage-tiers

This commit is contained in:
Sam Germain
2022-02-16 08:05:51 -06:00
10 changed files with 53 additions and 43 deletions

View File

@@ -85,7 +85,7 @@ def start_download_data(args: Dict[str, Any]) -> None:
new_pairs_days=config['new_pairs_days'],
erase=bool(config.get('erase')), data_format=config['dataformat_ohlcv'],
trading_mode=config.get('trading_mode', 'spot'),
)
)
except KeyboardInterrupt:
sys.exit("SIGINT received, aborting ...")

View File

@@ -8,8 +8,10 @@ class CandleType(str, Enum):
MARK = "mark"
INDEX = "index"
PREMIUMINDEX = "premiumIndex"
# TODO-lev: not sure this belongs here, as the datatype is really different
# TODO: Could take up less memory if these weren't a CandleType
FUNDING_RATE = "funding_rate"
# BORROW_RATE = "borrow_rate" # * unimplemented
@staticmethod
def from_string(value: str) -> 'CandleType':

View File

@@ -10,16 +10,19 @@ class RPCMessageType(Enum):
BUY_FILL = 'buy_fill'
BUY_CANCEL = 'buy_cancel'
SELL = 'sell'
SELL_FILL = 'sell_fill'
SELL_CANCEL = 'sell_cancel'
PROTECTION_TRIGGER = 'protection_trigger'
PROTECTION_TRIGGER_GLOBAL = 'protection_trigger_global'
SHORT = 'short'
SHORT_FILL = 'short_fill'
SHORT_CANCEL = 'short_cancel'
# TODO: The below messagetypes should be renamed to "exit"!
# Careful - has an impact on webhooks, therefore needs proper communication
SELL = 'sell'
SELL_FILL = 'sell_fill'
SELL_CANCEL = 'sell_cancel'
PROTECTION_TRIGGER = 'protection_trigger'
PROTECTION_TRIGGER_GLOBAL = 'protection_trigger_global'
def __repr__(self):
return self.value

View File

@@ -503,7 +503,7 @@ class Exchange:
# Note: ccxt has BaseCurrency/QuoteCurrency format for pairs
if self.markets and pair not in self.markets:
raise OperationalException(
f'Pair {pair} is not available on {self.name}. '
f'Pair {pair} is not available on {self.name} {self.trading_mode.value}. '
f'Please remove {pair} from your whitelist.')
# From ccxt Documentation:
@@ -1533,7 +1533,6 @@ class Exchange:
:return: Dict of [{(pair, timeframe): Dataframe}]
"""
logger.debug("Refreshing candle (OHLCV) data for %d pairs", len(pair_list))
# TODO-lev: maybe depend this on candle type?
drop_incomplete = self._ohlcv_partial_candle if drop_incomplete is None else drop_incomplete
input_coroutines = []
cached_pairs = []

View File

@@ -740,6 +740,9 @@ class FreqtradeBot(LoggingMixin):
# in case of FOK the order may be filled immediately and fully
elif order_status == 'closed':
# TODO-lev: Evaluate this. Why is setting stake_amount here necessary?
# it should never change in theory - and in case of leveraged orders,
# may be the leveraged amount.
stake_amount = order['cost']
amount = safe_value_fallback(order, 'filled', 'amount')
enter_limit_filled_price = safe_value_fallback(order, 'average', 'price')
@@ -1288,6 +1291,7 @@ class FreqtradeBot(LoggingMixin):
# * Check edge cases, we don't want to make leverage > 1.0 if we don't have to
# * (for leverage modes which aren't isolated futures)
# TODO-lev: The below calculation needs to include leverage ...
trade.stake_amount = trade.amount * trade.open_rate
self.update_trade_state(trade, trade.open_order_id, corder)
@@ -1736,7 +1740,7 @@ class FreqtradeBot(LoggingMixin):
trade.update_fee(fee_cost, fee_currency, fee_rate, order.get('side', ''))
if not isclose(amount, order_amount, abs_tol=constants.MATH_CLOSE_PREC):
# TODO-lev: leverage?
# * Leverage could be a cause for this warning, leverage hasn't been thoroughly tested
logger.warning(f"Amount {amount} does not match amount {trade.amount}")
raise DependencyException("Half bought? Amounts don't match")

View File

@@ -538,7 +538,6 @@ class Backtesting:
sell_candle_time: datetime = sell_row[DATE_IDX].to_pydatetime()
if self.trading_mode == TradingMode.FUTURES:
# TODO-lev: liquidation price?
trade.funding_fees = self.exchange.calculate_funding_fees(
self.futures_data[trade.pair],
amount=trade.amount,

View File

@@ -15,7 +15,7 @@ import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
# TODO-lev: Create a meaningfull short strategy (not just revresed signs).
# TODO: Create a meaningfull short strategy (not just revresed signs).
# This class is a sample. Feel free to customize it.
class SampleShortStrategy(IStrategy):
"""