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,37 +285,38 @@ 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(data) &&
Array.isArray(result.data) && (this.openTrades.length !== data.length ||
(this.openTrades.length !== result.data.length || !this.openTrades.every((val, index) => val.trade_id === data[index].trade_id))
!this.openTrades.every( ) {
(val, index) => val.trade_id === result.data[index].trade_id, // Open trades changed, so we should refresh now.
)) this.refreshRequired = true;
) { this.refreshSlow(false);
// Open trades changed, so we should refresh now. }
this.refreshRequired = true; if (Array.isArray(data)) {
this.refreshSlow(false); const openTrades = data.map((t) => ({
...t,
botId,
botName,
botTradeId: `${botId}__${t.trade_id}`,
// eslint-disable-next-line @typescript-eslint/camelcase
profit_ratio: t.profit_ratio ?? -1,
}));
// TODO Don't force-patch profit_ratio but handle null values properly
this.openTrades = openTrades;
if (this.selectedPair === '') {
this.selectedPair = openTrades[0]?.pair || '';
} }
if (Array.isArray(result.data)) { }
const openTrades = result.data.map((t) => ({ } catch (data) {
...t, return console.error(data);
botId, }
botName,
botTradeId: `${botId}__${t.trade_id}`,
// eslint-disable-next-line @typescript-eslint/camelcase
profit_ratio: t.profit_ratio ?? -1,
}));
// TODO Don't force-patch profit_ratio but handle null values properly
this.openTrades = openTrades;
}
})
.catch(console.error);
}, },
getLocks() { getLocks() {
return api return api