2020-03-01 08:35:53 +00:00
|
|
|
|
2020-06-14 05:00:55 +00:00
|
|
|
def bot_loop_start(self, **kwargs) -> None:
|
|
|
|
"""
|
|
|
|
Called at the start of the bot iteration (one loop).
|
|
|
|
Might be used to perform pair-independent tasks
|
|
|
|
(e.g. gather some remote ressource for comparison)
|
2020-06-14 08:08:19 +00:00
|
|
|
|
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
|
|
|
|
|
|
When not implemented by a strategy, this simply does nothing.
|
2020-06-14 05:00:55 +00:00
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2022-01-23 18:40:12 +00:00
|
|
|
def custom_entry_price(self, pair: str, current_time: 'datetime', proposed_rate: float,
|
2022-05-07 09:55:49 +00:00
|
|
|
entry_tag: 'Optional[str]', side: str, **kwargs) -> float:
|
2022-01-23 18:40:12 +00:00
|
|
|
"""
|
|
|
|
Custom entry price logic, returning the new entry price.
|
|
|
|
|
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
|
|
|
|
|
|
When not implemented by a strategy, returns None, orderbook is used to set entry price
|
|
|
|
|
|
|
|
:param pair: Pair that's currently analyzed
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
2022-03-27 16:03:49 +00:00
|
|
|
:param proposed_rate: Rate, calculated based on pricing settings in exit_pricing.
|
2022-01-23 18:40:12 +00:00
|
|
|
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
|
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
|
|
:return float: New entry price value if provided
|
|
|
|
"""
|
|
|
|
return proposed_rate
|
|
|
|
|
2022-05-06 04:30:35 +00:00
|
|
|
def adjust_entry_price(self, trade: 'Trade', order: 'Optional[Order]', pair: str,
|
2022-04-28 21:10:17 +00:00
|
|
|
current_time: datetime, proposed_rate: float, current_order_rate: float,
|
|
|
|
entry_tag: Optional[str], side: str, **kwargs) -> float:
|
|
|
|
"""
|
|
|
|
Entry price re-adjustment logic, returning the user desired limit price.
|
2022-05-06 04:23:06 +00:00
|
|
|
This only executes when a order was already placed, still open (unfilled fully or partially)
|
2022-04-28 21:10:17 +00:00
|
|
|
and not timed out on subsequent candles after entry trigger.
|
|
|
|
|
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-callbacks/
|
|
|
|
|
|
|
|
When not implemented by a strategy, returns current_order_rate as default.
|
|
|
|
If current_order_rate is returned then the existing order is maintained.
|
|
|
|
If None is returned then order gets canceled but not replaced by a new one.
|
|
|
|
|
|
|
|
:param pair: Pair that's currently analyzed
|
|
|
|
:param trade: Trade object.
|
|
|
|
:param order: Order object
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
|
|
|
:param proposed_rate: Rate, calculated based on pricing settings in entry_pricing.
|
|
|
|
:param current_order_rate: Rate of the existing order in place.
|
|
|
|
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
|
|
|
|
:param side: 'long' or 'short' - indicating the direction of the proposed trade
|
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
|
|
:return float: New entry price value if provided
|
|
|
|
|
|
|
|
"""
|
|
|
|
return current_order_rate
|
2022-04-16 12:08:09 +00:00
|
|
|
|
2022-01-23 18:40:12 +00:00
|
|
|
def custom_exit_price(self, pair: str, trade: 'Trade',
|
|
|
|
current_time: 'datetime', proposed_rate: float,
|
2022-04-27 04:42:56 +00:00
|
|
|
current_profit: float, exit_tag: Optional[str], **kwargs) -> float:
|
2022-01-23 18:40:12 +00:00
|
|
|
"""
|
|
|
|
Custom exit price logic, returning the new exit price.
|
|
|
|
|
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
|
|
|
|
|
|
When not implemented by a strategy, returns None, orderbook is used to set exit price
|
|
|
|
|
|
|
|
:param pair: Pair that's currently analyzed
|
|
|
|
:param trade: trade object.
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
2022-03-27 16:03:49 +00:00
|
|
|
:param proposed_rate: Rate, calculated based on pricing settings in exit_pricing.
|
2022-01-23 18:40:12 +00:00
|
|
|
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
2022-04-26 06:39:15 +00:00
|
|
|
:param exit_tag: Exit reason.
|
2022-01-23 18:40:12 +00:00
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
|
|
:return float: New exit price value if provided
|
|
|
|
"""
|
|
|
|
return proposed_rate
|
|
|
|
|
2022-07-08 17:44:20 +00:00
|
|
|
def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,
|
2022-05-07 09:55:49 +00:00
|
|
|
proposed_stake: float, min_stake: Optional[float], max_stake: float,
|
2022-07-08 17:44:20 +00:00
|
|
|
leverage: float, entry_tag: Optional[str], side: str,
|
|
|
|
**kwargs) -> float:
|
2021-08-04 04:46:21 +00:00
|
|
|
"""
|
2021-09-26 17:35:54 +00:00
|
|
|
Customize stake size for each new trade.
|
2021-08-04 04:46:21 +00:00
|
|
|
|
|
|
|
:param pair: Pair that's currently analyzed
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
2022-03-27 16:03:49 +00:00
|
|
|
:param current_rate: Rate, calculated based on pricing settings in exit_pricing.
|
2021-08-04 04:46:21 +00:00
|
|
|
:param proposed_stake: A stake amount proposed by the bot.
|
|
|
|
:param min_stake: Minimal stake size allowed by exchange.
|
|
|
|
:param max_stake: Balance available for trading.
|
2022-07-08 17:44:20 +00:00
|
|
|
:param leverage: Leverage selected for this trade.
|
2022-01-23 18:32:38 +00:00
|
|
|
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
|
2021-09-26 17:35:54 +00:00
|
|
|
:param side: 'long' or 'short' - indicating the direction of the proposed trade
|
2021-08-04 04:46:21 +00:00
|
|
|
:return: A stake size, which is between min_stake and max_stake.
|
|
|
|
"""
|
|
|
|
return proposed_stake
|
|
|
|
|
2020-12-20 10:12:22 +00:00
|
|
|
use_custom_stoploss = True
|
2020-12-20 09:13:47 +00:00
|
|
|
|
2021-04-26 17:27:22 +00:00
|
|
|
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: 'datetime',
|
2021-10-04 17:11:35 +00:00
|
|
|
current_rate: float, current_profit: float, **kwargs) -> float:
|
2020-12-20 09:13:47 +00:00
|
|
|
"""
|
|
|
|
Custom stoploss logic, returning the new distance relative to current_rate (as ratio).
|
|
|
|
e.g. returning -0.05 would create a stoploss 5% below current_rate.
|
|
|
|
The custom stoploss can never be below self.stoploss, which serves as a hard maximum loss.
|
|
|
|
|
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
|
|
|
|
|
|
When not implemented by a strategy, returns the initial stoploss value
|
2020-12-20 10:12:22 +00:00
|
|
|
Only called when use_custom_stoploss is set to True.
|
2020-12-20 09:13:47 +00:00
|
|
|
|
2021-10-04 17:11:35 +00:00
|
|
|
:param pair: Pair that's currently analyzed
|
2020-12-20 09:13:47 +00:00
|
|
|
:param trade: trade object.
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
2022-03-27 16:03:49 +00:00
|
|
|
:param current_rate: Rate, calculated based on pricing settings in exit_pricing.
|
2020-12-20 09:13:47 +00:00
|
|
|
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
2021-10-04 17:11:35 +00:00
|
|
|
:return float: New stoploss value, relative to the current_rate
|
2020-12-20 09:13:47 +00:00
|
|
|
"""
|
|
|
|
return self.stoploss
|
|
|
|
|
2022-03-12 10:15:27 +00:00
|
|
|
def custom_exit(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,
|
2021-08-04 04:46:21 +00:00
|
|
|
current_profit: float, **kwargs) -> 'Optional[Union[str, bool]]':
|
|
|
|
"""
|
2022-04-03 17:39:13 +00:00
|
|
|
Custom exit signal logic indicating that specified position should be sold. Returning a
|
2021-08-04 04:46:21 +00:00
|
|
|
string or True from this method is equal to setting sell signal on a candle at specified
|
|
|
|
time. This method is not called when sell signal is set.
|
|
|
|
|
|
|
|
This method should be overridden to create sell signals that depend on trade parameters. For
|
|
|
|
example you could implement a sell relative to the candle when the trade was opened,
|
|
|
|
or a custom 1:2 risk-reward ROI.
|
|
|
|
|
2022-04-03 17:39:13 +00:00
|
|
|
Custom exit reason max length is 64. Exceeding characters will be removed.
|
2021-08-04 04:46:21 +00:00
|
|
|
|
|
|
|
:param pair: Pair that's currently analyzed
|
|
|
|
:param trade: trade object.
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
2022-03-27 16:03:49 +00:00
|
|
|
:param current_rate: Rate, calculated based on pricing settings in exit_pricing.
|
2021-08-04 04:46:21 +00:00
|
|
|
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
2022-04-03 17:36:32 +00:00
|
|
|
:return: To execute sell, return a string with custom exit reason or True. Otherwise return
|
2021-08-04 04:46:21 +00:00
|
|
|
None or False.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2020-06-14 08:08:19 +00:00
|
|
|
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,
|
2022-05-06 04:30:35 +00:00
|
|
|
time_in_force: str, current_time: datetime, entry_tag: Optional[str],
|
2021-09-26 17:32:24 +00:00
|
|
|
side: str, **kwargs) -> bool:
|
2020-06-14 08:08:19 +00:00
|
|
|
"""
|
2021-09-26 17:32:24 +00:00
|
|
|
Called right before placing a entry order.
|
2020-06-14 08:08:19 +00:00
|
|
|
Timing for this function is critical, so avoid doing heavy computations or
|
2020-06-14 08:49:15 +00:00
|
|
|
network requests in this method.
|
2020-06-14 08:08:19 +00:00
|
|
|
|
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
|
|
|
|
|
|
When not implemented by a strategy, returns True (always confirming).
|
|
|
|
|
2021-09-26 17:32:24 +00:00
|
|
|
:param pair: Pair that's about to be bought/shorted.
|
2020-06-14 08:08:19 +00:00
|
|
|
:param order_type: Order type (as configured in order_types). usually limit or market.
|
2022-05-31 15:52:45 +00:00
|
|
|
:param amount: Amount in target (base) currency that's going to be traded.
|
2020-06-14 08:08:19 +00:00
|
|
|
:param rate: Rate that's going to be used when using limit orders
|
2022-06-09 17:41:08 +00:00
|
|
|
or current rate for market orders.
|
2020-06-14 08:08:19 +00:00
|
|
|
:param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).
|
2021-05-09 07:56:36 +00:00
|
|
|
:param current_time: datetime object, containing the current datetime
|
2022-01-23 18:32:38 +00:00
|
|
|
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
|
2021-09-26 17:32:24 +00:00
|
|
|
:param side: 'long' or 'short' - indicating the direction of the proposed trade
|
2020-06-14 08:08:19 +00:00
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
|
|
|
:return bool: When True is returned, then the buy-order is placed on the exchange.
|
|
|
|
False aborts the process
|
|
|
|
"""
|
|
|
|
return True
|
|
|
|
|
2020-08-06 23:13:36 +00:00
|
|
|
def confirm_trade_exit(self, pair: str, trade: 'Trade', order_type: str, amount: float,
|
2022-03-25 05:37:40 +00:00
|
|
|
rate: float, time_in_force: str, exit_reason: str,
|
2021-05-09 07:56:36 +00:00
|
|
|
current_time: 'datetime', **kwargs) -> bool:
|
2020-06-14 08:08:19 +00:00
|
|
|
"""
|
2022-05-31 15:52:45 +00:00
|
|
|
Called right before placing a regular exit order.
|
2020-06-14 08:08:19 +00:00
|
|
|
Timing for this function is critical, so avoid doing heavy computations or
|
2020-06-14 08:49:15 +00:00
|
|
|
network requests in this method.
|
2020-06-14 08:08:19 +00:00
|
|
|
|
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
|
|
|
|
|
|
When not implemented by a strategy, returns True (always confirming).
|
|
|
|
|
2022-05-31 15:52:45 +00:00
|
|
|
:param pair: Pair for trade that's about to be exited.
|
2020-06-14 08:08:19 +00:00
|
|
|
:param trade: trade object.
|
|
|
|
:param order_type: Order type (as configured in order_types). usually limit or market.
|
2022-05-31 15:52:45 +00:00
|
|
|
:param amount: Amount in base currency.
|
2020-06-14 08:08:19 +00:00
|
|
|
:param rate: Rate that's going to be used when using limit orders
|
2022-06-09 17:41:08 +00:00
|
|
|
or current rate for market orders.
|
2020-06-14 08:08:19 +00:00
|
|
|
:param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).
|
2022-03-25 05:37:40 +00:00
|
|
|
:param exit_reason: Exit reason.
|
2020-06-14 08:08:19 +00:00
|
|
|
Can be any of ['roi', 'stop_loss', 'stoploss_on_exchange', 'trailing_stop_loss',
|
2022-04-04 15:10:02 +00:00
|
|
|
'exit_signal', 'force_exit', 'emergency_exit']
|
2021-05-09 07:56:36 +00:00
|
|
|
:param current_time: datetime object, containing the current datetime
|
2020-06-14 08:08:19 +00:00
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
2022-05-31 15:52:45 +00:00
|
|
|
:return bool: When True, then the exit-order is placed on the exchange.
|
2020-06-14 08:08:19 +00:00
|
|
|
False aborts the process
|
|
|
|
"""
|
|
|
|
return True
|
|
|
|
|
2022-04-16 04:47:56 +00:00
|
|
|
def check_entry_timeout(self, pair: str, trade: 'Trade', order: 'Order',
|
|
|
|
current_time: datetime, **kwargs) -> bool:
|
2020-03-01 08:35:53 +00:00
|
|
|
"""
|
2022-03-25 18:46:56 +00:00
|
|
|
Check entry timeout function callback.
|
|
|
|
This method can be used to override the entry-timeout.
|
|
|
|
It is called whenever a limit entry order has been created,
|
2020-03-01 08:35:53 +00:00
|
|
|
and is not yet fully filled.
|
|
|
|
Configuration options in `unfilledtimeout` will be verified before this,
|
|
|
|
so ensure to set these timeouts high enough.
|
|
|
|
|
2020-03-01 08:40:07 +00:00
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
|
|
|
2020-03-01 08:35:53 +00:00
|
|
|
When not implemented by a strategy, this simply returns False.
|
|
|
|
:param pair: Pair the trade is for
|
2022-04-16 04:47:56 +00:00
|
|
|
:param trade: Trade object.
|
|
|
|
:param order: Order object.
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
2020-03-01 08:35:53 +00:00
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
2022-04-16 04:47:56 +00:00
|
|
|
:return bool: When True is returned, then the entry order is cancelled.
|
2020-03-01 08:35:53 +00:00
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
2022-04-16 04:47:56 +00:00
|
|
|
def check_exit_timeout(self, pair: str, trade: 'Trade', order: 'Order',
|
|
|
|
current_time: datetime, **kwargs) -> bool:
|
2020-03-01 08:35:53 +00:00
|
|
|
"""
|
2022-03-25 18:46:56 +00:00
|
|
|
Check exit timeout function callback.
|
|
|
|
This method can be used to override the exit-timeout.
|
|
|
|
It is called whenever a limit exit order has been created,
|
2020-03-01 08:35:53 +00:00
|
|
|
and is not yet fully filled.
|
|
|
|
Configuration options in `unfilledtimeout` will be verified before this,
|
|
|
|
so ensure to set these timeouts high enough.
|
|
|
|
|
2020-03-01 08:40:07 +00:00
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
|
|
|
2020-03-01 08:35:53 +00:00
|
|
|
When not implemented by a strategy, this simply returns False.
|
|
|
|
:param pair: Pair the trade is for
|
2022-04-16 04:47:56 +00:00
|
|
|
:param trade: Trade object.
|
|
|
|
:param order: Order object.
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
2020-03-01 08:35:53 +00:00
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
2022-04-04 14:59:27 +00:00
|
|
|
:return bool: When True is returned, then the exit-order is cancelled.
|
2020-03-01 08:35:53 +00:00
|
|
|
"""
|
|
|
|
return False
|
2022-01-23 18:40:12 +00:00
|
|
|
|
2022-07-31 12:19:04 +00:00
|
|
|
def adjust_trade_position(self, trade: 'Trade', current_time: datetime,
|
|
|
|
current_rate: float, current_profit: float,
|
|
|
|
min_stake: Optional[float], max_stake: float,
|
|
|
|
current_entry_rate: float, current_exit_rate: float,
|
|
|
|
current_entry_profit: float, current_exit_profit: float,
|
|
|
|
**kwargs) -> Optional[float]:
|
2022-01-23 18:40:12 +00:00
|
|
|
"""
|
2022-07-31 12:19:04 +00:00
|
|
|
Custom trade adjustment logic, returning the stake amount that a trade should be
|
|
|
|
increased or decreased.
|
|
|
|
This means extra buy or sell orders with additional fees.
|
2022-01-23 18:40:12 +00:00
|
|
|
Only called when `position_adjustment_enable` is set to True.
|
|
|
|
|
|
|
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
|
|
|
|
|
|
|
When not implemented by a strategy, returns None
|
|
|
|
|
|
|
|
:param trade: trade object.
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
|
|
|
:param current_rate: Current buy rate.
|
|
|
|
:param current_profit: Current profit (as ratio), calculated based on current_rate.
|
2022-07-31 12:19:04 +00:00
|
|
|
:param min_stake: Minimal stake size allowed by exchange (for both entries and exits)
|
|
|
|
:param max_stake: Maximum stake allowed (either through balance, or by exchange limits).
|
|
|
|
:param current_entry_rate: Current rate using entry pricing.
|
|
|
|
:param current_exit_rate: Current rate using exit pricing.
|
|
|
|
:param current_entry_profit: Current profit using entry pricing.
|
|
|
|
:param current_exit_profit: Current profit using exit pricing.
|
2022-01-23 18:40:12 +00:00
|
|
|
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
2022-07-31 12:19:04 +00:00
|
|
|
:return float: Stake amount to adjust your trade,
|
|
|
|
Positive values to increase position, Negative values to decrease position.
|
|
|
|
Return None for no action.
|
2022-01-23 18:40:12 +00:00
|
|
|
"""
|
|
|
|
return None
|
2022-02-23 19:19:52 +00:00
|
|
|
|
|
|
|
def leverage(self, pair: str, current_time: datetime, current_rate: float,
|
2022-06-05 08:21:06 +00:00
|
|
|
proposed_leverage: float, max_leverage: float, entry_tag: Optional[str],
|
|
|
|
side: str, **kwargs) -> float:
|
2022-02-23 19:19:52 +00:00
|
|
|
"""
|
|
|
|
Customize leverage for each new trade. This method is only called in futures mode.
|
|
|
|
|
|
|
|
:param pair: Pair that's currently analyzed
|
|
|
|
:param current_time: datetime object, containing the current datetime
|
2022-03-27 16:03:49 +00:00
|
|
|
:param current_rate: Rate, calculated based on pricing settings in exit_pricing.
|
2022-02-23 19:19:52 +00:00
|
|
|
:param proposed_leverage: A leverage proposed by the bot.
|
|
|
|
:param max_leverage: Max leverage allowed on this pair
|
2022-06-05 08:21:06 +00:00
|
|
|
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
|
2022-02-23 19:19:52 +00:00
|
|
|
:param side: 'long' or 'short' - indicating the direction of the proposed trade
|
|
|
|
:return: A leverage amount, which is between 1.0 and max_leverage.
|
|
|
|
"""
|
|
|
|
return 1.0
|