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 +4 -4
- data/History.md +5 -1
- data/lib/rapflag/bitfinex.rb +19 -13
- data/lib/rapflag/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49743ea60e2bd47dfbdf5ad864c4b7119ba0e7d0
|
4
|
+
data.tar.gz: fd4883603a73ad3512d1ee771d22852aa77b3262
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/rapflag/bitfinex.rb
CHANGED
@@ -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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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 =>
|
50
|
-
puts "
|
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 #{
|
67
|
-
sleep(
|
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
|
data/lib/rapflag/version.rb
CHANGED