heisencoin 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/tests/arbitrage.rb +48 -45
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 299b73b5c1ca03c9f2e4a344a07c577518204030
|
|
4
|
+
data.tar.gz: e34f66875a7de255c5c8dcc9eab8fbf12c2dab5e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5c8145003e9d9f53a2ac2cb7cbe026cfd3608b40c8ede2de9bce9f742d12971bfb46f5c890f00484f14edf63c84739ee7d387c880955da975ec2c0c2f46ece3
|
|
7
|
+
data.tar.gz: ec851b165c22da8b0f6fed05d45004bfde9f312b9a0f3b1a71bb58e134e7bdb3fe0236123b62e7e6fec32c0579435a055620bc78264f15f0cef47f35f665125b
|
data/tests/arbitrage.rb
CHANGED
|
@@ -4,13 +4,12 @@ require 'heisencoin'
|
|
|
4
4
|
|
|
5
5
|
class TestMeme < Minitest::Test
|
|
6
6
|
|
|
7
|
+
include Heisencoin
|
|
8
|
+
|
|
7
9
|
describe Heisencoin::Arbitrage do
|
|
8
10
|
before do
|
|
9
11
|
@arby = Heisencoin::Arbitrage.new
|
|
10
|
-
@ex1 = Heisencoin::Exchange.new({'name' =>'btcx'
|
|
11
|
-
'time' => "1970-01-01",
|
|
12
|
-
'depth' => {"asks" => [], "bids" => []}
|
|
13
|
-
})
|
|
12
|
+
@ex1 = Heisencoin::Exchange.new({'name' =>'btcx'})
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
describe "when setting up the list of exchanges" do
|
|
@@ -26,22 +25,24 @@ class TestMeme < Minitest::Test
|
|
|
26
25
|
end
|
|
27
26
|
|
|
28
27
|
describe "when importing offers" do
|
|
28
|
+
before do
|
|
29
|
+
@depth = {"asks" => [ [10,1],
|
|
30
|
+
[11,1,1],
|
|
31
|
+
[9,0.9] ],
|
|
32
|
+
"bids" => [ [20,1],
|
|
33
|
+
[21,1,1],
|
|
34
|
+
[19,0.9] ]}
|
|
35
|
+
@arby.add_depth(@ex1, @depth)
|
|
36
|
+
end
|
|
37
|
+
|
|
29
38
|
it "must keep the asks sorted" do
|
|
30
|
-
@
|
|
31
|
-
|
|
32
|
-
[9,0.9] ]
|
|
33
|
-
@arby.add_exchanges([@ex1])
|
|
34
|
-
@arby.asks.offers.length.must_equal 3
|
|
35
|
-
@arby.asks.offers.first[1].must_equal 9
|
|
39
|
+
@arby.asks.offers.length.must_equal @depth["asks"].size
|
|
40
|
+
@arby.asks.offers.first.price.must_equal 9
|
|
36
41
|
end
|
|
37
42
|
|
|
38
43
|
it "must keep the bids sorted" do
|
|
39
|
-
@
|
|
40
|
-
|
|
41
|
-
[19,0.9] ]
|
|
42
|
-
@arby.add_exchanges([@ex1])
|
|
43
|
-
@arby.bids.offers.length.must_equal 3
|
|
44
|
-
@arby.bids.offers.first[1].must_equal 21
|
|
44
|
+
@arby.bids.offers.length.must_equal @depth["bids"].size
|
|
45
|
+
@arby.bids.offers.first.price.must_equal 21
|
|
45
46
|
end
|
|
46
47
|
end
|
|
47
48
|
|
|
@@ -51,54 +52,56 @@ class TestMeme < Minitest::Test
|
|
|
51
52
|
before do
|
|
52
53
|
# full setup
|
|
53
54
|
@arby = Heisencoin::Arbitrage.new
|
|
54
|
-
@ex1 = Heisencoin::Exchange.new({'name' =>'btcx'
|
|
55
|
-
|
|
56
|
-
'depth' => {"asks" => [], "bids" => []}
|
|
57
|
-
})
|
|
58
|
-
@ex2 = Heisencoin::Exchange.new({'name' =>'crytpsy',
|
|
59
|
-
'time' => "1970-01-01",
|
|
60
|
-
'depth' => {"asks" => [], "bids" => []}
|
|
61
|
-
})
|
|
62
|
-
# ex1 has a 14 bid above ex2
|
|
63
|
-
@ex1.depth["asks"] += [ [16,1],
|
|
64
|
-
[17,1.1],
|
|
65
|
-
[15,0.9] ]
|
|
66
|
-
@ex1.depth["bids"] += [ [13,1],
|
|
67
|
-
[14.1,1.1],[14.2,1.2],
|
|
68
|
-
[12,0.9] ]
|
|
69
|
-
# ex2 has a 13.5 ask below ex2
|
|
70
|
-
@ex2.depth["asks"] += [ [14,1],
|
|
71
|
-
[15,1.1],
|
|
72
|
-
[13.5,0.9],[13.4,0.5] ]
|
|
73
|
-
@ex2.depth["bids"] += [ [11,1],
|
|
74
|
-
[12,1.1],
|
|
75
|
-
[10,0.9] ]
|
|
55
|
+
@ex1 = Heisencoin::Exchange.new({'name' =>'btcx'})
|
|
56
|
+
@ex2 = Heisencoin::Exchange.new({'name' =>'crytpsy'})
|
|
76
57
|
@arby.add_exchanges([@ex1, @ex2])
|
|
58
|
+
# ex1 has a 14.1 and 14.2 bid above ex2's 14 ask
|
|
59
|
+
depth = {"asks" => [ [16,1],
|
|
60
|
+
[17,1.1],
|
|
61
|
+
[15,0.9] ],
|
|
62
|
+
"bids" => [ [13,1],
|
|
63
|
+
[14.1,1.1],[14.2,1.2],
|
|
64
|
+
[12,0.9] ]}
|
|
65
|
+
@arby.add_depth(@ex1, depth)
|
|
66
|
+
# ex2 has a 13.5 ask below ex2
|
|
67
|
+
depth = {"asks" => [ [14,1],
|
|
68
|
+
[15,1.1],
|
|
69
|
+
[13.5,0.9],[13.4,0.5] ],
|
|
70
|
+
"bids" => [ [11,1],
|
|
71
|
+
[12,1.1],
|
|
72
|
+
[10,0.9] ]}
|
|
73
|
+
@arby.add_depth(@ex2, depth)
|
|
77
74
|
end
|
|
78
75
|
|
|
79
|
-
it "should find the
|
|
76
|
+
it "should find the least profitable bid price" do
|
|
80
77
|
limit_bid_price = @arby.best_price(@arby.bids, @arby.asks){|offer, other| offer > other}
|
|
81
|
-
limit_bid_price.must_equal 14.
|
|
78
|
+
limit_bid_price.must_equal 14.2
|
|
82
79
|
end
|
|
83
80
|
|
|
84
|
-
it "should find the
|
|
81
|
+
it "should find the least profitable ask price" do
|
|
85
82
|
limit_ask_price = @arby.best_price(@arby.asks, @arby.bids){|offer, other| offer < other}
|
|
86
|
-
limit_ask_price.must_equal
|
|
83
|
+
limit_ask_price.must_equal 13.4
|
|
87
84
|
end
|
|
88
85
|
|
|
89
86
|
it "should find all profitable asks" do
|
|
90
87
|
winners = @arby.profitable_asks
|
|
91
|
-
winners.must_equal [
|
|
88
|
+
winners.must_equal [ Offer.from_array(@ex2, [13.4, 0.5]),
|
|
89
|
+
Offer.from_array(@ex2, [13.5, 0.9]),
|
|
90
|
+
Offer.from_array(@ex2, [14, 1])]
|
|
92
91
|
end
|
|
93
92
|
|
|
94
93
|
it "should find all profitable bids" do
|
|
95
94
|
winners = @arby.profitable_bids
|
|
96
|
-
winners.must_equal [
|
|
95
|
+
winners.must_equal [ Offer.from_array(@ex1, [14.2, 1.2]),
|
|
96
|
+
Offer.from_array(@ex1, [14.1, 1.1])]
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
it "should make all available trades" do
|
|
100
100
|
trades = @arby.trade_all(@arby.profitable_asks, @arby.profitable_bids)
|
|
101
|
-
trades.must_equal [ [@ex1,
|
|
101
|
+
trades.must_equal [ [@ex1, 14.2, @ex2, 13.4, 0.5],
|
|
102
|
+
[@ex1, 14.2, @ex2, 13.5, 0.7],
|
|
103
|
+
[@ex1, 14.1, @ex2, 13.5, 0.20000000000000007],
|
|
104
|
+
[@ex1, 14.1, @ex2, 14, 0.9]]
|
|
102
105
|
end
|
|
103
106
|
|
|
104
107
|
it "should work" do
|