Created
January 5, 2018 06:34
-
-
Save guchimon99/87661b75bdb4159a41f74eadd0369425 to your computer and use it in GitHub Desktop.
Zaifの取引履歴のCSVのダウンロード
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
const fs = require('fs'), | |
Zaif = require('zaif'), | |
moment = require('moment') | |
const output = './trade.csv' | |
const key = "****", | |
secret = "****" | |
const zaif = new Zaif(key, secret) | |
zaif.tradeHistory() | |
.then(function(res) { | |
var csv = "マーケット,取引種別,価格,数量,取引手数料,ボーナス円,日時,コメント\n" | |
var data = res.return | |
Object.keys(data).forEach(function(id) { | |
var d = data[id] | |
csv += [ | |
d['currency_pair'] || '', | |
d['your_action'] == 'bid' ? '買い' : '売り', | |
d['price'] || 0, | |
d['amount'] || 0, | |
d['fee_amount'] || 0, | |
d['bonus'] || '', | |
d['bouns_yen'] || '', | |
moment(new Date(d['timestamp']*1000)).format('YYYY-MM-DD hh:mm:ss.000'), | |
d['commont'] | |
].join(',') + "\n" | |
}) | |
fs.writeFileSync(output, csv) | |
}) | |
.catch(function(err) { | |
console.log(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment