cns 0.1.5 → 0.2.2
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/.reek.yml +74 -0
- data/.rubocop.yml +4 -3
- data/Gemfile.lock +30 -20
- data/cns.gemspec +1 -0
- data/lib/cns.rb +2 -0
- data/lib/cns/apibc.rb +55 -48
- data/lib/cns/apice1.rb +22 -72
- data/lib/cns/apice2.rb +82 -39
- data/lib/cns/beaconchain1.rb +102 -0
- data/lib/cns/beaconchain2.rb +90 -0
- data/lib/cns/bigquery1.rb +28 -23
- data/lib/cns/bigquery2.rb +23 -0
- data/lib/cns/bigquery3.rb +109 -47
- data/lib/cns/bigquery4.rb +53 -52
- data/lib/cns/bitcoinde.rb +21 -20
- data/lib/cns/etherscan1.rb +21 -19
- data/lib/cns/etherscan2.rb +7 -7
- data/lib/cns/greymass1.rb +23 -18
- data/lib/cns/greymass2.rb +8 -26
- data/lib/cns/kraken.rb +21 -20
- data/lib/cns/paymium.rb +15 -15
- data/lib/cns/therock.rb +16 -15
- data/lib/cns/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a1cf9704e8ec6d00b5c85e0af4b8a55ab5358fbc650d37471bfe9201caf6dbf
|
4
|
+
data.tar.gz: 0136a2129eabca46d1b6d23798e628f1e1c5c034e81d35fc350e0545aff14b6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '05993d0c2cd1830d7e7e28f4a24dac4b0489b3fcdeabdc49f02e3be3f5b0bb76617f08f5c35973683361365371efd6ed04a38ba8667e65bdb4b1ce9f9c84bed4'
|
7
|
+
data.tar.gz: 5d58eff9b68fab68f14c689700934c6bf47c728acdf03399b3a829e7ff860a30b105379d89af6cfb9a62140abc8b35d7506a1b411a1f9b637f589bed090f1bec
|
data/.reek.yml
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
---
|
2
|
+
detectors:
|
3
|
+
TooManyStatements:
|
4
|
+
exclude:
|
5
|
+
- initialize
|
6
|
+
max_statements: 10
|
7
|
+
RepeatedConditional:
|
8
|
+
exclude:
|
9
|
+
- "Cns::Apice"
|
10
|
+
FeatureEnvy:
|
11
|
+
exclude:
|
12
|
+
- "Cns::Apice#deposit_unif"
|
13
|
+
- "Cns::Apice#withdrawal_unif"
|
14
|
+
- "Cns::Bigquery#etht_1val"
|
15
|
+
- "Cns::Bigquery#etht_2val"
|
16
|
+
- "Cns::Bigquery#etht_3val"
|
17
|
+
- "Cns::Bigquery#ethk_1val"
|
18
|
+
- "Cns::Bigquery#ethk_2val"
|
19
|
+
- "Cns::Bigquery#ethk_3val"
|
20
|
+
- "Cns::Bigquery#eost_1val"
|
21
|
+
- "Cns::Bigquery#eost_2val"
|
22
|
+
- "Cns::Bigquery#det_1val"
|
23
|
+
- "Cns::Bigquery#det_2val"
|
24
|
+
- "Cns::Bigquery#mtl_1val"
|
25
|
+
- "Cns::Bigquery#ust_1val"
|
26
|
+
- "Cns::Bigquery#frl_val"
|
27
|
+
- "Cns::Bigquery#usl_val"
|
28
|
+
- "Cns::Bitcoinde#formata_ledger"
|
29
|
+
- "Cns::Bitcoinde#formata_trades"
|
30
|
+
- "Cns::Etherscan#bq_bc"
|
31
|
+
- "Cns::Etherscan#formata_valores"
|
32
|
+
- "Cns::Etherscan#formata_endereco"
|
33
|
+
- "Cns::Etherscan#formata_transacao_norml"
|
34
|
+
- "Cns::Etherscan#formata_transacao_token"
|
35
|
+
- "Cns::Greymass#bq_bc"
|
36
|
+
- "Cns::Greymass#greymass_sl"
|
37
|
+
- "Cns::Greymass#formata_carteira"
|
38
|
+
- "Cns::Greymass#formata_ledger"
|
39
|
+
- "Cns::Greymass#filtrar_tx"
|
40
|
+
- "Cns::Beaconchain#base_bc"
|
41
|
+
- "Cns::Beaconchain#bq_bc"
|
42
|
+
- "Cns::Kraken#formata_ledger"
|
43
|
+
- "Cns::Kraken#formata_trades"
|
44
|
+
- "Cns::Paymium#formata_ledger"
|
45
|
+
- "Cns::Paymium#formata_uuid"
|
46
|
+
- "Cns::TheRock#formata_ledger"
|
47
|
+
- "Cns::TheRock#formata_saldos"
|
48
|
+
- "Cns::Beaconchain#formata_saldos"
|
49
|
+
- "Cns::Beaconchain#formata_endereco"
|
50
|
+
- "Cns::Beaconchain#formata_valores"
|
51
|
+
UtilityFunction:
|
52
|
+
exclude:
|
53
|
+
- "Cns::Apice#hus"
|
54
|
+
- "Cns::Bigquery#del_val"
|
55
|
+
- "Cns::Etherscan#ok?"
|
56
|
+
- "Cns::Greymass#ok?"
|
57
|
+
- "Cns::Beaconchain#itx"
|
58
|
+
- "Cns::Beaconchain#ok?"
|
59
|
+
NestedIterators:
|
60
|
+
exclude:
|
61
|
+
- "Cns::Etherscan#idk"
|
62
|
+
- "Cns::Etherscan#idt"
|
63
|
+
- "Cns::Etherscan#novtx"
|
64
|
+
- "Cns::Etherscan#novkx"
|
65
|
+
- "Cns::Etherscan#dados"
|
66
|
+
- "Cns::Etherscan#filtrar_tx"
|
67
|
+
- "Cns::Greymass#novax"
|
68
|
+
- "Cns::Greymass#idt"
|
69
|
+
- "Cns::Greymass#dados"
|
70
|
+
- "Cns::Paymium#kyl"
|
71
|
+
- "Cns::Paymium#ledger"
|
72
|
+
- "Cns::Beaconchain#dados"
|
73
|
+
- "Cns::Beaconchain#idb"
|
74
|
+
- "Cns::Beaconchain#nov"
|
data/.rubocop.yml
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
---
|
1
2
|
AllCops:
|
2
3
|
TargetRubyVersion: 2.7
|
3
4
|
EnabledByDefault: true
|
4
5
|
|
5
6
|
Style/Copyright:
|
6
|
-
|
7
|
+
Enabled: false
|
7
8
|
|
8
9
|
Lint/ConstantResolution:
|
9
|
-
|
10
|
+
Enabled: false
|
10
11
|
|
11
12
|
Style/ConstantVisibility:
|
12
|
-
|
13
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cns (0.
|
4
|
+
cns (0.2.2)
|
5
5
|
curb
|
6
6
|
faraday
|
7
7
|
google-cloud-bigquery
|
@@ -14,16 +14,18 @@ GEM
|
|
14
14
|
public_suffix (>= 2.0.2, < 5.0)
|
15
15
|
ast (2.4.1)
|
16
16
|
backport (1.1.2)
|
17
|
-
benchmark (0.1.
|
17
|
+
benchmark (0.1.1)
|
18
18
|
concurrent-ruby (1.1.7)
|
19
19
|
curb (0.9.11)
|
20
20
|
declarative (0.0.20)
|
21
21
|
declarative-option (0.1.0)
|
22
22
|
e2mmap (0.1.0)
|
23
|
-
faraday (1.
|
23
|
+
faraday (1.3.0)
|
24
|
+
faraday-net_http (~> 1.0)
|
24
25
|
multipart-post (>= 1.2, < 3)
|
25
26
|
ruby2_keywords
|
26
|
-
|
27
|
+
faraday-net_http (1.0.0)
|
28
|
+
google-api-client (0.52.0)
|
27
29
|
addressable (~> 2.5, >= 2.5.1)
|
28
30
|
googleauth (~> 0.9)
|
29
31
|
httpclient (>= 2.8.1, < 3.0)
|
@@ -54,21 +56,26 @@ GEM
|
|
54
56
|
httpclient (2.8.3)
|
55
57
|
jaro_winkler (1.5.4)
|
56
58
|
jwt (2.2.2)
|
59
|
+
kramdown (2.3.0)
|
60
|
+
rexml
|
61
|
+
kramdown-parser-gfm (1.1.0)
|
62
|
+
kramdown (~> 2.0)
|
57
63
|
kwalify (0.7.2)
|
58
|
-
maruku (0.7.3)
|
59
64
|
memoist (0.16.2)
|
60
65
|
mini_mime (1.0.2)
|
61
|
-
mini_portile2 (2.
|
66
|
+
mini_portile2 (2.5.0)
|
62
67
|
multi_json (1.15.0)
|
63
68
|
multipart-post (2.1.1)
|
64
|
-
nokogiri (1.
|
65
|
-
mini_portile2 (~> 2.
|
69
|
+
nokogiri (1.11.1)
|
70
|
+
mini_portile2 (~> 2.5.0)
|
71
|
+
racc (~> 1.4)
|
66
72
|
os (1.1.1)
|
67
73
|
parallel (1.20.1)
|
68
74
|
parser (2.7.2.0)
|
69
75
|
ast (~> 2.4.1)
|
70
|
-
psych (3.
|
76
|
+
psych (3.3.0)
|
71
77
|
public_suffix (4.0.6)
|
78
|
+
racc (1.5.2)
|
72
79
|
rainbow (3.0.0)
|
73
80
|
rake (12.3.3)
|
74
81
|
reek (6.0.2)
|
@@ -76,7 +83,7 @@ GEM
|
|
76
83
|
parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
|
77
84
|
psych (~> 3.1)
|
78
85
|
rainbow (>= 2.0, < 4.0)
|
79
|
-
regexp_parser (2.0.
|
86
|
+
regexp_parser (2.0.3)
|
80
87
|
representable (3.0.4)
|
81
88
|
declarative (< 0.1.0)
|
82
89
|
declarative-option (< 0.2.0)
|
@@ -85,35 +92,37 @@ GEM
|
|
85
92
|
reverse_markdown (2.0.0)
|
86
93
|
nokogiri
|
87
94
|
rexml (3.2.4)
|
88
|
-
rubocop (
|
95
|
+
rubocop (1.7.0)
|
89
96
|
parallel (~> 1.10)
|
90
97
|
parser (>= 2.7.1.5)
|
91
98
|
rainbow (>= 2.2.2, < 4.0)
|
92
|
-
regexp_parser (>= 1.8)
|
99
|
+
regexp_parser (>= 1.8, < 3.0)
|
93
100
|
rexml
|
94
|
-
rubocop-ast (>=
|
101
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
95
102
|
ruby-progressbar (~> 1.7)
|
96
103
|
unicode-display_width (>= 1.4.0, < 2.0)
|
97
|
-
rubocop-ast (1.
|
104
|
+
rubocop-ast (1.4.0)
|
98
105
|
parser (>= 2.7.1.5)
|
99
|
-
|
106
|
+
rubocop-rake (0.5.1)
|
107
|
+
rubocop
|
108
|
+
ruby-progressbar (1.11.0)
|
100
109
|
ruby2_keywords (0.0.2)
|
101
110
|
signet (0.14.0)
|
102
111
|
addressable (~> 2.3)
|
103
112
|
faraday (>= 0.17.3, < 2.0)
|
104
113
|
jwt (>= 1.5, < 3.0)
|
105
114
|
multi_json (~> 1.10)
|
106
|
-
solargraph (0.
|
115
|
+
solargraph (0.40.1)
|
107
116
|
backport (~> 1.1)
|
108
117
|
benchmark
|
109
118
|
bundler (>= 1.17.2)
|
110
119
|
e2mmap
|
111
120
|
jaro_winkler (~> 1.5)
|
112
|
-
|
113
|
-
|
121
|
+
kramdown (~> 2.3)
|
122
|
+
kramdown-parser-gfm (~> 1.1)
|
114
123
|
parser (~> 2.3)
|
115
124
|
reverse_markdown (>= 1.0.5, < 3)
|
116
|
-
rubocop (
|
125
|
+
rubocop (>= 0.52)
|
117
126
|
thor (~> 1.0)
|
118
127
|
tilt (~> 2.0)
|
119
128
|
yard (~> 0.9, >= 0.9.24)
|
@@ -121,7 +130,7 @@ GEM
|
|
121
130
|
tilt (2.0.10)
|
122
131
|
uber (0.1.0)
|
123
132
|
unicode-display_width (1.7.0)
|
124
|
-
yard (0.9.
|
133
|
+
yard (0.9.26)
|
125
134
|
|
126
135
|
PLATFORMS
|
127
136
|
ruby
|
@@ -132,6 +141,7 @@ DEPENDENCIES
|
|
132
141
|
rake (~> 12.0)
|
133
142
|
reek
|
134
143
|
rubocop
|
144
|
+
rubocop-rake
|
135
145
|
solargraph
|
136
146
|
yard
|
137
147
|
|
data/cns.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency('rake')
|
31
31
|
spec.add_development_dependency('reek')
|
32
32
|
spec.add_development_dependency('rubocop')
|
33
|
+
spec.add_development_dependency('rubocop-rake')
|
33
34
|
spec.add_development_dependency('solargraph')
|
34
35
|
spec.add_development_dependency('yard')
|
35
36
|
|
data/lib/cns.rb
CHANGED
data/lib/cns/apibc.rb
CHANGED
@@ -7,6 +7,17 @@ require('json')
|
|
7
7
|
module Cns
|
8
8
|
# classe para acesso dados blockchains
|
9
9
|
class Apibc
|
10
|
+
# @param [String] uri ETH2 API
|
11
|
+
# @return [Array<Hash>] lista dados beaconchain
|
12
|
+
def data_bc(uri)
|
13
|
+
res = JSON.parse(conn_bc.get(uri).body, symbolize_names: true)[:data] || []
|
14
|
+
# calls are rate limited to 10 requests/minute/IP
|
15
|
+
sleep(3)
|
16
|
+
res.is_a?(Array) ? res : [res]
|
17
|
+
rescue StandardError
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
|
10
21
|
# @example account_es
|
11
22
|
# {
|
12
23
|
# status: '1',
|
@@ -17,20 +28,17 @@ module Cns
|
|
17
28
|
# ]
|
18
29
|
# }
|
19
30
|
# @param [String] ads lista enderecos ETH (max 20)
|
20
|
-
# @param [Hash] par parametros base do pedido HTTP
|
21
31
|
# @return [Array<Hash>] lista enderecos e seus saldos
|
22
|
-
def account_es(ads
|
32
|
+
def account_es(ads)
|
23
33
|
JSON.parse(
|
24
|
-
|
25
|
-
o.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
|
26
|
-
o.params = par.merge(address: ads.join(','), apikey: ENV['ETHERSCAN_API_KEY'])
|
27
|
-
end).body,
|
34
|
+
conn_es.get('/api', action: 'balancemulti', tag: 'latest', address: ads.join(',')).body,
|
28
35
|
symbolize_names: true
|
29
36
|
)[:result]
|
30
37
|
rescue StandardError
|
31
38
|
[]
|
32
39
|
end
|
33
40
|
|
41
|
+
# @example account_gm
|
34
42
|
# @example account_gm
|
35
43
|
# {
|
36
44
|
# account_name: '...',
|
@@ -82,15 +90,9 @@ module Cns
|
|
82
90
|
# rex_info: nil
|
83
91
|
# }
|
84
92
|
# @param [String] add endereco EOS
|
85
|
-
# @param [String] uri Uniform Resource Identifier do pedido HTTP
|
86
93
|
# @return [Hash] endereco e seus saldo/recursos
|
87
|
-
def account_gm(add
|
88
|
-
JSON.parse(
|
89
|
-
conn_gm.post(
|
90
|
-
uri, { account_name: add }.to_json, content_type: 'application/json'
|
91
|
-
).body,
|
92
|
-
symbolize_names: true
|
93
|
-
)
|
94
|
+
def account_gm(add)
|
95
|
+
JSON.parse(conn_gm.post('/v1/chain/get_account', { account_name: add }.to_json).body, symbolize_names: true)
|
94
96
|
rescue StandardError
|
95
97
|
{ core_liquid_balance: 0, total_resources: { net_weight: 0, cpu_weight: 0 } }
|
96
98
|
end
|
@@ -125,20 +127,17 @@ module Cns
|
|
125
127
|
# }
|
126
128
|
# @param [String] add endereco ETH
|
127
129
|
# @param [Integer] pag pagina transacoes
|
128
|
-
# @param [Array<Hash>]
|
129
|
-
# @param par (see account_es)
|
130
|
+
# @param [Array<Hash>] aes acumulador transacoes
|
130
131
|
# @return [Array<Hash>] lista completa transacoes etherscan
|
131
|
-
def norml_es(add, pag = 0,
|
132
|
-
|
133
|
-
|
134
|
-
o.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
|
135
|
-
o.params = par.merge(address: add, page: pag + 1, apikey: ENV['ETHERSCAN_API_KEY'])
|
136
|
-
end).body,
|
132
|
+
def norml_es(add, pag = 0, aes = [])
|
133
|
+
res = JSON.parse(
|
134
|
+
conn_es.get('/api', action: 'txlist', offset: 10_000, address: add, page: pag += 1).body,
|
137
135
|
symbolize_names: true
|
138
136
|
)[:result]
|
139
|
-
|
137
|
+
aes += res
|
138
|
+
res.count < 10_000 ? aes : norml_es(add, pag, aes)
|
140
139
|
rescue StandardError
|
141
|
-
|
140
|
+
aes
|
142
141
|
end
|
143
142
|
|
144
143
|
# @example token_es
|
@@ -172,20 +171,18 @@ module Cns
|
|
172
171
|
# }
|
173
172
|
# @param (see norml_es)
|
174
173
|
# @return [Array<Hash>] lista completa token transfer events etherscan
|
175
|
-
def token_es(add, pag = 0,
|
174
|
+
def token_es(add, pag = 0, aes = [])
|
176
175
|
# registos duplicados aparecem em token events (ver exemplo acima)
|
177
176
|
# -quando ha erros na blockchain (acho)
|
178
177
|
# -quando ha token events identicos no mesmo block (acho)
|
179
|
-
|
180
|
-
|
181
|
-
o.headers = { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
|
182
|
-
o.params = par.merge(address: add, page: pag + 1, apikey: ENV['ETHERSCAN_API_KEY'])
|
183
|
-
end).body,
|
178
|
+
res = JSON.parse(
|
179
|
+
conn_es.get('/api', action: 'tokentx', offset: 10_000, address: add, page: pag += 1).body,
|
184
180
|
symbolize_names: true
|
185
181
|
)[:result]
|
186
|
-
|
182
|
+
aes += res
|
183
|
+
res.count < 10_000 ? aes : token_es(add, pag, aes)
|
187
184
|
rescue StandardError
|
188
|
-
|
185
|
+
aes
|
189
186
|
end
|
190
187
|
|
191
188
|
# @example ledger_gm
|
@@ -236,20 +233,17 @@ module Cns
|
|
236
233
|
# last_irreversible_block: 141_721_371
|
237
234
|
# }
|
238
235
|
# @param add (see account_gm)
|
239
|
-
# @param [
|
240
|
-
# @param [Array<Hash>] ary acumulador transacoes
|
241
|
-
# @param uri (see account_gm)
|
236
|
+
# @param [Array<Hash>] agm acumulador transacoes
|
242
237
|
# @return [Array<Hash>] lista completa transacoes greymass
|
243
|
-
def ledger_gm(add,
|
244
|
-
|
245
|
-
conn_gm.post(
|
246
|
-
uri, { account_name: add, pos: pos, offset: 100 }.to_json, content_type: 'application/json'
|
247
|
-
).body,
|
238
|
+
def ledger_gm(add, agm = [])
|
239
|
+
res = JSON.parse(
|
240
|
+
conn_gm.post('/v1/history/get_actions', { account_name: add, pos: agm.count, offset: 100 }.to_json).body,
|
248
241
|
symbolize_names: true
|
249
242
|
)[:actions]
|
250
|
-
|
243
|
+
agm += res
|
244
|
+
res.count < 100 ? agm : ledger_gm(add, agm)
|
251
245
|
rescue StandardError
|
252
|
-
|
246
|
+
agm
|
253
247
|
end
|
254
248
|
|
255
249
|
private
|
@@ -262,18 +256,31 @@ module Cns
|
|
262
256
|
# @return [<Faraday::Connection>] connection object for etherscan
|
263
257
|
def conn_es
|
264
258
|
@conn_es ||=
|
265
|
-
Faraday.new(
|
266
|
-
|
267
|
-
|
259
|
+
Faraday.new(
|
260
|
+
url: 'https://api.etherscan.io',
|
261
|
+
params: { module: 'account', apikey: ENV['ETHERSCAN_API_KEY'] },
|
262
|
+
headers: { content_type: 'application/json', accept: 'application/json', user_agent: 'etherscan;ruby' }
|
263
|
+
) do |con|
|
264
|
+
con.request(:url_encoded)
|
265
|
+
con.adapter(adapter)
|
268
266
|
end
|
269
267
|
end
|
270
268
|
|
271
269
|
# @return [<Faraday::Connection>] connection object for greymass
|
272
270
|
def conn_gm
|
273
271
|
@conn_gm ||=
|
274
|
-
Faraday.new(url: 'https://eos.greymass.com') do |
|
275
|
-
|
276
|
-
|
272
|
+
Faraday.new(url: 'https://eos.greymass.com', headers: { content_type: 'application/json' }) do |con|
|
273
|
+
con.request(:url_encoded)
|
274
|
+
con.adapter(adapter)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
# @return [<Faraday::Connection>] connection object for beaconchain
|
279
|
+
def conn_bc
|
280
|
+
@conn_bc ||=
|
281
|
+
Faraday.new(url: 'https://beaconcha.in', headers: { accept: 'application/json' }) do |con|
|
282
|
+
con.request(:url_encoded)
|
283
|
+
con.adapter(adapter)
|
277
284
|
end
|
278
285
|
end
|
279
286
|
end
|
data/lib/cns/apice1.rb
CHANGED
@@ -31,7 +31,7 @@ module Cns
|
|
31
31
|
# @return [Hash] saldos no bitcoinde
|
32
32
|
def account_de(uri = 'https://api.bitcoin.de/v4/account')
|
33
33
|
JSON.parse(
|
34
|
-
Curl.get(uri) { |
|
34
|
+
Curl.get(uri) { |obj| obj.headers = hde(uri) }.body,
|
35
35
|
symbolize_names: true
|
36
36
|
)[:data][:balances]
|
37
37
|
rescue StandardError
|
@@ -56,7 +56,7 @@ module Cns
|
|
56
56
|
# @return [Hash] saldos no paymium
|
57
57
|
def account_fr(uri = 'https://paymium.com/api/v1/user')
|
58
58
|
JSON.parse(
|
59
|
-
Curl.get(uri) { |
|
59
|
+
Curl.get(uri) { |obj| obj.headers = hfr(uri) }.body,
|
60
60
|
symbolize_names: true
|
61
61
|
)
|
62
62
|
rescue StandardError
|
@@ -76,11 +76,11 @@ module Cns
|
|
76
76
|
# @return [Array<Hash>] lista saldos no therock
|
77
77
|
def account_mt(uri = 'https://api.therocktrading.com/v1/balances')
|
78
78
|
JSON.parse(
|
79
|
-
Curl.get(uri) { |
|
79
|
+
Curl.get(uri) { |obj| obj.headers = hmt(uri) }.body,
|
80
80
|
symbolize_names: true
|
81
81
|
)[:balances]
|
82
|
-
.delete_if { |
|
83
|
-
.sort { |
|
82
|
+
.delete_if { |del| DC.include?(del[:currency]) }
|
83
|
+
.sort { |oba, obb| oba[:currency] <=> obb[:currency] }
|
84
84
|
rescue StandardError
|
85
85
|
[]
|
86
86
|
end
|
@@ -103,7 +103,7 @@ module Cns
|
|
103
103
|
# @return [Hash] saldos no kraken
|
104
104
|
def account_us(urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc)
|
105
105
|
JSON.parse(
|
106
|
-
Curl.post("#{urb}/#{uri}", nonce: non) { |
|
106
|
+
Curl.post("#{urb}/#{uri}", nonce: non) { |obj| obj.headers = hus(uri, nonce: non) }.body,
|
107
107
|
symbolize_names: true
|
108
108
|
)[:result]
|
109
109
|
rescue StandardError
|
@@ -112,113 +112,63 @@ module Cns
|
|
112
112
|
|
113
113
|
private
|
114
114
|
|
115
|
-
# @example deposits_unif_de
|
116
|
-
# [
|
117
|
-
# {
|
118
|
-
# txid: 177_245,
|
119
|
-
# time: '2014-01-31T22:01:30+01:00',
|
120
|
-
# tp: 'deposit',
|
121
|
-
# add: '1KK6HhG3quojFS4CY1mPcbyrjQ8BMDQxmT',
|
122
|
-
# qt: '0.13283',
|
123
|
-
# moe: 'btc',
|
124
|
-
# fee: '0'
|
125
|
-
# },
|
126
|
-
# {}
|
127
|
-
# ]
|
128
|
-
# @param [Hash] hde pagina depositos bitcoinde
|
129
|
-
# @return [Array<Hash>] lista uniformizada pagina depositos bitcoinde
|
130
|
-
def deposits_unif_de(hde)
|
131
|
-
hde[:deposits].map do |h|
|
132
|
-
{
|
133
|
-
add: h[:address],
|
134
|
-
time: Time.parse(h[:created_at]),
|
135
|
-
qt: h[:amount],
|
136
|
-
txid: Integer(h[:deposit_id])
|
137
|
-
}.merge(tp: 'deposit', moe: 'btc', fee: '0')
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# @example withdrawals_unif_de
|
142
|
-
# [
|
143
|
-
# {
|
144
|
-
# txid: 136_605,
|
145
|
-
# time: '2014-02-05T13:05:17+01:00',
|
146
|
-
# tp: 'withdrawal',
|
147
|
-
# add: '1K9YMDDrmMV25EoYNqi7KUEK57Kn3TCNUJ',
|
148
|
-
# qt: '0.120087',
|
149
|
-
# fee: '0',
|
150
|
-
# moe: 'btc'
|
151
|
-
# },
|
152
|
-
# {}
|
153
|
-
# ]
|
154
|
-
# @param [Hash] hwi pagina withdrawals bitcoinde
|
155
|
-
# @return [Array<Hash>] lista uniformizada pagina withdrawals bitcoinde
|
156
|
-
def withdrawals_unif_de(hwi)
|
157
|
-
hwi[:withdrawals].map do |h|
|
158
|
-
{
|
159
|
-
add: h[:address],
|
160
|
-
time: Time.parse(h[:transferred_at]),
|
161
|
-
qt: h[:amount],
|
162
|
-
fee: h[:network_fee],
|
163
|
-
txid: Integer(h[:withdrawal_id])
|
164
|
-
}.merge(tp: 'withdrawal', moe: 'btc')
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
115
|
# @return [Integer] continually-increasing unsigned integer nonce from the current Unix Time
|
169
116
|
def nnc
|
170
117
|
Integer(Float(Time.now) * 1e6)
|
171
118
|
end
|
172
119
|
|
173
|
-
# @param [String]
|
120
|
+
# @param [String] qde query a incluir no pedido HTTP
|
174
121
|
# @param [Integer] non continually-increasing unsigned integer
|
175
122
|
# @return [Hash] headers necessarios para pedido HTTP da exchange bitcoinde
|
176
|
-
def hde(
|
123
|
+
def hde(qde, non = nnc)
|
124
|
+
key = ENV['BITCOINDE_API_KEY']
|
177
125
|
{
|
178
|
-
'X-API-KEY':
|
126
|
+
'X-API-KEY': key,
|
179
127
|
'X-API-NONCE': non,
|
180
128
|
'X-API-SIGNATURE': OpenSSL::HMAC.hexdigest(
|
181
129
|
'sha256',
|
182
130
|
ENV['BITCOINDE_API_SECRET'],
|
183
|
-
['GET',
|
131
|
+
['GET', qde, key, non, Digest::MD5.hexdigest('')].join('#')
|
184
132
|
)
|
185
133
|
}
|
186
134
|
end
|
187
135
|
|
188
|
-
# @param
|
136
|
+
# @param [String] qfr query a incluir no pedido HTTP
|
137
|
+
# @param non (see hde)
|
189
138
|
# @return [Hash] headers necessarios para pedido HTTP da exchange paymium
|
190
|
-
def hfr(
|
139
|
+
def hfr(qfr, non = nnc)
|
191
140
|
{
|
192
141
|
content_type: 'application/json',
|
193
142
|
'Api-Key': ENV['PAYMIUM_API_KEY'],
|
194
143
|
'Api-Nonce': non,
|
195
|
-
'Api-Signature': OpenSSL::HMAC.hexdigest('sha256', ENV['PAYMIUM_API_SECRET'], [non,
|
144
|
+
'Api-Signature': OpenSSL::HMAC.hexdigest('sha256', ENV['PAYMIUM_API_SECRET'], [non, qfr].join)
|
196
145
|
}
|
197
146
|
end
|
198
147
|
|
199
|
-
# @param
|
148
|
+
# @param [String] qmt query a incluir no pedido HTTP
|
149
|
+
# @param non (see hde)
|
200
150
|
# @return [Hash] headers necessarios para pedido HTTP da exchange therock
|
201
|
-
def hmt(
|
151
|
+
def hmt(qmt, non = nnc)
|
202
152
|
{
|
203
153
|
content_type: 'application/json',
|
204
154
|
'X-TRT-KEY': ENV['THEROCK_API_KEY'],
|
205
155
|
'X-TRT-NONCE': non,
|
206
|
-
'X-TRT-SIGN': OpenSSL::HMAC.hexdigest('sha512', ENV['THEROCK_API_SECRET'], [non,
|
156
|
+
'X-TRT-SIGN': OpenSSL::HMAC.hexdigest('sha512', ENV['THEROCK_API_SECRET'], [non, qmt].join)
|
207
157
|
}
|
208
158
|
end
|
209
159
|
|
210
|
-
# @param
|
160
|
+
# @param [String] qus query a incluir no pedido HTTP
|
211
161
|
# @param [Hash] ops opcoes trabalho
|
212
162
|
# @option ops [Hash] :nonce continually-increasing unsigned integer
|
213
163
|
# @return [Hash] headers necessarios para pedido HTTP da exchange kraken
|
214
|
-
def hus(
|
164
|
+
def hus(qus, ops)
|
215
165
|
{
|
216
166
|
'api-key': ENV['KRAKEN_API_KEY'],
|
217
167
|
'api-sign': Base64.strict_encode64(
|
218
168
|
OpenSSL::HMAC.digest(
|
219
169
|
'sha512',
|
220
170
|
Base64.decode64(ENV['KRAKEN_API_SECRET']),
|
221
|
-
['/0/private/',
|
171
|
+
['/0/private/', qus, Digest::SHA256.digest("#{ops[:nonce]}#{URI.encode_www_form(ops)}")].join
|
222
172
|
)
|
223
173
|
)
|
224
174
|
}
|