Browse Source

last tests & crystal upgrade

master
Polo 2 years ago
parent
commit
713d55b4c2
28 changed files with 502 additions and 19 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -1
      README.md
  3. +0
    -0
      app/arbitrage.cr
  4. +1
    -1
      app/broker.cr
  5. +0
    -0
      app/config.cr
  6. +1
    -1
      app/helper.cr
  7. +1
    -1
      app/market.cr
  8. +0
    -0
      app/order.cr
  9. +15
    -14
      app/strategy.cr
  10. +0
    -0
      app/summary.cr
  11. +0
    -0
      app/tick.cr
  12. +0
    -0
      app/wallet.cr
  13. +9
    -0
      brl-btc-eur.txt
  14. +0
    -0
      doc/arbitrage.md
  15. +0
    -0
      doc/arbitragem.png
  16. +2
    -1
      doc/flow.cr
  17. +0
    -0
      doc/pump.jpeg
  18. +0
    -0
      doc/sample.png
  19. +223
    -0
      extra/bot.log
  20. BIN
      extra/dax
  21. +182
    -0
      extra/extra.cr
  22. +1
    -0
      extra/icr
  23. +6
    -0
      extra/shard.lock
  24. +6
    -0
      extra/shard.yml
  25. +53
    -0
      luno.cr
  26. +0
    -0
      renda.cr
  27. +0
    -0
      shard.lock
  28. +0
    -0
      shard.yml

+ 1
- 0
.gitignore View File

@ -3,3 +3,4 @@
.shards
renda
/web
extra/lib

+ 1
- 1
README.md View File

@ -11,7 +11,7 @@ Methods,
- show history
- pump detectors (ex: which coin values grows 5% in 5 minutes)
- fake order/buy to simulate price evolution
- detect arbitrage opportunities (price different in betwwen brokers)
- detect arbitrage opportunities (price different in between brokers)
- make order in dolar (ex: buy $50 of XRP)
- log all activities


+ 0
- 0
app/arbitrage.cr View File


+ 1
- 1
app/broker.cr View File

@ -29,7 +29,7 @@ class Broker
# sign non-public requests
unless method.starts_with?("public")
url += "?apikey=#{KEY}&nonce=#{start_time.epoch_ms}&#{params}"
url += "?apikey=#{KEY}&nonce=#{start_time.to_unix_ms}&#{params}"
apisign = OpenSSL::HMAC.hexdigest(:sha512, PVT, url)
headers = HTTP::Headers{"apisign" => apisign}
else


+ 0
- 0
app/config.cr View File


+ 1
- 1
app/helper.cr View File

@ -33,7 +33,7 @@ def percentage(x, y)
end
def as_time(time, tmz=false)
parsed_time = Time.parse(time.to_s, "%Ft%T.%L")
parsed_time = Time.parse!(time.to_s, "%Ft%T.%L")
tmz ? parsed_time + TMZ : parsed_time
end


+ 1
- 1
app/market.cr View File

@ -52,7 +52,7 @@ class Market
begin
# date_in_btc = JSON.parse(File.read("log/orders.json"))[currency][datetime.to_s].to_s.to_f64
# result = date_in_btc * last_value_from("usdt-btc")
url = "/public?command=returnChartData&currencyPair=USDT_BTC&start=#{(datetime - 1.hour).epoch}&end=#{datetime.epoch}&period=86400"
url = "/public?command=returnChartData&currencyPair=USDT_BTC&start=#{(datetime - 1.hour).to_unix_ms}&end=#{datetime.to_unix_ms}&period=86400"
client = HTTP::Client.new(URI.parse("https://poloniex.com"))
Logger.log "-> #{url}"
result = JSON.parse(client.get(url).body).first["weightedAverage"].to_s.to_f64.as(Float64)


+ 0
- 0
app/order.cr View File


+ 15
- 14
app/strategy.cr View File

@ -9,9 +9,9 @@ class Strategy
fastestes = ["xrp","nano","eos","steem","xlm","bits"]
last_btc_in_usd = Market.last_value_from("usdt-btc")
loop do
#loop do
sleep 1
cryptopia = get("https://www.cryptopia.co.nz", "/api/GetMarkets/BTC")
bittrex = get("https://bittrex.com", "/api/v1.1/public/getmarketsummaries")
@ -41,7 +41,7 @@ class Strategy
perc = percentage(last_b, last_c)
end
if perc > 8 && perc < 100
if perc > 5 && perc < 100
count = total = 0
puts "=> #{market} | #{from}->#{to} | #{from_value}->#{to_value} | +#{perc}%".colorize(:yellow)# if hist[coin]>0 || hist[coin]!=perc
# hist[coin] = perc
@ -50,22 +50,23 @@ class Strategy
qtd = h["Total"].to_s.to_f64
ago = as_time_ago(Time.parse(h["Timestamp"].to_s, "%s") - (Time.now + 2.hours))
puts "#{ago} | #{price} | #{percentage(from_value, price)}% | #{percentage(to_value, price)}% | $#{qtd*last_btc_in_usd}".colorize(h["Type"] == "Sell" ? :red : :green)
#end
line
if price > last_c
count += 1
qtd = h["Total"].to_s.to_f64
puts "+#{percentage(last_c, price)}% | $#{qtd*last_btc_in_usd}"
total += qtd
end
end
puts total*last_btc_in_usd if total > 0
line
# if price > last_c
# count += 1
# qtd = buy["Total"].to_s.to_f64
# puts "+#{percentage(last_c, price)}% | $#{qtd*last_btc_in_usd}"
# total += qtd
# end
# end
# puts total*last_btc_in_usd if total > 0
# line
end
end
end
end
end
#end
# end
end
#puts "#{bigger} #{market} +#{perc} | #{cryptopia} / #{bittrex}".colorize(:green) if perc > 10 && perc < 200 && bigger=="cryptopia"


+ 0
- 0
app/summary.cr View File


+ 0
- 0
app/tick.cr View File


+ 0
- 0
app/wallet.cr View File


+ 9
- 0
brl-btc-eur.txt View File

@ -0,0 +1,9 @@
1000 BRL em BTC na brasilex
- 0.5% trade fee = 995 BRL
= 995 ÷ 27156.84 = 0.03663902 BTC
= 0.03663902 x 5650 = 207 EUR
= -1.5% fee = 203 EUR
= 944.23BRL
:(

+ 0
- 0
doc/arbitrage.md View File


+ 0
- 0
doc/arbitragem.png View File

Before After
Width: 1600  |  Height: 900  |  Size: 284 KiB Width: 1600  |  Height: 900  |  Size: 284 KiB

+ 2
- 1
doc/flow.cr View File

@ -1,6 +1,7 @@
require "colorize"
# is sell it in BRL profitable bringing back to EUR? no!
# is sell it in BRL profitable bringing back to EUR?
# no!
def profit!(invest)
# euro_to_exchange | n26 -> luno


+ 0
- 0
doc/pump.jpeg View File

Before After
Width: 800  |  Height: 450  |  Size: 65 KiB Width: 800  |  Height: 450  |  Size: 65 KiB

+ 0
- 0
doc/sample.png View File

Before After
Width: 1600  |  Height: 900  |  Size: 268 KiB Width: 1600  |  Height: 900  |  Size: 268 KiB

+ 223
- 0
extra/bot.log View File

@ -0,0 +1,223 @@
= kraken x mercadobitcoin =
EUR:BRL : 4.51
+---------+--------------------+---------------------+--------+--------+
| Coin | BRL->€ | €->BRL | Diff % | |
+---------+--------------------+---------------------+--------+--------+
| BTC | 29500.0 -> 6541.02 | 6395.4 -> 28843.254 | 2.28 | |
+---------+--------------------+---------------------+--------+--------+
| Buying | Ammount | BRL | Diff % | Profit |
+---------+--------------------+---------------------+--------+--------+
| 29500.0 | 0.0338983 | 1000.0 | 2.28 | 22.8 |
+---------+--------------------+---------------------+--------+--------+
| 29440.0 | 0.00442224 | 130.19 | 2.07 | 2.69 |
+---------+--------------------+---------------------+--------+--------+
| 29430.0 | 0.00396872 | 116.8 | 2.03 | 2.37 |
+---------+--------------------+---------------------+--------+--------+
| 29430.0 | 0.00319905 | 94.15 | 2.03 | 1.91 |
+---------+--------------------+---------------------+--------+--------+
| 29430.0 | 0.00268304 | 78.96 | 2.03 | 1.6 |
+---------+--------------------+---------------------+--------+--------+
| 29410.0 | 0.0030825 | 90.66 | 1.96 | 1.78 |
+---------+--------------------+---------------------+--------+--------+
| 29410.0 | 0.0026556 | 78.1 | 1.96 | 1.53 |
+---------+--------------------+---------------------+--------+--------+
| 29410.0 | 0.0016432 | 48.33 | 1.96 | 0.95 |
+---------+--------------------+---------------------+--------+--------+
| 29410.0 | 0.00080506 | 23.68 | 1.96 | 0.46 |
+---------+--------------------+---------------------+--------+--------+
| 29410.0 | 0.0049162 | 144.59 | 1.96 | 2.83 |
+---------+--------------------+---------------------+--------+--------+
| 29410.0 | 0.00172571 | 50.75 | 1.96 | 0.99 |
+---------+--------------------+---------------------+--------+--------+
| 29410.0 | 0.00125705 | 36.97 | 1.96 | 0.72 |
+---------+--------------------+---------------------+--------+--------+
| 29410.0 | 0.00147865 | 43.49 | 1.96 | 0.85 |
+---------+--------------------+---------------------+--------+--------+
| 29410.0 | 0.00369495 | 108.67 | 1.96 | 2.13 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.06802721 | 2000.0 | 1.93 | 38.6 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00480512 | 141.27 | 1.93 | 2.73 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00066404 | 19.52 | 1.93 | 0.38 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00209531 | 61.6 | 1.93 | 1.19 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.0014736 | 43.32 | 1.93 | 0.84 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00341414 | 100.38 | 1.93 | 1.94 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00387204 | 113.84 | 1.93 | 2.2 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00324722 | 95.47 | 1.93 | 1.84 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00130886 | 38.48 | 1.93 | 0.74 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00453385 | 133.3 | 1.93 | 2.57 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.001258 | 36.99 | 1.93 | 0.71 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.001451 | 42.66 | 1.93 | 0.82 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00471949 | 138.75 | 1.93 | 2.68 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00371942 | 109.35 | 1.93 | 2.11 |
+---------+--------------------+---------------------+--------+--------+
| 29400.0 | 0.00237519 | 69.83 | 1.93 | 1.35 |
+---------+--------------------+---------------------+--------+--------+
| 29390.0 | 0.00328934 | 96.67 | 1.9 | 1.84 |
+---------+--------------------+---------------------+--------+--------+
| 29390.0 | 0.00301783 | 88.69 | 1.9 | 1.69 |
+---------+--------------------+---------------------+--------+--------+
| 29390.0 | 0.00261581 | 76.88 | 1.9 | 1.46 |
+---------+--------------------+---------------------+--------+--------+
| 29390.0 | 0.00089906 | 26.42 | 1.9 | 0.5 |
+---------+--------------------+---------------------+--------+--------+
| 29390.0 | 0.00174163 | 51.19 | 1.9 | 0.97 |
+---------+--------------------+---------------------+--------+--------+
| 29390.0 | 0.00263847 | 77.54 | 1.9 | 1.47 |
+---------+--------------------+---------------------+--------+--------+
| 29380.0 | 0.00482208 | 141.67 | 1.86 | 2.64 |
+---------+--------------------+---------------------+--------+--------+
| 29380.0 | 0.00491699 | 144.46 | 1.86 | 2.69 |
+---------+--------------------+---------------------+--------+--------+
| 29380.0 | 0.00077307 | 22.71 | 1.86 | 0.42 |
+---------+--------------------+---------------------+--------+--------+
| 29380.0 | 0.00499858 | 146.86 | 1.86 | 2.73 |
+---------+--------------------+---------------------+--------+--------+
| 29380.0 | 0.00268455 | 78.87 | 1.86 | 1.47 |
+---------+--------------------+---------------------+--------+--------+
| 29370.0 | 0.00407762 | 119.76 | 1.83 | 2.19 |
+---------+--------------------+---------------------+--------+--------+
| 29370.0 | 0.00414101 | 121.62 | 1.83 | 2.23 |
+---------+--------------------+---------------------+--------+--------+
| 29370.0 | 0.00238066 | 69.92 | 1.83 | 1.28 |
+---------+--------------------+---------------------+--------+--------+
| 29370.0 | 0.00365914 | 107.47 | 1.83 | 1.97 |
+---------+--------------------+---------------------+--------+--------+
| 29360.0 | 0.00161822 | 47.51 | 1.79 | 0.85 |
+---------+--------------------+---------------------+--------+--------+
| 29340.0 | 0.00341949 | 100.33 | 1.72 | 1.73 |
+---------+--------------------+---------------------+--------+--------+
| 29340.0 | 0.00227311 | 66.69 | 1.72 | 1.15 |
+---------+--------------------+---------------------+--------+--------+
| 29310.0 | 0.0048604 | 142.46 | 1.62 | 2.31 |
+---------+--------------------+---------------------+--------+--------+
| 29300.0 | 0.05119453 | 1500.0 | 1.58 | 23.7 |
+---------+--------------------+---------------------+--------+--------+
| 29250.0 | 0.0037726 | 110.35 | 1.41 | 1.56 |
+---------+--------------------+---------------------+--------+--------+
| 29240.0 | 0.00433101 | 126.64 | 1.38 | 1.75 |
+---------+--------------------+---------------------+--------+--------+
| 29230.0 | 0.00084619 | 24.73 | 1.34 | 0.33 |
+---------+--------------------+---------------------+--------+--------+
| 29230.0 | 0.00209873 | 61.35 | 1.34 | 0.82 |
+---------+--------------------+---------------------+--------+--------+
| 29220.0 | 0.00493669 | 144.25 | 1.31 | 1.89 |
+---------+--------------------+---------------------+--------+--------+
| 29220.0 | 0.00271674 | 79.38 | 1.31 | 1.04 |
+---------+--------------------+---------------------+--------+--------+
| 29220.0 | 0.00103819 | 30.34 | 1.31 | 0.4 |
+---------+--------------------+---------------------+--------+--------+
| 29220.0 | 0.00163589 | 47.8 | 1.31 | 0.63 |
+---------+--------------------+---------------------+--------+--------+
| 29220.0 | 0.00155659 | 45.48 | 1.31 | 0.6 |
+---------+--------------------+---------------------+--------+--------+
| 29220.0 | 0.00248891 | 72.73 | 1.31 | 0.95 |
+---------+--------------------+---------------------+--------+--------+
| 29210.0 | 0.00493468 | 144.14 | 1.27 | 1.83 |
+---------+--------------------+---------------------+--------+--------+
| 29210.0 | 0.00178082 | 52.02 | 1.27 | 0.66 |
+---------+--------------------+---------------------+--------+--------+
| 29210.0 | 0.00263204 | 76.88 | 1.27 | 0.98 |
+---------+--------------------+---------------------+--------+--------+
| 29210.0 | 0.00462767 | 135.17 | 1.27 | 1.72 |
+---------+--------------------+---------------------+--------+--------+
| 29210.0 | 0.00338985 | 99.02 | 1.27 | 1.26 |
+---------+--------------------+---------------------+--------+--------+
| 29210.0 | 0.00187295 | 54.71 | 1.27 | 0.69 |
+---------+--------------------+---------------------+--------+--------+
| 29210.0 | 0.00278892 | 81.46 | 1.27 | 1.03 |
+---------+--------------------+---------------------+--------+--------+
| 29210.0 | 0.00054685 | 15.97 | 1.27 | 0.2 |
+---------+--------------------+---------------------+--------+--------+
| 29200.0 | 0.00302074 | 88.21 | 1.24 | 1.09 |
+---------+--------------------+---------------------+--------+--------+
| 29200.0 | 0.00439534 | 128.34 | 1.24 | 1.59 |
+---------+--------------------+---------------------+--------+--------+
| 29200.0 | 0.00347375 | 101.43 | 1.24 | 1.26 |
+---------+--------------------+---------------------+--------+--------+
| 29200.0 | 0.002736 | 79.89 | 1.24 | 0.99 |
+---------+--------------------+---------------------+--------+--------+
| 29200.0 | 0.03424657 | 1000.0 | 1.24 | 12.4 |
+---------+--------------------+---------------------+--------+--------+
| 29200.0 | 0.00167208 | 48.82 | 1.24 | 0.61 |
+---------+--------------------+---------------------+--------+--------+
| 29190.0 | 0.00164478 | 48.01 | 1.2 | 0.58 |
+---------+--------------------+---------------------+--------+--------+
| 29190.0 | 0.00384711 | 112.3 | 1.2 | 1.35 |
+---------+--------------------+---------------------+--------+--------+
| 29190.0 | 0.00216209 | 63.11 | 1.2 | 0.76 |
+---------+--------------------+---------------------+--------+--------+
| 29190.0 | 0.0012053 | 35.18 | 1.2 | 0.42 |
+---------+--------------------+---------------------+--------+--------+
| 29180.0 | 0.00083191 | 24.28 | 1.17 | 0.28 |
+---------+--------------------+---------------------+--------+--------+
| 29180.0 | 0.0035297 | 103.0 | 1.17 | 1.21 |
+---------+--------------------+---------------------+--------+--------+
| 29180.0 | 0.00371082 | 108.28 | 1.17 | 1.27 |
+---------+--------------------+---------------------+--------+--------+
| 29170.0 | 0.00498899 | 145.53 | 1.13 | 1.64 |
+---------+--------------------+---------------------+--------+--------+
| 29000.0 | 0.08620689 | 2500.0 | 0.54 | 13.5 |
+---------+--------------------+---------------------+--------+--------+
| 29000.0 | 0.06896551 | 2000.0 | 0.54 | 10.8 |
+---------+--------------------+---------------------+--------+--------+
| Total | 0.5610492500000003 | 16406.63 | 1.63 | 267.43 |
+---------+--------------------+---------------------+--------+--------+
+--------+-------------------+--------------------+--------+--------+
| Coin | BRL->€ | €->BRL | Diff % | |
+--------+-------------------+--------------------+--------+--------+
| ETH | 540.0 -> 119.7339 | 115.92 -> 522.7992 | 3.29 | |
+--------+-------------------+--------------------+--------+--------+
| Buying | Ammount | BRL | Diff % | Profit |
+--------+-------------------+--------------------+--------+--------+
+--------+------------------+-------------------+--------+--------+
| Coin | BRL->€ | €->BRL | Diff % | |
+--------+------------------+-------------------+--------+--------+
| LTC | 240.0 -> 53.2151 | 36.96 -> 166.6896 | 43.98 | |
+--------+------------------+-------------------+--------+--------+
| Buying | Ammount | BRL | Diff % | Profit |
+--------+------------------+-------------------+--------+--------+
| 190.0 | 0.52631578 | 100.0 | 13.98 | 13.98 |
+--------+------------------+-------------------+--------+--------+
| Total | 0.52631578 | 100.0 | 13.98 | 13.98 |
+--------+------------------+-------------------+--------+--------+
+--------+-------------------+------------------+--------+--------+
| Coin | BRL->€ | €->BRL | Diff % | |
+--------+-------------------+------------------+--------+--------+
| BCH | 823.0 -> 182.4834 | 181.5 -> 818.565 | 0.54 | |
+--------+-------------------+------------------+--------+--------+
| Buying | Ammount | BRL | Diff % | Profit |
+--------+-------------------+------------------+--------+--------+
| 823.0 | 0.14122866 | 116.23 | 0.54 | 0.63 |
+--------+-------------------+------------------+--------+--------+
| Total | 0.14122866 | 116.23 | 0.54 | 0.63 |
+--------+-------------------+------------------+--------+--------+
+--------+------------------+--------------------+--------+--------+
| Coin | BRL->€ | €->BRL | Diff % | |
+--------+------------------+--------------------+--------+--------+
| DASH | 210.0 -> 46.5632 | 37.176 -> 167.6638 | 25.25 | |
+--------+------------------+--------------------+--------+--------+
| Buying | Ammount | BRL | Diff % | Profit |
+--------+------------------+--------------------+--------+--------+
| 210.0 | 0.47619047 | 100.0 | 25.25 | 25.25 |
+--------+------------------+--------------------+--------+--------+
| Total | 0.47619047 | 100.0 | 25.25 | 25.25 |
+--------+------------------+--------------------+--------+--------+
2020-01-02 00:12:24 UTC

BIN
extra/dax View File


+ 182
- 0
extra/extra.cr View File

@ -0,0 +1,182 @@
require "colorize"
require "json"
require "http/client"
require "openssl/hmac"
require "terminal_table"
DEBUG = false
def log(str)
pp str if DEBUG
end
def eur_brl
get_json("https://economia.awesomeapi.com.br", "/eur")[0]["ask"].to_s.to_f64
end
def percentage(x, y)
x, y = x.to_f64, y.to_f64
pct = x < y ? ((y - x) / x) * 100.0 : - ((x - y) / y) * 100.0
pct.round(2)
end
def profit_perct(x, por)
(x.to_f64 * por.to_f64/100).round(2).to_s
end
def get_json(url, path)
# result = 0
# puts "http://51.15.63.128:2020/?url=#{url}#{path}"
log "=> #{url}#{path}".colorize(:yellow)
z = HTTP::Client.get("#{url}#{path}").body
JSON.parse(z)
# rescue e
# log "error: #{e}"
# end
end
def ago(utc)
date = utc ? Time.parse(utc, "%Y-%m-%dT%H:%M:%S.%6N", Time::Location::UTC) : Time.now
span = (Time.now - date)
"#{span.days}d#{span.hours}h#{span.minutes}m#{span.seconds}s"
end
class Order
JSON.mapping(
bids: Array(Float)
)
end
# get_json("https://api.kraken.com", "/0/public/AssetPairs", "result").each_value do |market|
# begin
# from, to = market["wsname"].to_s.split("/")
# puts "#{from} -> #{to};"
# end
# end
# def arbitrage
# euro = eur_brl
# coins = ["xxbt", "eth", "ltc", "bch", "xrp", "xdg", "link", "ada", "eos", "xlm"]
# coins.each do |c1|
# coins.each do |c2|
# begin
# ticker = get_json("https://api.kraken.com", "/0/public/Depth?pair=#{c1}#{c2}")["result"]
# key = /\"(\w+)\"/.match(ticker.to_s).try &.[1] || "eth"
# next_c1 = ticker[key]["asks"][0][0].to_s.to_f64.round(4) || 0
#
#
# c1 = (c1=="xbt") ? "btc" : c1
# c1 = (c1=="xdg") ? "doge" : c1
#
# c2 = (c2=="xbt") ? "btc" : c2
# c2 = (c2=="xdg") ? "doge" : c2
# json = get_json("https://api.novadax.com", "/v1/market/ticker?symbol=#{c1.upcase}_#{c2.upcase}")
# last_c2 = json["data"]["lastPrice"].to_s.to_f64
# perct = percentage(next_c1, last_c2)
#
# puts "#{c1}:#{c2} #{next_c1} -> #{last_c2} | #{perct.to_s}"
# rescue e
# puts e
# end
# end
# end
# end
# https://www.mercadobitcoin.net/api/eth/orderbook/
def arbitrage2
euro = eur_brl
puts "EUR:BRL : #{euro}"
# braziliex x kraken
table = nil
big_total = big_invested = 0.0
["xxbt", "eth", "bch", "xrp", "dash", "ltc"].each do |coin|
# ["xxbt", "eth", "ltc", "bch", "xrp", "xdg", "link", "ada", "eos", "xlm"].each do |coin| #
table = TerminalTable.new
table.headings = ["Coin", "BRL->€", "€->BRL","Diff %",""]
coin = "xbt" if coin == "xxbt"
ticker = get_json("https://api.kraken.com", "/0/public/Depth?pair=#{coin}eur")["result"]
key = /\"(\w+)\"/.match(ticker.to_s).try &.[1] || "eth"
next_eur = ticker[key]["asks"][0][0].to_s.to_f64.round(4) || 0
in_brl = (next_eur * euro).round(4)
coin = (coin=="xbt") ? "btc" : coin
coin = (coin=="xdg") ? "doge" : coin
# last_brl = get_json("https://api.cryptomkt.com/", "v1/ticker?market=#{coin.upcase}BRL")["data"][0]["last_price"].to_s.to_f64
# json = get_json("https://api.novadax.com", "/v1/market/ticker?symbol=#{coin.upcase}_BRL")
# last_brl = json["data"]["lastPrice"].to_s.to_f64
# last_brl =get_json("https://www.mercadobitcoin.net", "/api/#{coin.upcase}/ticker/")["ticker"]["last"].to_s.to_f64
last_brl = get_json("https://omnitrade.io/", "api/v2/tickers/#{coin}brl")["ticker"]["last"].to_s.to_f64
in_euro = (last_brl / euro).round(4)
perct = percentage(next_eur, in_euro)
table << [coin.to_s.upcase, "#{last_brl} -> #{in_euro}", "#{next_eur} -> #{in_brl}", perct.to_s, ""]
# orderbook
# data = get_json("https://www.mercadobitcoin.net", "/api/#{coin}/orderbook/")
# data = get_json("https://api.cryptomkt.com","/v1/book?market=#{coin.upcase}BRL&type=buy&page=0")["data"]
# data = get_json("https://api.novadax.com", "/v1/market/depth?symbol=#{coin.upcase}_BRL&limit=10")["data"]
data = get_json("https://omnitrade.io/", "api/v2/order_book?market=#{coin}brl&bids_limit=200")
buys = data["bids"]
sells = data["asks"]
count = 0
total_price = total_perc = total = 0.0
[sells, buys].each do |book|
table << ["Sell/Buy", "Ammount", "BRL","Diff %","Profit"]
book.size.times do |i|
price = book[i]["price"].to_s.to_f64
amount = book[i]["volume"].to_s.to_f64
perc = percentage(in_brl, price)
# if perc >= 0.4
count += 1
total += amount
total_price += price*amount
total_perc += percentage(in_brl, price)
totalt=(price*amount)
profit_perc = profit_perct(totalt, perc)
big_total += profit_perc.to_f64
table << [price.round(4).to_s, amount.to_s, totalt.round(3).to_s, perc.to_s, profit_perc]
# end
end
end
tp = (total_price).round(2)
big_invested += tp
avg = (total_perc/count).round(2)
table << ["Total", total.to_s, tp.to_s, avg, profit_perct(tp, avg)] if avg > 0
table.separate_rows = true
puts table.render
puts
# table.push ["Buy", "Ammount", "BRL","Diff %","Profit"]
# buys = get_json("https://braziliex.com", "/api/v1/public/orderbook/#{coin}_brl")["bids"].to_json
# Array(Order).from_json(buys)[0..8].each do |o|
# price = o.price.to_f64
# amount = o.amount.to_f64
# perc = percentage(in_brl, price)
# if price >= in_brl
# totalt=(price*amount)
# table.push [price.round(2).to_s, amount.to_s, totalt.round(2).to_s, perc.to_s, profit_perct(totalt, perc)]
# end
# end
end
puts
puts "#{big_total.round(2)} profit with #{big_invested.round(2)} invested"
end
# arbitrage
puts " = kraken x mercadobitcoin = "
arbitrage2
# puts Time.utc
# 0.68% to buy eos em mkt
# +------+---------------------+---------------------+--------+
# | Coin | BRL->€ | €->BRL | Diff % |
# +------+---------------------+---------------------+--------+
# | eos | 21.765 -> 4.9354 | 4.6478 -> 20.4968 | 6.19 |
# +------+---------------------+---------------------+--------+
# | btc | 21506.0 -> 4876.644 | 4718.3 -> 20807.703 | 3.36 |
# +------+---------------------+---------------------+--------+
# | eth | 703.6 -> 159.5465 | 151.31 -> 667.2771 | 5.44 |
# +------+---------------------+---------------------+--------+

+ 1
- 0
extra/icr

@ -0,0 +1 @@
Subproject commit 08c1f60e2f4b3b1fa662e19fce27748d136e2808

+ 6
- 0
extra/shard.lock View File

@ -0,0 +1,6 @@
version: 1.0
shards:
terminal_table:
github: benoist/terminal_table.cr
commit: a14e244219a6a7b804b3491bafcff73f4b74855e

+ 6
- 0
extra/shard.yml View File

@ -0,0 +1,6 @@
name: shards
version: 0.1.0
dependencies:
terminal_table:
github: benoist/terminal_table.cr

+ 53
- 0
luno.cr View File

@ -0,0 +1,53 @@
require "colorize"
# is sell it in BRL profitable bringing back to EUR? no!
def profit!(invest)
# euro_to_exchange | n26 -> luno
puts "=> #{invest} EUR".colorize(:green)
puts "euro -> btc".colorize(:blue)
last_eur_btc = 8821.225 # @last_eur_btc = https://www.luno.com/ajax/1/price_chart?currency=XBTEUR
btcs = (1/last_eur_btc) * invest
puts "=> #{btcs} BTC".colorize(:green)
puts "# btc_to_market".colorize(:blue) # | luno -> mercadobitcoin
send_fee = (1/last_eur_btc) * 30 # 2018/01/20"),22.403 : https://bitinfocharts.com/comparison/bitcoin-transactionfees.html#3m
puts "=> #{send_fee} BTC send fee".colorize(:red)
sent = btcs - send_fee
puts "=> #{sent} BTC sent".colorize(:green)
puts "# sell_btc_for_BRL".colorize(:blue)
received = sent
last_btc_brl = 36996.0 # https://www.mercadobitcoin.net/api/BTC/ticker/
in_brl = last_btc_brl * received
puts "=> R$#{in_brl} conversion".colorize(:yellow)
execution_fee = in_brl - (in_brl - (in_brl*0.01))
puts "=> R$#{execution_fee} execution fee".colorize(:red)
convertido = in_brl - execution_fee
puts "=> R$#{convertido} convertido".colorize(:yellow)
puts "# withdraw_real".colorize(:blue) # send to ITAU
saque_fee = in_brl - (in_brl - (in_brl*0.02)) - 3 # R$ 2,90 + 1,99%
puts "=> R$#{saque_fee} saque fee".colorize(:red)
sacado = convertido - saque_fee
puts "=> R$#{sacado} sacado".colorize(:yellow)
puts "# EUR_in_BRL".colorize(:blue)
cotacao = 0.25439 # brl-eur
converted = (1/cotacao) * (invest - 30)
puts "=> R$#{converted} EUR/BRL".colorize(:green)
puts "# real_to_eur".colorize(:blue) # transferWise euros back
puts "=> #{converted} EUR convertido".colorize(:yellow)
reenvio_fee = converted - (converted - (converted*0.028))
puts "=> #{reenvio_fee} BRL reenvio fee".colorize(:red)
total = converted - reenvio_fee
puts "=> #{total} EUR reconvertido".colorize(:yellow)
puts "=> #{total-invest} EUR lucro".colorize(:green)
end
profit! 8821

+ 0
- 0
renda.cr View File


+ 0
- 0
shard.lock View File


+ 0
- 0
shard.yml View File


Loading…
Cancel
Save