Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
update live gekko to 0.6 events
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed Jun 29, 2018
1 parent acc8018 commit 46c984f
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 80 deletions.
Binary file removed web/vue/public/favicon.ico
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
methods: {
diff: n => moment.duration(n).humanize(),
humanizeDuration: (n) => window.humanizeDuration(n),
fmt: mom => moment.unix(mom).utc().format('YYYY-MM-DD HH:mm'),
fmt: mom => moment(mom).utc().format('YYYY-MM-DD HH:mm'),
round: n => (+n).toFixed(3),
},
}
Expand Down
10 changes: 5 additions & 5 deletions web/vue/src/components/gekko/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
th last update
th duration
tbody
tr.clickable(v-for='gekko in watchers', v-on:click='$router.push({path: `live-gekkos/watcher/${gekko.id}`})')
tr.clickable(v-for='gekko in watchers', v-on:click='$router.push({path: `live-gekkos/${gekko.id}`})')
td {{ gekko.config.watch.exchange }}
td {{ gekko.config.watch.currency }}
td {{ gekko.config.watch.asset }}
Expand All @@ -41,7 +41,7 @@
th type
th trades
tbody
tr.clickable(v-for='gekko in stratrunners', v-on:click='$router.push({path: `live-gekkos/stratrunner/${gekko.id}`})')
tr.clickable(v-for='gekko in stratrunners', v-on:click='$router.push({path: `live-gekkos/${gekko.id}`})')
td {{ gekko.config.watch.exchange }}
td {{ gekko.config.watch.currency }}
td {{ gekko.config.watch.asset }}
Expand All @@ -53,10 +53,10 @@
td
template(v-if='!gekko.report') 0
template(v-if='gekko.report') {{ round(gekko.report.profit) }} {{ gekko.watch.currency }}
td {{ gekko.logType }}
td
template(v-if='gekko.trader') {{ gekko.trader }}
td
template(v-if='gekko.trades') {{ gekko.trades.length }}
template(v-if='!gekko.events.trades') 0
template(v-if='gekko.events.trades') {{ gekko.events.trades.length }}
.hr
h2 Start a new live Gekko
router-link.btn--primary(to='/live-gekkos/new') Start a new live Gekko!
Expand Down
8 changes: 3 additions & 5 deletions web/vue/src/components/gekko/new.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
gekko-config-builder(v-on:config='updateConfig')
.hr
.txt--center(v-if='config.valid')
a.w100--s.my1.btn--primary(href='#', v-on:click.prevent='start') Start
a.w100--s.my1.btn--primary(href='#', v-on:click.prevent='start', v-if="!pendingStratrunner") Start
</template>

<script>
Expand Down Expand Up @@ -98,14 +98,12 @@ export default {
const gekko = this.existingMarketWatcher;
console.log('watching...', gekko);
if(gekko.events.latest.candle) {
this.pendingStratrunner = false;
this.startGekko((err, resp) => {
this.$router.push({
path: `/live-gekkos/stratrunner/${resp.id}`
path: `/live-gekkos/${resp.id}`
});
});
}
Expand Down Expand Up @@ -176,7 +174,7 @@ export default {
return console.error(err, resp.error);
this.$router.push({
path: `/live-gekkos/stratrunner/${resp.id}`
path: `/live-gekkos/${resp.id}`
});
},
startWatcher: function(next) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
<template lang='pug'>
div.my2
.contain(v-if='!data')
h1 Unknown Strat runner
p Gekko doesn't know what strat runner this is...
h1 Unknown Gekko instance
p Gekko doesn't know what gekko this is...
div(v-if='data')
h2.contain Strat runner
h2.contain Gekko {{ type }}
.grd.contain
.grd-row
.grd-row-col-3-6
h3 Market
.grd-row
.grd-row-col-3-6 Exchange
.grd-row-col-3-6 {{ data.watch.exchange }}
.grd-row-col-3-6 {{ config.watch.exchange }}
.grd-row
.grd-row-col-3-6 Currency
.grd-row-col-3-6 {{ data.watch.currency }}
.grd-row-col-3-6 {{ config.watch.currency }}
.grd-row
.grd-row-col-3-6 Asset
.grd-row-col-3-6 {{ data.watch.asset }}
.grd-row-col-3-6 {{ config.watch.asset }}
.grd-row
.grd-row-col-3-6 Type
.grd-row-col-3-6 {{ data.trader }}
.grd-row-col-3-6 {{ type }}
.grd-row-col-3-6
h3 Runtime
spinner(v-if='isLoading')
template(v-if='!isLoading')
.grd-row(v-if='data.firstCandle')
.grd-row(v-if='initialEvents.candle')
.grd-row-col-2-6 Watching since
.grd-row-col-4-6 {{ fmt(data.firstCandle.start) }}
.grd-row(v-if='data.lastCandle')
.grd-row-col-4-6 {{ fmt(initialEvents.candle.start) }}
.grd-row(v-if='latestEvents.candle')
.grd-row-col-2-6 Received data until
.grd-row-col-4-6 {{ fmt(data.lastCandle.start) }}
.grd-row(v-if='data.lastCandle && data.firstCandle')
.grd-row-col-4-6 {{ fmt(latestEvents.candle.start) }}
.grd-row(v-if='latestEvents.candle')
.grd-row-col-2-6 Data spanning
.grd-row-col-4-6 {{ humanizeDuration(moment(data.lastCandle.start).diff(moment(data.firstCandle.start))) }}
.grd-row(v-if='data.lastCandle && data.firstCandle')
.grd-row-col-2-6 Amount of trades
.grd-row-col-4-6 {{ data.trades.length }}
.grd-row(v-if='data.strat && data.strat.tradingAdvisor && data.strat.tradingAdvisor.candleSize')
.grd-row-col-2-6 Candle size
.grd-row-col-4-6 {{ data.strat.tradingAdvisor.candleSize }}
.grd-row(v-if='data.strat && data.strat.tradingAdvisor && data.strat.tradingAdvisor.historySize')
.grd-row-col-2-6 History size
.grd-row-col-4-6 {{ data.strat.tradingAdvisor.historySize }}
.grd-row
.grd-row-col-4-6 {{ humanizeDuration(moment(latestEvents.candle.start).diff(moment(initialEvents.candle.start))) }}
template(v-if='isStratrunner')
.grd-row
.grd-row-col-2-6 Amount of trades
.grd-row-col-4-6 {{ trades.length }}
.grd-row
.grd-row-col-2-6 Candle size
.grd-row-col-4-6 {{ config.tradingAdvisor.candleSize }}
.grd-row
.grd-row-col-2-6 History size
.grd-row-col-4-6 {{ config.tradingAdvisor.historySize }}
.grd-row(v-if='isStratrunner')
.grd-row-col-3-6
h3 Strategy
.grd-row
Expand All @@ -66,24 +67,23 @@
.grd-row-col-3-6 {{ round(report.balance) }}
.grd-row
.grd-row-col-3-6 Market
.grd-row-col-3-6 {{round(report.market / 100 * report.startPrice)}} {{ data.watch.currency }} ({{ round(report.market) }} %)
.grd-row-col-3-6 {{round(report.market / 100 * report.startPrice)}} {{ config.watch.currency }} ({{ round(report.market) }} %)
.grd-row
.grd-row-col-3-6 Profit
.grd-row-col-3-6 {{ round(report.profit) }} {{ data.watch.currency }} ({{ round(report.relativeProfit) }} %)
.grd-row-col-3-6 {{ round(report.profit) }} {{ config.watch.currency }} ({{ round(report.relativeProfit) }} %)
.grd-row
.grd-row-col-3-6 Alpha
.grd-row-col-3-6 {{ round(report.alpha) }} {{ data.watch.currency }}
p(v-if='watcher')
em This strat runner gets data from
router-link(:to='"/live-gekkos/watcher/" + watcher.id') this market watcher
.grd-row-col-3-6 {{ round(report.alpha) }} {{ config.watch.currency }}
p(v-if='isStratrunner')
em This gekko gets market data from
router-link(:to='"/live-gekkos/" + watcher.id') this market watcher
| .
template(v-if='!isLoading')
h3.contain Market graph
spinner(v-if='candleFetch === "fetching"')
template(v-if='candleFetch === "fetched"')
chart(:data='chartData', :height='300')
roundtrips(:roundtrips='data.roundtrips')

roundtrips(v-if='isStratrunner', :roundtrips='roundtrips')
</template>

<script>
Expand Down Expand Up @@ -116,39 +116,64 @@ export default {
}
},
computed: {
stratrunners: function() {
return this.$store.state.stratrunners;
id: function() {
return this.$route.params.id;
},
gekkos: function() {
return this.$store.state.gekkos;
},
data: function() {
return _.find(this.stratrunners, {id: this.$route.params.id});
if(!this.gekkos)
return false;
if(_.has(this.gekkos, this.id))
return this.gekkos[this.id];
if(_.has(this.finishedGekkos, this.id))
return this.finishedGekkos[this.id];
return false;
},
config: function() {
return _.get(this, 'data.config');
},
latestEvents: function() {
return _.get(this, 'data.events.latest');
},
initialEvents: function() {
return _.get(this, 'data.events.initial');
},
trades: function() {
return _.get(this, 'data.events.trades') || [];
},
roundtrips: function() {
return _.get(this, 'data.events.roundtrip') || [];
},
isLive: function() {
return _.has(this.gekkos, this.id);
},
type: function() {
return this.data.logType;
},
isStratrunner: function() {
return this.type !== 'watcher';
},
chartData: function() {
return {
candles: this.candles,
trades: this.trades
}
},
trades: function() {
if(!this.data)
return [];
return this.data.trades;
},
report: function() {
if(!this.data)
return;
return this.data.report;
return _.get(this.latestEvents, 'performanceReport');
},
stratName: function() {
if(this.data)
return this.data.strat.tradingAdvisor.method;
return this.data.config.tradingAdvisor.method;
},
stratParams: function() {
if(!this.data)
return '';
return 'Loading...';
let stratParams = Vue.util.extend({}, this.data.strat.params);
let stratParams = Vue.util.extend({}, this.data.config[this.stratName]);
delete stratParams.__empty;
if(_.isEmpty(stratParams))
Expand All @@ -159,23 +184,29 @@ export default {
isLoading: function() {
if(!this.data)
return true;
if(!_.isObject(this.data.firstCandle))
if(!_.get(this.data, 'events.initial.candle'))
return true;
if(!_.isObject(this.data.lastCandle))
if(!_.get(this.data, 'events.latest.candle'))
return true;
return false;
},
watchers: function() {
return this.$store.state.watchers;
},
watcher: function() {
let watch = Vue.util.extend({}, this.data.watch);
return _.find(this.watchers, { watch });
if(!this.isStratrunner) {
return false;
}
let watch = Vue.util.extend({}, this.data.config.watch);
return _.find(this.gekkos, g => {
if(g.id === this.id)
return false;
return _.isEqual(watch, g.config.watch);
});
},
},
watch: {
'data.lastCandle.start': function() {
'data.events.latest.candle.start': function() {
this.candleFetch = 'dirty';
},
data: function(val, prev) {
Expand All @@ -194,18 +225,21 @@ export default {
getCandles: function() {
this.candleFetch = 'fetching';
let to = this.data.lastCandle.start;
let from = this.data.firstCandle.start;
let candleSize = this.data.strat.tradingAdvisor.candleSize;
let to = this.data.events.latest.candle.start;
let from = this.data.events.initial.candle.start;
let candleSize = 1;
if(this.type !== 'watcher') {
candleSize = this.data.config.tradingAdvisor.candleSize;
}
let config = {
watch: this.data.watch,
daterange: {
to, from
},
// hourly candles
candleSize
};
watch: this.data.config.watch,
daterange: {
to, from
},
candleSize
};
post('getCandles', config, (err, res) => {
this.candleFetch = 'fetched';
Expand Down
6 changes: 2 additions & 4 deletions web/vue/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import config from './components/config/config.vue'

import gekkoList from './components/gekko/list.vue'
import newGekko from './components/gekko/new.vue'
import singleStratrunner from './components/gekko/singleStratrunner.vue'
import singleWatcher from './components/gekko/singleWatcher.vue'
import singleGekko from './components/gekko/singleGekko.vue'
import { connect as connectWS } from './components/global/ws'

const router = new VueRouter({
Expand All @@ -33,8 +32,7 @@ const router = new VueRouter({
{ path: '/data/importer/import/:id', component: singleImport },
{ path: '/live-gekkos', component: gekkoList },
{ path: '/live-gekkos/new', component: newGekko },
{ path: '/live-gekkos/stratrunner/:id', component: singleStratrunner },
{ path: '/live-gekkos/watcher/:id', component: singleWatcher }
{ path: '/live-gekkos/:id', component: singleGekko },
]
});

Expand Down

0 comments on commit 46c984f

Please sign in to comment.