heisencoin 0.0.1
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 +7 -0
- data/lib/heisencoin.rb +7 -0
- data/tests/arbitrage.rb +115 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 223ad3bb10435bdc4ea7daac565e2d04f36aee90
|
|
4
|
+
data.tar.gz: 5da6f811b51bcc77edcb9492f22292ddff1ca691
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0bb932f9e1c56d2f1bbbab147695624e73c17484230901a5dc8479de3884b019e7539db7f0c70cbda6b49a939477958a9382a405e989f81202d41babeb0d26d3
|
|
7
|
+
data.tar.gz: 0d45944fcf6b95283749f93ffc5a6c6d0aa7a915850730c5309acaaca184d7a197dba789caefd6d0394825a4f504c4fbf2fe4790f01d5b8b6c08aae9604a2504
|
data/lib/heisencoin.rb
ADDED
data/tests/arbitrage.rb
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require "minitest/autorun"
|
|
2
|
+
require "time"
|
|
3
|
+
require 'heisencoin'
|
|
4
|
+
|
|
5
|
+
class TestMeme < Minitest::Test
|
|
6
|
+
|
|
7
|
+
describe Heisencoin::Arbitrage do
|
|
8
|
+
before do
|
|
9
|
+
@arby = Heisencoin::Arbitrage.new
|
|
10
|
+
@ex1 = Heisencoin::Exchange.new({'name' =>'btcx',
|
|
11
|
+
'time' => "1970-01-01",
|
|
12
|
+
'depth' => {"asks" => [], "bids" => []}
|
|
13
|
+
})
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "when setting up the list of exchanges" do
|
|
17
|
+
it "must start empty" do
|
|
18
|
+
@arby.exchanges.size.must_equal 0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "must accept new exchanges" do
|
|
22
|
+
exchanges = [@ex1]
|
|
23
|
+
@arby.add_exchanges(exchanges)
|
|
24
|
+
@arby.exchanges.size.must_equal 1
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "when importing offers" do
|
|
29
|
+
it "must keep the asks sorted" do
|
|
30
|
+
@ex1.depth["asks"] += [ [10,1],
|
|
31
|
+
[11,1,1],
|
|
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
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "must keep the bids sorted" do
|
|
39
|
+
@ex1.depth["bids"] += [ [20,1],
|
|
40
|
+
[21,1,1],
|
|
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
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "when optimizing for arbitrage" do
|
|
51
|
+
before do
|
|
52
|
+
# full setup
|
|
53
|
+
@arby = Heisencoin::Arbitrage.new
|
|
54
|
+
@ex1 = Heisencoin::Exchange.new({'name' =>'btcx',
|
|
55
|
+
'time' => "1970-01-01",
|
|
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] ]
|
|
76
|
+
@arby.add_exchanges([@ex1, @ex2])
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should find the lowest profitable bid price" do
|
|
80
|
+
limit_bid_price = @arby.best_price(@arby.bids, @arby.asks){|offer, other| offer > other}
|
|
81
|
+
limit_bid_price.must_equal 14.1
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should find the highest profitable ask price" do
|
|
85
|
+
limit_ask_price = @arby.best_price(@arby.asks, @arby.bids){|offer, other| offer < other}
|
|
86
|
+
limit_ask_price.must_equal 14
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "should find all profitable asks" do
|
|
90
|
+
winners = @arby.profitable_asks
|
|
91
|
+
winners.must_equal [ [@ex2, 13.4, 0.5], [@ex2, 13.5, 0.9], [@ex2, 14, 1]]
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should find all profitable bids" do
|
|
95
|
+
winners = @arby.profitable_bids
|
|
96
|
+
winners.must_equal [ [@ex1, 14.2, 1.2], [@ex1, 14.1, 1.1]]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should make all available trades" do
|
|
100
|
+
trades = @arby.trade_all(@arby.profitable_asks, @arby.profitable_bids)
|
|
101
|
+
trades.must_equal [ [@ex1, @ex2, 13.4, 0.5], [@ex1, @ex2, 13.4, 0.5]]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should work" do
|
|
105
|
+
# buy 13.5 x0.9 from ex2, sell to ex1 (up to x1.1)
|
|
106
|
+
#plan = @arby.plan
|
|
107
|
+
#plan.steps.size.must_equal 1
|
|
108
|
+
#step1 = plan.steps.first
|
|
109
|
+
#step1.from.must_equal @ex2
|
|
110
|
+
#step1.to.must_equal @ex1
|
|
111
|
+
#step1.amount.must_equal 0.9
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: heisencoin
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Don Park
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-08-31 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: finance methods targeted for cryptocoin markets
|
|
14
|
+
email: donp@donp.org
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/heisencoin.rb
|
|
20
|
+
- tests/arbitrage.rb
|
|
21
|
+
homepage: https://github.com/cointhink/heisencoin
|
|
22
|
+
licenses:
|
|
23
|
+
- Apache 2.0
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - '>='
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.0.3
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: cryptocoin finance methods
|
|
45
|
+
test_files:
|
|
46
|
+
- tests/arbitrage.rb
|