Move pair selection to CandleChartContainer

This commit is contained in:
Matthias 2020-09-14 19:56:43 +02:00
parent 4798ca6908
commit 660a471943
2 changed files with 92 additions and 65 deletions

View File

@ -9,31 +9,54 @@
> >
<PlotConfigurator v-model="plotConfig" :columns="datasetColumns" /> <PlotConfigurator v-model="plotConfig" :columns="datasetColumns" />
</b-modal> </b-modal>
<div class="row ml-auto">
<div class="col-mb-2 mr-2"> <div class="row mr-0">
<div class="col-mb-2 ml-2">
<b-select v-model="pair" :options="availablePairs" size="sm" @change="refresh"> </b-select>
</div>
<div class="col-mb-2 ml-2 mr-2">
<b-button :disabled="!!!pair" size="sm" @click="refresh">&#x21bb;</b-button>
</div>
<div class="col-mb-2 ml-auto mr-2">
<b-select <b-select
v-model="plotConfigName" v-model="plotConfigName"
:options="availablePlotConfigNames" :options="availablePlotConfigNames"
size="sm"
@change="plotConfigChanged" @change="plotConfigChanged"
> >
</b-select> </b-select>
</div> </div>
<div class="col-mb-2 mr-2"> <div class="col-mb-2 mr-2">
<b-checkbox v-model="useUTC" title="Use UTC for graph">useUtc</b-checkbox> <b-checkbox v-model="useUTC" title="Use UTC for graph">useUtc</b-checkbox>
</div> </div>
<div class="col-mb-2 mr-3"> <div class="col-mb-2 mr-1">
<b-button size="sm" title="Plot configurator" @click="showConfigurator">&#9881;</b-button> <b-button size="sm" title="Plot configurator" @click="showConfigurator">&#9881;</b-button>
</div> </div>
</div> </div>
<CandleChart :dataset="dataset" :trades="trades" :plot-config="plotConfig" :use-u-t-c="useUTC"> <div class="row mr-1 ml-1">
</CandleChart> <CandleChart
:dataset="dataset"
:trades="trades"
:plot-config="plotConfig"
:use-u-t-c="useUTC"
>
</CandleChart>
</div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator'; import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
import { namespace } from 'vuex-class'; import { namespace } from 'vuex-class';
import { Trade, PairHistory, EMPTY_PLOTCONFIG, PlotConfig } from '@/types'; import {
Trade,
PairHistory,
EMPTY_PLOTCONFIG,
PlotConfig,
PairCandlePayload,
PairHistoryPayload,
} 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';
@ -42,11 +65,23 @@ const ftbot = namespace('ftbot');
@Component({ components: { CandleChart, PlotConfigurator } }) @Component({ components: { CandleChart, PlotConfigurator } })
export default class CandleChartContainer extends Vue { export default class CandleChartContainer extends Vue {
@Prop({ required: true }) readonly availablePairs!: string[];
@Prop({ required: true }) readonly timeframe!: string; @Prop({ required: true }) readonly timeframe!: string;
@Prop({ required: false, default: [] }) readonly trades!: Array<Trade>; @Prop({ required: false, default: [] }) readonly trades!: Array<Trade>;
@Prop({ required: true }) readonly dataset!: PairHistory; @Prop({ required: false, default: false }) historicView!: boolean;
/** Only required if historicView is true */
@Prop({ required: false, default: false }) timerange!: string;
/**
* Only required if historicView is true
*/
@Prop({ required: false, default: false }) strategy!: string;
pair = '';
useUTC = true; useUTC = true;
@ -58,6 +93,23 @@ export default class CandleChartContainer extends Vue {
@ftbot.Action setPlotConfigName; @ftbot.Action setPlotConfigName;
@ftbot.State candleData!: PairHistory;
@ftbot.State history!: PairHistory;
// 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() {
if (this.historicView) {
return this.history[`${this.pair}__${this.timeframe}`];
}
return this.candleData[`${this.pair}__${this.timeframe}`];
}
get datasetColumns() { get datasetColumns() {
return this.dataset ? this.dataset.columns : []; return this.dataset ? this.dataset.columns : [];
} }
@ -76,6 +128,27 @@ export default class CandleChartContainer extends Vue {
showConfigurator() { showConfigurator() {
this.$bvModal.show('plotConfiguratorModal'); this.$bvModal.show('plotConfiguratorModal');
} }
refresh() {
if (this.pair && this.timeframe) {
if (this.historicView) {
this.getPairHistory({
pair: this.pair,
timeframe: this.timeframe,
timerange: this.timerange,
strategy: this.strategy,
});
} else {
this.getPairCandles({ pair: this.pair, timeframe: this.timeframe, limit: 500 });
}
}
}
@Watch('availablePairs')
watchAvailablePairs() {
[this.pair] = this.availablePairs;
this.refresh();
}
} }
</script> </script>

View File

@ -4,13 +4,6 @@
<div class="col-mb-2"> <div class="col-mb-2">
<b-checkbox v-model="historicView">HistoricData</b-checkbox> <b-checkbox v-model="historicView">HistoricData</b-checkbox>
</div> </div>
<div class="col-mb-2 ml-2 mr-2">
<b-button :disabled="!!!pair" @click="refresh">&#x21bb;</b-button>
</div>
<div class="col-mb-2">
<b-select v-model="pair" :options="historicView ? pairlist : whitelist" @change="refresh">
</b-select>
</div>
</div> </div>
<div v-if="historicView" class="mt-2 row"> <div v-if="historicView" class="mt-2 row">
<TimeRangeSelect v-model="timerange" class="col-md-4 mr-2"></TimeRangeSelect> <TimeRangeSelect v-model="timerange" class="col-md-4 mr-2"></TimeRangeSelect>
@ -18,7 +11,14 @@
</div> </div>
<div class="row"> <div class="row">
<CandleChartContainer :pair="pair" :timeframe="timeframe" :dataset="dataset" :trades="trades"> <CandleChartContainer
:available-pairs="historicView ? pairlist : whitelist"
:historic-view="historicView"
:timeframe="timeframe"
:trades="trades"
:timerange="historicView ? timerange : ''"
:strategy="historicView ? strategy : ''"
>
</CandleChartContainer> </CandleChartContainer>
</div> </div>
</div> </div>
@ -30,13 +30,7 @@ import { namespace } from 'vuex-class';
import CandleChartContainer from '@/components/charts/CandleChartContainer.vue'; import CandleChartContainer from '@/components/charts/CandleChartContainer.vue';
import TimeRangeSelect from '@/components/ftbot/TimeRangeSelect.vue'; import TimeRangeSelect from '@/components/ftbot/TimeRangeSelect.vue';
import StrategyList from '@/components/ftbot/StrategyList.vue'; import StrategyList from '@/components/ftbot/StrategyList.vue';
import { import { AvailablePairPayload, AvailablePairResult, WhitelistResponse } from '@/types';
AvailablePairPayload,
AvailablePairResult,
PairCandlePayload,
PairHistoryPayload,
WhitelistResponse,
} from '@/types';
const ftbot = namespace('ftbot'); const ftbot = namespace('ftbot');
@ -44,8 +38,6 @@ const ftbot = namespace('ftbot');
components: { CandleChartContainer, StrategyList, TimeRangeSelect }, components: { CandleChartContainer, StrategyList, TimeRangeSelect },
}) })
export default class Graphs extends Vue { export default class Graphs extends Vue {
pair = '';
timeframe = '5m'; timeframe = '5m';
historicView = false; historicView = false;
@ -56,20 +48,10 @@ export default class Graphs extends Vue {
@ftbot.State pairlist; @ftbot.State pairlist;
@ftbot.State candleData;
@ftbot.State history;
@ftbot.State whitelist; @ftbot.State whitelist;
@ftbot.State trades; @ftbot.State trades;
// 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;
@ftbot.Action public getWhitelist!: () => Promise<WhitelistResponse>; @ftbot.Action public getWhitelist!: () => Promise<WhitelistResponse>;
@ftbot.Action public getAvailablePairs!: ( @ftbot.Action public getAvailablePairs!: (
@ -78,40 +60,12 @@ export default class Graphs extends Vue {
) => Promise<AvailablePairResult>; ) => Promise<AvailablePairResult>;
mounted() { mounted() {
this.getWhitelist().then((whitelist) => { this.getWhitelist();
// Autoselect first pair in whitelist // this.refresh();
if (whitelist?.whitelist?.length > 0) {
[this.pair] = whitelist.whitelist;
this.refresh();
}
});
this.refresh();
this.getAvailablePairs({ timeframe: this.timeframe }).then((val) => { this.getAvailablePairs({ timeframe: this.timeframe }).then((val) => {
console.log(val); console.log(val);
}); });
} }
get dataset() {
if (this.historicView) {
return this.history[`${this.pair}__${this.timeframe}`];
}
return this.candleData[`${this.pair}__${this.timeframe}`];
}
refresh() {
if (this.pair && this.timeframe) {
if (this.historicView) {
this.getPairHistory({
pair: this.pair,
timeframe: this.timeframe,
timerange: this.timerange,
strategy: this.strategy,
});
} else {
this.getPairCandles({ pair: this.pair, timeframe: this.timeframe, limit: 500 });
}
}
}
} }
</script> </script>