cns 2.1.6 → 2.1.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/Gemfile.lock +1 -1
- data/lib/cns/apice.rb +14 -10
- data/lib/cns/bitcoinde.rb +2 -2
- data/lib/cns/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8c3291d5689453fc6b8055d59f4468b00b8f1d65244d98d9a1e2e0f7397c6c6
|
|
4
|
+
data.tar.gz: e6feab9a8d9da05c236ed46f9e6d019d002812ce9d000a2765549dcb56bb433f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cff4090062ae367a6df696863a5d6db89cd5f67d2c01d374793013ff890e9ee4aad9195142b3233e672626148bd208051b873aaf0934aea8800cead3c99c3536
|
|
7
|
+
data.tar.gz: 2e2c356ad94b02e6ca2ae0c1fe16e2c79221e0bcb0ccb7ce0597842cd4f3503caa798a162ac3553c2e2d69054f6e60202f4fc64e04268da042796c996bedabee
|
data/Gemfile.lock
CHANGED
data/lib/cns/apice.rb
CHANGED
|
@@ -40,7 +40,8 @@ module Cns
|
|
|
40
40
|
# @return [Array<Hash>] trades bitcoinde
|
|
41
41
|
def trades_de(tsp = nil)
|
|
42
42
|
prm = {state: 1}
|
|
43
|
-
|
|
43
|
+
# Bitcoin.de API needs round UTC Time down to nearest 15-minute mark (00,15,30,45) and format as RFC 3339 with +00:00
|
|
44
|
+
prm[:date_start] = Time.at(tsp).utc.then { |t| Time.utc(t.year, t.month, t.day, t.hour, 0, 0).strftime('%Y-%m-%dT%H:%M:%S+00:00') } if tsp
|
|
44
45
|
pag_de_req("#{API[:de]}/trades", prm, :trades)
|
|
45
46
|
rescue Curl::Err::CurlError
|
|
46
47
|
[]
|
|
@@ -49,10 +50,8 @@ module Cns
|
|
|
49
50
|
# Get deposits from Bitcoin.de, uniformly formatted
|
|
50
51
|
# @param [Integer] tsp optional unix timestamp (seconds) to fetch deposits from (start date on bitcoin.de API)
|
|
51
52
|
# @return [Array<Hash>] depositos uniformizados bitcoinde
|
|
52
|
-
def deposits_de
|
|
53
|
-
|
|
54
|
-
prm[:date_start] = Time.at(tsp).utc.iso8601 if tsp
|
|
55
|
-
pag_de_req("#{API[:de]}/btc/deposits", prm, :deposits) { |i| i.map { |h| deposit_unif(h) } }
|
|
53
|
+
def deposits_de
|
|
54
|
+
pag_de_req("#{API[:de]}/btc/deposits", {}, :deposits) { |i| i.map { |h| deposit_unif(h) } }
|
|
56
55
|
rescue Curl::Err::CurlError
|
|
57
56
|
[]
|
|
58
57
|
end
|
|
@@ -60,10 +59,8 @@ module Cns
|
|
|
60
59
|
# Get withdrawals from Bitcoin.de, uniformly formatted
|
|
61
60
|
# @param [Integer] tsp optional unix timestamp (seconds) to fetch withdrawals from (start date on bitcoin.de API)
|
|
62
61
|
# @return [Array<Hash>] withdrawals uniformizadas bitcoinde
|
|
63
|
-
def withdrawals_de
|
|
64
|
-
|
|
65
|
-
prm[:date_start] = Time.at(tsp).utc.iso8601 if tsp
|
|
66
|
-
pag_de_req("#{API[:de]}/btc/withdrawals", prm, :withdrawals) { |i| i.map { |h| withdrawal_unif(h) } }
|
|
62
|
+
def withdrawals_de
|
|
63
|
+
pag_de_req("#{API[:de]}/btc/withdrawals", {}, :withdrawals) { |i| i.map { |h| withdrawal_unif(h) } }
|
|
67
64
|
rescue Curl::Err::CurlError
|
|
68
65
|
[]
|
|
69
66
|
end
|
|
@@ -152,10 +149,17 @@ module Cns
|
|
|
152
149
|
loop do
|
|
153
150
|
url = "#{uri}?#{URI.encode_www_form(prm.merge(page: pag))}"
|
|
154
151
|
rcrl(@curl, url, headers: hde(url))
|
|
152
|
+
# Check HTTP status
|
|
153
|
+
unless @curl.response_code == 200
|
|
154
|
+
puts("Bitcoin.de API returned non-200 status: #{@curl.response_code} for #{url}")
|
|
155
|
+
break
|
|
156
|
+
end
|
|
155
157
|
res = pjsn(@curl)
|
|
156
158
|
bth = res.fetch(key, [])
|
|
157
159
|
ary.concat(block_given? ? yield(bth) : bth)
|
|
158
|
-
|
|
160
|
+
current = res.dig(:page, :current) || 1
|
|
161
|
+
last = res.dig(:page, :last) || 1
|
|
162
|
+
break if current >= last || bth.empty?
|
|
159
163
|
|
|
160
164
|
pag += 1
|
|
161
165
|
end
|
data/lib/cns/bitcoinde.rb
CHANGED
|
@@ -43,7 +43,7 @@ module Cns
|
|
|
43
43
|
vtt, vnt = exd[:tt].count, bqd[:nt].count
|
|
44
44
|
vtl, vnl = exd[:tl].count, bqd[:nl].count
|
|
45
45
|
|
|
46
|
-
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vtt, b: vnt, o: vtt == vnt ? 'OK' : 'NOK')}")
|
|
46
|
+
puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vtt, b: vnt, o: vtt == vnt ? 'OK' : 'NOK')}") if vtt.positive?
|
|
47
47
|
puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vtl, d: vnl, o: vtl == vnl ? 'OK' : 'NOK')}")
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -161,7 +161,7 @@ module Cns
|
|
|
161
161
|
memoize def exd
|
|
162
162
|
# unix timestamp para obter transacoes 24x60x60 = 86400 segundos
|
|
163
163
|
tsp = ops&.[](:d)&.positive? ? Integer(Time.now - (ops[:d] * 86_400)) : nil
|
|
164
|
-
{sl: pdea(api.account_de), tt: pdet(api.trades_de(tsp)), tl: pdel(api.deposits_de
|
|
164
|
+
{sl: pdea(api.account_de), tt: pdet(api.trades_de(tsp)), tl: pdel(api.deposits_de + api.withdrawals_de)}
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
# @return [Array<String>] indices trades bigquery
|
data/lib/cns/version.rb
CHANGED