2023-05-23 18:27:33 +00:00
|
|
|
<template>
|
2023-05-24 18:19:46 +00:00
|
|
|
<b-container fluid>
|
|
|
|
<b-row align-v="stretch">
|
2023-05-26 17:45:03 +00:00
|
|
|
<b-col cols="12" md="3" style="height: 760px; overflow-y: scroll">
|
2023-05-24 18:19:46 +00:00
|
|
|
<div ref="availablePairlistsEl" class="available-pairlists">
|
|
|
|
<b-row
|
|
|
|
v-for="pairlist in availablePairlists"
|
|
|
|
:key="pairlist.name"
|
|
|
|
align-v="center"
|
|
|
|
class="pairlist"
|
|
|
|
>
|
|
|
|
<b-col>
|
|
|
|
{{ pairlist.name }}
|
|
|
|
</b-col>
|
|
|
|
<b-col cols="auto">
|
|
|
|
<b-button
|
|
|
|
class="p-0"
|
|
|
|
style="border: none"
|
|
|
|
variant="outline-light"
|
2023-05-26 11:12:40 +00:00
|
|
|
@click="addToConfig(pairlist, selectedConfig.pairlists.length)"
|
2023-05-24 18:19:46 +00:00
|
|
|
><i-mdi-arrow-right-bold-box class="fs-4"
|
|
|
|
/></b-button>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
</div>
|
|
|
|
</b-col>
|
|
|
|
<b-col>
|
|
|
|
<b-row>
|
|
|
|
<b-col>
|
|
|
|
<b-form-input
|
|
|
|
v-model="config.name"
|
|
|
|
class="mb-2"
|
|
|
|
placeholder="Configuration name..."
|
|
|
|
></b-form-input>
|
|
|
|
</b-col>
|
|
|
|
<b-col cols="auto">
|
|
|
|
<b-button @click="save">Save</b-button>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
<div ref="pairlistConfigsEl" style="height: 100%">
|
|
|
|
<PairlistConfigItem
|
2023-05-26 11:12:40 +00:00
|
|
|
v-for="(pairlist, i) in pairlistsComp"
|
2023-05-24 18:19:46 +00:00
|
|
|
:key="pairlist.id"
|
|
|
|
v-model="config.pairlists[i]"
|
|
|
|
:index="i"
|
|
|
|
@remove="removeFromConfig"
|
|
|
|
/>
|
2023-05-26 11:12:40 +00:00
|
|
|
<b-button
|
|
|
|
:disabled="evaluating || config.pairlists.length == 0"
|
|
|
|
variant="primary"
|
|
|
|
size="lg"
|
|
|
|
squared
|
|
|
|
class="mt-2 evaluate"
|
|
|
|
@click="test"
|
|
|
|
>Evaluate</b-button
|
|
|
|
>
|
2023-05-24 18:19:46 +00:00
|
|
|
</div>
|
|
|
|
</b-col>
|
2023-05-26 11:12:40 +00:00
|
|
|
<b-col cols="12" md="3">
|
|
|
|
<pre class="text-start"><code>{{ configJSON }}</code></pre>
|
|
|
|
</b-col>
|
2023-05-24 18:19:46 +00:00
|
|
|
</b-row>
|
|
|
|
</b-container>
|
2023-05-23 18:27:33 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2023-05-24 18:19:46 +00:00
|
|
|
import { computed, onMounted, ref, toRaw, watch } from 'vue';
|
2023-05-23 18:27:33 +00:00
|
|
|
import { useBotStore } from '@/stores/ftbotwrapper';
|
|
|
|
import PairlistConfigItem from './PairlistConfigItem.vue';
|
2023-05-24 23:40:43 +00:00
|
|
|
import { Pairlist, PairlistConfig, PairlistParamType, PairlistPayloadItem } from '@/types';
|
2023-05-23 18:27:33 +00:00
|
|
|
import { useSortable, moveArrayElement } from '@vueuse/integrations/useSortable';
|
|
|
|
|
2023-05-24 23:40:43 +00:00
|
|
|
const emit = defineEmits([
|
|
|
|
'update:modelValue',
|
|
|
|
'saveConfig',
|
|
|
|
'started',
|
|
|
|
'progress',
|
|
|
|
'done',
|
|
|
|
'error',
|
|
|
|
]);
|
2023-05-23 18:27:33 +00:00
|
|
|
const props = defineProps<{
|
2023-05-26 11:12:40 +00:00
|
|
|
selectedConfig: PairlistConfig;
|
2023-05-23 18:27:33 +00:00
|
|
|
}>();
|
|
|
|
|
|
|
|
const botStore = useBotStore();
|
|
|
|
|
|
|
|
const availablePairlists = ref<Pairlist[]>([]);
|
2023-05-26 11:12:40 +00:00
|
|
|
const config = ref<PairlistConfig>(props.selectedConfig);
|
2023-05-23 18:27:33 +00:00
|
|
|
const pairlistConfigsEl = ref<HTMLElement | null>(null);
|
2023-05-24 18:19:46 +00:00
|
|
|
const availablePairlistsEl = ref<HTMLElement | null>(null);
|
2023-05-24 23:40:43 +00:00
|
|
|
const evaluating = ref(false);
|
2023-05-23 18:27:33 +00:00
|
|
|
|
|
|
|
// v-for updates with sorting, deleting and adding items seem to get wonky without unique keys for every item
|
2023-05-26 11:12:40 +00:00
|
|
|
const pairlistsComp = computed(() =>
|
2023-05-23 18:27:33 +00:00
|
|
|
config.value.pairlists.map((p) => {
|
|
|
|
if (p.id) {
|
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
return { id: Date.now().toString(36) + Math.random().toString(36).substring(2), ...p };
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2023-05-26 11:12:40 +00:00
|
|
|
const configJSON = computed(() => {
|
2023-05-26 11:43:15 +00:00
|
|
|
return JSON.stringify(configToPayloadItems(), null, 2);
|
2023-05-26 11:12:40 +00:00
|
|
|
});
|
|
|
|
|
2023-05-24 18:19:46 +00:00
|
|
|
useSortable(availablePairlistsEl, availablePairlists.value, {
|
|
|
|
group: {
|
|
|
|
name: 'configurator',
|
|
|
|
pull: 'clone',
|
|
|
|
put: false,
|
|
|
|
},
|
|
|
|
sort: false,
|
2023-05-23 18:27:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
useSortable(pairlistConfigsEl, config.value.pairlists, {
|
|
|
|
handle: '.handle',
|
2023-05-24 18:19:46 +00:00
|
|
|
group: 'configurator',
|
2023-05-23 18:27:33 +00:00
|
|
|
onUpdate: async (e) => {
|
|
|
|
moveArrayElement(config.value.pairlists, e.oldIndex, e.newIndex);
|
|
|
|
},
|
2023-05-24 18:19:46 +00:00
|
|
|
onAdd: (e) => {
|
|
|
|
const pairlist = availablePairlists.value[e.oldIndex];
|
|
|
|
addToConfig(pairlist, e.newIndex);
|
2023-05-24 21:53:10 +00:00
|
|
|
// quick fix from: https://github.com/SortableJS/Sortable/issues/1515
|
|
|
|
e.clone.replaceWith(e.item);
|
|
|
|
e.clone.remove();
|
2023-05-24 18:19:46 +00:00
|
|
|
},
|
2023-05-23 18:27:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
availablePairlists.value = (await botStore.activeBot.getPairlists()).pairlists;
|
|
|
|
});
|
|
|
|
|
2023-05-24 18:19:46 +00:00
|
|
|
const addToConfig = (pairlist: Pairlist, index: number) => {
|
|
|
|
pairlist = structuredClone(toRaw(pairlist));
|
|
|
|
for (const param in pairlist.params) {
|
|
|
|
pairlist.params[param].value = pairlist.params[param].default
|
|
|
|
? pairlist.params[param].default.toString()
|
|
|
|
: '';
|
2023-05-23 18:27:33 +00:00
|
|
|
}
|
2023-05-24 18:19:46 +00:00
|
|
|
config.value.pairlists.splice(index, 0, pairlist);
|
2023-05-23 18:27:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const removeFromConfig = (index: number) => {
|
|
|
|
config.value.pairlists.splice(index, 1);
|
|
|
|
};
|
|
|
|
|
2023-05-24 18:19:46 +00:00
|
|
|
const save = async () => {
|
2023-05-23 18:27:33 +00:00
|
|
|
emit('saveConfig', config.value);
|
|
|
|
};
|
|
|
|
|
2023-05-24 23:40:43 +00:00
|
|
|
const test = async () => {
|
|
|
|
const payload = configToPayload();
|
|
|
|
|
|
|
|
evaluating.value = true;
|
|
|
|
const res = await botStore.activeBot.evaluatePairlist(payload);
|
|
|
|
emit('started', res);
|
|
|
|
const evalIntervalId = setInterval(async () => {
|
2023-05-26 11:12:40 +00:00
|
|
|
const res = await botStore.activeBot.getPairlistEvalStatus(evalIntervalId);
|
2023-05-24 23:40:43 +00:00
|
|
|
if (res.status === 'success' && res.result) {
|
|
|
|
emit('done', res);
|
|
|
|
clearInterval(evalIntervalId);
|
|
|
|
evaluating.value = false;
|
|
|
|
} else if (res.error) {
|
|
|
|
emit('error', res);
|
|
|
|
clearInterval(evalIntervalId);
|
|
|
|
evaluating.value = false;
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertToParamType = (type: PairlistParamType, value: string) => {
|
|
|
|
if (type === PairlistParamType.number) {
|
|
|
|
return Number(value);
|
|
|
|
} else if (type === PairlistParamType.boolean) {
|
|
|
|
return Boolean(value);
|
|
|
|
} else {
|
|
|
|
return String(value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const configToPayload = () => {
|
2023-05-26 11:12:40 +00:00
|
|
|
const pairlists: PairlistPayloadItem[] = configToPayloadItems();
|
|
|
|
return {
|
|
|
|
pairlists: pairlists,
|
|
|
|
stake_currency: botStore.activeBot.stakeCurrency,
|
|
|
|
blacklist: [],
|
|
|
|
};
|
|
|
|
};
|
2023-05-24 23:40:43 +00:00
|
|
|
|
2023-05-26 11:12:40 +00:00
|
|
|
const configToPayloadItems = () => {
|
|
|
|
const pairlists: PairlistPayloadItem[] = [];
|
2023-05-24 23:40:43 +00:00
|
|
|
config.value.pairlists.forEach((config) => {
|
|
|
|
const pairlist = {
|
|
|
|
method: config.name,
|
|
|
|
};
|
|
|
|
for (const key in config.params) {
|
|
|
|
const param = config.params[key];
|
|
|
|
if (param.value) {
|
|
|
|
pairlist[key] = convertToParamType(param.type, param.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pairlists.push(pairlist);
|
|
|
|
});
|
|
|
|
|
2023-05-26 11:12:40 +00:00
|
|
|
return pairlists;
|
2023-05-24 23:40:43 +00:00
|
|
|
};
|
|
|
|
|
2023-05-24 18:19:46 +00:00
|
|
|
watch(
|
2023-05-26 11:12:40 +00:00
|
|
|
() => props.selectedConfig,
|
2023-05-24 18:19:46 +00:00
|
|
|
() => {
|
2023-05-26 11:12:40 +00:00
|
|
|
config.value = structuredClone(toRaw(props.selectedConfig));
|
2023-05-24 18:19:46 +00:00
|
|
|
},
|
|
|
|
);
|
2023-05-23 18:27:33 +00:00
|
|
|
</script>
|
2023-05-24 18:19:46 +00:00
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.pairlist {
|
2023-05-24 20:15:28 +00:00
|
|
|
padding: 1rem 0;
|
2023-05-24 18:19:46 +00:00
|
|
|
width: 100%;
|
|
|
|
border: 1px solid white;
|
|
|
|
text-align: left;
|
|
|
|
margin: 5px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.pairlist:hover {
|
|
|
|
cursor: grab;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data-theme='light'] .pairlist {
|
|
|
|
border-color: black;
|
|
|
|
}
|
|
|
|
</style>
|