script change
This commit is contained in:
parent
e39510b309
commit
898bf7d1eb
|
|
@ -9,22 +9,25 @@ require 'json'
|
|||
pause_interval = 3
|
||||
|
||||
start_index = '-1'
|
||||
currency = Currency.where(name: 'BTC').first
|
||||
currencies = {1 => "BTC", 4 => "LSK", 7 => "GAME"}
|
||||
currency_ids = [4,7]
|
||||
#currency = Currency.where(name: 'LSK').first
|
||||
while true
|
||||
for currency_id in currency_ids
|
||||
start_time = Time.now.to_i
|
||||
bbt_index = BitBayTrade.where('currency_id = ?', currency.id).order('cast(tid as unsigned) DESC').first
|
||||
bbt_index = BitBayTrade.where('currency_id = ?', currency_id).order('cast(tid as unsigned) DESC').first
|
||||
unless bbt_index.blank?
|
||||
start_index = bbt_index.tid
|
||||
end
|
||||
uri = "https://bitbay.net/API/Public/#{currency.name}PLN/trades.json?since=#{start_index}"
|
||||
puts "start at #{start_index} index"
|
||||
uri = "https://bitbay.net/API/Public/#{currencies[currency_id]}PLN/trades.json?since=#{start_index}"
|
||||
puts "start at #{start_index} index for #{currencies[currency_id]}"
|
||||
url = URI.parse(uri)
|
||||
resp = Net::HTTP.get_response(url)
|
||||
my_hash = JSON.parse(resp.body)
|
||||
for mh in my_hash
|
||||
bbt = BitBayTrade.where('currency_id = ? AND tid = ?', currency.id, mh['tid']).first
|
||||
bbt = BitBayTrade.where('currency_id = ? AND tid = ?', currency_id, mh['tid']).first
|
||||
if bbt.blank?
|
||||
BitBayTrade.create(currency_id: currency.id, tid: mh['tid'], date: Time.at(mh['date'].to_i), transaction_type: mh['type'], price: mh['price'], amount: mh['amount'])
|
||||
BitBayTrade.create(currency_id: currency_id, tid: mh['tid'], date: Time.at(mh['date'].to_i), transaction_type: mh['type'], price: mh['price'], amount: mh['amount'])
|
||||
#puts "#{mh['tid']} -#{mh['date']} - #{mh['price']} - #{mh['type']} - #{mh['amount']}"
|
||||
end
|
||||
|
||||
|
|
@ -40,3 +43,4 @@ while true
|
|||
sleep(pause_interval)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue