bitex 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bitex/order.rb CHANGED
@@ -7,6 +7,7 @@ module Bitex
7
7
  attr_accessor :specie
8
8
  attr_accessor :price
9
9
  attr_accessor :status
10
+ attr_accessor :reason
10
11
 
11
12
  # Returns an array with all your active orders
12
13
  # of this type, and any other order of this type that was active in the
@@ -24,7 +25,7 @@ module Bitex
24
25
  # Find an order in your list of active orders.
25
26
  # Uses {Order.active} under the hood.
26
27
  def self.find(id)
27
- active.select{|o| o.id == id}.first
28
+ from_json(Api.private(:get, "/private#{base_path}/#{id}"))
28
29
  end
29
30
 
30
31
  # @visibility private
@@ -37,7 +38,7 @@ module Bitex
37
38
  order = from_json(Api.private(:post, "/private#{base_path}", params))
38
39
  retries = 0
39
40
  while wait && order.status == :received
40
- new_order = all.select{|o| o.id == order.id}.first
41
+ new_order = find(order.id)
41
42
  if new_order.nil?
42
43
  raise StandardError.new(
43
44
  "Order #{base_path} ##{order.id} not found in list")
@@ -67,9 +68,16 @@ module Bitex
67
68
  4 => :cancelled,
68
69
  5 => :completed,
69
70
  }
71
+ reason_lookup = {
72
+ 0 => :not_cancelled,
73
+ 1 => :not_enough_funds,
74
+ 2 => :user_cancelled,
75
+ 3 => :system_cancelled,
76
+ }
70
77
  Api.from_json(order || new, json, true) do |thing|
71
78
  thing.price = BigDecimal.new(json[6].to_s)
72
79
  thing.status = status_lookup[json[7]]
80
+ thing.reason = reason_lookup[json[8]]
73
81
  end
74
82
  end
75
83
  end
@@ -105,6 +113,13 @@ module Bitex
105
113
  # * :cancelled no further executed. May have some Remaining Amount.
106
114
  # * :completed Fully executed, Remaining Amount should be 0.
107
115
 
116
+ # @!attribute reason
117
+ # The cancellation reason for this Bid, if any.
118
+ # * :not_cancelled Has not been cancelled.
119
+ # * :not_enough_funds Not enough funds to place this order.
120
+ # * :user_cancelled Cancelled per user's request
121
+ # * :system_cancelled Bitex cancelled this order, for a good reason.
122
+
108
123
  # @visibility private
109
124
  def self.base_path
110
125
  '/bids'
@@ -162,6 +177,13 @@ module Bitex
162
177
  # * :cancelled no further executed. May have some Remaining Quantity.
163
178
  # * :completed Fully executed, Remaining Quantity should be 0.
164
179
 
180
+ # @!attribute reason
181
+ # The cancellation reason of this Ask.
182
+ # * :not_cancelled Has not been cancelled.
183
+ # * :not_enough_funds Not enough funds to place this order.
184
+ # * :user_cancelled Cancelled per user's request
185
+ # * :system_cancelled Bitex cancelled this order, for a good reason.
186
+
165
187
  # @visibility private
166
188
  def self.base_path
167
189
  '/asks'
data/lib/bitex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bitex
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1 @@
1
+ [1,12345678,946685400,1,100.00000000,100.00000000,1000.00000000,2,0]
@@ -0,0 +1 @@
1
+ [1,12345678,946685400,1,100.00000000,100.00000000,1000.00000000,2,0]
data/spec/order_spec.rb CHANGED
@@ -12,12 +12,4 @@ describe Bitex::Order do
12
12
  ask.should be_a Bitex::Ask
13
13
  empty.should be_nil
14
14
  end
15
-
16
- it 'gets active orders' do
17
- stub_private(:get, "/private/orders/active", 'orders')
18
- bid, ask, empty = Bitex::Order.active
19
- bid.should be_a Bitex::Bid
20
- ask.should be_a Bitex::Ask
21
- empty.should be_nil
22
- end
23
15
  end
@@ -49,4 +49,15 @@ shared_examples_for 'JSON deserializable order' do
49
49
  subject.class.from_json(as_json).status.should == symbol
50
50
  end
51
51
  end
52
+
53
+ { 0 => :not_cancelled,
54
+ 1 => :not_enough_funds,
55
+ 2 => :user_cancelled,
56
+ 3 => :system_cancelled,
57
+ }.each do |code, symbol|
58
+ it "sets reason #{code} to #{symbol}" do
59
+ as_json[8] = code
60
+ subject.class.from_json(as_json).reason.should == symbol
61
+ end
62
+ end
52
63
  end
@@ -6,15 +6,8 @@ shared_examples_for 'Order' do |api_path|
6
6
  empty.should be_nil
7
7
  end
8
8
 
9
- it 'lists all active' do
10
- stub_private(:get, "/private/orders/active", 'orders')
11
- order, empty = subject.class.active
12
- order.should be_a subject.class
13
- empty.should be_nil
14
- end
15
-
16
9
  it 'gets one' do
17
- stub_private(:get, "/private/orders/active", 'orders')
10
+ stub_private(:get, "/private/#{api_path}/12345678", "#{api_path}_show")
18
11
  order = subject.class.find(12345678)
19
12
  order.should be_a subject.class
20
13
  order.id.should == 12345678
@@ -39,7 +32,7 @@ shared_examples_for 'Order' do |api_path|
39
32
  it 'places for btc and waits until processed by our matching engine' do
40
33
  stub_private(:post, "/private/#{api_path}", "#{api_path}_create",
41
34
  {amount: 100.50, price: 1000.00, specie: 1})
42
- stub_private(:get, "/private/orders", 'orders')
35
+ stub_private(:get, "/private/#{api_path}/12345678", "#{api_path}_show")
43
36
  order = subject.class.create!(:btc, 100.50, 1000.00, true)
44
37
  order.should be_a subject.class
45
38
  order.status.should == :executing
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.7
4
+ version: 0.0.8
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-14 00:00:00.000000000 Z
13
+ date: 2014-07-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -192,8 +192,10 @@ files:
192
192
  - spec/fixtures/aggregated_data.json
193
193
  - spec/fixtures/asks_cancel.json
194
194
  - spec/fixtures/asks_create.json
195
+ - spec/fixtures/asks_show.json
195
196
  - spec/fixtures/bids_cancel.json
196
197
  - spec/fixtures/bids_create.json
198
+ - spec/fixtures/bids_show.json
197
199
  - spec/fixtures/market_ticker.json
198
200
  - spec/fixtures/order_book.json
199
201
  - spec/fixtures/orders.json
@@ -245,8 +247,10 @@ test_files:
245
247
  - spec/fixtures/aggregated_data.json
246
248
  - spec/fixtures/asks_cancel.json
247
249
  - spec/fixtures/asks_create.json
250
+ - spec/fixtures/asks_show.json
248
251
  - spec/fixtures/bids_cancel.json
249
252
  - spec/fixtures/bids_create.json
253
+ - spec/fixtures/bids_show.json
250
254
  - spec/fixtures/market_ticker.json
251
255
  - spec/fixtures/order_book.json
252
256
  - spec/fixtures/orders.json