bitx 0.0.1 → 0.2.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/README.md +92 -5
- data/Rakefile +7 -0
- data/bitx.gemspec +7 -4
- data/lib/bitx.rb +42 -54
- data/lib/bitx_connection.rb +0 -0
- data/lib/private_api.rb +289 -0
- data/lib/public_api.rb +77 -0
- data/lib/version.rb +9 -0
- data/test/balance_test.rb +58 -0
- data/test/order_test.rb +116 -0
- data/test/public_test.rb +224 -0
- data/test/quotes_test.rb +163 -0
- data/test/receive_address_test.rb +101 -0
- data/test/send_test.rb +40 -0
- data/test/withdrawal_test.rb +108 -0
- metadata +39 -5
data/test/quotes_test.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
require "minitest/pride"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require_relative "../lib/bitx.rb"
|
4
|
+
|
5
|
+
module QuoteStubs
|
6
|
+
def self.conn
|
7
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
8
|
+
|
9
|
+
stub.post('/api/1/quotes', {type:"BUY", pair:"XBTZAR", base_amount:0.1}) {[ 200, {},
|
10
|
+
'{
|
11
|
+
"id": "1324",
|
12
|
+
"type": "BUY",
|
13
|
+
"pair": "XBTZAR",
|
14
|
+
"base_amount": "0.1",
|
15
|
+
"counter_amount": "1234.24",
|
16
|
+
"created_at": 1418377612342,
|
17
|
+
"expires_at": 1418377912342,
|
18
|
+
"discarded": false,
|
19
|
+
"exercised": false
|
20
|
+
}']}
|
21
|
+
|
22
|
+
|
23
|
+
stub.post('/api/1/quotes', {type:"SELL", pair:"XBTZAR", base_amount:0.1}) {[ 200, {},
|
24
|
+
'{
|
25
|
+
"id": "1325",
|
26
|
+
"type": "SELL",
|
27
|
+
"pair": "XBTZAR",
|
28
|
+
"base_amount": "0.1",
|
29
|
+
"counter_amount": "1200.00",
|
30
|
+
"created_at": 1418377612342,
|
31
|
+
"expires_at": 1418377912342,
|
32
|
+
"discarded": false,
|
33
|
+
"exercised": false
|
34
|
+
}']}
|
35
|
+
|
36
|
+
stub.put('/api/1/quotes/1324') {[ 200, {},
|
37
|
+
'{
|
38
|
+
"id": "1324",
|
39
|
+
"type": "BUY",
|
40
|
+
"pair": "XBTZAR",
|
41
|
+
"base_amount": "0.1",
|
42
|
+
"counter_amount": "1234.24",
|
43
|
+
"created_at": 1418377612342,
|
44
|
+
"expires_at": 1418377912342,
|
45
|
+
"discarded": false,
|
46
|
+
"exercised": true
|
47
|
+
}']}
|
48
|
+
|
49
|
+
stub.get('/api/1/quotes/1325') {[ 200, {},
|
50
|
+
'{
|
51
|
+
"id": "1325",
|
52
|
+
"type": "SELL",
|
53
|
+
"pair": "XBTZAR",
|
54
|
+
"base_amount": "0.1",
|
55
|
+
"counter_amount": "1200.00",
|
56
|
+
"created_at": 1418377612342,
|
57
|
+
"expires_at": 1418377912342,
|
58
|
+
"discarded": false,
|
59
|
+
"exercised": false
|
60
|
+
}']}
|
61
|
+
|
62
|
+
stub.delete('/api/1/quotes/1325') {[ 200, {},
|
63
|
+
'{
|
64
|
+
"id": "1325",
|
65
|
+
"type": "SELL",
|
66
|
+
"pair": "XBTZAR",
|
67
|
+
"base_amount": "0.1",
|
68
|
+
"counter_amount": "1200.00",
|
69
|
+
"created_at": 1418377612342,
|
70
|
+
"expires_at": 1418377912342,
|
71
|
+
"discarded": true,
|
72
|
+
"exercised": false
|
73
|
+
}']}
|
74
|
+
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
Faraday.new do |faraday|
|
79
|
+
faraday.adapter :test, stubs
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class TestQuotes < Minitest::Test
|
85
|
+
|
86
|
+
def setup_module
|
87
|
+
BitX.set_conn(QuoteStubs.conn)
|
88
|
+
end
|
89
|
+
def setup_connection
|
90
|
+
BitX::Connection.new(QuoteStubs.conn)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_post_buy
|
94
|
+
setup_module
|
95
|
+
r = BitX.create_quote('XBTZAR', 0.1, 'BUY')
|
96
|
+
assert_equal '1324', r[:id]
|
97
|
+
assert_equal false, r[:exercised]
|
98
|
+
assert_equal false, r[:discarded]
|
99
|
+
end
|
100
|
+
def test_connection_post_buy
|
101
|
+
r = setup_connection.create_quote('XBTZAR', 0.1, 'BUY')
|
102
|
+
assert_equal '1324', r[:id]
|
103
|
+
assert_equal false, r[:exercised]
|
104
|
+
assert_equal false, r[:discarded]
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_post_sell
|
108
|
+
setup_module
|
109
|
+
r = BitX.create_quote('XBTZAR', 0.1, 'SELL')
|
110
|
+
assert_equal '1325', r[:id]
|
111
|
+
assert_equal false, r[:exercised]
|
112
|
+
assert_equal false, r[:discarded]
|
113
|
+
end
|
114
|
+
def test_connection_post_sell
|
115
|
+
r = setup_connection.create_quote('XBTZAR', 0.1, 'SELL')
|
116
|
+
assert_equal '1325', r[:id]
|
117
|
+
assert_equal false, r[:exercised]
|
118
|
+
assert_equal false, r[:discarded]
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_put_exercise
|
122
|
+
setup_module
|
123
|
+
r = BitX.exercise_quote('1324')
|
124
|
+
assert_equal '1324', r[:id]
|
125
|
+
assert_equal true, r[:exercised]
|
126
|
+
assert_equal false, r[:discarded]
|
127
|
+
end
|
128
|
+
def test_connection_put_exercise
|
129
|
+
r = setup_connection.exercise_quote('1324')
|
130
|
+
assert_equal '1324', r[:id]
|
131
|
+
assert_equal true, r[:exercised]
|
132
|
+
assert_equal false, r[:discarded]
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_get_view
|
136
|
+
setup_module
|
137
|
+
r = BitX.view_quote('1325')
|
138
|
+
assert_equal '1325', r[:id]
|
139
|
+
assert_equal false, r[:exercised]
|
140
|
+
assert_equal false, r[:discarded]
|
141
|
+
end
|
142
|
+
def test_connection_get_view
|
143
|
+
r = setup_connection.view_quote('1325')
|
144
|
+
assert_equal '1325', r[:id]
|
145
|
+
assert_equal false, r[:exercised]
|
146
|
+
assert_equal false, r[:discarded]
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def test_delete_discard
|
151
|
+
setup_module
|
152
|
+
r = BitX.discard_quote('1325')
|
153
|
+
assert_equal '1325', r[:id]
|
154
|
+
assert_equal false, r[:exercised]
|
155
|
+
assert_equal true, r[:discarded]
|
156
|
+
end
|
157
|
+
def test_connection_delete_discard
|
158
|
+
r = setup_connection.discard_quote('1325')
|
159
|
+
assert_equal '1325', r[:id]
|
160
|
+
assert_equal false, r[:exercised]
|
161
|
+
assert_equal true, r[:discarded]
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require "minitest/pride"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require_relative "../lib/bitx.rb"
|
4
|
+
|
5
|
+
module ReceiveAddressStubs
|
6
|
+
def self.conn
|
7
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
stub.get('/api/1/funding_address?address=supersecretotherbicoinwallet&asset=XBT') {[ 200, {},
|
12
|
+
'{
|
13
|
+
"asset": "XBT",
|
14
|
+
"address": "supersecretotherbicoinwallet",
|
15
|
+
"total_received": "929.23001",
|
16
|
+
"total_unconfirmed": "0.30"
|
17
|
+
}']}
|
18
|
+
|
19
|
+
|
20
|
+
stub.get('/api/1/funding_address?asset=XBT') {[ 200, {},
|
21
|
+
'{
|
22
|
+
"asset": "XBT",
|
23
|
+
"address": "B1tC0InExAMPL3fundIN6AdDreS5t0Use1",
|
24
|
+
"total_received": "1.234567",
|
25
|
+
"total_unconfirmed": "0.00"
|
26
|
+
}']}
|
27
|
+
|
28
|
+
stub.post('/api/1/funding_address') {[ 200, {},
|
29
|
+
'{
|
30
|
+
"asset": "XBT",
|
31
|
+
"address": "B1tC0InExAMPL3fundIN6AdDreS5t0Use2",
|
32
|
+
"total_received": "0.00",
|
33
|
+
"total_unconfirmed": "0.00"
|
34
|
+
}']}
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
Faraday.new do |faraday|
|
39
|
+
faraday.adapter :test, stubs
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class TestReceiveAddress < Minitest::Test
|
45
|
+
|
46
|
+
def setup_module
|
47
|
+
BitX.set_conn(ReceiveAddressStubs.conn)
|
48
|
+
end
|
49
|
+
def setup_connection
|
50
|
+
BitX::Connection.new(ReceiveAddressStubs.conn)
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def test_get_receive_address
|
55
|
+
setup_module
|
56
|
+
r = BitX.received_by_address
|
57
|
+
assert_equal r[:total_received], "1.234567"
|
58
|
+
assert_equal r[:total_unconfirmed], "0.00"
|
59
|
+
assert_equal r[:address], 'B1tC0InExAMPL3fundIN6AdDreS5t0Use1'
|
60
|
+
assert_equal r[:asset], 'XBT'
|
61
|
+
end
|
62
|
+
def test_connection_get_receive_address
|
63
|
+
r = setup_connection.received_by_address
|
64
|
+
assert_equal r[:total_received], "1.234567"
|
65
|
+
assert_equal r[:total_unconfirmed], "0.00"
|
66
|
+
assert_equal r[:address], 'B1tC0InExAMPL3fundIN6AdDreS5t0Use1'
|
67
|
+
assert_equal r[:asset], 'XBT'
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_new_receive_address
|
71
|
+
setup_module
|
72
|
+
r = BitX.new_receive_address
|
73
|
+
assert_equal r[:total_received], "0.00"
|
74
|
+
assert_equal r[:total_unconfirmed], "0.00"
|
75
|
+
assert_equal r[:address], 'B1tC0InExAMPL3fundIN6AdDreS5t0Use2'
|
76
|
+
assert_equal r[:asset], 'XBT'
|
77
|
+
end
|
78
|
+
def test_connection_new_receive_address
|
79
|
+
r = setup_connection.new_receive_address
|
80
|
+
assert_equal r[:total_received], "0.00"
|
81
|
+
assert_equal r[:total_unconfirmed], "0.00"
|
82
|
+
assert_equal r[:address], 'B1tC0InExAMPL3fundIN6AdDreS5t0Use2'
|
83
|
+
assert_equal r[:asset], 'XBT'
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_specify_address
|
87
|
+
setup_module
|
88
|
+
r = BitX.received_by_address({address: 'supersecretotherbicoinwallet'})
|
89
|
+
assert_equal r[:total_received], "929.23001"
|
90
|
+
assert_equal r[:total_unconfirmed], "0.30"
|
91
|
+
assert_equal r[:address], 'supersecretotherbicoinwallet'
|
92
|
+
assert_equal r[:asset], 'XBT'
|
93
|
+
end
|
94
|
+
def test_connection_specify_address
|
95
|
+
r = setup_connection.received_by_address({address: 'supersecretotherbicoinwallet'})
|
96
|
+
assert_equal r[:total_received], "929.23001"
|
97
|
+
assert_equal r[:total_unconfirmed], "0.30"
|
98
|
+
assert_equal r[:address], 'supersecretotherbicoinwallet'
|
99
|
+
assert_equal r[:asset], 'XBT'
|
100
|
+
end
|
101
|
+
end
|
data/test/send_test.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "minitest/pride"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require_relative "../lib/bitx.rb"
|
4
|
+
|
5
|
+
module SendStubs
|
6
|
+
def self.conn
|
7
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
8
|
+
# send
|
9
|
+
|
10
|
+
stub.post('/api/1/send') {[ 200, {},
|
11
|
+
'{"success":true}']}
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
Faraday.new do |faraday|
|
16
|
+
faraday.adapter :test, stubs
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class TestSend < Minitest::Test
|
22
|
+
|
23
|
+
def setup_module
|
24
|
+
BitX.set_conn(SendStubs.conn)
|
25
|
+
end
|
26
|
+
def setup_connection
|
27
|
+
BitX::Connection.new(SendStubs.conn)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_send
|
31
|
+
#BitX.send(amount, address, currency='XBT', description='', message='', pin=nil)
|
32
|
+
setup_module
|
33
|
+
r = BitX.send(1, 'mockaddress')
|
34
|
+
assert_equal r[:success], true
|
35
|
+
end
|
36
|
+
def test_connection_send
|
37
|
+
r = setup_connection.send(1, 'mockaddress')
|
38
|
+
assert_equal r[:success], true
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "minitest/pride"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require_relative "../lib/bitx.rb"
|
4
|
+
|
5
|
+
module WithdrawalStubs
|
6
|
+
def self.conn
|
7
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
8
|
+
|
9
|
+
stub.get('/api/1/withdrawals') {[ 200, {},
|
10
|
+
'{
|
11
|
+
"withdrawals": [
|
12
|
+
{
|
13
|
+
"status": "PENDING",
|
14
|
+
"id": "2221"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"status": "COMPLETED",
|
18
|
+
"id": "1121"
|
19
|
+
}
|
20
|
+
]
|
21
|
+
}']}
|
22
|
+
|
23
|
+
|
24
|
+
stub.post('/api/1/withdrawals', {type:"ZAR_EFT", amount:1000}) {[ 200, {},
|
25
|
+
'{
|
26
|
+
"status": "PENDING",
|
27
|
+
"id": "1212"
|
28
|
+
}']}
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
stub.get('/api/1/withdrawals/1212') {[ 200, {},
|
33
|
+
'{
|
34
|
+
"status": "COMPLETED",
|
35
|
+
"id": "1212"
|
36
|
+
}']}
|
37
|
+
|
38
|
+
stub.delete('/api/1/withdrawals/1215') {[ 200, {},
|
39
|
+
'{
|
40
|
+
"status": "CANCELLED",
|
41
|
+
"id": "1215"
|
42
|
+
}']}
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
Faraday.new do |faraday|
|
48
|
+
faraday.adapter :test, stubs
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class TestWithdrawals < Minitest::Test
|
54
|
+
|
55
|
+
def setup_module
|
56
|
+
BitX.set_conn(WithdrawalStubs.conn)
|
57
|
+
end
|
58
|
+
def setup_connection
|
59
|
+
BitX::Connection.new(WithdrawalStubs.conn)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_list
|
63
|
+
setup_module
|
64
|
+
r = BitX.withdrawals
|
65
|
+
assert_equal r.size, 2
|
66
|
+
end
|
67
|
+
def test_connection_list
|
68
|
+
r = setup_connection.withdrawals
|
69
|
+
assert_equal r.size, 2
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_withdraw
|
73
|
+
setup_module
|
74
|
+
r = BitX.withdraw('ZAR_EFT', 1000)
|
75
|
+
assert_equal r[:status], 'PENDING'
|
76
|
+
assert_equal r[:id], '1212'
|
77
|
+
end
|
78
|
+
def test_connection_withdraw
|
79
|
+
r = setup_connection.withdraw('ZAR_EFT', 1000)
|
80
|
+
assert_equal r[:status], 'PENDING'
|
81
|
+
assert_equal r[:id], '1212'
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_view_withdrawal
|
85
|
+
setup_module
|
86
|
+
r = BitX.withdrawal('1212')
|
87
|
+
assert_equal r[:status], 'COMPLETED'
|
88
|
+
assert_equal r[:id], '1212'
|
89
|
+
end
|
90
|
+
def test_connection_view_withdrawal
|
91
|
+
r = setup_connection.withdrawal('1212')
|
92
|
+
assert_equal r[:status], 'COMPLETED'
|
93
|
+
assert_equal r[:id], '1212'
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_cancel_withdrawal
|
97
|
+
setup_module
|
98
|
+
r = BitX.cancel_withdrawal('1215')
|
99
|
+
assert_equal r[:status], 'CANCELLED'
|
100
|
+
assert_equal r[:id], '1215'
|
101
|
+
end
|
102
|
+
def test_connection_cancel_withdrawal
|
103
|
+
r = setup_connection.cancel_withdrawal('1215')
|
104
|
+
assert_equal r[:status], 'CANCELLED'
|
105
|
+
assert_equal r[:id], '1215'
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothy Stranex
|
8
|
+
- Francois Paul
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -38,6 +39,20 @@ dependencies:
|
|
38
39
|
- - '>='
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
41
56
|
- !ruby/object:Gem::Dependency
|
42
57
|
name: faraday
|
43
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,7 +69,8 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
description: BitX API wrapper
|
56
71
|
email:
|
57
|
-
- timothy@
|
72
|
+
- timothy@bitx.co
|
73
|
+
- franc@bitx.co
|
58
74
|
executables: []
|
59
75
|
extensions: []
|
60
76
|
extra_rdoc_files: []
|
@@ -66,7 +82,18 @@ files:
|
|
66
82
|
- Rakefile
|
67
83
|
- bitx.gemspec
|
68
84
|
- lib/bitx.rb
|
69
|
-
|
85
|
+
- lib/bitx_connection.rb
|
86
|
+
- lib/private_api.rb
|
87
|
+
- lib/public_api.rb
|
88
|
+
- lib/version.rb
|
89
|
+
- test/balance_test.rb
|
90
|
+
- test/order_test.rb
|
91
|
+
- test/public_test.rb
|
92
|
+
- test/quotes_test.rb
|
93
|
+
- test/receive_address_test.rb
|
94
|
+
- test/send_test.rb
|
95
|
+
- test/withdrawal_test.rb
|
96
|
+
homepage: https://bitx.co/api
|
70
97
|
licenses:
|
71
98
|
- MIT
|
72
99
|
metadata: {}
|
@@ -90,4 +117,11 @@ rubygems_version: 2.0.14
|
|
90
117
|
signing_key:
|
91
118
|
specification_version: 4
|
92
119
|
summary: Ruby wrapper for the BitX API
|
93
|
-
test_files:
|
120
|
+
test_files:
|
121
|
+
- test/balance_test.rb
|
122
|
+
- test/order_test.rb
|
123
|
+
- test/public_test.rb
|
124
|
+
- test/quotes_test.rb
|
125
|
+
- test/receive_address_test.rb
|
126
|
+
- test/send_test.rb
|
127
|
+
- test/withdrawal_test.rb
|