mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-13 03:33:50 +00:00
pinia: botcomparison
This commit is contained in:
parent
ef364ddc94
commit
d58d7c5fd2
|
@ -43,32 +43,16 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper';
|
|
||||||
import ProfitPill from '@/components/general/ProfitPill.vue';
|
import ProfitPill from '@/components/general/ProfitPill.vue';
|
||||||
import { formatPrice } from '@/shared/formatters';
|
import { formatPrice } from '@/shared/formatters';
|
||||||
import StoreModules from '@/store/storeSubModules';
|
|
||||||
import { defineComponent, computed } from '@vue/composition-api';
|
import { defineComponent, computed } from '@vue/composition-api';
|
||||||
import { useNamespacedGetters } from 'vuex-composition-helpers';
|
import { useBotStore } from '@/stores/ftbotwrapper';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'BotComparisonList',
|
name: 'BotComparisonList',
|
||||||
components: { ProfitPill },
|
components: { ProfitPill },
|
||||||
setup() {
|
setup() {
|
||||||
const {
|
const botStore = useBotStore();
|
||||||
allProfit,
|
|
||||||
allOpenTradeCount,
|
|
||||||
allOpenTrades,
|
|
||||||
allBotState,
|
|
||||||
allBalance,
|
|
||||||
allAvailableBots,
|
|
||||||
} = useNamespacedGetters(StoreModules.ftbot, [
|
|
||||||
MultiBotStoreGetters.allProfit,
|
|
||||||
MultiBotStoreGetters.allOpenTradeCount,
|
|
||||||
MultiBotStoreGetters.allOpenTrades,
|
|
||||||
MultiBotStoreGetters.allBotState,
|
|
||||||
MultiBotStoreGetters.allBalance,
|
|
||||||
MultiBotStoreGetters.allAvailableBots,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const tableFields: Record<string, string | Function>[] = [
|
const tableFields: Record<string, string | Function>[] = [
|
||||||
{ key: 'botId', label: 'Bot' },
|
{ key: 'botId', label: 'Bot' },
|
||||||
|
@ -93,28 +77,28 @@ export default defineComponent({
|
||||||
losses: 0,
|
losses: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.entries(allProfit.value).forEach(([k, v]: [k: string, v: any]) => {
|
Object.entries(botStore.allProfit).forEach(([k, v]: [k: string, v: any]) => {
|
||||||
const allStakes = allOpenTrades.value[k].reduce((a, b) => a + b.stake_amount, 0);
|
const allStakes = botStore.allOpenTrades[k].reduce((a, b) => a + b.stake_amount, 0);
|
||||||
const profitOpenRatio =
|
const profitOpenRatio =
|
||||||
allOpenTrades.value[k].reduce((a, b) => a + b.profit_ratio * b.stake_amount, 0) /
|
botStore.allOpenTrades[k].reduce((a, b) => a + b.profit_ratio * b.stake_amount, 0) /
|
||||||
allStakes;
|
allStakes;
|
||||||
const profitOpen = allOpenTrades.value[k].reduce((a, b) => a + b.profit_abs, 0);
|
const profitOpen = botStore.allOpenTrades[k].reduce((a, b) => a + b.profit_abs, 0);
|
||||||
|
|
||||||
// TODO: handle one inactive bot ...
|
// TODO: handle one inactive bot ...
|
||||||
val.push({
|
val.push({
|
||||||
botId: allAvailableBots.value[k].botName,
|
botId: botStore.availableBots[k].botName,
|
||||||
trades: `${allOpenTradeCount.value[k]} / ${
|
trades: `${botStore.allOpenTradeCount[k]} / ${
|
||||||
allBotState.value[k]?.max_open_trades || 'N/A'
|
botStore.allBotState[k]?.max_open_trades || 'N/A'
|
||||||
}`,
|
}`,
|
||||||
profitClosed: v.profit_closed_coin,
|
profitClosed: v.profit_closed_coin,
|
||||||
profitClosedRatio: v.profit_closed_ratio || 0,
|
profitClosedRatio: v.profit_closed_ratio || 0,
|
||||||
stakeCurrency: allBotState.value[k]?.stake_currency || '',
|
stakeCurrency: botStore.allBotState[k]?.stake_currency || '',
|
||||||
profitOpenRatio,
|
profitOpenRatio,
|
||||||
profitOpen,
|
profitOpen,
|
||||||
wins: v.winning_trades,
|
wins: v.winning_trades,
|
||||||
losses: v.losing_trades,
|
losses: v.losing_trades,
|
||||||
balance: allBalance.value[k]?.total,
|
balance: botStore.allBalance[k]?.total,
|
||||||
stakeCurrencyDecimals: allBotState.value[k]?.stake_currency_decimals || 3,
|
stakeCurrencyDecimals: botStore.allBotState[k]?.stake_currency_decimals || 3,
|
||||||
});
|
});
|
||||||
if (v.profit_closed_coin !== undefined) {
|
if (v.profit_closed_coin !== undefined) {
|
||||||
summary.profitClosed += v.profit_closed_coin;
|
summary.profitClosed += v.profit_closed_coin;
|
||||||
|
@ -129,12 +113,6 @@ export default defineComponent({
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
allProfit,
|
|
||||||
allOpenTradeCount,
|
|
||||||
allOpenTrades,
|
|
||||||
allBotState,
|
|
||||||
allBalance,
|
|
||||||
allAvailableBots,
|
|
||||||
formatPrice,
|
formatPrice,
|
||||||
tableFields,
|
tableFields,
|
||||||
tableItems,
|
tableItems,
|
||||||
|
|
|
@ -1,19 +1,25 @@
|
||||||
import { UserService } from '@/shared/userService';
|
import { UserService } from '@/shared/userService';
|
||||||
import {
|
import {
|
||||||
|
BalanceInterface,
|
||||||
BotDescriptor,
|
BotDescriptor,
|
||||||
BotDescriptors,
|
BotDescriptors,
|
||||||
|
BotState,
|
||||||
DailyPayload,
|
DailyPayload,
|
||||||
MultiDeletePayload,
|
MultiDeletePayload,
|
||||||
MultiForcesellPayload,
|
MultiForcesellPayload,
|
||||||
|
ProfitInterface,
|
||||||
RenameBotPayload,
|
RenameBotPayload,
|
||||||
|
Trade,
|
||||||
} from '@/types';
|
} from '@/types';
|
||||||
import { AxiosInstance } from 'axios';
|
import { AxiosInstance } from 'axios';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { createBotSubStore } from './ftbot';
|
import { createBotSubStore } from './ftbot';
|
||||||
const AUTH_SELECTED_BOT = 'ftSelectedBot';
|
const AUTH_SELECTED_BOT = 'ftSelectedBot';
|
||||||
|
|
||||||
|
export type BotSubStore = ReturnType<typeof createBotSubStore>;
|
||||||
|
|
||||||
export interface SubStores {
|
export interface SubStores {
|
||||||
[key: string]: ReturnType<typeof createBotSubStore>;
|
[key: string]: BotSubStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useBotStore = defineStore('wrapper', {
|
export const useBotStore = defineStore('wrapper', {
|
||||||
|
@ -32,8 +38,7 @@ export const useBotStore = defineStore('wrapper', {
|
||||||
hasBots: (state) => Object.keys(state.availableBots).length > 0,
|
hasBots: (state) => Object.keys(state.availableBots).length > 0,
|
||||||
botCount: (state) => Object.keys(state.availableBots).length,
|
botCount: (state) => Object.keys(state.availableBots).length,
|
||||||
allBotStores: (state) => Object.values(state.botStores),
|
allBotStores: (state) => Object.values(state.botStores),
|
||||||
activeBot: (state) =>
|
activeBot: (state) => state.botStores[state.selectedBot] as BotSubStore,
|
||||||
state.botStores[state.selectedBot] as ReturnType<typeof createBotSubStore>,
|
|
||||||
selectedBotObj: (state) => state.availableBots[state.selectedBot],
|
selectedBotObj: (state) => state.availableBots[state.selectedBot],
|
||||||
nextBotId: (state) => {
|
nextBotId: (state) => {
|
||||||
let botCount = Object.keys(state.availableBots).length;
|
let botCount = Object.keys(state.availableBots).length;
|
||||||
|
@ -43,6 +48,49 @@ export const useBotStore = defineStore('wrapper', {
|
||||||
}
|
}
|
||||||
return `ftbot.${botCount}`;
|
return `ftbot.${botCount}`;
|
||||||
},
|
},
|
||||||
|
allProfit: (state): Record<string, ProfitInterface> => {
|
||||||
|
const result: Record<string, ProfitInterface> = {};
|
||||||
|
Object.entries(state.botStores).forEach(([k, botStore]) => {
|
||||||
|
result[k] = botStore.profit;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
allOpenTradeCount: (state): Record<string, number> => {
|
||||||
|
const result: Record<string, number> = {};
|
||||||
|
Object.entries(state.botStores).forEach(([k, botStore]) => {
|
||||||
|
result[k] = botStore.openTradeCount;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
allOpenTrades: (state): Record<string, Trade[]> => {
|
||||||
|
const result: Record<string, Trade[]> = {};
|
||||||
|
Object.entries(state.botStores).forEach(([k, botStore]) => {
|
||||||
|
result[k] = botStore.openTrades;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
allBalance: (state): Record<string, BalanceInterface> => {
|
||||||
|
const result: Record<string, BalanceInterface> = {};
|
||||||
|
Object.entries(state.botStores).forEach(([k, botStore]) => {
|
||||||
|
result[k] = botStore.balance;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
allBotState: (state): Record<string, BotState> => {
|
||||||
|
const result: Record<string, BotState> = {};
|
||||||
|
Object.entries(state.botStores).forEach(([k, botStore]) => {
|
||||||
|
result[k] = botStore.botState;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
allOpenTradesAllBots: (state): Trade[] => {
|
||||||
|
const result: Trade[] = [];
|
||||||
|
Object.entries(state.botStores).forEach(([, botStore]) => {
|
||||||
|
result.concat([...botStore.openTrades]);
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
selectBot(botId: string) {
|
selectBot(botId: string) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user