[POLONIEX] gekko imports with gaps
The market was pink date was 2017-04-04 with sqlite
(by @generalectric)
see https://github.com/askmike/gekko/issues/699#issuecomment-294898636
Importing from poloniex with sqlite results in multiple dateranges and missing candles.
2017-04-18 11:18:53 (INFO): Scanning local history for backtestable dateranges.2017-04-18 11:18:53 (DEBUG): Available 19129
2017-04-18 11:18:53 (DEBUG): Optimal 20356
2017-04-18 11:18:53 (INFO): The database has 1228 candles missing, Figuring out which ones...
2017-04-18 11:18:53 (INFO): Gekko detected multiple dateranges in the locally stored history. Please pick the daterange you are interested in testing:
2017-04-18 11:18:53 (INFO): OPTION 1:
2017-04-18 11:18:53 (INFO): from: 2017-04-04 00:22:00
2017-04-18 11:18:53 (INFO): to: 2017-04-16 08:22:00
2017-04-18 11:18:53 (INFO): OPTION 2:
2017-04-18 11:18:53 (INFO): from: 2017-04-16 09:22:00
2017-04-18 11:18:53 (INFO): to: 2017-04-16 10:22:00
2017-04-18 11:18:53 (INFO): OPTION 3:
2017-04-18 11:18:53 (INFO): from: 2017-04-16 11:22:00
2017-04-18 11:18:53 (INFO): to: 2017-04-16 12:22:00
2017-04-18 11:18:53 (INFO): OPTION 4:
2017-04-18 11:18:53 (INFO): from: 2017-04-16 13:22:00
2017-04-18 11:18:53 (INFO): to: 2017-04-16 14:22:00
2017-04-18 11:18:53 (INFO): OPTION 5:
2017-04-18 11:18:53 (INFO): from: 2017-04-16 18:22:00
2017-04-18 11:18:53 (INFO): to: 2017-04-16 19:22:00
2017-04-18 11:18:53 (INFO): OPTION 6:
2017-04-18 11:18:53 (INFO): from: 2017-04-16 20:22:00
2017-04-18 11:18:53 (INFO): to: 2017-04-16 21:22:00
prompt: option:
Gekko needs to have complete history of candles available: if there are gaps (missing data) of more than 3 minutes Gekko won't accept backtesting over that period. So this bug is clearly happening during importing.
@generalectric very strange. I just imported the last 3 months of BTC/PINK on my laptop and have no problems at all:
2017-04-18 18:01:04 (INFO): Scanning local history for backtestable dateranges.
2017-04-18 18:01:04 (DEBUG): Available 129378
2017-04-18 18:01:04 (DEBUG): Optimal 129377
2017-04-18 18:01:04 (INFO): Gekko is able to fully use the local history.
2017-04-18 18:01:04 (INFO): Gekko was able to find a single daterange in the locally stored history:
2017-04-18 18:01:04 (INFO): from: 2017-01-18 19:09:00
2017-04-18 18:01:04 (INFO): to: 2017-04-18 15:26:00
Can you let me know the following:
- Did you use gekko to import the data?
- What is the output of:
node gekko --version?
correct, fresh import using gekko with no history directory
Gekko version: v0.4.9 Nodejs version: v7.6.0
Very strange indeed, a few more questions:
- What version of raspberry pi do you have?
- Is IO scarce (are you also running a fullnode or so?)
- Where is gekko stored? (microSD, external HD)
- When you did the import, where you importing more [poloniex] markets at the same time?
just did a fresh import from command line and replicated same behavior this time with 1851 candles missing
Distributor ID: Raspbian Description: Raspbian GNU/Linux 8.0 (jessie) Release: 8.0 Codename: jessie
running on rpi3
this gekko install is in ~/gekko/pink
each gekko subfolder is for one specific asset
is IO scarce? fullnode? could you elaborate further?
this gekko install is in ~/gekko/pink
And that is on the microSD card plugged into your raspberry?
is IO scarce? fullnode? could you elaborate further?
Is the raspberry PI doing anything else (other applications)?
correct on sdcard. it runs about 9 gekkos though it does run a LAMP setup which i use to chart gekko debug output so that i can get talib indicators and buy sell points graphed (when using custom methods or strategies i believe they are now)
Interesting stuff! Were you running those gekkos at the time of import? And all of them on poloniex?
correct i have like 5 of them in watch only mode live trading turned off.... and i have a couple of them actively trading. there are no issues with just live market data... its when i do a import it creates missing candles
adm1n@rpi:~/gekko/pink $ pm2 l
┌────────────┬──────┬────────┬───┬─────┬───────────┐
│ Name │ mode │ status │ ↺ │ cpu │ memory │
├────────────┼──────┼────────┼───┼─────┼───────────┤
│ bela-trade │ fork │ online │ 0 │ 0% │ 39.5 MB │
│ dash-watch │ fork │ online │ 0 │ 0% │ 40.3 MB │
│ dcr-watch │ fork │ online │ 0 │ 0% │ 35.5 MB │
│ etc-watch │ fork │ online │ 0 │ 0% │ 42.7 MB │
│ eth-trade │ fork │ online │ 0 │ 0% │ 37.6 MB │
│ fct-watch │ fork │ online │ 0 │ 0% │ 38.7 MB │
│ rep-watch │ fork │ online │ 0 │ 0% │ 38.8 MB │
│ xmr-watch │ fork │ online │ 0 │ 0% │ 40.8 MB │
│ xrp-watch │ fork │ online │ 0 │ 0% │ 41.6 MB │
└────────────┴──────┴────────┴───┴─────┴───────────┘
Use `pm2 show <id|name>` to get more details about an app
I have a few ideas on how to fix this:
- sqlite doesn't like it when you use the same DB for a lot of processes, right now Gekko creates one DB per exchange (and stores different markets inside) - we could split this up as a DB per market.
- gekko doesn't batch insert on imports.
I'll work on those and hope that fixes it.
In the meantime a workaround would (hopefully be):
If you want to import + backtest over a market. Please set the dataDirectory in the config to something else (so gekko will create a new DB file just for that market). And try to import & backtest again.
Could you try this out and let me know if it works?
i realized sqlite doesnt play nice with multiple connections so i run them all with their own dbs using stock sqlite settings in config-sample.js every asset has its own db. which then meant i had to run like 10 different installs with different configs and methods.... so i made a script to manage them. honestly i think best solution is drop sqlite altogether and just goto postgresql especially now that it has the central db or one database for them all functionality in this last update
here is my command line script i use to manage them all. i keep it in /usr/local/bin and is used like so...
coin <asset> <command>
#!/usr/bin/php -q
<?php
$usrhome = '/home/adm1n/gekko/';
$coin = $argv[1];
$activated = 0;
if ($argv[2] && $argv[2] == 'trade') {
if (coinstatus($coin) === 'trade') {
echo $coin . ' is already actively trading!' . PHP_EOL;
} else {
if (coinstatus($coin) === 'watch') {
echo 'deactivating ' . $coin . ' watch process...' . PHP_EOL;
exec('pm2 stop ' . getpm2($coin,'name'));
echo 'deleting watch process...' . PHP_EOL;
exec('pm2 delete ' . getpm2($coin,'name'));
}
echo 'starting new ' . $coin . ' process in trade mode...' . PHP_EOL;
//print 'pm2 start ' . $usrhome . $coin . '/gekko.js --name ' . $coin . '-' . $argv[2] . ' -- -c trade.js';
exec('pm2 start ' . $usrhome . $coin . '/gekko.js --name ' . $coin . '-' . $argv[2] . ' -- -c ' . $usrhome . $coin . '/trade.js');
exec('pm2 save');
echo $coin . ' is now actively trading!' . PHP_EOL;
}
} elseif($argv[2] && $argv[2] == 'watch') {
if (coinstatus($coin) === 'watch') {
echo $coin . ' is already actively watching!' . PHP_EOL;
} else {
if (coinstatus($coin) === 'trade') {
echo 'deactivating ' . $coin . '...' . PHP_EOL;
exec('pm2 stop ' . getpm2($coin,'name'));
echo 'deleting trade process...' . PHP_EOL;
exec('pm2 delete ' . getpm2($coin,'name'));
}
echo 'starting new ' . $coin . ' process in watch mode...' . PHP_EOL;
exec('pm2 start ' . $usrhome . $coin . '/gekko.js --name ' . $coin . '-' . $argv[2] . ' -- -c ' . $usrhome . $coin . '/watch.js');
exec('pm2 save');
echo $coin . ' is now actively watching!' . PHP_EOL;
}
} elseif($argv[2] && $argv[2] == 'stop') {
if (coinstatus($coin)) {
echo 'terminating ' . $coin . '...' . PHP_EOL;
exec('pm2 stop ' . getpm2($coin,'name'));
exec('pm2 delete ' . getpm2($coin,'name'));
exec('pm2 save');
echo $coin . ' is now deactivated!' . PHP_EOL;
} else
echo 'no process currently running for ' . $coin . PHP_EOL;
} elseif($argv[2] && $argv[2] == 'restart') {
if (coinstatus($coin)) {
echo 'restarting ' . $coin . '-' . coinstatus($coin) . ' process...' . PHP_EOL;
exec('pm2 restart ' . getpm2($coin,'name'));
echo $coin . ' process restarted in ' . coinstatus($coin) . ' mode!' . PHP_EOL;
} else
echo 'no process currently running for ' . $coin . PHP_EOL;
} elseif($argv[2] && $argv[2] == 'update') {
file_put_contents($usrhome . $coin . '/trade.js', str_replace("{{tradebool}}",'true',file_get_contents($usrhome . $coin . '/config.js')));
file_put_contents($usrhome . $coin . '/watch.js', str_replace("{{tradebool}}",'false',file_get_contents($usrhome . $coin . '/config.js')));
echo $coin . ' config files updated!' . PHP_EOL;
} elseif($argv[2] && $argv[2] == 'config') {
system('nano ' . $usrhome . $coin . '/config.js > /dev/' . exec("ps ax | grep $$ | awk '{ print $2 }'"));
file_put_contents($usrhome . $coin . '/trade.js', str_replace('{{tradebool}}','true',file_get_contents($usrhome . $coin . '/config.js')));
file_put_contents($usrhome . $coin . '/watch.js', str_replace('{{tradebool}}','false',file_get_contents($usrhome . $coin . '/config.js')));
//file_put_contents($usrhome . $coin . '/trade.js', str_replace("{{coin}}",strtoupper($coin),file_get_contents($usrhome . $coin . '/config.js')));
//file_put_contents($usrhome . $coin . '/watch.js', str_replace("{{coin}}",strtoupper($coin),file_get_contents($usrhome . $coin . '/config.js')));
echo $coin . ' configuration updated!' . PHP_EOL;
} elseif($argv[2] && $argv[2] == 'test') {
//echo 'node ' . $usrhome . $coin . '/gekko.js -c ' . $usrhome . $coin . '/trade.js -b';
//passthru('node ' . $usrhome . $coin . '/gekko.js -c ' . $usrhome . $coin . '/trade.js -b');
passthru('node ' . $usrhome . $coin . '/gekko.js -c trade.js -b');
} elseif($argv[2] && $argv[2] == 'import') {
if (coinstatus($coin)) {
echo 'deactivating ' . $coin . '...' . PHP_EOL;
exec('pm2 stop ' . getpm2($coin,'name'));
echo 'deleting ' . coinstatus($coin) . ' process...' . PHP_EOL;
exec('pm2 delete ' . getpm2($coin,'name'));
}
if (array_diff(scandir($usrhome . $coin . '/history'), array('.', '..'))) { exec('rm ' . $usrhome . $coin . '/history/*'); }
//print 'node ' . $usrhome . $coin . '/gekko.js -c trade.js --import';
passthru('node ' . $usrhome . $coin . '/gekko.js -c ' . $usrhome . $coin . '/trade.js --import');
echo 'starting new ' . $coin . ' process in watch mode...' . PHP_EOL;
exec('pm2 start ' . $usrhome . $coin . '/gekko.js --name ' . $coin . '-watch -- -c watch.js');
exec('pm2 save');
echo $coin . ' is now actively watching!' . PHP_EOL;
} elseif($argv[2] && $argv[2] == 'method') {
$pt = exec("ps ax | grep $$ | awk '{ print $2 }'");
system('nano ' . $usrhome . $coin . '/strategies/custom.js > /dev/' . $pt);
echo $coin . ' method updated!' . PHP_EOL;
} elseif($argv[2] && $argv[2] == 'backup') {
exec('cp ' . $usrhome . $coin . '/config.js ' . $usrhome . 'backup/' . $coin . '/config.js');
exec('cp ' . $usrhome . $coin . '/strategies/custom.js ' . $usrhome . 'backup/' . $coin . '/custom.js');
echo $coin . ' config and method backed up!' . PHP_EOL;
} elseif($argv[2] && $argv[2] == 'restore') {
exec('cp ' . $usrhome . 'backup/' . $coin . '/config.js ' . $usrhome . $coin . '/config.js');
exec('cp ' . $usrhome . 'backup/' . $coin . '/custom.js ' . $usrhome . $coin . '/strategies/custom.js');
file_put_contents($usrhome . $coin . '/trade.js', str_replace("{{tradebool}}",'true',file_get_contents($usrhome . $coin . '/config.js')));
file_put_contents($usrhome . $coin . '/watch.js', str_replace("{{tradebool}}",'false',file_get_contents($usrhome . $coin . '/config.js')));
echo $coin . ' config and method restored!' . PHP_EOL;
} elseif($argv[2] && $argv[2] == 'status') {
getpm2($coin,'name');
$status = coinstatus($coin);
if($status)
print $coin . ' is activated and running in ' . $status . ' mode!' . PHP_EOL;
else
print $coin . ' is not currently activated.' . PHP_EOL;
} else
echo 'command: \'' . $argv[2] . '\' not valid' . PHP_EOL;
function getpm2($coin,$par) {
$coinproc = shell_exec('pm2 -m l');
if (preg_match('/\+\-\-\-.(?<name>' . $coin . '-.....)\npid.\:.(?<pid>[0-9]+)\npm2.id.\:.(?<id>[0-9]+)\nstatus.\:.(?<status>.*)\nmode.\:.(?<mode>.*)\nrestarted.\:.(?<restarts>[0-9]+)\nuptime.\:.(?<uptime>.*)\nmemory.usage.\:.(?<memusage>.*)\nerror.log.\:.(?<errorlog>.*)\nwatching.\:.(?<watching>.*)\nPID.file.\:.(?<pidfile>.*)/', $coinproc, $coinpm2))
return $coinpm2[$par];
else
return 0;
}
function coinstatus($coin) {
$name = getpm2($coin,'name');
if (preg_match('/' . $coin . '-(?<status>.....)/', $name, $activity))
return $activity['status'];
else
return 0;
}
?>
Woah you went to great lengths! It's great to see people doing all these things with Gekko :) Except for the fact that you had to do some many funky things just to get it working properly.
As for dynamically rewriting config files, this should work but soon there will be an easier way: The gekko UI is basically a webapp written around an API (highly unstable at the moment). You can use REST calls to interact with it (such as starting a gekko with a specific config). Let me know if you are interested in this.
honestly i think best solution is drop sqlite altogether and just goto postgresql especially now that it has the central db or one database for them all functionality in this last update
Have you tried this out? I need to do some more testing but if everything turns out to be stable I will definitely recommend using postgre for more advanced users (that run multiple gekkos constantly). The great thing about sqlite is that it extremely lightweight and easy to install. This way users don't have to install and setup their own databases.
yes pg is perfect.... except for my setup... the front end.... i have a webpage with a drop down box i select the asset which is a list of subdirectories in ~/gekko/*... or gekko installs.... it runs a backtest and all debug output goes to a variable then the variable is parsed and insterted to chart data using google charts to annotate the buys and sells and tooltip all the indicators for each candle. the problem is when i backtest with pg it never ends the process..... meaning gekko will just run indefinitely after the test is over it doesnt go back to command prompt... so the output is never graphed. running node gekko.js -c trade.js -b the backtest runs fine gives the overall stats but just sits until i hit control-c then exits to command prompt
and the end result........ im not much of a node guy. if i could i would make it work in the UI

oh and gekko works great. i really appreciate yours and everyone elses hard work its amazing.. and i didnt have to do anything to make it work properly. I dont currently use the UI though im very interested in it! rest calls? i did a search its pretty much... ajax right?
the problem is when i backtest with pg it never ends the process..... meaning gekko will just run indefinitely after the test is over it doesnt go back to command prompt...
Nice find, I just fixed this (in gekko develop branch for now).
and the end result........ im not much of a node guy. if i could i would make it work in the UI
Woow that looks great! I really love it that you are hacking/building on top of Gekko to get charts that you want. I know the charts in the UI are extremely basic right now (no indicators are plotted), I have opened an issue to discuss improvements for that here: #690.
oh and gekko works great. i really appreciate yours and everyone elses hard work its amazing.. and i didnt have to do anything to make it work properly.
Thanks a lot! You'd have to thank @RatkoR for fixing postgresql integration.
I dont currently use the UI though im very interested in it! rest calls? i did a search its pretty much... ajax right?
Yes ajax calls are the same (in browser context)! I can give you an example gist if you let me know what programming type you are most comfortable with (frontend, php, python, etc). I see you are using chrome: you can also open the UI, open the console and go to the network tab and start a backtest. You'd see something like this:

But note that what data you need to send and what data you get back is changing a lot at the moment, so don't spend to much time integrating.