Add /forceenter endpoint

This commit is contained in:
Matthias 2022-01-26 07:10:38 +01:00
parent 13978e9893
commit 67651e013e
2 changed files with 14 additions and 10 deletions

View File

@ -4,7 +4,7 @@ from typing import Any, Dict, List, Optional, Union
from pydantic import BaseModel from pydantic import BaseModel
from freqtrade.constants import DATETIME_PRINT_FORMAT from freqtrade.constants import DATETIME_PRINT_FORMAT
from freqtrade.enums import OrderTypeValues from freqtrade.enums import OrderTypeValues, SignalDirection
class Ping(BaseModel): class Ping(BaseModel):
@ -247,7 +247,7 @@ class TradeResponse(BaseModel):
total_trades: int total_trades: int
class ForceBuyResponse(BaseModel): class ForceEnterResponse(BaseModel):
__root__: Union[TradeSchema, StatusMsg] __root__: Union[TradeSchema, StatusMsg]
@ -277,8 +277,9 @@ class Logs(BaseModel):
logs: List[List] logs: List[List]
class ForceBuyPayload(BaseModel): class ForceEnterPayload(BaseModel):
pair: str pair: str
side: SignalDirection = SignalDirection.LONG
price: Optional[float] price: Optional[float]
ordertype: Optional[OrderTypeValues] ordertype: Optional[OrderTypeValues]
stakeamount: Optional[float] stakeamount: Optional[float]

View File

@ -14,8 +14,8 @@ from freqtrade.exceptions import OperationalException
from freqtrade.rpc import RPC from freqtrade.rpc import RPC
from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, BlacklistPayload, from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, BlacklistPayload,
BlacklistResponse, Count, Daily, BlacklistResponse, Count, Daily,
DeleteLockRequest, DeleteTrade, ForceBuyPayload, DeleteLockRequest, DeleteTrade, ForceEnterPayload,
ForceBuyResponse, ForceSellPayload, Locks, Logs, ForceEnterResponse, ForceSellPayload, Locks, Logs,
OpenTradeSchema, PairHistory, PerformanceEntry, OpenTradeSchema, PairHistory, PerformanceEntry,
Ping, PlotConfig, Profit, ResultMsg, ShowConfig, Ping, PlotConfig, Profit, ResultMsg, ShowConfig,
Stats, StatusMsg, StrategyListResponse, Stats, StatusMsg, StrategyListResponse,
@ -33,7 +33,9 @@ logger = logging.getLogger(__name__)
# 1.11: forcebuy and forcesell accept ordertype # 1.11: forcebuy and forcesell accept ordertype
# 1.12: add blacklist delete endpoint # 1.12: add blacklist delete endpoint
# 1.13: forcebuy supports stake_amount # 1.13: forcebuy supports stake_amount
API_VERSION = 1.13 # versions 2.xx -> futures/short branch
# 2.13: addition of Forceenter
API_VERSION = 2.13
# Public API, requires no auth. # Public API, requires no auth.
router_public = APIRouter() router_public = APIRouter()
@ -133,17 +135,18 @@ def show_config(rpc: Optional[RPC] = Depends(get_rpc_optional), config=Depends(g
return resp return resp
@router.post('/forcebuy', response_model=ForceBuyResponse, tags=['trading']) # /forcebuy is deprecated with short addition. use ForceEntry instead
def forcebuy(payload: ForceBuyPayload, rpc: RPC = Depends(get_rpc)): @router.post(['/forceenter', '/forcebuy'], response_model=ForceEnterResponse, tags=['trading'])
def forceentry(payload: ForceEnterPayload, rpc: RPC = Depends(get_rpc)):
ordertype = payload.ordertype.value if payload.ordertype else None ordertype = payload.ordertype.value if payload.ordertype else None
stake_amount = payload.stakeamount if payload.stakeamount else None stake_amount = payload.stakeamount if payload.stakeamount else None
trade = rpc._rpc_forcebuy(payload.pair, payload.price, ordertype, stake_amount) trade = rpc._rpc_forcebuy(payload.pair, payload.price, ordertype, stake_amount)
if trade: if trade:
return ForceBuyResponse.parse_obj(trade.to_json()) return ForceEnterResponse.parse_obj(trade.to_json())
else: else:
return ForceBuyResponse.parse_obj({"status": f"Error buying pair {payload.pair}."}) return ForceEnterResponse.parse_obj({"status": f"Error entering {payload.side} trade for pair {payload.pair}."})
@router.post('/forcesell', response_model=ResultMsg, tags=['trading']) @router.post('/forcesell', response_model=ResultMsg, tags=['trading'])