mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-22 19:15:15 +00:00
Add UI for cancel open order
This commit is contained in:
parent
5ecdce8494
commit
3e59cd8100
|
@ -36,6 +36,15 @@
|
||||||
>
|
>
|
||||||
<ForceSellIcon :size="16" title="Forceexit partial" class="me-1" />Forceexit partial
|
<ForceSellIcon :size="16" title="Forceexit partial" class="me-1" />Forceexit partial
|
||||||
</b-button>
|
</b-button>
|
||||||
|
<b-button
|
||||||
|
v-if="botApiVersion >= 2.24 && trade.open_order_id"
|
||||||
|
class="btn-xs text-start mt-1"
|
||||||
|
size="sm"
|
||||||
|
title="Cancel open orders"
|
||||||
|
@click="$emit('cancelOpenOrder', trade)"
|
||||||
|
>
|
||||||
|
<CancelIcon :size="16" title="Cancel open order" class="me-1" />Cancel open order
|
||||||
|
</b-button>
|
||||||
|
|
||||||
<b-button
|
<b-button
|
||||||
class="btn-xs text-start mt-1"
|
class="btn-xs text-start mt-1"
|
||||||
|
@ -53,6 +62,7 @@
|
||||||
import { Trade } from '@/types';
|
import { Trade } from '@/types';
|
||||||
import DeleteIcon from 'vue-material-design-icons/Delete.vue';
|
import DeleteIcon from 'vue-material-design-icons/Delete.vue';
|
||||||
import ForceSellIcon from 'vue-material-design-icons/CloseBoxMultiple.vue';
|
import ForceSellIcon from 'vue-material-design-icons/CloseBoxMultiple.vue';
|
||||||
|
import CancelIcon from 'vue-material-design-icons/Cancel.vue';
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
botApiVersion: {
|
botApiVersion: {
|
||||||
|
@ -64,7 +74,7 @@ defineProps({
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
defineEmits(['forceExit', 'forceExitPartial', 'deleteTrade']);
|
defineEmits(['forceExit', 'forceExitPartial', 'cancelOpenOrder', 'deleteTrade']);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss"></style>
|
<style scoped lang="scss"></style>
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
@deleteTrade="removeTradeHandler"
|
@deleteTrade="removeTradeHandler"
|
||||||
@forceExit="forceExitHandler"
|
@forceExit="forceExitHandler"
|
||||||
@forceExitPartial="forceExitPartialHandler"
|
@forceExitPartial="forceExitPartialHandler"
|
||||||
|
@cancel-open-order="cancelOpenOrderHandler"
|
||||||
/>
|
/>
|
||||||
</b-popover>
|
</b-popover>
|
||||||
</template>
|
</template>
|
||||||
|
@ -90,12 +91,7 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<force-exit-form v-if="activeTrades" v-model="forceExitVisible" :trade="feTrade" />
|
<force-exit-form v-if="activeTrades" v-model="forceExitVisible" :trade="feTrade" />
|
||||||
<b-modal
|
<b-modal v-model="removeTradeVisible" title="Exit trade" @ok="forceExitExecuter">
|
||||||
ref="removeTradeModal"
|
|
||||||
v-model="removeTradeVisible"
|
|
||||||
title="Exit trade"
|
|
||||||
@ok="forceExitExecuter"
|
|
||||||
>
|
|
||||||
{{ confirmExitText }}
|
{{ confirmExitText }}
|
||||||
</b-modal>
|
</b-modal>
|
||||||
</div>
|
</div>
|
||||||
|
@ -114,6 +110,13 @@ import ForceExitForm from '@/components/ftbot/ForceExitForm.vue';
|
||||||
import { ref, computed, watch } from 'vue';
|
import { ref, computed, watch } from 'vue';
|
||||||
import { useBotStore } from '@/stores/ftbotwrapper';
|
import { useBotStore } from '@/stores/ftbotwrapper';
|
||||||
|
|
||||||
|
enum ModalReasons {
|
||||||
|
removeTrade,
|
||||||
|
forceExit,
|
||||||
|
forceExitPartial,
|
||||||
|
cancelOpenOrder,
|
||||||
|
}
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
trades: { required: true, type: Array as () => Array<Trade> },
|
trades: { required: true, type: Array as () => Array<Trade> },
|
||||||
title: { default: 'Trades', type: String },
|
title: { default: 'Trades', type: String },
|
||||||
|
@ -133,7 +136,7 @@ const tradesTable = ref<HTMLFormElement>();
|
||||||
const forceExitVisible = ref(false);
|
const forceExitVisible = ref(false);
|
||||||
const removeTradeVisible = ref(false);
|
const removeTradeVisible = ref(false);
|
||||||
const confirmExitText = ref('');
|
const confirmExitText = ref('');
|
||||||
const removeTradeModal = ref<HTMLElement>();
|
const confirmExitValue = ref<ModalReasons | null>(null);
|
||||||
|
|
||||||
const openFields: Record<string, string | Function>[] = [{ key: 'actions' }];
|
const openFields: Record<string, string | Function>[] = [{ key: 'actions' }];
|
||||||
const closedFields: Record<string, string | Function>[] = [
|
const closedFields: Record<string, string | Function>[] = [
|
||||||
|
@ -180,24 +183,21 @@ const tableFields: Record<string, string | Function>[] = [
|
||||||
const feOrderType = ref<string | undefined>(undefined);
|
const feOrderType = ref<string | undefined>(undefined);
|
||||||
const forceExitHandler = (item: Trade, ordertype: string | undefined = undefined) => {
|
const forceExitHandler = (item: Trade, ordertype: string | undefined = undefined) => {
|
||||||
feTrade.value = item;
|
feTrade.value = item;
|
||||||
|
confirmExitValue.value = ModalReasons.forceExit;
|
||||||
confirmExitText.value = `Really exit trade ${item.trade_id} (Pair ${item.pair}) using ${ordertype} Order?`;
|
confirmExitText.value = `Really exit trade ${item.trade_id} (Pair ${item.pair}) using ${ordertype} Order?`;
|
||||||
removeTradeVisible.value = true;
|
removeTradeVisible.value = true;
|
||||||
feOrderType.value = ordertype;
|
feOrderType.value = ordertype;
|
||||||
};
|
};
|
||||||
|
|
||||||
const forceExitExecuter = () => {
|
const forceExitExecuter = () => {
|
||||||
// TODO: this should be done properly.
|
if (confirmExitValue.value === ModalReasons.removeTrade) {
|
||||||
if (confirmExitText.value.includes('delete')) {
|
|
||||||
const payload: MultiDeletePayload = {
|
const payload: MultiDeletePayload = {
|
||||||
tradeid: String(feTrade.value.trade_id),
|
tradeid: String(feTrade.value.trade_id),
|
||||||
botId: feTrade.value.botId,
|
botId: feTrade.value.botId,
|
||||||
};
|
};
|
||||||
botStore.deleteTradeMulti(payload).catch((error) => console.log(error.response));
|
botStore.deleteTradeMulti(payload).catch((error) => console.log(error.response));
|
||||||
removeTradeVisible.value = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
console.log(confirmExitText.value);
|
if (confirmExitValue.value === ModalReasons.forceExit) {
|
||||||
|
|
||||||
const payload: MultiForcesellPayload = {
|
const payload: MultiForcesellPayload = {
|
||||||
tradeid: String(feTrade.value.trade_id),
|
tradeid: String(feTrade.value.trade_id),
|
||||||
botId: feTrade.value.botId,
|
botId: feTrade.value.botId,
|
||||||
|
@ -209,12 +209,22 @@ const forceExitExecuter = () => {
|
||||||
.forceSellMulti(payload)
|
.forceSellMulti(payload)
|
||||||
.then((xxx) => console.log(xxx))
|
.then((xxx) => console.log(xxx))
|
||||||
.catch((error) => console.log(error.response));
|
.catch((error) => console.log(error.response));
|
||||||
|
}
|
||||||
|
if (confirmExitValue.value === ModalReasons.cancelOpenOrder) {
|
||||||
|
const payload: MultiDeletePayload = {
|
||||||
|
tradeid: String(feTrade.value.trade_id),
|
||||||
|
botId: feTrade.value.botId,
|
||||||
|
};
|
||||||
|
botStore.cancelOpenOrderMulti(payload);
|
||||||
|
}
|
||||||
|
|
||||||
feOrderType.value = undefined;
|
feOrderType.value = undefined;
|
||||||
removeTradeVisible.value = false;
|
removeTradeVisible.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeTradeHandler = (item: Trade) => {
|
const removeTradeHandler = (item: Trade) => {
|
||||||
confirmExitText.value = `Really delete trade ${item.trade_id} (Pair ${item.pair})?`;
|
confirmExitText.value = `Really delete trade ${item.trade_id} (Pair ${item.pair})?`;
|
||||||
|
confirmExitValue.value = ModalReasons.removeTrade;
|
||||||
feTrade.value = item;
|
feTrade.value = item;
|
||||||
removeTradeVisible.value = true;
|
removeTradeVisible.value = true;
|
||||||
};
|
};
|
||||||
|
@ -224,6 +234,13 @@ const forceExitPartialHandler = (item: Trade) => {
|
||||||
forceExitVisible.value = true;
|
forceExitVisible.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const cancelOpenOrderHandler = (item: Trade) => {
|
||||||
|
confirmExitText.value = `Cancel open order for trade ${item.trade_id} (Pair ${item.pair})?`;
|
||||||
|
feTrade.value = item;
|
||||||
|
confirmExitValue.value = ModalReasons.cancelOpenOrder;
|
||||||
|
removeTradeVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
const handleContextMenuEvent = (item, index, event) => {
|
const handleContextMenuEvent = (item, index, event) => {
|
||||||
// stop browser context menu from appearing
|
// stop browser context menu from appearing
|
||||||
if (!props.activeTrades) {
|
if (!props.activeTrades) {
|
||||||
|
|
|
@ -616,6 +616,21 @@ export function createBotSubStore(botId: string, botName: string) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async cancelOpenOrder(tradeid: string) {
|
||||||
|
try {
|
||||||
|
const res = await api.delete<DeleteTradeResponse>(`/trades/${tradeid}/open-order`);
|
||||||
|
showAlert(
|
||||||
|
res.data.result_msg ? res.data.result_msg : `Canceled open order for ${tradeid}`,
|
||||||
|
);
|
||||||
|
return Promise.resolve(res);
|
||||||
|
} catch (error) {
|
||||||
|
if (axios.isAxiosError(error)) {
|
||||||
|
console.error(error.response);
|
||||||
|
}
|
||||||
|
showAlert(`Failed to cancel open order ${tradeid}`, 'danger');
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
},
|
||||||
async startTrade() {
|
async startTrade() {
|
||||||
try {
|
try {
|
||||||
const res = await api.post('/start_trade', {});
|
const res = await api.post('/start_trade', {});
|
||||||
|
|
|
@ -324,6 +324,9 @@ export const useBotStore = defineStore('wrapper', {
|
||||||
async deleteTradeMulti(deletePayload: MultiDeletePayload) {
|
async deleteTradeMulti(deletePayload: MultiDeletePayload) {
|
||||||
return this.botStores[deletePayload.botId].deleteTrade(deletePayload.tradeid);
|
return this.botStores[deletePayload.botId].deleteTrade(deletePayload.tradeid);
|
||||||
},
|
},
|
||||||
|
async cancelOpenOrderMulti(deletePayload: MultiDeletePayload) {
|
||||||
|
return this.botStores[deletePayload.botId].cancelOpenOrder(deletePayload.tradeid);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user