ledger_get_prices 0.0.7 → 0.0.8
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
- data/ledger_get_prices.gemspec +1 -1
- data/lib/ledger_get_prices.rb +25 -18
- data/lib/ledger_get_prices/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82002be160f52fc01564edb64715b8126b57dcef
|
4
|
+
data.tar.gz: 266d9a38f944428cf3fcf84c3454cc3bdc75d91c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93fc33cf7c01e3195b02ede4b468bfc66487ce6e0fff35dec66bc0b7927d52bab2b7a2048d8530562f096a8ccb7bb2a79230e005786dca9f308039393753992f
|
7
|
+
data.tar.gz: b06564e0d3208a20b2a4124590eb5b4dd7062908e032e4cc806e98693d971a6edab65f71fccf3562249b8b1ac304e324afea7adbf4fe0e0c37d6469eeee5f4f3
|
data/ledger_get_prices.gemspec
CHANGED
data/lib/ledger_get_prices.rb
CHANGED
@@ -17,16 +17,17 @@ module LedgerGetPrices
|
|
17
17
|
# running +ledger+ vanilla knows where to get the journal and
|
18
18
|
# pricedb.
|
19
19
|
#
|
20
|
+
# Yahoo works best when fetching all prices relative to USD.
|
21
|
+
# So regardless of whether or not USD is actually used, it will
|
22
|
+
# always appear in the resulting prices file.
|
23
|
+
#
|
20
24
|
# = Options
|
21
25
|
#
|
22
|
-
# +LEDGER_BASE_CURRENCY+: Defaults to USD, change this to your reporting currency.
|
23
26
|
# +LEDGER_PRICE_DATE_FORMAT+: The date format of the outputted pricedb. Defaults to +%Y/%m/%d+.
|
24
27
|
class GetPrices
|
25
28
|
class << self
|
26
29
|
|
27
|
-
#
|
28
|
-
# different we will also store the USD price of that currency
|
29
|
-
# to allow for conversion.
|
30
|
+
# The base currency should be the currency that the dollar sign represents in your reports.
|
30
31
|
BASE_CURRENCY = ENV['LEDGER_BASE_CURRENCY'] || "USD"
|
31
32
|
|
32
33
|
PRICE_DB_PATH = ENV['LEDGER_PRICE_DB'] || ENV['PRICE_HIST'] # PRICE_HIST is <v3
|
@@ -51,15 +52,18 @@ module LedgerGetPrices
|
|
51
52
|
#
|
52
53
|
# @return [Array] an array of formatted prices
|
53
54
|
def new_prices
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
# Since everything is relative to USD, we don't need to fetch it.
|
56
|
+
commodities
|
57
|
+
.reject { |c| c == "USD" }
|
58
|
+
.reduce(existing_prices) do |db, c|
|
59
|
+
# `|` is a shortcut for merge
|
60
|
+
db | prices_for_symbol(c, start_date: start_date, end_date: end_date)
|
61
|
+
.map { |x| price_string_from_result(x, symbol: c) }
|
62
|
+
end
|
59
63
|
end
|
60
64
|
|
61
65
|
# @return [Array] of YahooFinance results (OpenStruct)
|
62
|
-
def prices_for_symbol(symbol, start_date:
|
66
|
+
def prices_for_symbol(symbol, start_date: nil, end_date: nil) # -> Array
|
63
67
|
puts "Getting historical quotes for: #{symbol}"
|
64
68
|
|
65
69
|
if COMMODITY_BLACKLIST.include?(symbol)
|
@@ -77,7 +81,11 @@ module LedgerGetPrices
|
|
77
81
|
while quote_strings.length > 0 && result.nil?
|
78
82
|
begin
|
79
83
|
result = YahooFinance::Client.new.historical_quotes(
|
80
|
-
quote_strings.shift,
|
84
|
+
quote_strings.shift,
|
85
|
+
start_date: start_date,
|
86
|
+
end_date: end_date,
|
87
|
+
period: :daily)
|
88
|
+
|
81
89
|
rescue OpenURI::HTTPError => e
|
82
90
|
err = e
|
83
91
|
end
|
@@ -97,8 +105,8 @@ module LedgerGetPrices
|
|
97
105
|
PRICE_FORMAT % {
|
98
106
|
date: Date.strptime(data.trade_date, '%Y-%m-%d').strftime(DATE_FORMAT),
|
99
107
|
time: '23:59:59',
|
100
|
-
symbol:
|
101
|
-
price:
|
108
|
+
symbol: 'USD',
|
109
|
+
price: symbol + data.close
|
102
110
|
}
|
103
111
|
end
|
104
112
|
|
@@ -131,11 +139,10 @@ module LedgerGetPrices
|
|
131
139
|
|
132
140
|
def commodities
|
133
141
|
# All the commodities we care about.
|
134
|
-
@commodities ||= `ledger commodities`.split("\n")
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
142
|
+
@commodities ||= `ledger commodities`.split("\n")
|
143
|
+
.reject { |x| x == "$" }
|
144
|
+
.tap { |c| c << BASE_CURRENCY }
|
145
|
+
.uniq
|
139
146
|
end
|
140
147
|
|
141
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledger_get_prices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Kot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.1.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.1.0
|
55
55
|
description:
|
56
56
|
email:
|
57
57
|
- nk@nathankot.com
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.4.5
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: Intelligently update your ledger pricedb
|