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

View File

@ -26,10 +26,13 @@ export const usePairlistConfigStore = defineStore(
const blacklist = 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: '', exchange: botStore.activeBot?.botState.exchange ?? '',
trade_mode: { trade_mode: {
trading_mode: TradingMode.SPOT, trading_mode: botStore.activeBot?.botState.trading_mode ?? TradingMode.SPOT,
margin_mode: MarginMode.NONE, 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 { export enum MarginMode {
NONE = 'none', NONE = '',
ISOLATED = 'isolated', ISOLATED = 'isolated',
// CROSS = 'cross', // CROSS = 'cross',
} }