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

Commit

Permalink
fix #39 404 for trades.csv
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez committed Aug 25, 2016
1 parent 651fc19 commit 6e18f1c
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions plugins/server/controllers/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = function container (get, set) {
.get('/sim_trades.csv', function (req, res, next) {
res.setHeader('Content-Type', 'text/csv')
res.write('Type,Time,Asset,Currency,Exchange,Price,Size,RSI,ROI\n')
if (!req.session.secret) {
return res.end()
}
get('db.run_states').load(req.query.sim_id, function (err, sim_result) {
if (err) return next(err)
if (sim_result && sim_result.actions) {
Expand All @@ -30,31 +33,29 @@ module.exports = function container (get, set) {
})
})
.get('/trades.csv', function (req, res, next) {
res.setHeader('Content-Type', 'text/csv')
res.write('Type,Time,Asset,Currency,Exchange,Price,Size,RSI,ROI\n')
if (!req.session.secret) {
res.setHeader('Content-Type', 'text/csv')
res.write('Type,Time,Asset,Currency,Exchange,Price,Size,RSI,ROI\n')
res.end()
return
return res.end()
}
get('db.run_states').load(get('zenbrain:app_name') + '_run', function (err, run_state) {
if (err) return next(err)
if (!run_state) return res.renderStatus(404)
res.setHeader('Content-Type', 'text/csv')
res.write('Type,Time,Asset,Currency,Exchange,Price,Size,RSI,ROI\n')
;(run_state.actions || []).forEach(function (action) {
var line = [
action.type,
action.time,
action.asset,
action.currency,
action.exchange,
action.price,
action.size,
action.rsi,
action.roi
].join(',')
res.write(line + '\n')
})
if (run_state && run_state.actions) {
run_state.actions.forEach(function (action) {
var line = [
action.type,
action.time,
action.asset,
action.currency,
action.exchange,
action.price,
action.size,
action.rsi,
action.roi
].join(',')
res.write(line + '\n')
})
}
res.end()
})
})
Expand Down

0 comments on commit 6e18f1c

Please sign in to comment.