cryptobot/app/controllers/home_controller.rb

40 lines
1.4 KiB
Ruby

class HomeController < ApplicationController
def index
@currencies = Currency.all
@curr_id = Currency.first.id
bbt
end
def seed
market = Market.where(name: 'BitBay').first
if market.blank?
market = Market.new(name: 'BitBay', url: 'https://bitbay.net')
market.save
end
bit_bay_currencies = [['BTC', 'Bitcoin'],['BCC', 'Bitcoin Cash'], ['ETH','Ethereum'], ['LSK', 'Lisk'], ['LTC', 'Litecoin'], ['DASH', 'Dash'], ['GAME', 'GameCredits']]
for bbc in bit_bay_currencies
curr = Currency.where('name = ?', bbc[0]).first
if curr.blank?
curr = Currency.new(name: bbc[0], description: bbc[1], market_id: market.id)
curr.save
end
end
end
def get_trades
@currencies = Currency.all
@curr_id = params[:curr_id]
bbt
end
def bbt
@bbt = BitBayTrade.where('currency_id = ?', @curr_id).order('cast(tid as unsigned) DESC').limit(20)
@bbt_max_lifetime = BitBayTrade.where('currency_id = ?', @curr_id).order('price DESC').first
@bbt_min_lifetime = BitBayTrade.where('currency_id = ?', @curr_id).order('price ASC').first
time = Time.now - 24.hours
@bbt_max_24h = BitBayTrade.where('currency_id = ? AND date > ?', @curr_id,time).order('price DESC').first
@bbt_min_24h = BitBayTrade.where('currency_id = ? AND date > ?', @curr_id,time).order('price ASC').first
end
end