lib/krkt/bigquery.rb in krkt-0.1.1 vs lib/krkt/bigquery.rb in krkt-0.1.2

- old
+ new

@@ -5,11 +5,11 @@ # @author Hernani Rodrigues Vaz module Krkt BD = 'hernanirvaz.coins' - # classe para processar kraken & bigquery + # classe para processar bigquery & kraken class Bigquery # @return [Google::Cloud::Bigquery] API bigquery attr_reader :api # @return [Google::Cloud::Bigquery::QueryJob] job bigquery attr_reader :job @@ -18,21 +18,21 @@ # @return (see sql) attr_reader :sqr # @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho # @option pop [Hash] :h ({}) configuracao ajuste reposicionamento temporal - # @option pop [Boolean] :v (false) mostra transacoes normais & ledger? + # @option pop [Boolean] :v (false) mostra transacoes trades & ledger? # @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas? - # @return [Bigquery] API bigquery & API kraken + # @return [Bigquery] API bigquery & kraken def initialize(pop) # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials # @see https://cloud.google.com/bigquery/docs/authentication/getting-started @api = Google::Cloud::Bigquery.new @ops = pop end - # @return [Kraken] API kraken - processar transacoes normais e ledgers + # @return [Kraken] API kraken - obter saldos & transacoes trades e ledger def transacoes @transacoes ||= Kraken.new( { sl: sql("select * from #{BD}.ussl")[0], nt: sql("select * from #{BD}.ustx order by time,txid"), @@ -78,14 +78,14 @@ end # @return [String] comando insert SQL formatado usl (ledger) def usl_ins "insert #{BD}.usl(txid,refid,time,type,aclass,asset,amount,fee" \ - ") VALUES#{transacoes.ledger.map { |k, v| usl_val1(k, v) }.join(',')}" + ") VALUES#{transacoes.ledger.map { |k, v| usl_val(k, v) }.join(',')}" end - # @return [String] valores formatados usl (ledger parte1) - def usl_val1(idx, hes) + # @return [String] valores formatados usl (ledger) + def usl_val(idx, hes) "('#{idx}'," \ "'#{hes['refid']}'," \ "PARSE_DATETIME('%s', '#{String(hes['time'].round)}')," \ "'#{hes['type']}'," \ "#{hes['aclass'].length.zero? ? 'null' : "'#{hes['aclass']}'"}," \