2020-06-14 09:38:56 +00:00
# Freqtrade basics
2020-07-04 07:43:49 +00:00
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.
2021-08-31 05:18:09 +00:00
* **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.
By default, loop runs every few seconds (`internals.process_throttle_secs`) and does roughly the following in the following sequence:
* Fetch open trades from persistence.
* Calculate current list of tradable pairs.
2022-03-18 05:38:54 +00:00
* 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()`
2022-03-12 09:49:00 +00:00
* 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.
2022-03-22 19:21:24 +00:00
* Calls `check_buy_timeout()` strategy callback for open entry orders.
* Calls `check_sell_timeout()` strategy callback for open exit orders.
* Verifies existing positions and eventually places exit orders.
* Considers stoploss, ROI and exit-signal, `custom_exit()` and `custom_stoploss()` .
* Determine exit-price based on `ask_strategy` configuration setting or by using the `custom_exit_price()` callback.
* 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 `bid_strategy` 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.
2022-03-19 14:27:06 +00:00
* Determine stake size by calling the `custom_stake_amount()` callback.
2022-03-03 19:24:06 +00:00
* Before a buy 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.
2020-10-11 17:50:37 +00:00
* 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-22 19:21:24 +00:00
* Confirm trade entry / exits (calls `confirm_trade_entry()` and `confirm_trade_exit()` if implemented in the strategy).
2021-12-03 16:44:53 +00:00
* 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.
2022-03-19 14:27:06 +00:00
* 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.
2022-03-22 19:21:24 +00:00
* For exits based on exit-signal and custom-exit: Call `custom_exit_price()` to determine exit price (Prices are moved to be within the closing candle).
2022-02-06 12:37:31 +00:00
* Check for Order timeouts, either via the `unfilledtimeout` configuration, or via `check_buy_timeout()` / `check_sell_timeout()` strategy callbacks.
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.