Browse Source

update

master
Rafael Polo 11 months ago
parent
commit
dbad874ab7
5 changed files with 29 additions and 22 deletions
  1. +3
    -2
      app/broker.cr
  2. +1
    -0
      app/config.cr
  3. +12
    -7
      app/helper.cr
  4. +10
    -6
      public/views/arbs.slang
  5. +3
    -7
      speculari.cr

+ 3
- 2
app/broker.cr View File

@ -7,10 +7,11 @@ module Broker
end
def self.update!
update_last_eur_brl
update_last_eur_brl unless Config.params[:eur_brl]
puts "Updating..."
Broker.all.each do |b|
b.coins.each do |coin|
spawn { b.book(coin) }
spawn { b.trades(coin) }
end
end
end


+ 1
- 0
app/config.cr View File

@ -3,6 +3,7 @@ class Config
def initialize
# @params[:requests] = 0
@params[:eur_brl] = false
@params[:web] = false
@params[:cache] = false
@params[:log] = false


+ 12
- 7
app/helper.cr View File

@ -78,7 +78,7 @@ module Helper
json = HTTP::Client.get("#{url}#{path}").body
File.write(cache, json)
Logger.log "=> #{url}#{path}".colorize(:green)
end
end
rescue e
Logger.log "error: #{e.message}".colorize(:red)
end
@ -86,12 +86,16 @@ module Helper
end
def update_last_eur_brl
json = get_json("https://economia.awesomeapi.com.br", "/eur")[0]
Config.params[:eur_brl] = json["ask"].to_s.to_f64
var_eur_brl = percentage(json["low"].to_s.to_f64, json["high"].to_s.to_f64)
spread = percentage(json["bid"].to_s.to_f64, json["ask"].to_s.to_f64)
puts "EUR:BRL: #{Config.params[:eur_brl]}".colorize(:light_red)
puts "#{var_eur_brl}% diff : #{spread}% spread".colorize(:light_red)
unless Config.params[:eur_brl]
json = get_json("https://economia.awesomeapi.com.br", "/eur")[0]
Config.params[:eur_brl] = json["ask"].to_s.to_f64
var_eur_brl = percentage(json["low"].to_s.to_f64, json["high"].to_s.to_f64)
spread = percentage(json["bid"].to_s.to_f64, json["ask"].to_s.to_f64)
puts "EUR:BRL: #{Config.params[:eur_brl]}".colorize(:light_red)
puts "#{var_eur_brl}% diff : #{spread}% spread".colorize(:light_red)
else
puts "EUR:BRL! #{Config.params[:eur_brl]}".colorize(:light_red)
end
end
def to_eur(f64)
@ -154,6 +158,7 @@ module Helper
end
include Helper
puts intro
class Logger
def self.log(msg, file=:renda, error=false)


+ 10
- 6
public/views/arbs.slang View File

@ -23,12 +23,14 @@ javascript:
var layout = {
title: coin.toUpperCase(), // + " | " + b1 + " ⟷ " + b2,
legend: {
x: 0.1,
y: 1.15,
orientation: "h",
font: {
family: 'Ubuntu',
size: 13,
size: 11,
color: '#000'
},
borderwidth: 1
}
}
};
Plotly.newPlot(id, [], layout, {responsive: true});
@ -54,11 +56,13 @@ javascript:
var trades = json.filter(function(e, i) { return e.type==type && new Date(e.utc) >= horasAntes });
var prices = trades.map(function(e, i){ return e.value.toFixed(3) });
var times = trades.map(function(e, i){ return e.utc });
var avg = prices.reduce((a, b) => (parseFloat(a) + parseFloat(b))) / prices.length;
var symb = type == "bought" ? " < " : " > ";
var trace = {
x: times,
y: prices,
name: broker + " / " + type + " (" + trades.length + ")",
name: broker + symb + trades.length,
line: {shape: 'spline'},
hovertemplate: '%{y:€.2f}',
type: 'scatter',
@ -77,8 +81,8 @@ body
- perms = [Broker::MercadoBitcoin.new, Broker::Kraken.new].combinations(2)
- perms.each do |duo|
/ h3= "#{duo[0].broker_name} ⟷ #{duo[1].broker_name}"
- coins = (duo[0].coins & duo[1].coins) - ["btc", ]
- coins = (duo[0].coins & duo[1].coins)
- coins.each do |coin|
#arb
.graph b1=duo[0].to_s b2=duo[1].to_s coin=coin id="graph-#{duo[0].to_s}-#{duo[1].to_s}-#{coin}"
p.stats b1=duo[0].to_s b2=duo[1].to_s coin=coin id="stats-#{duo[0].to_s}-#{duo[1].to_s}-#{coin}" %
p.stats b1=duo[0].to_s b2=duo[1].to_s coin=coin id="stats-#{duo[0].to_s}-#{duo[1].to_s}-#{coin}" %

+ 3
- 7
speculari.cr View File

@ -34,6 +34,7 @@ OptionParser.parse do |args|
args.banner = "Usage: rico [arguments]"
args.on("-l", "--log", "Show broker HTTP/JSON request/answer logs"){ config[:log] = true }
args.on("-c", "--cache", "Use last cached requests"){ config[:cache] = true }
args.on("-e EURO", "--euro=EURO", "Define EURO:BRL manually"){ |e| config[:eur_brl] = e.to_f64 }
# args.on("-s", "--simulate", "Fake buy"){ config[:simulate] = true }
# args.on("-a", "--assets", "Show wallets"){ Wallet.assets(:format) }
# args.on("-t", "--total", "Sum wallets values and taxes in dolar"){ Wallet.total(:format) }
@ -47,13 +48,8 @@ OptionParser.parse do |args|
args.on("-h", "--help", "Show this help") { puts args; exit }
end
puts intro
if config[:cache]
update_last_eur_brl
else
spawn { puts "Updating..."; Broker.update! }
end
update_last_eur_brl
spawn { Broker.update! } unless config[:cache]
Kemal.run if config[:web]


Loading…
Cancel
Save