freqtrade_origin/freqtrade/rpc/api_server/api_schemas.py

540 lines
13 KiB
Python
Raw Normal View History

2020-12-27 08:02:35 +00:00
from datetime import date, datetime
from typing import Any, Dict, List, Optional, Union
2020-12-27 08:02:35 +00:00
from pydantic import BaseModel, ConfigDict, RootModel, SerializeAsAny
from freqtrade.constants import DATETIME_PRINT_FORMAT, IntOrInf
2023-06-04 11:25:39 +00:00
from freqtrade.enums import MarginMode, OrderTypeValues, SignalDirection, TradingMode
from freqtrade.types import ValidExchangesType
2020-12-27 08:02:35 +00:00
2023-06-03 04:57:25 +00:00
class ExchangeModePayloadMixin(BaseModel):
trading_mode: Optional[TradingMode] = None
margin_mode: Optional[MarginMode] = None
exchange: Optional[str] = None
2023-06-03 04:57:25 +00:00
class Ping(BaseModel):
status: str
2020-12-25 12:11:01 +00:00
2020-12-25 14:50:19 +00:00
class AccessToken(BaseModel):
access_token: str
class AccessAndRefreshToken(AccessToken):
refresh_token: str
2020-12-25 12:11:01 +00:00
class Version(BaseModel):
version: str
2020-12-25 19:07:12 +00:00
class StatusMsg(BaseModel):
status: str
2023-05-31 05:00:20 +00:00
class BgJobStarted(StatusMsg):
job_id: str
class BackgroundTaskStatus(BaseModel):
2023-05-31 05:08:27 +00:00
job_id: str
job_category: str
2023-05-31 05:00:20 +00:00
status: str
running: bool
progress: Optional[float] = None
2023-05-31 05:00:20 +00:00
class BackgroundTaskResult(BaseModel):
error: Optional[str] = None
2023-05-31 05:00:20 +00:00
status: str
2020-12-26 16:33:27 +00:00
class ResultMsg(BaseModel):
result: str
class Balance(BaseModel):
currency: str
free: float
balance: float
used: float
bot_owned: Optional[float] = None
est_stake: float
est_stake_bot: Optional[float] = None
stake: str
# Starting with 2.x
side: str
leverage: float
is_position: bool
position: float
2023-04-22 12:57:13 +00:00
is_bot_managed: bool
class Balances(BaseModel):
currencies: List[Balance]
total: float
2023-04-22 14:13:27 +00:00
total_bot: float
symbol: str
value: float
2023-04-22 14:13:27 +00:00
value_bot: float
stake: str
note: str
starting_capital: float
starting_capital_ratio: float
starting_capital_pct: float
starting_capital_fiat: float
starting_capital_fiat_ratio: float
starting_capital_fiat_pct: float
2020-12-26 14:54:22 +00:00
class Count(BaseModel):
current: int
max: int
total_stake: float
2020-12-26 15:43:15 +00:00
class PerformanceEntry(BaseModel):
pair: str
profit: float
2021-10-31 09:42:42 +00:00
profit_ratio: float
profit_pct: float
2021-05-15 17:39:46 +00:00
profit_abs: float
2020-12-26 15:43:15 +00:00
count: int
class Profit(BaseModel):
profit_closed_coin: float
profit_closed_percent_mean: float
profit_closed_ratio_mean: float
profit_closed_percent_sum: float
profit_closed_ratio_sum: float
profit_closed_percent: float
profit_closed_ratio: float
2020-12-26 15:43:15 +00:00
profit_closed_fiat: float
profit_all_coin: float
profit_all_percent_mean: float
profit_all_ratio_mean: float
profit_all_percent_sum: float
profit_all_ratio_sum: float
profit_all_percent: float
profit_all_ratio: float
2020-12-26 15:43:15 +00:00
profit_all_fiat: float
trade_count: int
closed_trade_count: int
first_trade_date: str
first_trade_humanized: str
2020-12-26 15:43:15 +00:00
first_trade_timestamp: int
latest_trade_date: str
latest_trade_humanized: str
2020-12-26 15:43:15 +00:00
latest_trade_timestamp: int
avg_duration: str
best_pair: str
best_rate: float
best_pair_profit_ratio: float
2020-12-26 15:43:15 +00:00
winning_trades: int
losing_trades: int
profit_factor: float
2023-07-15 15:27:58 +00:00
winrate: float
expectancy: float
2023-07-17 13:16:22 +00:00
expectancy_ratio: float
max_drawdown: float
max_drawdown_abs: float
trading_volume: Optional[float] = None
2023-04-08 14:40:22 +00:00
bot_start_timestamp: int
bot_start_date: str
2020-12-26 15:43:15 +00:00
class SellReason(BaseModel):
wins: int
losses: int
draws: int
class Stats(BaseModel):
2022-03-24 19:33:47 +00:00
exit_reasons: Dict[str, SellReason]
durations: Dict[str, Optional[float]]
2020-12-26 16:33:27 +00:00
class DailyRecord(BaseModel):
date: date
abs_profit: float
2022-06-11 09:28:45 +00:00
rel_profit: float
starting_balance: float
2020-12-26 16:33:27 +00:00
fiat_value: float
trade_count: int
class Daily(BaseModel):
data: List[DailyRecord]
fiat_display_currency: str
stake_currency: str
2021-11-06 15:12:25 +00:00
class UnfilledTimeout(BaseModel):
entry: Optional[int] = None
exit: Optional[int] = None
unit: Optional[str] = None
exit_timeout_count: Optional[int] = None
2021-11-06 15:12:25 +00:00
class OrderTypes(BaseModel):
entry: OrderTypeValues
exit: OrderTypeValues
emergency_exit: Optional[OrderTypeValues] = None
force_exit: Optional[OrderTypeValues] = None
force_entry: Optional[OrderTypeValues] = None
2021-11-24 19:11:04 +00:00
stoploss: OrderTypeValues
2021-11-06 15:12:25 +00:00
stoploss_on_exchange: bool
stoploss_on_exchange_interval: Optional[int] = None
2021-11-06 15:12:25 +00:00
2021-01-02 14:48:33 +00:00
class ShowConfig(BaseModel):
2021-11-06 15:12:25 +00:00
version: str
strategy_version: Optional[str] = None
2021-11-23 06:06:53 +00:00
api_version: float
2021-02-20 18:17:10 +00:00
dry_run: bool
trading_mode: str
short_allowed: bool
2021-01-02 14:48:33 +00:00
stake_currency: str
stake_amount: str
available_capital: Optional[float] = None
stake_currency_decimals: int
max_open_trades: IntOrInf
2021-01-02 14:48:33 +00:00
minimal_roi: Dict[str, Any]
stoploss: Optional[float] = None
stoploss_on_exchange: bool
trailing_stop: Optional[bool] = None
trailing_stop_positive: Optional[float] = None
trailing_stop_positive_offset: Optional[float] = None
trailing_only_offset_is_reached: Optional[bool] = None
unfilledtimeout: Optional[UnfilledTimeout] = None # Empty in webserver mode
order_types: Optional[OrderTypes] = None
use_custom_stoploss: Optional[bool] = None
timeframe: Optional[str] = None
2021-01-02 14:48:33 +00:00
timeframe_ms: int
timeframe_min: int
exchange: str
strategy: Optional[str] = None
2022-04-08 11:39:41 +00:00
force_entry_enable: bool
exit_pricing: Dict[str, Any]
entry_pricing: Dict[str, Any]
bot_name: str
2021-01-02 14:48:33 +00:00
state: str
runmode: str
2022-01-21 00:35:22 +00:00
position_adjustment_enable: bool
max_entry_position_adjustment: int
2021-01-02 14:48:33 +00:00
2022-02-26 15:10:54 +00:00
class OrderSchema(BaseModel):
pair: str
order_id: str
status: str
remaining: Optional[float] = None
2022-02-26 15:10:54 +00:00
amount: float
safe_price: float
cost: float
filled: Optional[float] = None
2022-02-26 15:10:54 +00:00
ft_order_side: str
order_type: str
is_open: bool
order_timestamp: Optional[int] = None
order_filled_timestamp: Optional[int] = None
ft_fee_base: Optional[float] = None
2022-02-26 15:10:54 +00:00
2021-01-01 18:36:03 +00:00
class TradeSchema(BaseModel):
2021-01-01 18:38:28 +00:00
trade_id: int
2021-01-01 18:36:03 +00:00
pair: str
2022-04-09 14:42:18 +00:00
base_currency: str
quote_currency: str
2021-01-01 18:36:03 +00:00
is_open: bool
is_short: bool
2021-01-01 18:36:03 +00:00
exchange: str
amount: float
amount_requested: float
stake_amount: float
max_stake_amount: Optional[float] = None
2021-01-01 18:36:03 +00:00
strategy: str
enter_tag: Optional[str] = None
2021-01-01 18:38:28 +00:00
timeframe: int
fee_open: Optional[float] = None
fee_open_cost: Optional[float] = None
fee_open_currency: Optional[str] = None
fee_close: Optional[float] = None
fee_close_cost: Optional[float] = None
fee_close_currency: Optional[str] = None
2023-02-28 17:09:52 +00:00
2021-01-01 18:36:03 +00:00
open_date: str
open_timestamp: int
open_rate: float
open_rate_requested: Optional[float] = None
2021-01-01 18:36:03 +00:00
open_trade_value: float
2023-02-28 17:09:52 +00:00
close_date: Optional[str] = None
close_timestamp: Optional[int] = None
close_rate: Optional[float] = None
close_rate_requested: Optional[float] = None
2023-02-28 17:09:52 +00:00
close_profit: Optional[float] = None
close_profit_pct: Optional[float] = None
close_profit_abs: Optional[float] = None
2023-02-28 17:09:52 +00:00
profit_ratio: Optional[float] = None
profit_pct: Optional[float] = None
profit_abs: Optional[float] = None
profit_fiat: Optional[float] = None
2023-02-28 17:09:52 +00:00
2023-02-27 19:31:02 +00:00
realized_profit: float
realized_profit_ratio: Optional[float] = None
exit_reason: Optional[str] = None
exit_order_status: Optional[str] = None
stop_loss_abs: Optional[float] = None
stop_loss_ratio: Optional[float] = None
stop_loss_pct: Optional[float] = None
stoploss_order_id: Optional[str] = None
stoploss_last_update: Optional[str] = None
stoploss_last_update_timestamp: Optional[int] = None
initial_stop_loss_abs: Optional[float] = None
initial_stop_loss_ratio: Optional[float] = None
initial_stop_loss_pct: Optional[float] = None
min_rate: Optional[float] = None
max_rate: Optional[float] = None
orders: List[OrderSchema]
2021-01-01 18:36:03 +00:00
leverage: Optional[float] = None
interest_rate: Optional[float] = None
liquidation_price: Optional[float] = None
funding_fees: Optional[float] = None
trading_mode: Optional[TradingMode] = None
amount_precision: Optional[float] = None
price_precision: Optional[float] = None
precision_mode: Optional[int] = None
2023-03-25 10:55:47 +00:00
2021-01-01 18:36:03 +00:00
2021-01-01 18:38:28 +00:00
class OpenTradeSchema(TradeSchema):
stoploss_current_dist: Optional[float] = None
stoploss_current_dist_pct: Optional[float] = None
stoploss_current_dist_ratio: Optional[float] = None
stoploss_entry_dist: Optional[float] = None
stoploss_entry_dist_ratio: Optional[float] = None
2021-01-01 18:38:28 +00:00
current_rate: float
2023-02-28 19:31:02 +00:00
total_profit_abs: float
total_profit_fiat: Optional[float] = None
total_profit_ratio: Optional[float] = None
2023-02-28 19:31:02 +00:00
2021-01-01 18:38:28 +00:00
2021-01-01 18:36:03 +00:00
class TradeResponse(BaseModel):
trades: List[TradeSchema]
trades_count: int
2022-06-18 15:44:15 +00:00
offset: int
total_trades: int
2021-01-01 18:36:03 +00:00
2023-07-18 04:52:09 +00:00
ForceEnterResponse = RootModel[Union[TradeSchema, StatusMsg]]
2021-01-02 14:11:40 +00:00
2020-12-26 16:33:27 +00:00
class LockModel(BaseModel):
2021-03-01 18:50:39 +00:00
id: int
2020-12-26 16:33:27 +00:00
active: bool
lock_end_time: str
lock_end_timestamp: int
lock_time: str
lock_timestamp: int
pair: str
2022-04-24 09:51:33 +00:00
side: str
reason: Optional[str] = None
2020-12-26 16:33:27 +00:00
class Locks(BaseModel):
lock_count: int
locks: List[LockModel]
2021-03-01 18:50:39 +00:00
class DeleteLockRequest(BaseModel):
pair: Optional[str] = None
lockid: Optional[int] = None
2021-03-01 18:50:39 +00:00
2020-12-26 16:33:27 +00:00
class Logs(BaseModel):
log_count: int
logs: List[List]
2022-01-26 06:10:38 +00:00
class ForceEnterPayload(BaseModel):
pair: str
2022-01-26 06:10:38 +00:00
side: SignalDirection = SignalDirection.LONG
price: Optional[float] = None
ordertype: Optional[OrderTypeValues] = None
stakeamount: Optional[float] = None
entry_tag: Optional[str] = None
leverage: Optional[float] = None
2022-04-06 01:35:43 +00:00
class ForceExitPayload(BaseModel):
tradeid: str
ordertype: Optional[OrderTypeValues] = None
amount: Optional[float] = None
2020-12-26 16:33:27 +00:00
class BlacklistPayload(BaseModel):
blacklist: List[str]
class BlacklistResponse(BaseModel):
blacklist: List[str]
blacklist_expanded: List[str]
errors: Dict
length: int
method: List[str]
class WhitelistResponse(BaseModel):
whitelist: List[str]
length: int
method: List[str]
2023-05-31 05:00:20 +00:00
class WhitelistEvaluateResponse(BackgroundTaskResult):
result: Optional[WhitelistResponse] = None
2020-12-26 16:33:27 +00:00
class DeleteTrade(BaseModel):
cancel_order_count: int
result: str
result_msg: str
trade_id: int
2020-12-26 19:05:27 +00:00
2021-01-02 14:11:40 +00:00
class PlotConfig_(BaseModel):
2020-12-31 10:01:50 +00:00
main_plot: Dict[str, Any]
subplots: Dict[str, Any]
2020-12-26 19:05:27 +00:00
2023-07-18 04:52:09 +00:00
PlotConfig = RootModel[Union[PlotConfig_, Dict]]
2021-01-02 14:11:40 +00:00
2020-12-26 19:05:27 +00:00
class StrategyListResponse(BaseModel):
strategies: List[str]
class ExchangeListResponse(BaseModel):
exchanges: List[ValidExchangesType]
2023-04-19 16:35:52 +00:00
class PairListResponse(BaseModel):
2023-04-20 16:15:31 +00:00
name: str
description: str
2023-04-20 16:15:31 +00:00
is_pairlist_generator: bool
params: Dict[str, Any]
class PairListsResponse(BaseModel):
pairlists: List[PairListResponse]
2023-04-19 16:35:52 +00:00
2023-06-03 04:57:25 +00:00
class PairListsPayload(ExchangeModePayloadMixin, BaseModel):
pairlists: List[Dict[str, Any]]
blacklist: List[str]
stake_currency: str
2022-12-20 06:21:52 +00:00
class FreqAIModelListResponse(BaseModel):
freqaimodels: List[str]
2020-12-26 19:05:27 +00:00
class StrategyResponse(BaseModel):
strategy: str
code: str
class AvailablePairs(BaseModel):
length: int
pairs: List[str]
pair_interval: List[List[str]]
2020-12-27 08:02:35 +00:00
class PairHistory(BaseModel):
strategy: str
pair: str
timeframe: str
timeframe_ms: int
columns: List[str]
data: SerializeAsAny[List[Any]]
2020-12-27 08:02:35 +00:00
length: int
buy_signals: int
sell_signals: int
enter_long_signals: int
exit_long_signals: int
enter_short_signals: int
exit_short_signals: int
2020-12-27 08:02:35 +00:00
last_analyzed: datetime
last_analyzed_ts: int
data_start_ts: int
data_start: str
data_stop: str
data_stop_ts: int
# TODO[pydantic]: The following keys were removed: `json_encoders`.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
model_config = ConfigDict(json_encoders={
datetime: lambda v: v.strftime(DATETIME_PRINT_FORMAT),
})
2021-01-02 14:13:32 +00:00
2022-12-20 18:44:01 +00:00
class BacktestFreqAIInputs(BaseModel):
identifier: str
2021-01-02 14:13:32 +00:00
class BacktestRequest(BaseModel):
strategy: str
timeframe: Optional[str] = None
timeframe_detail: Optional[str] = None
timerange: Optional[str] = None
max_open_trades: Optional[IntOrInf] = None
2023-07-18 16:19:42 +00:00
stake_amount: Optional[Union[str, float]] = None
enable_protections: bool
dry_run_wallet: Optional[float] = None
backtest_cache: Optional[str] = None
freqaimodel: Optional[str] = None
freqai: Optional[BacktestFreqAIInputs] = None
2021-01-02 14:13:32 +00:00
class BacktestResponse(BaseModel):
status: str
running: bool
status_msg: str
2021-03-11 18:16:18 +00:00
step: str
progress: float
trade_count: Optional[float] = None
2021-01-02 14:13:32 +00:00
# TODO: Properly type backtestresult...
backtest_result: Optional[Dict[str, Any]] = None
2021-10-06 17:36:28 +00:00
2023-07-31 18:26:21 +00:00
# TODO: This is a copy of BacktestHistoryEntryType
class BacktestHistoryEntry(BaseModel):
filename: str
strategy: str
run_id: str
backtest_start_time: int
2023-07-31 19:15:33 +00:00
notes: Optional[str] = ''
2023-07-31 19:16:25 +00:00
class BacktestMetadataUpdate(BaseModel):
strategy: str
2023-08-03 04:28:28 +00:00
notes: str = ''
class SysInfo(BaseModel):
cpu_pct: List[float]
ram_pct: float
class Health(BaseModel):
last_process: Optional[datetime] = None
last_process_ts: Optional[int] = None