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