-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot_bitfinex.rb
78 lines (53 loc) · 1.37 KB
/
bot_bitfinex.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'dotenv'
require 'bitfinex-rb'
require_relative 'bitfinex/db'
Dotenv.load('.env')
BASE_URL = "https://api.bitfinex.com/v2/"
API_KEY = ENV["BF_API_KEY"]
API_SECRET = ENV["BF_SECRET"]
Bitfinex::Client.configure do |conf|
conf.secret = API_SECRET
conf.api_key = API_KEY
conf.use_api_v2
end
def base_curr
"ETH"
end
def use_v2
Bitfinex::Client.configure do |conf|
conf.use_api_v2
end
end
def get_pairs
#["tEOSETH","tBTCUSD","tETHUSD","tNEOETH","tOMGETH"]
curr = BitfinexDB.get_wallet_curr
curr.delete("tETHETH")
curr+=["tETHUSD","tBTCUSD"]
curr
end
def update_bitfinex_tickers
client = Bitfinex::Client.new
#use_v2
symbols_id=BitfinexDB.symb_hash
symbols = get_pairs
tickers = client.ticker(*symbols)
out=[]
tickers.each do |tt|
symb=tt.shift
v1name = symb.sub('t','')
sid = symbols_id[v1name]
BitfinexDB.save_tick_to_db(sid,tt)
BitfinexDB.save_to_rates(sid,tt)
bid=tt[0]
last = BitfinexDB.get_last_order(v1name).first
diff=100
if last
diff = bid/last[:price]*100
end
mname = "#{symb}(#{sid})".ljust(13,' ')
out<< "[bitfinex] #{mname} ask %0.8f bid %0.8f diff %0.1f" % [ tt[2], tt[0], diff ]
end
p "**********Bitfinex*************"
puts out
end
update_bitfinex_tickers