Slighlty improve docs

This commit is contained in:
Matthias
2024-02-12 18:17:48 +01:00
parent 626c904103
commit d49da76382
+19 -4
View File
@@ -13,6 +13,13 @@ The call sequence of the methods described here is covered under [bot execution
## Storing information (Non-Persistent) ## Storing information (Non-Persistent)
!!! Warning "Deprecated"
This method of storing information is deprecated, and we do advise against using non-persistent storage.
Please use the below [Persistent Storing Information Section](#storing-information-persistent) instead.
It's content has therefore be collapsed.
??? Abstract "Storing information"
Storing information can be accomplished by creating a new dictionary within the strategy class. Storing information can be accomplished by creating a new dictionary within the strategy class.
The name of the variable can be chosen at will, but should be prefixed with `custom_` to avoid naming collisions with predefined strategy variables. The name of the variable can be chosen at will, but should be prefixed with `custom_` to avoid naming collisions with predefined strategy variables.
@@ -43,8 +50,9 @@ class AwesomeStrategy(IStrategy):
## Storing information (Persistent) ## Storing information (Persistent)
Storing information can also be performed in a persistent manner. Freqtrade allows storing/retrieving user custom information associated with a specific trade. Storing information can also be performed in a persistent manner. Freqtrade allows storing/retrieving user custom information associated with a specific trade.
Using a trade object handle information can be stored using `trade_obj.set_custom_data(key='my_key', value=my_value)` and retrieved using `trade_obj.get_custom_data(key='my_key')`.
Each data entry is associated with a trade and a user supplied key (of type `string`). This means that this can only be used in callbacks that also provide a trade object handle. Using a trade object, information can be stored using `trade_obj.set_custom_data(key='my_key', value=my_value)` and retrieved using `trade_obj.get_custom_data(key='my_key')`. Each data entry is associated with a trade and a user supplied key (of type `string`). This means that this can only be used in callbacks that also provide a trade object.
For the data to be able to be stored within the database it must be serialized. This is done by converting it to a JSON formatted string. For the data to be able to be stored within the database it must be serialized. This is done by converting it to a JSON formatted string.
```python ```python
@@ -69,7 +77,13 @@ class AwesomeStrategy(IStrategy):
current_time: datetime, proposed_rate: float, current_order_rate: float, current_time: datetime, proposed_rate: float, current_order_rate: float,
entry_tag: Optional[str], side: str, **kwargs) -> float: entry_tag: Optional[str], side: str, **kwargs) -> float:
# Limit orders to use and follow SMA200 as price target for the first 10 minutes since entry trigger for BTC/USDT pair. # Limit orders to use and follow SMA200 as price target for the first 10 minutes since entry trigger for BTC/USDT pair.
if pair == 'BTC/USDT' and entry_tag == 'long_sma200' and side == 'long' and (current_time - timedelta(minutes=10) > trade.open_date_utc and order.filled == 0.0: if (
pair == 'BTC/USDT'
and entry_tag == 'long_sma200'
and side == 'long'
and (current_time - timedelta(minutes=10)) > trade.open_date_utc
and order.filled == 0.0
):
dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe) dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)
current_candle = dataframe.iloc[-1].squeeze() current_candle = dataframe.iloc[-1].squeeze()
# store information about entry adjustment # store information about entry adjustment
@@ -104,8 +118,9 @@ class AwesomeStrategy(IStrategy):
!!! Note !!! Note
It is recommended that simple data types are used `[bool, int, float, str]` to ensure no issues when serializing the data that needs to be stored. It is recommended that simple data types are used `[bool, int, float, str]` to ensure no issues when serializing the data that needs to be stored.
Storing big junks of data may lead to unintended side-effects, like a database becoming big pretty fast (and as a consequence, also slow).
!!! Warning !!! Warning "Non-serializable data"
If supplied data cannot be serialized a warning is logged and the entry for the specified `key` will contain `None` as data. If supplied data cannot be serialized a warning is logged and the entry for the specified `key` will contain `None` as data.
## Dataframe access ## Dataframe access