mycoins 0.2.0 → 0.2.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -3
- data/lib/mycoins.rb +53 -15
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1eeaa2d4398a92bbc3079a14e66f834deac201b
|
4
|
+
data.tar.gz: 6b05e301b76e0c9b7faf6747c5033a8ee522f9cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eceb49d43867af6b28b6c2c693f4befcf08788289d4dc54128c5729c3af1b0c16650905aeb610eb8ad88f6b30659d6ce383fee10a4c402e121c8342903fd4bd
|
7
|
+
data.tar.gz: 65bb1cb36f12c85bbf742cee232d72ec1c325cffe70d7c9b76300c6bd5ee8130bdc26ff6a8f8cffb59e8ef0e3a18718c76faf3e97c58fff7bb4896cb1bb6c2b5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
data/lib/mycoins.rb
CHANGED
@@ -28,7 +28,7 @@ class MyCoins
|
|
28
28
|
|
29
29
|
puts '@dx.to_xml: ' + @dx.to_xml if @debug
|
30
30
|
|
31
|
-
@mycurrency = @dx.currency || mycurrency.upcase
|
31
|
+
@mycurrency = (@dx.currency || mycurrency).upcase
|
32
32
|
puts '@mycurrency: ' + @mycurrency.inspect if @debug
|
33
33
|
|
34
34
|
mycoins = @dx.all.inject([]) do |r, mycoin|
|
@@ -53,20 +53,29 @@ class MyCoins
|
|
53
53
|
a = @dx.all.inject([]) do |r, x|
|
54
54
|
|
55
55
|
puts 'x: ' + x.inspect if @debug
|
56
|
-
|
56
|
+
coin = @ccf.find(x.title)
|
57
|
+
usd_rate = coin.price_usd.to_f
|
58
|
+
|
59
|
+
paid = ((x.qty.to_f * x.btc_price.to_f) * \
|
60
|
+
@ccf.price('bitcoin', x.date_purchased) * \
|
61
|
+
@jer.rate(@mycurrency)).round(2)
|
62
|
+
|
63
|
+
value_usd = (usd_rate * x.qty.to_f).round(2)
|
57
64
|
|
58
65
|
h = {
|
66
|
+
rank: coin.rank.to_i,
|
59
67
|
name: x.title,
|
60
|
-
qty: x.qty,
|
61
|
-
|
68
|
+
qty: x.qty,
|
69
|
+
btc_price: x.btc_price,
|
70
|
+
paid: "%.2f" % paid,
|
71
|
+
value_usd: "%.2f" % value_usd
|
62
72
|
}
|
63
73
|
|
64
74
|
|
65
75
|
mycurrency = if @mycurrency and @mycurrency != 'USD' then
|
66
76
|
|
67
77
|
local_value = ((usd_rate * x.qty.to_f) * @jer.rate(@mycurrency)).round(2)
|
68
|
-
h.merge!(('value_' + @mycurrency.downcase).to_sym => local_value)
|
69
|
-
|
78
|
+
h.merge!(('value_' + @mycurrency.downcase).to_sym => "%.2f" % local_value)
|
70
79
|
|
71
80
|
@mycurrency
|
72
81
|
|
@@ -76,26 +85,55 @@ class MyCoins
|
|
76
85
|
|
77
86
|
end
|
78
87
|
|
79
|
-
|
88
|
+
value = (local_value || value_usd)
|
89
|
+
|
90
|
+
h2 = {
|
91
|
+
profit: "%.2f" % (value - paid).round(2),
|
92
|
+
pct_profit: "%.2f" % (((value - paid) / value) * 100).round(2)
|
93
|
+
}
|
94
|
+
|
95
|
+
r << h.merge!(h2)
|
80
96
|
|
81
97
|
end
|
82
98
|
|
83
|
-
coins = a.map {|x| x.values}
|
99
|
+
coins = a.sort_by{|x| x[:rank]}.map {|x| x.values}
|
84
100
|
|
85
|
-
labels = %w(Name Qty USD)
|
86
|
-
labels << @mycurrency if @mycurrency
|
101
|
+
labels = %w(Rank Name Qty btc_price) + ["paid(#{@mycurrency}):", 'value(USD):']
|
102
|
+
labels << "value(#{@mycurrency}):" if @mycurrency
|
103
|
+
labels += ['Profit:', 'Profit (%):']
|
87
104
|
|
88
105
|
puts 'labels: ' + labels.inspect if @debug
|
89
106
|
tf = TableFormatter.new(source: coins, labels: labels)
|
90
|
-
out =
|
107
|
+
out = "# " + @dx.title + "\n\n"
|
108
|
+
out << "last_updated: " + Time.now.strftime("%d/%m/%Y\n\n")
|
109
|
+
out << tf.display
|
110
|
+
|
111
|
+
invested = sum(a, :paid)
|
112
|
+
total = sum(a, ('value_' + @mycurrency.downcase).to_sym)
|
113
|
+
net_profit = sum(a, :profit)
|
91
114
|
|
92
|
-
|
93
|
-
r + x[('value_' + @mycurrency.downcase).to_sym]
|
94
|
-
end
|
115
|
+
gross_profit_list, losses_list = a.partition {|x| x[:profit].to_f > 0}
|
95
116
|
|
96
|
-
|
117
|
+
gross_profit = sum(gross_profit_list, :profit)
|
118
|
+
losses = sum(losses_list, :profit)
|
119
|
+
|
120
|
+
pct_gross_profit = 100 / (invested / gross_profit)
|
121
|
+
pct_losses = 100 / (invested / losses)
|
122
|
+
|
123
|
+
|
124
|
+
out << "\n\nInvested: %.2f %s" % [invested, @mycurrency]
|
125
|
+
out << "\nRevenue: %.2f %s" % [total, @mycurrency]
|
126
|
+
out << "\n\nGross profit: %.2f %s (%%%.2f)" % [gross_profit, @mycurrency, pct_gross_profit]
|
127
|
+
out << "\nLosses: %.2f %s (%%%.2f)" % [losses, @mycurrency, pct_losses]
|
128
|
+
out << "\n\nNet profit: %.2f %s" % [net_profit, @mycurrency]
|
97
129
|
out
|
98
130
|
|
99
131
|
end
|
100
132
|
|
133
|
+
private
|
134
|
+
|
135
|
+
def sum(a, field)
|
136
|
+
a.inject(0) {|r, x| r + x[field].to_f }
|
137
|
+
end
|
138
|
+
|
101
139
|
end
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|