Skip to content

Commit

Permalink
REST API UI v1.1 (DeviaVir#1015)
Browse files Browse the repository at this point in the history
* Migrated base code from pull DeviaVir#850 minus dist files and bower code, as it is depreciated.

* Add popper.js for bootstrap

* add bootstrap, associated packages, and webpack

* add more dependencies, remove bootstrap-loader

* add babel-preset-es2015

* remove bootstrap css from app.js

* integrate non-intrusive changes, convert from bower to webpack, condense all current included css and js

* add generation data to gitignore

* add webpack dist folder to .gitignore

* modify col-xs-* to col-*, per bootstrap 4

* fix typo

* code from PR DeviaVir#850, seems to add extra stats to the tradeObject consumed in api.js
also initializes the lib.output later and announces it at the start of live trading

* Add basic README info

* accidental backtick inserted
  • Loading branch information
kernelsndrs authored and DeviaVir committed Jan 2, 2018
1 parent 9c424f4 commit 5e068ff
Show file tree
Hide file tree
Showing 17 changed files with 11,722 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ models/*.html
temp.html
logs
.sync
dist/*
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,12 @@ c.oversold_rsi_periods = 20
c.max_slippage_pct = 10
c.order_adjust_time = 10000
```
## GUI
A basic web UI is available at the url stated during startup. This port can be configured in the conf.js or randomly assigned.
In it's infancy, there are a few caveats with the current UI.
- In order to have statistics displayed, they must first be dumped from the CLI. Pressing `D` will refresh the statistics on each refresh of the dashboard.
- Currently the data is mostly static with the exception of the tradingview charts.
- Currently only READ-ONLY

## Reading the console output

Expand Down
34 changes: 33 additions & 1 deletion commands/trade.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = function container (get, set, clear) {
process.exit(1)
}
var engine = get('lib.engine')(s)
get('lib.output').initializeOutput(s)


const keyMap = new Map()
keyMap.set('b', 'limit'.grey + ' BUY'.green)
Expand Down Expand Up @@ -158,6 +158,16 @@ module.exports = function container (get, set, clear) {
output_lines.push('buy hold: ' + buy_hold.format('0.00000000').yellow + ' (' + n(buy_hold_profit).format('0.00%') + ')')
output_lines.push('vs. buy hold: ' + n(tmp_balance).subtract(buy_hold).divide(buy_hold).format('0.00%').yellow)
output_lines.push(s.my_trades.length + ' trades over ' + s.day_count + ' days (avg ' + n(s.my_trades.length / s.day_count).format('0.00') + ' trades/day)')
// Build stats for UI
s.stats = {
profit: profit.format('0.00%'),
tmp_balance: n(tmp_balance).format('0.00000000'),
buy_hold: buy_hold.format('0.00000000'),
buy_hold_profit: n(buy_hold_profit).format('0.00%'),
day_count: s.day_count,
trade_per_day: n(s.my_trades.length / s.day_count).format('0.00')
}

var last_buy
var losses = 0, sells = 0
s.my_trades.forEach(function (trade) {
Expand All @@ -174,6 +184,11 @@ module.exports = function container (get, set, clear) {
if (s.my_trades.length && sells > 0) {
output_lines.push('win/loss: ' + (sells - losses) + '/' + losses)
output_lines.push('error rate: ' + (sells ? n(losses).divide(sells).format('0.00%') : '0.00%').yellow)

//for API
s.stats.win = (sells - losses)
s.stats.losses = losses
s.stats.error_rate = (sells ? n(losses).divide(sells).format('0.00%') : '0.00%')
}
output_lines.forEach(function (line) {
console.log(line)
Expand Down Expand Up @@ -250,6 +265,16 @@ module.exports = function container (get, set, clear) {
output_lines.push('buy hold: ' + buy_hold.format('0.00000000').yellow + ' (' + n(buy_hold_profit).format('0.00%') + ')')
output_lines.push('vs. buy hold: ' + n(tmp_balance).subtract(buy_hold).divide(buy_hold).format('0.00%').yellow)
output_lines.push(s.my_trades.length + ' trades over ' + s.day_count + ' days (avg ' + n(s.my_trades.length / s.day_count).format('0.00') + ' trades/day)')
// Build stats for UI
s.stats = {
profit: profit.format('0.00%'),
tmp_balance: n(tmp_balance).format('0.00000000'),
buy_hold: buy_hold.format('0.00000000'),
buy_hold_profit: n(buy_hold_profit).format('0.00%'),
day_count: s.day_count,
trade_per_day: n(s.my_trades.length / s.day_count).format('0.00')
}

var last_buy
var losses = 0, sells = 0
s.my_trades.forEach(function (trade) {
Expand All @@ -266,6 +291,11 @@ module.exports = function container (get, set, clear) {
if (s.my_trades.length && sells > 0) {
output_lines.push('win/loss: ' + (sells - losses) + '/' + losses)
output_lines.push('error rate: ' + (sells ? n(losses).divide(sells).format('0.00%') : '0.00%').yellow)

//for API
s.stats.win = (sells - losses)
s.stats.losses = losses
s.stats.error_rate = (sells ? n(losses).divide(sells).format('0.00%') : '0.00%')
}

var html_output = output_lines.map(function (line) {
Expand Down Expand Up @@ -356,6 +386,8 @@ module.exports = function container (get, set, clear) {
get('db.trades').select(opts, function (err, trades) {
if (err) throw err
if (!trades.length) {
console.log('------------------------------------------ INITIALIZE OUTPUT ------------------------------------------')
get('lib.output').initializeOutput(s)
console.log('---------------------------- STARTING ' + so.mode.toUpperCase() + ' TRADING ----------------------------')
if (so.mode === 'paper') {
console.log('!!! Paper mode enabled. No real trades are performed until you remove --paper from the startup command.')
Expand Down
29 changes: 26 additions & 3 deletions extensions/output/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = function container (get) {
let express = require('express')
let app = express()
let random_port = require('random-port')
let path = require('path')

let run = function(reporter, tradeObject) {
if (!reporter.port || reporter.port === 0) {
Expand All @@ -16,15 +17,37 @@ module.exports = function container (get) {
}
}

let objectWithoutKey = (object, key) => {
const {[key]: deletedKey, ...otherKeys} = object;
return otherKeys;
};

let startServer = function(port, tradeObject) {
tradeObject.port = port

app.set('views', path.join(__dirname+'../../../templates'));
app.set('view engine', 'ejs');

app.use('/assets', express.static(__dirname+'../../../templates/dashboard_assets'));
app.use('/assets-wp', express.static(__dirname+'../../../dist/'));
app.use('/assets-zenbot', express.static(__dirname+'../../../assets'));

app.get('/', function (req, res) {
let datas = objectWithoutKey(tradeObject, 'options');
datas = objectWithoutKey(tradeObject, 'lookback');
res.render('dashboard', datas);
});

app.get('/trades', function (req, res) {
res.send(tradeObject)
})
res.send(objectWithoutKey(tradeObject, 'options'));
});

app.get('/stats', function (req, res) {
res.sendFile(path.join(__dirname+'../../../stats/index.html'));
});

app.listen(port)
tradeObject.url = require('ip').address() + ':' + port + '/trades'
tradeObject.url = require('ip').address() + ':' + port + '/'
console.log('api running on ' + tradeObject.url)
}

Expand Down
27 changes: 25 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,43 @@
},
"scripts": {
"test": "jasmine test/**/**.test.js",
"postinstall": "rm -rf node_modules/forex.analytics/.git"
"postinstall": "rm -rf node_modules/forex.analytics/.git && webpack -p"
},
"dependencies": {
"@slack/client": "^3.14.0",
"async": "^2.5.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"bitfinex-api-node": "^1.2.0",
"bitstamp": "^1.0.4",
"bl": "^1.2.1",
"bootstrap": "^4.0.0-beta.2",
"ccxt": "^1.10.171",
"cexio-api-node": "^1.0.8",
"cliff": "^0.1.10",
"css-loader": "^0.28.7",
"codemap": "^1.3.1",
"colors": "^1.1.2",
"commander": "^2.9.0",
"convnetjs": "0.3.0",
"counterup": "^1.0.2",
"css-loader": "^0.28.7",
"ejs": "^2.5.7",
"express": "^4.16.2",
"exports-loader": "^0.6.4",
"expose-loader": "^0.7.4",
"file-loader": "^1.1.6",
"forex.analytics": "mkmarek/forex.analytics#7bc278987700d4204e959af17de61495941d1a14",
"gdax": "coinbase/gdax-node#v0.5.0",
"gemini-api": "^2.0.4",
"glob": "^7.1.1",
"har-validator": "^5.0.3",
"idgen": "^2.0.2",
"imports-loader": "^0.7.1",
"ip": "~1.1.5",
"jasmine": "^2.8.0",
"jquery": "^3.2.1",
"kraken-api": "^0.1.7",
"mathjs": "^3.17.0",
"micro-request": "^666.0.10",
Expand All @@ -46,27 +59,37 @@
"moment": "^2.18.1",
"mongodb": "^2.2.31",
"node-prowl": "^0.1.7",
"node-sass": "^4.7.2",
"node-telegram-bot-api": "^0.29.0",
"node-uuid": "^1.4.8",
"node.bittrex.api": "^0.2.5",
"number-abbreviate": "^2.0.0",
"numbro": "highvelocityspace/numbro",
"path": "^0.12.7",
"poloniex.js": "0.0.7",
"popper.js": "^1.12.9",
"postcss-loader": "^2.0.9",
"progress": "^2.0.0",
"pushbullet": "2.0.0",
"pusher-js": "^4.1.0",
"quadrigacx": "0.0.7",
"random-port": "^0.1.0",
"regression": "^2.0.0",
"resolve-url-loader": "^2.2.1",
"run-parallel": "^1.1.6",
"run-series": "^1.1.4",
"regression": "^2.0.0",
"sass-loader": "^6.0.6",
"semver": "^5.4.1",
"simple-xmpp": "^1.3.0",
"sosa_mongo": "^1.0.3",
"stats-lite": "2.1.0",
"style-loader": "^0.19.1",
"talib": "^1.0.3",
"timebucket": "^0.4.0",
"trend": "0.3.0",
"url-loader": "^0.6.2",
"waypoints": "^4.0.1",
"webpack": "^3.10.0",
"wexnz": "^0.1.3",
"ws": "^3.2.0",
"zero-fill": "^2.2.3"
Expand Down
Loading

0 comments on commit 5e068ff

Please sign in to comment.