ledger_get_prices 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41c009059067525d46e9499b59d27afd58c6d5cb
4
- data.tar.gz: 50562e2f41338701f426c9b7c73ed7ab2399e924
3
+ metadata.gz: 82002be160f52fc01564edb64715b8126b57dcef
4
+ data.tar.gz: 266d9a38f944428cf3fcf84c3454cc3bdc75d91c
5
5
  SHA512:
6
- metadata.gz: e334b3491995b5815d7785648c0e6a676b62272a6d913154482b0f9f7c4b24bd792591b2c563487d4b92bcb5c866b5bcdafa2a7b455e494c96ba191885d7c0c5
7
- data.tar.gz: 5d2e26fc192954bbad458f81c1224aa3905f0d6fa56fbfdd1d0a422c48c5ac1077e99934df6d43ec69981aa929fa4174685d329b5272b425831f4efa6ecd0924
6
+ metadata.gz: 93fc33cf7c01e3195b02ede4b468bfc66487ce6e0fff35dec66bc0b7927d52bab2b7a2048d8530562f096a8ccb7bb2a79230e005786dca9f308039393753992f
7
+ data.tar.gz: b06564e0d3208a20b2a4124590eb5b4dd7062908e032e4cc806e98693d971a6edab65f71fccf3562249b8b1ac304e324afea7adbf4fe0e0c37d6469eeee5f4f3
@@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.6"
21
21
  spec.add_development_dependency "rake"
22
- spec.add_runtime_dependency "yahoo-finance", "~> 1.0.0"
22
+ spec.add_runtime_dependency "yahoo-finance", "~> 1.1.0"
23
23
  end
@@ -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
- # Yahoo finance works best in USD, if the base currency is
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
- commodities.reduce(existing_prices) do |db, c|
55
- # `|` is a shortcut for merge
56
- db | prices_for_symbol(c, start_date: start_date, end_date: end_date)
57
- .map { |x| price_string_from_result(x, symbol: c) }
58
- end
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: start_date, end_date: end_date) # -> Array
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, start_date: start_date, end_date: end_date, period: :daily)
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: (BASE_CURRENCY == 'USD' ? '$' : 'USD'),
101
- price: (BASE_CURRENCY == symbol ? '$' : symbol)+ data.close
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").reject { |x| x == "$" }.tap do |c|
135
- # Since all quotes will be in USD, we don't need to bother
136
- # retrieving USD/USD quotes.
137
- c << BASE_CURRENCY if BASE_CURRENCY != 'USD'
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
@@ -1,3 +1,3 @@
1
1
  module LedgerGetPrices
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  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.7
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-05-13 00:00:00.000000000 Z
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.0.0
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.0.0
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.2.2
92
+ rubygems_version: 2.4.5
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Intelligently update your ledger pricedb