diff --git a/app/scripts/get_bit_bay_trades.rb b/app/scripts/get_bit_bay_trades.rb index 4b4e86f..790b28f 100644 --- a/app/scripts/get_bit_bay_trades.rb +++ b/app/scripts/get_bit_bay_trades.rb @@ -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 @@ -39,4 +42,5 @@ while true else sleep(pause_interval) end -end \ No newline at end of file +end +end