mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-23 03:25:15 +00:00
Add forceshort capability to forcebuy form
This commit is contained in:
parent
5396add212
commit
ca3cd13629
|
@ -44,8 +44,8 @@
|
|||
v-if="botState && botState.forcebuy_enabled"
|
||||
class="btn btn-secondary btn-sm ml-1"
|
||||
:disabled="!isTrading || !isRunning"
|
||||
title="Force Buy - Immediately buy an asset at an optional price. Sells are then handled according to strategy rules."
|
||||
@click="initiateForcebuy"
|
||||
title="Force enter - Immediately buy an asset at an optional price. Sells are then handled according to strategy rules."
|
||||
@click="initiateForceenter"
|
||||
>
|
||||
<ForceBuyIcon />
|
||||
</button>
|
||||
|
@ -115,7 +115,7 @@ export default class BotControls extends Vue {
|
|||
return this.botState?.state === 'running';
|
||||
}
|
||||
|
||||
initiateForcebuy() {
|
||||
initiateForceenter() {
|
||||
this.$bvModal.show('forcebuy-modal');
|
||||
}
|
||||
|
||||
|
|
|
@ -3,12 +3,26 @@
|
|||
<b-modal
|
||||
id="forcebuy-modal"
|
||||
ref="modal"
|
||||
title="Force buying a pair"
|
||||
title="Force entering a trade"
|
||||
@show="resetForm"
|
||||
@hidden="resetForm"
|
||||
@ok="handleBuy"
|
||||
>
|
||||
<form ref="form" @submit.stop.prevent="handleSubmit">
|
||||
<b-form-group
|
||||
v-if="botApiVersion >= 2.13 && shortAllowed"
|
||||
label="Order direction (Long or Short)"
|
||||
label-for="order-direction"
|
||||
invalid-feedback="Stake-amount must be empty or a positive number"
|
||||
>
|
||||
<b-select
|
||||
v-model="orderSide"
|
||||
class="ml-2"
|
||||
:options="['long', 'short']"
|
||||
style="min-width: 7em"
|
||||
>
|
||||
</b-select>
|
||||
</b-form-group>
|
||||
<b-form-group label="Pair" label-for="pair-input" invalid-feedback="Pair is required">
|
||||
<b-form-input
|
||||
id="pair-input"
|
||||
|
@ -67,7 +81,7 @@
|
|||
<script lang="ts">
|
||||
import { Component, Vue } from 'vue-property-decorator';
|
||||
import { namespace } from 'vuex-class';
|
||||
import { BotState, ForcebuyPayload } from '@/types';
|
||||
import { BotState, ForceEnterPayload, OrderSides } from '@/types';
|
||||
import { BotStoreGetters } from '@/store/modules/ftbot';
|
||||
import StoreModules from '@/store/storeSubModules';
|
||||
|
||||
|
@ -83,18 +97,22 @@ export default class ForceBuyForm extends Vue {
|
|||
|
||||
ordertype?: string = '';
|
||||
|
||||
orderSide: OrderSides = OrderSides.long;
|
||||
|
||||
$refs!: {
|
||||
form: HTMLFormElement;
|
||||
};
|
||||
|
||||
@ftbot.Getter [BotStoreGetters.botState]?: BotState;
|
||||
|
||||
@ftbot.Getter [BotStoreGetters.shortAllowed]?: boolean;
|
||||
|
||||
@ftbot.Getter [BotStoreGetters.botApiVersion]: number;
|
||||
|
||||
@ftbot.Getter [BotStoreGetters.stakeCurrency]!: string;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@ftbot.Action forcebuy!: (payload: ForcebuyPayload) => Promise<string>;
|
||||
@ftbot.Action forcebuy!: (payload: ForceEnterPayload) => Promise<string>;
|
||||
|
||||
created() {
|
||||
this.$bvModal.show('forcebuy-modal');
|
||||
|
@ -133,7 +151,7 @@ export default class ForceBuyForm extends Vue {
|
|||
return;
|
||||
}
|
||||
// call forcebuy
|
||||
const payload: ForcebuyPayload = { pair: this.pair };
|
||||
const payload: ForceEnterPayload = { pair: this.pair };
|
||||
if (this.price) {
|
||||
payload.price = Number(this.price);
|
||||
}
|
||||
|
@ -143,6 +161,9 @@ export default class ForceBuyForm extends Vue {
|
|||
if (this.stakeAmount) {
|
||||
payload.stakeamount = this.stakeAmount;
|
||||
}
|
||||
if (this.botApiVersion >= 2.13) {
|
||||
payload.orderside = this.orderSide;
|
||||
}
|
||||
this.forcebuy(payload);
|
||||
this.$nextTick(() => {
|
||||
this.$bvModal.hide('forcebuy-modal');
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
BacktestResult,
|
||||
BotState,
|
||||
BlacklistPayload,
|
||||
ForcebuyPayload,
|
||||
ForceEnterPayload,
|
||||
Logs,
|
||||
DailyPayload,
|
||||
Trade,
|
||||
|
@ -72,6 +72,7 @@ export enum BotStoreGetters {
|
|||
timeframe = 'timeframe',
|
||||
isTrading = 'isTrading',
|
||||
isWebserverMode = 'isWebserverMode',
|
||||
shortAllowed = 'shortAllowed',
|
||||
refreshRequired = 'refreshRequired',
|
||||
selectedBacktestResult = 'selectedBacktestResult',
|
||||
canRunBacktest = 'canRunBacktest',
|
||||
|
@ -239,6 +240,9 @@ export function createBotSubStore(botId: string, botName: string) {
|
|||
[BotStoreGetters.isWebserverMode](state: FtbotStateType): boolean {
|
||||
return state.botState?.runmode === RunModes.WEBSERVER;
|
||||
},
|
||||
[BotStoreGetters.shortAllowed](state: FtbotStateType): boolean {
|
||||
return state.botState?.short_allowed || false;
|
||||
},
|
||||
[BotStoreGetters.refreshRequired](state: FtbotStateType): boolean {
|
||||
return state.refreshRequired;
|
||||
},
|
||||
|
@ -867,14 +871,15 @@ export function createBotSubStore(botId: string, botName: string) {
|
|||
return Promise.reject(error);
|
||||
}
|
||||
},
|
||||
async [BotStoreActions.forcebuy]({ dispatch }, payload: ForcebuyPayload) {
|
||||
async [BotStoreActions.forcebuy]({ dispatch }, payload: ForceEnterPayload) {
|
||||
if (payload && payload.pair) {
|
||||
try {
|
||||
// TODO: Update forcebuy to forceenter ...
|
||||
const res = await api.post<
|
||||
ForcebuyPayload,
|
||||
ForceEnterPayload,
|
||||
AxiosResponse<StatusResponse | TradeResponse>
|
||||
>('/forcebuy', payload);
|
||||
showAlert(dispatch, `Buy order for ${payload.pair} created.`);
|
||||
showAlert(dispatch, `Order for ${payload.pair} created.`);
|
||||
|
||||
return Promise.resolve(res);
|
||||
} catch (error) {
|
||||
|
@ -882,7 +887,7 @@ export function createBotSubStore(botId: string, botName: string) {
|
|||
console.error(error.response);
|
||||
showAlert(
|
||||
dispatch,
|
||||
`Error occured buying: '${(error as any).response?.data?.error}'`,
|
||||
`Error occured entering: '${(error as any).response?.data?.error}'`,
|
||||
'danger',
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
export interface ForcebuyPayload {
|
||||
export enum OrderSides {
|
||||
long = 'long',
|
||||
short = 'short',
|
||||
}
|
||||
|
||||
export interface ForceEnterPayload {
|
||||
pair: string;
|
||||
orderside?: OrderSides;
|
||||
price?: number;
|
||||
ordertype?: string;
|
||||
stakeamount?: number;
|
||||
|
|
Loading…
Reference in New Issue
Block a user