mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-11 02:33:51 +00:00
compositon: candleChartcontainer
This commit is contained in:
parent
938f3dd54b
commit
2a49381c6c
|
@ -67,7 +67,7 @@
|
||||||
:trades="trades"
|
:trades="trades"
|
||||||
:plot-config="plotConfig"
|
:plot-config="plotConfig"
|
||||||
:heikin-ashi="heikinAshi"
|
:heikin-ashi="heikinAshi"
|
||||||
:use-u-t-c="timezone === 'UTC'"
|
:use-u-t-c="settingsStore.timezone === 'UTC'"
|
||||||
:theme="getChartTheme"
|
:theme="getChartTheme"
|
||||||
>
|
>
|
||||||
</CandleChart>
|
</CandleChart>
|
||||||
|
@ -89,17 +89,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
|
import { Trade, PairHistory, EMPTY_PLOTCONFIG, PlotConfig } from '@/types';
|
||||||
import { Getter, namespace } from 'vuex-class';
|
|
||||||
import {
|
|
||||||
Trade,
|
|
||||||
PairHistory,
|
|
||||||
EMPTY_PLOTCONFIG,
|
|
||||||
PlotConfig,
|
|
||||||
PairCandlePayload,
|
|
||||||
PairHistoryPayload,
|
|
||||||
LoadingStatus,
|
|
||||||
} from '@/types';
|
|
||||||
import CandleChart from '@/components/charts/CandleChart.vue';
|
import CandleChart from '@/components/charts/CandleChart.vue';
|
||||||
import PlotConfigurator from '@/components/charts/PlotConfigurator.vue';
|
import PlotConfigurator from '@/components/charts/PlotConfigurator.vue';
|
||||||
import { getCustomPlotConfig, getPlotConfigName } from '@/shared/storage';
|
import { getCustomPlotConfig, getPlotConfigName } from '@/shared/storage';
|
||||||
|
@ -108,170 +98,168 @@ import vSelect from 'vue-select';
|
||||||
import StoreModules from '@/store/storeSubModules';
|
import StoreModules from '@/store/storeSubModules';
|
||||||
import { useSettingsStore } from '@/stores/settings';
|
import { useSettingsStore } from '@/stores/settings';
|
||||||
|
|
||||||
const ftbot = namespace(StoreModules.ftbot);
|
import { defineComponent, ref, computed, watch, onMounted } from '@vue/composition-api';
|
||||||
|
import { useGetters, useNamespacedActions, useNamespacedGetters } from 'vuex-composition-helpers';
|
||||||
|
|
||||||
@Component({ components: { CandleChart, PlotConfigurator, vSelect } })
|
export default defineComponent({
|
||||||
export default class CandleChartContainer extends Vue {
|
name: 'CandleChartContainer',
|
||||||
@Prop({ required: true }) readonly availablePairs!: string[];
|
components: { CandleChart, PlotConfigurator, vSelect },
|
||||||
|
props: {
|
||||||
@Prop({ required: true }) readonly timeframe!: string;
|
trades: { required: false, default: [], type: Array as () => Trade[] },
|
||||||
|
availablePairs: { required: true, type: Array as () => string[] },
|
||||||
@Prop({ required: false, default: () => [] }) readonly trades!: Array<Trade>;
|
timeframe: { required: true, type: String },
|
||||||
|
historicView: { required: false, default: false, type: Boolean },
|
||||||
@Prop({ required: false, default: false }) historicView!: boolean;
|
plotConfigModal: { required: false, default: true, type: Boolean },
|
||||||
|
/** Only required if historicView is true */
|
||||||
@Prop({ required: false, default: true }) plotConfigModal!: boolean;
|
timerange: { required: false, default: '', type: String },
|
||||||
|
/** Only required if historicView is true */
|
||||||
/** Only required if historicView is true */
|
strategy: { required: false, default: '', type: String },
|
||||||
@Prop({ required: false, default: false }) timerange!: string;
|
},
|
||||||
|
setup(props, { root }) {
|
||||||
/**
|
|
||||||
* Only required if historicView is true
|
|
||||||
*/
|
|
||||||
@Prop({ required: false, default: false }) strategy!: string;
|
|
||||||
|
|
||||||
pair = '';
|
|
||||||
|
|
||||||
plotConfig: PlotConfig = { ...EMPTY_PLOTCONFIG };
|
|
||||||
|
|
||||||
plotConfigName = '';
|
|
||||||
|
|
||||||
showPlotConfig = this.plotConfigModal;
|
|
||||||
|
|
||||||
heikinAshi: boolean = false;
|
|
||||||
|
|
||||||
@Getter getChartTheme!: string;
|
|
||||||
|
|
||||||
@ftbot.Getter [BotStoreGetters.availablePlotConfigNames]!: string[];
|
|
||||||
|
|
||||||
@ftbot.Action setPlotConfigName;
|
|
||||||
|
|
||||||
@ftbot.Getter [BotStoreGetters.candleDataStatus]!: LoadingStatus;
|
|
||||||
|
|
||||||
@ftbot.Getter [BotStoreGetters.candleData]!: PairHistory;
|
|
||||||
|
|
||||||
@ftbot.Getter [BotStoreGetters.historyStatus]!: LoadingStatus;
|
|
||||||
|
|
||||||
@ftbot.Getter [BotStoreGetters.history]!: PairHistory;
|
|
||||||
|
|
||||||
@ftbot.Getter [BotStoreGetters.selectedPair]!: string;
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
@ftbot.Action public getPairCandles!: (payload: PairCandlePayload) => void;
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
@ftbot.Action public getPairHistory!: (payload: PairHistoryPayload) => void;
|
|
||||||
|
|
||||||
get dataset(): PairHistory {
|
|
||||||
if (this.historicView) {
|
|
||||||
return this.history[`${this.pair}__${this.timeframe}`];
|
|
||||||
}
|
|
||||||
return this.candleData[`${this.pair}__${this.timeframe}`];
|
|
||||||
}
|
|
||||||
|
|
||||||
get strategyName() {
|
|
||||||
return this.strategy || this.dataset?.strategy || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
get datasetColumns() {
|
|
||||||
return this.dataset ? this.dataset.columns : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoadingDataset(): boolean {
|
|
||||||
if (this.historicView) {
|
|
||||||
return this.historyStatus === 'loading';
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.candleDataStatus === 'loading';
|
|
||||||
}
|
|
||||||
|
|
||||||
get noDatasetText(): string {
|
|
||||||
const status = this.historicView ? this.historyStatus : this.candleDataStatus;
|
|
||||||
|
|
||||||
switch (status) {
|
|
||||||
case 'loading':
|
|
||||||
return 'Loading...';
|
|
||||||
|
|
||||||
case 'success':
|
|
||||||
return 'No data available';
|
|
||||||
|
|
||||||
case 'error':
|
|
||||||
return 'Failed to load data';
|
|
||||||
|
|
||||||
default:
|
|
||||||
return 'Unknown';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get hasDataset(): boolean {
|
|
||||||
return !!this.dataset;
|
|
||||||
}
|
|
||||||
|
|
||||||
timezone: string = 'UTC';
|
|
||||||
|
|
||||||
mounted() {
|
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
this.timezone = settingsStore.timezone;
|
const { getChartTheme } = useGetters(['getChartTheme']);
|
||||||
settingsStore.$subscribe((_, state) => {
|
const {
|
||||||
this.timezone = state.timezone;
|
availablePlotConfigNames,
|
||||||
|
candleDataStatus,
|
||||||
|
candleData,
|
||||||
|
historyStatus,
|
||||||
|
history,
|
||||||
|
selectedPair,
|
||||||
|
} = useNamespacedGetters(StoreModules.ftbot, [
|
||||||
|
BotStoreGetters.availablePlotConfigNames,
|
||||||
|
BotStoreGetters.candleDataStatus,
|
||||||
|
BotStoreGetters.candleData,
|
||||||
|
BotStoreGetters.historyStatus,
|
||||||
|
BotStoreGetters.history,
|
||||||
|
BotStoreGetters.selectedPair,
|
||||||
|
]);
|
||||||
|
const { setPlotConfigName, getPairCandles, getPairHistory } = useNamespacedActions(
|
||||||
|
StoreModules.ftbot,
|
||||||
|
['setPlotConfigName', 'getPairCandles', 'getPairHistory'],
|
||||||
|
);
|
||||||
|
const pair = ref('');
|
||||||
|
const plotConfig = ref<PlotConfig>({ ...EMPTY_PLOTCONFIG });
|
||||||
|
const plotConfigName = ref('');
|
||||||
|
const heikinAshi = ref(false);
|
||||||
|
const showPlotConfig = ref(props.plotConfigModal);
|
||||||
|
|
||||||
|
const dataset = computed((): PairHistory => {
|
||||||
|
if (props.historicView) {
|
||||||
|
return history.value[`${pair.value}__${props.timeframe}`];
|
||||||
|
}
|
||||||
|
return candleData.value[`${pair.value}__${props.timeframe}`];
|
||||||
|
});
|
||||||
|
const strategyName = computed(() => props.strategy || dataset.value?.strategy || '');
|
||||||
|
const datasetColumns = computed(() => (dataset.value ? dataset.value.columns : []));
|
||||||
|
const hasDataset = computed(() => !!dataset.value);
|
||||||
|
const isLoadingDataset = computed((): boolean => {
|
||||||
|
if (props.historicView) {
|
||||||
|
return historyStatus.value === 'loading';
|
||||||
|
}
|
||||||
|
|
||||||
|
return candleDataStatus.value === 'loading';
|
||||||
|
});
|
||||||
|
const noDatasetText = computed((): string => {
|
||||||
|
const status = props.historicView ? historyStatus.value : candleDataStatus.value;
|
||||||
|
|
||||||
|
switch (status) {
|
||||||
|
case 'loading':
|
||||||
|
return 'Loading...';
|
||||||
|
|
||||||
|
case 'success':
|
||||||
|
return 'No data available';
|
||||||
|
|
||||||
|
case 'error':
|
||||||
|
return 'Failed to load data';
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 'Unknown';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.selectedPair) {
|
const plotConfigChanged = () => {
|
||||||
this.pair = this.selectedPair;
|
console.log('plotConfigChanged');
|
||||||
} else if (this.availablePairs.length > 0) {
|
plotConfig.value = getCustomPlotConfig(plotConfigName.value);
|
||||||
[this.pair] = this.availablePairs;
|
setPlotConfigName(plotConfigName.value);
|
||||||
}
|
};
|
||||||
this.plotConfigName = getPlotConfigName();
|
|
||||||
this.plotConfig = getCustomPlotConfig(this.plotConfigName);
|
|
||||||
|
|
||||||
if (!this.hasDataset) {
|
const showConfigurator = () => {
|
||||||
this.refresh();
|
if (props.plotConfigModal) {
|
||||||
}
|
root.$bvModal.show('plotConfiguratorModal');
|
||||||
}
|
|
||||||
|
|
||||||
plotConfigChanged() {
|
|
||||||
console.log('plotConfigChanged');
|
|
||||||
this.plotConfig = getCustomPlotConfig(this.plotConfigName);
|
|
||||||
this.setPlotConfigName(this.plotConfigName);
|
|
||||||
}
|
|
||||||
|
|
||||||
showConfigurator() {
|
|
||||||
if (this.plotConfigModal) {
|
|
||||||
this.$bvModal.show('plotConfiguratorModal');
|
|
||||||
} else {
|
|
||||||
this.showPlotConfig = !this.showPlotConfig;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
refresh() {
|
|
||||||
if (this.pair && this.timeframe) {
|
|
||||||
if (this.historicView) {
|
|
||||||
this.getPairHistory({
|
|
||||||
pair: this.pair,
|
|
||||||
timeframe: this.timeframe,
|
|
||||||
timerange: this.timerange,
|
|
||||||
strategy: this.strategy,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
this.getPairCandles({ pair: this.pair, timeframe: this.timeframe, limit: 500 });
|
showPlotConfig.value = !showPlotConfig.value;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
const refresh = () => {
|
||||||
|
if (pair.value && props.timeframe) {
|
||||||
|
if (props.historicView) {
|
||||||
|
getPairHistory({
|
||||||
|
pair: pair.value,
|
||||||
|
timeframe: props.timeframe,
|
||||||
|
timerange: props.timerange,
|
||||||
|
strategy: props.strategy,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
getPairCandles({ pair: pair.value, timeframe: props.timeframe, limit: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Watch('availablePairs')
|
watch(props.availablePairs, () => {
|
||||||
watchAvailablePairs() {
|
if (!props.availablePairs.find((p) => p === pair.value)) {
|
||||||
if (!this.availablePairs.find((pair) => pair === this.pair)) {
|
[pair.value] = props.availablePairs;
|
||||||
[this.pair] = this.availablePairs;
|
refresh();
|
||||||
this.refresh();
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
@Watch(BotStoreGetters.selectedPair)
|
watch(selectedPair, () => {
|
||||||
watchSelectedPair() {
|
pair.value = selectedPair.value;
|
||||||
this.pair = this.selectedPair;
|
refresh();
|
||||||
this.refresh();
|
});
|
||||||
}
|
|
||||||
}
|
onMounted(() => {
|
||||||
|
if (selectedPair.value) {
|
||||||
|
pair.value = selectedPair.value;
|
||||||
|
} else if (props.availablePairs.length > 0) {
|
||||||
|
[pair.value] = props.availablePairs;
|
||||||
|
}
|
||||||
|
plotConfigName.value = getPlotConfigName();
|
||||||
|
plotConfig.value = getCustomPlotConfig(plotConfigName.value);
|
||||||
|
|
||||||
|
if (!hasDataset) {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
getChartTheme,
|
||||||
|
availablePlotConfigNames,
|
||||||
|
candleDataStatus,
|
||||||
|
candleData,
|
||||||
|
historyStatus,
|
||||||
|
history,
|
||||||
|
selectedPair,
|
||||||
|
setPlotConfigName,
|
||||||
|
getPairCandles,
|
||||||
|
getPairHistory,
|
||||||
|
dataset,
|
||||||
|
strategyName,
|
||||||
|
datasetColumns,
|
||||||
|
isLoadingDataset,
|
||||||
|
noDatasetText,
|
||||||
|
hasDataset,
|
||||||
|
settingsStore,
|
||||||
|
heikinAshi,
|
||||||
|
plotConfigChanged,
|
||||||
|
showPlotConfig,
|
||||||
|
showConfigurator,
|
||||||
|
refresh,
|
||||||
|
plotConfigName,
|
||||||
|
pair,
|
||||||
|
plotConfig,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user