kuzetsa / gekko

A GHS reinvestment bot written in node.js
GNU Affero General Public License v3.0
15 stars 4 forks source link

parseFloat(data.BTC.available) error on start-up. #4

Open JamieCressey opened 10 years ago

JamieCressey commented 10 years ago

Upon startup, I receive the following error

/root/cex/exchanges/cexio.js:121
    currency = parseFloat(data.BTC.available)
                                  ^
TypeError: Cannot read property 'available' of undefined
    at calculate (/root/cex/exchanges/cexio.js:121:35)
    at bound (/root/cex/node_modules/lodash/dist/lodash.js:729:21)
    at IncomingMessage.<anonymous> (/root/cex/node_modules/cexio/cexio.js:65:9)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

This is only shown when "trader" is enabled. The username\key\secret being used have been tested elsewhere successfully.

kuzetsa commented 10 years ago

That error is caused by a problem with the API data returned by the exchange being "not good"

So far, the only people who have reported errors like this were trying to use an older key.

cex.io lets you make a second API key (or third, etc.)

Please make a new one, and when you do, take a note on which permissions you've enabled (or disabled) for the API key, and if you're able to reproduce this error with the fresh API key, let me know.

... Include that information about which permissions are enabled / disabled when you update this github issue.


In the meantime, what version of the node.js engine are you using?

You can confirm by just typing:

node -v

The latest version is v0.10.29

JamieCressey commented 10 years ago

Hey kuzetsa. I tried creating a new API key, with full permissions and activated it. Using these credentials I receive the same error.

node version is v0.10.25, which I believe to be the latest available upstream for Ubuntu 14.04.

JamieCressey commented 10 years ago

Just tested the new key on the original Gekko code and get the same error. I am assuming its a problem at CEXio's side. The key is verified - as much as the secret is now hidden. Yet not working!

kuzetsa commented 10 years ago

Obfuscate, omit, or redact the key & secret if you're worried about it, but could you please post your config.js?

http://gist.github.com/


Also, when is the last time you ran the command:

npm update

(that may help, since gekko uses some 3rd party modules from the node package manager system)

Midgardsomr commented 10 years ago

Same problem here. System is Raspbian with nodejs 0.10.25. My config.js:

// Everything is explained here:
// https://github.com/kuzetsa/gekko/blob/master/docs/Configuring_gekko.md

var config = {};

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                          GENERAL SETTINGS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Gekko stores historical history
config.history = {
  // in what directory should Gekko store
  // and load historical data from?
  directory: './history/'
};

config.debug = false; // for additional logging / debugging

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                         WATCHING A MARKET
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Monitor the live market
config.watch = {
  enabled: true,
  exchange: 'cexio', // 'MtGox', 'BTCe', 'Bitstamp', 'cexio' or 'kraken'
  currency: 'BTC',
  asset: 'GHS'
};

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                       CONFIGURING TRADING ADVICE
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

config.tradingAdvisor = {
  enabled: true,
  method: 'ZERO',
  candleSize: 1,
  historySize: 887
};

// Exponential Moving Averages settings:
config.DEMA = {
  // EMA weight (α)
  // the higher the weight, the more smooth (and delayed) the line
  short: 10,
  long: 21,
  // amount of candles to remember and base initial EMAs on
  // the difference between the EMAs (to act as triggers)
  thresholds: {
    down: -0.025,
    up: 0.025
  }
};

// MACD settings:
config.MACD = {
  // EMA weight (α)
  // the higher the weight, the more smooth (and delayed) the line
  short: 53,
  long: 109,
  signal: 41,
  // the difference between the EMAs (to act as triggers)
  thresholds: {
    down: -9999,
    up: 0.00000001,
  }
};

// x2MACD settings:
config.x2MACD = {
  // EMA weight (α)
  // the higher the weight, the more smooth (and delayed) the line
  short: 53,
  long: 109,
  signal: 41,
  // the difference between the EMAs (to act as triggers)
  thresholds: {
    down: -9999,
    up: 0.00000001,
  }
};

// nikiehihsa settings:
config.nikiehihsa = {
  // EMA weight (α)
  // the higher the weight, the more smooth (and delayed) the line
  short: 53,
  long: 109,
  signal: 41,
  // the difference between the EMAs (to act as triggers)
  thresholds: {
    down: -9999,
    up: 0.00000001,
  }
};

// x3nikiehihsa settings:
config.x3nikiehihsa = {
  // EMA weight (α)
  // the higher the weight, the more smooth (and delayed) the line
  short: 53,
  long: 109,
  signal: 41,
  // the difference between the EMAs (to act as triggers)
  thresholds: {
    down: -9999,
    up: 0.00000001,
  }
};

// ZERO settings:
config.ZERO = {
  // EMA weight (α)
  // the higher the weight, the more smooth (and delayed) the line
  short: 43,
  long: 83,
  signal: 29,
  // the difference between the EMAs (to act as triggers)
  thresholds: {
    down: -9999,
    up: 0.00000001,
  }
};

// PPO settings:
config.PPO = {
  // EMA weight (α)
  // the higher the weight, the more smooth (and delayed) the line
  short: 12,
  long: 26,
  signal: 9,
  // the difference between the EMAs (to act as triggers)
  thresholds: {
    down: -9999,
    up: 0.00000001,
  }
};

// RSI settings:
config.RSI = {
  interval: 14,
  thresholds: {
    low: 30,
    high: 70,
    // How many candle intervals should a trend persist
    // before we consider it real?
    persistence: 1
  }
};

// custom settings:
config.custom = {
  my_custom_setting: 10,
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                       CONFIGURING PLUGINS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Want Gekko to perform real trades on buy or sell advice?
// Enabling this will activate trades for the market being
// watched by config.watch
config.trader = {
  enabled: true,
  key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  username: 'xxxxxxx', // your username, as required by cexio
}

config.adviceLogger = {
  enabled: true
}

// do you want Gekko to calculate the profit of its own advice?
config.profitSimulator = {
  enabled: false,
  // report the profit in the currency or the asset?
  reportInCurrency: true,
  // start balance, on what the current balance is compared with
  simulationBalance: {
    // these are in the unit types configured in the watcher.
    asset: 1,
    currency: 100,
  },
  // only want report after a sell? set to `false`.
  verbose: true,
  // how much fee in % does each trade cost?
  fee: 1,
  // how much slippage should Gekko assume per trade?
  slippage: 0.5
}

// want Gekko to send a mail on buy or sell advice?
config.mailer = {
  enabled: false,       // Send Emails if true, false to turn off
  sendMailOnStart: true,    // Send 'Gekko starting' message if true, not if false

  email: '',    // Your Gmail address

  // You don't have to set your password here, if you leave it blank we will ask it
  // when Gekko's starts.
  //
  // NOTE: Gekko is an open source project < https://github.com/kuzetsa/gekko >,
  // make sure you looked at the code or trust the maintainer of this bot when you
  // fill in your email and password.
  //
  // WARNING: If you have NOT downloaded Gekko from the github page above we CANNOT
  // guarantuee that your email address & password are safe!

  password: '',       // Your Gmail Password - if not supplied Gekko will prompt on startup.

  tag: '[GEKKO] ',      // Prefix all email subject lines with this

            //       ADVANCED MAIL SETTINGS
            // you can leave those as is if you 
            // just want to use Gmail

  server: 'smtp.gmail.com',   // The name of YOUR outbound (SMTP) mail server.
  smtpauth: true,     // Does SMTP server require authentication (true for Gmail)
          // The following 3 values default to the Email (above) if left blank
  user: '',       // Your Email server user name - usually your full Email address 'me@mydomain.com'
  from: '',       // 'me@mydomain.com'
  to: '',       // 'me@somedomain.com, me@someotherdomain.com'
  ssl: true,        // Use SSL (true for Gmail)
  port: '',       // Set if you don't want to use the default port
  tls: false        // Use TLS if true
}

config.ircbot = {
  enabled: false,
  emitUpdats: false,
  channel: '#your-channel',
  server: 'irc.freenode.net',
  botName: 'gekkobot'
}

config.campfire = {
  enabled: false,
  emitUpdates: false,
  nickname: 'Gordon',
  roomId: null,
  apiKey: '',
  account: ''
}

config.redisBeacon = {
  enabled: false,
  port: 6379, // redis default
  host: '127.0.0.1', // localhost
    // On default Gekko broadcasts
    // events in the channel with
    // the name of the event, set
    // an optional prefix to the
    // channel name.
  channelPrefix: '',
  broadcast: [
    'small candle'
  ]
}

// the web interface not currently supported, maintainer of the plugin quit
// (not in a working state)
// read: https://github.com/askmike/gekko/issues/156
config.webserver = {
  enabled: false,
  ws: {
    host: 'localhost',
    port: 1338,
  },
  http: {
    host: 'localhost',
    port: 1339,
  }
}

// not working, leave as is
config.backtest = {
  enabled: false
}

// set this to true if you understand that Gekko will 
// invest according to how you configured the indicators.
// None of the advice in the output is Gekko telling you
// to take a certain position. Instead it is the result 
// of running the indicators you configured automatically.
// 
// In other words: Gekko automates your trading strategies,
// it doesn't advice on itself, only set to true if you truly
// understand this.
// 
config['I understand that Gekko only automates MY OWN trading strategies'] = true;

module.exports = config;

edited by kuzetsa to fence code blocks around the paste (this is to prevent markdown formatting and make it more readable)

-- future reference, http://gist.github.com/ is my preference if you're pasting more than 5-10 lines..

JamieCressey commented 10 years ago

As requested; https://gist.github.com/jayc89/c0aeb33de938fcd39fdc

NPM was up to date as is the distro.

@Sirius1977 have you tested your API key elsewhere? When I tried running standard Gekko with my key(s) I got the same errors. Which leads me to believe it's either 1) a problem with Gekko running against CEX (unlikely) 2) a problem at CEX

kuzetsa commented 10 years ago

@jayc89 your (Ubuntu 14.04) distro's package manager is is lagging behind the //actual// current version on node.js (you reported v0.10.25 is the version you have) I'm not sure if that's causing problems or not...

@Sirius1977 I'm somewhat suspicious of this error you're having as well, also with node.js v0.10.25

I'll investigate this further with the older version of node.js, as both of your configs look correct.

If either of you is willing to test this out, see if you can figure out how to install the ACTUAL current / up-to-date node.js engine (v0.10.29) ... I have no idea how ubuntu or raspbian works, so I can't provide any guidance on this.

node.js v0.10.29 is the one I'm developing and testing with, and I believe it's likely expected by the various npm dependencies as well.


If I'm able to confirm that the error is because of the older versions of node.js I'll be pushing an update to require v0.10.29

(the various npm-installed dependencies are where this error originates, not in the code of gekko itself. If the dependencies require newer node.js version there's nothing I can do other than force gekko to report a cleaner, less cryptic "node is too old" error on older versions)

Midgardsomr commented 10 years ago

@jayc89 No, i didn't test it elsewhere.

@kuzetsa Thanks for your support. I will try to use 0.10.29 and report back if it's working or not.

kuzetsa commented 10 years ago

I was not able to reproduce this error on an older version of gekko.


Are you using the cex.io API key IP address whitelist feature?

I left mine blank (default policy for API keys means it can be used from any IP address)

Quoted for emphasis:

That error is caused by a problem with the API data returned by the exchange being "not good"

So far, the only people who have reported errors like this were trying to use an older key.

cex.io lets you make a second API key (or third, etc.)

Please make a new one, and when you do, take a note on which permissions you've enabled (or disabled) for the API key, and if you're able to reproduce this error with the fresh API key, let me know.


For now, I've marked this issue as:

... at this time I'm still convinced it's an issue with the API key.

Please generate a new API key, and be sure to enable all permissions and DO NOT put anything in the IP address whitelist / blacklist area.

Midgardsomr commented 10 years ago

I left the IP whitelist feature also blank.

Just a clue, i registered my account at cex.io today. Maybe they changed something for new accounts?

JamieCressey commented 10 years ago

Updated to 0.10.29 and I have the same error;

root@trader01:~/cex# /usr/local/node/bin/node -v
v0.10.29
root@trader01:~/cex# /usr/local/node/bin/node gekko
2014-07-03 18:58:46 (INFO): Gekko v0.1.2 started
2014-07-03 18:58:46 (INFO): I'm gonna make you rich, Bud Fox. 

2014-07-03 18:58:46 (INFO): Setting up Gekko in realtime mode

2014-07-03 18:58:46 (INFO): Setting up:
2014-07-03 18:58:46 (INFO):      Trading Advisor
2014-07-03 18:58:46 (INFO):      Calculate trading advice
2014-07-03 18:58:46 (INFO):      Using trading method: ZERO

2014-07-03 18:58:46 (INFO): Setting up:
2014-07-03 18:58:46 (INFO):      Trader
2014-07-03 18:58:46 (INFO):      Trader will follow the advice and create real orders.

/root/cex/exchanges/cexio.js:121
    currency = parseFloat(data.BTC.available)
                                  ^
TypeError: Cannot read property 'available' of undefined
    at calculate (/root/cex/exchanges/cexio.js:121:35)
    at bound (/root/cex/node_modules/lodash/dist/lodash.js:729:21)
    at IncomingMessage.<anonymous> (/root/cex/node_modules/cexio/cexio.js:65:9)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:929:16
    at process._tickCallback (node.js:419:13)
Midgardsomr commented 10 years ago

Same here: assets = parseFloat(data.GHS.available); ^ TypeError: Cannot read property 'available' of undefined at calculate (/home/markus/gekko/exchanges/cexio.js:125:33) at bound (/home/markus/gekko/node_modules/lodash/dist/lodash.js:729:21) at IncomingMessage. (/home/markus/gekko/node_modules/cexio/cexio.js:65:9) at IncomingMessage.emit (events.js:117:20) at _stream_readable.js:929:16 at process._tickCallback (node.js:419:13)

@kuzetsa On which system are you developing?

kuzetsa commented 10 years ago

@Sirius1977 Not just linux, gekko works for me on windows too, no patches of any kind required.

If not the API keys, I wonder if it's your distro since it works on both windows and linux for me
(and other people have it working as well)


As for linux the system I'm developing on, it's this:

screenshot

That's from running this script a couple weeks ago when I built a new kernel:

#!/bin/bash
# kuzetsa's timestamp generator
date +%A_%B_%d_%Y_%H%M%S
cat /proc/version
uptime

Also, here's some other details about the main system I run gekko on:

sys-apps/coreutils-8.21
sys-devel/gcc-4.8.3
sys-devel/autoconf-2.69
sys-devel/binutils-2.24
sys-devel/make-3.82
sys-devel/automake-1.13.4
sys-devel/libtool-2.4.2
sys-libs/glibc-2.17
dev-libs/glib-2.40.0
dev-libs/openssl-1.0.1h
dev-util/pkgconfig-0.28
net-libs/nodejs-0.10.29

Technically my glibc isn't current, but I have reasons for using 2.17 still instead of 2.19

Midgardsomr commented 10 years ago

Is there something we can do about this error? I'm not that comfortable with nodeJS, but there must be a way to see whats coming from the cex.io server that gekko can't handle.

EDIT: Works when automatic trading is disabled.

2014-07-04 22:02:51 (INFO):     Starting to watch the market: CEX.io GHS/BTC
2014-07-04 22:02:53 (INFO):     We don't have enough history yet to start giving advice, I'll need to gather more data first.
2014-07-04 22:02:53 (INFO):     I will start giving advice around 2014-07-05 22:02:00 (local time, that's in a day).
2014-07-04 22:02:53 (INFO):     processing 1001 trade(s)
2014-07-04 22:03:42 (INFO):     processing 13 trade(s)
2014-07-04 22:04:30 (INFO):     processing 12 trade(s)
2014-07-04 22:05:19 (INFO):     processing 9 trade(s)
2014-07-04 22:06:08 (INFO):     processing 10 trade(s)
kuzetsa commented 10 years ago

Is there something we can do about this error? I'm not that comfortable with nodeJS, but there must be a way to see whats coming from the cex.io server that gekko can't handle.

@Sirius1977: yes, there's a way to see what's going on IN GREAT DETAIL, AND IN REALTIME!!!

node.js can be used with an IDE and an interactive debugging tool like
enide studio available from the "node eclipse" website
(download link will probably be sourceforge)

... it's the way I personally debug things when there's ever weird, unexpected behavior from code in such a way I can't figure it out without using an interactive debugger.


For the record, I've had this error before too, but only ever when there was something wrong with my API key. I suggest contacting cex.io support and asking them if they can help you troubleshoot the problems with your API key.

Midgardsomr commented 10 years ago

I've tried to play around a little bit with enide. It looks like that the response from cex is empty. Is it possible to set breakpoints in the code window? I've tried set some but it doesn't work.

JamieCressey commented 10 years ago

I have a suspicion the problem is with CEX. Has anyone tried creating a new key and testing? None of my new keys appear to be active and their support is shocking!

Sent from my HTC

----- Reply message ----- From: "Sirius1977" notifications@github.com To: "kuzetsa/gekko" gekko@noreply.github.com Cc: "jayc89" jamie-cressey@live.co.uk Subject: [gekko] parseFloat(data.BTC.available) error on start-up. (#4) Date: Sat, Jul 5, 2014 11:32

I've tried to play around a little bit with enide. It looks like that the response from cex is empty. Is it possible to set breakpoints in the code window? I've tried set some but it doesn't work.


Reply to this email directly or view it on GitHub: https://github.com/kuzetsa/gekko/issues/4#issuecomment-48083217

Midgardsomr commented 10 years ago

Yep, to activate you need a workaround actually.

Paste your key and your 2FA key in this URL and you can activate it.

https://cex.io/trade/profile?activate_key=YOURAPIKEY&otp_code=YOURGOOGLEAUTHKEY

JamieCressey commented 10 years ago

I've seen the workaround, but I suspect it isn't actually working. Have you tested a newly created key elsewhere? I'm guessing it won't work, even though it's supposedly activated.

Sent from my HTC

----- Reply message ----- From: "Sirius1977" notifications@github.com To: "kuzetsa/gekko" gekko@noreply.github.com Cc: "jayc89" jamie-cressey@live.co.uk Subject: [gekko] parseFloat(data.BTC.available) error on start-up. (#4) Date: Sat, Jul 5, 2014 12:13

Yep, to activate you need a workaround actually.

Paste your key and your 2FA key in this URL and you can activate it.

https://cex.io/trade/profile?activate_key=YOURAPIKEY&otp_code=YOURGOOGLEAUTHKEY


Reply to this email directly or view it on GitHub: https://github.com/kuzetsa/gekko/issues/4#issuecomment-48083891

Midgardsomr commented 10 years ago

I think you're right. Tested with disabled 2FA and activate the API key. Confirmed the email confirmation and it won't work anyway. Seems that the key ist not active. CEX.IO problem it seems: https://support.cex.io/hc/communities/public/questions/201931408-How-can-I-Activate-API-Key-

kuzetsa commented 10 years ago

Yeah, I had to completely disable 2FA while activating my new API keys, and then only after I confirmed they were correctly working did I re-enable 2FA... Once the key is working though, reenabling 2FA won't break the already tested, working API keys.

kuzetsa commented 10 years ago

I've tried to play around a little bit with enide. It looks like that the response from cex is empty. Is it possible to set breakpoints in the code window? I've tried set some but it doesn't work.

@Sirius1977 Yes, breakpoints work... I'm not sure why they wouldn't work for you O_O

Just as a test, try setting a breakpoint really early into gekko's initialization like during the "bud fox" reference when gekko.js first starts up.


This video shows how breakpoints and debugging work in the "enide" flavor of eclipe IDE:

http://youtu.be/8ACnLALdKT8

Just ignore the step where it says to create a new project. So long as your entire gekko installation which you wish to debug (_including the npm packages / nodemodules directory) is already visible within the project it'll be fine.

.. That information in the video is still relevant even though that's a really old version of enide.

kuzetsa commented 10 years ago

I'm making a patch for this which I'm unable to test.

The patch will include an error handler to warn about the invalid API return
(undefined values / lack of data / etc.)

With this patch, gekko (hopefully) shouldn't crash anymore, but instead will just complain and continue operating... All this patch will do is to make gekko explain the problem more gracefully than "/stack dump and crash/"... It won't actually fix the issue.

I have no way of testing this personally, since I don't get back bad data from cex.io using known-working API keys.

kuzetsa commented 10 years ago

@Sirius1977, @jayc89:

As promised, error handler:

https://github.com/kuzetsa/gekko/commit/9dabd7d7d47e965e191fb71d12b9bbb0ef2ba370

^ see commentary on that patch (it's going to be useful for adding NMC support anyway)


Example of what output should look like when it's NOT having issues:

https://gist.github.com/kuzetsa/e881a91fb1d646e76647

Midgardsomr commented 10 years ago

@kuzetsa I've got the following output:

2014-07-06 20:29:14 (INFO):     Setting up:
2014-07-06 20:29:14 (INFO):              Trader
2014-07-06 20:29:14 (INFO):              Trader will follow the advice and create real orders.

/home/markus/gekko-2014.July.6.1343/exchanges/cexio.js:157
    if (typeof data.GHS.available == "undefined") {
                       ^
TypeError: Cannot read property 'available' of undefined
    at calculate (/home/markus/gekko-2014.July.6.1343/exchanges/cexio.js:157:24)
    at bound (/home/markus/gekko-2014.July.6.1343/node_modules/lodash/dist/lodash.js:729:21)
    at IncomingMessage.<anonymous> (/home/markus/gekko-2014.July.6.1343/node_modules/cexio/cexio.js:65:9)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:929:16
    at process._tickCallback (node.js:419:13)
kuzetsa commented 10 years ago

Did you enable "debug" in your config.js?

There should've been messages before the crash.

Midgardsomr commented 10 years ago

Sorry, my fault. Maybe cex.io didn't return a zero when no GHS's are availble? I only have Bitcoins in it at the moment. Here is the output with debug enabled:

2014-07-07 07:33:03 (DEBUG):    API data object returned from getPortfolio()
2014-07-07 07:33:03 (DEBUG):    data.BTC object returned from getPortfolio()
2014-07-07 07:33:03 (DEBUG):    data.GHS undefined state during getPortfolio()
2014-07-07 07:33:03 (DEBUG):    data.NMC undefined state during getPortfolio()

/home/markus/gekko-2014.July.6.1343/exchanges/cexio.js:157
    if (typeof data.GHS.available == "undefined") {
                       ^
TypeError: Cannot read property 'available' of undefined
    at calculate (/home/markus/gekko-2014.July.6.1343/exchanges/cexio.js:157:24)
    at bound (/home/markus/gekko-2014.July.6.1343/node_modules/lodash/dist/lodash.js:729:21)
    at IncomingMessage.<anonymous> (/home/markus/gekko-2014.July.6.1343/node_modules/cexio/cexio.js:65:9)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:929:16
    at process._tickCallback (node.js:419:13)
kuzetsa commented 10 years ago

Wow, that's really interesting -- According to your log, it really does look like the GHS (as well as namecoin) isn't being returned in the API call because there's nothing in your portfolio.

Try manually buying some GHS (even a very small amount if you don't like the price) to see if that fixes it for you.


Edited to add:

I'll be doing a total rewrite of the cex.io API wrapper soon, so I'll apparently need to add in special handler code for cases where a portfolio returns   "-   nothing at all, zero data of any kind   -"   for one of the currencies or assets (presumably it's to make it easier for them to save tiny amount of bandwidth on API calls or something instead of sending back a zero)

Midgardsomr commented 10 years ago

It seems to work. Undefined is gone for GHS.

2014-07-07 08:27:27 (DEBUG):    Getting balance & fee from cex.io

2014-07-07 08:27:28 (DEBUG):    API data object returned from getPortfolio()
2014-07-07 08:27:28 (DEBUG):    data.BTC object returned from getPortfolio()
2014-07-07 08:27:28 (DEBUG):    data.GHS object returned from getPortfolio()
2014-07-07 08:27:28 (DEBUG):    data.NMC undefined state during getPortfolio()

/home/markus/gekko-2014.July.6.1343/exchanges/cexio.js:161
    if (typeof data.NMC.available == "undefined") {
                       ^
TypeError: Cannot read property 'available' of undefined
    at calculate (/home/markus/gekko-2014.July.6.1343/exchanges/cexio.js:161:24)
    at bound (/home/markus/gekko-2014.July.6.1343/node_modules/lodash/dist/lodash.js:729:21)
    at IncomingMessage.<anonymous> (/home/markus/gekko-2014.July.6.1343/node_modules/cexio/cexio.js:65:9)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:929:16
    at process._tickCallback (node.js:419:13)

Normal gekko is working:

2014-07-07 08:29:37 (INFO):     Setting up:
2014-07-07 08:29:37 (INFO):              Trader
2014-07-07 08:29:37 (INFO):              Trader will follow the advice and create real orders.

2014-07-07 08:29:39 (INFO):     Trading at cex.io ACTIVE
2014-07-07 08:29:39 (INFO):     cex.io trading fee will be: 0.2%
2014-07-07 08:29:39 (INFO):     cex.io portfolio:
2014-07-07 08:29:39 (INFO):              BTC: 0.05763116
2014-07-07 08:29:39 (INFO):              GHS: 0.10000000
2014-07-07 08:29:40 (INFO):     Starting to watch the market: CEX.io GHS/BTC
2014-07-07 08:29:41 (INFO):     We don't have enough history yet to start giving advice, I'll need to gather more data first.
2014-07-07 08:29:41 (INFO):     I will start giving advice around 2014-07-08 08:29:00 (local time, that's in a day).
2014-07-07 08:29:42 (INFO):     processing 1001 trade(s)
kuzetsa commented 10 years ago

The debug code was probably just confused because it isn't getting any API response saying you have namecoin... that should no longer be an issue after you've mined ANY amount of namecoin with GHS (or bought a small amount)


I've updated the status of this issue to "bug" since we've managed to confirm that there really is a bug since the API wrapper --- it is making the naive assumption that the cex.io exchange will always return data even on an empty currency or asset which has a zero balance.

Midgardsomr commented 10 years ago

With the non debug version of gekko it works directly after i bought GHS. No need to buy NMC also.

kuzetsa commented 10 years ago

yes, the debug version crashes in a very predictable way. It was more of a diagnostic / debug patch than anything aimed at preventing crashes O_O

kuzetsa commented 10 years ago

/releases/tag/2014.July.16.1319 contains a new version of the error handler...
...theoretically handles errors more gracefully than just crashing in a less-unreadable way.

Either way, the code is much more readable now so it should be easier to debug
(about an hour of refactoring to make it pass jshint sanity checks without any warnings)

kuzetsa commented 10 years ago

Thanks for the report and helping test...

Unless further issues are reported, I'm planning to close this bug once the cex.io API wrapper has been fully audited, refactored, rewritten, and merged into the main branch.

  1. The cause for this bug is a naive assumption in the original API wrapper that the exchange would send back data 100% of the time even if a portfolio does not contain < currency or asset X >
  2. This updated version of the error handler from the "portfolio.debug" branch should help with troubleshooting further issues in the cex.io API wrapper...
  3. Eventually, the cex.io API wrapper refactor and rewrite will be done, and the whole thing will be merged. (portfolio.debug branch is stable already, and will be merged VERY SOON [tm],
    I just don't have time to finish work on auditing and testing until a few weeks,
    and tentatively I'll say you can probably expect it some time after August 1st
    )
kuzetsa commented 10 years ago

Maybe cex.io didn't return a zero when no GHS's are availble?

Thanks @Sirius1977, I'm certain that's what caused the issue. I poked around a bit more, and it's cex.io's fault with the way their API handles zero balances.

I've been using a debug version of gekko ever since this issue came up, and the issue only seemed to happen when the portfolio balance for a particular asset or currency balance was zero.

To actually fix this bug, where will need to be some sanity-checking code added into cex.io's API so that when the API response leaves stuff out or blank or whatever...

Hmm...

Actually I'll probably implement the change to the API code as a patch to the cex.io API itself, and send a pull request to https://github.com/pulsecat/cexio or something.

kuzetsa commented 10 years ago

Someone (me, or anyone really... I don't care & accept pull requests so long as the code isn't buggy) Should probably fix this bug and/or a patch to the upstream API like with pulsecat's cexio API now that cexio finally made the decision to release FIAT trading support (including on their APIs)