cns 0.9.4 → 0.9.6
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 +77 -59
 - data/lib/cns/apice.rb +79 -36
 - data/lib/cns/bigquery.rb +6 -8
 - data/lib/cns/bitcoinde.rb +9 -9
 - data/lib/cns/etherscan.rb +14 -12
 - data/lib/cns/greymass.rb +5 -5
 - data/lib/cns/kraken.rb +27 -38
 - 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: 60e46e5d964570303d66901fde56320d6102a12ff0f53495d420dc73fc5c5045
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: fbc9a980fe5be810ee82c541ecbd769feae8ea87e84a9a2d80c356e0e8b313a0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 425413cbc19a0cbd77889e32a8cac2ba934cf32c9775e2c3bfd891d732f81c025b9f89b92e87211980b4f1e6a318a968fe369b46add18a3c133316b46ec64ceb
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3cd4b50b92b93d31abe4795d1887a24dd358ba4d7aee75edb0ff2329a0ff5b722217547dc77b2aaa944b002c3d22b3107b4a561eea4c8209e8a0a6936ad0448f
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/cns/apibc.rb
    CHANGED
    
    | 
         @@ -7,141 +7,159 @@ require('json') 
     | 
|
| 
       7 
7 
     | 
    
         
             
            module Cns
         
     | 
| 
       8 
8 
     | 
    
         
             
              # classe para acesso dados blockchains
         
     | 
| 
       9 
9 
     | 
    
         
             
              class Apibc
         
     | 
| 
       10 
     | 
    
         
            -
                ESPS = 10_000
         
     | 
| 
       11 
     | 
    
         
            -
                GMPS = 100
         
     | 
| 
      
 10 
     | 
    
         
            +
                ESPS = 10_000 # Etherscan maximum records per page
         
     | 
| 
      
 11 
     | 
    
         
            +
                GMPS = 100    # Greymass maximum actions per request
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                def initialize
         
     | 
| 
       14 
     | 
    
         
            -
                  @ 
     | 
| 
       15 
     | 
    
         
            -
                  @ 
     | 
| 
      
 14 
     | 
    
         
            +
                  @escn = connection('https://api.etherscan.io')
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @gmcn = connection('https://eos.greymass.com')
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @esky = ENV.fetch('ETHERSCAN_API_KEY', nil)
         
     | 
| 
       16 
17 
     | 
    
         
             
                end
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
19 
     | 
    
         
             
                # Get account balances for multiple ETH addresses
         
     | 
| 
       19 
     | 
    
         
            -
                # @param  
     | 
| 
      
 20 
     | 
    
         
            +
                # @param [Array<String>] addresses List of ETH addresses (max 20)
         
     | 
| 
       20 
21 
     | 
    
         
             
                # @return [Array<Hash>] List of addresses with balances
         
     | 
| 
       21 
22 
     | 
    
         
             
                def account_es(addresses)
         
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
                  return [] if addresses.empty?
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  res = es_req('balancemulti', addresses.join(','), 1, tag: 'latest')
         
     | 
| 
      
 26 
     | 
    
         
            +
                  res[:status] == '1' ? res[:result] || [] : []
         
     | 
| 
       24 
27 
     | 
    
         
             
                end
         
     | 
| 
       25 
28 
     | 
    
         | 
| 
       26 
29 
     | 
    
         
             
                # Get normal transactions for ETH address
         
     | 
| 
       27 
30 
     | 
    
         
             
                # @param [String] address endereco ETH
         
     | 
| 
       28 
31 
     | 
    
         
             
                # @return [Array<Hash>] lista transacoes normais etherscan
         
     | 
| 
       29 
32 
     | 
    
         
             
                def norml_es(address)
         
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
      
 33 
     | 
    
         
            +
                  pag_es_req('txlist', address)
         
     | 
| 
       31 
34 
     | 
    
         
             
                end
         
     | 
| 
       32 
35 
     | 
    
         | 
| 
       33 
36 
     | 
    
         
             
                # Get internal transactions for ETH address
         
     | 
| 
       34 
37 
     | 
    
         
             
                # @param (see norml_es)
         
     | 
| 
       35 
38 
     | 
    
         
             
                # @return [Array<Hash>] lista transacoes internas etherscan
         
     | 
| 
       36 
39 
     | 
    
         
             
                def inter_es(address)
         
     | 
| 
       37 
     | 
    
         
            -
                   
     | 
| 
      
 40 
     | 
    
         
            +
                  pag_es_req('txlistinternal', address)
         
     | 
| 
       38 
41 
     | 
    
         
             
                end
         
     | 
| 
       39 
42 
     | 
    
         | 
| 
       40 
43 
     | 
    
         
             
                # Get mined blocks for ETH address
         
     | 
| 
       41 
44 
     | 
    
         
             
                # @param (see norml_es)
         
     | 
| 
       42 
45 
     | 
    
         
             
                # @return [Array<Hash>] lista blocos etherscan
         
     | 
| 
       43 
46 
     | 
    
         
             
                def block_es(address)
         
     | 
| 
       44 
     | 
    
         
            -
                   
     | 
| 
      
 47 
     | 
    
         
            +
                  pag_es_req('getminedblocks', address, blocktype: 'blocks')
         
     | 
| 
       45 
48 
     | 
    
         
             
                end
         
     | 
| 
       46 
49 
     | 
    
         | 
| 
       47 
50 
     | 
    
         
             
                # Get withdrawals for ETH address
         
     | 
| 
       48 
51 
     | 
    
         
             
                # @param (see norml_es)
         
     | 
| 
       49 
52 
     | 
    
         
             
                # @return [Array<Hash>] lista blocos etherscan
         
     | 
| 
       50 
53 
     | 
    
         
             
                def withw_es(address)
         
     | 
| 
       51 
     | 
    
         
            -
                   
     | 
| 
      
 54 
     | 
    
         
            +
                  pag_es_req('txsBeaconWithdrawal', address)
         
     | 
| 
       52 
55 
     | 
    
         
             
                end
         
     | 
| 
       53 
56 
     | 
    
         | 
| 
       54 
57 
     | 
    
         
             
                # Get token transfers for ETH address
         
     | 
| 
       55 
58 
     | 
    
         
             
                # @param (see norml_es)
         
     | 
| 
       56 
59 
     | 
    
         
             
                # @return [Array<Hash>] lista token transfer events etherscan
         
     | 
| 
       57 
60 
     | 
    
         
             
                def token_es(address)
         
     | 
| 
       58 
     | 
    
         
            -
                   
     | 
| 
      
 61 
     | 
    
         
            +
                  pag_es_req('tokentx', address)
         
     | 
| 
       59 
62 
     | 
    
         
             
                end
         
     | 
| 
       60 
63 
     | 
    
         | 
| 
       61 
64 
     | 
    
         
             
                # Get EOS account information
         
     | 
| 
       62 
     | 
    
         
            -
                # @param  
     | 
| 
      
 65 
     | 
    
         
            +
                # @param [String] address EOS account name
         
     | 
| 
       63 
66 
     | 
    
         
             
                # @return [Hash] Account details with resources
         
     | 
| 
       64 
67 
     | 
    
         
             
                def account_gm(address)
         
     | 
| 
       65 
     | 
    
         
            -
                   
     | 
| 
       66 
     | 
    
         
            -
                   
     | 
| 
      
 68 
     | 
    
         
            +
                  res = gm_req('/v1/chain/get_account', account_name: address)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  res[:core_liquid_balance]&.to_d&.positive? ? res : gm_erro
         
     | 
| 
       67 
70 
     | 
    
         
             
                end
         
     | 
| 
       68 
71 
     | 
    
         | 
| 
       69 
72 
     | 
    
         
             
                # Get complete transaction history for EOS account
         
     | 
| 
       70 
73 
     | 
    
         
             
                # @param (see account_gm)
         
     | 
| 
       71 
74 
     | 
    
         
             
                # @return [Array<Hash>] lista completa transacoes greymass
         
     | 
| 
       72 
75 
     | 
    
         
             
                def ledger_gm(address)
         
     | 
| 
       73 
     | 
    
         
            -
                   
     | 
| 
      
 76 
     | 
    
         
            +
                  trx = []
         
     | 
| 
       74 
77 
     | 
    
         
             
                  pos = 0
         
     | 
| 
       75 
78 
     | 
    
         
             
                  loop do
         
     | 
| 
       76 
     | 
    
         
            -
                     
     | 
| 
       77 
     | 
    
         
            -
                     
     | 
| 
       78 
     | 
    
         
            -
                     
     | 
| 
       79 
     | 
    
         
            -
                    break if  
     | 
| 
      
 79 
     | 
    
         
            +
                    res = gm_req('/v1/history/get_actions', account_name: address, pos: pos, offset: GMPS)
         
     | 
| 
      
 80 
     | 
    
         
            +
                    bth = res[:actions] || []
         
     | 
| 
      
 81 
     | 
    
         
            +
                    trx.concat(bth)
         
     | 
| 
      
 82 
     | 
    
         
            +
                    break if bth.size < GMPS
         
     | 
| 
       80 
83 
     | 
    
         | 
| 
       81 
84 
     | 
    
         
             
                    pos += GMPS
         
     | 
| 
       82 
85 
     | 
    
         
             
                  end
         
     | 
| 
       83 
     | 
    
         
            -
                   
     | 
| 
      
 86 
     | 
    
         
            +
                  trx
         
     | 
| 
       84 
87 
     | 
    
         
             
                end
         
     | 
| 
       85 
88 
     | 
    
         | 
| 
       86 
89 
     | 
    
         
             
                private
         
     | 
| 
       87 
90 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
                #  
     | 
| 
       89 
     | 
    
         
            -
                 
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                  end
         
     | 
| 
       97 
     | 
    
         
            -
                end
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
                # Generic Etherscan API request handler
         
     | 
| 
       100 
     | 
    
         
            -
                def etherscan_req(action, address, page = 1, params = {})
         
     | 
| 
       101 
     | 
    
         
            -
                  params = {module: 'account', action: action, address: address, page: page, apikey: ENV.fetch('ETHERSCAN_API_KEY')}.merge(params)
         
     | 
| 
       102 
     | 
    
         
            -
                  parse_json(@etherscan_conn.get('/api', params))
         
     | 
| 
      
 91 
     | 
    
         
            +
                # Make a request to the Etherscan API
         
     | 
| 
      
 92 
     | 
    
         
            +
                # @param [String] act API action name
         
     | 
| 
      
 93 
     | 
    
         
            +
                # @param [String] add Blockchain address
         
     | 
| 
      
 94 
     | 
    
         
            +
                # @param [Integer] pag Page number for pagination
         
     | 
| 
      
 95 
     | 
    
         
            +
                # @param [Hash] prm Additional request parameters
         
     | 
| 
      
 96 
     | 
    
         
            +
                # @return [Hash] Parsed API response
         
     | 
| 
      
 97 
     | 
    
         
            +
                def es_req(act, add, pag = 1, prm = {})
         
     | 
| 
      
 98 
     | 
    
         
            +
                  parse_json(@escn.get('/api', prm.merge(module: 'account', action: act, address: add, page: pag, apikey: @esky)))
         
     | 
| 
       103 
99 
     | 
    
         
             
                rescue Faraday::Error
         
     | 
| 
       104 
100 
     | 
    
         
             
                  {status: '0'}
         
     | 
| 
       105 
101 
     | 
    
         
             
                end
         
     | 
| 
       106 
102 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
                #  
     | 
| 
       108 
     | 
    
         
            -
                # @param  
     | 
| 
       109 
     | 
    
         
            -
                # @param  
     | 
| 
       110 
     | 
    
         
            -
                # @param  
     | 
| 
      
 103 
     | 
    
         
            +
                # Fetch paginated results from Etherscan
         
     | 
| 
      
 104 
     | 
    
         
            +
                # @param act [String] API action name
         
     | 
| 
      
 105 
     | 
    
         
            +
                # @param add [String] Blockchain address
         
     | 
| 
      
 106 
     | 
    
         
            +
                # @param prm [Hash] Additional request parameters
         
     | 
| 
       111 
107 
     | 
    
         
             
                # @return [Array<Hash>] Combined results from all pages
         
     | 
| 
       112 
     | 
    
         
            -
                def  
     | 
| 
       113 
     | 
    
         
            -
                   
     | 
| 
       114 
     | 
    
         
            -
                   
     | 
| 
      
 108 
     | 
    
         
            +
                def pag_es_req(act, add, prm = {})
         
     | 
| 
      
 109 
     | 
    
         
            +
                  prm = prm.merge(offset: ESPS)
         
     | 
| 
      
 110 
     | 
    
         
            +
                  trx = []
         
     | 
| 
      
 111 
     | 
    
         
            +
                  pag = 1
         
     | 
| 
       115 
112 
     | 
    
         
             
                  loop do
         
     | 
| 
       116 
     | 
    
         
            -
                     
     | 
| 
       117 
     | 
    
         
            -
                    break unless  
     | 
| 
      
 113 
     | 
    
         
            +
                    res = es_req(act, add, pag, prm)
         
     | 
| 
      
 114 
     | 
    
         
            +
                    break unless res[:status] == '1'
         
     | 
| 
       118 
115 
     | 
    
         | 
| 
       119 
     | 
    
         
            -
                     
     | 
| 
       120 
     | 
    
         
            -
                     
     | 
| 
       121 
     | 
    
         
            -
                    break if  
     | 
| 
      
 116 
     | 
    
         
            +
                    bth = res[:result] || []
         
     | 
| 
      
 117 
     | 
    
         
            +
                    trx.concat(bth)
         
     | 
| 
      
 118 
     | 
    
         
            +
                    break if bth.size < ESPS
         
     | 
| 
       122 
119 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
                     
     | 
| 
      
 120 
     | 
    
         
            +
                    pag += 1
         
     | 
| 
       124 
121 
     | 
    
         
             
                  end
         
     | 
| 
       125 
     | 
    
         
            -
                   
     | 
| 
       126 
     | 
    
         
            -
                end
         
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
                # Generic Greymass API error
         
     | 
| 
       129 
     | 
    
         
            -
                def gm_erro
         
     | 
| 
       130 
     | 
    
         
            -
                  {core_liquid_balance: 0, total_resources: {net_weight: 0, cpu_weight: 0}}
         
     | 
| 
      
 122 
     | 
    
         
            +
                  trx
         
     | 
| 
       131 
123 
     | 
    
         
             
                end
         
     | 
| 
       132 
124 
     | 
    
         | 
| 
       133 
     | 
    
         
            -
                #  
     | 
| 
       134 
     | 
    
         
            -
                 
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
      
 125 
     | 
    
         
            +
                # Make a request to the Greymass API
         
     | 
| 
      
 126 
     | 
    
         
            +
                # @param [String] url API endpoint
         
     | 
| 
      
 127 
     | 
    
         
            +
                # @param [Hash] pyl Request payload
         
     | 
| 
      
 128 
     | 
    
         
            +
                # @return [Hash] Parsed API response
         
     | 
| 
      
 129 
     | 
    
         
            +
                def gm_req(url, pyl)
         
     | 
| 
      
 130 
     | 
    
         
            +
                  parse_json(@gmcn.post(url) { |r| r.body = pyl })
         
     | 
| 
       136 
131 
     | 
    
         
             
                rescue Faraday::Error
         
     | 
| 
       137 
132 
     | 
    
         
             
                  gm_erro
         
     | 
| 
       138 
133 
     | 
    
         
             
                end
         
     | 
| 
       139 
134 
     | 
    
         | 
| 
       140 
     | 
    
         
            -
                #  
     | 
| 
      
 135 
     | 
    
         
            +
                # Default error response for Greymass API
         
     | 
| 
      
 136 
     | 
    
         
            +
                # @return [Hash] Error response with zeroed values
         
     | 
| 
      
 137 
     | 
    
         
            +
                def gm_erro
         
     | 
| 
      
 138 
     | 
    
         
            +
                  {core_liquid_balance: 0, total_resources: {net_weight: 0, cpu_weight: 0}}
         
     | 
| 
      
 139 
     | 
    
         
            +
                end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                # Safely parse JSON response
         
     | 
| 
      
 142 
     | 
    
         
            +
                # @param [Faraday::Response] res API response
         
     | 
| 
      
 143 
     | 
    
         
            +
                # @return [Hash] Parsed JSON or empty hash on error
         
     | 
| 
       141 
144 
     | 
    
         
             
                def parse_json(res)
         
     | 
| 
      
 145 
     | 
    
         
            +
                  return {} if res.body.to_s.empty?
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
       142 
147 
     | 
    
         
             
                  JSON.parse(res.body, symbolize_names: true) || {}
         
     | 
| 
       143 
148 
     | 
    
         
             
                rescue JSON::ParserError
         
     | 
| 
       144 
149 
     | 
    
         
             
                  {}
         
     | 
| 
       145 
150 
     | 
    
         
             
                end
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                # Create a Faraday connection with JSON configuration
         
     | 
| 
      
 153 
     | 
    
         
            +
                # @param [String] url Base URL for the API
         
     | 
| 
      
 154 
     | 
    
         
            +
                # @return [Faraday::Connection] Configured Faraday connection
         
     | 
| 
      
 155 
     | 
    
         
            +
                def connection(url)
         
     | 
| 
      
 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)
         
     | 
| 
      
 162 
     | 
    
         
            +
                  end
         
     | 
| 
      
 163 
     | 
    
         
            +
                end
         
     | 
| 
       146 
164 
     | 
    
         
             
              end
         
     | 
| 
       147 
165 
     | 
    
         
             
            end
         
     | 
    
        data/lib/cns/apice.rb
    CHANGED
    
    | 
         @@ -17,8 +17,13 @@ module Cns 
     | 
|
| 
       17 
17 
     | 
    
         
             
                  @curl.connect_timeout = 10
         
     | 
| 
       18 
18 
     | 
    
         
             
                  @curl.follow_location = true
         
     | 
| 
       19 
19 
     | 
    
         
             
                  @curl.ssl_verify_peer = true
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @deky = ENV.fetch('BITCOINDE_API_KEY', nil)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @desc = ENV.fetch('BITCOINDE_API_SECRET', nil)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @usky = ENV.fetch('KRAKEN_API_KEY', nil)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @ussc = ENV.fetch('KRAKEN_API_SECRET', nil)
         
     | 
| 
       20 
24 
     | 
    
         
             
                end
         
     | 
| 
       21 
25 
     | 
    
         | 
| 
      
 26 
     | 
    
         
            +
                # Get account balances from Bitcoin.de
         
     | 
| 
       22 
27 
     | 
    
         
             
                # @return [Hash] saldos no bitcoinde
         
     | 
| 
       23 
28 
     | 
    
         
             
                def account_de
         
     | 
| 
       24 
29 
     | 
    
         
             
                  uri = "#{API[:de]}/account"
         
     | 
| 
         @@ -28,6 +33,7 @@ module Cns 
     | 
|
| 
       28 
33 
     | 
    
         
             
                  {}
         
     | 
| 
       29 
34 
     | 
    
         
             
                end
         
     | 
| 
       30 
35 
     | 
    
         | 
| 
      
 36 
     | 
    
         
            +
                # Get trades from Bitcoin.de
         
     | 
| 
       31 
37 
     | 
    
         
             
                # @return [Array<Hash>] trades bitcoinde
         
     | 
| 
       32 
38 
     | 
    
         
             
                def trades_de
         
     | 
| 
       33 
39 
     | 
    
         
             
                  pag_de_req("#{API[:de]}/trades", {state: 1}, :trades)
         
     | 
| 
         @@ -35,6 +41,7 @@ module Cns 
     | 
|
| 
       35 
41 
     | 
    
         
             
                  []
         
     | 
| 
       36 
42 
     | 
    
         
             
                end
         
     | 
| 
       37 
43 
     | 
    
         | 
| 
      
 44 
     | 
    
         
            +
                # Get deposits from Bitcoin.de, uniformly formatted
         
     | 
| 
       38 
45 
     | 
    
         
             
                # @return [Array<Hash>] depositos uniformizados bitcoinde
         
     | 
| 
       39 
46 
     | 
    
         
             
                def deposits_de
         
     | 
| 
       40 
47 
     | 
    
         
             
                  pag_de_req("#{API[:de]}/btc/deposits", {state: 2}, :deposits) { |i| i.map { |h| deposit_unif(h) } }
         
     | 
| 
         @@ -42,6 +49,7 @@ module Cns 
     | 
|
| 
       42 
49 
     | 
    
         
             
                  []
         
     | 
| 
       43 
50 
     | 
    
         
             
                end
         
     | 
| 
       44 
51 
     | 
    
         | 
| 
      
 52 
     | 
    
         
            +
                # Get withdrawals from Bitcoin.de, uniformly formatted
         
     | 
| 
       45 
53 
     | 
    
         
             
                # @return [Array<Hash>] withdrawals uniformizadas bitcoinde
         
     | 
| 
       46 
54 
     | 
    
         
             
                def withdrawals_de
         
     | 
| 
       47 
55 
     | 
    
         
             
                  pag_de_req("#{API[:de]}/btc/withdrawals", {state: 1}, :withdrawals) { |i| i.map { |h| withdrawal_unif(h) } }
         
     | 
| 
         @@ -49,60 +57,83 @@ module Cns 
     | 
|
| 
       49 
57 
     | 
    
         
             
                  []
         
     | 
| 
       50 
58 
     | 
    
         
             
                end
         
     | 
| 
       51 
59 
     | 
    
         | 
| 
      
 60 
     | 
    
         
            +
                # Get account balances from Kraken
         
     | 
| 
       52 
61 
     | 
    
         
             
                # @return [Hash] saldos kraken
         
     | 
| 
       53 
62 
     | 
    
         
             
                def account_us
         
     | 
| 
       54 
63 
     | 
    
         
             
                  uri = 'Balance'
         
     | 
| 
       55 
64 
     | 
    
         
             
                  ops = {nonce: nnc}
         
     | 
| 
       56 
     | 
    
         
            -
                  run_curl(@curl, "#{API[:us]}/#{uri}", method:  
     | 
| 
      
 65 
     | 
    
         
            +
                  run_curl(@curl, "#{API[:us]}/#{uri}", method: 'POST', post_data: ops, headers: hus(uri, ops))
         
     | 
| 
       57 
66 
     | 
    
         
             
                  parse_json(@curl).fetch(:result, {})
         
     | 
| 
       58 
67 
     | 
    
         
             
                rescue Curl::Err::CurlError
         
     | 
| 
       59 
68 
     | 
    
         
             
                  {}
         
     | 
| 
       60 
69 
     | 
    
         
             
                end
         
     | 
| 
       61 
70 
     | 
    
         | 
| 
      
 71 
     | 
    
         
            +
                # Get trades from Kraken
         
     | 
| 
       62 
72 
     | 
    
         
             
                # @return [Hash] trades kraken
         
     | 
| 
       63 
73 
     | 
    
         
             
                def trades_us
         
     | 
| 
       64 
74 
     | 
    
         
             
                  pag_us_req('TradesHistory', :trades)
         
     | 
| 
       65 
75 
     | 
    
         
             
                rescue Curl::Err::CurlError
         
     | 
| 
       66 
     | 
    
         
            -
                   
     | 
| 
      
 76 
     | 
    
         
            +
                  []
         
     | 
| 
       67 
77 
     | 
    
         
             
                end
         
     | 
| 
       68 
78 
     | 
    
         | 
| 
      
 79 
     | 
    
         
            +
                # Get ledger from Kraken
         
     | 
| 
       69 
80 
     | 
    
         
             
                # @return [Hash] ledger kraken
         
     | 
| 
       70 
81 
     | 
    
         
             
                def ledger_us
         
     | 
| 
       71 
82 
     | 
    
         
             
                  pag_us_req('Ledgers', :ledger)
         
     | 
| 
       72 
83 
     | 
    
         
             
                rescue Curl::Err::CurlError
         
     | 
| 
       73 
     | 
    
         
            -
                   
     | 
| 
      
 84 
     | 
    
         
            +
                  []
         
     | 
| 
       74 
85 
     | 
    
         
             
                end
         
     | 
| 
       75 
86 
     | 
    
         | 
| 
       76 
87 
     | 
    
         
             
                private
         
     | 
| 
       77 
88 
     | 
    
         | 
| 
      
 89 
     | 
    
         
            +
                # Uniformly format transacao kraken
         
     | 
| 
      
 90 
     | 
    
         
            +
                # @param [Symbol] key id da transacao
         
     | 
| 
      
 91 
     | 
    
         
            +
                # @param [Hash] trx transacao
         
     | 
| 
      
 92 
     | 
    
         
            +
                # @return [Hash] transacao uniformizada
         
     | 
| 
      
 93 
     | 
    
         
            +
                def us_unif(key, trx)
         
     | 
| 
      
 94 
     | 
    
         
            +
                  t = trx[:time].to_i
         
     | 
| 
      
 95 
     | 
    
         
            +
                  trx.merge(txid: key.to_s, srx: t, time: Time.at(t))
         
     | 
| 
      
 96 
     | 
    
         
            +
                rescue ArgumentError
         
     | 
| 
      
 97 
     | 
    
         
            +
                  trx.merge(txid: key.to_s, srx: 0, time: Time.at(0))
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
       78 
100 
     | 
    
         
             
                # Generic paginated request handler for Kraken
         
     | 
| 
      
 101 
     | 
    
         
            +
                # @param [String] uri API endpoint URI
         
     | 
| 
      
 102 
     | 
    
         
            +
                # @param [Symbol] key Key to extract from the result
         
     | 
| 
      
 103 
     | 
    
         
            +
                # @yield [Array<Hash>] Block to process each batch of results
         
     | 
| 
      
 104 
     | 
    
         
            +
                # @return [Array<Hash>] Combined results from all pages
         
     | 
| 
       79 
105 
     | 
    
         
             
                def pag_us_req(uri, key)
         
     | 
| 
       80 
     | 
    
         
            -
                   
     | 
| 
      
 106 
     | 
    
         
            +
                  ary = []
         
     | 
| 
       81 
107 
     | 
    
         
             
                  ofs = 0
         
     | 
| 
       82 
108 
     | 
    
         
             
                  loop do
         
     | 
| 
       83 
109 
     | 
    
         
             
                    sleep(ofs.zero? ? 0 : 2)
         
     | 
| 
       84 
110 
     | 
    
         
             
                    ops = {nonce: nnc, ofs: ofs}
         
     | 
| 
       85 
     | 
    
         
            -
                    run_curl(@curl, "#{API[:us]}/#{uri}", method:  
     | 
| 
       86 
     | 
    
         
            -
                     
     | 
| 
       87 
     | 
    
         
            -
                    break if  
     | 
| 
      
 111 
     | 
    
         
            +
                    run_curl(@curl, "#{API[:us]}/#{uri}", method: 'POST', post_data: ops, headers: hus(uri, ops))
         
     | 
| 
      
 112 
     | 
    
         
            +
                    bth = parse_json(@curl).fetch(:result, {}).fetch(key, []).map { |k, v| us_unif(k, v) }
         
     | 
| 
      
 113 
     | 
    
         
            +
                    break if bth.empty?
         
     | 
| 
       88 
114 
     | 
    
         | 
| 
       89 
     | 
    
         
            -
                     
     | 
| 
       90 
     | 
    
         
            -
                    ofs +=  
     | 
| 
      
 115 
     | 
    
         
            +
                    ary.concat(bth)
         
     | 
| 
      
 116 
     | 
    
         
            +
                    ofs += bth.size
         
     | 
| 
       91 
117 
     | 
    
         
             
                  end
         
     | 
| 
       92 
     | 
    
         
            -
                   
     | 
| 
      
 118 
     | 
    
         
            +
                  ary
         
     | 
| 
       93 
119 
     | 
    
         
             
                end
         
     | 
| 
       94 
120 
     | 
    
         | 
| 
       95 
121 
     | 
    
         
             
                # Generic paginated request handler for Bitcoin.de
         
     | 
| 
       96 
     | 
    
         
            -
                 
     | 
| 
      
 122 
     | 
    
         
            +
                # @param [String] uri Base URL for the API request
         
     | 
| 
      
 123 
     | 
    
         
            +
                # @param [Hash] prm Additional parameters for the request
         
     | 
| 
      
 124 
     | 
    
         
            +
                # @param [Symbol] key Key to extract from the result
         
     | 
| 
      
 125 
     | 
    
         
            +
                # @yield [Array<Hash>] Optional block to process each batch of results
         
     | 
| 
      
 126 
     | 
    
         
            +
                # @return [Array<Hash>] Combined results from all pages
         
     | 
| 
      
 127 
     | 
    
         
            +
                def pag_de_req(uri, prm, key)
         
     | 
| 
       97 
128 
     | 
    
         
             
                  ary = []
         
     | 
| 
       98 
129 
     | 
    
         
             
                  pag = 1
         
     | 
| 
       99 
130 
     | 
    
         
             
                  loop do
         
     | 
| 
       100 
     | 
    
         
            -
                    url = "#{ 
     | 
| 
      
 131 
     | 
    
         
            +
                    url = "#{uri}?#{URI.encode_www_form(prm.merge(page: pag))}"
         
     | 
| 
       101 
132 
     | 
    
         
             
                    run_curl(@curl, url, headers: hde(url))
         
     | 
| 
       102 
     | 
    
         
            -
                     
     | 
| 
       103 
     | 
    
         
            -
                     
     | 
| 
       104 
     | 
    
         
            -
                    ary.concat(block_given? ? yield( 
     | 
| 
       105 
     | 
    
         
            -
                    break if  
     | 
| 
      
 133 
     | 
    
         
            +
                    res = parse_json(@curl)
         
     | 
| 
      
 134 
     | 
    
         
            +
                    bth = res.fetch(key, [])
         
     | 
| 
      
 135 
     | 
    
         
            +
                    ary.concat(block_given? ? yield(bth) : bth)
         
     | 
| 
      
 136 
     | 
    
         
            +
                    break if res[:page]&.[](:current)&.>= res[:page]&.[](:last)
         
     | 
| 
       106 
137 
     | 
    
         | 
| 
       107 
138 
     | 
    
         
             
                    pag += 1
         
     | 
| 
       108 
139 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -110,64 +141,76 @@ module Cns 
     | 
|
| 
       110 
141 
     | 
    
         
             
                end
         
     | 
| 
       111 
142 
     | 
    
         | 
| 
       112 
143 
     | 
    
         
             
                # Configure Curl object for request
         
     | 
| 
       113 
     | 
    
         
            -
                 
     | 
| 
      
 144 
     | 
    
         
            +
                # @param [Curl::Easy] curl Curl object to configure
         
     | 
| 
      
 145 
     | 
    
         
            +
                # @param [String] url URL for the request
         
     | 
| 
      
 146 
     | 
    
         
            +
                # @param [String] method HTTP method (GET or POST)
         
     | 
| 
      
 147 
     | 
    
         
            +
                # @param [Hash] post_data Data to send in POST requests
         
     | 
| 
      
 148 
     | 
    
         
            +
                # @param [Hash] headers HTTP headers for the request
         
     | 
| 
      
 149 
     | 
    
         
            +
                def run_curl(curl, url, method: 'GET', post_data: nil, headers: {})
         
     | 
| 
       114 
150 
     | 
    
         
             
                  curl.reset
         
     | 
| 
       115 
151 
     | 
    
         
             
                  curl.url = url
         
     | 
| 
       116 
     | 
    
         
            -
                  curl.http(method 
     | 
| 
      
 152 
     | 
    
         
            +
                  curl.http(method)
         
     | 
| 
       117 
153 
     | 
    
         
             
                  curl.headers = headers
         
     | 
| 
       118 
154 
     | 
    
         
             
                  curl.post_body = URI.encode_www_form(post_data) if post_data
         
     | 
| 
       119 
155 
     | 
    
         
             
                  curl.perform
         
     | 
| 
       120 
156 
     | 
    
         
             
                end
         
     | 
| 
       121 
157 
     | 
    
         | 
| 
       122 
158 
     | 
    
         
             
                # Safe JSON parsing with error handling
         
     | 
| 
      
 159 
     | 
    
         
            +
                # @param [Curl::Easy] res Curl response object
         
     | 
| 
      
 160 
     | 
    
         
            +
                # @return [Hash] Parsed JSON or empty hash on error
         
     | 
| 
       123 
161 
     | 
    
         
             
                def parse_json(res)
         
     | 
| 
       124 
162 
     | 
    
         
             
                  JSON.parse(res.body_str, symbolize_names: true)
         
     | 
| 
       125 
163 
     | 
    
         
             
                rescue JSON::ParserError
         
     | 
| 
       126 
164 
     | 
    
         
             
                  {}
         
     | 
| 
       127 
165 
     | 
    
         
             
                end
         
     | 
| 
       128 
166 
     | 
    
         | 
| 
       129 
     | 
    
         
            -
                #  
     | 
| 
      
 167 
     | 
    
         
            +
                # Generate a continually-increasing unsigned integer nonce from the current Unix Time
         
     | 
| 
      
 168 
     | 
    
         
            +
                # @return [Integer] Nonce value
         
     | 
| 
       130 
169 
     | 
    
         
             
                def nnc
         
     | 
| 
       131 
     | 
    
         
            -
                   
     | 
| 
      
 170 
     | 
    
         
            +
                  Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond).to_i
         
     | 
| 
       132 
171 
     | 
    
         
             
                end
         
     | 
| 
       133 
172 
     | 
    
         | 
| 
      
 173 
     | 
    
         
            +
                # Uniformly format a deposit from Bitcoin.de
         
     | 
| 
      
 174 
     | 
    
         
            +
                # @param [Hash] has Deposit data from Bitcoin.de
         
     | 
| 
       134 
175 
     | 
    
         
             
                # @return [Hash] deposito uniformizado bitcoinde
         
     | 
| 
       135 
176 
     | 
    
         
             
                def deposit_unif(has)
         
     | 
| 
       136 
     | 
    
         
            -
                  {add: has[:address], time: Time.parse(has[:created_at]),  
     | 
| 
      
 177 
     | 
    
         
            +
                  {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)
         
     | 
| 
       137 
178 
     | 
    
         
             
                end
         
     | 
| 
       138 
179 
     | 
    
         | 
| 
      
 180 
     | 
    
         
            +
                # Uniformly format a withdrawal from Bitcoin.de
         
     | 
| 
      
 181 
     | 
    
         
            +
                # @param [Hash] has Withdrawal data from Bitcoin.de
         
     | 
| 
       139 
182 
     | 
    
         
             
                # @return [Hash] withdrawal uniformizada bitcoinde
         
     | 
| 
       140 
183 
     | 
    
         
             
                def withdrawal_unif(has)
         
     | 
| 
       141 
184 
     | 
    
         
             
                  {
         
     | 
| 
       142 
185 
     | 
    
         
             
                    add: has[:address],
         
     | 
| 
       143 
186 
     | 
    
         
             
                    time: Time.parse(has[:transferred_at]),
         
     | 
| 
       144 
     | 
    
         
            -
                     
     | 
| 
       145 
     | 
    
         
            -
                    fee: has[:network_fee],
         
     | 
| 
       146 
     | 
    
         
            -
                     
     | 
| 
      
 187 
     | 
    
         
            +
                    qtd: -1 * has[:amount].to_d,
         
     | 
| 
      
 188 
     | 
    
         
            +
                    fee: has[:network_fee].to_d,
         
     | 
| 
      
 189 
     | 
    
         
            +
                    nxid: has[:withdrawal_id].to_i,
         
     | 
| 
       147 
190 
     | 
    
         
             
                    tp: 'withdrawal',
         
     | 
| 
       148 
     | 
    
         
            -
                    moe: ' 
     | 
| 
      
 191 
     | 
    
         
            +
                    moe: 'BTC'
         
     | 
| 
       149 
192 
     | 
    
         
             
                  }
         
     | 
| 
       150 
193 
     | 
    
         
             
                end
         
     | 
| 
       151 
194 
     | 
    
         | 
| 
       152 
     | 
    
         
            -
                #  
     | 
| 
       153 
     | 
    
         
            -
                # @param [ 
     | 
| 
       154 
     | 
    
         
            -
                # @ 
     | 
| 
      
 195 
     | 
    
         
            +
                # Generate headers for Bitcoin.de HTTP requests
         
     | 
| 
      
 196 
     | 
    
         
            +
                # @param [String] qde Query string to include in the HTTP request
         
     | 
| 
      
 197 
     | 
    
         
            +
                # @param [Integer] non Nonce value (default: generated from nnc)
         
     | 
| 
      
 198 
     | 
    
         
            +
                # @return [Hash] Headers required for Bitcoin.de HTTP requests
         
     | 
| 
       155 
199 
     | 
    
         
             
                def hde(qde, non = nnc)
         
     | 
| 
       156 
     | 
    
         
            -
                   
     | 
| 
       157 
     | 
    
         
            -
                   
     | 
| 
       158 
     | 
    
         
            -
                   
     | 
| 
       159 
     | 
    
         
            -
                  {'X-API-KEY': key, 'X-API-NONCE': non, 'X-API-SIGNATURE': mac}
         
     | 
| 
      
 200 
     | 
    
         
            +
                  md5 = ['GET', qde, @deky, non, Digest::MD5.hexdigest('')].join('#')
         
     | 
| 
      
 201 
     | 
    
         
            +
                  mac = OpenSSL::HMAC.hexdigest('sha256', @desc, md5)
         
     | 
| 
      
 202 
     | 
    
         
            +
                  {'X-API-KEY' => @deky, 'X-API-NONCE' => non.to_s, 'X-API-SIGNATURE' => mac}
         
     | 
| 
       160 
203 
     | 
    
         
             
                end
         
     | 
| 
       161 
204 
     | 
    
         | 
| 
      
 205 
     | 
    
         
            +
                # Generate headers for Kraken HTTP requests
         
     | 
| 
       162 
206 
     | 
    
         
             
                # @param [String] qus query a incluir no pedido HTTP
         
     | 
| 
       163 
207 
     | 
    
         
             
                # @param [Hash] ops opcoes trabalho
         
     | 
| 
       164 
208 
     | 
    
         
             
                # @option ops [Hash] :nonce continually-increasing unsigned integer
         
     | 
| 
       165 
     | 
    
         
            -
                # @return [Hash]  
     | 
| 
      
 209 
     | 
    
         
            +
                # @return [Hash] Headers required for Kraken HTTP requests
         
     | 
| 
       166 
210 
     | 
    
         
             
                def hus(qus, ops)
         
     | 
| 
       167 
     | 
    
         
            -
                  key = ENV.fetch('KRAKEN_API_KEY', nil)
         
     | 
| 
       168 
211 
     | 
    
         
             
                  sha = ['/0/private/', qus, Digest::SHA256.digest("#{ops[:nonce]}#{URI.encode_www_form(ops)}")].join
         
     | 
| 
       169 
     | 
    
         
            -
                  mac = OpenSSL::HMAC.digest('sha512', Base64.decode64( 
     | 
| 
       170 
     | 
    
         
            -
                  {'api-key' 
     | 
| 
      
 212 
     | 
    
         
            +
                  mac = OpenSSL::HMAC.digest('sha512', Base64.decode64(@ussc), sha)
         
     | 
| 
      
 213 
     | 
    
         
            +
                  {'api-key' => @usky, 'api-sign' => Base64.strict_encode64(mac)}
         
     | 
| 
       171 
214 
     | 
    
         
             
                end
         
     | 
| 
       172 
215 
     | 
    
         
             
              end
         
     | 
| 
       173 
216 
     | 
    
         
             
            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,14 +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 
     | 
    
         
            -
              }
         
     | 
| 
      
 47 
     | 
    
         
            +
              }.freeze
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
49 
     | 
    
         
             
              # classe para processar bigquery
         
     | 
| 
       50 
50 
     | 
    
         
             
              class Bigquery
         
     | 
| 
         @@ -223,7 +223,7 @@ module Cns 
     | 
|
| 
       223 
223 
     | 
    
         
             
                      novx = src.send("nov#{i}")
         
     | 
| 
       224 
224 
     | 
    
         
             
                      next if novx.empty?
         
     | 
| 
       225 
225 
     | 
    
         | 
| 
       226 
     | 
    
         
            -
                      format(' %<n>i %<t>s', n: dml(ins_sql(i,  
     | 
| 
      
 226 
     | 
    
         
            +
                      format(' %<n>i %<t>s', n: dml(ins_sql(i, novx)), t: "#{i}")
         
     | 
| 
       227 
227 
     | 
    
         
             
                    end
         
     | 
| 
       228 
228 
     | 
    
         
             
                  )
         
     | 
| 
       229 
229 
     | 
    
         
             
                  str.join
         
     | 
| 
         @@ -253,9 +253,7 @@ module Cns 
     | 
|
| 
       253 
253 
     | 
    
         | 
| 
       254 
254 
     | 
    
         
             
                # @return [String] SQL integer formatting
         
     | 
| 
       255 
255 
     | 
    
         
             
                def fin(value)
         
     | 
| 
       256 
     | 
    
         
            -
                   
     | 
| 
       257 
     | 
    
         
            -
                rescue StandardError
         
     | 
| 
       258 
     | 
    
         
            -
                  '0'
         
     | 
| 
      
 256 
     | 
    
         
            +
                  value.to_i.to_s
         
     | 
| 
       259 
257 
     | 
    
         
             
                end
         
     | 
| 
       260 
258 
     | 
    
         | 
| 
       261 
259 
     | 
    
         
             
                # @return [String] SQL timestamp formatting
         
     | 
| 
         @@ -330,7 +328,7 @@ module Cns 
     | 
|
| 
       330 
328 
     | 
    
         
             
                # @param [Hash] htx trades kraken
         
     | 
| 
       331 
329 
     | 
    
         
             
                # @return [String] valores formatados cust
         
     | 
| 
       332 
330 
     | 
    
         
             
                def cust_val(htx)
         
     | 
| 
       333 
     | 
    
         
            -
                  fvals(htx.merge(ledgers: apius.uskl.select { | 
     | 
| 
      
 331 
     | 
    
         
            +
                  fvals(htx.merge(ledgers: apius.uskl.select { |o| o[:refid] == htx[:txid] }.map { |t| t[:txid] }.join(',')), TB[:hust], :txid)
         
     | 
| 
       334 
332 
     | 
    
         
             
                end
         
     | 
| 
       335 
333 
     | 
    
         | 
| 
       336 
334 
     | 
    
         
             
                # @param [Hash] htx ledger kraken
         
     | 
    
        data/lib/cns/bitcoinde.rb
    CHANGED
    
    | 
         @@ -100,7 +100,7 @@ module Cns 
     | 
|
| 
       100 
100 
     | 
    
         
             
                def fol(hlx)
         
     | 
| 
       101 
101 
     | 
    
         
             
                  format(
         
     | 
| 
       102 
102 
     | 
    
         
             
                    '%<ky>6i %<dt>19.19s %<ty>-10.10s %<mo>-3.3s %<pr>19.8f %<vl>18.8f',
         
     | 
| 
       103 
     | 
    
         
            -
                    ky: hlx[: 
     | 
| 
      
 103 
     | 
    
         
            +
                    ky: hlx[:nxid],
         
     | 
| 
       104 
104 
     | 
    
         
             
                    dt: hlx[:time].strftime('%F %T'),
         
     | 
| 
       105 
105 
     | 
    
         
             
                    ty: hlx[:tp],
         
     | 
| 
       106 
106 
     | 
    
         
             
                    mo: hlx[:moe],
         
     | 
| 
         @@ -130,7 +130,7 @@ module Cns 
     | 
|
| 
       130 
130 
     | 
    
         
             
                # @return [Hash] transaccao filtrada
         
     | 
| 
       131 
131 
     | 
    
         
             
                def pdes(key, itm)
         
     | 
| 
       132 
132 
     | 
    
         
             
                  tym = ptm(itm[key])
         
     | 
| 
       133 
     | 
    
         
            -
                  itm.merge(srx:  
     | 
| 
      
 133 
     | 
    
         
            +
                  itm.merge(srx: tym.to_i, key => tym)
         
     | 
| 
       134 
134 
     | 
    
         
             
                end
         
     | 
| 
       135 
135 
     | 
    
         | 
| 
       136 
136 
     | 
    
         
             
                # @param [Array<Hash>] htx trade bitcoinde
         
     | 
| 
         @@ -150,7 +150,7 @@ module Cns 
     | 
|
| 
       150 
150 
     | 
    
         
             
                # @param [Array<Hash>] hlx ledger bitcoinde
         
     | 
| 
       151 
151 
     | 
    
         
             
                # @return [Array<Hash>] transaccao filtrada
         
     | 
| 
       152 
152 
     | 
    
         
             
                def pdel(hlx)
         
     | 
| 
       153 
     | 
    
         
            -
                  hlx.map { |t| pdes(:time, t) 
     | 
| 
      
 153 
     | 
    
         
            +
                  hlx.map { |t| pdes(:time, t) }
         
     | 
| 
       154 
154 
     | 
    
         
             
                end
         
     | 
| 
       155 
155 
     | 
    
         | 
| 
       156 
156 
     | 
    
         
             
                # @return [Hash] dados exchange bitcoinde - saldos & trades & deposits & withdrawals
         
     | 
| 
         @@ -173,19 +173,19 @@ module Cns 
     | 
|
| 
       173 
173 
     | 
    
         
             
                  @kyt ||= ded[:tt].map { |t| t[:trade_id] } - bqkyt
         
     | 
| 
       174 
174 
     | 
    
         
             
                end
         
     | 
| 
       175 
175 
     | 
    
         | 
| 
       176 
     | 
    
         
            -
                # @return [Array<Integer>] lista  
     | 
| 
      
 176 
     | 
    
         
            +
                # @return [Array<Integer>] lista nxid ledger novos
         
     | 
| 
       177 
177 
     | 
    
         
             
                def kyl
         
     | 
| 
       178 
     | 
    
         
            -
                  @kyl ||= ded[:tl].map { |t| t[: 
     | 
| 
      
 178 
     | 
    
         
            +
                  @kyl ||= ded[:tl].map { |t| t[:nxid] } - bqkyl
         
     | 
| 
       179 
179 
     | 
    
         
             
                end
         
     | 
| 
       180 
180 
     | 
    
         | 
| 
       181 
     | 
    
         
            -
                # @return [Array<Hash>] lista trades bitcoinde 
     | 
| 
      
 181 
     | 
    
         
            +
                # @return [Array<Hash>] lista trades novos bitcoinde
         
     | 
| 
       182 
182 
     | 
    
         
             
                def novcdet
         
     | 
| 
       183 
     | 
    
         
            -
                  @novcdet ||= ded[:tt].select { | 
     | 
| 
      
 183 
     | 
    
         
            +
                  @novcdet ||= ded[:tt].select { |o| kyt.include?(o[:trade_id]) }
         
     | 
| 
       184 
184 
     | 
    
         
             
                end
         
     | 
| 
       185 
185 
     | 
    
         | 
| 
       186 
     | 
    
         
            -
                # @return [Array<Hash>] lista  
     | 
| 
      
 186 
     | 
    
         
            +
                # @return [Array<Hash>] lista ledgers (deposits + withdrawals) novos bitcoinde
         
     | 
| 
       187 
187 
     | 
    
         
             
                def novcdel
         
     | 
| 
       188 
     | 
    
         
            -
                  @novcdel ||= ded[:tl].select { | 
     | 
| 
      
 188 
     | 
    
         
            +
                  @novcdel ||= ded[:tl].select { |o| kyl.include?(o[:nxid]) }
         
     | 
| 
       189 
189 
     | 
    
         
             
                end
         
     | 
| 
       190 
190 
     | 
    
         
             
              end
         
     | 
| 
       191 
191 
     | 
    
         
             
            end
         
     | 
    
        data/lib/cns/etherscan.rb
    CHANGED
    
    | 
         @@ -18,36 +18,36 @@ 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
         
     | 
| 
         @@ -166,7 +166,7 @@ module Cns 
     | 
|
| 
       166 
166 
     | 
    
         
             
                  return 'erro' if max < 7
         
     | 
| 
       167 
167 
     | 
    
         | 
| 
       168 
168 
     | 
    
         
             
                  max -= 2
         
     | 
| 
       169 
     | 
    
         
            -
                  ini =  
     | 
| 
      
 169 
     | 
    
         
            +
                  ini = (max / 2).to_i + 4
         
     | 
| 
       170 
170 
     | 
    
         
             
                  inf = max % 2
         
     | 
| 
       171 
171 
     | 
    
         
             
                  "#{add[0, ini - 3]}..#{add[-inf - ini + 5..]}"
         
     | 
| 
       172 
172 
     | 
    
         
             
                end
         
     | 
| 
         @@ -180,7 +180,7 @@ module Cns 
     | 
|
| 
       180 
180 
     | 
    
         
             
                  return 'erro' if max < 7
         
     | 
| 
       181 
181 
     | 
    
         | 
| 
       182 
182 
     | 
    
         
             
                  max -= 2
         
     | 
| 
       183 
     | 
    
         
            -
                  ini =  
     | 
| 
      
 183 
     | 
    
         
            +
                  ini = (max / 2).to_i
         
     | 
| 
       184 
184 
     | 
    
         
             
                  inf = max % 2
         
     | 
| 
       185 
185 
     | 
    
         
             
                  hid = bqd[:wb].find { |o| o[:ax] == add }
         
     | 
| 
       186 
186 
     | 
    
         
             
                  ndd = hid ? "#{hid[:id]}-#{add}" : add
         
     | 
| 
         @@ -234,29 +234,31 @@ module Cns 
     | 
|
| 
       234 
234 
     | 
    
         
             
                # @param [Hash] htx transacao
         
     | 
| 
       235 
235 
     | 
    
         
             
                # @return [Hash] transaccao filtrada
         
     | 
| 
       236 
236 
     | 
    
         
             
                def pess(htx)
         
     | 
| 
       237 
     | 
    
         
            -
                  tym =  
     | 
| 
      
 237 
     | 
    
         
            +
                  tym = htx[:timeStamp].to_i
         
     | 
| 
       238 
238 
     | 
    
         
             
                  htx.merge(srx: tym, timeStamp: Time.at(tym))
         
     | 
| 
      
 239 
     | 
    
         
            +
                rescue ArgumentError
         
     | 
| 
      
 240 
     | 
    
         
            +
                  htx.merge(srx: 0, timeStamp: Time.at(0))
         
     | 
| 
       239 
241 
     | 
    
         
             
                end
         
     | 
| 
       240 
242 
     | 
    
         | 
| 
       241 
243 
     | 
    
         
             
                # @param add (see foe1)
         
     | 
| 
       242 
244 
     | 
    
         
             
                # @param [Array<Hash>] ary lista transacoes normal(t)/(i)nternal/to(k)en
         
     | 
| 
       243 
245 
     | 
    
         
             
                # @return [Array<Hash>] lista transacoes filtrada
         
     | 
| 
       244 
246 
     | 
    
         
             
                def ftik(add, ary)
         
     | 
| 
       245 
     | 
    
         
            -
                  ary.map { |o| pess(o).merge(itx:  
     | 
| 
      
 247 
     | 
    
         
            +
                  ary.map { |o| pess(o).merge(itx: o[:hash].to_s, iax: add, value: o[:value].to_d) }
         
     | 
| 
       246 
248 
     | 
    
         
             
                end
         
     | 
| 
       247 
249 
     | 
    
         | 
| 
       248 
250 
     | 
    
         
             
                # @param add (see foe1)
         
     | 
| 
       249 
251 
     | 
    
         
             
                # @param [Array<Hash>] ary lista transacoes (p)roduced blocks
         
     | 
| 
       250 
252 
     | 
    
         
             
                # @return [Array<Hash>] lista transacoes filtrada
         
     | 
| 
       251 
253 
     | 
    
         
             
                def fppp(add, ary)
         
     | 
| 
       252 
     | 
    
         
            -
                  ary.map { |o| o.merge(itx:  
     | 
| 
      
 254 
     | 
    
         
            +
                  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 
255 
     | 
    
         
             
                end
         
     | 
| 
       254 
256 
     | 
    
         | 
| 
       255 
257 
     | 
    
         
             
                # @param add (see foe1)
         
     | 
| 
       256 
258 
     | 
    
         
             
                # @param [Array<Hash>] ary lista transacoes (w)ithdrawals
         
     | 
| 
       257 
259 
     | 
    
         
             
                # @return [Array<Hash>] lista transacoes filtrada
         
     | 
| 
       258 
260 
     | 
    
         
             
                def fwww(add, ary)
         
     | 
| 
       259 
     | 
    
         
            -
                  ary.map { |o| o.merge(itx:  
     | 
| 
      
 261 
     | 
    
         
            +
                  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 
262 
     | 
    
         
             
                end
         
     | 
| 
       261 
263 
     | 
    
         | 
| 
       262 
264 
     | 
    
         
             
                # @param [Hash] aes account etherscan
         
     | 
    
        data/lib/cns/greymass.rb
    CHANGED
    
    | 
         @@ -17,7 +17,7 @@ module Cns 
     | 
|
| 
       17 
17 
     | 
    
         
             
                  header: "\nsequence num from         to           accao      data              valor moeda",
         
     | 
| 
       18 
18 
     | 
    
         
             
                  sork: :itx,
         
     | 
| 
       19 
19 
     | 
    
         
             
                  adjk: :itx
         
     | 
| 
       20 
     | 
    
         
            -
                }
         
     | 
| 
      
 20 
     | 
    
         
            +
                }.freeze
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                # @param [Hash] dad todos os dados bigquery
         
     | 
| 
       23 
23 
     | 
    
         
             
                # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
         
     | 
| 
         @@ -77,7 +77,7 @@ module Cns 
     | 
|
| 
       77 
77 
     | 
    
         
             
                # @param (see foct)
         
     | 
| 
       78 
78 
     | 
    
         
             
                # @return [Boolean] carteira tem transacoes novas(sim=NOK, nao=OK)?
         
     | 
| 
       79 
79 
     | 
    
         
             
                def ok?(hjn)
         
     | 
| 
       80 
     | 
    
         
            -
                  hjn[:bs] == hjn[:es] && hjn[:bt].count == hjn[:et].count
         
     | 
| 
      
 80 
     | 
    
         
            +
                  hjn[:bs].round(6) == hjn[:es].round(6) && hjn[:bt].count == hjn[:et].count
         
     | 
| 
       81 
81 
     | 
    
         
             
                end
         
     | 
| 
       82 
82 
     | 
    
         | 
| 
       83 
83 
     | 
    
         
             
                # @param [Hash] hlx ledger greymass
         
     | 
| 
         @@ -104,8 +104,8 @@ module Cns 
     | 
|
| 
       104 
104 
     | 
    
         
             
                # @return [Array<BigDecimal>] lista recursos - liquido, net, spu
         
     | 
| 
       105 
105 
     | 
    
         
             
                def peosa(add)
         
     | 
| 
       106 
106 
     | 
    
         
             
                  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]
         
     | 
| 
      
 107 
     | 
    
         
            +
                  htr = hac.fetch(:total_resources, {})
         
     | 
| 
      
 108 
     | 
    
         
            +
                  [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 
109 
     | 
    
         
             
                end
         
     | 
| 
       110 
110 
     | 
    
         | 
| 
       111 
111 
     | 
    
         
             
                # @param add (see peosa)
         
     | 
| 
         @@ -122,7 +122,7 @@ module Cns 
     | 
|
| 
       122 
122 
     | 
    
         
             
                      quantity: qtd.to_d,
         
     | 
| 
       123 
123 
     | 
    
         
             
                      account: act[:account],
         
     | 
| 
       124 
124 
     | 
    
         
             
                      to: adt[:to],
         
     | 
| 
       125 
     | 
    
         
            -
                      memo:  
     | 
| 
      
 125 
     | 
    
         
            +
                      memo: adt[:memo].to_s.gsub(/\p{C}/, ''), # remove Non-Printable Characters
         
     | 
| 
       126 
126 
     | 
    
         
             
                      moe: qtd[/[[:upper:]]+/],
         
     | 
| 
       127 
127 
     | 
    
         
             
                      itx: t[:global_action_seq],
         
     | 
| 
       128 
128 
     | 
    
         
             
                      iax: add,
         
     | 
    
        data/lib/cns/kraken.rb
    CHANGED
    
    | 
         @@ -23,7 +23,7 @@ module Cns 
     | 
|
| 
       23 
23 
     | 
    
         
             
                  @ops = pop.transform_keys(&:to_sym)
         
     | 
| 
       24 
24 
     | 
    
         
             
                end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                #  
     | 
| 
      
 26 
     | 
    
         
            +
                # mosta resumo saldos & transacoes & ajuste dias
         
     | 
| 
       27 
27 
     | 
    
         
             
                def mresumo
         
     | 
| 
       28 
28 
     | 
    
         
             
                  puts("\nKRAKEN\ntipo                 kraken              bigquery")
         
     | 
| 
       29 
29 
     | 
    
         
             
                  usd[:sl].sort.each { |key, val| puts(fos(key, val)) }
         
     | 
| 
         @@ -33,7 +33,7 @@ module Cns 
     | 
|
| 
       33 
33 
     | 
    
         
             
                  mledger
         
     | 
| 
       34 
34 
     | 
    
         
             
                  return if novcust.empty?
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                  puts("\nstring ajuste dias dos trades\n-h=#{novcust.sort_by { | 
     | 
| 
      
 36 
     | 
    
         
            +
                  puts("\nstring ajuste dias dos trades\n-h=#{novcust.sort_by { |i| -i[:srx] }.map { |o| "#{o[:txid]}:0" }.join(' ')}")
         
     | 
| 
       37 
37 
     | 
    
         
             
                end
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
                # @return [Hash] ledgers exchange kraken
         
     | 
| 
         @@ -59,7 +59,7 @@ module Cns 
     | 
|
| 
       59 
59 
     | 
    
         
             
                  return unless ops[:v] && novcust.any?
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
                  puts("\ntrade  data       hora     tipo       par         preco     volume         custo")
         
     | 
| 
       62 
     | 
    
         
            -
                  novcust.sort_by { | 
     | 
| 
      
 62 
     | 
    
         
            +
                  novcust.sort_by { |i| -i[:srx] }.each { |o| puts(fot(o)) }
         
     | 
| 
       63 
63 
     | 
    
         
             
                end
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
       65 
65 
     | 
    
         
             
                # mosta transacoes ledger
         
     | 
| 
         @@ -67,14 +67,14 @@ module Cns 
     | 
|
| 
       67 
67 
     | 
    
         
             
                  return unless ops[:v] && novcusl.any?
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
69 
     | 
    
         
             
                  puts("\nledger data       hora     tipo       moeda        quantidade              custo")
         
     | 
| 
       70 
     | 
    
         
            -
                  novcusl.sort_by { | 
     | 
| 
      
 70 
     | 
    
         
            +
                  novcusl.sort_by { |i| -i[:srx] }.each { |o| puts(fol(o)) }
         
     | 
| 
       71 
71 
     | 
    
         
             
                end
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
                # @param [String] moe codigo kraken da moeda
         
     | 
| 
       74 
74 
     | 
    
         
             
                # @param [BigDecimal] sal saldo kraken da moeda
         
     | 
| 
       75 
75 
     | 
    
         
             
                # @return [String] texto formatado saldos
         
     | 
| 
       76 
76 
     | 
    
         
             
                def fos(moe, sal)
         
     | 
| 
       77 
     | 
    
         
            -
                  vbq = bqd[:sl] 
     | 
| 
      
 77 
     | 
    
         
            +
                  vbq = (bqd[:sl]&.fetch(moe.downcase.to_sym, nil) || 0).to_d
         
     | 
| 
       78 
78 
     | 
    
         
             
                  format(
         
     | 
| 
       79 
79 
     | 
    
         
             
                    '%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s',
         
     | 
| 
       80 
80 
     | 
    
         
             
                    mo: moe.upcase,
         
     | 
| 
         @@ -84,13 +84,12 @@ module Cns 
     | 
|
| 
       84 
84 
     | 
    
         
             
                  )
         
     | 
| 
       85 
85 
     | 
    
         
             
                end
         
     | 
| 
       86 
86 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
                # @param [Symbol] idx id da transacao
         
     | 
| 
       88 
87 
     | 
    
         
             
                # @param [Hash] htn trades kraken
         
     | 
| 
       89 
88 
     | 
    
         
             
                # @return [String] texto formatado trade
         
     | 
| 
       90 
     | 
    
         
            -
                def fot( 
     | 
| 
      
 89 
     | 
    
         
            +
                def fot(htx)
         
     | 
| 
       91 
90 
     | 
    
         
             
                  format(
         
     | 
| 
       92 
91 
     | 
    
         
             
                    '%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-8.8s %<pr>8.2f %<vl>10.4f %<co>13.2f',
         
     | 
| 
       93 
     | 
    
         
            -
                    ky:  
     | 
| 
      
 92 
     | 
    
         
            +
                    ky: htx[:txid],
         
     | 
| 
       94 
93 
     | 
    
         
             
                    dt: htx[:time].strftime('%F %T'),
         
     | 
| 
       95 
94 
     | 
    
         
             
                    ty: "#{htx[:type]}/#{htx[:ordertype]}",
         
     | 
| 
       96 
95 
     | 
    
         
             
                    mo: htx[:pair],
         
     | 
| 
         @@ -100,13 +99,12 @@ module Cns 
     | 
|
| 
       100 
99 
     | 
    
         
             
                  )
         
     | 
| 
       101 
100 
     | 
    
         
             
                end
         
     | 
| 
       102 
101 
     | 
    
         | 
| 
       103 
     | 
    
         
            -
                # @param idx (see fot)
         
     | 
| 
       104 
102 
     | 
    
         
             
                # @param [Hash] hln ledger kraken
         
     | 
| 
       105 
103 
     | 
    
         
             
                # @return [String] texto formatado ledger
         
     | 
| 
       106 
     | 
    
         
            -
                def fol( 
     | 
| 
      
 104 
     | 
    
         
            +
                def fol(hlx)
         
     | 
| 
       107 
105 
     | 
    
         
             
                  format(
         
     | 
| 
       108 
106 
     | 
    
         
             
                    '%<ky>-6.6s %<dt>19.19s %<ty>-10.10s %<mo>-4.4s %<pr>18.7f %<vl>18.7f',
         
     | 
| 
       109 
     | 
    
         
            -
                    ky:  
     | 
| 
      
 107 
     | 
    
         
            +
                    ky: hlx[:txid],
         
     | 
| 
       110 
108 
     | 
    
         
             
                    dt: hlx[:time].strftime('%F %T'),
         
     | 
| 
       111 
109 
     | 
    
         
             
                    ty: hlx[:type],
         
     | 
| 
       112 
110 
     | 
    
         
             
                    mo: hlx[:asset],
         
     | 
| 
         @@ -126,25 +124,16 @@ module Cns 
     | 
|
| 
       126 
124 
     | 
    
         
             
                  itm.select { |k, _| EM.include?(k) }.transform_values { |v| v.to_d }
         
     | 
| 
       127 
125 
     | 
    
         
             
                end
         
     | 
| 
       128 
126 
     | 
    
         | 
| 
       129 
     | 
    
         
            -
                # @param [Hash]  
     | 
| 
       130 
     | 
    
         
            -
                # @return [Hash]  
     | 
| 
       131 
     | 
    
         
            -
                def pusk(itm)
         
     | 
| 
       132 
     | 
    
         
            -
                  itm.map do |k, v|
         
     | 
| 
       133 
     | 
    
         
            -
                    t = Integer(v[:time])
         
     | 
| 
       134 
     | 
    
         
            -
                    [k, v.merge(txid: k.to_s, srx: t, time: Time.at(t))]
         
     | 
| 
       135 
     | 
    
         
            -
                  end.to_h
         
     | 
| 
       136 
     | 
    
         
            -
                end
         
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
                # @param [Hash] htx trade kraken
         
     | 
| 
       139 
     | 
    
         
            -
                # @return [Hash] transaccao filtrada
         
     | 
| 
      
 127 
     | 
    
         
            +
                # @param [Array<Hash>] htx trades kraken
         
     | 
| 
      
 128 
     | 
    
         
            +
                # @return [Array<Hash>] transaccoes filtradas
         
     | 
| 
       140 
129 
     | 
    
         
             
                def pust(htx)
         
     | 
| 
       141 
     | 
    
         
            -
                   
     | 
| 
      
 130 
     | 
    
         
            +
                  htx.map { |t| t.merge(pair: t[:pair].upcase, price: t[:price].to_d, vol: t[:vol].to_d, cost: t[:cost].to_d) }
         
     | 
| 
       142 
131 
     | 
    
         
             
                end
         
     | 
| 
       143 
132 
     | 
    
         | 
| 
       144 
     | 
    
         
            -
                # @param [Hash] hlx  
     | 
| 
       145 
     | 
    
         
            -
                # @return [Hash]  
     | 
| 
      
 133 
     | 
    
         
            +
                # @param [Array<Hash>] hlx ledgers kraken
         
     | 
| 
      
 134 
     | 
    
         
            +
                # @return [Array<Hash>] transaccoes filtradas
         
     | 
| 
       146 
135 
     | 
    
         
             
                def pusl(hlx)
         
     | 
| 
       147 
     | 
    
         
            -
                   
     | 
| 
      
 136 
     | 
    
         
            +
                  hlx.map { |t| t.merge(asset: t[:asset].upcase, amount: t[:amount].to_d, fee: t[:fee].to_d) }
         
     | 
| 
       148 
137 
     | 
    
         
             
                end
         
     | 
| 
       149 
138 
     | 
    
         | 
| 
       150 
139 
     | 
    
         
             
                # @return [Hash] dados exchange kraken - saldos & transacoes trades e ledger
         
     | 
| 
         @@ -152,34 +141,34 @@ module Cns 
     | 
|
| 
       152 
141 
     | 
    
         
             
                  @usd ||= {sl: pusa(api.account_us), kt: pust(api.trades_us), kl: pusl(api.ledger_us)}
         
     | 
| 
       153 
142 
     | 
    
         
             
                end
         
     | 
| 
       154 
143 
     | 
    
         | 
| 
       155 
     | 
    
         
            -
                # @return [Array< 
     | 
| 
      
 144 
     | 
    
         
            +
                # @return [Array<String>] indices trades bigquery
         
     | 
| 
       156 
145 
     | 
    
         
             
                def bqkyt
         
     | 
| 
       157 
     | 
    
         
            -
                  @bqkyt ||= show_all? ? [] : bqd[:nt].map { |t| t[:txid] 
     | 
| 
      
 146 
     | 
    
         
            +
                  @bqkyt ||= show_all? ? [] : bqd[:nt].map { |t| t[:txid] }
         
     | 
| 
       158 
147 
     | 
    
         
             
                end
         
     | 
| 
       159 
148 
     | 
    
         | 
| 
       160 
     | 
    
         
            -
                # @return [Array< 
     | 
| 
      
 149 
     | 
    
         
            +
                # @return [Array<String>] indices ledger bigquery
         
     | 
| 
       161 
150 
     | 
    
         
             
                def bqkyl
         
     | 
| 
       162 
     | 
    
         
            -
                  @bqkyl ||= show_all? ? [] : bqd[:nl].map { |l| l[:txid] 
     | 
| 
      
 151 
     | 
    
         
            +
                  @bqkyl ||= show_all? ? [] : bqd[:nl].map { |l| l[:txid] }
         
     | 
| 
       163 
152 
     | 
    
         
             
                end
         
     | 
| 
       164 
153 
     | 
    
         | 
| 
       165 
     | 
    
         
            -
                # @return [Array< 
     | 
| 
      
 154 
     | 
    
         
            +
                # @return [Array<String>] lista txid trades novos
         
     | 
| 
       166 
155 
     | 
    
         
             
                def kyt
         
     | 
| 
       167 
     | 
    
         
            -
                  @kyt ||= usd[:kt]. 
     | 
| 
      
 156 
     | 
    
         
            +
                  @kyt ||= usd[:kt].map { |t| t[:txid] } - bqkyt
         
     | 
| 
       168 
157 
     | 
    
         
             
                end
         
     | 
| 
       169 
158 
     | 
    
         | 
| 
       170 
     | 
    
         
            -
                # @return [Array< 
     | 
| 
      
 159 
     | 
    
         
            +
                # @return [Array<String>] lista txid ledger novos
         
     | 
| 
       171 
160 
     | 
    
         
             
                def kyl
         
     | 
| 
       172 
     | 
    
         
            -
                  @kyl ||= usd[:kl]. 
     | 
| 
      
 161 
     | 
    
         
            +
                  @kyl ||= usd[:kl].map { |t| t[:txid] } - bqkyl
         
     | 
| 
       173 
162 
     | 
    
         
             
                end
         
     | 
| 
       174 
163 
     | 
    
         | 
| 
       175 
     | 
    
         
            -
                # @return [Hash] trades kraken 
     | 
| 
      
 164 
     | 
    
         
            +
                # @return [Array<Hash>] trades novos kraken
         
     | 
| 
       176 
165 
     | 
    
         
             
                def novcust
         
     | 
| 
       177 
     | 
    
         
            -
                  @novcust ||= usd[:kt]. 
     | 
| 
      
 166 
     | 
    
         
            +
                  @novcust ||= usd[:kt].select { |o| kyt.include?(o[:txid]) }
         
     | 
| 
       178 
167 
     | 
    
         
             
                end
         
     | 
| 
       179 
168 
     | 
    
         | 
| 
       180 
     | 
    
         
            -
                # @return [Hash]  
     | 
| 
      
 169 
     | 
    
         
            +
                # @return [Array<Hash>] ledgers novos kraken
         
     | 
| 
       181 
170 
     | 
    
         
             
                def novcusl
         
     | 
| 
       182 
     | 
    
         
            -
                  @novcusl ||= usd[:kl]. 
     | 
| 
      
 171 
     | 
    
         
            +
                  @novcusl ||= usd[:kl].select { |o| kyl.include?(o[:txid]) }
         
     | 
| 
       183 
172 
     | 
    
         
             
                end
         
     | 
| 
       184 
173 
     | 
    
         
             
              end
         
     | 
| 
       185 
174 
     | 
    
         
             
            end
         
     | 
    
        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.9. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.9.6
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Hernâni Rodrigues Vaz
         
     | 
| 
       8 
8 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       9 
9 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       10 
     | 
    
         
            -
            date: 2025-03- 
     | 
| 
      
 10 
     | 
    
         
            +
            date: 2025-03-06 00:00:00.000000000 Z
         
     | 
| 
       11 
11 
     | 
    
         
             
            dependencies:
         
     | 
| 
       12 
12 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       13 
13 
     | 
    
         
             
              name: bundler
         
     |