Allow forceselling in multibot environment correctly

closes #590
This commit is contained in:
Matthias 2021-11-26 07:00:09 +01:00
parent 27d433d56a
commit cf398f98e8
4 changed files with 53 additions and 22 deletions

View File

@ -77,7 +77,7 @@ import { namespace } from 'vuex-class';
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
import { formatPercent, formatPrice } from '@/shared/formatters'; 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 DeleteIcon from 'vue-material-design-icons/Delete.vue';
import ForceSellIcon from 'vue-material-design-icons/CloseBoxMultiple.vue'; import ForceSellIcon from 'vue-material-design-icons/CloseBoxMultiple.vue';
import DateTimeTZ from '@/components/general/DateTimeTZ.vue'; import DateTimeTZ from '@/components/general/DateTimeTZ.vue';
@ -119,10 +119,10 @@ export default class TradeList extends Vue {
@ftbot.Action setDetailTrade; @ftbot.Action setDetailTrade;
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action forcesell!: (tradeid: string) => Promise<string>; @ftbot.Action forceSellMulti!: (payload: MultiForcesellPayload) => Promise<string>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action deleteTrade!: (tradeid: string) => Promise<string>; @ftbot.Action deleteTradeMulti!: (payload: MultiDeletePayload) => Promise<string>;
currentPage = 1; currentPage = 1;
@ -195,7 +195,11 @@ export default class TradeList extends Vue {
.msgBoxConfirm(`Really forcesell trade ${item.trade_id} (Pair ${item.pair})?`) .msgBoxConfirm(`Really forcesell trade ${item.trade_id} (Pair ${item.pair})?`)
.then((value: boolean) => { .then((value: boolean) => {
if (value) { 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)) .then((xxx) => console.log(xxx))
.catch((error) => console.log(error.response)); .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})?`) .msgBoxConfirm(`Really delete trade ${item.trade_id} (Pair ${item.pair})?`)
.then((value: boolean) => { .then((value: boolean) => {
if (value) { 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));
} }
}); });
} }

View File

@ -4,6 +4,8 @@ import {
DailyPayload, DailyPayload,
DailyRecord, DailyRecord,
DailyReturnValue, DailyReturnValue,
MultiDeletePayload,
MultiForcesellPayload,
Trade, Trade,
} from '@/types'; } from '@/types';
import { AxiosInstance } from 'axios'; import { AxiosInstance } from 'axios';
@ -324,6 +326,15 @@ export default function createBotStore(store) {
dispatch(`${e}/getDaily`, payload); 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 // Autocreate Actions from botstores
Object.keys(BotStoreActions).forEach((e) => { Object.keys(BotStoreActions).forEach((e) => {

View File

@ -35,6 +35,7 @@ import {
StatusResponse, StatusResponse,
DeleteTradeResponse, DeleteTradeResponse,
BlacklistResponse, BlacklistResponse,
ForceSellPayload,
} from '@/types'; } from '@/types';
import { import {
@ -842,25 +843,21 @@ export function createBotSubStore(botId: string, botName: string) {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async [BotStoreActions.forcesell]({ dispatch }, tradeid: string) { async [BotStoreActions.forcesell]({ dispatch }, payload: ForceSellPayload) {
if (tradeid) {
const payload = { tradeid };
try { try {
const res = await api.post('/forcesell', payload); const res = await api.post<ForceSellPayload, AxiosResponse<StatusResponse>>(
showAlert(dispatch, `Sell order for ${tradeid} created`); '/forcesell',
payload,
);
showAlert(dispatch, `Sell order for ${payload.tradeid} created`);
return Promise.resolve(res); return Promise.resolve(res);
} catch (error) { } catch (error) {
if (axios.isAxiosError(error)) { if (axios.isAxiosError(error)) {
console.error(error.response); console.error(error.response);
} }
showAlert(dispatch, `Failed to create sell order for ${tradeid}`, 'danger'); showAlert(dispatch, `Failed to create sell order for ${payload.tradeid}`, 'danger');
return Promise.reject(error); return Promise.reject(error);
} }
}
// Error branchs
const error = 'Tradeid is empty';
console.error(error);
return Promise.reject(error);
}, },
async [BotStoreActions.forcebuy]({ dispatch }, payload: ForcebuyPayload) { async [BotStoreActions.forcebuy]({ dispatch }, payload: ForcebuyPayload) {
if (payload && payload.pair) { if (payload && payload.pair) {

View File

@ -4,6 +4,21 @@ export interface ForcebuyPayload {
ordertype?: string; 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 { export interface PerformanceEntry {
count: number; count: number;
pair: string; pair: string;