2022-08-03 18:09:45 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<b-modal
|
|
|
|
id="forceexit-modal"
|
2022-11-19 13:39:46 +00:00
|
|
|
v-model="model"
|
2022-08-03 18:09:45 +00:00
|
|
|
title="Force exiting a trade"
|
|
|
|
@show="resetForm"
|
|
|
|
@hidden="resetForm"
|
|
|
|
@ok="handleEntry"
|
|
|
|
>
|
|
|
|
<form ref="form" @submit.stop.prevent="handleSubmit">
|
|
|
|
<p>
|
|
|
|
<span>Exiting Trade #{{ trade.trade_id }} {{ trade.pair }}.</span>
|
|
|
|
<br />
|
|
|
|
<span>Currently owning {{ trade.amount }} {{ trade.base_currency }}</span>
|
|
|
|
</p>
|
|
|
|
<b-form-group
|
|
|
|
v-if="botStore.activeBot.botApiVersion > 1.12"
|
2022-11-20 07:40:22 +00:00
|
|
|
:label="`*Amount in ${trade.base_currency} [optional]`"
|
2022-08-03 18:09:45 +00:00
|
|
|
label-for="stake-input"
|
|
|
|
invalid-feedback="Amount must be empty or a positive number"
|
2022-11-20 07:40:22 +00:00
|
|
|
:state="amount !== undefined && amount > 0"
|
2022-08-03 18:09:45 +00:00
|
|
|
>
|
|
|
|
<b-form-input
|
|
|
|
id="stake-input"
|
|
|
|
v-model="amount"
|
|
|
|
type="number"
|
|
|
|
step="0.000001"
|
|
|
|
@keydown.enter.native="handleEntry"
|
|
|
|
></b-form-input>
|
|
|
|
<b-form-input
|
|
|
|
id="stake-input"
|
|
|
|
v-model="amount"
|
|
|
|
type="range"
|
|
|
|
step="0.000001"
|
|
|
|
min="0"
|
|
|
|
:max="trade.amount"
|
|
|
|
@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-20 07:40:22 +00:00
|
|
|
:state="ordertype !== undefined"
|
2022-08-03 18:09:45 +00:00
|
|
|
>
|
2022-11-18 15:16:14 +00:00
|
|
|
<b-form-select
|
2022-08-03 18:09:45 +00:00
|
|
|
v-model="ordertype"
|
2022-11-18 18:48:15 +00:00
|
|
|
class="ms-2"
|
2022-08-03 18:09:45 +00:00
|
|
|
:options="['market', 'limit']"
|
|
|
|
style="min-width: 7em"
|
|
|
|
size="sm"
|
|
|
|
>
|
2022-11-18 15:16:14 +00:00
|
|
|
</b-form-select>
|
2022-08-03 18:09:45 +00:00
|
|
|
</b-form-group>
|
|
|
|
</form>
|
|
|
|
</b-modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
<script setup lang="ts">
|
2022-08-03 18:09:45 +00:00
|
|
|
import { useBotStore } from '@/stores/ftbotwrapper';
|
|
|
|
import { ForceSellPayload, Trade } from '@/types';
|
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
import { ref, computed } from 'vue';
|
2022-08-03 18:09:45 +00:00
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
const props = defineProps({
|
|
|
|
trade: {
|
|
|
|
type: Object as () => Trade,
|
|
|
|
required: true,
|
2022-08-03 18:09:45 +00:00
|
|
|
},
|
2023-02-15 06:05:27 +00:00
|
|
|
modelValue: { required: true, default: false, type: Boolean },
|
|
|
|
});
|
|
|
|
const emit = defineEmits(['update:modelValue']);
|
|
|
|
const botStore = useBotStore();
|
2022-08-03 18:09:45 +00:00
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
const form = ref<HTMLFormElement>();
|
|
|
|
const amount = ref<number | undefined>(undefined);
|
|
|
|
const ordertype = ref('limit');
|
2022-08-03 18:09:45 +00:00
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
const checkFormValidity = () => {
|
|
|
|
const valid = form.value?.checkValidity();
|
2022-08-03 18:09:45 +00:00
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
return valid;
|
|
|
|
};
|
2022-08-03 18:09:45 +00:00
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
const model = computed({
|
|
|
|
get() {
|
|
|
|
return props.modelValue;
|
|
|
|
},
|
|
|
|
set(value: boolean) {
|
|
|
|
emit('update:modelValue', value);
|
|
|
|
},
|
|
|
|
});
|
2022-11-19 13:39:46 +00:00
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
const handleSubmit = () => {
|
|
|
|
// Exit when the form isn't valid
|
|
|
|
if (!checkFormValidity()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// call forceentry
|
|
|
|
const payload: ForceSellPayload = { tradeid: String(props.trade.trade_id) };
|
2022-08-03 18:09:45 +00:00
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
if (ordertype.value) {
|
|
|
|
payload.ordertype = ordertype.value;
|
|
|
|
}
|
|
|
|
if (amount.value) {
|
|
|
|
payload.amount = amount.value;
|
|
|
|
}
|
|
|
|
botStore.activeBot.forceexit(payload);
|
|
|
|
model.value = false;
|
|
|
|
};
|
|
|
|
const resetForm = () => {
|
|
|
|
amount.value = props.trade.amount;
|
|
|
|
if (botStore.activeBot.botApiVersion > 1.1) {
|
|
|
|
ordertype.value =
|
|
|
|
botStore.activeBot.botState?.order_types?.force_exit ||
|
|
|
|
botStore.activeBot.botState?.order_types?.exit ||
|
|
|
|
'limit';
|
|
|
|
}
|
|
|
|
};
|
2022-08-03 18:09:45 +00:00
|
|
|
|
2023-02-15 06:05:27 +00:00
|
|
|
const handleEntry = () => {
|
|
|
|
// Trigger submit handler
|
|
|
|
handleSubmit();
|
|
|
|
};
|
2022-08-03 18:09:45 +00:00
|
|
|
</script>
|