Last active
January 2, 2016 02:28
-
-
Save codedot/8236958 to your computer and use it in GitHub Desktop.
Hedging analyst for Bitstamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 i\ | |
[ | |
/}/ s/}/},/ | |
/ ...: '/ { | |
s/ \(...\): '\(.*\)'/ "\1": "\2"/ | |
p | |
} | |
$ i\ | |
{} ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOGFILE = $$HOME/.bitstamp.log | |
all: | |
-while date; do \ | |
$(MAKE) trace; \ | |
sleep 60; \ | |
done | |
trace: | |
sed -n -f log2json.sed $(LOGFILE) >spyhedge.json | |
node prohedge | |
clean: | |
-rm -f spyhedge.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var read = require("fs").readFileSync; | |
var log = read("spyhedge.json", "utf8"); | |
var trace = JSON.parse(log); | |
var fee; | |
function separate(trace) | |
{ | |
var dict = {}; | |
var i; | |
for (i in trace) { | |
var state = trace[i]; | |
var fee = state.fee; | |
if (!fee) | |
break; | |
if (!dict[fee]) | |
dict[fee] = []; | |
dict[fee].push({ | |
fiat: state.usd, | |
coin: state.btc, | |
last: state.cur | |
}); | |
} | |
return dict; | |
} | |
function filter(trace) | |
{ | |
var list = []; | |
var i; | |
for (i in trace) { | |
var state = trace[i]; | |
var prev; | |
if (prev != state.last) | |
list.push(state); | |
prev = state.last; | |
} | |
return list; | |
} | |
trace = separate(trace); | |
for (fee in trace) { | |
var path = filter(trace[fee]); | |
var work = path.length - 1; | |
var orig, last, origf, lastf, earn, size; | |
if (!work) | |
continue; | |
size = Math.ceil(100 / fee) / 100 - 0.01; | |
orig = path[0]; | |
origf = { | |
fiat: parseFloat(orig.fiat), | |
coin: parseFloat(orig.coin), | |
last: parseFloat(orig.last) | |
}; | |
origf.cash = origf.fiat + origf.coin * origf.last; | |
last = path[work]; | |
lastf = { | |
fiat: parseFloat(last.fiat), | |
coin: parseFloat(last.coin), | |
last: parseFloat(last.last) | |
}; | |
lastf.cash = lastf.fiat + lastf.coin * origf.last; | |
earn = 100 * lastf.cash / origf.cash - 100; | |
console.log({ | |
path: { | |
size: size.toFixed(2), | |
earn: earn.toFixed(2), | |
work: work.toFixed(0) | |
}, | |
orig: orig, | |
last: last | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment