• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

freqtrade / freqtrade / 14507242113

02 Dec 2024 07:11PM UTC coverage: 94.422% (+0.05%) from 94.377%
14507242113

push

github

web-flow
Merge pull request #11028 from xzmeng/fix-none

fix: check if days is None before conversion

1 of 1 new or added line in 1 file covered. (100.0%)

525 existing lines in 54 files now uncovered.

21684 of 22965 relevant lines covered (94.42%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/freqtrade/rpc/api_server/api_pairlists.py
1
import logging
1✔
2
from copy import deepcopy
1✔
3

4
from fastapi import APIRouter, BackgroundTasks, Depends
1✔
5
from fastapi.exceptions import HTTPException
1✔
6

7
from freqtrade.constants import Config
1✔
8
from freqtrade.enums import CandleType
1✔
9
from freqtrade.exceptions import OperationalException
1✔
10
from freqtrade.persistence import FtNoDBContext
1✔
11
from freqtrade.rpc.api_server.api_schemas import (
1✔
12
    BgJobStarted,
13
    ExchangeModePayloadMixin,
14
    PairListsPayload,
15
    PairListsResponse,
16
    WhitelistEvaluateResponse,
17
)
18
from freqtrade.rpc.api_server.deps import get_config, get_exchange
1✔
19
from freqtrade.rpc.api_server.webserver_bgwork import ApiBG
1✔
20

21

22
logger = logging.getLogger(__name__)
1✔
23

24
# Private API, protected by authentication and webserver_mode dependency
25
router = APIRouter()
1✔
26

27

28
@router.get(
1✔
29
    "/pairlists/available", response_model=PairListsResponse, tags=["pairlists", "webserver"]
30
)
31
def list_pairlists(config=Depends(get_config)):
1✔
32
    from freqtrade.resolvers import PairListResolver
1✔
33

34
    pairlists = PairListResolver.search_all_objects(config, False)
1✔
35
    pairlists = sorted(pairlists, key=lambda x: x["name"])
1✔
36

37
    return {
1✔
38
        "pairlists": [
39
            {
40
                "name": x["name"],
41
                "is_pairlist_generator": x["class"].is_pairlist_generator,
42
                "params": x["class"].available_parameters(),
43
                "description": x["class"].description(),
44
            }
45
            for x in pairlists
46
        ]
47
    }
48

49

50
def __run_pairlist(job_id: str, config_loc: Config):
1✔
51
    try:
1✔
52
        ApiBG.jobs[job_id]["is_running"] = True
1✔
53
        from freqtrade.plugins.pairlistmanager import PairListManager
1✔
54

55
        with FtNoDBContext():
1✔
56
            exchange = get_exchange(config_loc)
1✔
57
            pairlists = PairListManager(exchange, config_loc)
1✔
58
            pairlists.refresh_pairlist()
1✔
59
            ApiBG.jobs[job_id]["result"] = {
1✔
60
                "method": pairlists.name_list,
61
                "length": len(pairlists.whitelist),
62
                "whitelist": pairlists.whitelist,
63
            }
64
            ApiBG.jobs[job_id]["status"] = "success"
1✔
65
    except (OperationalException, Exception) as e:
×
66
        logger.exception(e)
×
67
        ApiBG.jobs[job_id]["error"] = str(e)
×
68
        ApiBG.jobs[job_id]["status"] = "failed"
×
69
    finally:
70
        ApiBG.jobs[job_id]["is_running"] = False
1✔
71
        ApiBG.pairlist_running = False
1✔
72

73

74
@router.post("/pairlists/evaluate", response_model=BgJobStarted, tags=["pairlists", "webserver"])
1✔
75
def pairlists_evaluate(
1✔
76
    payload: PairListsPayload, background_tasks: BackgroundTasks, config=Depends(get_config)
77
):
78
    if ApiBG.pairlist_running:
1✔
79
        raise HTTPException(status_code=400, detail="Pairlist evaluation is already running.")
1✔
80

81
    config_loc = deepcopy(config)
1✔
82
    config_loc["stake_currency"] = payload.stake_currency
1✔
83
    config_loc["pairlists"] = payload.pairlists
1✔
84
    handleExchangePayload(payload, config_loc)
1✔
85
    # TODO: overwrite blacklist? make it optional and fall back to the one in config?
86
    # Outcome depends on the UI approach.
87
    config_loc["exchange"]["pair_blacklist"] = payload.blacklist
1✔
88
    # Random job id
89
    job_id = ApiBG.get_job_id()
1✔
90

91
    ApiBG.jobs[job_id] = {
1✔
92
        "category": "pairlist",
93
        "status": "pending",
94
        "progress": None,
95
        "is_running": False,
96
        "result": {},
97
        "error": None,
98
    }
99
    background_tasks.add_task(__run_pairlist, job_id, config_loc)
1✔
100
    ApiBG.pairlist_running = True
1✔
101

102
    return {
1✔
103
        "status": "Pairlist evaluation started in background.",
104
        "job_id": job_id,
105
    }
106

107

108
def handleExchangePayload(payload: ExchangeModePayloadMixin, config_loc: Config):
1✔
109
    """
110
    Handle exchange and trading mode payload.
111
    Updates the configuration with the payload values.
112
    """
113
    if payload.exchange:
1✔
114
        config_loc["exchange"]["name"] = payload.exchange
1✔
115
    if payload.trading_mode:
1✔
116
        config_loc["trading_mode"] = payload.trading_mode
1✔
117
        config_loc["candle_type_def"] = CandleType.get_default(
1✔
118
            config_loc.get("trading_mode", "spot") or "spot"
119
        )
120
    if payload.margin_mode:
1✔
121
        config_loc["margin_mode"] = payload.margin_mode
1✔
122

123

124
@router.get(
1✔
125
    "/pairlists/evaluate/{jobid}",
126
    response_model=WhitelistEvaluateResponse,
127
    tags=["pairlists", "webserver"],
128
)
129
def pairlists_evaluate_get(jobid: str):
1✔
130
    if not (job := ApiBG.jobs.get(jobid)):
1✔
131
        raise HTTPException(status_code=404, detail="Job not found.")
1✔
132

133
    if job["is_running"]:
1✔
UNCOV
134
        raise HTTPException(status_code=400, detail="Job not finished yet.")
×
135

136
    if error := job["error"]:
1✔
UNCOV
137
        return {
×
138
            "status": "failed",
139
            "error": error,
140
        }
141

142
    return {
1✔
143
        "status": "success",
144
        "result": job["result"],
145
    }
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc