git ssb

0+

cel / ledger-scripts



Tree: f1521af2d73e96acaa4e96dfc60dbfc50373845a

Files: f1521af2d73e96acaa4e96dfc60dbfc50373845a / coinbase2ledger-transfers

1240 bytesRaw
1#!/usr/bin/awk -f
2#
3# coinbase2ledger-transfers
4# Render Coinbase Transfers CSV into a ledger journal
5
6BEGIN {
7 FS=",";
8 assets_account="Assets:Bitcoin:Coinbase";
9 fee_account="Expenses:Broker:Coinbase";
10}
11
12function format_money(amount) {
13 if(currency == "USD")
14 return "$" amount;
15 else
16 return amount " " currency;
17}
18
19/^[0-9]/ {
20 timestamp = $1;
21 type = $2;
22 btc = $3;
23 subtotal = $4;
24 fees = $5;
25 total = $6;
26 currency = $7;
27 price_per_coin = $8;
28 payment_method = $9;
29 id = $10;
30
31 i = index(timestamp, " ")-1;
32 date = substr(timestamp, 1, i);
33 gsub("-", "/", date);
34
35 if (match(payment_method, /^.* [*-]/)) {
36 bank = substr(payment_method, 1, RLENGTH - 2);
37 account = "Assets:Bank:" bank;
38 } else {
39 account = "Assets";
40 }
41
42 if (type == "Buy") {
43 total *= -1;
44 } else {
45 btc *= -1;
46 }
47
48 description = type " BTC";
49
50 printf "%s %s\n", date, description;
51 printf " %-32s %16s\n", account, format_money(total);
52 if (fees) printf " %-32s %16s\n", fee_account, format_money(fees);
53 printf " %-32s %12s BTC @ %s\n", assets_account, btc,
54 format_money(price_per_coin);
55 print "";
56}
57

Built with git-ssb-web