Created
December 1, 2017 03:53
-
-
Save guchimon99/5c5ee7d32d32d55f9e6879a21ae00da3 to your computer and use it in GitHub Desktop.
利益計算用取引所別スクリプト zaif
This file contains hidden or 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 fs = require('fs') | |
const | |
PATH_CURRENCY = "path/to/trade_log.csv", | |
PATH_TOKEN = "path/to/token_trade_log.csv" | |
var currencyCsv = fs.readFileSync(PATH_CURRENCY, 'utf-8'), | |
tokenCsv = fs.readFileSync(PATH_TOKEN, 'utf-8') | |
var result = {} | |
function iterator(row, i) { | |
var cols = row.split(','), | |
pair = cols[0], | |
type = cols[1], | |
price = +cols[2] * cols[3], | |
amount = +cols[3] | |
if (!pair) return | |
result[pair] = result[pair] || { | |
buy_total: 0, | |
buy_amount: 0, | |
sell_total: 0, | |
sell_amount: 0, | |
} | |
if (type == "売り") { | |
result[pair].sell_total += price | |
result[pair].sell_amount += amount | |
} else { | |
result[pair].buy_total += price | |
result[pair].buy_amount += amount | |
} | |
} | |
currencyCsv.split('\n').slice(1).forEach(iterator) | |
tokenCsv.split('\n').slice(1).forEach(iterator) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment