gtmtech-crypto 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gtmtech-crypto.gemspec +1 -1
- data/lib/gtmtech/crypto.rb +1 -1
- data/lib/gtmtech/crypto/data.rb +36 -10
- data/lib/gtmtech/crypto/subcommands/reconcile.rb +13 -4
- data/lib/gtmtech/crypto/utils.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f46c9c9aef20bd2c10db09c32bd54babe62b648a
|
4
|
+
data.tar.gz: f4c2dfa08b79ad6c8344af05088479745c85e835
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c92f1bf92055336e8ba92ddd0f78373eff333a41a50146998eac08f9dd4da4176abe56be65456a645458217b59f935012b08e57abfbd9cde7f19058292495953
|
7
|
+
data.tar.gz: 689cc7b71547047088ff6960c192a7a15daac222b112253d7ef6a7293a4f532dc5d12016918ea4ae0fcd052a3fc03c908e831b8b0239214bcb5cf45050391582
|
data/gtmtech-crypto.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "gtmtech-crypto"
|
7
|
-
gem.version = "0.0
|
7
|
+
gem.version = "0.1.0"
|
8
8
|
gem.description = "Simple tool for accounting of cryptocurrencies"
|
9
9
|
gem.summary = "Simple tool for accounting of cryptocurrencies"
|
10
10
|
gem.author = "Geoff Meakin"
|
data/lib/gtmtech/crypto.rb
CHANGED
data/lib/gtmtech/crypto/data.rb
CHANGED
@@ -69,12 +69,17 @@ module Gtmtech
|
|
69
69
|
|
70
70
|
def self.list_transactions
|
71
71
|
puts "Transactions for profile \"#{ENV['CRYPTO_PROFILE'] || 'main'}\":"
|
72
|
-
printf("%-36s %-20s %-15s %-15s %-15s %-15s\n", "id", "date", "src account", "src amount", "dest account", "dest amount")
|
73
|
-
puts "-" *
|
72
|
+
printf("%-36s %-20s %-15s %-15s %-15s %-15s %-30s\n", "id", "date", "src account", "src amount", "dest account", "dest amount", "ratio src/dest")
|
73
|
+
puts "-" * 150
|
74
74
|
@@document[ "transactions" ].each do |id, txn|
|
75
|
-
|
75
|
+
ratio = ""
|
76
|
+
if txn["source_currency"] != txn["dest_currency"]
|
77
|
+
ratio = Utils.decimal_divide( txn["source_amount"], txn["dest_amount"] )
|
78
|
+
end
|
79
|
+
printf("%-36s %-20s %-15s %-15s %-15s %-15s %-30s\n", id, txn["date"], "#{txn["source_account"]}.#{txn["source_currency"]}", txn["source_amount"], "#{txn["dest_account"]}.#{txn["dest_currency"]}", txn["dest_amount"], ratio)
|
80
|
+
ratio = ""
|
76
81
|
if txn["fees_account"]
|
77
|
-
printf("%-36s %-20s %-15s %-15s %-15s %-15s\n", id, txn["date"], "#{txn["fees_account"]}.#{txn["fees_currency"]}", txn["fees_amount"], "fees.#{txn["fees_currency"]}", txn["fees_amount"])
|
82
|
+
printf("%-36s %-20s %-15s %-15s %-15s %-15s %-30s\n", id, txn["date"], "#{txn["fees_account"]}.#{txn["fees_currency"]}", txn["fees_amount"], "fees.#{txn["fees_currency"]}", txn["fees_amount"], ratio)
|
78
83
|
end
|
79
84
|
end
|
80
85
|
end
|
@@ -83,10 +88,10 @@ module Gtmtech
|
|
83
88
|
@@document[ "transactions" ].delete( id )
|
84
89
|
end
|
85
90
|
|
86
|
-
def self.reconcile_transactions
|
91
|
+
def self.reconcile_transactions conversions
|
87
92
|
self.list_transactions
|
88
93
|
puts ""
|
89
|
-
printf("%-20s %-10s %-20s\n", "account", "currency", "amount")
|
94
|
+
printf("%-20s %-10s %-20s %-30s\n", "account", "currency", "amount", "GBP equivalent")
|
90
95
|
puts "-" * 120
|
91
96
|
fees = {}
|
92
97
|
currencies = {}
|
@@ -125,14 +130,18 @@ module Gtmtech
|
|
125
130
|
currencies[ currency ] = "0.0"
|
126
131
|
end
|
127
132
|
currencies[ currency ] = Utils.decimal_add( currencies[ currency ], decimal )
|
128
|
-
|
133
|
+
gbp_equiv = "?"
|
134
|
+
gbp_equiv = Utils.decimal_multiply( decimal, conversions[ currency ] ) if conversions.key? currency
|
135
|
+
printf( "%-20s %-10s %-20s %-30s\n", name, currency, decimal, gbp_equiv )
|
129
136
|
end
|
130
137
|
end
|
131
138
|
fees.keys.sort.each do |currency|
|
132
139
|
unless currencies.key? currency
|
133
140
|
currencies[ currency ] = "0.0"
|
134
141
|
end
|
135
|
-
|
142
|
+
gbp_equiv = "?"
|
143
|
+
gbp_equiv = Utils.decimal_multiply( fees[ currency ], conversions[ currency ] ) if conversions.key? currency
|
144
|
+
printf( "%-20s %-10s %-20s %-30s\n", "**FEES**", currency, fees[ currency ], gbp_equiv)
|
136
145
|
end
|
137
146
|
|
138
147
|
puts ""
|
@@ -143,11 +152,28 @@ module Gtmtech
|
|
143
152
|
printf( "%-10s %-20s\n", currency, Utils.decimal_add( currencies[ currency ], currency_fees ) )
|
144
153
|
end
|
145
154
|
|
155
|
+
gbp_total = "0.0"
|
156
|
+
gbp_known = true
|
146
157
|
puts ""
|
147
|
-
printf( "%-10s %-20s\n", "currency", "totals" )
|
158
|
+
printf( "%-10s %-20s %-20s\n", "currency", "totals", "GBP equivalent" )
|
148
159
|
puts "-" * 120
|
149
160
|
currencies.keys.sort.each do |currency|
|
150
|
-
|
161
|
+
amount = currencies[ currency ]
|
162
|
+
if conversions.key? currency
|
163
|
+
gbp_equiv = Utils.decimal_multiply( amount, conversions[ currency ] )
|
164
|
+
printf( "%-10s %-20s %-20s\n", currency, currencies[ currency ], gbp_equiv )
|
165
|
+
gbp_total = Utils.decimal_add( gbp_total, gbp_equiv )
|
166
|
+
else
|
167
|
+
printf( "%-10s %-20s %-20s\n", currency, currencies[ currency ], "?" )
|
168
|
+
gbp_known = false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
puts ""
|
173
|
+
if gbp_known
|
174
|
+
puts "GBP profit/loss (equivalent): #{gbp_total}"
|
175
|
+
else
|
176
|
+
puts "GBP profit/loss (equivalent): unknown - specify conversions on command-line"
|
151
177
|
end
|
152
178
|
end
|
153
179
|
|
@@ -12,11 +12,13 @@ module Gtmtech
|
|
12
12
|
|
13
13
|
def self.usage
|
14
14
|
<<-EOS
|
15
|
-
Usage (crypto #{self.prettyname})
|
15
|
+
Usage (crypto #{self.prettyname}) [BTC=<current btc price> ETH=<current eth price> .... etc ...]
|
16
16
|
|
17
17
|
crypto #{self.prettyname}
|
18
18
|
- reconcile all transactions
|
19
19
|
|
20
|
+
If you specify the current price (in GBP) of each coin, the summary will become more illuminating
|
21
|
+
|
20
22
|
Options:
|
21
23
|
EOS
|
22
24
|
end
|
@@ -25,13 +27,20 @@ EOS
|
|
25
27
|
[]
|
26
28
|
end
|
27
29
|
|
28
|
-
def self.reconcile
|
30
|
+
def self.reconcile values
|
29
31
|
Data.load
|
30
|
-
Data.reconcile_transactions
|
32
|
+
Data.reconcile_transactions values
|
31
33
|
end
|
32
34
|
|
33
35
|
def self.execute
|
34
|
-
|
36
|
+
values = {}
|
37
|
+
while ARGV.length > 0
|
38
|
+
current_valuation = ARGV.shift
|
39
|
+
currency = current_valuation.split("=")[0]
|
40
|
+
gbp_equiv = current_valuation.split("=")[1]
|
41
|
+
values[ currency ] = gbp_equiv
|
42
|
+
end
|
43
|
+
self.reconcile values
|
35
44
|
end
|
36
45
|
|
37
46
|
end
|
data/lib/gtmtech/crypto/utils.rb
CHANGED
@@ -67,6 +67,14 @@ module Gtmtech
|
|
67
67
|
( BigDecimal( decimal1 ) - BigDecimal( decimal2 ) ).to_s("F")
|
68
68
|
end
|
69
69
|
|
70
|
+
def self.decimal_multiply decimal1, decimal2
|
71
|
+
( BigDecimal( decimal1 ) * BigDecimal( decimal2 ) ).truncate(8).to_s("F")
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.decimal_divide decimal1, decimal2
|
75
|
+
( BigDecimal( decimal1 ) / BigDecimal( decimal2 ) ).truncate(8).to_s("F")
|
76
|
+
end
|
77
|
+
|
70
78
|
end
|
71
79
|
end
|
72
80
|
end
|