bitex 0.0.4 → 0.0.5
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.
- data/lib/bitex/order.rb +32 -14
- data/lib/bitex/version.rb +1 -1
- data/spec/fixtures/orders.json +1 -1
- data/spec/support/order_shared_examples.rb +11 -0
- metadata +2 -2
data/lib/bitex/order.rb
CHANGED
@@ -26,6 +26,26 @@ module Bitex
|
|
26
26
|
def self.find(id)
|
27
27
|
active.select{|o| o.id == id}.first
|
28
28
|
end
|
29
|
+
|
30
|
+
# @visibility private
|
31
|
+
def self.create!(specie, amount, price, wait=false)
|
32
|
+
params = {
|
33
|
+
amount: amount,
|
34
|
+
price: price,
|
35
|
+
specie: {btc: 1, ltc: 2}[specie]
|
36
|
+
}
|
37
|
+
order = from_json(Api.private(:post, "/private#{base_path}", params))
|
38
|
+
retries = 0
|
39
|
+
while wait && order.status == :received
|
40
|
+
order = find(order.id)
|
41
|
+
sleep 0.2
|
42
|
+
retries += 1
|
43
|
+
if retries > 100
|
44
|
+
raise StandardError.new("Timed out waiting for #{base_path} ##{order.id}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
return order
|
48
|
+
end
|
29
49
|
|
30
50
|
def cancel!
|
31
51
|
path = "/private#{self.class.base_path}/cancel"
|
@@ -87,14 +107,13 @@ module Bitex
|
|
87
107
|
# Create a new Bid for spending Amount USD paying no more than
|
88
108
|
# price per unit.
|
89
109
|
# @param specie [Symbol] :btc or :ltc, whatever you're buying.
|
110
|
+
# @param amount [BigDecimal] Amount to spend buying.
|
111
|
+
# @param price [BigDecimal] Maximum price to pay per unit.
|
112
|
+
# @param wait [Boolean] Block the process and wait until this
|
113
|
+
# bid moves out of the :received state, defaults to false.
|
90
114
|
# @see https://bitex.la/developers#create-bid
|
91
|
-
def self.create!(specie, amount, price)
|
92
|
-
|
93
|
-
amount: amount,
|
94
|
-
price: price,
|
95
|
-
specie: {btc: 1, ltc: 2}[specie]
|
96
|
-
}
|
97
|
-
from_json(Api.private(:post, "/private#{base_path}", params))
|
115
|
+
def self.create!(specie, amount, price, wait=false)
|
116
|
+
super
|
98
117
|
end
|
99
118
|
|
100
119
|
# @visibility private
|
@@ -145,14 +164,13 @@ module Bitex
|
|
145
164
|
# Create a new Ask for selling a Quantity of specie charging no less than
|
146
165
|
# Price per each.
|
147
166
|
# @param specie [Symbol] :btc or :ltc, whatever you're selling.
|
167
|
+
# @param quantity [BigDecimal] Quantity to sell.
|
168
|
+
# @param price [BigDecimal] Minimum price to charge when selling.
|
169
|
+
# @param wait [Boolean] Block the process and wait until this
|
170
|
+
# ask moves out of the :received state, defaults to false.
|
148
171
|
# @see https://bitex.la/developers#create-ask
|
149
|
-
def self.create!(specie, quantity, price)
|
150
|
-
|
151
|
-
amount: quantity,
|
152
|
-
price: price,
|
153
|
-
specie: {btc: 1, ltc: 2}[specie]
|
154
|
-
}
|
155
|
-
from_json(Api.private(:post, "/private#{base_path}", params))
|
172
|
+
def self.create!(specie, quantity, price, wait=false)
|
173
|
+
super
|
156
174
|
end
|
157
175
|
|
158
176
|
# @visibility private
|
data/lib/bitex/version.rb
CHANGED
data/spec/fixtures/orders.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[[1,12345678,946685400,1,100.00000000,10.00000000,1000.00000000,
|
1
|
+
[[1,12345678,946685400,1,100.00000000,10.00000000,1000.00000000,2],[2,12345678,946685400,1,10.00000000,1.00000000,1100.00000000,2]]
|
@@ -25,6 +25,7 @@ shared_examples_for 'Order' do |api_path|
|
|
25
25
|
{amount: 100.50, price: 1000.00, specie: 1})
|
26
26
|
order = subject.class.create!(:btc, 100.50, 1000.00)
|
27
27
|
order.should be_a subject.class
|
28
|
+
order.status.should == :received
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'places for ltc' do
|
@@ -32,6 +33,16 @@ shared_examples_for 'Order' do |api_path|
|
|
32
33
|
{amount: 100.50, price: 1000.00, specie: 2})
|
33
34
|
order = subject.class.create!(:ltc, 100.50, 1000.00)
|
34
35
|
order.should be_a subject.class
|
36
|
+
order.status.should == :received
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'places for btc and waits until processed by our matching engine' do
|
40
|
+
stub_private(:post, "/private/#{api_path}", "#{api_path}_create",
|
41
|
+
{amount: 100.50, price: 1000.00, specie: 1})
|
42
|
+
stub_private(:get, "/private/orders/active", 'orders')
|
43
|
+
order = subject.class.create!(:btc, 100.50, 1000.00, true)
|
44
|
+
order.should be_a subject.class
|
45
|
+
order.status.should == :executing
|
35
46
|
end
|
36
47
|
|
37
48
|
it 'cancels one' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-07-
|
13
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|