cns 0.9.5 → 0.9.7
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/apibc.rb +11 -8
- data/lib/cns/apice.rb +13 -7
- data/lib/cns/bigquery.rb +4 -7
- data/lib/cns/bitcoinde.rb +7 -3
- data/lib/cns/etherscan.rb +20 -14
- data/lib/cns/greymass.rb +16 -20
- data/lib/cns/kraken.rb +16 -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: 809b82040355c90e5e2b99a47e643a9d2cd347a03469a0a34c738607d72d4e36
|
4
|
+
data.tar.gz: caa74260e481ce81ad556e36828e1eeb30021eb3e20e4b41c02d266986a99727
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d46323b0b8b4970f5a67fe77530f396d1aa86fd09fb1b09a9f67e09f17198152599311c557ca71b96cfe2d290d18f43fead30d6317f44a8e059a9b5b85700e
|
7
|
+
data.tar.gz: 345f0ba90f40769b5a02099d307d5e1a0dfd03e3ff6c4642854c7999fe63b4a222462fab1e0f096dc0a6b46616d970ea20c0527d269f31c24c635ddfcb1d9d09
|
data/Gemfile.lock
CHANGED
data/lib/cns/apibc.rb
CHANGED
@@ -20,6 +20,8 @@ module Cns
|
|
20
20
|
# @param [Array<String>] addresses List of ETH addresses (max 20)
|
21
21
|
# @return [Array<Hash>] List of addresses with balances
|
22
22
|
def account_es(addresses)
|
23
|
+
return [] if addresses.empty?
|
24
|
+
|
23
25
|
res = es_req('balancemulti', addresses.join(','), 1, tag: 'latest')
|
24
26
|
res[:status] == '1' ? res[:result] || [] : []
|
25
27
|
end
|
@@ -93,8 +95,7 @@ module Cns
|
|
93
95
|
# @param [Hash] prm Additional request parameters
|
94
96
|
# @return [Hash] Parsed API response
|
95
97
|
def es_req(act, add, pag = 1, prm = {})
|
96
|
-
prm
|
97
|
-
parse_json(@escn.get('/api', prm))
|
98
|
+
parse_json(@escn.get('/api', prm.merge(module: 'account', action: act, address: add, page: pag, apikey: @esky)))
|
98
99
|
rescue Faraday::Error
|
99
100
|
{status: '0'}
|
100
101
|
end
|
@@ -141,6 +142,8 @@ module Cns
|
|
141
142
|
# @param [Faraday::Response] res API response
|
142
143
|
# @return [Hash] Parsed JSON or empty hash on error
|
143
144
|
def parse_json(res)
|
145
|
+
return {} if res.body.to_s.empty?
|
146
|
+
|
144
147
|
JSON.parse(res.body, symbolize_names: true) || {}
|
145
148
|
rescue JSON::ParserError
|
146
149
|
{}
|
@@ -150,12 +153,12 @@ module Cns
|
|
150
153
|
# @param [String] url Base URL for the API
|
151
154
|
# @return [Faraday::Connection] Configured Faraday connection
|
152
155
|
def connection(url)
|
153
|
-
Faraday.new(url) do |
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
156
|
+
Faraday.new(url) do |c|
|
157
|
+
c.request(:json)
|
158
|
+
c.headers = {accept: 'application/json', user_agent: 'blockchain-api-client'}
|
159
|
+
c.options.timeout = 30
|
160
|
+
c.options.open_timeout = 10
|
161
|
+
c.adapter(Faraday.default_adapter)
|
159
162
|
end
|
160
163
|
end
|
161
164
|
end
|
data/lib/cns/apice.rb
CHANGED
@@ -91,10 +91,10 @@ module Cns
|
|
91
91
|
# @param [Hash] trx transacao
|
92
92
|
# @return [Hash] transacao uniformizada
|
93
93
|
def us_unif(key, trx)
|
94
|
-
t =
|
94
|
+
t = trx[:time].to_i
|
95
95
|
trx.merge(txid: key.to_s, srx: t, time: Time.at(t))
|
96
|
-
rescue
|
97
|
-
|
96
|
+
rescue ArgumentError
|
97
|
+
trx.merge(txid: key.to_s, srx: 0, time: Time.at(0))
|
98
98
|
end
|
99
99
|
|
100
100
|
# Generic paginated request handler for Kraken
|
@@ -106,7 +106,8 @@ module Cns
|
|
106
106
|
ary = []
|
107
107
|
ofs = 0
|
108
108
|
loop do
|
109
|
-
|
109
|
+
# Rate limiting for page requests (2s in Kraken)
|
110
|
+
sleep(@lpag - Time.now + 2) if @lpag && Time.now - @lpag < 2
|
110
111
|
ops = {nonce: nnc, ofs: ofs}
|
111
112
|
run_curl(@curl, "#{API[:us]}/#{uri}", method: 'POST', post_data: ops, headers: hus(uri, ops))
|
112
113
|
bth = parse_json(@curl).fetch(:result, {}).fetch(key, []).map { |k, v| us_unif(k, v) }
|
@@ -114,6 +115,7 @@ module Cns
|
|
114
115
|
|
115
116
|
ary.concat(bth)
|
116
117
|
ofs += bth.size
|
118
|
+
@lpag = Time.now
|
117
119
|
end
|
118
120
|
ary
|
119
121
|
end
|
@@ -167,14 +169,14 @@ module Cns
|
|
167
169
|
# Generate a continually-increasing unsigned integer nonce from the current Unix Time
|
168
170
|
# @return [Integer] Nonce value
|
169
171
|
def nnc
|
170
|
-
|
172
|
+
Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond).to_i
|
171
173
|
end
|
172
174
|
|
173
175
|
# Uniformly format a deposit from Bitcoin.de
|
174
176
|
# @param [Hash] has Deposit data from Bitcoin.de
|
175
177
|
# @return [Hash] deposito uniformizado bitcoinde
|
176
178
|
def deposit_unif(has)
|
177
|
-
{add: has[:address], time: Time.parse(has[:created_at]), qtd: has[:amount].to_d, nxid:
|
179
|
+
{add: has[:address], time: Time.parse(has[:created_at]), qtd: has[:amount].to_d, nxid: has[:deposit_id].to_i}.merge(tp: 'deposit', moe: 'BTC', fee: 0.to_d)
|
178
180
|
end
|
179
181
|
|
180
182
|
# Uniformly format a withdrawal from Bitcoin.de
|
@@ -186,7 +188,7 @@ module Cns
|
|
186
188
|
time: Time.parse(has[:transferred_at]),
|
187
189
|
qtd: -1 * has[:amount].to_d,
|
188
190
|
fee: has[:network_fee].to_d,
|
189
|
-
nxid:
|
191
|
+
nxid: has[:withdrawal_id].to_i,
|
190
192
|
tp: 'withdrawal',
|
191
193
|
moe: 'BTC'
|
192
194
|
}
|
@@ -200,6 +202,8 @@ module Cns
|
|
200
202
|
md5 = ['GET', qde, @deky, non, Digest::MD5.hexdigest('')].join('#')
|
201
203
|
mac = OpenSSL::HMAC.hexdigest('sha256', @desc, md5)
|
202
204
|
{'X-API-KEY' => @deky, 'X-API-NONCE' => non.to_s, 'X-API-SIGNATURE' => mac}
|
205
|
+
rescue OpenSSL::HMACError => e
|
206
|
+
raise("HMAC generation failed: #{e.message}")
|
203
207
|
end
|
204
208
|
|
205
209
|
# Generate headers for Kraken HTTP requests
|
@@ -211,6 +215,8 @@ module Cns
|
|
211
215
|
sha = ['/0/private/', qus, Digest::SHA256.digest("#{ops[:nonce]}#{URI.encode_www_form(ops)}")].join
|
212
216
|
mac = OpenSSL::HMAC.digest('sha512', Base64.decode64(@ussc), sha)
|
213
217
|
{'api-key' => @usky, 'api-sign' => Base64.strict_encode64(mac)}
|
218
|
+
rescue OpenSSL::HMACError => e
|
219
|
+
raise("HMAC generation failed: #{e.message}")
|
214
220
|
end
|
215
221
|
end
|
216
222
|
end
|
data/lib/cns/bigquery.rb
CHANGED
@@ -29,7 +29,7 @@ module Cns
|
|
29
29
|
hust: %i[txid ordertxid pair time type ordertype price cost fee vol margin misc ledgers],
|
30
30
|
cusl: %w[txid refid time type aclass asset amount fee],
|
31
31
|
husl: %i[txid refid time type aclass asset amount fee]
|
32
|
-
}
|
32
|
+
}.freeze
|
33
33
|
# para testes bigquery
|
34
34
|
TL = {
|
35
35
|
ins: 'INSERT',
|
@@ -37,15 +37,14 @@ module Cns
|
|
37
37
|
est: '', # ' limit 226',
|
38
38
|
esi: '', # ' limit 22',
|
39
39
|
esp: '', # ' limit 72',
|
40
|
-
esw: '', # ' limit
|
40
|
+
esw: '', # ' limit 2320',
|
41
41
|
esk: '', # ' limit 20',
|
42
42
|
gmt: '', # ' limit 1091',
|
43
43
|
ust: '', # ' limit 182',
|
44
44
|
usl: '', # ' limit 448',
|
45
45
|
det: '', # ' limit 27',
|
46
46
|
del: '' # ' limit 16'
|
47
|
-
|
48
|
-
}
|
47
|
+
}.freeze
|
49
48
|
|
50
49
|
# classe para processar bigquery
|
51
50
|
class Bigquery
|
@@ -254,9 +253,7 @@ module Cns
|
|
254
253
|
|
255
254
|
# @return [String] SQL integer formatting
|
256
255
|
def fin(value)
|
257
|
-
|
258
|
-
rescue StandardError
|
259
|
-
'0'
|
256
|
+
value.to_i.to_s
|
260
257
|
end
|
261
258
|
|
262
259
|
# @return [String] SQL timestamp formatting
|
data/lib/cns/bitcoinde.rb
CHANGED
@@ -16,9 +16,7 @@ module Cns
|
|
16
16
|
# @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
|
17
17
|
# @option pop [Boolean] :v (false) mostra dados transacoes trades & ledger?
|
18
18
|
# @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
|
19
|
-
# @return [Bitcoinde] API bitcoinde - obter saldos & transacoes trades e ledger
|
20
19
|
def initialize(dad, pop)
|
21
|
-
@api = Apice.new
|
22
20
|
@bqd = dad
|
23
21
|
@ops = pop.transform_keys(&:to_sym)
|
24
22
|
end
|
@@ -130,7 +128,7 @@ module Cns
|
|
130
128
|
# @return [Hash] transaccao filtrada
|
131
129
|
def pdes(key, itm)
|
132
130
|
tym = ptm(itm[key])
|
133
|
-
itm.merge(srx:
|
131
|
+
itm.merge(srx: tym.to_i, key => tym)
|
134
132
|
end
|
135
133
|
|
136
134
|
# @param [Array<Hash>] htx trade bitcoinde
|
@@ -153,6 +151,12 @@ module Cns
|
|
153
151
|
hlx.map { |t| pdes(:time, t) }
|
154
152
|
end
|
155
153
|
|
154
|
+
# Lazy Bitcoinde API Initialization
|
155
|
+
# @return [Bitcoinde] API - obter saldos & transacoes trades e ledger
|
156
|
+
def api
|
157
|
+
@api ||= Apice.new
|
158
|
+
end
|
159
|
+
|
156
160
|
# @return [Hash] dados exchange bitcoinde - saldos & trades & deposits & withdrawals
|
157
161
|
def ded
|
158
162
|
@ded ||= {sl: pdea(api.account_de), tt: pdet(api.trades_de), tl: pdel(api.deposits_de + api.withdrawals_de)}
|
data/lib/cns/etherscan.rb
CHANGED
@@ -18,44 +18,42 @@ module Cns
|
|
18
18
|
header: "\ntx normal from to data valor",
|
19
19
|
sork: :srx,
|
20
20
|
adjk: :hash
|
21
|
-
},
|
21
|
+
}.freeze,
|
22
22
|
internal: {
|
23
23
|
new: :novnethi,
|
24
24
|
format: :foti,
|
25
25
|
header: "\ntx intern from to data valor",
|
26
26
|
sork: :srx,
|
27
27
|
adjk: :hash
|
28
|
-
},
|
28
|
+
}.freeze,
|
29
29
|
block: {
|
30
30
|
new: :novnethp,
|
31
31
|
format: :fop,
|
32
32
|
header: "\ntx block address data valor",
|
33
33
|
sork: :itx,
|
34
34
|
adjk: :blockNumber
|
35
|
-
},
|
35
|
+
}.freeze,
|
36
36
|
token: {
|
37
37
|
new: :novnethk,
|
38
38
|
format: :fok,
|
39
39
|
header: "\ntx token from to data valor moeda",
|
40
40
|
sork: :srx,
|
41
41
|
adjk: :hash
|
42
|
-
},
|
42
|
+
}.freeze,
|
43
43
|
withdrawal: {
|
44
44
|
new: :novnethw,
|
45
45
|
format: :fow,
|
46
46
|
header: "\nwithdrawal validator data valor",
|
47
47
|
sork: :itx,
|
48
48
|
adjk: :withdrawalIndex
|
49
|
-
}
|
50
|
-
}
|
49
|
+
}.freeze
|
50
|
+
}.freeze
|
51
51
|
|
52
52
|
# @param [Hash] dad todos os dados bigquery
|
53
53
|
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
|
54
54
|
# @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
|
55
55
|
# @option pop [Boolean] :v (false) mostra dados transacoes
|
56
|
-
# @return [Etherscan] API etherscan - processar transacoes
|
57
56
|
def initialize(dad, pop)
|
58
|
-
@api = Apibc.new
|
59
57
|
@bqd = dad
|
60
58
|
@ops = pop.transform_keys(&:to_sym)
|
61
59
|
end
|
@@ -166,7 +164,7 @@ module Cns
|
|
166
164
|
return 'erro' if max < 7
|
167
165
|
|
168
166
|
max -= 2
|
169
|
-
ini =
|
167
|
+
ini = (max / 2).to_i + 4
|
170
168
|
inf = max % 2
|
171
169
|
"#{add[0, ini - 3]}..#{add[-inf - ini + 5..]}"
|
172
170
|
end
|
@@ -180,7 +178,7 @@ module Cns
|
|
180
178
|
return 'erro' if max < 7
|
181
179
|
|
182
180
|
max -= 2
|
183
|
-
ini =
|
181
|
+
ini = (max / 2).to_i
|
184
182
|
inf = max % 2
|
185
183
|
hid = bqd[:wb].find { |o| o[:ax] == add }
|
186
184
|
ndd = hid ? "#{hid[:id]}-#{add}" : add
|
@@ -234,29 +232,31 @@ module Cns
|
|
234
232
|
# @param [Hash] htx transacao
|
235
233
|
# @return [Hash] transaccao filtrada
|
236
234
|
def pess(htx)
|
237
|
-
tym =
|
235
|
+
tym = htx[:timeStamp].to_i
|
238
236
|
htx.merge(srx: tym, timeStamp: Time.at(tym))
|
237
|
+
rescue ArgumentError
|
238
|
+
htx.merge(srx: 0, timeStamp: Time.at(0))
|
239
239
|
end
|
240
240
|
|
241
241
|
# @param add (see foe1)
|
242
242
|
# @param [Array<Hash>] ary lista transacoes normal(t)/(i)nternal/to(k)en
|
243
243
|
# @return [Array<Hash>] lista transacoes filtrada
|
244
244
|
def ftik(add, ary)
|
245
|
-
ary.map { |o| pess(o).merge(itx:
|
245
|
+
ary.map { |o| pess(o).merge(itx: o[:hash].to_s, iax: add, value: o[:value].to_d) }
|
246
246
|
end
|
247
247
|
|
248
248
|
# @param add (see foe1)
|
249
249
|
# @param [Array<Hash>] ary lista transacoes (p)roduced blocks
|
250
250
|
# @return [Array<Hash>] lista transacoes filtrada
|
251
251
|
def fppp(add, ary)
|
252
|
-
ary.map { |o| o.merge(itx:
|
252
|
+
ary.map { |o| o.merge(itx: o[:blockNumber].to_i, iax: add, blockReward: o[:blockReward].to_d, timeStamp: Time.at(o[:timeStamp].to_i)) }
|
253
253
|
end
|
254
254
|
|
255
255
|
# @param add (see foe1)
|
256
256
|
# @param [Array<Hash>] ary lista transacoes (w)ithdrawals
|
257
257
|
# @return [Array<Hash>] lista transacoes filtrada
|
258
258
|
def fwww(add, ary)
|
259
|
-
ary.map { |o| o.merge(itx:
|
259
|
+
ary.map { |o| o.merge(itx: o[:withdrawalIndex].to_i, iax: add, amount: o[:amount].to_d, timeStamp: Time.at(o[:timestamp].to_i)) }
|
260
260
|
end
|
261
261
|
|
262
262
|
# @param [Hash] aes account etherscan
|
@@ -297,6 +297,12 @@ module Cns
|
|
297
297
|
}
|
298
298
|
end
|
299
299
|
|
300
|
+
# Lazy Etherscan API Initialization
|
301
|
+
# @return [Etherscan] API - processar transacoes
|
302
|
+
def api
|
303
|
+
@api ||= Apibc.new
|
304
|
+
end
|
305
|
+
|
300
306
|
# @return [Array<String>] lista enderecos
|
301
307
|
def lax
|
302
308
|
@lax ||= bqd[:wb].map { |o| o[:ax] }
|
data/lib/cns/greymass.rb
CHANGED
@@ -11,22 +11,14 @@ module Cns
|
|
11
11
|
# @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
|
12
12
|
attr_reader :api, :bqd, :ops
|
13
13
|
|
14
|
-
TT = {
|
15
|
-
new: :novneost,
|
16
|
-
format: :fol,
|
17
|
-
header: "\nsequence num from to accao data valor moeda",
|
18
|
-
sork: :itx,
|
19
|
-
adjk: :itx
|
20
|
-
}
|
14
|
+
TT = {sork: :itx, adjk: :itx}.freeze
|
21
15
|
|
22
16
|
# @param [Hash] dad todos os dados bigquery
|
23
17
|
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
|
24
18
|
# @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
|
25
19
|
# @option pop [Boolean] :v (false) mostra dados transacoes?
|
26
20
|
# @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
|
27
|
-
# @return [Greymass] API greymass - processar transacoes
|
28
21
|
def initialize(dad, pop)
|
29
|
-
@api = Apibc.new
|
30
22
|
@bqd = dad
|
31
23
|
@ops = pop.transform_keys(&:to_sym)
|
32
24
|
end
|
@@ -45,19 +37,17 @@ module Cns
|
|
45
37
|
|
46
38
|
# mosta transacoes novas
|
47
39
|
def mtransacoes_novas
|
48
|
-
|
49
|
-
return unless ops[:v] && ntx.any?
|
40
|
+
return unless ops[:v] && novneost.any?
|
50
41
|
|
51
|
-
puts(
|
52
|
-
|
42
|
+
puts("\nsequence num from to accao data valor moeda")
|
43
|
+
novneost.sort_by { |s| -s[TT[:sork]] }.each { |t| puts(fol(t)) }
|
53
44
|
end
|
54
45
|
|
55
46
|
# mostra configuration text for adjusting days
|
56
47
|
def mconfiguracao_ajuste_dias
|
57
|
-
|
58
|
-
return unless ntx.any?
|
48
|
+
return unless novneost.any?
|
59
49
|
|
60
|
-
puts("\nstring ajuste dias\n-h=#{
|
50
|
+
puts("\nstring ajuste dias\n-h=#{novneost.sort_by { |s| -s[TT[:sork]] }.map { |t| "#{t[TT[:adjk]]}:0" }.join(' ')}")
|
61
51
|
end
|
62
52
|
|
63
53
|
# @param [Hash] hjn dados juntos bigquery & greymass
|
@@ -77,7 +67,7 @@ module Cns
|
|
77
67
|
# @param (see foct)
|
78
68
|
# @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
|
79
69
|
def ok?(hjn)
|
80
|
-
hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count
|
70
|
+
hjn[:bs].round(6) == hjn[:es].round(6) && hjn[:bt].count == hjn[:et].count
|
81
71
|
end
|
82
72
|
|
83
73
|
# @param [Hash] hlx ledger greymass
|
@@ -104,8 +94,8 @@ module Cns
|
|
104
94
|
# @return [Array<BigDecimal>] lista recursos - liquido, net, spu
|
105
95
|
def peosa(add)
|
106
96
|
hac = api.account_gm(add)
|
107
|
-
htr = hac
|
108
|
-
[hac[:core_liquid_balance].to_d, htr[:net_weight].to_d, htr[:cpu_weight].to_d]
|
97
|
+
htr = hac.fetch(:total_resources, {})
|
98
|
+
[hac[:core_liquid_balance]&.to_d || 0.to_d, htr[:net_weight]&.to_d || 0.to_d, htr[:cpu_weight]&.to_d || 0.to_d]
|
109
99
|
end
|
110
100
|
|
111
101
|
# @param add (see peosa)
|
@@ -122,7 +112,7 @@ module Cns
|
|
122
112
|
quantity: qtd.to_d,
|
123
113
|
account: act[:account],
|
124
114
|
to: adt[:to],
|
125
|
-
memo:
|
115
|
+
memo: adt[:memo].to_s.gsub(/\p{C}/, ''), # remove Non-Printable Characters
|
126
116
|
moe: qtd[/[[:upper:]]+/],
|
127
117
|
itx: t[:global_action_seq],
|
128
118
|
iax: add,
|
@@ -153,6 +143,12 @@ module Cns
|
|
153
143
|
}
|
154
144
|
end
|
155
145
|
|
146
|
+
# Lazy Greymass API Initialization
|
147
|
+
# @return [Greymass] API - processar transacoes
|
148
|
+
def api
|
149
|
+
@api ||= Apibc.new
|
150
|
+
end
|
151
|
+
|
156
152
|
# @return [Array<Hash>] todos os dados greymass - saldos & transacoes
|
157
153
|
def gmd
|
158
154
|
@gmd ||= bqd[:wb].map { |o| bsgm(o) }
|
data/lib/cns/kraken.rb
CHANGED
@@ -16,9 +16,7 @@ module Cns
|
|
16
16
|
# @option pop [Hash] :h ({}) configuracao dias ajuste reposicionamento temporal
|
17
17
|
# @option pop [Boolean] :v (false) mostra dados transacoes trades & ledger?
|
18
18
|
# @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
|
19
|
-
# @return [Kraken] API kraken - obter saldos & transacoes trades e ledger
|
20
19
|
def initialize(dad, pop)
|
21
|
-
@api = Apice.new
|
22
20
|
@bqd = dad
|
23
21
|
@ops = pop.transform_keys(&:to_sym)
|
24
22
|
end
|
@@ -136,6 +134,22 @@ module Cns
|
|
136
134
|
hlx.map { |t| t.merge(asset: t[:asset].upcase, amount: t[:amount].to_d, fee: t[:fee].to_d) }
|
137
135
|
end
|
138
136
|
|
137
|
+
# Lazy kraken API Initialization decorated with rate limiting logic
|
138
|
+
# @return [Kraken] API - obter saldos & transacoes trades e ledger
|
139
|
+
def api
|
140
|
+
@api ||=
|
141
|
+
begin
|
142
|
+
t = Apice.new
|
143
|
+
# Rate limiting to this specific instance (0.5s in Kraken)
|
144
|
+
t.define_singleton_method(:run_curl) do |curl, url, **options|
|
145
|
+
sleep(@lapi - Time.now + 0.5) if @lapi && Time.now - @lapi < 0.5
|
146
|
+
super(curl, url, **options)
|
147
|
+
@lapi = Time.now
|
148
|
+
end
|
149
|
+
t
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
139
153
|
# @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
|
140
154
|
def usd
|
141
155
|
@usd ||= {sl: pusa(api.account_us), kt: pust(api.trades_us), kl: pusl(api.ledger_us)}
|
data/lib/cns/version.rb
CHANGED