rapflag 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: 72ac31a1ed8f02d2602c12a87d0ca55a79b00d67
4
- data.tar.gz: c6e7abce5e56208207a88a2d98b585555f25cdae
3
+ metadata.gz: 49743ea60e2bd47dfbdf5ad864c4b7119ba0e7d0
4
+ data.tar.gz: fd4883603a73ad3512d1ee771d22852aa77b3262
5
5
  SHA512:
6
- metadata.gz: e72b855a3bf4f541f72abd75dbdb3ef2a3150fdd2e71ffced58c22b41d4fc19c51af6cf817e1421308f2ce56405020c4a0d77861d9ee85ccc6fd3c7715455217
7
- data.tar.gz: 00c95b069c5eb24d6ec2eb50e958bdb40aba1cd341ae238be597b0d8c573788f1c7fa9b1de2099f32c2510647081042888083daa942886295bda673c216adc97
6
+ metadata.gz: d21582fab1a3105f8e9cb169766b02e574f216608182f3476664665ef80af766c96185b938012e228a0da4f88ae7ead744cfcd56a77c02cd9853ae4f0a08f294
7
+ data.tar.gz: 8ebc39817d2a380fc81401a021dda7225e7771000697682670ebc7cee7c9ddc4b061384b12e20511b299fde8fc4e2be3f5c42936e4cfe8ba3f3e8299d37db3c4
data/History.md CHANGED
@@ -1,6 +1,10 @@
1
+ # 0.0.8 of 2017.04.17
2
+
3
+ * Wait (possibly several times) when we hit the rate limiter of the bitfinex REST API while fetching the currency rates
4
+
1
5
  # 0.0.7 of 2017.04.17
2
6
 
3
- * Wait (possibly several times) when we hit the rate limiter of the bitfinex REST API
7
+ * Wait (possibly several times) when we hit the rate limiter of the bitfinex REST API while fetching the histor
4
8
 
5
9
  # 0.0.6 of 2017.04.11
6
10
 
@@ -9,6 +9,7 @@ module RAPFLAG
9
9
  class Bitfinex < History
10
10
  @@btc_to_usd = {}
11
11
  @@bfx_to_usd = {}
12
+ Delay_in_seconds = 30
12
13
 
13
14
  def get_usd_exchange(date_time = Time.now, from='BTC')
14
15
  return 1.0 if from == 'USD'
@@ -20,18 +21,22 @@ module RAPFLAG
20
21
  ms_next_date = ms + (3*24*3600)*1000
21
22
  # this does not work
22
23
  # url = "https://api.bitfinex.com/v2/candles/trade:1D:t#{from}USD/hist?start:#{ms}?end:#{ms_next_date}"
23
- url = "https://api.bitfinex.com/v2/candles/trade:1D:t#{from}USD/hist?start:#{ms}?end:#{ms_next_date}"
24
24
  # therefore we just return the most uptodate
25
25
  url = "https://api.bitfinex.com/v2/candles/trade:1D:t#{from}USD/hist?start:#{ms}"
26
- puts "Fetching #{date_time}: #{url} #{@@btc_to_usd.size} BTC #{@@bfx_to_usd.size} BFX" if $VERBOSE
27
- response = Faraday.get(url)
28
- items = eval(response.body)
29
26
  rates = {}
30
- items.each do |item|
31
- if item.first.eql?(:error)
32
- puts "Fetching returned #{item}. Aborting"
33
- exit(1)
27
+ while true
28
+ puts "Fetching #{date_time}: #{url} #{@@btc_to_usd.size} BTC #{@@bfx_to_usd.size} BFX" if $VERBOSE
29
+ response = Faraday.get(url)
30
+ items = eval(response.body)
31
+ if items && items.size > 0 && items.first.first.eql?(:error)
32
+ puts "#{Time.now}: Fetching #{url} returned #{items.first}."
33
+ puts " Retrying in #{Delay_in_seconds} seconds"
34
+ sleep(Delay_in_seconds)
35
+ else
36
+ break
34
37
  end
38
+ end
39
+ items.each do |item|
35
40
  # http://docs.bitfinex.com/v2/reference#rest-public-candles
36
41
  # field definitions for [ MTS, OPEN, CLOSE, HIGH, LOW, VOLUME ],
37
42
  # MTS int millisecond time stamp
@@ -46,13 +51,14 @@ module RAPFLAG
46
51
  end;
47
52
  from.eql?('BTC') ? @@btc_to_usd = rates.clone : @@bfx_to_usd = rates.clone
48
53
  rates[key] ? rates[key] : nil
49
- rescue => err
50
- puts "Err #{err}"
54
+ rescue => error
55
+ puts "error #{error}"
56
+ puts " backtrace: #{error.backtrace[0..10].join("\n")}"
57
+ require 'pry'; binding.pry
51
58
  end
52
59
 
53
60
  def fetch_csv_history
54
61
  @history = []
55
- delay_in_seconds = 30
56
62
  check_config
57
63
  client = ::Bitfinex::Client.new
58
64
  timestamp = Time.now.to_i + 1
@@ -63,8 +69,8 @@ module RAPFLAG
63
69
  partial = client.history(@currency, { :limit => 1000, :until => timestamp, :wallet => @wallet})
64
70
  if partial.is_a?(Hash) && (partial.size > 0) && partial['error'].eql?('ERR_RATE_LIMIT')
65
71
  puts "Got #{partial['error']} while fetching #{@wallet} #{@currency} #{client.history} items"
66
- puts " Will wait #{delay_in_seconds} seconds before retrying"
67
- sleep(delay_in_seconds)
72
+ puts " Will wait #{Delay_in_seconds} seconds before retrying"
73
+ sleep(Delay_in_seconds)
68
74
  end
69
75
  break if partial && partial.is_a?(Array)
70
76
  end
@@ -1,4 +1,4 @@
1
1
  module RAPFLAG
2
2
  Wallets = ['trading', 'exchange', 'deposit']
3
- VERSION='0.0.7'
3
+ VERSION='0.0.8'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapflag
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
  - Zeno R.R. Davatz, Niklaus Giger