From 13324c8d372947119da508f399484f49837f25b1 Mon Sep 17 00:00:00 2001 From: Tako Date: Tue, 30 May 2023 11:41:37 +0000 Subject: [PATCH] more things to pairlistStore --- src/components/ftbot/PairlistConfigurator.vue | 51 ++--------- src/stores/pairlistConfig.ts | 86 +++++++++++++++---- 2 files changed, 74 insertions(+), 63 deletions(-) diff --git a/src/components/ftbot/PairlistConfigurator.vue b/src/components/ftbot/PairlistConfigurator.vue index 504cf4fa..cc22d696 100644 --- a/src/components/ftbot/PairlistConfigurator.vue +++ b/src/components/ftbot/PairlistConfigurator.vue @@ -85,7 +85,10 @@ - + @@ -97,7 +100,7 @@ import { useBotStore } from '@/stores/ftbotwrapper'; import { usePairlistConfigStore } from '@/stores/pairlistConfig'; import PairlistConfigItem from './PairlistConfigItem.vue'; import PairlistConfigBlacklist from './PairlistConfigBlacklist.vue'; -import { Pairlist, PairlistParamType, PairlistPayloadItem } from '@/types'; +import { Pairlist } from '@/types'; import { useSortable, moveArrayElement } from '@vueuse/integrations/useSortable'; import CopyableTextfield from '@/components/general/CopyableTextfield.vue'; @@ -119,10 +122,6 @@ const pairlistsComp = computed(() => }), ); -const configJSON = computed(() => { - return JSON.stringify(configToPayloadItems(), null, 2); -}); - useSortable(availablePairlistsEl, availablePairlists.value, { group: { name: 'configurator', @@ -161,45 +160,7 @@ onMounted(async () => { }); async function evaluateClick() { - const payload = configToPayload(); - pairlistStore.startPairlistEvaluation(payload); -} - -function convertToParamType(type: PairlistParamType, value: string) { - if (type === PairlistParamType.number) { - return Number(value); - } else if (type === PairlistParamType.boolean) { - return Boolean(value); - } else { - return String(value); - } -} - -function configToPayload() { - const pairlists: PairlistPayloadItem[] = configToPayloadItems(); - return { - pairlists: pairlists, - stake_currency: botStore.activeBot.stakeCurrency, - blacklist: pairlistStore.blacklist, - }; -} - -function configToPayloadItems() { - const pairlists: PairlistPayloadItem[] = []; - pairlistStore.config.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); - }); - - return pairlists; + pairlistStore.startPairlistEvaluation(); } diff --git a/src/stores/pairlistConfig.ts b/src/stores/pairlistConfig.ts index db468050..923709b8 100644 --- a/src/stores/pairlistConfig.ts +++ b/src/stores/pairlistConfig.ts @@ -1,7 +1,13 @@ import { defineStore } from 'pinia'; import { useBotStore } from './ftbotwrapper'; -import { Pairlist, PairlistConfig, PairlistsPayload } from '@/types'; +import { + Pairlist, + PairlistConfig, + PairlistParamType, + PairlistPayloadItem, + PairlistsPayload, +} from '@/types'; import { computed, ref, toRaw } from 'vue'; import { showAlert } from './alerts'; @@ -29,23 +35,9 @@ export const usePairlistConfigStore = defineStore( return firstPairlistIsGenerator.value && config.value.pairlists.length > 0; }); - async function startPairlistEvaluation(payload: PairlistsPayload) { - evaluating.value = true; - await botStore.activeBot.evaluatePairlist(payload); - - intervalId.value = setInterval(async () => { - const res = await botStore.activeBot.getPairlistEvalStatus(); - if (res.status === 'success' && res.result) { - clearInterval(intervalId.value); - evaluating.value = false; - whitelist.value = res.result.whitelist; - } else if (res.error) { - showAlert(res.error, 'danger'); - clearInterval(intervalId.value); - evaluating.value = false; - } - }, 1000); - } + const configJSON = computed(() => { + return JSON.stringify(configToPayloadItems(), null, 2); + }); function addToConfig(pairlist: Pairlist, index: number) { pairlist = structuredClone(toRaw(pairlist)); @@ -87,10 +79,68 @@ export const usePairlistConfigStore = defineStore( blacklist.value.splice(index, 1); } + async function startPairlistEvaluation() { + const payload: PairlistsPayload = configToPayload(); + + evaluating.value = true; + await botStore.activeBot.evaluatePairlist(payload); + + intervalId.value = setInterval(async () => { + const res = await botStore.activeBot.getPairlistEvalStatus(); + if (res.status === 'success' && res.result) { + clearInterval(intervalId.value); + evaluating.value = false; + whitelist.value = res.result.whitelist; + } else if (res.error) { + showAlert(res.error, 'danger'); + clearInterval(intervalId.value); + evaluating.value = false; + } + }, 1000); + } + + function convertToParamType(type: PairlistParamType, value: string) { + if (type === PairlistParamType.number) { + return Number(value); + } else if (type === PairlistParamType.boolean) { + return Boolean(value); + } else { + return String(value); + } + } + + function configToPayload() { + const pairlists: PairlistPayloadItem[] = configToPayloadItems(); + return { + pairlists: pairlists, + stake_currency: botStore.activeBot.stakeCurrency, + blacklist: blacklist.value, + }; + } + + function configToPayloadItems() { + const pairlists: PairlistPayloadItem[] = []; + 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); + }); + + return pairlists; + } + return { evaluating, whitelist, config, + configJSON, savedConfigs, blacklist, startPairlistEvaluation,