cns 2.1.8 → 2.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8c3291d5689453fc6b8055d59f4468b00b8f1d65244d98d9a1e2e0f7397c6c6
4
- data.tar.gz: e6feab9a8d9da05c236ed46f9e6d019d002812ce9d000a2765549dcb56bb433f
3
+ metadata.gz: 35cbb3480d93201fac4d588ef04df6a57f4e487d911f6ebd01f4c629c6701287
4
+ data.tar.gz: e1f7387b9cb172028410c3a3d1f358787374d3a24fceb84214808a62fc596922
5
5
  SHA512:
6
- metadata.gz: cff4090062ae367a6df696863a5d6db89cd5f67d2c01d374793013ff890e9ee4aad9195142b3233e672626148bd208051b873aaf0934aea8800cead3c99c3536
7
- data.tar.gz: 2e2c356ad94b02e6ca2ae0c1fe16e2c79221e0bcb0ccb7ce0597842cd4f3503caa798a162ac3553c2e2d69054f6e60202f4fc64e04268da042796c996bedabee
6
+ metadata.gz: 56adc131c7198a2496dec57d3781f930465ce0ab06cc4895b3853673906e19dcee6b992026dc87c43158e1276b4266c2684487cb18dc95b78a3a91032289af19
7
+ data.tar.gz: f9f29e2b1f086a3de056126d873fd48c5e960ce0e2f9f5f17b98eb408af5c478bf3b4b2120ce2abcc046e4d728c3d76af2b93f00879a737f98ae80684f9d82a5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cns (2.1.8)
4
+ cns (2.2.0)
5
5
  curb
6
6
  faraday
7
7
  faraday-retry
@@ -112,14 +112,14 @@ GEM
112
112
  multi_json (1.19.1)
113
113
  net-http (0.9.1)
114
114
  uri (>= 0.11.1)
115
- nokogiri (1.19.0-x86_64-linux-gnu)
115
+ nokogiri (1.19.1-x86_64-linux-gnu)
116
116
  racc (~> 1.4)
117
117
  observer (0.1.2)
118
118
  open3 (0.2.1)
119
119
  os (1.1.4)
120
120
  ostruct (0.6.3)
121
121
  parallel (1.27.0)
122
- parser (3.3.10.1)
122
+ parser (3.3.10.2)
123
123
  ast (~> 2.4.1)
124
124
  racc
125
125
  prism (1.9.0)
@@ -141,7 +141,7 @@ GEM
141
141
  declarative (< 0.1.0)
142
142
  trailblazer-option (>= 0.1.1, < 0.2.0)
143
143
  uber (< 0.2.0)
144
- retriable (3.1.2)
144
+ retriable (3.2.1)
145
145
  reverse_markdown (3.0.2)
146
146
  nokogiri
147
147
  rexml (3.4.4)
@@ -205,7 +205,7 @@ GEM
205
205
  yard (>= 0.8)
206
206
  yard-solargraph (0.1.0)
207
207
  yard (~> 0.9)
208
- zeitwerk (2.7.4)
208
+ zeitwerk (2.7.5)
209
209
 
210
210
  PLATFORMS
211
211
  x86_64-linux
data/lib/cns/apice.rb CHANGED
@@ -10,6 +10,7 @@ module Cns
10
10
  # classe para acesso dados centralized exchanges
11
11
  class Apice
12
12
  API = {de: 'https://api.bitcoin.de/v4', us: 'https://api.kraken.com/0/private'}.freeze
13
+ MDE = %w[btc eth].freeze
13
14
 
14
15
  def initialize
15
16
  @curl =
@@ -48,19 +49,23 @@ module Cns
48
49
  end
49
50
 
50
51
  # Get deposits from Bitcoin.de, uniformly formatted
51
- # @param [Integer] tsp optional unix timestamp (seconds) to fetch deposits from (start date on bitcoin.de API)
52
52
  # @return [Array<Hash>] depositos uniformizados bitcoinde
53
53
  def deposits_de
54
- pag_de_req("#{API[:de]}/btc/deposits", {}, :deposits) { |i| i.map { |h| deposit_unif(h) } }
54
+ MDE.flat_map do |cry|
55
+ pag_de_req("#{API[:de]}/#{cry}/deposits", {}, :deposits) { |i| i.map { |h| deposit_unif(h, cry.upcase) } }
56
+ end
57
+ # pag_de_req("#{API[:de]}/btc/deposits", {}, :deposits) { |i| i.map { |h| deposit_unif(h) } }
55
58
  rescue Curl::Err::CurlError
56
59
  []
57
60
  end
58
61
 
59
62
  # Get withdrawals from Bitcoin.de, uniformly formatted
60
- # @param [Integer] tsp optional unix timestamp (seconds) to fetch withdrawals from (start date on bitcoin.de API)
61
63
  # @return [Array<Hash>] withdrawals uniformizadas bitcoinde
62
64
  def withdrawals_de
63
- pag_de_req("#{API[:de]}/btc/withdrawals", {}, :withdrawals) { |i| i.map { |h| withdrawal_unif(h) } }
65
+ MDE.flat_map do |cry|
66
+ pag_de_req("#{API[:de]}/#{cry}/withdrawals", {}, :withdrawals) { |i| i.map { |h| withdrawal_unif(h, cry.upcase) } }
67
+ end
68
+ # pag_de_req("#{API[:de]}/btc/withdrawals", {}, :withdrawals) { |i| i.map { |h| withdrawal_unif(h) } }
64
69
  rescue Curl::Err::CurlError
65
70
  []
66
71
  end
@@ -127,6 +132,10 @@ module Cns
127
132
  sleep(@lpag - Time.now + 2) if @lpag && Time.now - @lpag < 2
128
133
  ops = prm.merge({nonce: nnc, ofs: ofs})
129
134
  rcrl(@curl, "#{API[:us]}/#{uri}", method: 'POST', post_data: ops, headers: hus(uri, ops))
135
+ unless @curl.response_code == 200
136
+ puts("Kraken API returned non-200 status: #{@curl.response_code} for #{uri}")
137
+ break
138
+ end
130
139
  bth = pjsn(@curl).fetch(:result, {}).fetch(key, []).map { |k, v| us_unif(k, v) }
131
140
  break if bth.empty?
132
141
 
@@ -149,7 +158,6 @@ module Cns
149
158
  loop do
150
159
  url = "#{uri}?#{URI.encode_www_form(prm.merge(page: pag))}"
151
160
  rcrl(@curl, url, headers: hde(url))
152
- # Check HTTP status
153
161
  unless @curl.response_code == 200
154
162
  puts("Bitcoin.de API returned non-200 status: #{@curl.response_code} for #{url}")
155
163
  break
@@ -200,15 +208,17 @@ module Cns
200
208
 
201
209
  # Uniformly format a deposit from Bitcoin.de
202
210
  # @param [Hash] has Deposit data from Bitcoin.de
211
+ # @param [String] moe Currency code (e.g., 'BTC', 'ETH')
203
212
  # @return [Hash] deposito uniformizado bitcoinde
204
- def deposit_unif(has)
205
- {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)
213
+ def deposit_unif(has, moe)
214
+ {add: has[:address], time: Time.parse(has[:created_at]), qtd: has[:amount].to_d, nxid: has[:deposit_id].to_i}.merge(tp: 'deposit', moe: moe, fee: 0.to_d)
206
215
  end
207
216
 
208
217
  # Uniformly format a withdrawal from Bitcoin.de
209
218
  # @param [Hash] has Withdrawal data from Bitcoin.de
219
+ # @param [String] moe Currency code (e.g., 'BTC', 'ETH')
210
220
  # @return [Hash] withdrawal uniformizada bitcoinde
211
- def withdrawal_unif(has)
221
+ def withdrawal_unif(has, moe)
212
222
  {
213
223
  add: has[:address],
214
224
  time: Time.parse(has[:transferred_at]),
@@ -216,7 +226,7 @@ module Cns
216
226
  fee: has[:network_fee].to_d,
217
227
  nxid: has[:withdrawal_id].to_i,
218
228
  tp: 'withdrawal',
219
- moe: 'BTC'
229
+ moe: moe
220
230
  }
221
231
  end
222
232
 
data/lib/cns/bigquery.rb CHANGED
@@ -252,7 +252,7 @@ module Cns
252
252
  kys.map do |k|
253
253
  case k
254
254
  when :amount, :btc, :cost, :fee, :gas, :gasPrice, :gasUsed, :margin, :price, :quantity, :value, :vol, :eur, :blockReward, :qtd then fnm(hsh[k])
255
- when :blockNumber, :timeStamp, :nonce, :transactionIndex, :isError, :txreceipt_status, :tokenDecimal, :withdrawalIndex, :validatorIndex then fin(hsh[k])
255
+ when :blockNumber, :timeStamp, :nonce, :transactionIndex, :isError, :txreceipt_status, :tokenDecimal, :withdrawalIndex, :validatorIndex, :nxid then fin(hsh[k])
256
256
  when :block_time, :successfully_finished_at, :time, :trade_marked_as_paid_at then fts(hsh[k])
257
257
  when :memo, :input, :misc then fqe(hsh[k])
258
258
  else fqt(hsh[k])
data/lib/cns/bitcoinde.rb CHANGED
@@ -43,7 +43,7 @@ module Cns
43
43
  vtt, vnt = exd[:tt].count, bqd[:nt].count
44
44
  vtl, vnl = exd[:tl].count, bqd[:nl].count
45
45
 
46
- puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vtt, b: vnt, o: vtt == vnt ? 'OK' : 'NOK')}") if vtt.positive?
46
+ puts("TRADES #{format('%<a>20i %<b>21i %<o>3.3s', a: vtt, b: vnt, o: vtt == vnt ? 'OK' : 'NOK')}")
47
47
  puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vtl, d: vnl, o: vtl == vnl ? 'OK' : 'NOK')}")
48
48
  end
49
49
 
@@ -51,7 +51,7 @@ module Cns
51
51
  def mtrades
52
52
  return unless ops[:v] && novxt.any?
53
53
 
54
- puts("\ntrades data hora dt criacao tipo par btc eur")
54
+ puts("\ntrades data hora dt criacao tipo crypto eur")
55
55
  novxt.sort_by { |i| -i[:srx] }.each { |o| puts(fot(o)) }
56
56
  end
57
57
 
@@ -59,7 +59,7 @@ module Cns
59
59
  def mledger
60
60
  return unless ops[:v] && novxl.any?
61
61
 
62
- puts("\nledger data hora tipo moe quantidade custo")
62
+ puts("\nledger data hora tipo moe crypto custo")
63
63
  novxl.sort_by { |i| -i[:srx] }.each { |o| puts(fol(o)) }
64
64
  end
65
65
 
@@ -82,12 +82,11 @@ module Cns
82
82
  # @return [String] texto formatado trade
83
83
  def fot(htx)
84
84
  format(
85
- '%<ky>-6.6s %<dt>19.19s %<dp>10.10s %<ty>-5.5s %<mo>-8.8s %<vl>18.8f %<co>8.2f',
85
+ '%<ky>-6.6s %<dt>19.19s %<dp>10.10s %<ty>-8.8s %<vl>18.8f %<co>14.2f',
86
86
  ky: htx[:trade_id],
87
- dt: htx[:successfully_finished_at].strftime('%F %T'),
88
- dp: htx[:trade_marked_as_paid_at].strftime('%F'),
87
+ dt: htx[:successfully_finished_at]&.strftime('%F %T'),
88
+ dp: htx[:trade_marked_as_paid_at]&.strftime('%F'),
89
89
  ty: htx[:type],
90
- mo: htx[:trading_pair],
91
90
  vl: htx[:btc],
92
91
  co: htx[:eur]
93
92
  )
@@ -138,9 +137,9 @@ module Cns
138
137
  pdes(:successfully_finished_at, t).merge(
139
138
  trade_marked_as_paid_at: ptm(t[:trade_marked_as_paid_at]),
140
139
  username: t[:trading_partner_information][:username],
141
- btc: t[:type] == 'buy' ? t[:amount_currency_to_trade_after_fee].to_d : -1 * t[:amount_currency_to_trade].to_d,
142
- eur: t[:volume_currency_to_pay_after_fee].to_d,
143
- trading_pair: t[:trading_pair].upcase
140
+ type: "#{t[:trading_pair][0..2]}#{t[:type]}",
141
+ btc: t[:type] == 'buy' ? t[:amount_currency_to_trade_after_fee].to_d : t[:amount_currency_to_trade].to_d * -1,
142
+ eur: t[:volume_currency_to_pay_after_fee].to_d
144
143
  )
145
144
  end
146
145
  end
data/lib/cns/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cns
4
- VERSION = '2.1.8'
4
+ VERSION = '2.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cns
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.8
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz