busca possibilidades de arbitragem entre corretoras
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

218 lines
7.0 KiB

module Exchange
property coins = Array(String).new
abstract def book(coin)
abstract def trades(coin)
def broker_name
self.class.name.gsub("Broker::", "")
end
end
module Broker
class Kraken
include Exchange
@coins =
["eth","btc","xrp","ltc","usdt","bch","eur","rep","zec","ada","qtum","xtz","atom","gno","eos","mln","bat","waves","icx","link","sc","omg","paxg","nano","lsk","algo","trx","oxt","kava","comp","storj","knc","repv2","xmr","xlm","dash","dai","usdc", "xdg"]
COIN_CODE = {
"eth": "XETHZEUR",
"btc": "XXBTZEUR",
"xrp": "XXRPZEUR",
"ltc": "XLTCZEUR",
"usdt": "USDTEUR",
"bch": "BCHEUR",
"eur": "EUREUR",
"rep": "REPEUR",
"zec": "XZECZEUR",
"ada": "ADAEUR",
"qtum": "QTUMEUR",
"xtz": "XTZEUR",
"atom": "ATOMEUR",
"gno": "GNOEUR",
"eos": "EOSEUR",
"mln": "MLNEUR",
"bat": "BATEUR",
"waves": "WAVESEUR",
"icx": "ICXEUR",
"link": "LINKEUR",
"sc": "SCEUR",
"omg": "OMGEUR",
"paxg": "PAXGEUR",
"nano": "NANOEUR",
"lsk": "LSKEUR",
"algo": "ALGOEUR",
"trx": "TRXEUR",
"oxt": "OXTEUR",
"kava": "KAVAEUR",
"comp": "COMPEUR",
"storj": "STORJEUR",
"knc": "KNCEUR",
"repv2": "REPV2EUR",
"xmr": "XXMRZEUR",
"xdg": "XDGEUR",
"xlm": "XXLMZEUR",
"dash": "DASHEUR",
"dai": "DAIEUR",
"usdc": "USDCEUR"
}
def book(coin)
url_coin = coin=="btc" ? "xbt" : coin
book = get_json("https://api.kraken.com", "/0/public/Depth?pair=#{url_coin}eur")["result"][COIN_CODE[coin]]
orders = Array(Order).new
asks = book["asks"]
(0..asks.size-1).each do |i|
order = asks[i]
# type, value, quantity, time
orders << Order.new("ask", f(order[0]), (f(order[1]) * f(order[0])), order[2].to_s)
end
bids = book["bids"]
(0..bids.size-1).each do |i|
order = bids[i]
# type, value, quantity, time
orders << Order.new("bid", f(order[0]), (f(order[1]) * f(order[0])), order[2].to_s)
end
orders.sort_by!{|o| o.utc}.reverse
end
def trades(coin)
url_coin = coin=="btc" ? "xbt" : coin
trades_json = get_json("https://api.kraken.com", "/0/public/Trades?pair=#{url_coin}eur")["result"][COIN_CODE[coin]]
trades = Array(Order).new
(0..trades_json.size-1).each do |i|
trade = trades_json[i]
type = trade[3].to_s == "s" ? "sold" : "bought"
trades << Order.new(type, f(trade[0]), (f(trade[1]) * f(trade[0])), trade[2].to_s)
end
trades.sort_by{|o| o.utc}.reverse
end
end
class NovaDAX
include Exchange
@coins = ["btc", "dgb", "dcr", "eth", "bsv", "xmr", "bch", "xlm", "xrp", "waves", "etc", "trx", "btt", "eos", "ada", "bnb", "link", "dash", "ltc", "xtz", "iota", "omg", "doge", "nuls", "brz"]
def book(coin)
book = get_json("https://api.novadax.com", "/v1/market/depth?symbol=#{coin.upcase}_BRL&limit=20")["data"]
orders = Array(Order).new
asks = book["asks"]
(0..asks.size-1).each do |i|
order = asks[i]
# type, value, quantity, time
orders << Order.new("ask", to_eur(f(order[0])), to_eur(f(order[1]) * f(order[0])), Time.utc.to_unix_ms.to_s)
end
bids = book["bids"]
(0..bids.size-1).each do |i|
order = bids[i]
# type, value, quantity, time
orders << Order.new("bid", to_eur(f(order[0])), to_eur(f(order[1]) * f(order[0])), Time.utc.to_unix_ms.to_s)
end
orders.sort_by!{|o| o.utc}.reverse
end
def trades(coin)
trades_json = get_json("https://api.novadax.com", "/v1/market/trades?symbol=#{coin.upcase}_BRL&limit=20")["data"]
trades = Array(Order).new
(0..trades_json.size-1).each do |i|
trade = trades_json[i]
type = trade["side"].to_s == "SELL" ? "sold" : "bought"
trades << Order.new(type, to_eur(f(trade["price"])), to_eur(f(trade["amount"]) * f(trade["price"])), trade["timestamp"].to_s)
end
trades.sort_by!{|t| t.utc}.reverse
end
end
class Braziliex
include Exchange
@coins =
["brl","btc","bch","ltc","eth","dash","zec","dcr","xrp","usdt","tusd","zrx","dai","paxg","sngls","brzx","gmr","omg","gnt","epc","abc","mxt","smart","nbr","bsv","crw","lcc","onix","etc","iop","btg","bnb","eos","prsp","cfty","trx"]
def fees
result = Hash(String, Float64).new
fees_json = get_json("https://braziliex.com", "/api/v1/public/currencies")
coins.each do |c|
result[c] = to_eur fees_json[c]["txWithdrawalFee"].to_s.to_f64
end
result
end
def book(coin)
book = get_json("https://braziliex.com", "/api/v1/public/orderbook/#{coin}_brl")
orders = Array(Order).new
asks = book["asks"]
(0..asks.size-1).each do |i|
order = asks[i]
# type, value, quantity, time
eur_price = to_eur(f(order["price"]))
orders << Order.new("ask", eur_price, f(order["amount"]) * eur_price, Time.utc.to_unix_ms.to_s)
end
bids = book["bids"]
(0..bids.size-1).each do |i|
order = bids[i]
# type, value, quantity, time
eur_price = to_eur(f(order["price"]))
orders << Order.new("bid", eur_price, f(order["amount"]) * eur_price, Time.utc.to_unix_ms.to_s)
end
orders.sort_by!{|o| o.utc}.reverse
end
def trades(coin)
trades_json = get_json("https://braziliex.com", "/api/v1/public/tradehistory/#{coin}_brl")
trades = Array(Order).new
(0..trades_json.size-1).each do |i|
trade = trades_json[i]
type = trade["type"].to_s == "sell" ? "sold" : "bought"
trades << Order.new(type, to_eur(f(trade["price"])), to_eur(f(trade["amount"]) * f(trade["price"])), trade["timestamp"].to_s)
end
trades.sort_by{|t| t.utc}.reverse
end
end
class MercadoBitcoin
include Exchange
@coins = ["btc", "ltc", "usdc", "xrp", "bch", "eth"]
def book(coin)
book = get_json("https://www.mercadobitcoin.net", "/api/#{coin}/orderbook/")
orders = Array(Order).new
asks = book["asks"]
(0..asks.size-1).each do |i|
order = asks[i]
# type, value, quantity, time
orders << Order.new("ask", to_eur(f(order[0])), to_eur(f(order[1]) * f(order[0])), Time.utc.to_unix_ms.to_s)
end
bids = book["bids"]
(0..bids.size-1).each do |i|
order = bids[i]
# type, value, quantity, time
orders << Order.new("bid", to_eur(f(order[0])), to_eur(f(order[1]) * f(order[0])), Time.utc.to_unix_ms.to_s)
end
orders.sort_by!{|o| o.utc}.reverse
end
def trades(coin)
trades_json = get_json("https://www.mercadobitcoin.net", "/api/#{coin}/trades/")
trades = Array(Order).new
(0..trades_json.size-1).each do |i|
trade = trades_json[i]
type = trade["type"].to_s == "sell" ? "sold" : "bought"
trades << Order.new(type, to_eur(f(trade["price"])), to_eur(f(trade["amount"]) * f(trade["price"])), trade["date"].to_s)
end
trades.sort_by{|t| t.utc}.reverse
end
end
end