diff --git a/src/components/ftbot/TradeList.vue b/src/components/ftbot/TradeList.vue index ea24f4c4..5b6fa758 100644 --- a/src/components/ftbot/TradeList.vue +++ b/src/components/ftbot/TradeList.vue @@ -77,7 +77,7 @@ import { namespace } from 'vuex-class'; // eslint-disable-next-line @typescript-eslint/no-unused-vars import { formatPercent, formatPrice } from '@/shared/formatters'; -import { Trade } from '@/types'; +import { MultiDeletePayload, MultiForcesellPayload, Trade } from '@/types'; import DeleteIcon from 'vue-material-design-icons/Delete.vue'; import ForceSellIcon from 'vue-material-design-icons/CloseBoxMultiple.vue'; import DateTimeTZ from '@/components/general/DateTimeTZ.vue'; @@ -119,10 +119,10 @@ export default class TradeList extends Vue { @ftbot.Action setDetailTrade; // eslint-disable-next-line @typescript-eslint/no-unused-vars - @ftbot.Action forcesell!: (tradeid: string) => Promise; + @ftbot.Action forceSellMulti!: (payload: MultiForcesellPayload) => Promise; // eslint-disable-next-line @typescript-eslint/no-unused-vars - @ftbot.Action deleteTrade!: (tradeid: string) => Promise; + @ftbot.Action deleteTradeMulti!: (payload: MultiDeletePayload) => Promise; currentPage = 1; @@ -195,7 +195,11 @@ export default class TradeList extends Vue { .msgBoxConfirm(`Really forcesell trade ${item.trade_id} (Pair ${item.pair})?`) .then((value: boolean) => { if (value) { - this.forcesell(String(item.trade_id)) + const payload: MultiForcesellPayload = { + tradeid: String(item.trade_id), + botId: item.botId, + }; + this.forceSellMulti(payload) .then((xxx) => console.log(xxx)) .catch((error) => console.log(error.response)); } @@ -218,7 +222,11 @@ export default class TradeList extends Vue { .msgBoxConfirm(`Really delete trade ${item.trade_id} (Pair ${item.pair})?`) .then((value: boolean) => { if (value) { - this.deleteTrade(item.trade_id).catch((error) => console.log(error.response)); + const payload: MultiDeletePayload = { + tradeid: String(item.trade_id), + botId: item.botId, + }; + this.deleteTradeMulti(payload).catch((error) => console.log(error.response)); } }); } diff --git a/src/store/modules/botStoreWrapper.ts b/src/store/modules/botStoreWrapper.ts index 2170b06e..8266e4b2 100644 --- a/src/store/modules/botStoreWrapper.ts +++ b/src/store/modules/botStoreWrapper.ts @@ -4,6 +4,8 @@ import { DailyPayload, DailyRecord, DailyReturnValue, + MultiDeletePayload, + MultiForcesellPayload, Trade, } from '@/types'; import { AxiosInstance } from 'axios'; @@ -324,6 +326,15 @@ export default function createBotStore(store) { dispatch(`${e}/getDaily`, payload); }); }, + async forceSellMulti({ dispatch }, forcesellPayload: MultiForcesellPayload) { + return dispatch(`${forcesellPayload.botId}/${[BotStoreActions.forcesell]}`, forcesellPayload); + }, + async deleteTradeMulti({ dispatch }, deletePayload: MultiDeletePayload) { + return dispatch( + `${deletePayload.botId}/${[BotStoreActions.deleteTrade]}`, + deletePayload.tradeid, + ); + }, }; // Autocreate Actions from botstores Object.keys(BotStoreActions).forEach((e) => { diff --git a/src/store/modules/ftbot/index.ts b/src/store/modules/ftbot/index.ts index 15944e43..a19f1c0f 100644 --- a/src/store/modules/ftbot/index.ts +++ b/src/store/modules/ftbot/index.ts @@ -35,6 +35,7 @@ import { StatusResponse, DeleteTradeResponse, BlacklistResponse, + ForceSellPayload, } from '@/types'; import { @@ -842,25 +843,21 @@ export function createBotSubStore(botId: string, botName: string) { return Promise.reject(error); } }, - async [BotStoreActions.forcesell]({ dispatch }, tradeid: string) { - if (tradeid) { - const payload = { tradeid }; - try { - const res = await api.post('/forcesell', payload); - showAlert(dispatch, `Sell order for ${tradeid} created`); - return Promise.resolve(res); - } catch (error) { - if (axios.isAxiosError(error)) { - console.error(error.response); - } - showAlert(dispatch, `Failed to create sell order for ${tradeid}`, 'danger'); - return Promise.reject(error); + async [BotStoreActions.forcesell]({ dispatch }, payload: ForceSellPayload) { + try { + const res = await api.post>( + '/forcesell', + payload, + ); + showAlert(dispatch, `Sell order for ${payload.tradeid} created`); + return Promise.resolve(res); + } catch (error) { + if (axios.isAxiosError(error)) { + console.error(error.response); } + showAlert(dispatch, `Failed to create sell order for ${payload.tradeid}`, 'danger'); + return Promise.reject(error); } - // Error branchs - const error = 'Tradeid is empty'; - console.error(error); - return Promise.reject(error); }, async [BotStoreActions.forcebuy]({ dispatch }, payload: ForcebuyPayload) { if (payload && payload.pair) { diff --git a/src/types/types.ts b/src/types/types.ts index 632dbff2..cd2746ef 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -4,6 +4,21 @@ export interface ForcebuyPayload { ordertype?: string; } +export interface ForceSellPayload { + tradeid: string; +} + +/** Interface only used internally to ensure the right bot is being called in a multibot environment. */ +export interface MultiForcesellPayload extends ForceSellPayload { + botId: string; +} + +/** Interface only used internally to ensure the right bot is being called in a multibot environment. */ +export interface MultiDeletePayload { + tradeid: string; + botId: string; +} + export interface PerformanceEntry { count: number; pair: string;