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

ROI calc fix #22

Merged
merged 2 commits into from
Aug 16, 2016
Merged
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: 6 additions & 5 deletions default_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = function container (get, set, clear) {
var recovery_ticks = 300
var trade_pct = 0.95
var min_trade = 0.01
var start_balance = 1000
function onOrder (err, resp, order) {
if (err) return get('logger').error('order err', err, resp, order, {feed: 'errors'})
if (resp.statusCode !== 200) {
Expand Down Expand Up @@ -92,10 +93,10 @@ module.exports = function container (get, set, clear) {
rs.progress || (rs.progress = 0)
if (!rs.market_price) return cb()
if (!rs.balance) {
// start with $1000, neutral position
// start with start_balance, neutral position
rs.balance = {}
rs.balance[currency] = 500
rs.balance[asset] = n(500).divide(rs.market_price).value()
rs.balance[currency] = start_balance/2
rs.balance[asset] = n(start_balance/2).divide(rs.market_price).value()
}
rs.ticks++
if (tick.size !== check_period) {
Expand Down Expand Up @@ -192,7 +193,7 @@ module.exports = function container (get, set, clear) {
}
// consolidate balance
var new_end_balance = n(new_balance[currency]).add(n(new_balance[asset]).multiply(rs.market_price)).value()
var new_roi = n(new_end_balance).divide(1000).value()
var new_roi = n(new_end_balance).divide(start_balance).value()
rs.balance = new_balance
rs.end_balance = new_end_balance
rs.roi = new_roi
Expand Down Expand Up @@ -225,4 +226,4 @@ module.exports = function container (get, set, clear) {
}
// END DEFAULT TRADE LOGIC
]
}
}