Skip to content
This repository was archived by the owner on Feb 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,17 @@ https://www.prowlapp.com/
Supply zenbot with your TextBelt API key and zenbot will send SMS notifications to your cell phone.
https://www.textbelt.com/

## Rest API

You can enable a Rest API for Zenbot by enabling the following configuration
```
c.output.api = {}
c.output.api.on = true
c.output.api.port = 0 // 0 = random port
```
You can choose a port, or pick 0 for a random port.

Once you did that, you can call the API on: http://\<hostname\>:\<port\>/trades

## Manual trade tools

Expand Down
3 changes: 2 additions & 1 deletion commands/trade.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ 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)
keyMap.set('B', 'market'.grey + ' BUY'.green)
Expand Down
7 changes: 7 additions & 0 deletions conf-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,10 @@ c.notifiers.textbelt.phone = '3121234567'
c.notifiers.textbelt.key = 'textbelt'
// end textbelt configs

// output
c.output = {}

// REST API
c.output.api = {}
c.output.api.on = true
c.output.api.port = 0 // 0 = random port
5 changes: 5 additions & 0 deletions extensions/output/_codemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
_ns: 'zenbot',

'output.api': require('./api')
}
34 changes: 34 additions & 0 deletions extensions/output/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


module.exports = function container (get) {
let c = get('conf')
let express = require('express')
let app = express()
let random_port = require('random-port')

let run = function(reporter, tradeObject) {
if (!reporter.port || reporter.port === 0) {
random_port({from: 20000}, function(port) {
startServer(port, tradeObject)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try/catch if the port doesn't work, and we try a different one automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I will do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the random_port function already searches for a free port, so I dont think this is neccesary anymore. The function also tests explicitly if the port is available through a try / catch mechanism

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sweet! Thanks for digging that up.

})
} else {
startServer(reporter.port, tradeObject)
}
}

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

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

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

return {
run: run
}
}
1 change: 1 addition & 0 deletions lib/_codemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'srsi': require('./srsi'),
'stddev': require('./stddev'),
'notify': require('./notify'),
'output': require('./output'),
'tcf': require('./tcf'),
'vma': require('./vma'),
'lrc': require('./lrc'),
Expand Down
18 changes: 18 additions & 0 deletions lib/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = function container (get) {
var c = get('conf')

var initializeOutput = function(tradeObject) {
for (var output in c.output) {
if (c.output[output].on) {
if (c.debug) {
console.log(`initializing output ${output}`)
}
get(`output.${output}`).run(c.output[output], tradeObject)
}
}
}

return {
initializeOutput: initializeOutput
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
"commander": "^2.9.0",
"convnetjs": "0.3.0",
"ccxt": "^1.10.171",
"express": "^4.16.2",
"forex.analytics": "mkmarek/forex.analytics#7bc278987700d4204e959af17de61495941d1a14",
"gdax": "^0.4.2",
"gemini-api": "^2.0.4",
"glob": "^7.1.1",
"har-validator": "^5.0.3",
"idgen": "^2.0.2",
"ip": "~1.1.5",
"kraken-api": "^0.1.7",
"mathjs": "3.16.5",
"micro-request": "^666.0.10",
Expand All @@ -48,6 +50,7 @@
"pushbullet": "2.0.0",
"pusher-js": "^4.1.0",
"quadrigacx": "0.0.7",
"random-port": "^0.1.0",
"run-parallel": "^1.1.6",
"run-series": "^1.1.4",
"regression": "^2.0.0",
Expand Down