Improve exchange Select behavior

This commit is contained in:
Matthias 2023-06-04 15:45:49 +02:00
parent 35a81a8d9b
commit f6c0e3d0b6
3 changed files with 33 additions and 17 deletions

View File

@ -19,7 +19,7 @@
<script setup lang="ts">
import { useBotStore } from '@/stores/ftbotwrapper';
import { computed, onMounted } from 'vue';
import { computed, onMounted, watch } from 'vue';
import { ExchangeSelection } from '@/types';
const exchangeModel = defineModel({
@ -44,20 +44,33 @@ const exchangeList = computed(() => {
.map((e) => e.name);
});
const tradeModes = computed<Record<string, unknown>[]>(() => {
const val = botStore.activeBot.exchangeList
.find((ex) => ex.name === exchangeModel.value.exchange)
?.trade_modes.map((tm) => {
return (
{
text: `${tm.margin_mode} ${tm.trading_mode}`,
value: tm,
} ?? []
);
});
return (val ?? []) as Record<string, unknown>[];
const tradeModesTyped = computed(() => {
const val = botStore.activeBot.exchangeList.find(
(ex) => ex.name === exchangeModel.value.exchange,
)?.trade_modes;
return val ?? [];
});
const tradeModes = computed<Record<string, unknown>[]>(() => {
return tradeModesTyped.value.map((tm) => {
return (
{
text: `${tm.margin_mode} ${tm.trading_mode}`,
value: tm,
} ?? []
);
}) as Record<string, unknown>[];
});
watch(
() => exchangeModel.value.exchange,
() => {
if (tradeModesTyped.value.length < 2) {
exchangeModel.value.trade_mode = tradeModesTyped.value[0];
}
},
);
onMounted(() => {
if (botStore.activeBot.exchangeList.length === 0) {
botStore.activeBot.getExchangeList();

View File

@ -26,10 +26,13 @@ export const usePairlistConfigStore = defineStore(
const blacklist = ref<string[]>([]);
const customExchange = ref<boolean>(false);
const selectedExchange = ref<ExchangeSelection>({
exchange: '',
exchange: botStore.activeBot?.botState.exchange ?? '',
trade_mode: {
trading_mode: TradingMode.SPOT,
margin_mode: MarginMode.NONE,
trading_mode: botStore.activeBot?.botState.trading_mode ?? TradingMode.SPOT,
margin_mode:
botStore.activeBot?.botState.trading_mode === TradingMode.FUTURES
? MarginMode.ISOLATED
: MarginMode.NONE,
},
});

View File

@ -81,7 +81,7 @@ export enum TradingMode {
}
export enum MarginMode {
NONE = 'none',
NONE = '',
ISOLATED = 'isolated',
// CROSS = 'cross',
}