Enhance some response models

This commit is contained in:
Matthias 2021-01-01 19:36:03 +01:00
parent 718f2b24d2
commit 29f4dd1dcd
3 changed files with 64 additions and 9 deletions

View File

@ -112,6 +112,60 @@ class Daily(BaseModel):
stake_currency: str
class TradeSchema(BaseModel):
trade_id: str
pair: str
is_open: bool
exchange: str
amount: float
amount_requested: float
stake_amount: float
strategy: str
timeframe: str
fee_open: Optional[float]
fee_open_cost: Optional[float]
fee_open_currency: Optional[str]
fee_close: Optional[float]
fee_close_cost: Optional[float]
fee_close_currency: Optional[str]
open_date_hum: str
open_date: str
open_timestamp: int
open_rate: float
open_rate_requested: Optional[float]
open_trade_value: float
close_date_hum: Optional[str]
close_date: Optional[str]
close_timestamp: Optional[int]
close_rate: Optional[float]
close_rate_requested: Optional[float]
close_profit: Optional[float]
close_profit_pct: Optional[float]
close_profit_abs: Optional[float]
profit_ratio: Optional[float]
profit_pct: Optional[float]
profit_abs: Optional[float]
sell_reason: Optional[str]
sell_order_status: Optional[str]
stop_loss_abs: Optional[float]
stop_loss_ratio: Optional[float]
stop_loss_pct: Optional[float]
stoploss_order_id: Optional[str]
stoploss_last_update: Optional[str]
stoploss_last_update_timestamp: Optional[int]
initial_stop_loss_abs: Optional[float]
initial_stop_loss_ratio: Optional[float]
initial_stop_loss_pct: Optional[float]
min_rate: Optional[float]
max_rate: Optional[float]
open_order_id: Optional[str]
class TradeResponse(BaseModel):
trades: List[TradeSchema]
trades_count: int
class LockModel(BaseModel):
active: bool
lock_end_time: str

View File

@ -15,7 +15,7 @@ from freqtrade.rpc.api_server.api_models import (AvailablePairs, Balances, Black
ForceBuyPayload, ForceSellPayload, Locks, Logs,
PairHistory, PerformanceEntry, Ping, PlotConfig,
Profit, ResultMsg, Stats, StatusMsg,
StrategyListResponse, StrategyResponse, Version,
StrategyListResponse, StrategyResponse, TradeResponse, TradeSchema, Version,
WhitelistResponse)
from freqtrade.rpc.api_server.deps import get_config, get_rpc
from freqtrade.rpc.rpc import RPCException
@ -74,7 +74,7 @@ def daily(timescale: int = 7, rpc: RPC = Depends(get_rpc), config=Depends(get_co
# TODO: Missing response model
@router.get('/status', tags=['info'])
@router.get('/status', response_model=List[TradeSchema], tags=['info'])
def status(rpc: RPC = Depends(get_rpc)):
try:
return rpc._rpc_trade_status()
@ -82,8 +82,7 @@ def status(rpc: RPC = Depends(get_rpc)):
return []
# TODO: Missing response model
@router.get('/trades', tags=['info', 'trading'])
@router.get('/trades', response_model=TradeResponse, tags=['info', 'trading'])
def trades(limit: int = 0, rpc: RPC = Depends(get_rpc)):
return rpc._rpc_trade_history(limit)
@ -105,8 +104,7 @@ def show_config(rpc: RPC = Depends(get_rpc), config=Depends(get_config)):
return RPC._rpc_show_config(config, rpc._freqtrade.state)
# TODO: Missing response model
@router.post('/forcebuy', tags=['trading'])
@router.post('/forcebuy', response_model=Union[TradeSchema, StatusMsg], tags=['trading'])
def forcebuy(payload: ForceBuyPayload, rpc: RPC = Depends(get_rpc)):
trade = rpc._rpc_forcebuy(payload.pair, payload.price)

View File

@ -853,6 +853,9 @@ def test_api_forcebuy(botclient, mocker, fee):
fee_close=fee.return_value,
fee_open=fee.return_value,
close_rate=0.265441,
id='22',
timeframe="5m",
strategy="DefaultStrategy"
))
mocker.patch("freqtrade.rpc.RPC._rpc_forcebuy", fbuy_mock)
@ -862,7 +865,7 @@ def test_api_forcebuy(botclient, mocker, fee):
assert rc.json() == {
'amount': 1,
'amount_requested': 1,
'trade_id': None,
'trade_id': '22',
'close_date': None,
'close_date_hum': None,
'close_timestamp': None,
@ -903,8 +906,8 @@ def test_api_forcebuy(botclient, mocker, fee):
'open_trade_value': 0.24605460,
'sell_reason': None,
'sell_order_status': None,
'strategy': None,
'timeframe': None,
'strategy': 'DefaultStrategy',
'timeframe': '5m',
'exchange': 'bittrex',
}