Add leverage to force_entry
This commit is contained in:
parent
daf015d007
commit
eff8cd7ecb
@ -624,7 +624,8 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
ordertype: Optional[str] = None,
|
ordertype: Optional[str] = None,
|
||||||
enter_tag: Optional[str] = None,
|
enter_tag: Optional[str] = None,
|
||||||
trade: Optional[Trade] = None,
|
trade: Optional[Trade] = None,
|
||||||
order_adjust: bool = False
|
order_adjust: bool = False,
|
||||||
|
leverage_: Optional[float] = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
Executes a limit buy for the given pair
|
Executes a limit buy for the given pair
|
||||||
@ -640,7 +641,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
pos_adjust = trade is not None
|
pos_adjust = trade is not None
|
||||||
|
|
||||||
enter_limit_requested, stake_amount, leverage = self.get_valid_enter_price_and_stake(
|
enter_limit_requested, stake_amount, leverage = self.get_valid_enter_price_and_stake(
|
||||||
pair, price, stake_amount, trade_side, enter_tag, trade, order_adjust)
|
pair, price, stake_amount, trade_side, enter_tag, trade, order_adjust, leverage_)
|
||||||
|
|
||||||
if not stake_amount:
|
if not stake_amount:
|
||||||
return False
|
return False
|
||||||
@ -787,6 +788,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
entry_tag: Optional[str],
|
entry_tag: Optional[str],
|
||||||
trade: Optional[Trade],
|
trade: Optional[Trade],
|
||||||
order_adjust: bool,
|
order_adjust: bool,
|
||||||
|
leverage_: Optional[float],
|
||||||
) -> Tuple[float, float, float]:
|
) -> Tuple[float, float, float]:
|
||||||
|
|
||||||
if price:
|
if price:
|
||||||
@ -809,16 +811,19 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
if not enter_limit_requested:
|
if not enter_limit_requested:
|
||||||
raise PricingError('Could not determine entry price.')
|
raise PricingError('Could not determine entry price.')
|
||||||
|
|
||||||
if trade is None:
|
if self.trading_mode != TradingMode.SPOT and trade is None:
|
||||||
max_leverage = self.exchange.get_max_leverage(pair, stake_amount)
|
max_leverage = self.exchange.get_max_leverage(pair, stake_amount)
|
||||||
leverage = strategy_safe_wrapper(self.strategy.leverage, default_retval=1.0)(
|
if leverage_:
|
||||||
pair=pair,
|
leverage = leverage_
|
||||||
current_time=datetime.now(timezone.utc),
|
else:
|
||||||
current_rate=enter_limit_requested,
|
leverage = strategy_safe_wrapper(self.strategy.leverage, default_retval=1.0)(
|
||||||
proposed_leverage=1.0,
|
pair=pair,
|
||||||
max_leverage=max_leverage,
|
current_time=datetime.now(timezone.utc),
|
||||||
side=trade_side, entry_tag=entry_tag,
|
current_rate=enter_limit_requested,
|
||||||
) if self.trading_mode != TradingMode.SPOT else 1.0
|
proposed_leverage=1.0,
|
||||||
|
max_leverage=max_leverage,
|
||||||
|
side=trade_side, entry_tag=entry_tag,
|
||||||
|
)
|
||||||
# Cap leverage between 1.0 and max_leverage.
|
# Cap leverage between 1.0 and max_leverage.
|
||||||
leverage = min(max(leverage, 1.0), max_leverage)
|
leverage = min(max(leverage, 1.0), max_leverage)
|
||||||
else:
|
else:
|
||||||
|
@ -325,6 +325,7 @@ class ForceEnterPayload(BaseModel):
|
|||||||
ordertype: Optional[OrderTypeValues]
|
ordertype: Optional[OrderTypeValues]
|
||||||
stakeamount: Optional[float]
|
stakeamount: Optional[float]
|
||||||
entry_tag: Optional[str]
|
entry_tag: Optional[str]
|
||||||
|
leverage: Optional[float]
|
||||||
|
|
||||||
|
|
||||||
class ForceExitPayload(BaseModel):
|
class ForceExitPayload(BaseModel):
|
||||||
|
@ -37,7 +37,8 @@ logger = logging.getLogger(__name__)
|
|||||||
# 2.14: Add entry/exit orders to trade response
|
# 2.14: Add entry/exit orders to trade response
|
||||||
# 2.15: Add backtest history endpoints
|
# 2.15: Add backtest history endpoints
|
||||||
# 2.16: Additional daily metrics
|
# 2.16: Additional daily metrics
|
||||||
API_VERSION = 2.16
|
# 2.16: Forceentry - leverage, partial force_exit
|
||||||
|
API_VERSION = 2.17
|
||||||
|
|
||||||
# Public API, requires no auth.
|
# Public API, requires no auth.
|
||||||
router_public = APIRouter()
|
router_public = APIRouter()
|
||||||
@ -142,12 +143,11 @@ def show_config(rpc: Optional[RPC] = Depends(get_rpc_optional), config=Depends(g
|
|||||||
@router.post('/forcebuy', response_model=ForceEnterResponse, tags=['trading'])
|
@router.post('/forcebuy', response_model=ForceEnterResponse, tags=['trading'])
|
||||||
def force_entry(payload: ForceEnterPayload, rpc: RPC = Depends(get_rpc)):
|
def force_entry(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
|
|
||||||
entry_tag = payload.entry_tag if payload.entry_tag else 'force_entry'
|
|
||||||
|
|
||||||
trade = rpc._rpc_force_entry(payload.pair, payload.price, order_side=payload.side,
|
trade = rpc._rpc_force_entry(payload.pair, payload.price, order_side=payload.side,
|
||||||
order_type=ordertype, stake_amount=stake_amount,
|
order_type=ordertype, stake_amount=payload.stakeamount,
|
||||||
enter_tag=entry_tag)
|
enter_tag=payload.entry_tag or 'force_entry',
|
||||||
|
leverage=payload.leverage)
|
||||||
|
|
||||||
if trade:
|
if trade:
|
||||||
return ForceEnterResponse.parse_obj(trade.to_json())
|
return ForceEnterResponse.parse_obj(trade.to_json())
|
||||||
|
@ -732,7 +732,8 @@ class RPC:
|
|||||||
order_type: Optional[str] = None,
|
order_type: Optional[str] = None,
|
||||||
order_side: SignalDirection = SignalDirection.LONG,
|
order_side: SignalDirection = SignalDirection.LONG,
|
||||||
stake_amount: Optional[float] = None,
|
stake_amount: Optional[float] = None,
|
||||||
enter_tag: Optional[str] = 'force_entry') -> Optional[Trade]:
|
enter_tag: Optional[str] = 'force_entry',
|
||||||
|
leverage: Optional[float] = None) -> Optional[Trade]:
|
||||||
"""
|
"""
|
||||||
Handler for forcebuy <asset> <price>
|
Handler for forcebuy <asset> <price>
|
||||||
Buys a pair trade at the given or current price
|
Buys a pair trade at the given or current price
|
||||||
@ -774,6 +775,7 @@ class RPC:
|
|||||||
ordertype=order_type, trade=trade,
|
ordertype=order_type, trade=trade,
|
||||||
is_short=is_short,
|
is_short=is_short,
|
||||||
enter_tag=enter_tag,
|
enter_tag=enter_tag,
|
||||||
|
leverage_=leverage,
|
||||||
):
|
):
|
||||||
Trade.commit()
|
Trade.commit()
|
||||||
trade = Trade.get_trades([Trade.is_open.is_(True), Trade.pair == pair]).first()
|
trade = Trade.get_trades([Trade.is_open.is_(True), Trade.pair == pair]).first()
|
||||||
|
Loading…
Reference in New Issue
Block a user