Fixed issues raised in PR

This commit is contained in:
Rahul 2023-02-27 22:51:22 +00:00
parent 2261cbd92e
commit 39331b59ed
4 changed files with 47 additions and 20 deletions

View File

@ -179,7 +179,7 @@ official commands. You can ask at any moment for help with `/help`.
| `/count` | Displays number of trades used and available | `/count` | Displays number of trades used and available
| `/locks` | Show currently locked pairs. | `/locks` | Show currently locked pairs.
| `/unlock <pair or lock_id>` | Remove the lock for this pair (or for this lock id). | `/unlock <pair or lock_id>` | Remove the lock for this pair (or for this lock id).
| `/marketdir [long | short | even | none]` | Updates the user managed variable that represents the current market direction. | `/marketdir [long | short | even | none]` | Updates the user managed variable that represents the current market direction. If no direction is provided, the currently set direction will be displayed.
| **Modify Trade states** | | **Modify Trade states** |
| `/forceexit <trade_id> | /fx <tradeid>` | Instantly exits the given trade (Ignoring `minimum_roi`). | `/forceexit <trade_id> | /fx <tradeid>` | Instantly exits the given trade (Ignoring `minimum_roi`).
| `/forceexit all | /fx all` | Instantly exits all open trades (Ignoring `minimum_roi`). | `/forceexit all | /fx all` | Instantly exits all open trades (Ignoring `minimum_roi`).
@ -420,6 +420,12 @@ ARDR/ETH 0.366667 0.143059 -0.01
### /marketdir ### /marketdir
Updates the user managed variable that represents the current market direction. This variable is not set If a market direction is provided the command updates the user managed variable that represents the current market direction.
to any valid market direction on bot startup and must be set by the user. As an example `/marketdir long` This variable is not set to any valid market direction on bot startup and must be set by the user. The example below is for `/marketdir long`:
would set the variable to be `long`. ```
Successfully updated marketdirection from none to long.
```
If no market direction is provided the command outputs the currently set market directions. The example below is for `/marketdir`:
```
Currently set marketdirection: even
```

View File

@ -8,4 +8,8 @@ class MarketDirection(Enum):
LONG = "long" LONG = "long"
SHORT = "short" SHORT = "short"
EVEN = "even" EVEN = "even"
NONE = '' NONE = "none"
def __str__(self):
# convert to string
return self.value

View File

@ -1206,5 +1206,8 @@ class RPC:
'last_process_ts': int(last_p.timestamp()), 'last_process_ts': int(last_p.timestamp()),
} }
def _update_market_direction(self, direction: MarketDirection): def _update_market_direction(self, direction: MarketDirection) -> None:
self._freqtrade.strategy.market_direction = direction self._freqtrade.strategy.market_direction = direction
def _get_market_direction(self) -> MarketDirection:
return self._freqtrade.strategy.market_direction

View File

@ -129,7 +129,8 @@ class Telegram(RPCHandler):
r'/weekly$', r'/weekly \d+$', r'/monthly$', r'/monthly \d+$', r'/weekly$', r'/weekly \d+$', r'/monthly$', r'/monthly \d+$',
r'/forcebuy$', r'/forcelong$', r'/forceshort$', r'/forcebuy$', r'/forcelong$', r'/forceshort$',
r'/forcesell$', r'/forceexit$', r'/forcesell$', r'/forceexit$',
r'/edge$', r'/health$', r'/help$', r'/version$', r'/marketdir (long|short|even|none)$' r'/edge$', r'/health$', r'/help$', r'/version$', r'/marketdir (long|short|even|none)$',
r'/marketdir$'
] ]
# Create keys for generation # Create keys for generation
valid_keys_print = [k.replace('$', '') for k in valid_keys] valid_keys_print = [k.replace('$', '') for k in valid_keys]
@ -1496,7 +1497,8 @@ class Telegram(RPCHandler):
"*/edge:* `Shows validated pairs by Edge if it is enabled` \n" "*/edge:* `Shows validated pairs by Edge if it is enabled` \n"
"*/health* `Show latest process timestamp - defaults to 1970-01-01 00:00:00` \n" "*/health* `Show latest process timestamp - defaults to 1970-01-01 00:00:00` \n"
"*/marketdir [long | short | even | none]:* `Updates the user managed variable " "*/marketdir [long | short | even | none]:* `Updates the user managed variable "
" that represents the current market direction` \n" "that represents the current market direction. If no direction is provided `"
"`the currently set market direction will be output.` \n"
"_Statistics_\n" "_Statistics_\n"
"------------\n" "------------\n"
@ -1691,16 +1693,28 @@ class Telegram(RPCHandler):
:return: None :return: None
""" """
if context.args and len(context.args) == 1: if context.args and len(context.args) == 1:
new_market_dir = context.args[0] new_market_dir_arg = context.args[0]
if new_market_dir == "long": old_market_dir = self._rpc._get_market_direction()
self._rpc._update_market_direction(MarketDirection.LONG) new_market_dir = None
elif new_market_dir == "short": if new_market_dir_arg == "long":
self._rpc._update_market_direction(MarketDirection.SHORT) new_market_dir = MarketDirection.LONG
elif new_market_dir == "even": elif new_market_dir_arg == "short":
self._rpc._update_market_direction(MarketDirection.EVEN) new_market_dir = MarketDirection.SHORT
elif new_market_dir == "none": elif new_market_dir_arg == "even":
self._rpc._update_market_direction(MarketDirection.NONE) new_market_dir = MarketDirection.EVEN
elif new_market_dir_arg == "none":
new_market_dir = MarketDirection.NONE
if new_market_dir is not None:
self._rpc._update_market_direction(new_market_dir)
self._send_msg("Successfully updated market direction"
f" from *{old_market_dir}* to *{new_market_dir}*.")
else: else:
raise RPCException("Invalid market direction provided") raise RPCException("Invalid market direction provided. \n"
"Valid market directions: *long, short, even, none*")
elif context.args is not None and len(context.args) == 0:
old_market_dir = self._rpc._get_market_direction()
self._send_msg(f"Currently set market direction: *{old_market_dir}*")
else: else:
raise RPCException("Invalid usage of command /marketdir.") raise RPCException("Invalid usage of command /marketdir. \n"
"Usage: */marketdir [short | long | even | none]*")