| 1 | ## Prices used for orders |
| 2 | |
| 3 | Prices for regular orders can be controlled via the parameter structures `bid_strategy` for buying and `ask_strategy` for selling. |
| 4 | Prices are always retrieved right before an order is placed, either by querying the exchange tickers or by using the orderbook data. |
| 5 | |
| 6 | !!! Note |
| 7 | Orderbook data used by Freqtrade are the data retrieved from exchange by the ccxt's function `fetch_order_book()`, i.e. are usually data from the L2-aggregated orderbook, while the ticker data are the structures returned by the ccxt's `fetch_ticker()`/`fetch_tickers()` functions. Refer to the ccxt library [documentation](https://github.com/ccxt/ccxt/wiki/Manual#market-data) for more details. |
| 8 | |
| 9 | !!! Warning "Using market orders" |
| 10 | Please read the section [Market order pricing](#market-order-pricing) section when using market orders. |
| 11 | |
| 12 | ### Buy price |
| 13 | |
| 14 | #### Check depth of market |
| 15 | |
| 16 | When check depth of market is enabled (`bid_strategy.check_depth_of_market.enabled=True`), the buy signals are filtered based on the orderbook depth (sum of all amounts) for each orderbook side. |
| 17 | |
| 18 | Orderbook `bid` (buy) side depth is then divided by the orderbook `ask` (sell) side depth and the resulting delta is compared to the value of the `bid_strategy.check_depth_of_market.bids_to_ask_delta` parameter. The buy order is only executed if the orderbook delta is greater than or equal to the configured delta value. |
| 19 | |
| 20 | !!! Note |
| 21 | A delta value below 1 means that `ask` (sell) orderbook side depth is greater than the depth of the `bid` (buy) orderbook side, while a value greater than 1 means opposite (depth of the buy side is higher than the depth of the sell side). |
| 22 | |
| 23 | #### Buy price side |
| 24 | |
| 25 | The configuration setting `bid_strategy.price_side` defines the side of the spread the bot looks for when buying. |
| 26 | |
| 27 | The following displays an orderbook. |
| 28 | |
| 29 | ``` explanation |
| 30 | ... |
| 31 | 103 |
| 32 | 102 |
| 33 | 101 # ask |
| 34 | -------------Current spread |
| 35 | 99 # bid |
| 36 | 98 |
| 37 | 97 |
| 38 | ... |
| 39 | ``` |
| 40 | |
| 41 | If `bid_strategy.price_side` is set to `"bid"`, then the bot will use 99 as buying price. |
| 42 | In line with that, if `bid_strategy.price_side` is set to `"ask"`, then the bot will use 101 as buying price. |
| 43 | |
| 44 | Using `ask` price often guarantees quicker filled orders, but the bot can also end up paying more than what would have been necessary. |
| 45 | Taker fees instead of maker fees will most likely apply even when using limit buy orders. |
| 46 | Also, prices at the "ask" side of the spread are higher than prices at the "bid" side in the orderbook, so the order behaves similar to a market order (however with a maximum price). |
| 47 | |
| 48 | #### Buy price with Orderbook enabled |
| 49 | |
| 50 | When buying with the orderbook enabled (`bid_strategy.use_order_book=True`), Freqtrade fetches the `bid_strategy.order_book_top` entries from the orderbook and then uses the entry specified as `bid_strategy.order_book_top` on the configured side (`bid_strategy.price_side`) of the orderbook. 1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on. |
| 51 | |
| 52 | #### Buy price without Orderbook enabled |
| 53 | |
| 54 | The following section uses `side` as the configured `bid_strategy.price_side`. |
| 55 | |
| 56 | When not using orderbook (`bid_strategy.use_order_book=False`), Freqtrade uses the best `side` price from the ticker if it's below the `last` traded price from the ticker. Otherwise (when the `side` price is above the `last` price), it calculates a rate between `side` and `last` price. |
| 57 | |
| 58 | The `bid_strategy.ask_last_balance` configuration parameter controls this. A value of `0.0` will use `side` price, while `1.0` will use the `last` price and values between those interpolate between ask and last price. |
| 59 | |
| 60 | ### Sell price |
| 61 | |
| 62 | #### Sell price side |
| 63 | |
| 64 | The configuration setting `ask_strategy.price_side` defines the side of the spread the bot looks for when selling. |
| 65 | |
| 66 | The following displays an orderbook: |
| 67 | |
| 68 | ``` explanation |
| 69 | ... |
| 70 | 103 |
| 71 | 102 |
| 72 | 101 # ask |
| 73 | -------------Current spread |
| 74 | 99 # bid |
| 75 | 98 |
| 76 | 97 |
| 77 | ... |
| 78 | ``` |
| 79 | |
| 80 | If `ask_strategy.price_side` is set to `"ask"`, then the bot will use 101 as selling price. |
| 81 | In line with that, if `ask_strategy.price_side` is set to `"bid"`, then the bot will use 99 as selling price. |
| 82 | |
| 83 | #### Sell price with Orderbook enabled |
| 84 | |
| 85 | When selling with the orderbook enabled (`ask_strategy.use_order_book=True`), Freqtrade fetches the `ask_strategy.order_book_max` entries in the orderbook. Then each of the orderbook steps between `ask_strategy.order_book_min` and `ask_strategy.order_book_max` on the configured orderbook side are validated for a profitable sell-possibility based on the strategy configuration (`minimal_roi` conditions) and the sell order is placed at the first profitable spot. |
| 86 | |
| 87 | !!! Note |
| 88 | Using `order_book_max` higher than `order_book_min` only makes sense when ask_strategy.price_side is set to `"ask"`. |
| 89 | |
| 90 | The idea here is to place the sell order early, to be ahead in the queue. |
| 91 | |
| 92 | A fixed slot (mirroring `bid_strategy.order_book_top`) can be defined by setting `ask_strategy.order_book_min` and `ask_strategy.order_book_max` to the same number. |
| 93 | |
| 94 | !!! Warning "Order_book_max > 1 - increased risks for stoplosses!" |
| 95 | Using `ask_strategy.order_book_max` higher than 1 will increase the risk the stoploss on exchange is cancelled too early, since an eventual [stoploss on exchange](#understand-order_types) will be cancelled as soon as the order is placed. |
| 96 | Also, the sell order will remain on the exchange for `unfilledtimeout.sell` (or until it's filled) - which can lead to missed stoplosses (with or without using stoploss on exchange). |
| 97 | |
| 98 | !!! Warning "Order_book_max > 1 in dry-run" |
| 99 | Using `ask_strategy.order_book_max` higher than 1 will result in improper dry-run results (significantly better than real orders executed on exchange), since dry-run assumes orders to be filled almost instantly. |
| 100 | It is therefore advised to not use this setting for dry-runs. |
| 101 | |
| 102 | #### Sell price without Orderbook enabled |
| 103 | |
| 104 | When not using orderbook (`ask_strategy.use_order_book=False`), the price at the `ask_strategy.price_side` side (defaults to `"ask"`) from the ticker will be used as the sell price. |
| 105 | |
| 106 | When not using orderbook (`ask_strategy.use_order_book=False`), Freqtrade uses the best `side` price from the ticker if it's below the `last` traded price from the ticker. Otherwise (when the `side` price is above the `last` price), it calculates a rate between `side` and `last` price. |
| 107 | |
| 108 | The `ask_strategy.bid_last_balance` configuration parameter controls this. A value of `0.0` will use `side` price, while `1.0` will use the last price and values between those interpolate between `side` and last price. |
| 109 | |
| 110 | ### Market order pricing |
| 111 | |
| 112 | When using market orders, prices should be configured to use the "correct" side of the orderbook to allow realistic pricing detection. |
| 113 | Assuming both buy and sell are using market orders, a configuration similar to the following might be used |
| 114 | |
| 115 | ``` jsonc |
| 116 | "order_types": { |
| 117 | "buy": "market", |
| 118 | "sell": "market" |
| 119 | // ... |
| 120 | }, |
| 121 | "bid_strategy": { |
| 122 | "price_side": "ask", |
| 123 | // ... |
| 124 | }, |
| 125 | "ask_strategy":{ |
| 126 | "price_side": "bid", |
| 127 | // ... |
| 128 | }, |
| 129 | ``` |
| 130 | |
| 131 | Obviously, if only one side is using limit orders, different pricing combinations can be used. |