-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
60 lines (53 loc) · 1.61 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require('dotenv').config()
const axios = require('axios')
const { exit } = require('process')
const sign = require('./sign')
const secret = process.env.API_SECRET
const apiKey = process.env.API_KEY
const apiPassphrase = process.env.API_PASSPHRASE
const requestPath = '/transfers'
var timestamp = Date.now() / 1000
const UNKNOW_PAYMENT_TYPE = 'N/A'
async function main() {
let resp
try {
resp = await axios.get('https://api.pro.coinbase.com' + requestPath, {
params: {
// type: 'deposit',
},
headers: {
'CB-ACCESS-KEY': apiKey,
'CB-ACCESS-PASSPHRASE': apiPassphrase,
'CB-ACCESS-TIMESTAMP': timestamp,
'CB-ACCESS-SIGN': sign({
timestamp,
requestPath,
secret,
method: 'GET',
}),
},
})
} catch (err) {
console.log(err.toJSON())
exit(1)
}
const deposits = resp.data
const details = deposits.map((d) => {
return {
type: d.type,
createdAt: d.created_at,
amount: d.amount,
paymentMethodType: d.details.coinbase_payment_method_type || UNKNOW_PAYMENT_TYPE,
// details: d.details
}
})
const bankDetails = details.filter((d) => d.paymentMethodType !== UNKNOW_PAYMENT_TYPE && d.type === 'deposit')
const totalBankDeposits = bankDetails.reduce((acc, cur) => {
return acc + parseInt(cur.amount)
}, 0)
// const coinDetails = details.filter(d => d.paymentMethodType === UNKNOW_PAYMENT_TYPE)
console.log(JSON.stringify(bankDetails.reverse(), null, 2))
console.log(`Transactions #${deposits.length}`)
console.log(`Bank Deposits: $${totalBankDeposits}`)
}
main()