Zenbot: hitbtc not working

Created on 12 Nov 2017  路  10Comments  路  Source: DeviaVir/zenbot

Looks like using the old api, as hitbtc is now v2, looks liek system still runs v1. Comes out with a 403 error

enhancement

Most helpful comment

Nice! Creating orders work but I had problems getting orders, specifically the code thinks that the orders were instantly filled, however they were still open and unfilled on the hitbtc website. I think I fixed it by updating the order keywords:

    getOrder: function (opts, cb) {
      var func_args = [].slice.call(arguments)
      var client = authedClient()
      var order = orders['~' + opts.order_id]
      var args = {
        id: opts.order_id
      }
      client.privateGetOrder ({
       args
      }, {}).then(function (body) {
        if (body.status == 'filled') {
          order.status = 'done'
          order.done_at = new Date().getTime()
          order.filled_size = parseFloat(body.amount) - parseFloat(body.remaining)
          return cb(null, order)
        }
        else if (body.status == 'canceled' || body.status == 'expired' || body.status == 'suspended') {
          order.status = 'done'
          order.done_at = new Date().getTime()
          order.filled_size = '0.00000'
          return cb(null, order)
        }
        cb(null, order)
      }, function(err) {
        console.log(err)
        return retry('getOrder', func_args, err)
      })
    },

That seems to keep the trade status open and adjusts the trade with the ask quote price but after it is filled zenbot still sees it as still selling with order status: undefined.

All 10 comments

It polls all trades, unlike all the other exchanges that poll like 5 trades every poll_trades period. So because of that it just spams the terminal with trades. It doesn't listen to c.poll_trades either. I'm trying to figure out how to fix that. If anybody has any ideas please let me know.

Hey, I found the issue:
extensions/exchanges/hitbtc/exchange.js
line 95 should be moved to line 96.

It polls trades during a for loop for all available currencies in hitbtc. While it should do that for the specified currency only.

@abduegel Yes! I tried your fix and it works. I'm going to submit a pull request with that fix + an upgrade to HitBTC API 2.0. Thank you!

My PR was merged. Still working on fixing executing buys / sells

Hi, I found out that buys and sells were also not working, I'm also close to a fix.
I got buy, sell and cancel working, but getOrder is not working yet. Btw I'm trying to implement the binance functionality based on the hitbtc code (using ccxt), which is how I found out this fix.

I hope the code below could be of any help to you.
`

cancelOrder: function (opts, cb) {
  var func_args = [].slice.call(arguments)
  var client = authedClient()
  client.cancelOrder(opts.order_id, joinProduct(opts.product_id)).then(function (body) {
    if (body && (body.message === 'Order already done' || body.message === 'order not found')) return cb()
  },function(err){
    if (err) return retry('cancelOrder', func_args, err)
    cb()
  })
},

buy: function (opts, cb) {
  var func_args = [].slice.call(arguments)
  var client = authedClient()
  if (typeof opts.post_only === 'undefined') {
    opts.post_only = true
  }
  opts.type = 'limit'
  if (opts.order_type === 'taker') {
    delete opts.price
    delete opts.post_only
    opts.type = 'market'
  }
  opts.side = 'buy'
  delete opts.order_type
  var args = {}
  client.createOrder(joinProduct(opts.product_id), opts.type, opts.side, this.roundToNearest(opts.size, opts), opts.price, args).then(result => {
    if (result && result.message === 'Insufficient funds') {
      var order = {
        status: 'rejected',
        reject_reason: 'balance'
      }
      return cb(null, order)
    }
    orders['~' + result.id] = result
    cb(null, result)
  }).catch(function (error) {
    console.error('An error occurred', error)
    return retry('buy', func_args)
  })
},

sell: function (opts, cb) {
  var func_args = [].slice.call(arguments)
  var client = authedClient()
  if (typeof opts.post_only === 'undefined') {
    opts.post_only = true
  }
  opts.type = 'limit'
  if (opts.order_type === 'taker') {
    delete opts.price
    delete opts.post_only
    opts.type = 'market'
  }
  opts.side = 'sell'
  delete opts.order_type
  var args = {} 
  client.createOrder(joinProduct(opts.product_id), opts.order_type, opts.side, opts.size, opts.price, opts).then(result => {
    if (result && result.message === 'Insufficient funds') {
      var order = {
        status: 'rejected',
        reject_reason: 'balance'
  }
      return cb(null, order)
    }
    orders['~' + result.id] = result
    cb(null, result)
  }).catch(function (error) {
    console.error('An error occurred', error)
    return retry('buy', func_args)
  })
},

`

Did you try these lines on the latest version of zenbot, after I made the pull request? Your buy/sell code didn't seem to work for me. Also, it's strange that you can do cancelOrder but not getOrder, considering they use the same inputs.

It seemed to work on binance, with the same library and API. So it should be a good starting point to make this work in hitbtc, I was planning to look for a fix in HitBTC during the weekend.

(btw could you check again after you remove the "this.roundToNearest" part? that method was only neccesary for hitbtc)

The reason I posted this code is because some bugs were solved in it. For example some arguments in createOrder were undefined (like opts.market, and opts.type).

Hi, I got buying and selling working on hitbtc. Here is the exchange.js file:

https://gist.github.com/abduegal/4a049d38cae6f5f43b71b56a989ffa37
I also needed to update the update-product.js
https://gist.github.com/abduegal/d672e1e33c6f6e361969eec702389c1b

So for now HitBTC is buying and selling for me. @brucetus do you have time to create a pull request? my repository is quite a mess right now ;)

Nice! Creating orders work but I had problems getting orders, specifically the code thinks that the orders were instantly filled, however they were still open and unfilled on the hitbtc website. I think I fixed it by updating the order keywords:

    getOrder: function (opts, cb) {
      var func_args = [].slice.call(arguments)
      var client = authedClient()
      var order = orders['~' + opts.order_id]
      var args = {
        id: opts.order_id
      }
      client.privateGetOrder ({
       args
      }, {}).then(function (body) {
        if (body.status == 'filled') {
          order.status = 'done'
          order.done_at = new Date().getTime()
          order.filled_size = parseFloat(body.amount) - parseFloat(body.remaining)
          return cb(null, order)
        }
        else if (body.status == 'canceled' || body.status == 'expired' || body.status == 'suspended') {
          order.status = 'done'
          order.done_at = new Date().getTime()
          order.filled_size = '0.00000'
          return cb(null, order)
        }
        cb(null, order)
      }, function(err) {
        console.log(err)
        return retry('getOrder', func_args, err)
      })
    },

That seems to keep the trade status open and adjusts the trade with the ask quote price but after it is filled zenbot still sees it as still selling with order status: undefined.

Something wrong with order filled status: displays "buying" when already bought, displays "selling" when already sold. Does it affect further trading somehow ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michaelr524 picture michaelr524  路  3Comments

KryptoNova picture KryptoNova  路  3Comments

JensvdHeydt picture JensvdHeydt  路  3Comments

timstoop picture timstoop  路  4Comments

joeswann picture joeswann  路  4Comments