Auto-set pair to first open trade if no selection was present

This commit is contained in:
Matthias 2023-02-27 20:38:06 +01:00
parent 5e1b1d4c7b
commit 615bf8fdda

View File

@ -285,25 +285,22 @@ export function createBotSubStore(botId: string, botName: string) {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
getOpenTrades() { async getOpenTrades() {
return api try {
.get<never, AxiosResponse<Trade[]>>('/status') const { data } = await api.get<never, AxiosResponse<Trade[]>>('/status');
.then((result) => {
// Check if trade-id's are different in this call, then trigger a full refresh // Check if trade-id's are different in this call, then trigger a full refresh
if ( if (
Array.isArray(this.openTrades) && Array.isArray(this.openTrades) &&
Array.isArray(result.data) && Array.isArray(data) &&
(this.openTrades.length !== result.data.length || (this.openTrades.length !== data.length ||
!this.openTrades.every( !this.openTrades.every((val, index) => val.trade_id === data[index].trade_id))
(val, index) => val.trade_id === result.data[index].trade_id,
))
) { ) {
// Open trades changed, so we should refresh now. // Open trades changed, so we should refresh now.
this.refreshRequired = true; this.refreshRequired = true;
this.refreshSlow(false); this.refreshSlow(false);
} }
if (Array.isArray(result.data)) { if (Array.isArray(data)) {
const openTrades = result.data.map((t) => ({ const openTrades = data.map((t) => ({
...t, ...t,
botId, botId,
botName, botName,
@ -313,9 +310,13 @@ export function createBotSubStore(botId: string, botName: string) {
})); }));
// TODO Don't force-patch profit_ratio but handle null values properly // TODO Don't force-patch profit_ratio but handle null values properly
this.openTrades = openTrades; this.openTrades = openTrades;
if (this.selectedPair === '') {
this.selectedPair = openTrades[0]?.pair || '';
}
}
} catch (data) {
return console.error(data);
} }
})
.catch(console.error);
}, },
getLocks() { getLocks() {
return api return api