Merge more xmatthias changes

This commit is contained in:
Tako 2023-05-29 09:44:24 +00:00
commit db05f0aba0
3 changed files with 64 additions and 35 deletions

View File

@ -1,21 +1,17 @@
<template> <template>
<b-card no-body class="mb-2"> <b-card no-body class="mb-2">
<template #header> <template #header>
<b-row align-v="center" class="text-start"> <div class="d-flex text-start align-items-center">
<b-col> <div class="d-flex flex-grow-1 align-items-center">
<b-row align-v="center"> <i-mdi-reorder-horizontal role="button" class="handle me-2 fs-4" />
<b-col cols="auto"><i-mdi-reorder-horizontal class="handle me-2 fs-4" /></b-col> <b-button variant="link" @click="visible = !visible">
<b-col
><b-button variant="link" @click="visible = !visible">
<h6 class="mb-0">{{ pairlist.name }}</h6> <h6 class="mb-0">{{ pairlist.name }}</h6>
</b-button></b-col </b-button>
> </div>
</b-row> <b-button size="sm" @click="emit('remove', index)">
</b-col> <i-mdi-close />
<b-col cols="auto"> </b-button>
<b-button size="sm" @click="emit('remove', index)"><i-mdi-close></i-mdi-close></b-button> </div>
</b-col>
</b-row>
</template> </template>
<b-card-body :class="{ hidden: !visible }"> <b-card-body :class="{ hidden: !visible }">
<b-collapse v-model="visible"> <b-collapse v-model="visible">

View File

@ -7,7 +7,7 @@
v-for="pairlist in availablePairlists" v-for="pairlist in availablePairlists"
:key="pairlist.name" :key="pairlist.name"
align-v="center" align-v="center"
class="pairlist d-flex text-start" class="pairlist d-flex text-start align-items-center"
> >
<div class="d-flex flex-grow-1 align-items-start flex-column"> <div class="d-flex flex-grow-1 align-items-start flex-column">
<span class="fw-bold fd-italic">{{ pairlist.name }}</span> <span class="fw-bold fd-italic">{{ pairlist.name }}</span>
@ -18,8 +18,9 @@
style="border: none" style="border: none"
variant="outline-light" variant="outline-light"
@click="addToConfig(pairlist, selectedConfig.pairlists.length)" @click="addToConfig(pairlist, selectedConfig.pairlists.length)"
><i-mdi-arrow-right-bold-box class="fs-4" >
/></b-button> <i-mdi-arrow-right-bold-box-outline class="fs-4" />
</b-button>
</b-list-group-item> </b-list-group-item>
</b-list-group> </b-list-group>
</b-col> </b-col>
@ -37,6 +38,13 @@
</b-col> </b-col>
</b-row> </b-row>
<div ref="pairlistConfigsEl" class="h-100"> <div ref="pairlistConfigsEl" class="h-100">
<b-alert
:model-value="config.pairlists.length > 0 && !firstPairlistIsGenerator"
variant="warning"
>
First entry in the pairlist must be a Generating pairlist, like StaticPairList or
VolumePairList.
</b-alert>
<PairlistConfigItem <PairlistConfigItem
v-for="(pairlist, i) in pairlistsComp" v-for="(pairlist, i) in pairlistsComp"
:key="pairlist.id" :key="pairlist.id"
@ -45,12 +53,12 @@
@remove="removeFromConfig" @remove="removeFromConfig"
/> />
<b-button <b-button
:disabled="evaluating || config.pairlists.length == 0" :disabled="evaluating || !pairlistValid"
variant="primary" variant="primary"
size="lg" size="lg"
squared squared
class="mt-2 evaluate" class="mt-2 evaluate"
@click="test" @click="evaluateClick"
> >
<b-spinner v-if="evaluating" small></b-spinner> <b-spinner v-if="evaluating" small></b-spinner>
<span>{{ evaluating ? 'Evaluating...' : 'Evaluate' }}</span> <span>{{ evaluating ? 'Evaluating...' : 'Evaluate' }}</span>
@ -58,7 +66,13 @@
</div> </div>
</b-col> </b-col>
<b-col cols="12" md="3"> <b-col cols="12" md="3">
<pre class="text-start"><code>{{ configJSON }}</code></pre> <i-mdi-content-copy
v-if="isSupported && pairlistValid"
role="button"
class="position-absolute end-0 mt-1 me-3"
@click="copy(configJSON)"
/>
<pre class="text-start border p-1"><code>{{ configJSON }}</code></pre>
</b-col> </b-col>
</b-row> </b-row>
</b-container> </b-container>
@ -70,6 +84,7 @@ import { useBotStore } from '@/stores/ftbotwrapper';
import PairlistConfigItem from './PairlistConfigItem.vue'; import PairlistConfigItem from './PairlistConfigItem.vue';
import { Pairlist, PairlistConfig, PairlistParamType, PairlistPayloadItem } from '@/types'; import { Pairlist, PairlistConfig, PairlistParamType, PairlistPayloadItem } from '@/types';
import { useSortable, moveArrayElement } from '@vueuse/integrations/useSortable'; import { useSortable, moveArrayElement } from '@vueuse/integrations/useSortable';
import { useClipboard } from '@vueuse/core';
const emit = defineEmits([ const emit = defineEmits([
'update:modelValue', 'update:modelValue',
@ -91,6 +106,18 @@ const pairlistConfigsEl = ref<HTMLElement | null>(null);
const availablePairlistsEl = ref<HTMLElement | null>(null); const availablePairlistsEl = ref<HTMLElement | null>(null);
const evaluating = ref(false); const evaluating = ref(false);
const firstPairlistIsGenerator = computed<boolean>(() => {
// First pairlist must be a generator
if (config.value.pairlists[0]?.is_pairlist_generator) {
return true;
}
return false;
});
const pairlistValid = computed<boolean>(() => {
return firstPairlistIsGenerator.value && config.value.pairlists.length > 0;
});
// v-for updates with sorting, deleting and adding items seem to get wonky without unique keys for every item // v-for updates with sorting, deleting and adding items seem to get wonky without unique keys for every item
const pairlistsComp = computed(() => const pairlistsComp = computed(() =>
config.value.pairlists.map((p) => { config.value.pairlists.map((p) => {
@ -142,7 +169,7 @@ onMounted(async () => {
); );
}); });
const addToConfig = (pairlist: Pairlist, index: number) => { function addToConfig(pairlist: Pairlist, index: number) {
pairlist = structuredClone(toRaw(pairlist)); pairlist = structuredClone(toRaw(pairlist));
for (const param in pairlist.params) { for (const param in pairlist.params) {
pairlist.params[param].value = pairlist.params[param].default pairlist.params[param].value = pairlist.params[param].default
@ -150,17 +177,19 @@ const addToConfig = (pairlist: Pairlist, index: number) => {
: ''; : '';
} }
config.value.pairlists.splice(index, 0, pairlist); config.value.pairlists.splice(index, 0, pairlist);
}; }
const removeFromConfig = (index: number) => { function removeFromConfig(index: number) {
config.value.pairlists.splice(index, 1); config.value.pairlists.splice(index, 1);
}; }
const save = async () => { async function save() {
emit('saveConfig', config.value); emit('saveConfig', config.value);
}; }
const test = async () => { const { copy, isSupported } = useClipboard();
async function evaluateClick() {
const payload = configToPayload(); const payload = configToPayload();
evaluating.value = true; evaluating.value = true;
@ -178,9 +207,9 @@ const test = async () => {
evaluating.value = false; evaluating.value = false;
} }
}, 1000); }, 1000);
}; }
const convertToParamType = (type: PairlistParamType, value: string) => { function convertToParamType(type: PairlistParamType, value: string) {
if (type === PairlistParamType.number) { if (type === PairlistParamType.number) {
return Number(value); return Number(value);
} else if (type === PairlistParamType.boolean) { } else if (type === PairlistParamType.boolean) {
@ -188,18 +217,18 @@ const convertToParamType = (type: PairlistParamType, value: string) => {
} else { } else {
return String(value); return String(value);
} }
}; }
const configToPayload = () => { function configToPayload() {
const pairlists: PairlistPayloadItem[] = configToPayloadItems(); const pairlists: PairlistPayloadItem[] = configToPayloadItems();
return { return {
pairlists: pairlists, pairlists: pairlists,
stake_currency: botStore.activeBot.stakeCurrency, stake_currency: botStore.activeBot.stakeCurrency,
blacklist: [], blacklist: [],
}; };
}; }
const configToPayloadItems = () => { function configToPayloadItems() {
const pairlists: PairlistPayloadItem[] = []; const pairlists: PairlistPayloadItem[] = [];
config.value.pairlists.forEach((config) => { config.value.pairlists.forEach((config) => {
const pairlist = { const pairlist = {
@ -215,7 +244,7 @@ const configToPayloadItems = () => {
}); });
return pairlists; return pairlists;
}; }
watch( watch(
() => props.selectedConfig, () => props.selectedConfig,

View File

@ -51,6 +51,10 @@
color: $fg-color; color: $fg-color;
} }
.border {
border-color: lighten($bg-dark, 40%) !important;
}
.card { .card {
border-color: lighten($bg-dark, 10%); border-color: lighten($bg-dark, 10%);
background-color: $bg-dark; background-color: $bg-dark;