per config blacklist with copy option

This commit is contained in:
Tako 2023-06-09 11:02:21 +00:00
parent 6fcf47cd46
commit 7dde1648fc
3 changed files with 43 additions and 21 deletions

View File

@ -25,8 +25,19 @@
</template> </template>
<b-collapse v-model="visible"> <b-collapse v-model="visible">
<b-card-body> <b-card-body>
<b-input-group v-for="(item, i) in pairlistStore.blacklist" :key="i" class="mb-2"> <div class="d-flex mb-4 align-items-center gap-2">
<b-form-input v-model="pairlistStore.blacklist[i]" /> <span class="col-auto">Copy from:</span
><b-form-select
v-model="copyFromConfig"
size="sm"
:options="pairlistStore.savedConfigs.map((c) => c.name)"
/>
<b-button title="Copy" size="sm" @click="pairlistStore.duplicateBlacklist(copyFromConfig)"
><i-mdi-content-copy
/></b-button>
</div>
<b-input-group v-for="(item, i) in pairlistStore.config.blacklist" :key="i" class="mb-2">
<b-form-input v-model="pairlistStore.config.blacklist[i]" />
<b-input-group-append> <b-input-group-append>
<b-button size="sm" @click="pairlistStore.removeFromBlacklist(i)" <b-button size="sm" @click="pairlistStore.removeFromBlacklist(i)"
><i-mdi-close ><i-mdi-close
@ -42,7 +53,7 @@
import { ref } from 'vue'; import { ref } from 'vue';
import { usePairlistConfigStore } from '@/stores/pairlistConfig'; import { usePairlistConfigStore } from '@/stores/pairlistConfig';
const pairlistStore = usePairlistConfigStore(); const pairlistStore = usePairlistConfigStore();
const copyFromConfig = ref(pairlistStore.config.name);
const visible = ref(false); const visible = ref(false);
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>

View File

@ -23,7 +23,6 @@ export const usePairlistConfigStore = defineStore(
const intervalId = ref<number>(); const intervalId = ref<number>();
const stakeCurrency = ref<string>(botStore.activeBot?.stakeCurrency ?? 'USDT'); const stakeCurrency = ref<string>(botStore.activeBot?.stakeCurrency ?? 'USDT');
const whitelist = ref<string[]>([]); const whitelist = ref<string[]>([]);
const blacklist = ref<string[]>([]);
const customExchange = ref<boolean>(false); const customExchange = ref<boolean>(false);
const selectedExchange = ref<ExchangeSelection>({ const selectedExchange = ref<ExchangeSelection>({
exchange: botStore.activeBot?.botState.exchange ?? '', exchange: botStore.activeBot?.botState.exchange ?? '',
@ -36,7 +35,7 @@ export const usePairlistConfigStore = defineStore(
}, },
}); });
const config = ref<PairlistConfig>({ name: '', pairlists: [] }); const config = ref<PairlistConfig>(makeConfig());
const savedConfigs = ref<PairlistConfig[]>([]); const savedConfigs = ref<PairlistConfig[]>([]);
const configName = ref<string>(''); const configName = ref<string>('');
@ -86,16 +85,17 @@ export const usePairlistConfigStore = defineStore(
} }
function newConfig(name: string) { function newConfig(name: string) {
const c = { name: name, pairlists: [] }; const c = makeConfig({ name });
savedConfigs.value.push(c); savedConfigs.value.push(c);
config.value = structuredClone(c); config.value = structuredClone(c);
} }
function duplicateConfig(name = '') { function duplicateConfig(name = '') {
const c = { const c = makeConfig({
name: name, name,
pairlists: toRaw(config.value.pairlists), pairlists: toRaw(config.value.pairlists) as [],
}; blacklist: toRaw(config.value.blacklist) as [],
});
savedConfigs.value.push(c); savedConfigs.value.push(c);
config.value = structuredClone(c); config.value = structuredClone(c);
} }
@ -119,12 +119,23 @@ export const usePairlistConfigStore = defineStore(
} }
} }
function makeConfig({ name = '', pairlists = [], blacklist = [] } = {}): PairlistConfig {
return { name, pairlists, blacklist };
}
function addToBlacklist() { function addToBlacklist() {
blacklist.value.push(''); config.value.blacklist.push('');
} }
function removeFromBlacklist(index: number) { function removeFromBlacklist(index: number) {
blacklist.value.splice(index, 1); config.value.blacklist.splice(index, 1);
}
function duplicateBlacklist(configName: string) {
const conf = savedConfigs.value.find((c) => c.name === configName);
if (conf) {
config.value.blacklist = structuredClone(toRaw(conf.blacklist));
}
} }
async function startPairlistEvaluation() { async function startPairlistEvaluation() {
@ -167,19 +178,18 @@ export const usePairlistConfigStore = defineStore(
function configToPayload(): PairlistsPayload { function configToPayload(): PairlistsPayload {
const pairlists: PairlistPayloadItem[] = configToPayloadItems(); const pairlists: PairlistPayloadItem[] = configToPayloadItems();
const config: PairlistsPayload = { const c: PairlistsPayload = {
pairlists: pairlists, pairlists: pairlists,
stake_currency: stakeCurrency.value, stake_currency: stakeCurrency.value,
blacklist: blacklist.value, blacklist: config.value.blacklist,
}; };
console.log('asdf');
if (customExchange.value) { if (customExchange.value) {
console.log('setting custom exchange props'); console.log('setting custom exchange props');
config.exchange = selectedExchange.value.exchange; c.exchange = selectedExchange.value.exchange;
config.trading_mode = selectedExchange.value.trade_mode.trading_mode; c.trading_mode = selectedExchange.value.trade_mode.trading_mode;
config.margin_mode = selectedExchange.value.trade_mode.margin_mode; c.margin_mode = selectedExchange.value.trade_mode.margin_mode;
} }
return config; return c;
} }
function configToPayloadItems() { function configToPayloadItems() {
@ -216,7 +226,6 @@ export const usePairlistConfigStore = defineStore(
config, config,
configJSON, configJSON,
savedConfigs, savedConfigs,
blacklist,
configName, configName,
startPairlistEvaluation, startPairlistEvaluation,
addToConfig, addToConfig,
@ -228,6 +237,7 @@ export const usePairlistConfigStore = defineStore(
selectOrCreateConfig, selectOrCreateConfig,
addToBlacklist, addToBlacklist,
removeFromBlacklist, removeFromBlacklist,
duplicateBlacklist,
isSavedConfig, isSavedConfig,
firstPairlistIsGenerator, firstPairlistIsGenerator,
pairlistValid, pairlistValid,
@ -239,7 +249,7 @@ export const usePairlistConfigStore = defineStore(
{ {
persist: { persist: {
key: 'ftPairlistConfig', key: 'ftPairlistConfig',
paths: ['savedConfigs', 'blacklist'], paths: ['savedConfigs'],
}, },
}, },
); );

View File

@ -20,6 +20,7 @@ export interface Pairlist {
export interface PairlistConfig { export interface PairlistConfig {
name: string; name: string;
blacklist: string[];
pairlists: Pairlist[]; pairlists: Pairlist[];
} }