freqtrade_origin/docs/bot-basics.md

78 lines
4.9 KiB
Markdown
Raw Normal View History

2020-06-14 09:38:56 +00:00
# Freqtrade basics
This page provides you some basic concepts on how Freqtrade works and operates.
2020-06-14 09:38:56 +00:00
## Freqtrade terminology
2021-02-25 18:54:57 +00:00
* **Strategy**: Your trading strategy, telling the bot what to do.
* **Trade**: Open position.
* **Open Order**: Order which is currently placed on the exchange, and is not yet complete.
* **Pair**: Tradable pair, usually in the format of Base/Quote (e.g. XRP/USDT).
2021-02-25 18:54:57 +00:00
* **Timeframe**: Candle length to use (e.g. `"5m"`, `"1h"`, ...).
* **Indicators**: Technical indicators (SMA, EMA, RSI, ...).
* **Limit order**: Limit orders which execute at the defined limit price or better.
* **Market order**: Guaranteed to fill, may move price depending on the order size.
2020-06-14 09:38:56 +00:00
## Fee handling
All profit calculations of Freqtrade include fees. For Backtesting / Hyperopt / Dry-run modes, the exchange default fee is used (lowest tier on the exchange). For live operations, fees are used as applied by the exchange (this includes BNB rebates etc.).
## Bot execution logic
Starting freqtrade in dry-run or live mode (using `freqtrade trade`) will start the bot and start the bot iteration loop.
This will also run the `bot_start()` callback.
By default, the bot loop runs every few seconds (`internals.process_throttle_secs`) and performs the following actions:
2020-06-14 09:38:56 +00:00
* Fetch open trades from persistence.
* Calculate current list of tradable pairs.
* Download OHLCV data for the pairlist including all [informative pairs](strategy-customization.md#get-data-for-non-tradeable-pairs)
2020-06-14 09:38:56 +00:00
This step is only executed once per Candle to avoid unnecessary network traffic.
* Call `bot_loop_start()` strategy callback.
* Analyze strategy per pair.
* Call `populate_indicators()`
* Call `populate_entry_trend()`
2022-03-12 09:50:01 +00:00
* Call `populate_exit_trend()`
2020-06-14 09:38:56 +00:00
* Check timeouts for open orders.
* Calls `check_entry_timeout()` strategy callback for open entry orders.
* Calls `check_exit_timeout()` strategy callback for open exit orders.
* Calls `adjust_entry_price()` strategy callback for open entry orders.
2022-03-22 19:21:24 +00:00
* Verifies existing positions and eventually places exit orders.
* Considers stoploss, ROI and exit-signal, `custom_exit()` and `custom_stoploss()`.
* Determine exit-price based on `exit_pricing` configuration setting or by using the `custom_exit_price()` callback.
2022-03-22 19:21:24 +00:00
* Before a exit order is placed, `confirm_trade_exit()` strategy callback is called.
2022-01-15 14:11:13 +00:00
* Check position adjustments for open trades if enabled by calling `adjust_trade_position()` and place additional order if required.
2020-06-14 09:38:56 +00:00
* Check if trade-slots are still available (if `max_open_trades` is reached).
2022-03-22 19:21:24 +00:00
* Verifies entry signal trying to enter new positions.
* Determine entry-price based on `entry_pricing` configuration setting, or by using the `custom_entry_price()` callback.
2021-11-19 18:23:48 +00:00
* In Margin and Futures mode, `leverage()` strategy callback is called to determine the desired leverage.
* Determine stake size by calling the `custom_stake_amount()` callback.
2022-03-23 05:48:00 +00:00
* Before an entry order is placed, `confirm_trade_entry()` strategy callback is called.
2020-06-14 09:38:56 +00:00
This loop will be repeated again and again until the bot is stopped.
## Backtesting / Hyperopt execution logic
[backtesting](backtesting.md) or [hyperopt](hyperopt.md) do only part of the above logic, since most of the trading operations are fully simulated.
* Load historic data for configured pairlist.
* Calls `bot_start()` once.
* Calls `bot_loop_start()` once.
* Calculate indicators (calls `populate_indicators()` once per pair).
2022-03-22 19:21:24 +00:00
* Calculate entry / exit signals (calls `populate_entry_trend()` and `populate_exit_trend()` once per pair).
2020-06-14 09:38:56 +00:00
* Loops per candle simulating entry and exit points.
2022-03-29 04:58:41 +00:00
* Check for Order timeouts, either via the `unfilledtimeout` configuration, or via `check_entry_timeout()` / `check_exit_timeout()` strategy callbacks.
2022-05-07 15:47:37 +00:00
* Calls `adjust_entry_price()` strategy callback for open entry orders.
2022-03-29 04:58:41 +00:00
* Check for trade entry signals (`enter_long` / `enter_short` columns).
2022-03-22 19:21:24 +00:00
* Confirm trade entry / exits (calls `confirm_trade_entry()` and `confirm_trade_exit()` if implemented in the strategy).
* Call `custom_entry_price()` (if implemented in the strategy) to determine entry price (Prices are moved to be within the opening candle).
2022-03-03 19:24:06 +00:00
* In Margin and Futures mode, `leverage()` strategy callback is called to determine the desired leverage.
* Determine stake size by calling the `custom_stake_amount()` callback.
2022-01-15 14:11:13 +00:00
* Check position adjustments for open trades if enabled and call `adjust_trade_position()` to determine if an additional order is requested.
2022-03-12 10:07:31 +00:00
* Call `custom_stoploss()` and `custom_exit()` to find custom exit points.
* For exits based on exit-signal, custom-exit and partial exits: Call `custom_exit_price()` to determine exit price (Prices are moved to be within the closing candle).
2020-06-14 09:38:56 +00:00
* Generate backtest report output
!!! Note
Both Backtesting and Hyperopt include exchange default Fees in the calculation. Custom fees can be passed to backtesting / hyperopt by specifying the `--fee` argument.