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

Error after hours running on localDB branch #94

Closed
kingkorf opened this issue Dec 24, 2013 · 7 comments
Closed

Error after hours running on localDB branch #94

kingkorf opened this issue Dec 24, 2013 · 7 comments

Comments

@kingkorf
Copy link

Hi there,

I'm trying out your localDB branch and I get this error after about 3 hours running:

C:\Users\Me\Code\gekko [localDB +0 ~1 -0]> node gekko
2013-12-24 19:59:25 (INFO):     I'm gonna make you rich, Bud Fox.
2013-12-24 19:59:25 (INFO):     Let me show you some Exponential Moving Averages
.


2013-12-24 19:59:25 (INFO):     Using normal settings to monitor the live market

2013-12-24 19:59:25 (INFO):     NOT trading with real money
2013-12-24 19:59:26 (INFO):     Starting to watch the market: CEX.io BTC/GHS
NEW REAL CANDLE: 2013-12-24 18:57:00 O:0.06185449, H:0.0618545, L:0.06185449, C:
0.0618545
NEW REAL CANDLE: 2013-12-24 19:00:00 O:0.0618545, H:0.0618545, L:0.06109999, C:0
.06181467
NEW REAL CANDLE: 2013-12-24 19:03:00 O:0.06181466, H:0.06181466, L:0.06180319, C
:0.061814
NEW REAL CANDLE: 2013-12-24 19:06:00 O:0.06181399, H:0.06185143, L:0.06181398, C
:0.06185142
NEW REAL CANDLE: 2013-12-24 19:09:00 O:0.06184881, H:0.06185018, L:0.06182217, C
:0.06183
NEW REAL CANDLE: 2013-12-24 19:12:00 O:0.06183, H:0.0618499, L:0.06097, C:0.0618
215
NEW REAL CANDLE: 2013-12-24 19:15:00 O:0.0618215, H:0.0618215, L:0.0612, C:0.061
2
NEW REAL CANDLE: 2013-12-24 19:18:00 O:0.06181061, H:0.06181061, L:0.06123162, C
:0.0615
NEW REAL CANDLE: 2013-12-24 19:21:00 O:0.06149792, H:0.06149999, L:0.0614, C:0.0
614
NEW REAL CANDLE: 2013-12-24 19:24:00 O:0.0614, H:0.0614, L:0.06130026, C:0.06131
975
NEW REAL CANDLE: 2013-12-24 19:27:00 O:0.06131975, H:0.06137618, L:0.06120031, C
:0.06137554
NEW REAL CANDLE: 2013-12-24 19:30:00 O:0.06137554, H:0.06137555, L:0.0613504, C:
0.0613527
NEW REAL CANDLE: 2013-12-24 19:33:00 O:0.0613527, H:0.06135271, L:0.0613487, C:0
.06135268
NEW REAL CANDLE: 2013-12-24 19:36:00 O:0.06135267, H:0.06135267, L:0.06134809, C
:0.06135209
NEW REAL CANDLE: 2013-12-24 19:39:00 O:0.06134809, H:0.06135208, L:0.06134809, C
:0.06135207
NEW REAL CANDLE: 2013-12-24 19:43:00 O:0.06135111, H:0.06135207, L:0.06134809, C
:0.0613505
NEW REAL CANDLE: 2013-12-24 19:46:00 O:0.0613505, H:0.06135208, L:0.06134809, C:
0.0613486
NEW REAL CANDLE: 2013-12-24 19:49:00 O:0.06135049, H:0.0613527, L:0.0613481, C:0
.06135269
NEW REAL CANDLE: 2013-12-24 19:52:00 O:0.06135269, H:0.06139998, L:0.06135259, C
:0.06138893
NEW REAL CANDLE: 2013-12-24 19:55:00 O:0.06138893, H:0.06138893, L:0.061386, C:0
.061386
NEW REAL CANDLE: 2013-12-24 19:58:00 O:0.06138601, H:0.061396, L:0.06138601, C:0
.061396
NEW REAL CANDLE: 2013-12-24 20:01:00 O:0.0613885, H:0.06139529, L:0.06121, C:0.0
6138765
NEW REAL CANDLE: 2013-12-24 20:04:00 O:0.06139263, H:0.06145399, L:0.06138502, C
:0.06144978
NEW REAL CANDLE: 2013-12-24 20:07:00 O:0.06144978, H:0.06145101, L:0.06144978, C
:0.06144979
NEW REAL CANDLE: 2013-12-24 20:10:00 O:0.061451, H:0.06145398, L:0.0614498, C:0.
06145397
NEW REAL CANDLE: 2013-12-24 20:13:00 O:0.06144997, H:0.06159789, L:0.06144979, C
:0.06148662
NEW REAL CANDLE: 2013-12-24 20:16:00 O:0.06148661, H:0.06148661, L:0.06145398, C
:0.06147586
NEW REAL CANDLE: 2013-12-24 20:19:00 O:0.06147585, H:0.06148086, L:0.06147537, C
:0.06148086

C:\Users\Me\Code\gekko\exchanges\cexio.js:108
    function() { method.apply(self, args) },
                        ^
TypeError: Cannot call method 'apply' of undefined
    at null._onTimeout (C:\Users\Me\Code\gekko\exchanges\cexio.js:1
08:25)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

I don't know how this happend, but maybe you can make something out of it.

Cheers 👍

@askmike
Copy link
Owner

askmike commented Dec 24, 2013

I think I know why this happened, but can you turn on debug for now? And let me know when it happens again (with debug on)

@kingkorf
Copy link
Author

I just started running it in debug mode, will keep you posted!

@kuzetsa
Copy link
Contributor

kuzetsa commented Dec 25, 2013

@kingkorf This bug is NOT related to the "localDB branch"

I still get it on my own branch which doesn't have "localDB" support

c:\gekko\exchanges\cexio.js:157
    function() { method.apply(self, args) },
                        ^
TypeError: Cannot call method 'apply' of undefined
    at null._onTimeout (c:\gekko\exchanges\cexio.js:157:25)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

@askmike Based on the looks of it, I think this one is yet another bug related to an improperly set up (node.js conventions) error handler / the issue seems to have a similar surface area to the issue you fixed the other day with the upstream cex.io APIs gekko was relying on.

Edited to add:

Trader.prototype.retry = function(method, args) {
  var wait = +moment.duration(10, 'seconds');
  log.debug(this.name, 'returned an error, retrying..');

  var self = this;

  // make sure the callback (and any other fn)
  // is bound to Trader
  _.each(args, function(arg, i) {
    if(_.isFunction(arg))
      args[i] = _.bind(arg, self);
  });

  // run the failed method again with the same
  // arguments after wait
  setTimeout(
    function() { method.apply(self, args) },
    wait
  );
}

^ I didn't change that routine in my own branch, but line numbers might be different so I just wanted to put that out there, and ask for clarity:

Does gekko just assume that all exchange API object prototypes will have an "apply" method?

I don't have time today (about to go out of town since here in the local timezone in NY it's xmas and I have plans tonight)

@kingkorf
Copy link
Author

The previous log was on Windows 7 platform with latest node.

I just ran into another crash (same message I think), and noticed that cex.io gave me a 521 (Cloudflare). Check it out right now... This one is one Arch Linux platform with everything up-to-date.

➜  gekko git:(localDB) ✗ node gekko
2013-12-25 16:14:16 (INFO): I'm gonna make you rich, Bud Fox.
2013-12-25 16:14:16 (INFO): Let me show you some Exponential Moving Averages.


2013-12-25 16:14:16 (INFO): Using normal settings to monitor the live market
2013-12-25 16:14:16 (INFO): NOT trading with real money
2013-12-25 16:14:16 (INFO): Starting to watch the market: CEX.io BTC/GHS
2013-12-25 16:14:17 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:14:17 (DEBUG):    Fetched 1001 new trades, from 15:00:41 (UTC) to 15:14:16 (UTC)
2013-12-25 16:14:17 (DEBUG):    inserting candle 911 (15:11:00 UTC)
2013-12-25 16:14:17 (DEBUG):    inserting candle 912 (15:12:00 UTC)
2013-12-25 16:14:17 (DEBUG):    inserting candle 913 (15:13:00 UTC)
2013-12-25 16:14:17 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:11:00 O:0.046, H:0.04601301, L:0.04590001, C:0.04593399
2013-12-25 16:14:17 (DEBUG):    Leftovers: 914
2013-12-25 16:17:17 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:17:17 (DEBUG):    Fetched 1001 new trades, from 15:05:15 (UTC) to 15:17:35 (UTC)
2013-12-25 16:17:18 (DEBUG):    inserting candle 914 (15:14:00 UTC)
2013-12-25 16:17:18 (DEBUG):    inserting candle 915 (15:15:00 UTC)
2013-12-25 16:17:18 (DEBUG):    inserting candle 916 (15:16:00 UTC)
2013-12-25 16:17:18 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:14:00 O:0.0459258, H:0.047, L:0.04592301, C:0.04609997
2013-12-25 16:17:18 (DEBUG):    Leftovers: 917
2013-12-25 16:20:18 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:20:18 (DEBUG):    Fetched 1001 new trades, from 15:08:36 (UTC) to 15:20:53 (UTC)
2013-12-25 16:20:18 (DEBUG):    inserting candle 917 (15:17:00 UTC)
2013-12-25 16:20:18 (DEBUG):    inserting candle 918 (15:18:00 UTC)
2013-12-25 16:20:18 (DEBUG):    inserting candle 919 (15:19:00 UTC)
2013-12-25 16:20:18 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:17:00 O:0.04609985, H:0.04698, L:0.046001, C:0.0462
2013-12-25 16:20:18 (DEBUG):    Leftovers: 920
2013-12-25 16:23:18 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:23:18 (DEBUG):    Fetched 1001 new trades, from 15:13:54 (UTC) to 15:24:09 (UTC)
2013-12-25 16:23:18 (DEBUG):    inserting candle 920 (15:20:00 UTC)
2013-12-25 16:23:18 (DEBUG):    inserting candle 921 (15:21:00 UTC)
2013-12-25 16:23:18 (DEBUG):    inserting candle 922 (15:22:00 UTC)
2013-12-25 16:23:18 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:20:00 O:0.04620313, H:0.04697998, L:0.04601001, C:0.0463
2013-12-25 16:23:18 (DEBUG):    inserting candle 923 (15:23:00 UTC)
2013-12-25 16:23:18 (DEBUG):    Leftovers: 924
2013-12-25 16:26:19 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:26:19 (DEBUG):    Fetched 1001 new trades, from 15:16:56 (UTC) to 15:27:26 (UTC)
2013-12-25 16:26:19 (DEBUG):    inserting candle 924 (15:24:00 UTC)
2013-12-25 16:26:19 (DEBUG):    inserting candle 925 (15:25:00 UTC)
2013-12-25 16:26:19 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:23:00 O:0.0463, H:0.04999999, L:0.0463, C:0.04949988
2013-12-25 16:26:19 (DEBUG):    inserting candle 926 (15:26:00 UTC)
2013-12-25 16:26:19 (DEBUG):    Leftovers: 927
2013-12-25 16:29:19 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:29:19 (DEBUG):    Fetched 1001 new trades, from 15:21:21 (UTC) to 15:30:43 (UTC)
2013-12-25 16:29:19 (DEBUG):    inserting candle 927 (15:27:00 UTC)
2013-12-25 16:29:19 (DEBUG):    inserting candle 928 (15:28:00 UTC)
2013-12-25 16:29:19 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:26:00 O:0.0494, H:0.04949999, L:0.04900001, C:0.04939341
2013-12-25 16:29:19 (DEBUG):    inserting candle 929 (15:29:00 UTC)
2013-12-25 16:29:19 (DEBUG):    Leftovers: 930
2013-12-25 16:32:20 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:32:20 (DEBUG):    Fetched 1001 new trades, from 15:23:06 (UTC) to 15:33:31 (UTC)
2013-12-25 16:32:20 (DEBUG):    inserting candle 930 (15:30:00 UTC)
2013-12-25 16:32:20 (DEBUG):    inserting candle 931 (15:31:00 UTC)
2013-12-25 16:32:20 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:29:00 O:0.04939341, H:0.04959537, L:0.04901004, C:0.04959523
2013-12-25 16:32:20 (DEBUG):    inserting candle 932 (15:32:00 UTC)
2013-12-25 16:32:20 (DEBUG):    Leftovers: 933
2013-12-25 16:35:20 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:35:20 (DEBUG):    Fetched 1001 new trades, from 15:25:50 (UTC) to 15:36:16 (UTC)
2013-12-25 16:35:20 (DEBUG):    inserting candle 933 (15:33:00 UTC)
2013-12-25 16:35:20 (DEBUG):    inserting candle 934 (15:34:00 UTC)
2013-12-25 16:35:20 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:32:00 O:0.04959521, H:0.0499, L:0.04927154, C:0.0499
2013-12-25 16:35:20 (DEBUG):    inserting candle 935 (15:35:00 UTC)
2013-12-25 16:35:20 (DEBUG):    Leftovers: 936
2013-12-25 16:38:21 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:38:21 (DEBUG):    Fetched 1001 new trades, from 15:27:02 (UTC) to 15:39:04 (UTC)
2013-12-25 16:38:21 (DEBUG):    inserting candle 936 (15:36:00 UTC)
2013-12-25 16:38:21 (DEBUG):    inserting candle 937 (15:37:00 UTC)
2013-12-25 16:38:21 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:35:00 O:0.0499, H:0.0499, L:0.0493, C:0.04956267
2013-12-25 16:38:21 (DEBUG):    inserting candle 938 (15:38:00 UTC)
2013-12-25 16:38:21 (DEBUG):    Leftovers: 939
2013-12-25 16:41:21 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:41:21 (DEBUG):    Fetched 1001 new trades, from 15:29:11 (UTC) to 15:41:46 (UTC)
2013-12-25 16:41:21 (DEBUG):    inserting candle 939 (15:39:00 UTC)
2013-12-25 16:41:21 (DEBUG):    inserting candle 940 (15:40:00 UTC)
2013-12-25 16:41:21 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:38:00 O:0.04956266, H:0.04956266, L:0.049, C:0.04937785
2013-12-25 16:41:21 (DEBUG):    Leftovers: 941
2013-12-25 16:44:23 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:44:23 (DEBUG):    Fetched 1001 new trades, from 15:30:43 (UTC) to 15:44:38 (UTC)
2013-12-25 16:44:23 (DEBUG):    inserting candle 941 (15:41:00 UTC)
2013-12-25 16:44:23 (DEBUG):    inserting candle 942 (15:42:00 UTC)
2013-12-25 16:44:23 (DEBUG):    inserting candle 943 (15:43:00 UTC)
2013-12-25 16:44:23 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:41:00 O:0.04938893, H:0.04939993, L:0.04925457, C:0.04936289
2013-12-25 16:44:23 (DEBUG):    Leftovers: 944
2013-12-25 16:47:23 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:47:23 (DEBUG):    Fetched 1001 new trades, from 15:32:34 (UTC) to 15:47:23 (UTC)
2013-12-25 16:47:23 (DEBUG):    inserting candle 944 (15:44:00 UTC)
2013-12-25 16:47:23 (DEBUG):    inserting candle 945 (15:45:00 UTC)
2013-12-25 16:47:23 (DEBUG):    inserting candle 946 (15:46:00 UTC)
2013-12-25 16:47:23 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:44:00 O:0.0493629, H:0.0494235, L:0.04936289, C:0.0494225
2013-12-25 16:47:23 (DEBUG):    Leftovers: 947
2013-12-25 16:50:24 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:50:24 (DEBUG):    Fetched 1001 new trades, from 15:34:32 (UTC) to 15:50:23 (UTC)
2013-12-25 16:50:24 (DEBUG):    inserting candle 947 (15:47:00 UTC)
2013-12-25 16:50:24 (DEBUG):    inserting candle 948 (15:48:00 UTC)
2013-12-25 16:50:24 (DEBUG):    inserting candle 949 (15:49:00 UTC)
2013-12-25 16:50:24 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:47:00 O:0.04942043, H:0.051999, L:0.04942043, C:0.05020003
2013-12-25 16:50:24 (DEBUG):    Leftovers: 950
2013-12-25 16:53:24 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:53:24 (DEBUG):    Fetched 1001 new trades, from 15:40:49 (UTC) to 15:53:24 (UTC)
2013-12-25 16:53:24 (DEBUG):    inserting candle 950 (15:50:00 UTC)
2013-12-25 16:53:24 (DEBUG):    inserting candle 951 (15:51:00 UTC)
2013-12-25 16:53:24 (DEBUG):    inserting candle 952 (15:52:00 UTC)
2013-12-25 16:53:24 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:50:00 O:0.05029002, H:0.05234969, L:0.049, C:0.05000999
2013-12-25 16:53:24 (DEBUG):    Leftovers: 953
2013-12-25 16:56:25 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:56:25 (DEBUG):    Fetched 1001 new trades, from 15:46:07 (UTC) to 15:56:25 (UTC)
2013-12-25 16:56:25 (DEBUG):    inserting candle 953 (15:53:00 UTC)
2013-12-25 16:56:25 (DEBUG):    inserting candle 954 (15:54:00 UTC)
2013-12-25 16:56:25 (DEBUG):    inserting candle 955 (15:55:00 UTC)
2013-12-25 16:56:25 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:53:00 O:0.05000997, H:0.0515, L:0.05000754, C:0.051393
2013-12-25 16:56:25 (DEBUG):    Leftovers: 956
2013-12-25 16:59:25 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 16:59:25 (DEBUG):    Fetched 1001 new trades, from 15:49:31 (UTC) to 15:59:24 (UTC)
2013-12-25 16:59:25 (DEBUG):    inserting candle 956 (15:56:00 UTC)
2013-12-25 16:59:25 (DEBUG):    inserting candle 957 (15:57:00 UTC)
2013-12-25 16:59:25 (DEBUG):    inserting candle 958 (15:58:00 UTC)
2013-12-25 16:59:25 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:56:00 O:0.05185005, H:0.052, L:0.051001, C:0.05167904
2013-12-25 16:59:25 (DEBUG):    Leftovers: 959
2013-12-25 17:02:26 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 17:02:26 (DEBUG):    Fetched 1001 new trades, from 15:51:03 (UTC) to 16:02:25 (UTC)
2013-12-25 17:02:26 (DEBUG):    inserting candle 959 (15:59:00 UTC)
2013-12-25 17:02:26 (DEBUG):    inserting candle 960 (16:00:00 UTC)
2013-12-25 17:02:26 (DEBUG):    inserting candle 961 (16:01:00 UTC)
2013-12-25 17:02:26 (DEBUG):    NEW REAL CANDLE: 2013-12-25 15:59:00 O:0.05168984, H:0.051699, L:0.051, C:0.05137999
2013-12-25 17:02:26 (DEBUG):    Leftovers: 962
2013-12-25 17:05:26 (DEBUG):    Scheduling next fetch: in 3 minutes
2013-12-25 17:05:26 (DEBUG):    Fetched 1001 new trades, from 15:51:14 (UTC) to 16:05:25 (UTC)
2013-12-25 17:05:26 (DEBUG):    inserting candle 962 (16:02:00 UTC)
2013-12-25 17:05:26 (DEBUG):    inserting candle 963 (16:03:00 UTC)
2013-12-25 17:05:26 (DEBUG):    inserting candle 964 (16:04:00 UTC)
2013-12-25 17:05:26 (DEBUG):    NEW REAL CANDLE: 2013-12-25 16:02:00 O:0.05136995, H:0.05136995, L:0.05099179, C:0.05099179
2013-12-25 17:05:26 (DEBUG):    Leftovers: 965
2013-12-25 17:08:27 (DEBUG):    cex.io returned an error, retrying..

/home/me/Dev/gekko/exchanges/cexio.js:108
    function() { method.apply(self, args) },
                        ^
TypeError: Cannot call method 'apply' of undefined
    at null._onTimeout (/home/me/Dev/gekko/exchanges/cexio.js:108:25)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

Hope this helps.

@kuzetsa
Copy link
Contributor

kuzetsa commented Dec 25, 2013

Oh crap, I think I just spotted the issue. I think the function needs a bind.

I had a similar bug when I was first writing the code for #67 ...

... and because I was being VERY lazy I basically just reused some nearby code which already used a bind (can't remember if the async code I borrowed for no good reason other than being lazy and wanting something quick like... I think it was either from the underscore or lodash library, but I could've done the bind natively in node.js if I wasn't being so lazy)

https://github.com/kuzetsa/gekko/blob/72ab99fabf2df42a4cc2c711ec2bd96f3902338a/portfolioManager.js

Code in question:

  // callback function to REFRESH portfolio stats
  var displayPortfolio = function() {
          // lazy way to do it without a major rewrite
          async.series([
                        this.setPortfolio
                        ], _.bind(refreshPortfolioBeforeYouCanDisplay, this));
  };

As you can see, REALLY lazy. I vaguely remember you had to refactor that because it looked ugly (which I'm not gonna deny AT ALL)

Mostly I'm just posting this as a hint in case anyone wants to take a stab at fixing the issue (I'm not certain, and only SUSPECT it's actually related to setting up a callback without a bind, and it could be entirely unrelated)

Edited to add:

Not only am I often lazy, I'm procrastinating need to get ready / gonna be late for the holidays if I don't stop typing on this gekko issue and...

... (AFK, possibly for a day or two)

askmike added a commit that referenced this issue Dec 25, 2013
@askmike
Copy link
Owner

askmike commented Dec 25, 2013

I was assuming this bug was called by a stackoverflow (which happened after X amount of retries), which it did not. The error came from a refactor, after which I referenced to self a object non existant anymore. It should be fixed now.

@kuzetsa apply is a method that every function has. The error came from the fact that I was not passing a function (because I removed the self = this, so it wasn't passing a method but an undefined which doesn't have an apply method).

@askmike askmike closed this as completed Dec 25, 2013
@kingkorf
Copy link
Author

Thanks for the quick fix! 👍 How is trading for CEX.io comming along?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants