cns 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/cns/apibc.rb +26 -21
- data/lib/cns/apice.rb +103 -410
- data/lib/cns/bigquery.rb +0 -5
- data/lib/cns/bitcoinde.rb +0 -4
- data/lib/cns/greymass.rb +1 -5
- data/lib/cns/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 447a7eabc62ea51c62ff66775c277f6ea40a8812a781f28b695ce00f773dc2b7
|
4
|
+
data.tar.gz: '06778bee30d6d2e7ed2cd6ff13749b13941eb9006c961fbbaf80e358d38cb653'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a308f6d97e7685d5b2335225ee180347ab1b806ff08780eac84edbf1b732b74627d860026803d9871ccb90c9b0bf74e323e1b24b23d6d64f10916d6dd0f0dae4
|
7
|
+
data.tar.gz: 705c5c84272baeb7b2e60af69d5a6c802c7a6c28a9c34420a94395b87464829ac7e1a25fa37c60fe62a655aea7971cf210f827100638f37a1794d45cd6d8a89c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cns (0.8.
|
4
|
+
cns (0.8.3)
|
5
5
|
curb
|
6
6
|
faraday
|
7
7
|
google-cloud-bigquery
|
@@ -136,7 +136,7 @@ GEM
|
|
136
136
|
reverse_markdown (3.0.0)
|
137
137
|
nokogiri
|
138
138
|
rexml (3.4.1)
|
139
|
-
rubocop (1.72.
|
139
|
+
rubocop (1.72.2)
|
140
140
|
json (~> 2.3)
|
141
141
|
language_server-protocol (~> 3.17.0.2)
|
142
142
|
lint_roller (~> 1.1.0)
|
data/lib/cns/apibc.rb
CHANGED
@@ -12,15 +12,7 @@ module Cns
|
|
12
12
|
# @return [Array<Hash>] List of addresses with balances
|
13
13
|
def account_es(addresses)
|
14
14
|
response = etherscan_req('balancemulti', addresses.join(','), 1, tag: 'latest')
|
15
|
-
response
|
16
|
-
end
|
17
|
-
|
18
|
-
# Get EOS account information
|
19
|
-
# @param address [String] EOS account name
|
20
|
-
# @return [Hash] Account details with resources
|
21
|
-
def account_gm(address)
|
22
|
-
response = greymass_req('/v1/chain/get_account', { account_name: address })
|
23
|
-
response || { core_liquid_balance: 0, total_resources: { net_weight: 0, cpu_weight: 0 } }
|
15
|
+
response.fetch(:status, '0') == '1' ? response.fetch(:result, []) : []
|
24
16
|
end
|
25
17
|
|
26
18
|
# Get normal transactions for ETH address
|
@@ -58,6 +50,14 @@ module Cns
|
|
58
50
|
pag_etherscan_req('tokentx', address)
|
59
51
|
end
|
60
52
|
|
53
|
+
# Get EOS account information
|
54
|
+
# @param address [String] EOS account name
|
55
|
+
# @return [Hash] Account details with resources
|
56
|
+
def account_gm(address)
|
57
|
+
response = greymass_req('/v1/chain/get_account', account_name: address)
|
58
|
+
response.dig(:core_liquid_balance).to_d > 0 ? response : gm_erro
|
59
|
+
end
|
60
|
+
|
61
61
|
# Get complete transaction history for EOS account
|
62
62
|
# @param (see account_gm)
|
63
63
|
# @return [Array<Hash>] lista completa transacoes greymass
|
@@ -65,8 +65,8 @@ module Cns
|
|
65
65
|
actions = []
|
66
66
|
pos = 0
|
67
67
|
loop do
|
68
|
-
response = greymass_req('/v1/history/get_actions',
|
69
|
-
batch = response
|
68
|
+
response = greymass_req('/v1/history/get_actions', account_name: address, pos: pos, offset: 100)
|
69
|
+
batch = response.fetch(:actions, [])
|
70
70
|
actions += batch
|
71
71
|
break if batch.size < 100
|
72
72
|
|
@@ -88,9 +88,9 @@ module Cns
|
|
88
88
|
# Generic Etherscan API request handler
|
89
89
|
def etherscan_req(action, address, page = 1, params = {})
|
90
90
|
params = { module: 'account', action: action, address: address, page: page, apikey: ENV.fetch('ETHERSCAN_API_KEY') }.merge(params)
|
91
|
-
parse_json(connection('https://api.etherscan.io').get('/api', params)
|
92
|
-
rescue Faraday::Error
|
93
|
-
{ status: '0'
|
91
|
+
parse_json(connection('https://api.etherscan.io').get('/api', params))
|
92
|
+
rescue Faraday::Error
|
93
|
+
{ status: '0' }
|
94
94
|
end
|
95
95
|
|
96
96
|
# Generic method for paginated Etherscan requests
|
@@ -103,9 +103,9 @@ module Cns
|
|
103
103
|
page = 1
|
104
104
|
loop do
|
105
105
|
response = etherscan_req(action, address, page, params)
|
106
|
-
break unless response
|
106
|
+
break unless response.fetch(:status, '0') == '1'
|
107
107
|
|
108
|
-
batch = response
|
108
|
+
batch = response.fetch(:result, [])
|
109
109
|
results += batch
|
110
110
|
break if batch.size < 10_000
|
111
111
|
|
@@ -114,16 +114,21 @@ module Cns
|
|
114
114
|
results
|
115
115
|
end
|
116
116
|
|
117
|
+
# Generic Greymass API error
|
118
|
+
def gm_erro
|
119
|
+
{ core_liquid_balance: 0, total_resources: { net_weight: 0, cpu_weight: 0 } }
|
120
|
+
end
|
121
|
+
|
117
122
|
# Generic Greymass API request handler
|
118
123
|
def greymass_req(endpoint, payload)
|
119
|
-
parse_json((connection('https://eos.greymass.com').post(endpoint) { |req| req.body = payload.to_json })
|
120
|
-
rescue Faraday::Error
|
121
|
-
|
124
|
+
parse_json((connection('https://eos.greymass.com').post(endpoint) { |req| req.body = payload.to_json }))
|
125
|
+
rescue Faraday::Error
|
126
|
+
gm_erro
|
122
127
|
end
|
123
128
|
|
124
129
|
# Safe JSON parsing with error handling
|
125
|
-
def parse_json(
|
126
|
-
JSON.parse(body, symbolize_names: true)
|
130
|
+
def parse_json(res)
|
131
|
+
JSON.parse(res.body, symbolize_names: true) || {}
|
127
132
|
rescue JSON::ParserError
|
128
133
|
{}
|
129
134
|
end
|
data/lib/cns/apice.rb
CHANGED
@@ -7,202 +7,74 @@ require('json')
|
|
7
7
|
|
8
8
|
# @author Hernani Rodrigues Vaz
|
9
9
|
module Cns
|
10
|
-
|
10
|
+
API = { de: 'https://api.bitcoin.de/v4', us: 'https://api.kraken.com/0/private' }.freeze
|
11
11
|
|
12
12
|
# classe para acesso dados centralized exchanges
|
13
13
|
class Apice
|
14
|
-
# @example account_de
|
15
|
-
# {
|
16
|
-
# data: {
|
17
|
-
# balances: {
|
18
|
-
# btc: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
19
|
-
# bch: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
20
|
-
# btg: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
21
|
-
# eth: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
22
|
-
# bsv: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' },
|
23
|
-
# ltc: { total_amount: '0.00000000000000000000', available_amount: '0', reserved_amount: '0' }
|
24
|
-
# },
|
25
|
-
# encrypted_information: { uid: '0y...', bic_short: '0y...', bic_full: '0y...' }
|
26
|
-
# },
|
27
|
-
# errors: [],
|
28
|
-
# credits: 23
|
29
|
-
# }
|
30
|
-
# @param [String] uri Uniform Resource Identifier do pedido HTTP
|
31
14
|
# @return [Hash] saldos no bitcoinde
|
32
|
-
def account_de
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
)[:data][:balances]
|
37
|
-
rescue StandardError
|
15
|
+
def account_de
|
16
|
+
uri = "#{API[:de]}/account"
|
17
|
+
parse_json(Curl.get(uri) { |obj| obj.headers = hde(uri) }).dig(:data, :balances) || {}
|
18
|
+
rescue Curl::Err::CurlError
|
38
19
|
{}
|
39
20
|
end
|
40
21
|
|
41
|
-
# @
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# @param non (see hde)
|
56
|
-
# @return [Hash] saldos no kraken
|
57
|
-
def account_us(urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc)
|
58
|
-
JSON.parse(Curl.post("#{urb}/#{uri}", nonce: non) { |obj| obj.headers = hus(uri, nonce: non) }.body, symbolize_names: true)[:result]
|
59
|
-
rescue StandardError
|
60
|
-
{}
|
61
|
-
end
|
62
|
-
|
63
|
-
# @example trades_de
|
64
|
-
# {
|
65
|
-
# trades: [{
|
66
|
-
# trade_id: 'XUWWD3',
|
67
|
-
# trading_pair: 'btceur',
|
68
|
-
# is_external_wallet_trade: false,
|
69
|
-
# type: 'sell',
|
70
|
-
# amount_currency_to_trade: '0.1',
|
71
|
-
# price: 430,
|
72
|
-
# volume_currency_to_pay: 43,
|
73
|
-
# volume_currency_to_pay_after_fee: 42.79,
|
74
|
-
# amount_currency_to_trade_after_fee: 0.099,
|
75
|
-
# fee_currency_to_pay: 0.22,
|
76
|
-
# fee_currency_to_trade: '0.00100000',
|
77
|
-
# created_at: '2014-03-22T08:14:48+01:00',
|
78
|
-
# successfully_finished_at: '2014-03-25T14:03:22+01:00',
|
79
|
-
# state: 1,
|
80
|
-
# is_trade_marked_as_paid: true,
|
81
|
-
# trade_marked_as_paid_at: '2014-03-22T08:20:01+01:00',
|
82
|
-
# payment_method: 1,
|
83
|
-
# my_rating_for_trading_partner: 'positive',
|
84
|
-
# trading_partner_information: {
|
85
|
-
# username: 'emax2000',
|
86
|
-
# is_kyc_full: false,
|
87
|
-
# trust_level: 'bronze',
|
88
|
-
# amount_trades: 4,
|
89
|
-
# rating: 100,
|
90
|
-
# bank_name: 'CASSA DI RISPARMIO DI CIVITAVECCHIA SPA',
|
91
|
-
# bic: 'CRFIIT2CXXX',
|
92
|
-
# seat_of_bank: 'IT'
|
93
|
-
# }
|
94
|
-
# }, {}],
|
95
|
-
# page: { current: 1, last: 2 },
|
96
|
-
# errors: [],
|
97
|
-
# credits: 22
|
98
|
-
# }
|
99
|
-
# @param [Integer] pag pagina dos dados
|
100
|
-
# @param [Array<Hash>] ary acumulador dos dados
|
101
|
-
# @param [String] uri Uniform Resource Identifier do pedido HTTP
|
102
|
-
# @return [Array<Hash>] lista completa trades bitcoinde
|
103
|
-
def trades_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/trades')
|
104
|
-
par = "#{uri}?#{URI.encode_www_form(state: 1, page: pag += 1)}"
|
105
|
-
res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true)
|
106
|
-
ary += res[:trades]
|
107
|
-
rep = res[:page]
|
108
|
-
rep[:current] < rep[:last] ? trades_de(pag, ary) : ary
|
109
|
-
rescue StandardError
|
22
|
+
# @return [Array<Hash>] trades bitcoinde
|
23
|
+
def trades_de
|
24
|
+
pag = 1
|
25
|
+
ary = []
|
26
|
+
loop do
|
27
|
+
url = "#{API[:de]}/trades?#{URI.encode_www_form(state: 1, page: pag)}"
|
28
|
+
data = parse_json(Curl.get(url) { |obj| obj.headers = hde(url) })
|
29
|
+
ary += data.fetch(:trades, [])
|
30
|
+
break if data[:page][:current] >= data[:page][:last]
|
31
|
+
|
32
|
+
pag += 1
|
33
|
+
end
|
34
|
+
ary
|
35
|
+
rescue Curl::Err::CurlError
|
110
36
|
ary
|
111
37
|
end
|
112
38
|
|
113
|
-
# @
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
# page: { current: 1, last: 1 },
|
128
|
-
# errors: [],
|
129
|
-
# credits: 23
|
130
|
-
# }
|
131
|
-
# @param (see trades_de)
|
132
|
-
# @return [Array<Hash>] lista completa uniformizada depositos bitcoinde
|
133
|
-
def deposits_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/deposits')
|
134
|
-
par = "#{uri}?#{URI.encode_www_form(state: 2, page: pag += 1)}"
|
135
|
-
res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true)
|
136
|
-
ary += res[:deposits].map { |has| deposit_unif(has) }
|
137
|
-
rep = res[:page]
|
138
|
-
rep[:current] < rep[:last] ? deposits_de(pag, ary) : ary
|
139
|
-
rescue StandardError
|
39
|
+
# @return [Array<Hash>] depositos uniformizados bitcoinde
|
40
|
+
def deposits_de
|
41
|
+
pag = 1
|
42
|
+
ary = []
|
43
|
+
loop do
|
44
|
+
url = "#{API[:de]}/btc/deposits?#{URI.encode_www_form(state: 2, page: pag)}"
|
45
|
+
data = parse_json(Curl.get(url) { |obj| obj.headers = hde(url) })
|
46
|
+
ary += data.fetch(:deposits, []).map { |has| deposit_unif(has) }
|
47
|
+
break if data[:page][:current] >= data[:page][:last]
|
48
|
+
|
49
|
+
pag += 1
|
50
|
+
end
|
51
|
+
ary
|
52
|
+
rescue Curl::Err::CurlError
|
140
53
|
ary
|
141
54
|
end
|
142
55
|
|
143
|
-
# @
|
144
|
-
# [
|
145
|
-
# {
|
146
|
-
# txid: 177_245,
|
147
|
-
# time: '2014-01-31T22:01:30+01:00',
|
148
|
-
# tp: 'deposit',
|
149
|
-
# add: '1KK6HhG3quojFS4CY1mPcbyrjQ8BMDQxmT',
|
150
|
-
# qt: '0.13283',
|
151
|
-
# moe: 'btc',
|
152
|
-
# fee: '0'
|
153
|
-
# },
|
154
|
-
# {}
|
155
|
-
# ]
|
156
|
-
# @return [Hash] deposit uniformizado bitcoinde
|
56
|
+
# @return [Hash] deposito uniformizado bitcoinde
|
157
57
|
def deposit_unif(has)
|
158
58
|
{ add: has[:address], time: Time.parse(has[:created_at]), qt: has[:amount], txid: Integer(has[:deposit_id]) }.merge(tp: 'deposit', moe: 'btc', fee: '0')
|
159
59
|
end
|
160
60
|
|
161
|
-
# @
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
# {}
|
176
|
-
# ],
|
177
|
-
# page: { current: 1, last: 2 },
|
178
|
-
# errors: [],
|
179
|
-
# credits: 23
|
180
|
-
# }
|
181
|
-
# @param (see deposits_de)
|
182
|
-
# @return [Array<Hash>] lista completa uniformizada withdrawals bitcoinde
|
183
|
-
def withdrawals_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/withdrawals')
|
184
|
-
par = "#{uri}?#{URI.encode_www_form(state: 1, page: pag += 1)}"
|
185
|
-
res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true)
|
186
|
-
ary += res[:withdrawals].map { |has| withdrawal_unif(has) }
|
187
|
-
rep = res[:page]
|
188
|
-
rep[:current] < rep[:last] ? withdrawals_de(pag, ary) : ary
|
189
|
-
rescue StandardError
|
61
|
+
# @return [Array<Hash>] withdrawals uniformizadas bitcoinde
|
62
|
+
def withdrawals_de
|
63
|
+
ary = []
|
64
|
+
pag = 1
|
65
|
+
loop do
|
66
|
+
url = "#{API[:de]}/btc/withdrawals?#{URI.encode_www_form(state: 1, page: pag)}"
|
67
|
+
data = parse_json(Curl.get(url) { |obj| obj.headers = hde(url) })
|
68
|
+
ary += data.fetch(:withdrawals, []).map { |has| withdrawal_unif(has) }
|
69
|
+
break if data[:page][:current] >= data[:page][:last]
|
70
|
+
|
71
|
+
pag += 1
|
72
|
+
end
|
73
|
+
ary
|
74
|
+
rescue Curl::Err::CurlError
|
190
75
|
ary
|
191
76
|
end
|
192
77
|
|
193
|
-
# @example withdrawal_unif
|
194
|
-
# [
|
195
|
-
# {
|
196
|
-
# txid: 136_605,
|
197
|
-
# time: '2014-02-05T13:05:17+01:00',
|
198
|
-
# tp: 'withdrawal',
|
199
|
-
# add: '1K9YMDDrmMV25EoYNqi7KUEK57Kn3TCNUJ',
|
200
|
-
# qt: '0.120087',
|
201
|
-
# fee: '0',
|
202
|
-
# moe: 'btc'
|
203
|
-
# },
|
204
|
-
# {}
|
205
|
-
# ]
|
206
78
|
# @return [Hash] withdrawal uniformizada bitcoinde
|
207
79
|
def withdrawal_unif(has)
|
208
80
|
{
|
@@ -214,205 +86,62 @@ module Cns
|
|
214
86
|
}.merge(tp: 'withdrawal', moe: 'btc')
|
215
87
|
end
|
216
88
|
|
217
|
-
# @
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
# pair: 'XETHXXBT',
|
225
|
-
# time: 1_463_435_684.8387,
|
226
|
-
# type: 'buy',
|
227
|
-
# ordertype: 'market',
|
228
|
-
# price: '0.024989',
|
229
|
-
# cost: '1.193973',
|
230
|
-
# fee: '0.003104',
|
231
|
-
# vol: '47.77994129',
|
232
|
-
# margin: '0.000000',
|
233
|
-
# misc: ''
|
234
|
-
# },
|
235
|
-
# "OUTRO-TRADE-ID": {}
|
236
|
-
# },
|
237
|
-
# count: 157
|
238
|
-
# }
|
239
|
-
# }
|
240
|
-
# @param [Integer] ofs offset dos dados
|
241
|
-
# @param [Hash] has acumulador dos dados
|
242
|
-
# @param (see account_us)
|
243
|
-
# @return [Hash] dados trades kraken
|
244
|
-
def trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private', uri = 'TradesHistory', non = nnc)
|
245
|
-
res = JSON.parse(
|
246
|
-
Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body,
|
247
|
-
symbolize_names: true
|
248
|
-
)[:result]
|
249
|
-
has.merge!(res[:trades])
|
250
|
-
sleep(2)
|
251
|
-
res[:trades].count.positive? ? trades_us(ofs + res[:trades].count, has) : has
|
252
|
-
rescue StandardError
|
253
|
-
has
|
89
|
+
# @return [Hash] saldos kraken
|
90
|
+
def account_us
|
91
|
+
uri = 'Balance'
|
92
|
+
ops = { nonce: nnc }
|
93
|
+
parse_json(Curl.post("#{API[:us]}/#{uri}", ops) { |hed| hed.headers = hus(uri, ops) }).fetch(:result, {})
|
94
|
+
rescue Curl::Err::CurlError
|
95
|
+
{}
|
254
96
|
end
|
255
97
|
|
256
|
-
# @
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
# "OUTRO-LEDGER-ID": {}
|
273
|
-
# },
|
274
|
-
# count: 376
|
275
|
-
# }
|
276
|
-
# }
|
277
|
-
# @param (see trades_us)
|
278
|
-
# @return [Hash] dados ledger kraken
|
279
|
-
def ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private', uri = 'Ledgers', non = nnc)
|
280
|
-
res = JSON.parse(
|
281
|
-
Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body,
|
282
|
-
symbolize_names: true
|
283
|
-
)[:result]
|
284
|
-
has.merge!(res[:ledger])
|
285
|
-
sleep(2)
|
286
|
-
res[:ledger].count.positive? ? ledger_us(ofs + res[:ledger].count, has) : has
|
287
|
-
rescue StandardError
|
98
|
+
# @return [Hash] trades kraken
|
99
|
+
def trades_us
|
100
|
+
uri = 'TradesHistory'
|
101
|
+
has = {}
|
102
|
+
ofs = 0
|
103
|
+
loop do
|
104
|
+
sleep(1)
|
105
|
+
ops = { nonce: nnc, ofs: ofs }
|
106
|
+
result = parse_json(Curl.post("#{API[:us]}/#{uri}", ops) { |hed| hed.headers = hus(uri, ops) }).fetch(:result, {})
|
107
|
+
break if result.fetch(:trades, []).empty?
|
108
|
+
|
109
|
+
has.merge!(result[:trades])
|
110
|
+
ofs += result[:trades].size
|
111
|
+
end
|
112
|
+
has
|
113
|
+
rescue Curl::Err::CurlError
|
288
114
|
has
|
289
115
|
end
|
290
116
|
|
291
|
-
# @
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
# Curl.get(uri) { |obj| obj.headers = hfr(uri) }.body,
|
310
|
-
# symbolize_names: true
|
311
|
-
# )
|
312
|
-
# rescue StandardError
|
313
|
-
# {}
|
314
|
-
# end
|
315
|
-
#
|
316
|
-
# @example account_mt
|
317
|
-
# {
|
318
|
-
# balances: [
|
319
|
-
# { currency: 'BTC', balance: 0.0, trading_balance: 0.0 },
|
320
|
-
# { currency: 'ETH', balance: 0.0, trading_balance: 0.0 },
|
321
|
-
# { currency: 'EUR', balance: 0.0, trading_balance: 0.0 },
|
322
|
-
# { currency: 'DAI', balance: 0.0, trading_balance: 0.0 },
|
323
|
-
# ]
|
324
|
-
# }
|
325
|
-
# @param (see account_de)
|
326
|
-
# @return [Array<Hash>] lista saldos no therock
|
327
|
-
# def account_mt(uri = 'https://api.therocktrading.com/v1/balances')
|
328
|
-
# JSON.parse(
|
329
|
-
# Curl.get(uri) { |obj| obj.headers = hmt(uri) }.body,
|
330
|
-
# symbolize_names: true
|
331
|
-
# )[:balances]
|
332
|
-
# .delete_if { |del| DC.include?(del[:currency]) }
|
333
|
-
# .sort { |oba, obb| oba[:currency] <=> obb[:currency] }
|
334
|
-
# rescue StandardError
|
335
|
-
# []
|
336
|
-
# end
|
337
|
-
#
|
338
|
-
# @example ledger_fr
|
339
|
-
# [
|
340
|
-
# {
|
341
|
-
# uuid: '50551e61-4e74-4ae7-85fd-9c2040542818',
|
342
|
-
# currency_amount: nil,
|
343
|
-
# state: 'executed',
|
344
|
-
# btc_fee: '0.0',
|
345
|
-
# currency_fee: '0.0',
|
346
|
-
# created_at: '2014-03-04T09:00Z',
|
347
|
-
# updated_at: '2014-03-04T09:00Z',
|
348
|
-
# currency: 'EUR',
|
349
|
-
# comment: '5723',
|
350
|
-
# amount: '100.0',
|
351
|
-
# type: 'WireDeposit',
|
352
|
-
# account_operations: [{
|
353
|
-
# uuid: 'b5058a68-cf99-4438-86d3-e773eba418ec',
|
354
|
-
# name: 'wire_deposit',
|
355
|
-
# amount: '100.0',
|
356
|
-
# currency: 'EUR',
|
357
|
-
# created_at: '2014-03-04T09:00Z',
|
358
|
-
# created_at_int: 1_393_923_644,
|
359
|
-
# is_trading_account: false
|
360
|
-
# }, {}]
|
361
|
-
# },
|
362
|
-
# {}
|
363
|
-
# ]
|
364
|
-
# @param (see trades_de)
|
365
|
-
# @return [Array<Hash>] lista ledger paymium
|
366
|
-
# def ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders')
|
367
|
-
# res = JSON.parse(
|
368
|
-
# Curl.get(uri, offset: pag) { |obj| obj.headers = hfr("#{uri}?#{URI.encode_www_form(offset: pag)}") }.body,
|
369
|
-
# symbolize_names: true
|
370
|
-
# )
|
371
|
-
# res.empty? ? ary : ledger_fr(pag + res.size, ary + res)
|
372
|
-
# rescue StandardError
|
373
|
-
# ary
|
374
|
-
# end
|
375
|
-
#
|
376
|
-
# @example ledger_mt
|
377
|
-
# {
|
378
|
-
# transactions: [
|
379
|
-
# {
|
380
|
-
# id: 305_445,
|
381
|
-
# date: '2014-03-06T10:59:13.000Z',
|
382
|
-
# type: 'withdraw',
|
383
|
-
# price: 97.47,
|
384
|
-
# currency: 'EUR',
|
385
|
-
# fund_id: nil,
|
386
|
-
# order_id: nil,
|
387
|
-
# trade_id: nil,
|
388
|
-
# note: 'BOV withdraw',
|
389
|
-
# transfer_detail: nil
|
390
|
-
# },
|
391
|
-
# {}
|
392
|
-
# ],
|
393
|
-
# meta: {
|
394
|
-
# total_count: nil,
|
395
|
-
# first: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
|
396
|
-
# previous: nil,
|
397
|
-
# current: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
|
398
|
-
# next: { page: 2, href: 'https://api.therocktrading.com/v1/transactions?page=2' },
|
399
|
-
# last: nil
|
400
|
-
# }
|
401
|
-
# }
|
402
|
-
# @param (see trades_de)
|
403
|
-
# @return [Array<Hash>] lista ledger therock
|
404
|
-
# def ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions')
|
405
|
-
# res = JSON.parse(
|
406
|
-
# Curl.get(uri, page: pag) { |obj| obj.headers = hmt("#{uri}?#{URI.encode_www_form(page: pag)}") }.body,
|
407
|
-
# symbolize_names: true
|
408
|
-
# )[:transactions]
|
409
|
-
# res.empty? ? ary : ledger_mt(pag + res.size, ary + res)
|
410
|
-
# rescue StandardError
|
411
|
-
# ary
|
412
|
-
# end
|
117
|
+
# @return [Hash] ledger kraken
|
118
|
+
def ledger_us
|
119
|
+
uri = 'Ledgers'
|
120
|
+
has = {}
|
121
|
+
ofs = 0
|
122
|
+
loop do
|
123
|
+
sleep(2)
|
124
|
+
ops = { nonce: nnc, ofs: ofs }
|
125
|
+
result = parse_json(Curl.post("#{API[:us]}/#{uri}", ops) { |hed| hed.headers = hus(uri, ops) }).fetch(:result, {})
|
126
|
+
break if result.fetch(:ledger, []).empty?
|
127
|
+
|
128
|
+
has.merge!(result[:ledger])
|
129
|
+
ofs += result[:ledger].size
|
130
|
+
end
|
131
|
+
has
|
132
|
+
rescue Curl::Err::CurlError
|
133
|
+
has
|
134
|
+
end
|
413
135
|
|
414
136
|
private
|
415
137
|
|
138
|
+
# Safe JSON parsing with error handling
|
139
|
+
def parse_json(res)
|
140
|
+
JSON.parse(res.body, symbolize_names: true) || {}
|
141
|
+
rescue JSON::ParserError
|
142
|
+
{}
|
143
|
+
end
|
144
|
+
|
416
145
|
# @return [Integer] continually-increasing unsigned integer nonce from the current Unix Time
|
417
146
|
def nnc
|
418
147
|
Integer(Float(Time.now) * 1e6)
|
@@ -423,56 +152,20 @@ module Cns
|
|
423
152
|
# @return [Hash] headers necessarios para pedido HTTP da exchange bitcoinde
|
424
153
|
def hde(qde, non = nnc)
|
425
154
|
key = ENV.fetch('BITCOINDE_API_KEY', nil)
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
'X-API-SIGNATURE': OpenSSL::HMAC.hexdigest(
|
430
|
-
'sha256',
|
431
|
-
ENV.fetch('BITCOINDE_API_SECRET', nil),
|
432
|
-
['GET', qde, key, non, Digest::MD5.hexdigest('')].join('#')
|
433
|
-
)
|
434
|
-
}
|
155
|
+
md5 = ['GET', qde, key, non, Digest::MD5.hexdigest('')].join('#')
|
156
|
+
mac = OpenSSL::HMAC.hexdigest('sha256', ENV.fetch('BITCOINDE_API_SECRET', nil), md5)
|
157
|
+
{ 'X-API-KEY': key, 'X-API-NONCE': non, 'X-API-SIGNATURE': mac }
|
435
158
|
end
|
436
159
|
|
437
|
-
# @param [String] qfr query a incluir no pedido HTTP
|
438
|
-
# @param non (see hde)
|
439
|
-
# @return [Hash] headers necessarios para pedido HTTP da exchange paymium
|
440
|
-
# def hfr(qfr, non = nnc)
|
441
|
-
# {
|
442
|
-
# content_type: 'application/json',
|
443
|
-
# 'Api-Key': ENV['PAYMIUM_API_KEY'],
|
444
|
-
# 'Api-Nonce': non,
|
445
|
-
# 'Api-Signature': OpenSSL::HMAC.hexdigest('sha256', ENV['PAYMIUM_API_SECRET'], [non, qfr].join)
|
446
|
-
# }
|
447
|
-
# end
|
448
|
-
#
|
449
|
-
# @param [String] qmt query a incluir no pedido HTTP
|
450
|
-
# @param non (see hde)
|
451
|
-
# @return [Hash] headers necessarios para pedido HTTP da exchange therock
|
452
|
-
# def hmt(qmt, non = nnc)
|
453
|
-
# {
|
454
|
-
# content_type: 'application/json',
|
455
|
-
# 'X-TRT-KEY': ENV['THEROCK_API_KEY'],
|
456
|
-
# 'X-TRT-NONCE': non,
|
457
|
-
# 'X-TRT-SIGN': OpenSSL::HMAC.hexdigest('sha512', ENV['THEROCK_API_SECRET'], [non, qmt].join)
|
458
|
-
# }
|
459
|
-
# end
|
460
|
-
|
461
160
|
# @param [String] qus query a incluir no pedido HTTP
|
462
161
|
# @param [Hash] ops opcoes trabalho
|
463
162
|
# @option ops [Hash] :nonce continually-increasing unsigned integer
|
464
163
|
# @return [Hash] headers necessarios para pedido HTTP da exchange kraken
|
465
164
|
def hus(qus, ops)
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
'sha512',
|
471
|
-
Base64.decode64(ENV.fetch('KRAKEN_API_SECRET', nil)),
|
472
|
-
['/0/private/', qus, Digest::SHA256.digest("#{ops[:nonce]}#{URI.encode_www_form(ops)}")].join
|
473
|
-
)
|
474
|
-
)
|
475
|
-
}
|
165
|
+
key = ENV.fetch('KRAKEN_API_KEY', nil)
|
166
|
+
sha = ['/0/private/', qus, Digest::SHA256.digest("#{ops[:nonce]}#{URI.encode_www_form(ops)}")].join
|
167
|
+
mac = OpenSSL::HMAC.digest('sha512', Base64.decode64(ENV.fetch('KRAKEN_API_SECRET', nil)), sha)
|
168
|
+
{ 'api-key': key, 'api-sign': Base64.strict_encode64(mac) }
|
476
169
|
end
|
477
170
|
end
|
478
171
|
end
|
data/lib/cns/bigquery.rb
CHANGED
@@ -453,7 +453,6 @@ module Cns
|
|
453
453
|
"#{ops[:h][String(hlx[:itx])] || 0})"
|
454
454
|
end
|
455
455
|
|
456
|
-
# @example (see Apice#trades_de)
|
457
456
|
# @param [Hash] htx trade bitcoinde
|
458
457
|
# @return [String] valores formatados det (trades parte1)
|
459
458
|
def det_val(htx)
|
@@ -469,8 +468,6 @@ module Cns
|
|
469
468
|
"#{Integer(ops[:h][htx[:trade_id]] || 0)})"
|
470
469
|
end
|
471
470
|
|
472
|
-
# @example (see Apice#deposits_de)
|
473
|
-
# @example (see Apice#withdrawals_de)
|
474
471
|
# @param [Hash] hlx ledger (deposits + withdrawals) bitcoinde
|
475
472
|
# @return [String] valores formatados del (ledger)
|
476
473
|
def del_val(hlx)
|
@@ -484,7 +481,6 @@ module Cns
|
|
484
481
|
"cast(#{hlx[:fee]} as numeric))"
|
485
482
|
end
|
486
483
|
|
487
|
-
# @example (see Apice#trades_us)
|
488
484
|
# @param [String] idx identificador transacao
|
489
485
|
# @param [Hash] htx trade kraken
|
490
486
|
# @return [String] valores formatados ust (trades parte1)
|
@@ -506,7 +502,6 @@ module Cns
|
|
506
502
|
"#{Integer(ops[:h][idx] || 0)})"
|
507
503
|
end
|
508
504
|
|
509
|
-
# @example (see Apice#ledger_us)
|
510
505
|
# @param idx (see ust_val)
|
511
506
|
# @param [Hash] hlx ledger kraken
|
512
507
|
# @return [String] valores formatados usl (ledger)
|
data/lib/cns/bitcoinde.rb
CHANGED
@@ -63,7 +63,6 @@ module Cns
|
|
63
63
|
@kyl ||= exd[:tl].map { |oex| oex[:txid] }.flatten - (ops[:t] ? [] : bqd[:nl].map { |obq| obq[:txid] })
|
64
64
|
end
|
65
65
|
|
66
|
-
# @example (see Apice#account_de)
|
67
66
|
# @param [String] moe codigo bitcoinde da moeda
|
68
67
|
# @param [Hash] hsx saldo bitcoinde da moeda
|
69
68
|
# @return [String] texto formatado saldos
|
@@ -79,7 +78,6 @@ module Cns
|
|
79
78
|
)
|
80
79
|
end
|
81
80
|
|
82
|
-
# @example (see Apice#trades_de)
|
83
81
|
# @param (see Bigquery#det_val1)
|
84
82
|
# @return [String] texto formatado trade
|
85
83
|
def formata_trades(htx)
|
@@ -95,8 +93,6 @@ module Cns
|
|
95
93
|
)
|
96
94
|
end
|
97
95
|
|
98
|
-
# @example (see Apice#deposits_unif_de)
|
99
|
-
# @example (see Apice#withdrawals_unif_de)
|
100
96
|
# @param (see Bigquery#del_val)
|
101
97
|
# @return [String] texto formatado ledger
|
102
98
|
def formata_ledger(hlx)
|
data/lib/cns/greymass.rb
CHANGED
@@ -83,11 +83,7 @@ module Cns
|
|
83
83
|
def greymass_sl(add)
|
84
84
|
hac = api.account_gm(add)
|
85
85
|
htr = hac[:total_resources]
|
86
|
-
[
|
87
|
-
hac[:core_liquid_balance].to_d,
|
88
|
-
htr[:net_weight].to_d,
|
89
|
-
htr[:cpu_weight].to_d
|
90
|
-
]
|
86
|
+
[hac[:core_liquid_balance].to_d, htr[:net_weight].to_d, htr[:cpu_weight].to_d]
|
91
87
|
end
|
92
88
|
|
93
89
|
# @param add (see Apibc#account_gm)
|
data/lib/cns/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hernâni Rodrigues Vaz
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-02-
|
10
|
+
date: 2025-02-18 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bundler
|