frequi_origin/src/components/ftbot/ForceEntryForm.vue

218 lines
6.1 KiB
Vue
Raw Normal View History

2020-05-14 16:10:57 +00:00
<template>
2022-11-19 09:54:05 +00:00
<b-modal
id="forceentry-modal"
ref="modal"
v-model="model"
title="Force entering a trade"
@show="resetForm"
@hidden="resetForm"
@ok="handleEntry"
>
<form ref="form" @submit.stop.prevent="handleSubmit">
<b-form-group
v-if="botStore.activeBot.botApiVersion >= 2.13 && botStore.activeBot.shortAllowed"
label="Order direction (Long or Short)"
label-for="order-direction"
2022-12-03 16:23:01 +00:00
invalid-feedback="Order direction must be set"
:state="orderSide !== undefined"
2022-11-19 09:54:05 +00:00
>
<b-form-radio-group
id="order-direction"
v-model="orderSide"
:options="['long', 'short']"
name="radios-btn-default"
size="sm"
buttons
style="min-width: 10em"
button-variant="outline-primary"
></b-form-radio-group>
</b-form-group>
2022-11-19 10:08:25 +00:00
<b-form-group
label="Pair"
label-for="pair-input"
invalid-feedback="Pair is required"
:state="selectedPair !== undefined"
>
2022-11-19 09:54:05 +00:00
<b-form-input
id="pair-input"
v-model="selectedPair"
required
@keydown.enter.native="handleEntry"
@focus="inputSelect"
></b-form-input>
</b-form-group>
<b-form-group
label="*Price [optional]"
label-for="price-input"
invalid-feedback="Price must be empty or a positive number"
2022-11-19 10:08:25 +00:00
:state="!price || price > 0"
2022-11-19 09:54:05 +00:00
>
<b-form-input
id="price-input"
v-model="price"
type="number"
step="0.00000001"
@keydown.enter.native="handleEntry"
></b-form-input>
</b-form-group>
<b-form-group
v-if="botStore.activeBot.botApiVersion > 1.12"
:label="`*Stake-amount in ${botStore.activeBot.stakeCurrency} [optional]`"
label-for="stake-input"
invalid-feedback="Stake-amount must be empty or a positive number"
2022-11-19 10:08:25 +00:00
:state="!stakeAmount || stakeAmount > 0"
2022-11-19 09:54:05 +00:00
>
<b-form-input
id="stake-input"
v-model="stakeAmount"
type="number"
step="0.000001"
@keydown.enter.native="handleEntry"
></b-form-input>
</b-form-group>
<b-form-group
v-if="botStore.activeBot.botApiVersion > 2.16 && botStore.activeBot.shortAllowed"
:label="`*Leverage to apply [optional]`"
label-for="leverage-input"
invalid-feedback="Leverage must be empty or a positive number"
2022-11-19 10:08:25 +00:00
:state="!leverage || leverage > 0"
2022-11-19 09:54:05 +00:00
>
<b-form-input
id="leverage-input"
v-model="leverage"
type="number"
step="0.01"
@keydown.enter.native="handleEntry"
></b-form-input>
</b-form-group>
<b-form-group
v-if="botStore.activeBot.botApiVersion > 1.1"
label="*OrderType"
label-for="ordertype-input"
invalid-feedback="OrderType"
2022-11-19 10:08:25 +00:00
:state="true"
2022-11-19 09:54:05 +00:00
>
<b-form-radio-group
id="ordertype-input"
v-model="ordertype"
:options="['market', 'limit']"
name="radios-btn-default"
buttons
button-variant="outline-primary"
style="min-width: 10em"
size="sm"
></b-form-radio-group>
</b-form-group>
</form>
</b-modal>
2020-05-14 16:10:57 +00:00
</template>
2020-08-09 13:11:47 +00:00
<script lang="ts">
2022-04-19 04:53:35 +00:00
import { useBotStore } from '@/stores/ftbotwrapper';
2022-04-16 18:02:30 +00:00
import { ForceEnterPayload, OrderSides } from '@/types';
2022-11-19 09:53:04 +00:00
import { computed, defineComponent, nextTick, ref } from 'vue';
2022-04-16 18:02:30 +00:00
export default defineComponent({
2022-05-25 17:20:18 +00:00
name: 'ForceEntryForm',
2022-11-25 07:52:24 +00:00
props: {
2022-11-19 09:53:04 +00:00
modelValue: { required: true, default: false, type: Boolean },
pair: { type: String, default: '' },
2022-11-25 07:52:24 +00:00
},
2022-11-19 09:53:04 +00:00
emits: ['update:modelValue'],
setup(props, { emit }) {
2022-04-19 04:53:35 +00:00
const botStore = useBotStore();
2022-04-16 18:02:30 +00:00
const form = ref<HTMLFormElement>();
2022-11-25 07:52:24 +00:00
const selectedPair = ref('');
2022-11-19 10:08:25 +00:00
const price = ref<number | undefined>(undefined);
const stakeAmount = ref<number | undefined>(undefined);
const leverage = ref<number | undefined>(undefined);
2022-08-02 18:09:43 +00:00
2022-04-16 18:02:30 +00:00
const ordertype = ref('');
const orderSide = ref<OrderSides>(OrderSides.long);
2022-11-19 09:53:04 +00:00
const model = computed({
get() {
return props.modelValue;
},
set(value: boolean) {
emit('update:modelValue', value);
},
});
2022-04-16 18:02:30 +00:00
const checkFormValidity = () => {
const valid = form.value?.checkValidity();
return valid;
};
2022-11-21 17:44:06 +00:00
const handleSubmit = async () => {
2022-04-16 18:02:30 +00:00
// Exit when the form isn't valid
if (!checkFormValidity()) {
return;
}
2022-11-21 17:44:06 +00:00
2022-05-25 17:20:18 +00:00
// call forceentry
2022-11-25 07:52:24 +00:00
const payload: ForceEnterPayload = { pair: selectedPair.value };
2022-04-16 18:02:30 +00:00
if (price.value) {
payload.price = Number(price.value);
}
if (ordertype.value) {
payload.ordertype = ordertype.value;
}
if (stakeAmount.value) {
payload.stakeamount = stakeAmount.value;
}
2022-05-25 17:16:55 +00:00
if (botStore.activeBot.botApiVersion >= 2.13 && botStore.activeBot.shortAllowed) {
2022-04-16 18:02:30 +00:00
payload.side = orderSide.value;
}
2022-08-02 18:09:43 +00:00
if (leverage.value) {
payload.leverage = leverage.value;
}
2022-05-25 17:20:18 +00:00
botStore.activeBot.forceentry(payload);
2022-11-21 17:44:06 +00:00
await nextTick();
2022-11-19 09:53:04 +00:00
emit('update:modelValue', false);
2022-04-16 18:02:30 +00:00
};
const resetForm = () => {
console.log('resetForm');
2022-11-25 07:52:24 +00:00
selectedPair.value = props.pair;
2022-11-30 18:48:46 +00:00
price.value = undefined;
stakeAmount.value = undefined;
2022-04-19 04:53:35 +00:00
if (botStore.activeBot.botApiVersion > 1.1) {
2022-04-16 18:02:30 +00:00
ordertype.value =
2022-04-19 04:53:35 +00:00
botStore.activeBot.botState?.order_types?.forcebuy ||
botStore.activeBot.botState?.order_types?.force_entry ||
botStore.activeBot.botState?.order_types?.buy ||
botStore.activeBot.botState?.order_types?.entry ||
'limit';
2022-04-16 18:02:30 +00:00
}
};
2022-11-19 09:53:04 +00:00
const handleEntry = () => {
2022-04-16 18:02:30 +00:00
// Trigger submit handler
handleSubmit();
};
2022-11-25 07:52:24 +00:00
const inputSelect = (bvModalEvt) => {
bvModalEvt.srcElement?.select();
};
2022-04-16 18:02:30 +00:00
return {
handleSubmit,
2022-11-19 09:53:04 +00:00
model,
2022-04-19 04:53:35 +00:00
botStore,
2022-04-16 18:02:30 +00:00
form,
2022-05-25 17:20:18 +00:00
handleEntry,
2022-11-25 07:52:24 +00:00
inputSelect,
2022-04-16 18:02:30 +00:00
resetForm,
2022-11-25 07:52:24 +00:00
selectedPair,
2022-04-16 18:02:30 +00:00
price,
stakeAmount,
ordertype,
orderSide,
2022-08-02 18:09:43 +00:00
leverage,
2022-04-16 18:02:30 +00:00
};
},
});
2020-05-14 16:10:57 +00:00
</script>