frequi_origin/src/components/ftbot/ExchangeSelect.vue

79 lines
2.0 KiB
Vue
Raw Normal View History

2023-06-04 08:01:28 +00:00
<template>
<div class="w-100 d-flex">
<b-form-select id="exchange-select" v-model="exchangeModel.exchange" :options="exchangeList">
</b-form-select>
<b-form-select
id="tradeMode-select"
v-model="exchangeModel.trade_mode"
:options="tradeModes"
:disabled="tradeModes.length < 2"
>
</b-form-select>
<div class="ms-2">
<b-button @click="botStore.activeBot.getExchangeList">
<i-mdi-refresh />
</b-button>
</div>
</div>
</template>
<script setup lang="ts">
import { useBotStore } from '@/stores/ftbotwrapper';
2023-06-04 13:45:49 +00:00
import { computed, onMounted, watch } from 'vue';
2023-06-04 08:01:28 +00:00
import { ExchangeSelection } from '@/types';
const exchangeModel = defineModel({
type: Object as () => ExchangeSelection,
required: true,
});
const botStore = useBotStore();
const exchangeList = computed(() => {
2023-06-07 18:33:22 +00:00
const supported = botStore.activeBot.exchangeList
.filter((ex) => ex.valid && ex.supported)
.sort((a, b) => a.name.localeCompare(b.name));
const unsupported = botStore.activeBot.exchangeList
.filter((ex) => ex.valid && !ex.supported)
.sort((a, b) => a.name.localeCompare(b.name));
return [
{ label: 'Supported', options: supported.map((e) => e.name) },
{ label: 'Unsupported', options: unsupported.map((e) => e.name) },
];
2023-06-04 08:01:28 +00:00
});
2023-06-04 13:45:49 +00:00
const tradeModesTyped = computed(() => {
const val = botStore.activeBot.exchangeList.find(
(ex) => ex.name === exchangeModel.value.exchange,
)?.trade_modes;
return val ?? [];
});
2023-06-04 08:01:28 +00:00
const tradeModes = computed<Record<string, unknown>[]>(() => {
2023-06-04 13:45:49 +00:00
return tradeModesTyped.value.map((tm) => {
return (
{
text: `${tm.margin_mode} ${tm.trading_mode}`,
value: tm,
} ?? []
);
}) as Record<string, unknown>[];
2023-06-04 08:01:28 +00:00
});
2023-06-04 13:45:49 +00:00
watch(
() => exchangeModel.value.exchange,
() => {
if (tradeModesTyped.value.length < 2) {
exchangeModel.value.trade_mode = tradeModesTyped.value[0];
}
},
);
2023-06-04 08:01:28 +00:00
onMounted(() => {
if (botStore.activeBot.exchangeList.length === 0) {
botStore.activeBot.getExchangeList();
}
});
</script>