-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintra.rb
92 lines (68 loc) · 1.37 KB
/
intra.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
load "./bin/repl"
def markets
@markets ||= ["BTC-XVG", "USDT-XVG"]
end
Client.repl self
connect
def ids
@ids||={}
end
def order what, type, r
c.order market: what, type: type, limit: r do |o|
ids[type] = o.uuid
(@orders||={})[o.uuid] = o
end
end
def buy what, r
order what, :buy, r
end
def sell what, r
order what, :sell, r
end
def closed *ids
!ids.map do |id| orders[id].closed end.index(false)
end
def update *ids
ids.each do |id|
c.get_order id do |o|
(@orders||={})[id] = o
end
end
end
def spread
c.trades(["USDT-BTC"].push(*markets)) do |o|
btc,a,b = o
p s = (b=b[0]['Price']) / ((a=a[0]['Price'])*(br=btc[0]['Price']))
if s > 1.0085
@hold = true
buy markets[0], a
sell markets[1], b
until bid=@ids[:sell] and aid=@ids[:buy]
Thread.pass
end
until closed(aid, bid);
sleep 0.5
Thread.pass
update aid,bid
break if closed(aid, bid)
sleep 1
end
@ids[:sell] = nil
@ids[:bid] = nil
buy "USDT-BTC", br
until bid=@ids[:bid];
Thread.pass
end
until closed(bid);
Thread.pass
update bid
sleep 1;
end
@hold = false
end
end
end
loop do
spread if !@hold
sleep 5
end