mycoins 0.2.4 → 0.2.5
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 +0 -0
- data/lib/mycoins.rb +23 -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: ae93a879c55d95f55070ebb8731bcf73c135498b
|
4
|
+
data.tar.gz: f0bd6d46cc903407cb577effedbac04971f99981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4ed3d309508b0d7f2cb85072762639f646a85d8523d8f9e70081a217bfbac362aa0567f9f1f3b10ab3976bf3319d2847585fdfe8284155c8b71e9a2c342c427
|
7
|
+
data.tar.gz: 90ebeec8177ccd9dc552bfe5dc2e51ece56f465bef2335c8db3ef2778e2b5e4690f03ce2a416334f10a0ee27c387bd2b1f9a1403940596e65ac988cec62a2a7e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mycoins.rb
CHANGED
@@ -23,9 +23,7 @@ class MyCoins
|
|
23
23
|
if s =~ /<\?dynarex / then
|
24
24
|
|
25
25
|
@dx = Dynarex.new
|
26
|
-
@dx.import s
|
27
|
-
|
28
|
-
puts @dx.to_xml pretty: true
|
26
|
+
@dx.import s
|
29
27
|
|
30
28
|
end
|
31
29
|
|
@@ -64,8 +62,15 @@ class MyCoins
|
|
64
62
|
# return the value of a coin given either the qty or purchase amount in BTC
|
65
63
|
#
|
66
64
|
def price(coin_name, qty, btc: nil, date: nil)
|
67
|
-
|
68
|
-
|
65
|
+
|
66
|
+
price_usd = if date then
|
67
|
+
@ccf.price coin_name, date
|
68
|
+
else
|
69
|
+
coin = @ccf.find(coin_name)
|
70
|
+
coin.price_usd.to_f
|
71
|
+
end
|
72
|
+
|
73
|
+
"%.2f %s" % [(price_usd * qty.to_f) * @jer.rate(@mycurrency),
|
69
74
|
@mycurrency]
|
70
75
|
end
|
71
76
|
|
@@ -80,7 +85,6 @@ class MyCoins
|
|
80
85
|
|
81
86
|
r = build_portfolio(@dx.title)
|
82
87
|
dx = Dynarex.new
|
83
|
-
puts 'r.records: ' + r.records.inspect
|
84
88
|
dx.import r.records
|
85
89
|
|
86
90
|
h = r.to_h
|
@@ -106,6 +110,8 @@ class MyCoins
|
|
106
110
|
gross_profit_list, losses_list = a.partition {|x| x[:profit].to_f > 0}
|
107
111
|
gross_profit, losses = [gross_profit_list, losses_list]\
|
108
112
|
.map{|x| sum(x, :profit)}
|
113
|
+
pct_gross_profit = (100 / (invested / gross_profit)).round(2)
|
114
|
+
pct_losses = (100 / (invested / losses)).round(2)
|
109
115
|
|
110
116
|
h = {
|
111
117
|
title: title,
|
@@ -115,9 +121,10 @@ class MyCoins
|
|
115
121
|
invested: invested,
|
116
122
|
value: sum(a, ('value_' + @mycurrency.downcase).to_sym),
|
117
123
|
gross_profit: gross_profit.round(2), losses: losses.round(2),
|
118
|
-
pct_gross_profit:
|
119
|
-
pct_losses:
|
120
|
-
net_profit: sum(a, :profit).round(2)
|
124
|
+
pct_gross_profit: pct_gross_profit,
|
125
|
+
pct_losses: pct_losses,
|
126
|
+
net_profit: sum(a, :profit).round(2),
|
127
|
+
pct_net_profit: pct_gross_profit + pct_losses
|
121
128
|
}
|
122
129
|
|
123
130
|
@portfolio = OpenStruct.new(h)
|
@@ -143,9 +150,9 @@ class MyCoins
|
|
143
150
|
title: x.title,
|
144
151
|
rank: coin.rank.to_i,
|
145
152
|
qty: "%.2f" % x.qty,
|
146
|
-
btc_price: "%.
|
147
|
-
paid: "%.
|
148
|
-
value_usd: "%.
|
153
|
+
btc_price: "%.5f" % x.btc_price,
|
154
|
+
paid: "%.0f" % paid,
|
155
|
+
value_usd: "%.0f" % value_usd
|
149
156
|
}
|
150
157
|
|
151
158
|
mycurrency = if @mycurrency and @mycurrency != 'USD' then
|
@@ -163,6 +170,7 @@ class MyCoins
|
|
163
170
|
|
164
171
|
end
|
165
172
|
|
173
|
+
puts 'local_value: ' + local_value.inspect if @debug
|
166
174
|
value = (local_value || value_usd)
|
167
175
|
|
168
176
|
h2 = {
|
@@ -194,10 +202,10 @@ class MyCoins
|
|
194
202
|
out << tf.display
|
195
203
|
|
196
204
|
out << "\n\nInvested: %.2f %s" % [r.invested, @mycurrency]
|
197
|
-
out << "\n\nGross profit: %.2f %s (
|
205
|
+
out << "\n\nGross profit: %.2f %s (%.2f%%)" % \
|
198
206
|
[r.gross_profit, @mycurrency, r.pct_gross_profit]
|
199
|
-
out << "\nLosses: %.2f %s (
|
200
|
-
out << "\n\nNet profit: %.2f %s" % [r.net_profit, @mycurrency]
|
207
|
+
out << "\nLosses: %.2f %s (%.2f%%)" % [r.losses, @mycurrency, r.pct_losses]
|
208
|
+
out << "\n\nNet profit: %.2f %s (%.2f%%)" % [r.net_profit, @mycurrency, r.pct_net_profit]
|
201
209
|
out << "\nCurrent value: %.2f %s" % [r.value, @mycurrency]
|
202
210
|
out
|
203
211
|
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|