Skip to content

Instantly share code, notes, and snippets.

@guchimon99
Created December 1, 2017 03:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guchimon99/fb7d1ff3f64d3ad7cdf5094f0d6c4295 to your computer and use it in GitHub Desktop.
Save guchimon99/fb7d1ff3f64d3ad7cdf5094f0d6c4295 to your computer and use it in GitHub Desktop.
利益計算用取引所別スクリプト coincheck
var fs = require('fs')
const
PATH_SELLS = __dirname + "/../files/coincehck/buys-2017-11-30.csv",
PATH_BUYS = __dirname + "/../files/coincehck/sells-2017-11-30.csv"
var sellsCsv = fs.readFileSync(PATH_SELLS, 'utf-8'),
buysCsv = fs.readFileSync(PATH_BUYS, 'utf-8')
var result = {}
var iterator = function(type, row) {
var cols = row.split(','),
pair = (cols[3] + "_" + cols[4]).toLowerCase(),
price = +cols[2],
amount = +cols[1]
if (!cols[3] || !cols[4]) return
result[pair] = result[pair] || {
buy_total: 0,
buy_amount: 0,
sell_total: 0,
sell_amount: 0
}
if (type == "sell") {
result[pair].sell_total += price
result[pair].sell_amount += amount
} else {
result[pair].buy_total += price
result[pair].buy_amount += amount
}
}
sellsCsv.split('\n').slice(1).forEach(iterator.bind(this, 'sell'))
buysCsv.split('\n').slice(1).forEach(iterator.bind(this, 'buy'))
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment