Skip to content

Instantly share code, notes, and snippets.

@guchimon99
Created December 1, 2017 03:53
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/5c5ee7d32d32d55f9e6879a21ae00da3 to your computer and use it in GitHub Desktop.
Save guchimon99/5c5ee7d32d32d55f9e6879a21ae00da3 to your computer and use it in GitHub Desktop.
利益計算用取引所別スクリプト zaif
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