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

Commit

Permalink
Fix #270 and corrected balance calculation (#273)
Browse files Browse the repository at this point in the history
tested and working maker and taker when executing zenbot buy or sell. No more API down!
  • Loading branch information
nedievas authored and DeviaVir committed Jun 12, 2017
1 parent c6d6f09 commit 6b6b0e6
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions extensions/exchanges/bitfinex/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ module.exports = function container (get, set, clear) {
var balance = {asset: 0, currency: 0}
var accounts = _(body).filter(function (body) { return body.type === c.bitfinex.wallet }).forEach(function (account) {
if (account.currency.toUpperCase() === opts.currency) {
balance.currency = account.amount
balance.currency_hold = (account.amount - account.available)
balance.currency = n(account.amount).format('0.00000000')
balance.currency_hold = n(account.amount).subtract(account.available).format('0.00000000')
}
else if (account.currency.toUpperCase() === opts.asset) {
balance.asset = account.amount
balance.asset_hold = (account.amount - account.available)
balance.asset = n(account.amount).format('0.00000000')
balance.asset_hold = n(account.amount).subtract(account.available).format('0.00000000')
}
})
cb(null, balance)
Expand Down Expand Up @@ -108,15 +108,15 @@ module.exports = function container (get, set, clear) {
buy: function (opts, cb) {
var func_args = [].slice.call(arguments)
var client = authedClient()
if (typeof opts.type === 'undefined' && opts.order_type === 'maker') {
if (c.order_type === 'maker' && typeof opts.type === 'undefined') {
opts.type = 'exchange limit'
}
else if (typeof opts.type === 'undefined' && opts.order_type === 'taker') {
else if (c.order_type === 'taker' && typeof opts.type === 'undefined') {
opts.type = 'exchange market'
}
if (typeof opts.post_only === 'undefined') {
opts.post_only = true
}
opts.post_only = true
}
var symbol = joinProduct(opts.product_id)
var amount = opts.size
var price = opts.price
Expand All @@ -136,14 +136,17 @@ module.exports = function container (get, set, clear) {
is_postonly
}
client.make_request('order/new', params, function (err, body) {
var order = {
id: body && body.is_live === true ? body.id : null,
status: 'open',
price: opts.price,
size: opts.size,
post_only: !!opts.post_only,
created_at: new Date().getTime(),
filled_size: '0'
if (body.is_live === true) {
var order = {
id: body.id,
status: 'open',
price: opts.price,
size: opts.size,
post_only: !!opts.post_only,
created_at: new Date().getTime(),
filled_size: '0',
ordertype: c.order_type
}
}
if (err && err.toString('Error: Invalid order: not enough exchange balance')) {
status: 'rejected'
Expand All @@ -159,15 +162,15 @@ module.exports = function container (get, set, clear) {
sell: function (opts, cb) {
var func_args = [].slice.call(arguments)
var client = authedClient()
if (typeof opts.type === 'undefined' && opts.order_type === 'maker') {
if (c.order_type === 'maker' && typeof opts.type === 'undefined') {
opts.type = 'exchange limit'
}
else if (typeof opts.type === 'undefined' && opts.order_type === 'taker') {
else if (c.order_type === 'taker' && typeof opts.type === 'undefined') {
opts.type = 'exchange market'
}
if (typeof opts.post_only === 'undefined') {
opts.post_only = true
}
opts.post_only = true
}
var symbol = joinProduct(opts.product_id)
var amount = opts.size
var price = opts.price
Expand All @@ -187,14 +190,17 @@ module.exports = function container (get, set, clear) {
is_postonly
}
client.make_request('order/new', params, function (err, body) {
var order = {
id: body && body.is_live === true ? body.id : null,
status: 'open',
price: opts.price,
size: opts.size,
post_only: !!opts.post_only,
created_at: new Date().getTime(),
filled_size: '0'
if (body.is_live === true) {
var order = {
id: body.id,
status: 'open',
price: opts.price,
size: opts.size,
post_only: !!opts.post_only,
created_at: new Date().getTime(),
filled_size: '0',
ordertype: opts.order_type
}
}
if (err && err.toString('Error: Invalid order: not enough exchange balance')) {
status: 'rejected'
Expand Down

0 comments on commit 6b6b0e6

Please sign in to comment.