zenbot icon indicating copy to clipboard operation
zenbot copied to clipboard

[ERROR] non-200 status: 400 on a sell

Open rjohnsjr opened this issue 10 years ago • 8 comments

Since the update, zenbot has been able to buy, but not sell. In attempt to sell returns the error non-200 status: 400.

rjohnsjr avatar Sep 05 '16 14:09 rjohnsjr

nevermind - more info showed up in the logs. This was due to insufficient funds. One of the reasons it would be nice to have it cancel all existing orders first.

rjohnsjr avatar Sep 05 '16 14:09 rjohnsjr

Are you running into situations where you have sitting orders? What exchange are you using?

JFD3D avatar Sep 05 '16 19:09 JFD3D

It was - trying to run it simultaneously with a market-making program so there were open orders that caused there to be insufficient funds. I'm using GDAX. Not sure how difficult it would be to have a "cancel all open orders" API call go out right before the market order, but that would be pretty awesome if it were possible.

Thanks! Ron

rjohnsjr avatar Sep 05 '16 21:09 rjohnsjr

You should be able to cancel orders using @carlos8f's Coinbase-Exchange node for GDAX which is already installed when you ran npm install. Documentation for the GDAX API and the cancel all query can be found here: https://docs.gdax.com/#cancel-an-order

I don't trade on GDAX so I cannot confirm this myself but the command you are looking for is something like: client.cancelAllOrders() If you want this to go out right before the market order just add it to default_logic.js near the bottom before the client[rs.op] flag is triggered. Something like this might work although I don't know if lag will be a factor.

          client.cancelAllOrders()
          client[rs.op](params, function (err, resp, order) {
            onOrder(err, resp, order)
          })

I'm pretty sure this will cancel every order, not just the product_id you are currently trading. There are more functions that allow you to specify which orders you want to cancel in CoinBase-Exchange, you can find them in zenbot/node_modules/coinbase-exchange/lib/clients/authenticated.js starting on line 148

Hope this helps.

JFD3D avatar Sep 06 '16 01:09 JFD3D

Helps a ton! Thanks - I'll give it a shot and keep you posted.

  • Ron

rjohnsjr avatar Sep 06 '16 02:09 rjohnsjr

A quick update so anybody who tries this knows:

The cancel all orders API call worked but after the trade was executed launcher would report the following:

[ launcher] cmd 'run' exited with code 1, respawning now. [ launcher] cmd 'run' booting [ runner] starting

Then it try and execute another 2 trades right after with the remaining funds and it finally ended up doing trades on any trend change with "performance": null, and "waited: null"...

rjohnsjr avatar Sep 08 '16 14:09 rjohnsjr

Interesting, you said it ended up doing trades on any trend change, what trades does it execute (sell or buy)? Does it do this on a trend reversal? What RSI settings are you running? What are your settings for rs.min_double_wait and rs.min_reversal_wait? Does this only happen with client.cancelAllOrders() added or does it continue to reboot after you remove this line? Have you tried putting the cancel orders command elsewhere? Does the terminal console log any additional error information? What amounts did zenbot initially trade, the amount after or before the orders were canceled?

Also you may want to try adding a delay to this command using setTimeout() or a similar JS function. I'm not very familiar with GDAX but it may be an issue with zenbot seeing the wrong values due to lag or a miscalculation of 'performance' and 'waited' because the orders were only canceled right before the order, thus changing the amounts. You can try adding the cancel orders to the beginning of the trade signal function (I think this makes more sense since the balances may be needed to properly execute trades without crashing). On line 381 like this:

    // trigger trade signals from trends
    function (tick, trigger, rs, cb) {
      client.cancelAllOrders()

Please test with very small amounts or the very minimum, I am not responsible for any losses you may incur. BTW what is the market-making program you are running (this very well may be the issue here)? If none of this resolves the issue then it's probably best to run zenbot by itself.

JFD3D avatar Sep 12 '16 03:09 JFD3D

Thanks for the feedback. I have started running zenbot by itself. I was using Tribeca along side it but think I'm going to stick to zenbot for now because there are other issues I'm having with Tribeca as well. At some point I may give this a shot using a different account.

rjohnsjr avatar Sep 13 '16 13:09 rjohnsjr