2020-05-14 16:10:57 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<b-modal
|
2022-05-25 17:20:18 +00:00
|
|
|
id="forceentry-modal"
|
2020-05-14 16:10:57 +00:00
|
|
|
ref="modal"
|
2022-01-27 05:52:35 +00:00
|
|
|
title="Force entering a trade"
|
2020-05-14 16:10:57 +00:00
|
|
|
@show="resetForm"
|
|
|
|
@hidden="resetForm"
|
2022-05-25 17:20:18 +00:00
|
|
|
@ok="handleEntry"
|
2020-05-14 16:10:57 +00:00
|
|
|
>
|
|
|
|
<form ref="form" @submit.stop.prevent="handleSubmit">
|
2022-01-27 05:52:35 +00:00
|
|
|
<b-form-group
|
2022-04-19 04:53:35 +00:00
|
|
|
v-if="botStore.activeBot.botApiVersion >= 2.13 && botStore.activeBot.shortAllowed"
|
2022-01-27 05:52:35 +00:00
|
|
|
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>
|
2020-05-14 16:10:57 +00:00
|
|
|
<b-form-group label="Pair" label-for="pair-input" invalid-feedback="Pair is required">
|
|
|
|
<b-form-input
|
|
|
|
id="pair-input"
|
|
|
|
v-model="pair"
|
|
|
|
required
|
2022-05-25 17:20:18 +00:00
|
|
|
@keydown.enter.native="handleEntry"
|
2020-05-14 16:10:57 +00:00
|
|
|
></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"
|
|
|
|
>
|
|
|
|
<b-form-input
|
|
|
|
id="price-input"
|
|
|
|
v-model="price"
|
|
|
|
type="number"
|
2021-02-14 12:01:38 +00:00
|
|
|
step="0.00000001"
|
2022-05-25 17:20:18 +00:00
|
|
|
@keydown.enter.native="handleEntry"
|
2020-05-14 16:10:57 +00:00
|
|
|
></b-form-input>
|
|
|
|
</b-form-group>
|
2022-01-22 14:00:12 +00:00
|
|
|
<b-form-group
|
2022-04-19 04:53:35 +00:00
|
|
|
v-if="botStore.activeBot.botApiVersion > 1.12"
|
|
|
|
:label="`*Stake-amount in ${botStore.activeBot.stakeCurrency} [optional]`"
|
2022-01-22 14:00:12 +00:00
|
|
|
label-for="stake-input"
|
|
|
|
invalid-feedback="Stake-amount must be empty or a positive number"
|
|
|
|
>
|
|
|
|
<b-form-input
|
|
|
|
id="stake-input"
|
|
|
|
v-model="stakeAmount"
|
|
|
|
type="number"
|
|
|
|
step="0.000001"
|
2022-05-25 17:20:18 +00:00
|
|
|
@keydown.enter.native="handleEntry"
|
2022-01-22 14:00:12 +00:00
|
|
|
></b-form-input>
|
|
|
|
</b-form-group>
|
2021-11-24 19:19:34 +00:00
|
|
|
<b-form-group
|
2022-04-19 04:53:35 +00:00
|
|
|
v-if="botStore.activeBot.botApiVersion > 1.1"
|
2021-11-24 19:19:34 +00:00
|
|
|
label="*OrderType"
|
|
|
|
label-for="ordertype-input"
|
|
|
|
invalid-feedback="OrderType"
|
|
|
|
>
|
|
|
|
<b-select
|
|
|
|
v-model="ordertype"
|
|
|
|
class="ml-2"
|
|
|
|
:options="['market', 'limit']"
|
|
|
|
style="min-width: 7em"
|
|
|
|
size="sm"
|
|
|
|
>
|
|
|
|
</b-select>
|
|
|
|
</b-form-group>
|
2020-05-14 16:10:57 +00:00
|
|
|
</form>
|
|
|
|
</b-modal>
|
|
|
|
</div>
|
|
|
|
</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';
|
|
|
|
|
|
|
|
import { defineComponent, ref, nextTick } from '@vue/composition-api';
|
|
|
|
|
|
|
|
export default defineComponent({
|
2022-05-25 17:20:18 +00:00
|
|
|
name: 'ForceEntryForm',
|
2022-04-16 18:02:30 +00:00
|
|
|
setup(_, { root }) {
|
2022-04-19 04:53:35 +00:00
|
|
|
const botStore = useBotStore();
|
|
|
|
|
2022-04-16 18:02:30 +00:00
|
|
|
const form = ref<HTMLFormElement>();
|
|
|
|
const pair = ref('');
|
|
|
|
const price = ref<number | null>(null);
|
|
|
|
const stakeAmount = ref<number | null>(null);
|
|
|
|
const ordertype = ref('');
|
|
|
|
const orderSide = ref<OrderSides>(OrderSides.long);
|
|
|
|
|
|
|
|
const checkFormValidity = () => {
|
|
|
|
const valid = form.value?.checkValidity();
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleSubmit = () => {
|
|
|
|
// Exit when the form isn't valid
|
|
|
|
if (!checkFormValidity()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-05-25 17:20:18 +00:00
|
|
|
// call forceentry
|
2022-04-16 18:02:30 +00:00
|
|
|
const payload: ForceEnterPayload = { pair: pair.value };
|
|
|
|
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-05-25 17:20:18 +00:00
|
|
|
botStore.activeBot.forceentry(payload);
|
2022-04-16 18:02:30 +00:00
|
|
|
nextTick(() => {
|
2022-05-25 17:20:18 +00:00
|
|
|
root.$bvModal.hide('forceentry-modal');
|
2022-04-16 18:02:30 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
const resetForm = () => {
|
|
|
|
console.log('resetForm');
|
|
|
|
pair.value = '';
|
|
|
|
price.value = null;
|
|
|
|
stakeAmount.value = null;
|
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-05-25 17:20:18 +00:00
|
|
|
const handleEntry = (bvModalEvt) => {
|
2022-04-16 18:02:30 +00:00
|
|
|
// Prevent modal from closing
|
|
|
|
bvModalEvt.preventDefault();
|
|
|
|
// Trigger submit handler
|
|
|
|
handleSubmit();
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
handleSubmit,
|
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-04-16 18:02:30 +00:00
|
|
|
resetForm,
|
|
|
|
pair,
|
|
|
|
price,
|
|
|
|
stakeAmount,
|
|
|
|
ordertype,
|
|
|
|
orderSide,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2020-05-14 16:10:57 +00:00
|
|
|
</script>
|