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