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