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

Commit

Permalink
Merge branch 'unstable' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
DeviaVir authored Jan 5, 2018
2 parents fccae8e + 8b588f2 commit f5aef5d
Show file tree
Hide file tree
Showing 28 changed files with 12,034 additions and 75 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
76 changes: 39 additions & 37 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
server:
build: .
volumes:
- ./conf.js:/app/conf.js
- ./extensions:/app/extensions
- ./simulations:/app/simulations
links:
- mongodb
command: [ "trade", "--paper" ]
restart: always
tty: true
environment:
- MONGODB_PORT_27017_TCP_ADDR=mongodb
version: '3.1'

mongodb:
image: mongo:latest
volumes_from:
- mongodb-data
command: mongod --smallfiles --bind_ip_all
services:

mongodb-data:
image: mongo:latest
volumes:
- ./data/db:/data/db
command: "true"
server:
build: .
volumes:
- ./conf.js:/app/conf.js
- ./extensions:/app/extensions
- ./simulations:/app/simulations
links:
- mongodb
command: [ "trade", "--paper" ]
restart: always
tty: true
depends_on:
- mongodb
environment:
- MONGODB_PORT_27017_TCP_ADDR=mongodb

# Remove below comments to use this container. "adminMongo is a Web based user interface (GUI) to handle all your MongoDB connections/databases needs."
#
#adminmongo:
# image: mrvautin/adminmongo
# links:
# - mongodb
# tty: true
# ports:
# - "1234:1234"
# environment:
# - CONN_NAME=zenbot_mongodb
# - DB_HOST=mongodb
# - DB_PORT=27017
# command: "npm start"
mongodb:
image: mongo:latest
volumes:
- ./data/db:/data/db
command: mongod --smallfiles --logpath=/dev/null
ports:
- 27017:27017

# Remove below comments to use this container. "adminMongo is a Web based user interface (GUI) to handle all your MongoDB connections/databases needs."
#
#adminmongo:
# image: mrvautin/adminmongo
# links:
# - mongodb
# tty: true
# ports:
# - "1234:1234"
# environment:
# - CONN_NAME=zenbot_mongodb
# - DB_HOST=mongodb
# - DB_PORT=27017
# command: "npm start"
44 changes: 44 additions & 0 deletions extensions/exchanges/cexio/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,31 @@ module.exports = function container (get, set, clear) {
}, 10000)
}

function refreshFees(args) {
var skew = 5000 // in ms
var now = new Date();
var nowUTC = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds())
var midnightUTC = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()).setHours(24,0,0,0)
var countdown = midnightUTC - nowUTC + skew
if (so.debug) {
var hours = parseInt((countdown/(1000*60*60))%24)
var minutes = parseInt((countdown/(1000*60))%60)
var seconds = parseInt((countdown/1000)%60)
console.log('\nRefreshing fees in ' + hours + ' hours ' + minutes + ' minutes ' + seconds + ' seconds')
}
setTimeout(function() {
exchange['setFees'].apply(exchange, args)
}, countdown)
}

var orders = {}
var exchange = {
name: 'cexio',
historyScan: 'forward',
backfillRateLimit: 0,
makerFee: 0.16,
takerFee: 0.25,
dynamicFees: true,

getProducts: function () {
return require('./products.json')
Expand Down Expand Up @@ -182,6 +200,32 @@ module.exports = function container (get, set, clear) {
})
},

setFees: function(opts) {
var func_args = [].slice.call(arguments)
var client = authedClient()
client.get_my_fee(function (err, body) {
if (err || (typeof body === 'string' && body.match(/error/))) {
if (so.debug) {
console.log(('\nsetFees ' + body + ' - using fixed fees!').red)
}
return retry('setFees', func_args)
} else {
var pair = opts.asset + ':' + opts.currency
var makerFee = (parseFloat(body[pair].buyMaker) + parseFloat(body[pair].sellMaker)) / 2
var takerFee = (parseFloat(body[pair].buy) + parseFloat(body[pair].sell)) / 2
if (exchange.makerFee != makerFee) {
if (so.debug) console.log('\nMaker fee changed: ' + exchange.makerFee + '% -> ' + makerFee + '%')
exchange.makerFee = makerFee
}
if (exchange.takerFee != takerFee) {
if (so.debug) console.log('\nTaker fee changed: ' + exchange.takerFee + '% -> ' + takerFee + '%')
exchange.takerFee = takerFee
}
}
return refreshFees(func_args)
})
},

// return the property used for range querying.
getCursor: function (trade) {
return trade.trade_id
Expand Down
24 changes: 12 additions & 12 deletions extensions/exchanges/poloniex/products.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"asset": "BCH",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Bitcoin Cash/Tether USD"
Expand Down Expand Up @@ -90,7 +90,7 @@
{
"asset": "BTC",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Bitcoin/Tether USD"
Expand Down Expand Up @@ -170,7 +170,7 @@
{
"asset": "DASH",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Dash/Tether USD"
Expand Down Expand Up @@ -234,7 +234,7 @@
{
"asset": "ETC",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Ethereum Classic/Tether USD"
Expand All @@ -250,7 +250,7 @@
{
"asset": "ETH",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Ethereum/Tether USD"
Expand Down Expand Up @@ -394,7 +394,7 @@
{
"asset": "LTC",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Litecoin/Tether USD"
Expand Down Expand Up @@ -466,7 +466,7 @@
{
"asset": "NXT",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "NXT/Tether USD"
Expand Down Expand Up @@ -562,7 +562,7 @@
{
"asset": "REP",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Augur/Tether USD"
Expand Down Expand Up @@ -626,7 +626,7 @@
{
"asset": "STR",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Stellar/Tether USD"
Expand Down Expand Up @@ -706,7 +706,7 @@
{
"asset": "XMR",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Monero/Tether USD"
Expand All @@ -730,7 +730,7 @@
{
"asset": "XRP",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Ripple/Tether USD"
Expand Down Expand Up @@ -762,7 +762,7 @@
{
"asset": "ZEC",
"currency": "USDT",
"min_total": "0.0001",
"min_total": "1",
"max_size": null,
"increment": "0.00000001",
"label": "Zcash/Tether USD"
Expand Down
9 changes: 7 additions & 2 deletions extensions/exchanges/poloniex/update-products.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ request('https://poloniex.com/public?command=returnTicker', {headers: {'User-Age
var products = []
Object.keys(ticker).forEach(function (pair) {
var asset = pair.split('_')[1], currency = pair.split('_')[0]
if(currency === "USDT"){
min_total = '1'
}else {
min_total = '0.0001'
}
products.push({
asset: asset,
currency: currency,
min_total: '0.0001',
min_total: min_total,
max_size: null,
increment: '0.00000001',
label: currencies[asset].name + '/' + currencies[currency].name
Expand All @@ -42,4 +47,4 @@ request('https://poloniex.com/public?command=returnTicker', {headers: {'User-Age
console.log('wrote', target)
process.exit()
})
})
})
Loading

0 comments on commit f5aef5d

Please sign in to comment.