get_kval() -> get_kvals(). Update docs also.

This commit is contained in:
eSeR1805 2022-06-13 20:03:22 +03:00
parent f3dee5ec4f
commit c719860a16
No known key found for this signature in database
GPG Key ID: BA53686259B46936
2 changed files with 12 additions and 11 deletions

View File

@ -43,7 +43,7 @@ class AwesomeStrategy(IStrategy):
## 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.
Using a trade object handle information can be stored using `trade_obj.set_kval(key='my_key', value=my_value)` and retrieved using `trade_obj.get_kval(key='my_key')`.
Using a trade object handle information can be stored using `trade_obj.set_kval(key='my_key', value=my_value)` and retrieved using `trade_obj.get_kvals(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.
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.
@ -57,7 +57,7 @@ class AwesomeStrategy(IStrategy):
for trade in Trade.get_open_order_trades():
fills = trade.select_filled_orders(trade.entry_side)
if trade.pair == 'ETH/USDT':
trade_entry_type = trade.get_kval(key='entry_type')
trade_entry_type = trade.get_kvals(key='entry_type').kv_value
if trade_entry_type is None:
trade_entry_type = 'breakout' if 'entry_1' in trade.enter_tag else 'dip'
elif fills > 1:
@ -73,7 +73,7 @@ class AwesomeStrategy(IStrategy):
dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)
current_candle = dataframe.iloc[-1].squeeze()
# store information about entry adjustment
existing_count = trade.get_kval(key='num_entry_adjustments')
existing_count = trade.get_kvals(key='num_entry_adjustments').kv_value
if not existing_count:
existing_count = 1
else:
@ -88,8 +88,8 @@ class AwesomeStrategy(IStrategy):
def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs):
entry_adjustment_count = trade.get_kval(key='num_entry_adjustments')
trade_entry_type = trade.get_kval(key='entry_type')
entry_adjustment_count = trade.get_kvals(key='num_entry_adjustments').kv_value
trade_entry_type = trade.get_kvals(key='entry_type').kv_value
if entry_adjustment_count is None:
if current_profit > 0.01 and (current_time - timedelta(minutes=100) > trade.open_date_utc):
return True, 'exit_1'

View File

@ -923,7 +923,7 @@ class LocalTrade():
def set_kval(self, key: str, value: Any) -> None:
KeyValues.set_kval(key=key, value=value, trade_id=self.id)
def get_kval(self, key: Optional[str]) -> List[KeyValue]:
def get_kvals(self, key: Optional[str]) -> List[KeyValue]:
return KeyValues.get_kval(key=key, trade_id=self.id)
@property
@ -1127,12 +1127,13 @@ class Trade(_DECL_BASE, LocalTrade):
for order in self.orders:
Order.query.session.delete(order)
for kval in self.keyvalues:
KeyValue.query.session.delete(kval)
Trade.query.session.delete(self)
Trade.commit()
for kval in self.keyvalues:
KeyValue.query.session.delete(kval)
KeyValue.query.session.commit()
@staticmethod
def commit():
Trade.query.session.commit()
@ -1409,5 +1410,5 @@ class Trade(_DECL_BASE, LocalTrade):
def set_kval(self, key: str, value: Any) -> None:
super().set_kval(key=key, value=value)
def get_kval(self, key: Optional[str]) -> List[KeyValue]:
return super().get_kval(key=key)
def get_kvals(self, key: Optional[str]) -> List[KeyValue]:
return super().get_kvals(key=key)