Improve response models

This commit is contained in:
Matthias 2020-12-27 09:02:35 +01:00
parent 9350f505bc
commit 9f873305eb
4 changed files with 36 additions and 12 deletions

View File

@ -2,10 +2,9 @@ import secrets
from datetime import datetime, timedelta
import jwt
from fastapi import APIRouter, Depends, HTTPException, Request, status
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from fastapi.security.http import HTTPBasic, HTTPBasicCredentials
from pydantic import BaseModel
from freqtrade.rpc.api_server2.api_models import AccessAndRefreshToken, AccessToken

View File

@ -1,7 +1,10 @@
from datetime import date, datetime
from typing import Any, Dict, List, Optional, Union
from datetime import date
from pydantic import BaseModel
from freqtrade.constants import DATETIME_PRINT_FORMAT
class Ping(BaseModel):
status: str
@ -181,3 +184,26 @@ class AvailablePairs(BaseModel):
length: int
pairs: List[str]
pair_interval: List[List[str]]
class PairHistory(BaseModel):
strategy: str
pair: str
timeframe: str
timeframe_ms: int
columns: List[str]
data: List[Any]
length: int
buy_signals: int
sell_signals: int
last_analyzed: datetime
last_analyzed_ts: int
data_start_ts: int
data_start: str
data_stop: str
data_stop_ts: int
class Config:
json_encoders = {
datetime: lambda v: v.strftime(DATETIME_PRINT_FORMAT),
}

View File

@ -1,12 +1,12 @@
from copy import deepcopy
from freqtrade.constants import USERPATH_STRATEGIES
from typing import Dict, List, Optional, Union
from pathlib import Path
from typing import Dict, List, Optional, Union
from fastapi import APIRouter, Depends
from fastapi.exceptions import HTTPException
from freqtrade import __version__
from freqtrade.constants import USERPATH_STRATEGIES
from freqtrade.data.history import get_datahandler
from freqtrade.exceptions import OperationalException
from freqtrade.rpc import RPC
@ -14,7 +14,8 @@ from freqtrade.rpc.rpc import RPCException
from .api_models import (AvailablePairs, Balances, BlacklistPayload, BlacklistResponse, Count,
Daily, DeleteTrade, ForceBuyPayload, ForceSellPayload, Locks, Logs,
PerformanceEntry, Ping, PlotConfig, Profit, ResultMsg, Stats, StatusMsg, StrategyListResponse, StrategyResponse, Version,
PairHistory, PerformanceEntry, Ping, PlotConfig, Profit, ResultMsg, Stats,
StatusMsg, StrategyListResponse, StrategyResponse, Version,
WhitelistResponse)
from .deps import get_config, get_rpc
@ -164,14 +165,12 @@ def reload_config(rpc: RPC = Depends(get_rpc)):
return rpc._rpc_reload_config()
# TODO: Missing response model
@router.get('/pair_candles', tags=['candle data'])
@router.get('/pair_candles', response_model=PairHistory, tags=['candle data'])
def pair_candles(pair: str, timeframe: str, limit: Optional[int], rpc=Depends(get_rpc)):
return rpc._rpc_analysed_dataframe(pair, timeframe, limit)
# TODO: Missing response model
@router.get('/pair_history', tags=['candle data'])
@router.get('/pair_history', response_model=PairHistory, tags=['candle data'])
def pair_history(pair: str, timeframe: str, timerange: str, strategy: str,
config=Depends(get_config)):
config = deepcopy(config)

View File

@ -933,8 +933,8 @@ def test_api_pair_candles(botclient, ohlcv_history):
assert rc.json()['data_stop_ts'] == 1511686800000
assert isinstance(rc.json()['columns'], list)
assert rc.json()['columns'] == ['date', 'open', 'high',
'low', 'close', 'volume', 'sma', 'buy', 'sell',
'__date_ts', '_buy_signal_open', '_sell_signal_open']
'low', 'close', 'volume', 'sma', 'buy', 'sell',
'__date_ts', '_buy_signal_open', '_sell_signal_open']
assert 'pair' in rc.json()
assert rc.json()['pair'] == 'XRP/BTC'