Optional RPC dependency
This commit is contained in:
parent
3dc37dd79d
commit
e6176d43f3
@ -18,7 +18,7 @@ from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, Blac
|
||||
StatusMsg, StrategyListResponse, StrategyResponse,
|
||||
TradeResponse, TradeSchema, Version,
|
||||
WhitelistResponse)
|
||||
from freqtrade.rpc.api_server.deps import get_config, get_rpc
|
||||
from freqtrade.rpc.api_server.deps import get_config, get_rpc, get_rpc_optional
|
||||
from freqtrade.rpc.rpc import RPCException
|
||||
|
||||
|
||||
@ -100,8 +100,11 @@ def edge(rpc: RPC = Depends(get_rpc)):
|
||||
|
||||
# TODO: Missing response model
|
||||
@router.get('/show_config', tags=['info'])
|
||||
def show_config(rpc: RPC = Depends(get_rpc), config=Depends(get_config)):
|
||||
return RPC._rpc_show_config(config, rpc._freqtrade.state)
|
||||
def show_config(rpc: Optional[RPC] = Depends(get_rpc_optional), config=Depends(get_config)):
|
||||
state = ''
|
||||
if rpc:
|
||||
state = rpc._freqtrade.state
|
||||
return RPC._rpc_show_config(config, state)
|
||||
|
||||
|
||||
@router.post('/forcebuy', response_model=Union[TradeSchema, StatusMsg], tags=['trading'])
|
||||
|
@ -1,12 +1,22 @@
|
||||
from typing import Any, Dict
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from freqtrade.rpc.rpc import RPC
|
||||
from freqtrade.rpc.rpc import RPC, RPCException
|
||||
|
||||
from .webserver import ApiServer
|
||||
|
||||
|
||||
def get_rpc() -> RPC:
|
||||
def get_rpc_optional() -> Optional[RPC]:
|
||||
if ApiServer._has_rpc:
|
||||
return ApiServer._rpc
|
||||
return None
|
||||
|
||||
|
||||
def get_rpc() -> Optional[RPC]:
|
||||
_rpc = get_rpc_optional()
|
||||
if _rpc:
|
||||
return _rpc
|
||||
else:
|
||||
raise RPCException('Bot is not in the correct state')
|
||||
|
||||
|
||||
def get_config() -> Dict[str, Any]:
|
||||
|
@ -17,6 +17,7 @@ logger = logging.getLogger(__name__)
|
||||
class ApiServer(RPCHandler):
|
||||
|
||||
_rpc: RPC
|
||||
_has_rpc: bool = False
|
||||
_config: Dict[str, Any] = {}
|
||||
|
||||
def __init__(self, rpc: RPC, config: Dict[str, Any]) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user