Skip to content

Instantly share code, notes, and snippets.

View askmike's full-sized avatar

Mike van Rossum askmike

View GitHub Profile
@askmike
askmike / candleCalculator.js
Created June 21, 2013 12:18
Calculate trade candles for the MtGox exchange from a [sqlite trade database](https://bitcointalk.org/index.php?topic=221055.0).
var mtgoxDump = './dump.sql'; // this is the database file outputted by the Trade Downloader ( https://bitcointalk.org/index.php?topic=221055.0 )
var output = './candles-' + (+new Date()) + '.csv'; // csv file with your candles
var db = require('sqlite-wrapper')(mtgoxDump);
var moment = require('moment');
var _ = require('underscore');
var fs = require('fs');
var i = 0;
# you need to have node and npm installed
cd ~ # navigate to homedir
mkdir test # create a new test directory
cd test # go in the new directory
mkdir node_modules # make sure bitstamp will get installed locally
npm install bitstamp # download bitstamp module
cd node_modules/bitstamp # go to the files of the module
node example.js # run the example file through node.js
@askmike
askmike / gist:8181496
Created December 30, 2013 12:21
daily candles storage test
// var moment = require('moment');
var nedb = require('nedb');
// var async = require('async');
var db = new nedb({filename: 'test6.db', autoload: true});
var _ = require('lodash');
var candles = [];
_.each(_.range(1440), function(d) {
var candle = {
@askmike
askmike / gist:8183593
Last active January 1, 2016 18:29
Weird memory behaviour
var _ = require('lodash');
var candles = [];
var c = function() {
console.log('create candle');
_.each(_.range(100000), function(d) {
var candle = {
s: d,
o: Math.random() * 1000,
@askmike
askmike / gist:8191017
Created December 31, 2013 01:32
Possible neDB replacement for Gekko's localDB solution
//
// Low level datastore to persist 1m candles
// generated by the CandleManager to disk.
//
var zlib = require('zlib');
var fs = require('fs');
var lodash = require('lodash');
var async = require('async');
var _ = require('lodash');
@askmike
askmike / gist:8207874
Created January 1, 2014 12:58
also pipe stdout to file example
var fs = require('fs');
// log to stdout (console) fn
var stdout = process.stdout.write;
// log to file fn
var fileLog = fs.createWriteStream('log.txt', {'flags': 'a'});
// overwrite the original to log to both
process.stdout.write = function(d) {
fileLog.write(d);
@askmike
askmike / gist:8208456
Last active January 1, 2016 22:09
interface a candleStore needs for storing candles.
**openDay**(day String)
Should open a day from disk or create a new one if nonexistant. Can be async. Will overwrite the previous open day.
Note: if we are adding candles and they are not written yet, wait for this to finish first.
**addCandles**(candles Array)
Should add candles to the currently open day and write to disk. If we are opening a day store them temp in a queue and process once the openDay is loaded.
**loadDay**(day String, cb)
var fs = require('fs');
var _ = require('lodash');
var db = '[' + fs.readFileSync('file.db', 'utf8') + ']';
db = _.map(db.split('\n'), function(line) {
return line + ',';
}).join('\n');
console.log(db)
@askmike
askmike / app.js
Created January 7, 2014 22:07
event emitter example
var Trader = require('./trader');
var t = new Trader;
t.on('trading', console.log);
setInterval(t.trade, 1000);
var ws;
var handle = function(e) {
console.log(JSON.parse(e.data));
}
var reconnect = function() {
setTimeout(connect, 5000);
}