Class: Cns::Apice
- Inherits:
-
Object
- Object
- Cns::Apice
- Defined in:
- lib/cns/apice.rb
Overview
classe para acesso dados centralized exchanges
Instance Method Summary collapse
-
#account_de(uri = 'https://api.bitcoin.de/v4/account') ⇒ Hash
Saldos no bitcoinde.
-
#account_fr(uri = 'https://paymium.com/api/v1/user') ⇒ Hash
Saldos no paymium.
-
#account_mt(uri = 'https://api.therocktrading.com/v1/balances') ⇒ Array<Hash>
Lista saldos no therock.
-
#account_us(urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc) ⇒ Hash
Saldos no kraken.
-
#deposit_unif(has) ⇒ Hash
Deposit uniformizado bitcoinde.
-
#deposits_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/deposits') ⇒ Array<Hash>
Lista completa uniformizada depositos bitcoinde.
-
#ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders') ⇒ Array<Hash>
Lista ledger paymium.
-
#ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions') ⇒ Array<Hash>
Lista ledger therock.
-
#ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private') ⇒ Hash
Dados ledger kraken.
-
#trades_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/trades') ⇒ Array<Hash>
Lista completa trades bitcoinde.
-
#trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private') ⇒ Hash
Dados trades kraken.
-
#withdrawal_unif(has) ⇒ Hash
Withdrawal uniformizada bitcoinde.
-
#withdrawals_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/withdrawals') ⇒ Array<Hash>
Lista completa uniformizada withdrawals bitcoinde.
Instance Method Details
#account_de(uri = 'https://api.bitcoin.de/v4/account') ⇒ Hash
Returns saldos no bitcoinde.
32 33 34 35 36 37 38 39 |
# File 'lib/cns/apice.rb', line 32 def account_de(uri = 'https://api.bitcoin.de/v4/account') JSON.parse( Curl.get(uri) { |obj| obj.headers = hde(uri) }.body, symbolize_names: true )[:data][:balances] rescue StandardError {} end |
#account_fr(uri = 'https://paymium.com/api/v1/user') ⇒ Hash
Returns saldos no paymium.
57 58 59 60 61 62 63 64 |
# File 'lib/cns/apice.rb', line 57 def account_fr(uri = 'https://paymium.com/api/v1/user') JSON.parse( Curl.get(uri) { |obj| obj.headers = hfr(uri) }.body, symbolize_names: true ) rescue StandardError {} end |
#account_mt(uri = 'https://api.therocktrading.com/v1/balances') ⇒ Array<Hash>
Returns lista saldos no therock.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cns/apice.rb', line 77 def account_mt(uri = 'https://api.therocktrading.com/v1/balances') JSON.parse( Curl.get(uri) { |obj| obj.headers = hmt(uri) }.body, symbolize_names: true )[:balances] .delete_if { |del| DC.include?(del[:currency]) } .sort { |oba, obb| oba[:currency] <=> obb[:currency] } rescue StandardError [] end |
#account_us(urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc) ⇒ Hash
Returns saldos no kraken.
104 105 106 107 108 109 110 111 |
# File 'lib/cns/apice.rb', line 104 def account_us(urb = 'https://api.kraken.com/0/private', uri = 'Balance', non = nnc) JSON.parse( Curl.post("#{urb}/#{uri}", nonce: non) { |obj| obj.headers = hus(uri, nonce: non) }.body, symbolize_names: true )[:result] rescue StandardError {} end |
#deposit_unif(has) ⇒ Hash
Returns deposit uniformizado bitcoinde.
207 208 209 210 211 212 213 214 |
# File 'lib/cns/apice.rb', line 207 def deposit_unif(has) { add: has[:address], time: Time.parse(has[:created_at]), qt: has[:amount], txid: Integer(has[:deposit_id]) }.merge(tp: 'deposit', moe: 'btc', fee: '0') end |
#deposits_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/deposits') ⇒ Array<Hash>
Returns lista completa uniformizada depositos bitcoinde.
183 184 185 186 187 188 189 190 191 |
# File 'lib/cns/apice.rb', line 183 def deposits_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/deposits') par = "#{uri}?#{URI.encode_www_form(state: 2, page: pag += 1)}" res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true) ary += res[:deposits].map { |has| deposit_unif(has) } rep = res[:page] rep[:current] < rep[:last] ? deposits_de(pag, ary) : ary rescue StandardError ary end |
#ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders') ⇒ Array<Hash>
Returns lista ledger paymium.
300 301 302 303 304 305 306 307 308 |
# File 'lib/cns/apice.rb', line 300 def ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders') res = JSON.parse( Curl.get(uri, offset: pag) { |obj| obj.headers = hfr("#{uri}?#{URI.encode_www_form(offset: pag)}") }.body, symbolize_names: true ) res.empty? ? ary : ledger_fr(pag + res.size, ary + res) rescue StandardError ary end |
#ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions') ⇒ Array<Hash>
Returns lista ledger therock.
338 339 340 341 342 343 344 345 346 |
# File 'lib/cns/apice.rb', line 338 def ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions') res = JSON.parse( Curl.get(uri, page: pag) { |obj| obj.headers = hmt("#{uri}?#{URI.encode_www_form(page: pag)}") }.body, symbolize_names: true )[:transactions] res.empty? ? ary : ledger_mt(pag + res.size, ary + res) rescue StandardError ary end |
#ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private') ⇒ Hash
Returns dados ledger kraken.
412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/cns/apice.rb', line 412 def ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private') uri = 'Ledgers' non = nnc res = JSON.parse( Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body, symbolize_names: true )[:result] has.merge!(res[:ledger]) sleep 2 res[:ledger].count > 0 ? ledger_us(ofs + res[:ledger].count, has) : has rescue StandardError has end |
#trades_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/trades') ⇒ Array<Hash>
Returns lista completa trades bitcoinde.
153 154 155 156 157 158 159 160 161 |
# File 'lib/cns/apice.rb', line 153 def trades_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/trades') par = "#{uri}?#{URI.encode_www_form(state: 1, page: pag += 1)}" res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true) ary += res[:trades] rep = res[:page] rep[:current] < rep[:last] ? trades_de(pag, ary) : ary rescue StandardError ary end |
#trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private') ⇒ Hash
Returns dados trades kraken.
375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/cns/apice.rb', line 375 def trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private') uri = 'TradesHistory' non = nnc res = JSON.parse( Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body, symbolize_names: true )[:result] has.merge!(res[:trades]) sleep 2 res[:trades].count > 0 ? trades_us(ofs + res[:trades].count, has) : has rescue StandardError has end |
#withdrawal_unif(has) ⇒ Hash
Returns withdrawal uniformizada bitcoinde.
262 263 264 265 266 267 268 269 270 |
# File 'lib/cns/apice.rb', line 262 def withdrawal_unif(has) { add: has[:address], time: Time.parse(has[:transferred_at]), qt: has[:amount], fee: has[:network_fee], txid: Integer(has[:withdrawal_id]) }.merge(tp: 'withdrawal', moe: 'btc') end |
#withdrawals_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/withdrawals') ⇒ Array<Hash>
Returns lista completa uniformizada withdrawals bitcoinde.
238 239 240 241 242 243 244 245 246 |
# File 'lib/cns/apice.rb', line 238 def withdrawals_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/withdrawals') par = "#{uri}?#{URI.encode_www_form(state: 1, page: pag += 1)}" res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true) ary += res[:withdrawals].map { |has| withdrawal_unif(has) } rep = res[:page] rep[:current] < rep[:last] ? withdrawals_de(pag, ary) : ary rescue StandardError ary end |