cns 0.1.5 → 0.1.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/.reek.yml +64 -0
- data/.rubocop.yml +4 -3
- data/Gemfile.lock +19 -13
- data/cns.gemspec +1 -0
- data/lib/cns/apibc.rb +34 -48
- data/lib/cns/apice1.rb +22 -72
- data/lib/cns/apice2.rb +82 -39
- data/lib/cns/bigquery1.rb +5 -4
- data/lib/cns/bigquery3.rb +62 -47
- data/lib/cns/bigquery4.rb +51 -54
- data/lib/cns/bitcoinde.rb +21 -20
- data/lib/cns/etherscan1.rb +21 -19
- data/lib/cns/etherscan2.rb +7 -7
- data/lib/cns/greymass1.rb +23 -18
- data/lib/cns/greymass2.rb +8 -26
- data/lib/cns/kraken.rb +21 -20
- data/lib/cns/paymium.rb +15 -15
- data/lib/cns/therock.rb +16 -15
- data/lib/cns/version.rb +1 -1
- metadata +17 -2
data/lib/cns/apice2.rb
CHANGED
@@ -50,13 +50,11 @@ module Cns
|
|
50
50
|
# @param [String] uri Uniform Resource Identifier do pedido HTTP
|
51
51
|
# @return [Array<Hash>] lista completa trades bitcoinde
|
52
52
|
def trades_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/trades')
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
)
|
58
|
-
ary += r[:trades]
|
59
|
-
r[:page][:current] < r[:page][:last] ? trades_de(pag + 1, ary) : ary
|
53
|
+
par = "#{uri}?#{URI.encode_www_form(state: 1, page: pag += 1)}"
|
54
|
+
res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true)
|
55
|
+
ary += res[:trades]
|
56
|
+
rep = res[:page]
|
57
|
+
rep[:current] < rep[:last] ? trades_de(pag, ary) : ary
|
60
58
|
rescue StandardError
|
61
59
|
ary
|
62
60
|
end
|
@@ -82,17 +80,38 @@ module Cns
|
|
82
80
|
# @param (see trades_de)
|
83
81
|
# @return [Array<Hash>] lista completa uniformizada depositos bitcoinde
|
84
82
|
def deposits_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/deposits')
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
)
|
90
|
-
ary += deposits_unif_de(r)
|
91
|
-
r[:page][:current] < r[:page][:last] ? deposits_de(pag + 1, ary) : ary
|
83
|
+
par = "#{uri}?#{URI.encode_www_form(state: 2, page: pag += 1)}"
|
84
|
+
res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true)
|
85
|
+
ary += res[:deposits].map { |has| deposit_unif(has) }
|
86
|
+
rep = res[:page]
|
87
|
+
rep[:current] < rep[:last] ? deposits_de(pag, ary) : ary
|
92
88
|
rescue StandardError
|
93
89
|
ary
|
94
90
|
end
|
95
91
|
|
92
|
+
# @example deposit_unif
|
93
|
+
# [
|
94
|
+
# {
|
95
|
+
# txid: 177_245,
|
96
|
+
# time: '2014-01-31T22:01:30+01:00',
|
97
|
+
# tp: 'deposit',
|
98
|
+
# add: '1KK6HhG3quojFS4CY1mPcbyrjQ8BMDQxmT',
|
99
|
+
# qt: '0.13283',
|
100
|
+
# moe: 'btc',
|
101
|
+
# fee: '0'
|
102
|
+
# },
|
103
|
+
# {}
|
104
|
+
# ]
|
105
|
+
# @return [Hash] deposit uniformizado bitcoinde
|
106
|
+
def deposit_unif(has)
|
107
|
+
{
|
108
|
+
add: has[:address],
|
109
|
+
time: Time.parse(has[:created_at]),
|
110
|
+
qt: has[:amount],
|
111
|
+
txid: Integer(has[:deposit_id])
|
112
|
+
}.merge(tp: 'deposit', moe: 'btc', fee: '0')
|
113
|
+
end
|
114
|
+
|
96
115
|
# @example withdrawals_de
|
97
116
|
# {
|
98
117
|
# withdrawals: [
|
@@ -116,17 +135,39 @@ module Cns
|
|
116
135
|
# @param (see deposits_de)
|
117
136
|
# @return [Array<Hash>] lista completa uniformizada withdrawals bitcoinde
|
118
137
|
def withdrawals_de(pag = 0, ary = [], uri = 'https://api.bitcoin.de/v4/btc/withdrawals')
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
)
|
124
|
-
ary += withdrawals_unif_de(r)
|
125
|
-
r[:page][:current] < r[:page][:last] ? withdrawals_de(pag + 1, ary) : ary
|
138
|
+
par = "#{uri}?#{URI.encode_www_form(state: 1, page: pag += 1)}"
|
139
|
+
res = JSON.parse(Curl.get(par) { |obj| obj.headers = hde(par) }.body, symbolize_names: true)
|
140
|
+
ary += res[:withdrawals].map { |has| withdrawal_unif(has) }
|
141
|
+
rep = res[:page]
|
142
|
+
rep[:current] < rep[:last] ? withdrawals_de(pag, ary) : ary
|
126
143
|
rescue StandardError
|
127
144
|
ary
|
128
145
|
end
|
129
146
|
|
147
|
+
# @example withdrawal_unif
|
148
|
+
# [
|
149
|
+
# {
|
150
|
+
# txid: 136_605,
|
151
|
+
# time: '2014-02-05T13:05:17+01:00',
|
152
|
+
# tp: 'withdrawal',
|
153
|
+
# add: '1K9YMDDrmMV25EoYNqi7KUEK57Kn3TCNUJ',
|
154
|
+
# qt: '0.120087',
|
155
|
+
# fee: '0',
|
156
|
+
# moe: 'btc'
|
157
|
+
# },
|
158
|
+
# {}
|
159
|
+
# ]
|
160
|
+
# @return [Hash] withdrawal uniformizada bitcoinde
|
161
|
+
def withdrawal_unif(has)
|
162
|
+
{
|
163
|
+
add: has[:address],
|
164
|
+
time: Time.parse(has[:transferred_at]),
|
165
|
+
qt: has[:amount],
|
166
|
+
fee: has[:network_fee],
|
167
|
+
txid: Integer(has[:withdrawal_id])
|
168
|
+
}.merge(tp: 'withdrawal', moe: 'btc')
|
169
|
+
end
|
170
|
+
|
130
171
|
# @example ledger_fr
|
131
172
|
# [
|
132
173
|
# {
|
@@ -156,11 +197,11 @@ module Cns
|
|
156
197
|
# @param (see trades_de)
|
157
198
|
# @return [Array<Hash>] lista ledger paymium
|
158
199
|
def ledger_fr(pag = 0, ary = [], uri = 'https://paymium.com/api/v1/user/orders')
|
159
|
-
|
160
|
-
Curl.get(uri, offset: pag) { |
|
200
|
+
res = JSON.parse(
|
201
|
+
Curl.get(uri, offset: pag) { |obj| obj.headers = hfr("#{uri}?#{URI.encode_www_form(offset: pag)}") }.body,
|
161
202
|
symbolize_names: true
|
162
203
|
)
|
163
|
-
|
204
|
+
res.empty? ? ary : ledger_fr(pag + res.size, ary + res)
|
164
205
|
rescue StandardError
|
165
206
|
ary
|
166
207
|
end
|
@@ -194,11 +235,11 @@ module Cns
|
|
194
235
|
# @param (see trades_de)
|
195
236
|
# @return [Array<Hash>] lista ledger therock
|
196
237
|
def ledger_mt(pag = 1, ary = [], uri = 'https://api.therocktrading.com/v1/transactions')
|
197
|
-
|
198
|
-
Curl.get(uri, page: pag) { |
|
238
|
+
res = JSON.parse(
|
239
|
+
Curl.get(uri, page: pag) { |obj| obj.headers = hmt("#{uri}?#{URI.encode_www_form(page: pag)}") }.body,
|
199
240
|
symbolize_names: true
|
200
241
|
)[:transactions]
|
201
|
-
|
242
|
+
res.empty? ? ary : ledger_mt(pag + res.size, ary + res)
|
202
243
|
rescue StandardError
|
203
244
|
ary
|
204
245
|
end
|
@@ -230,14 +271,15 @@ module Cns
|
|
230
271
|
# @param [Hash] has acumulador dos dados
|
231
272
|
# @param (see account_us)
|
232
273
|
# @return [Hash] dados trades kraken
|
233
|
-
def trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private'
|
234
|
-
|
235
|
-
|
274
|
+
def trades_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private')
|
275
|
+
uri = 'TradesHistory'
|
276
|
+
non = nnc
|
277
|
+
res = JSON.parse(
|
278
|
+
Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body,
|
236
279
|
symbolize_names: true
|
237
280
|
)[:result]
|
238
|
-
has.merge!(
|
239
|
-
ofs += 50
|
240
|
-
ofs < r[:count] ? trades_us(ofs, has) : has
|
281
|
+
has.merge!(res[:trades])
|
282
|
+
(ofs += 50) < res[:count] ? trades_us(ofs, has) : has
|
241
283
|
rescue StandardError
|
242
284
|
has
|
243
285
|
end
|
@@ -265,14 +307,15 @@ module Cns
|
|
265
307
|
# }
|
266
308
|
# @param (see trades_us)
|
267
309
|
# @return [Hash] dados ledger kraken
|
268
|
-
def ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private'
|
269
|
-
|
270
|
-
|
310
|
+
def ledger_us(ofs = 0, has = {}, urb = 'https://api.kraken.com/0/private')
|
311
|
+
uri = 'Ledgers'
|
312
|
+
non = nnc
|
313
|
+
res = JSON.parse(
|
314
|
+
Curl.post("#{urb}/#{uri}", nonce: non, ofs: ofs) { |obj| obj.headers = hus(uri, nonce: non, ofs: ofs) }.body,
|
271
315
|
symbolize_names: true
|
272
316
|
)[:result]
|
273
|
-
has.merge!(
|
274
|
-
ofs += 50
|
275
|
-
ofs < r[:count] ? ledger_us(ofs, has) : has
|
317
|
+
has.merge!(res[:ledger])
|
318
|
+
(ofs += 50) < res[:count] ? ledger_us(ofs, has) : has
|
276
319
|
rescue StandardError
|
277
320
|
has
|
278
321
|
end
|
data/lib/cns/bigquery1.rb
CHANGED
@@ -8,7 +8,7 @@ module Cns
|
|
8
8
|
BD = 'hernanirvaz.coins'
|
9
9
|
|
10
10
|
# (see Bigquery)
|
11
|
-
class
|
11
|
+
class Bigquery
|
12
12
|
# @return [Google::Cloud::Bigquery] API bigquery
|
13
13
|
attr_reader :api
|
14
14
|
# @return [Google::Cloud::Bigquery::QueryJob] job bigquery
|
@@ -91,9 +91,10 @@ module Cns
|
|
91
91
|
# @return [Boolean] job ok?
|
92
92
|
def job?(cmd)
|
93
93
|
@job = api.query_job(cmd)
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
job.wait_until_done!
|
95
|
+
fld = job.failed?
|
96
|
+
puts(job.error['message']) if fld
|
97
|
+
fld
|
97
98
|
end
|
98
99
|
|
99
100
|
# cria Structured Query Language (SQL) job bigquery
|
data/lib/cns/bigquery3.rb
CHANGED
@@ -13,13 +13,36 @@ module Cns
|
|
13
13
|
def etht_ins
|
14
14
|
"insert #{BD}.etht(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
15
15
|
'value,gas,gasprice,gasused,iserror,txreceipt_status,input,contractaddress,dias' \
|
16
|
-
") VALUES#{apies.novtx.map { |
|
16
|
+
") VALUES#{apies.novtx.map { |obj| etht_1val(obj) }.join(',')}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String] comando insert SQL formatado ethk (token)
|
20
|
+
def ethk_ins
|
21
|
+
"insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
22
|
+
'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias' \
|
23
|
+
") VALUES#{apies.novkx.map { |obj| ethk_1val(obj) }.join(',')}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [String] comando insert SQL formatado eos
|
27
|
+
def eost_ins
|
28
|
+
"insert #{BD}.eos(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
|
29
|
+
") VALUES#{apigm.novax.map { |obj| eost_1val(obj) }.join(',')}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [String] comando insert SQL formatado det (trades)
|
33
|
+
def det_ins
|
34
|
+
"insert #{BD}.det(txid,time,tp,user,btc,eur,dtc,dias) VALUES#{apide.trades.map { |obj| det_1val(obj) }.join(',')}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [String] comando insert SQL formatado del (ledger)
|
38
|
+
def del_ins
|
39
|
+
"insert #{BD}.del(txid,time,tp,add,moe,qt,fee) VALUES#{apide.ledger.map { |obj| del_val(obj) }.join(',')}"
|
17
40
|
end
|
18
41
|
|
19
42
|
# @example (see Apibc#norml_es)
|
20
43
|
# @param [Hash] htx transacao norml etherscan
|
21
44
|
# @return [String] valores formatados etht (norml parte1)
|
22
|
-
def
|
45
|
+
def etht_1val(htx)
|
23
46
|
"(#{Integer(htx[:blockNumber])}," \
|
24
47
|
"#{Integer(htx[:timeStamp])}," \
|
25
48
|
"'#{htx[:hash]}'," \
|
@@ -29,40 +52,36 @@ module Cns
|
|
29
52
|
"'#{htx[:from]}'," \
|
30
53
|
"'#{htx[:to]}'," \
|
31
54
|
"'#{htx[:iax]}'," \
|
32
|
-
"#{
|
55
|
+
"#{etht_2val(htx)}"
|
33
56
|
end
|
34
57
|
|
35
|
-
# @param (see
|
58
|
+
# @param (see etht_1val)
|
36
59
|
# @return [String] valores formatados etht (norml parte2)
|
37
|
-
def
|
60
|
+
def etht_2val(htx)
|
61
|
+
txr = htx[:txreceipt_status]
|
38
62
|
"cast('#{htx[:value]}' as numeric)," \
|
39
63
|
"cast('#{htx[:gas]}' as numeric)," \
|
40
64
|
"cast('#{htx[:gasPrice]}' as numeric)," \
|
41
65
|
"cast('#{htx[:gasUsed]}' as numeric)," \
|
42
66
|
"#{Integer(htx[:isError])}," \
|
43
|
-
"#{
|
44
|
-
"#{
|
67
|
+
"#{txr.length.zero? ? 'null' : txr}," \
|
68
|
+
"#{etht_3val(htx)}"
|
45
69
|
end
|
46
70
|
|
47
|
-
# @param (see
|
71
|
+
# @param (see etht_1val)
|
48
72
|
# @return [String] valores formatados etht (norml parte3)
|
49
|
-
def
|
50
|
-
|
51
|
-
|
73
|
+
def etht_3val(htx)
|
74
|
+
cta = htx[:contractAddress]
|
75
|
+
inp = htx[:input]
|
76
|
+
"#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
|
77
|
+
"#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
|
52
78
|
"#{Integer(ops[:h][htx[:blockNumber]] || 0)})"
|
53
79
|
end
|
54
80
|
|
55
|
-
# @return [String] comando insert SQL formatado ethk (token)
|
56
|
-
def ethk_ins
|
57
|
-
"insert #{BD}.ethk(blocknumber,timestamp,txhash,nonce,blockhash,transactionindex,axfrom,axto,iax," \
|
58
|
-
'value,tokenname,tokensymbol,tokendecimal,gas,gasprice,gasused,input,contractaddress,dias' \
|
59
|
-
") VALUES#{apies.novkx.map { |e| ethk_val1(e) }.join(',')}"
|
60
|
-
end
|
61
|
-
|
62
81
|
# @example (see Apibc#token_es)
|
63
82
|
# @param [Hash] hkx token event etherscan
|
64
83
|
# @return [String] valores formatados ethk (token parte1)
|
65
|
-
def
|
84
|
+
def ethk_1val(hkx)
|
66
85
|
"(#{Integer(hkx[:blockNumber])}," \
|
67
86
|
"#{Integer(hkx[:timeStamp])}," \
|
68
87
|
"'#{hkx[:hash]}'," \
|
@@ -72,12 +91,12 @@ module Cns
|
|
72
91
|
"'#{hkx[:from]}'," \
|
73
92
|
"'#{hkx[:to]}'," \
|
74
93
|
"'#{hkx[:iax]}'," \
|
75
|
-
"#{
|
94
|
+
"#{ethk_2val(hkx)}"
|
76
95
|
end
|
77
96
|
|
78
|
-
# @param (see
|
97
|
+
# @param (see ethk_1val)
|
79
98
|
# @return [String] valores formatados ethk (token parte2)
|
80
|
-
def
|
99
|
+
def ethk_2val(hkx)
|
81
100
|
"cast('#{hkx[:value]}' as numeric)," \
|
82
101
|
"'#{hkx[:tokenName]}'," \
|
83
102
|
"'#{hkx[:tokenSymbol]}'," \
|
@@ -85,49 +104,45 @@ module Cns
|
|
85
104
|
"cast('#{hkx[:gas]}' as numeric)," \
|
86
105
|
"cast('#{hkx[:gasPrice]}' as numeric)," \
|
87
106
|
"cast('#{hkx[:gasUsed]}' as numeric)," \
|
88
|
-
"#{
|
107
|
+
"#{ethk_3val(hkx)}"
|
89
108
|
end
|
90
109
|
|
91
|
-
# @param (see
|
110
|
+
# @param (see ethk_1val)
|
92
111
|
# @return [String] valores formatados ethk (token parte3)
|
93
|
-
def
|
94
|
-
|
95
|
-
|
112
|
+
def ethk_3val(hkx)
|
113
|
+
cta = hkx[:contractAddress]
|
114
|
+
inp = hkx[:input]
|
115
|
+
"#{inp.length.zero? ? 'null' : "'#{inp}'"}," \
|
116
|
+
"#{cta.length.zero? ? 'null' : "'#{cta}'"}," \
|
96
117
|
"#{Integer(ops[:h][hkx[:blockNumber]] || 0)})"
|
97
118
|
end
|
98
119
|
|
99
|
-
# @return [String] comando insert SQL formatado eos
|
100
|
-
def eost_ins
|
101
|
-
"insert #{BD}.eos(gseq,aseq,bnum,time,contract,action,acfrom,acto,iax,amount,moeda,memo,dias" \
|
102
|
-
") VALUES#{apigm.novax.map { |e| eost_val1(e) }.join(',')}"
|
103
|
-
end
|
104
|
-
|
105
120
|
# @example (see Apibc#ledger_gm)
|
106
121
|
# @param [Hash] hlx ledger greymass
|
107
122
|
# @return [String] valores formatados para insert eos (parte1)
|
108
|
-
def
|
109
|
-
|
123
|
+
def eost_1val(hlx)
|
124
|
+
act = hlx[:action_trace][:act]
|
110
125
|
"(#{hlx[:global_action_seq]}," \
|
111
126
|
"#{hlx[:account_action_seq]}," \
|
112
127
|
"#{hlx[:block_num]}," \
|
113
128
|
"DATETIME(TIMESTAMP('#{hlx[:block_time]}'))," \
|
114
|
-
"'#{
|
115
|
-
"'#{
|
116
|
-
"#{
|
129
|
+
"'#{act[:account]}'," \
|
130
|
+
"'#{act[:name]}'," \
|
131
|
+
"#{eost_2val(hlx, act)}"
|
117
132
|
end
|
118
133
|
|
119
|
-
# @param (see
|
134
|
+
# @param (see eost_1val)
|
120
135
|
# @param [Hash] act dados da acao
|
121
136
|
# @return [String] valores formatados para insert eos (parte2)
|
122
|
-
def
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
"'#{
|
127
|
-
"'#{
|
137
|
+
def eost_2val(hlx, act)
|
138
|
+
dat = act[:data]
|
139
|
+
qtd = dat[:quantity].to_s
|
140
|
+
str = dat[:memo].inspect
|
141
|
+
"'#{dat[:from]}'," \
|
142
|
+
"'#{dat[:to]}'," \
|
128
143
|
"'#{hlx[:iax]}'," \
|
129
|
-
"#{
|
130
|
-
"nullif('#{
|
144
|
+
"#{qtd.to_d},'#{qtd[/[[:upper:]]+/]}'," \
|
145
|
+
"nullif('#{str.gsub(/['"]/, '')}','nil')," \
|
131
146
|
"#{ops[:h][String(hlx[:itx])] || 0})"
|
132
147
|
end
|
133
148
|
end
|
data/lib/cns/bigquery4.rb
CHANGED
@@ -6,25 +6,43 @@ module Cns
|
|
6
6
|
class Bigquery
|
7
7
|
private
|
8
8
|
|
9
|
-
# @return [String] comando insert SQL formatado
|
10
|
-
def
|
11
|
-
"insert #{BD}.
|
9
|
+
# @return [String] comando insert SQL formatado ust (trades)
|
10
|
+
def ust_ins
|
11
|
+
"insert #{BD}.ust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
|
12
|
+
"VALUES#{apius.trades.map { |key, val| ust_1val(key, val) }.join(',')}"
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [String] comando insert SQL formatado usl (ledger)
|
16
|
+
def usl_ins
|
17
|
+
"insert #{BD}.usl(txid,refid,time,type,aclass,asset,amount,fee) " \
|
18
|
+
"VALUES#{apius.ledger.map { |key, val| usl_val(key, val) }.join(',')}"
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [String] comando insert SQL formatado fr (ledger)
|
22
|
+
def frl_ins
|
23
|
+
"insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |obj| frl_val(obj) }.join(',')}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [String] comando insert SQL formatado fr (ledger)
|
27
|
+
def mtl_ins
|
28
|
+
"insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
|
29
|
+
"VALUES#{apimt.ledger.map { |obj| mtl_1val(obj) }.join(',')}"
|
12
30
|
end
|
13
31
|
|
14
32
|
# @example (see Apice#trades_de)
|
15
33
|
# @param [Hash] htx trade bitcoinde
|
16
34
|
# @return [String] valores formatados det (trades parte1)
|
17
|
-
def
|
35
|
+
def det_1val(htx)
|
18
36
|
"('#{htx[:trade_id]}'," \
|
19
37
|
"DATETIME(TIMESTAMP('#{htx[:successfully_finished_at]}'))," \
|
20
38
|
"'#{htx[:type]}'," \
|
21
39
|
"'#{htx[:trading_partner_information][:username]}'," \
|
22
|
-
"#{
|
40
|
+
"#{det_2val(htx)}"
|
23
41
|
end
|
24
42
|
|
25
|
-
# @param (see
|
43
|
+
# @param (see det_1val)
|
26
44
|
# @return [String] valores formatados det (trades parte2)
|
27
|
-
def
|
45
|
+
def det_2val(htx)
|
28
46
|
'cast(' \
|
29
47
|
"#{htx[:type] == 'buy' ? htx[:amount_currency_to_trade_after_fee] : "-#{htx[:amount_currency_to_trade]}"}" \
|
30
48
|
' as numeric),' \
|
@@ -33,36 +51,26 @@ module Cns
|
|
33
51
|
"#{Integer(ops[:h][htx[:trade_id]] || 0)})"
|
34
52
|
end
|
35
53
|
|
36
|
-
# @return [String] comando insert SQL formatado del (ledger)
|
37
|
-
def del_ins
|
38
|
-
"insert #{BD}.del(txid,time,tp,add,moe,qt,fee) VALUES#{apide.ledger.map { |h| del_val(h) }.join(',')}"
|
39
|
-
end
|
40
|
-
|
41
54
|
# @example (see Apice#deposits_de)
|
42
55
|
# @example (see Apice#withdrawals_de)
|
43
56
|
# @param [Hash] hlx ledger (deposits + withdrawals) bitcoinde
|
44
57
|
# @return [String] valores formatados del (ledger)
|
45
58
|
def del_val(hlx)
|
59
|
+
tip = hlx[:tp]
|
46
60
|
"(#{hlx[:txid]}," \
|
47
61
|
"DATETIME(TIMESTAMP('#{hlx[:time].iso8601}'))," \
|
48
|
-
"'#{
|
62
|
+
"'#{tip}'," \
|
49
63
|
"'#{hlx[:add]}'," \
|
50
64
|
"'#{hlx[:moe]}'," \
|
51
|
-
"cast(#{
|
65
|
+
"cast(#{tip == 'withdrawal' ? '-' : ''}#{hlx[:qt]} as numeric)," \
|
52
66
|
"cast(#{hlx[:fee]} as numeric))"
|
53
67
|
end
|
54
68
|
|
55
|
-
# @return [String] comando insert SQL formatado ust (trades)
|
56
|
-
def ust_ins
|
57
|
-
"insert #{BD}.ust(txid,ordertxid,pair,time,type,ordertype,price,cost,fee,vol,margin,misc,ledgers,dias) " \
|
58
|
-
"VALUES#{apius.trades.map { |k, v| ust_val1(k, v) }.join(',')}"
|
59
|
-
end
|
60
|
-
|
61
69
|
# @example (see Apice#trades_us)
|
62
70
|
# @param [String] idx identificador transacao
|
63
71
|
# @param [Hash] htx trade kraken
|
64
72
|
# @return [String] valores formatados ust (trades parte1)
|
65
|
-
def
|
73
|
+
def ust_1val(idx, htx)
|
66
74
|
"('#{idx}'," \
|
67
75
|
"'#{htx[:ordertxid]}'," \
|
68
76
|
"'#{htx[:pair]}'," \
|
@@ -72,81 +80,70 @@ module Cns
|
|
72
80
|
"cast(#{htx[:price]} as numeric)," \
|
73
81
|
"cast(#{htx[:cost]} as numeric)," \
|
74
82
|
"cast(#{htx[:fee]} as numeric)," \
|
75
|
-
"#{
|
83
|
+
"#{ust_2val(idx, htx)}"
|
76
84
|
end
|
77
85
|
|
78
|
-
# @param (see
|
86
|
+
# @param (see ust_1val)
|
79
87
|
# @return [String] valores formatados ust (trades parte2)
|
80
|
-
def
|
88
|
+
def ust_2val(idx, htx)
|
89
|
+
msc = htx[:misc].to_s
|
81
90
|
"cast(#{htx[:vol]} as numeric)," \
|
82
91
|
"cast(#{htx[:margin]} as numeric)," \
|
83
|
-
"#{
|
84
|
-
"'#{apius.ledger.select { |_,
|
92
|
+
"#{msc.empty? ? 'null' : "'#{msc}'"}," \
|
93
|
+
"'#{apius.ledger.select { |_, val| val[:refid] == idx }.keys.join(',') || ''}'," \
|
85
94
|
"#{Integer(ops[:h][idx] || 0)})"
|
86
95
|
end
|
87
96
|
|
88
|
-
# @return [String] comando insert SQL formatado usl (ledger)
|
89
|
-
def usl_ins
|
90
|
-
"insert #{BD}.usl(txid,refid,time,type,aclass,asset,amount,fee) " \
|
91
|
-
"VALUES#{apius.ledger.map { |k, v| usl_val(k, v) }.join(',')}"
|
92
|
-
end
|
93
|
-
|
94
97
|
# @example (see Apice#ledger_us)
|
95
|
-
# @param idx (see
|
98
|
+
# @param idx (see ust_1val)
|
96
99
|
# @param [Hash] hlx ledger kraken
|
97
100
|
# @return [String] valores formatados usl (ledger)
|
98
101
|
def usl_val(idx, hlx)
|
102
|
+
acl = hlx[:aclass].to_s
|
99
103
|
"('#{idx}'," \
|
100
104
|
"'#{hlx[:refid]}'," \
|
101
105
|
"PARSE_DATETIME('%s', '#{String(hlx[:time].round)}')," \
|
102
106
|
"'#{hlx[:type]}'," \
|
103
|
-
"#{
|
107
|
+
"#{acl.empty? ? 'null' : "'#{acl}'"}," \
|
104
108
|
"'#{hlx[:asset]}'," \
|
105
109
|
"cast(#{hlx[:amount]} as numeric)," \
|
106
110
|
"cast(#{hlx[:fee]} as numeric))"
|
107
111
|
end
|
108
112
|
|
109
|
-
# @return [String] comando insert SQL formatado fr (ledger)
|
110
|
-
def frl_ins
|
111
|
-
"insert #{BD}.fr(uuid,tipo,valor,moe,time,dias) VALUES#{apifr.ledger.map { |h| frl_val(h) }.join(',')}"
|
112
|
-
end
|
113
|
-
|
114
113
|
# @example (see Apice#ledger_fr)
|
115
114
|
# @param [Hash] hlx ledger paymium
|
116
115
|
# @return [String] valores formatados frl (ledger)
|
117
116
|
def frl_val(hlx)
|
118
|
-
|
117
|
+
uid = hlx[:uuid]
|
118
|
+
"('#{uid}'," \
|
119
119
|
"'#{hlx[:name]}'," \
|
120
120
|
"cast(#{hlx[:amount]} as numeric)," \
|
121
121
|
"'#{hlx[:currency]}'," \
|
122
122
|
"PARSE_DATETIME('%s', '#{hlx[:created_at_int]}')," \
|
123
|
-
"#{Integer(ops[:h][
|
124
|
-
end
|
125
|
-
|
126
|
-
# @return [String] comando insert SQL formatado fr (ledger)
|
127
|
-
def mtl_ins
|
128
|
-
"insert #{BD}.mt(id,time,type,valor,moe,pair,note,trade_id,dias) " \
|
129
|
-
"VALUES#{apimt.ledger.map { |h| mtl_val1(h) }.join(',')}"
|
123
|
+
"#{Integer(ops[:h][uid] || 0)})"
|
130
124
|
end
|
131
125
|
|
132
126
|
# @example (see Apice#ledger_mt)
|
133
127
|
# @param [Hash] hlx ledger therock
|
134
128
|
# @return [String] valores formatados mtl (ledger parte1)
|
135
|
-
def
|
129
|
+
def mtl_1val(hlx)
|
130
|
+
fid = hlx[:fund_id].to_s
|
136
131
|
"(#{hlx[:id]}," \
|
137
132
|
"DATETIME(TIMESTAMP('#{hlx[:date]}'))," \
|
138
133
|
"'#{hlx[:type]}'," \
|
139
134
|
"cast(#{hlx[:price]} as numeric)," \
|
140
135
|
"'#{hlx[:currency]}'," \
|
141
|
-
"#{
|
142
|
-
"#{
|
136
|
+
"#{fid.empty? ? 'null' : "'#{fid}'"}," \
|
137
|
+
"#{mtl_2val(hlx)}"
|
143
138
|
end
|
144
139
|
|
145
|
-
# @param (see
|
140
|
+
# @param (see mtl_1val)
|
146
141
|
# @return [String] valores formatados mtl (ledger parte2)
|
147
|
-
def
|
148
|
-
|
149
|
-
|
142
|
+
def mtl_2val(hlx)
|
143
|
+
nte = hlx[:note].to_s
|
144
|
+
tid = hlx[:trade_id].to_s
|
145
|
+
"#{nte.empty? ? 'null' : "'#{nte}'"}," \
|
146
|
+
"#{tid.empty? ? 'null' : tid.to_s}," \
|
150
147
|
"#{Integer(ops[:h][String(hlx[:id])] || 0)})"
|
151
148
|
end
|
152
149
|
end
|