gtmtech-crypto 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f46c9c9aef20bd2c10db09c32bd54babe62b648a
4
- data.tar.gz: f4c2dfa08b79ad6c8344af05088479745c85e835
3
+ metadata.gz: 666f62b7fcb98a96d19bfdd61f882db3af5c53f4
4
+ data.tar.gz: bf86844efd07b576b48b66d3d27de5c8491b4917
5
5
  SHA512:
6
- metadata.gz: c92f1bf92055336e8ba92ddd0f78373eff333a41a50146998eac08f9dd4da4176abe56be65456a645458217b59f935012b08e57abfbd9cde7f19058292495953
7
- data.tar.gz: 689cc7b71547047088ff6960c192a7a15daac222b112253d7ef6a7293a4f532dc5d12016918ea4ae0fcd052a3fc03c908e831b8b0239214bcb5cf45050391582
6
+ metadata.gz: 1d36a2cac0f0d375c6d1c743058d756f3f86519867a4c5ac92be9591b13b9b49897410b301eba4ccb2cd030f933c879fbc9359081dad016a2e4c69ef1dfd2bac
7
+ data.tar.gz: 6082adda14f0351d4610a34540fbedcd1ec849b4e979922016bc0a656d5b2b66f5f81938e2fb13d3275adf0488c5604a40f592a963314ae1a0047dad8fe1770d
@@ -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.1.0"
7
+ gem.version = "0.1.1"
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"
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ["lib"]
18
18
  gem.add_dependency('trollop', '~> 2.0')
19
+ gem.add_dependency('colorize', '~> 0.8.1')
19
20
  end
@@ -1,5 +1,6 @@
1
1
  require 'securerandom'
2
2
  require 'gtmtech/crypto/utils'
3
+ require 'colorize'
3
4
 
4
5
  module Gtmtech
5
6
  module Crypto
@@ -46,7 +47,7 @@ module Gtmtech
46
47
  true
47
48
  end
48
49
 
49
- def self.add_transaction date, source_account, source_currency, source_amount, dest_account, dest_currency, dest_amount, fees_account, fees_currency, fees_amount
50
+ def self.add_transaction date, source_account, source_currency, source_amount, dest_account, dest_currency, dest_amount, fees_account, fees_currency, fees_amount, references, percentage
50
51
  if date.downcase == "now"
51
52
  date = Time.now.to_s.split(" ").take(2).join(",")
52
53
  end
@@ -64,24 +65,110 @@ module Gtmtech
64
65
  "dest_amount" => dest_amount,
65
66
  "fees_account" => fees_account,
66
67
  "fees_currency" => fees_currency,
67
- "fees_amount" => fees_amount }
68
+ "fees_amount" => fees_amount,
69
+ "references" => references,
70
+ "percentage" => percentage }
68
71
  end
69
72
 
70
73
  def self.list_transactions
71
- puts "Transactions for profile \"#{ENV['CRYPTO_PROFILE'] || 'main'}\":"
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
+ outputs = []
75
+
76
+ puts "Transactions for profile \"#{ENV['CRYPTO_PROFILE'] || 'main'}\":\n".red
77
+ cols = "%-36s %-20s %-14s %-15s %-15s %-15s %-12s %-14s %s"
78
+ puts sprintf("#{cols}",
79
+ "id",
80
+ "date",
81
+ "%age",
82
+ "src account",
83
+ "src amount",
84
+ "dest account",
85
+ "dest amount",
86
+ "ratio",
87
+ "reference_ids").light_blue
88
+ puts "-" * 160
74
89
  @@document[ "transactions" ].each do |id, txn|
75
90
  ratio = ""
76
91
  if txn["source_currency"] != txn["dest_currency"]
77
92
  ratio = Utils.decimal_divide( txn["source_amount"], txn["dest_amount"] )
78
93
  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 = ""
94
+ outputs << { :date => txn["date"],
95
+ :lines => [] }
96
+ if Utils.decimal_equal?( txn[ "percentage" ], "100.0" )
97
+ outputs.last[ :lines ] << sprintf("#{cols}",
98
+ id,
99
+ txn["date"],
100
+ "-",
101
+ "#{txn[ "source_account"] }.#{txn[ "source_currency"] }",
102
+ txn["source_amount"],
103
+ "#{txn[ "dest_account"] }.#{txn[ "dest_currency"] }",
104
+ txn[ "dest_amount" ],
105
+ ratio,
106
+ txn[ "references" ][0..20] )
107
+ else
108
+ outputs.last[ :lines ] << sprintf("#{cols}",
109
+ id,
110
+ txn["date"],
111
+ "100.0",
112
+ "#{txn["source_account"]}.#{txn["source_currency"]}",
113
+ txn["source_amount"],
114
+ "#{txn["dest_account"]}.#{txn["dest_currency"]}",
115
+ txn[ "dest_amount" ],
116
+ ratio,
117
+ txn[ "references" ][0..20] ).light_black
118
+ outputs.last[ :lines ] << sprintf("#{cols}",
119
+ "",
120
+ "",
121
+ Utils.decimal_add( txn["percentage"], "0.0" ),
122
+ "#{txn["source_account"]}.#{txn["source_currency"]}",
123
+ Utils.decimal_multiply( txn["source_amount"], txn["percentage"], "0.01" ),
124
+ "#{txn["dest_account"]}.#{txn["dest_currency"]}",
125
+ Utils.decimal_multiply( txn[ "dest_amount" ], txn[ "percentage" ], "0.01" ),
126
+ "",
127
+ "" )
128
+ end
81
129
  if txn["fees_account"]
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)
130
+ if Utils.decimal_equal?( txn[ "percentage" ], "100.0" )
131
+ outputs.last[ :lines ] << sprintf("#{cols}",
132
+ "",
133
+ "",
134
+ "-",
135
+ "#{txn["fees_account"]}.#{txn["fees_currency"]}",
136
+ txn["fees_amount"],
137
+ "FEES.#{txn["fees_currency"]}",
138
+ txn[ "fees_amount" ],
139
+ "",
140
+ "" )
141
+ else
142
+ outputs.last[ :lines ] << sprintf("#{cols}",
143
+ "",
144
+ "",
145
+ "100.0",
146
+ "#{txn["fees_account"]}.#{txn["fees_currency"]}",
147
+ txn["fees_amount"],
148
+ "FEES.#{txn["fees_currency"]}",
149
+ txn[ "fees_amount" ],
150
+ "",
151
+ "" ).light_black
152
+ outputs.last[ :lines ] << sprintf("#{cols}",
153
+ "",
154
+ "",
155
+ Utils.decimal_add( txn["percentage"], "0.0" ),
156
+ "#{txn["fees_account"]}.#{txn["fees_currency"]}",
157
+ Utils.decimal_multiply( txn["fees_amount"], txn["percentage"], "0.01" ),
158
+ "FEES.#{txn["fees_currency"]}",
159
+ Utils.decimal_multiply( txn[ "fees_amount" ], txn["percentage"], "0.01" ),
160
+ "",
161
+ "" )
162
+ end
83
163
  end
84
164
  end
165
+
166
+ outputs.sort_by { |k| k[ :date ] }.each do |k|
167
+ k[ :lines ].each do |line|
168
+ puts line
169
+ end
170
+ end
171
+
85
172
  end
86
173
 
87
174
  def self.delete_transaction id
@@ -91,48 +178,57 @@ module Gtmtech
91
178
  def self.reconcile_transactions conversions
92
179
  self.list_transactions
93
180
  puts ""
94
- printf("%-20s %-10s %-20s %-30s\n", "account", "currency", "amount", "GBP equivalent")
181
+ cols = "%-20s %-10s %-20s %-30s"
182
+ puts sprintf("#{cols}", "account", "currency", "amount", "GBP equivalent").light_blue
95
183
  puts "-" * 120
96
184
  fees = {}
97
185
  currencies = {}
98
186
  @@document[ "accounts" ].each do | name, account_info |
99
187
  account_info[ "currencies" ].sort.each do | currency |
100
- decimal = "0.0"
188
+ total = "0.0"
189
+ txn_total = "0.0"
101
190
  @@document[ "transactions" ].each do |id, txn|
191
+
102
192
  # explicit fees
103
193
  if txn[ "fees_account" ] == name and txn[ "fees_currency" ] == currency
104
- decimal = Utils.decimal_minus( decimal, txn[ "fees_amount" ] )
194
+ # print "#{txn_total} : - #{txn[ "percentage" ]}% of #{txn[ "fees_amount" ]}".blue
195
+ txn_total = Utils.decimal_minus( txn_total, Utils.decimal_multiply( txn[ "fees_amount" ], txn[ "percentage" ], "0.01" ) )
196
+ # puts " = #{txn_total}".blue
105
197
  unless fees.key? currency
106
198
  fees[ currency ] = "0.0"
107
199
  end
108
- fees[ currency ] = Utils.decimal_add( fees[ currency ], txn[ "fees_amount" ])
200
+ fees[ currency ] = Utils.decimal_add( fees[ currency ], Utils.decimal_multiply( txn[ "fees_amount" ], txn[ "percentage" ], "0.01" ) )
109
201
  end
110
202
 
111
203
  # account reconciliation
112
204
  if txn[ "source_account" ] == name and txn[ "source_currency" ] == currency
113
- decimal = Utils.decimal_minus( decimal, txn[ "source_amount" ] )
114
-
205
+ # print "#{txn_total} : - #{txn[ "percentage" ]}% of #{txn[ "source_amount" ]}".blue
206
+ txn_total = Utils.decimal_minus( txn_total, Utils.decimal_multiply( txn[ "source_amount" ], txn[ "percentage" ], "0.01" ) )
207
+ # puts " = #{txn_total}".blue
208
+
115
209
  # implicit fees
116
210
  if txn[ "source_currency" ] == txn[ "dest_currency" ] and txn[ "source_amount" ] != txn[ "dest_amount" ]
117
211
  implicit_fees = Utils.decimal_minus( txn[ "source_amount" ], txn[ "dest_amount" ] )
118
212
  unless fees.key? currency
119
213
  fees[ currency ] = "0.0"
120
214
  end
121
- fees[ currency ] = Utils.decimal_add( fees[ currency ], implicit_fees )
215
+ fees[ currency ] = Utils.decimal_add( fees[ currency ], Utils.decimal_multiply( implicit_fees, txn[ "percentage" ], "0.01" ) )
122
216
  end
123
217
 
124
218
  end
125
219
  if txn[ "dest_account" ] == name and txn[ "dest_currency" ] == currency
126
- decimal = Utils.decimal_add( decimal, txn[ "dest_amount" ] )
220
+ # print "#{txn_total} : + #{txn[ "percentage" ]}% of #{txn[ "dest_amount" ]}".blue
221
+ txn_total = Utils.decimal_add( txn_total, Utils.decimal_multiply( txn[ "dest_amount" ], txn[ "percentage" ], "0.01" ) )
222
+ # puts " = #{txn_total}".blue
127
223
  end
128
224
  end
129
225
  unless currencies.key? currency
130
226
  currencies[ currency ] = "0.0"
131
227
  end
132
- currencies[ currency ] = Utils.decimal_add( currencies[ currency ], decimal )
228
+ currencies[ currency ] = Utils.decimal_add( currencies[ currency ], txn_total )
133
229
  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 )
230
+ gbp_equiv = Utils.decimal_multiply( txn_total, conversions[ currency ] ) if conversions.key? currency
231
+ puts sprintf( "#{cols}", name, currency, txn_total, gbp_equiv )
136
232
  end
137
233
  end
138
234
  fees.keys.sort.each do |currency|
@@ -141,11 +237,12 @@ module Gtmtech
141
237
  end
142
238
  gbp_equiv = "?"
143
239
  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)
240
+ puts sprintf( "#{cols}", "**FEES**", currency, fees[ currency ], gbp_equiv)
145
241
  end
146
242
 
147
243
  puts ""
148
- printf( "%-10s %-20s\n", "currency", "reconciliation" )
244
+ cols = "%-10s %-20s"
245
+ puts sprintf( "#{cols}", "currency", "reconciliation" ).light_blue
149
246
  puts "-" * 120
150
247
  currencies.keys.sort.each do |currency|
151
248
  currency_fees = fees[ currency ] || "0.0"
@@ -155,25 +252,28 @@ module Gtmtech
155
252
  gbp_total = "0.0"
156
253
  gbp_known = true
157
254
  puts ""
158
- printf( "%-10s %-20s %-20s\n", "currency", "totals", "GBP equivalent" )
255
+ cols = "%-10s %-20s %-20s"
256
+ puts sprintf( "#{cols}", "currency", "totals", "GBP equivalent" ).light_blue
159
257
  puts "-" * 120
160
258
  currencies.keys.sort.each do |currency|
161
259
  amount = currencies[ currency ]
162
260
  if conversions.key? currency
163
261
  gbp_equiv = Utils.decimal_multiply( amount, conversions[ currency ] )
164
- printf( "%-10s %-20s %-20s\n", currency, currencies[ currency ], gbp_equiv )
262
+ puts sprintf( "#{cols}", currency, currencies[ currency ], gbp_equiv )
165
263
  gbp_total = Utils.decimal_add( gbp_total, gbp_equiv )
166
264
  else
167
- printf( "%-10s %-20s %-20s\n", currency, currencies[ currency ], "?" )
265
+ puts sprintf( "#{cols}", currency, currencies[ currency ], "?" )
168
266
  gbp_known = false
169
267
  end
170
268
  end
171
269
 
172
270
  puts ""
271
+ puts "profit/loss (equivalent GBP)".blue
272
+ puts "----------------------------"
173
273
  if gbp_known
174
- puts "GBP profit/loss (equivalent): #{gbp_total}"
274
+ puts gbp_total
175
275
  else
176
- puts "GBP profit/loss (equivalent): unknown - specify conversions on command-line"
276
+ puts "unknown - specify conversions on command-line - see --help"
177
277
  end
178
278
  end
179
279
 
@@ -14,7 +14,7 @@ module Gtmtech
14
14
  <<-EOS
15
15
  Usage (crypto #{self.prettyname})
16
16
 
17
- crypto #{self.prettyname} new --date=<s> --from=<s> --to=<s> [--fees=<s>]
17
+ crypto #{self.prettyname} new --date=<s> --from=<s> --to=<s> [--fees=<s>] [--references=<s>] [--percentage=<s>]
18
18
  - create a new transaction
19
19
 
20
20
  crypto #{self.prettyname} delete --id=<s>
@@ -51,7 +51,17 @@ EOS
51
51
  {:name => :id,
52
52
  :description => "Specify the id you wish to amend/delete in a delete operation",
53
53
  :short => 'i',
54
- :type => :string}
54
+ :type => :string},
55
+ {:name => :references,
56
+ :description => "Specify any thirdparty / blockchain reference IDs associated with the transaction (Optional)",
57
+ :short => 'r',
58
+ :type => :string,
59
+ :default => ""},
60
+ {:name => :percentage,
61
+ :description => "Percentage of the transaction which actually applies to this profile (for the case of a transaction which spans multiple profiles and should only be counted in part) (Optional)",
62
+ :short => 'p',
63
+ :type => :string,
64
+ :default => "100.0"}
55
65
  ]
56
66
  end
57
67
 
@@ -93,7 +103,7 @@ EOS
93
103
  Data.load
94
104
  self.error "The account #{source_account}.#{source_currency} does not yet exist" unless Data.account_exists? source_account, source_currency
95
105
  self.error "The account #{dest_account}.#{dest_currency} does not yet exist" unless Data.account_exists? dest_account, dest_currency
96
- Data.add_transaction @@options[:date], source_account, source_currency, source_amount, dest_account, dest_currency, dest_amount, fees_account, fees_currency, fees_amount
106
+ Data.add_transaction @@options[:date], source_account, source_currency, source_amount, dest_account, dest_currency, dest_amount, fees_account, fees_currency, fees_amount, @@options[ :references ], @@options[ :percentage ]
97
107
  Data.save
98
108
  end
99
109
 
@@ -60,21 +60,24 @@ module Gtmtech
60
60
  end
61
61
 
62
62
  def self.decimal_add decimal1, decimal2
63
- ( BigDecimal( decimal1 ) + BigDecimal( decimal2 ) ).to_s("F")
63
+ ( BigDecimal( decimal1 ) + BigDecimal( decimal2 ) ).truncate(8).to_s("F")
64
64
  end
65
65
 
66
66
  def self.decimal_minus decimal1, decimal2
67
- ( BigDecimal( decimal1 ) - BigDecimal( decimal2 ) ).to_s("F")
67
+ ( BigDecimal( decimal1 ) - BigDecimal( decimal2 ) ).truncate(8).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")
70
+ def self.decimal_multiply decimal1, decimal2, decimal3 = "1.0"
71
+ ( BigDecimal( decimal1 ) * BigDecimal( decimal2 ) * BigDecimal( decimal3 ) ).truncate(8).to_s("F")
72
72
  end
73
73
 
74
74
  def self.decimal_divide decimal1, decimal2
75
75
  ( BigDecimal( decimal1 ) / BigDecimal( decimal2 ) ).truncate(8).to_s("F")
76
76
  end
77
77
 
78
+ def self.decimal_equal? decimal1, decimal2
79
+ BigDecimal( decimal1 ) == BigDecimal( decimal2 )
80
+ end
78
81
  end
79
82
  end
80
83
  end
@@ -1,7 +1,7 @@
1
1
  module Gtmtech
2
2
  module Crypto
3
3
 
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  DESCRIPTION = "crypto is a cli tool for simple accounting of cryptocurrencies"
6
6
 
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtmtech-crypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Meakin
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
27
41
  description: Simple tool for accounting of cryptocurrencies
28
42
  email:
29
43
  executables: