composition: botcontrols

This commit is contained in:
Matthias 2022-04-16 07:43:26 +02:00
parent 6d231533dd
commit e79409e35f

View File

@ -63,9 +63,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Vue } from 'vue-property-decorator'; import { ForceSellPayload } from '@/types';
import { namespace } from 'vuex-class';
import { BotState, ForceSellPayload } from '@/types';
import { BotStoreActions, BotStoreGetters } from '@/store/modules/ftbot'; import { BotStoreActions, BotStoreGetters } from '@/store/modules/ftbot';
import PlayIcon from 'vue-material-design-icons/Play.vue'; import PlayIcon from 'vue-material-design-icons/Play.vue';
import StopIcon from 'vue-material-design-icons/Stop.vue'; import StopIcon from 'vue-material-design-icons/Stop.vue';
@ -75,10 +73,11 @@ import ForceSellIcon from 'vue-material-design-icons/CloseBoxMultiple.vue';
import ForceBuyIcon from 'vue-material-design-icons/PlusBoxMultipleOutline.vue'; import ForceBuyIcon from 'vue-material-design-icons/PlusBoxMultipleOutline.vue';
import StoreModules from '@/store/storeSubModules'; import StoreModules from '@/store/storeSubModules';
import ForceBuyForm from './ForceBuyForm.vue'; import ForceBuyForm from './ForceBuyForm.vue';
import { defineComponent, computed, ref } from '@vue/composition-api';
import { useNamespacedActions, useNamespacedGetters } from 'vuex-composition-helpers';
const ftbot = namespace(StoreModules.ftbot); export default defineComponent({
name: 'BotControls',
@Component({
components: { components: {
ForceBuyForm, ForceBuyForm,
PlayIcon, PlayIcon,
@ -88,73 +87,81 @@ const ftbot = namespace(StoreModules.ftbot);
ForceSellIcon, ForceSellIcon,
ForceBuyIcon, ForceBuyIcon,
}, },
}) setup(_, { root }) {
export default class BotControls extends Vue { const forcebuyShow = ref(false);
forcebuyShow = false; const { botState, isTrading, isWebserverMode } = useNamespacedGetters(StoreModules.ftbot, [
BotStoreGetters.botState,
BotStoreGetters.isTrading,
BotStoreGetters.isWebserverMode,
]);
const { startBot, stopBot, stopBuy, reloadConfig, startTrade, forcesell } =
useNamespacedActions(StoreModules.ftbot, [
BotStoreActions.startBot,
BotStoreActions.stopBot,
BotStoreActions.stopBuy,
BotStoreActions.reloadConfig,
BotStoreActions.startTrade,
BotStoreActions.forcesell,
]);
@ftbot.Getter [BotStoreGetters.botState]?: BotState; const isRunning = computed((): boolean => {
return botState.value?.state === 'running';
@ftbot.Action startBot;
@ftbot.Action stopBot;
@ftbot.Action stopBuy;
@ftbot.Action reloadConfig;
@ftbot.Action startTrade;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action [BotStoreActions.forcesell]!: (payload: ForceSellPayload) => void;
@ftbot.Getter [BotStoreGetters.isTrading]!: boolean;
@ftbot.Getter [BotStoreGetters.isWebserverMode]!: boolean;
get isRunning(): boolean {
return this.botState?.state === 'running';
}
initiateForceenter() {
this.$bvModal.show('forcebuy-modal');
}
handleStopBot() {
this.$bvModal.msgBoxConfirm('Stop Bot?').then((value: boolean) => {
if (value) {
this.stopBot();
}
}); });
}
handleStopBuy() { const initiateForceenter = () => {
this.$bvModal root.$bvModal.show('forcebuy-modal');
.msgBoxConfirm('Stop buying? Freqtrade will continue to handle open trades.') };
.then((value: boolean) => {
const handleStopBot = () => {
root.$bvModal.msgBoxConfirm('Stop Bot?').then((value: boolean) => {
if (value) { if (value) {
this.stopBuy(); stopBot();
} }
}); });
} };
handleReloadConfig() { const handleStopBuy = () => {
this.$bvModal.msgBoxConfirm('Reload configuration?').then((value: boolean) => { root.$bvModal
if (value) { .msgBoxConfirm('Stop buying? Freqtrade will continue to handle open trades.')
this.reloadConfig(); .then((value: boolean) => {
} if (value) {
}); stopBuy();
} }
});
};
handleForceSell() { const handleReloadConfig = () => {
this.$bvModal.msgBoxConfirm(`Really forcesell ALL trades?`).then((value: boolean) => { root.$bvModal.msgBoxConfirm('Reload configuration?').then((value: boolean) => {
if (value) { if (value) {
const payload: ForceSellPayload = { reloadConfig();
tradeid: 'all', }
// TODO: support ordertype (?) });
}; };
this.forcesell(payload);
} const handleForceSell = () => {
}); root.$bvModal.msgBoxConfirm(`Really forcesell ALL trades?`).then((value: boolean) => {
} if (value) {
} const payload: ForceSellPayload = {
tradeid: 'all',
// TODO: support ordertype (?)
};
forcesell(payload);
}
});
};
return {
initiateForceenter,
handleStopBot,
handleStopBuy,
handleReloadConfig,
handleForceSell,
forcebuyShow,
isTrading,
isRunning,
botState,
isWebserverMode,
startBot,
};
},
});
</script> </script>