bitex 0.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +63 -0
  3. data/.rubocop.yml +32 -0
  4. data/.ruby-version +1 -0
  5. data/bitex.gemspec +21 -18
  6. data/lib/bitex.rb +7 -1
  7. data/lib/bitex/api.rb +34 -41
  8. data/lib/bitex/ask.rb +74 -0
  9. data/lib/bitex/base_order.rb +106 -0
  10. data/lib/bitex/bid.rb +72 -0
  11. data/lib/bitex/buy.rb +8 -5
  12. data/lib/bitex/kyc_file.rb +31 -9
  13. data/lib/bitex/kyc_profile.rb +113 -38
  14. data/lib/bitex/{market.rb → market_data.rb} +3 -3
  15. data/lib/bitex/match.rb +30 -15
  16. data/lib/bitex/order.rb +6 -238
  17. data/lib/bitex/payment.rb +30 -18
  18. data/lib/bitex/rates.rb +6 -8
  19. data/lib/bitex/sell.rb +5 -5
  20. data/lib/bitex/specie_deposit.rb +9 -4
  21. data/lib/bitex/specie_withdrawal.rb +29 -28
  22. data/lib/bitex/trade.rb +4 -5
  23. data/lib/bitex/transaction.rb +7 -8
  24. data/lib/bitex/usd_deposit.rb +46 -47
  25. data/lib/bitex/usd_withdrawal.rb +33 -34
  26. data/lib/bitex/version.rb +1 -1
  27. data/spec/ask_spec.rb +17 -5
  28. data/spec/bid_spec.rb +17 -5
  29. data/spec/buy_spec.rb +14 -4
  30. data/spec/kyc_file_spec.rb +34 -18
  31. data/spec/kyc_profile_spec.rb +158 -122
  32. data/spec/order_spec.rb +1 -1
  33. data/spec/payment_spec.rb +51 -45
  34. data/spec/sell_spec.rb +14 -4
  35. data/spec/spec_helper.rb +7 -6
  36. data/spec/specie_deposit_spec.rb +10 -4
  37. data/spec/specie_withdrawal_spec.rb +26 -25
  38. data/spec/support/from_json_shared_examples.rb +20 -22
  39. data/spec/support/order_shared_examples.rb +14 -17
  40. data/spec/support/request_stubs.rb +18 -12
  41. data/spec/trade_spec.rb +5 -5
  42. data/spec/transaction_spec.rb +12 -13
  43. data/spec/usd_deposit_spec.rb +120 -105
  44. data/spec/usd_withdrawal_spec.rb +89 -79
  45. metadata +57 -10
@@ -0,0 +1,72 @@
1
+ module Bitex
2
+ # A Bid is an order to buy a given orderbook.
3
+ # @see BaseOrder
4
+ class Bid < BaseOrder
5
+ # @!attribute id
6
+ # @return [Integer] This Bid's unique ID.
7
+
8
+ # @!attribute created_at
9
+ # @return [Time] Time when this Bid was created.
10
+
11
+ # @!attribute orderbook
12
+ # @return [Symbol] :btc_usd or :btc_ars
13
+
14
+ # @!attribute amount
15
+ # @return [BigDecimal] Amount of USD to spend in this Bid.
16
+ attr_accessor :amount
17
+
18
+ # @!attribute remaining_amount
19
+ # @return [BigDecimal] Amount of USD left to be spent in this Bid.
20
+ attr_accessor :remaining_amount
21
+
22
+ # @!attribute price
23
+ # @return [BigDecimal] Maximum price to pay per unit.
24
+
25
+ # @!attribute status
26
+ # The status of this Bid in its lifecycle.
27
+ # * :received queued to check if you have enough funds.
28
+ # * :executing available in our ourderbook waiting to be matched.
29
+ # * :cancelling To be cancelled as soon as our trading engine unlocks it.
30
+ # * :cancelled no further executed. May have some Remaining Amount.
31
+ # * :completed Fully executed, Remaining Amount should be 0.
32
+
33
+ # @!attribute reason
34
+ # The cancellation reason for this Bid, if any.
35
+ # * :not_cancelled Has not been cancelled.
36
+ # * :not_enough_funds Not enough funds to place this order.
37
+ # * :user_cancelled Cancelled per user's request
38
+ # * :system_cancelled Bitex cancelled this order, for a good reason.
39
+
40
+ # @!attribute produced_quantity
41
+ # TODO: rever esta documentacion
42
+ # @return [BigDecimal] Quantity of specie produced by this bid so far.
43
+ attr_accessor :produced_quantity
44
+
45
+ # @!attribute issuer
46
+ # @return [String] The issuer of this order, helps you tell apart orders created from the web UI and the API.
47
+
48
+ # @visibility private
49
+ def self.base_path
50
+ '/bids'
51
+ end
52
+
53
+ # Create a new Bid for spending Amount USD paying no more than price per unit.
54
+ # @param orderbook [Symbol] :btc_usd or :btc_ars, whatever you're buying.
55
+ # @param amount [BigDecimal] Amount to spend buying.
56
+ # @param price [BigDecimal] Maximum price to pay per unit.
57
+ # @param wait [Boolean] Block the process and wait until this bid moves out of the :received state, defaults to false.
58
+ # @see https://bitex.la/developers#create-bid
59
+ def self.create!(orderbook, amount, price, wait = false)
60
+ super
61
+ end
62
+
63
+ # @visibility private
64
+ def self.from_json(json, order = nil)
65
+ super(json, order).tap do |thing|
66
+ thing.amount = (json[4].presence || 0).to_d
67
+ thing.remaining_amount = (json[5].presence || 0).to_d
68
+ thing.produced_quantity = (json[9].presence || 0).to_d
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,4 +1,5 @@
1
1
  module Bitex
2
+ # TODO: rever esta docu
2
3
  # A transaction in which you bought some quantity of specie.
3
4
  class Buy < Match
4
5
  # @!attribute id
@@ -7,18 +8,20 @@ module Bitex
7
8
  # @!attribute created_at
8
9
  # @return [Time] Time when this Buy happened.
9
10
 
10
- # @!attribute specie
11
- # @return [Symbol] :btc or :ltc
12
-
11
+ # @!attribute orderbook
12
+ # @return [Symbol] :btc_usd or :btc_ars
13
+
13
14
  # @!attribute quantity
15
+ # TODO: rever esta docu
14
16
  # @return [BigDecimal] Quantity of specie bought
15
-
17
+
16
18
  # @!attribute amount
17
19
  # @return [BigDecimal] Amount of USD spent
18
20
 
19
21
  # @!attribute fee
22
+ # TODO: rever esta docu
20
23
  # @return [BigDecimal] Quantity of specie paid as transaction fee.
21
-
24
+
22
25
  # @!attribute price
23
26
  # @return [BigDecimal] Price paid per unit
24
27
 
@@ -1,18 +1,40 @@
1
1
  module Bitex
2
+ ##
3
+ # Documentation here!
4
+ #
2
5
  class KycFile
3
- attr_accessor :id, :kyc_profile_id, :url, :file_name,
4
- :content_type, :file_size
6
+ # @!attribute id
7
+ # @return [Integer] This KycFile's unique ID.
8
+ attr_accessor :id
9
+
10
+ # @!attribute id
11
+ # @return [Integer] This KycProfile's unique ID.
12
+ attr_accessor :kyc_profile_id
13
+
14
+ # @!attribute url
15
+ # @return [String] url to photo file.
16
+ attr_accessor :url
17
+
18
+ # @!attribute file_name
19
+ # @return [String] file name.
20
+ attr_accessor :file_name
21
+
22
+ # @!attribute file_size
23
+ # @return [Integer] file size.
24
+ attr_accessor :file_size
25
+
26
+ # @!attribute content_type
27
+ # @return [String] Content type.
28
+ attr_accessor :content_type
5
29
 
6
30
  def self.from_json(json)
7
- t = new
8
- t.id, t.kyc_profile_id, t.url, t.file_name, t.content_type, t.file_size =
9
- json
10
- t
31
+ new.tap do |file|
32
+ file.id, file.kyc_profile_id, file.url, file.file_name, file.content_type, file.file_size = json
33
+ end
11
34
  end
12
-
35
+
13
36
  def self.all
14
- Api.private(:get, "/private/kyc_files").collect{|x| from_json(x) }
37
+ Api.private(:get, '/private/kyc_files').map { |file| from_json(file) }
15
38
  end
16
39
  end
17
40
  end
18
-
@@ -1,40 +1,108 @@
1
1
  module Bitex
2
+ ##
3
+ # Documentation here!
4
+ #
2
5
  class KycProfile
6
+ # @!attribute id
7
+ # @return [Integer] This KycProfile's unique ID.
8
+ attr_accessor :id
3
9
 
4
- attr_accessor :id, :first_name, :last_name, :personal_id_number,
5
- :personal_id_issuer, :personal_id_type, :tax_id, :birth_date,
6
- :nationality, :gender, :occupation, :home_address, :work_address,
7
- :phone_numbers, :legal_entity, :politically_exposed_person,
8
- :usage_tier, :accepted_usage_tier
10
+ # @!attribute first_name
11
+ # @return [String] Name.
12
+ attr_accessor :first_name
13
+
14
+ # @!attribute last_name
15
+ # @return [String] Last Name.
16
+ attr_accessor :last_name
17
+
18
+ # @!attribute personal_id_number
19
+ # @return [String] Personal ID Number.
20
+ attr_accessor :personal_id_number
21
+
22
+ # @!attribute personal_id_issuer
23
+ # @return [String] ISO country code for the issuer of this ID.
24
+ attr_accessor :personal_id_issuer
25
+
26
+ # @!attribute personal_id_type
27
+ # @return [symbol] Type of ID. [:passport]
28
+ attr_accessor :personal_id_type
29
+
30
+ # @!attribute tax_id
31
+ # @return [Intger] Tax ID.
32
+ attr_accessor :tax_id
33
+
34
+ # @!attribute birth_date
35
+ # @return [Time] Birth date.
36
+ attr_accessor :birth_date
37
+
38
+ # @!attribute nationality
39
+ # @return [String] Nationality.
40
+ attr_accessor :nationality
41
+
42
+ # @!attribute gender
43
+ # @return [Symbol] Gender.
44
+ attr_accessor :gender
45
+
46
+ # @!attribute occupation
47
+ # @return [String]
48
+ attr_accessor :occupation
49
+
50
+ # @!attribute home_address
51
+ # @return [String] Home address.
52
+ attr_accessor :home_address
53
+
54
+ # @!attribute work_address
55
+ # @return [String] Work address.
56
+ attr_accessor :work_address
57
+
58
+ # @!attribute phone_numbers
59
+ # @return [String] Phone numbers.
60
+ attr_accessor :phone_numbers
61
+
62
+ # @!attribute legal_entity
63
+ # @return [Boolean] Is legal entity.
64
+ attr_accessor :legal_entity
65
+
66
+ # @!attribute politically_exposed_person
67
+ # @return [Boolean] Is politically exposed.
68
+ attr_accessor :politically_exposed_person
69
+
70
+ # @!attribute usage_tier
71
+ # @return [Symbol] Requested usage tier.
72
+ attr_accessor :usage_tier
73
+
74
+ # @!attribute accepted_usage_tier
75
+ # @return [Symbol] Current usage tier as accepted by our compliance officers.
76
+ attr_accessor :accepted_usage_tier
9
77
 
10
78
  # @visibility private
79
+ # rubocop:disable Metrics/AbcSize
11
80
  def self.from_json(json)
12
- new.tap do |thing|
13
- thing.id = json[0]
14
- thing.first_name = json[1]
15
- thing.last_name = json[2]
16
- thing.personal_id_number = json[3]
17
- thing.personal_id_issuer = json[4]
18
- thing.personal_id_type = json[5]
19
- thing.tax_id = json[6]
20
- thing.birth_date = json[7] ? Time.at(json[7]) : nil
21
- thing.nationality = json[8]
22
- thing.gender = json[9]
23
- thing.occupation = json[10]
24
- thing.home_address = json[11]
25
- thing.work_address = json[12]
26
- thing.phone_numbers = json[13]
27
- thing.legal_entity = json[14]
28
- thing.politically_exposed_person = json[15]
29
- thing.usage_tier = json[16]
30
- thing.accepted_usage_tier = json[17]
81
+ new.tap do |profile|
82
+ profile.id = json[0]
83
+ profile.first_name = json[1]
84
+ profile.last_name = json[2]
85
+ profile.personal_id_number = json[3]
86
+ profile.personal_id_issuer = json[4]
87
+ profile.personal_id_type = json[5].to_sym
88
+ profile.tax_id = json[6]
89
+ profile.birth_date = json[7] ? Time.at(json[7]) : nil
90
+ profile.nationality = json[8]
91
+ profile.gender = json[9].to_sym
92
+ profile.occupation = json[10]
93
+ profile.home_address = json[11]
94
+ profile.work_address = json[12]
95
+ profile.phone_numbers = json[13]
96
+ profile.legal_entity = json[14]
97
+ profile.politically_exposed_person = json[15]
98
+ profile.usage_tier = json[16].to_sym
99
+ profile.accepted_usage_tier = json[17].to_sym
31
100
  end
32
101
  end
102
+ # rubocop:enable Metrics/AbcSize
33
103
 
34
104
  def self.create!(params)
35
- params = params.dup
36
- .merge(birth_date: params[:birth_date].strftime('%Y/%m/%d'))
37
- from_json(Api.private(:post, "/private/kyc_profiles", params))
105
+ from_json(Api.private(:post, '/private/kyc_profiles', sanitize(params)))
38
106
  end
39
107
 
40
108
  def self.find(id)
@@ -42,25 +110,32 @@ module Bitex
42
110
  end
43
111
 
44
112
  def self.all
45
- Api.private(:get, "/private/kyc_profiles").collect{|x| from_json(x) }
113
+ Api.private(:get, '/private/kyc_profiles').map { |kyc| from_json(kyc) }
114
+ end
115
+
116
+ private_class_method
117
+
118
+ def self.sanitize(params)
119
+ params.merge(birth_date: params[:birth_date].strftime('%Y/%m/%d'))
46
120
  end
47
121
 
48
122
  def update!(params)
49
- params = params.dup
50
- .merge(birth_date: params[:birth_date].strftime('%Y/%m/%d'))
51
- self.class.from_json(Api.private(:put, "/private/kyc_profiles/#{id}", params))
123
+ self.class.from_json(Api.private(:put, "/private/kyc_profiles/#{id}", self.class.sanitize(params)))
52
124
  end
53
-
125
+
54
126
  def add_kyc_file!(path, content_type = nil)
55
- response = Api.private(:post, "/private/kyc_profiles/#{id}/kyc_files",
56
- {document_content_type: content_type}, {document: path})
127
+ response = Api.private(
128
+ :post,
129
+ "/private/kyc_profiles/#{id}/kyc_files",
130
+ { document_content_type: content_type },
131
+ document: path
132
+ )
133
+
57
134
  KycFile.from_json(response)
58
135
  end
59
-
136
+
60
137
  def kyc_files
61
- Api.private(:get, "/private/kyc_profiles/#{id}/kyc_files")
62
- .collect{|x| KycFile.from_json(x)}
138
+ Api.private(:get, "/private/kyc_profiles/#{id}/kyc_files").map { |kyc| KycFile.from_json(kyc) }
63
139
  end
64
140
  end
65
141
  end
66
-
@@ -2,7 +2,6 @@ module Bitex
2
2
  # Public market data for a specie, do not use directly, use
3
3
  # {BitcoinMarketData} instead.
4
4
  class MarketData
5
-
6
5
  # The species currency ticker conveniently formatted as a ruby Hash with
7
6
  # symbolized keys.
8
7
  # @see https://bitex.la/developers#ticker
@@ -12,7 +11,8 @@ module Bitex
12
11
 
13
12
  # The species order book as a Hash with two keys: bids and asks.
14
13
  # Each of them is a list of list consisting of [price, quantity]
15
- # @see https://bitex.la/developers#order_book
14
+ # @see https://bitex.la/developers#orderbook
15
+ # TODO: standarize name for order-books: orderbook | order_book
16
16
  def self.order_book
17
17
  api_get('/market/order_book').symbolize_keys
18
18
  end
@@ -23,7 +23,7 @@ module Bitex
23
23
  def self.transactions
24
24
  api_get('/market/transactions')
25
25
  end
26
-
26
+
27
27
  # Returns a list of lists with aggregated transaction data for each hour
28
28
  # from the last 24 hours.
29
29
  # @see https://bitex.la/developers#last_24_hours
@@ -1,24 +1,39 @@
1
1
  module Bitex
2
2
  # @visibility private
3
- # Both Buy and Sell are a kind of Match, they deserialize the same
4
- # and have very similar fields, although their documentation may differ.
3
+ # Both Buy and Sell are a kind of Match, they deserialize the same and have very similar fields, although their documentation
4
+ # may differ.
5
5
  class Match
6
- attr_accessor :id
7
- attr_accessor :created_at
8
- attr_accessor :specie
9
- attr_accessor :quantity
10
- attr_accessor :amount
11
- attr_accessor :fee
12
- attr_accessor :price
6
+ attr_accessor :id, :orderbook, :quantity, :amount, :fee, :price, :created_at
13
7
 
14
8
  # @visibility private
15
9
  def self.from_json(json)
16
- Api.from_json(new, json, true) do |thing|
17
- thing.quantity = BigDecimal.new(json[4].to_s)
18
- thing.amount = BigDecimal.new(json[5].to_s)
19
- thing.fee = BigDecimal.new(json[6].to_s)
20
- thing.price = BigDecimal.new(json[7].to_s)
21
- end
10
+ Api.from_json(new, json) do |thing|
11
+ thing.orderbook = orderbooks[json[3]]
12
+ thing.quantity = json[4].to_s.to_d
13
+ thing.amount = json[5].to_s.to_d
14
+ thing.fee = json[6].to_s.to_d
15
+ thing.price = json[7].to_s.to_d
16
+ end
17
+ end
18
+
19
+ private_class_method
20
+
21
+ def self.orderbooks
22
+ { 1 => :btc_usd, 5 => :btc_ars }
23
+ end
24
+
25
+ def base_currency
26
+ base_quote[0]
27
+ end
28
+
29
+ def quote_currency
30
+ base_quote[1]
31
+ end
32
+
33
+ private
34
+
35
+ def base_quote
36
+ orderbook.upcase.to_s.split('_')
22
37
  end
23
38
  end
24
39
  end
@@ -1,249 +1,17 @@
1
1
  module Bitex
2
-
3
- # Base class for Bids and Asks
4
- class OrderBase
5
- attr_accessor :id
6
- attr_accessor :created_at
7
- attr_accessor :specie
8
- attr_accessor :price
9
- attr_accessor :status
10
- attr_accessor :reason
11
- attr_accessor :issuer
12
-
13
- # Returns an array with all your active orders
14
- # of this type, and any other order of this type that was active in the
15
- # last 2 hours. Uses {Order.all} under the hood.
16
- def self.all
17
- Order.all.select{|o| o.is_a?(self) }
18
- end
19
-
20
- # Returns an array with all your active orders of this type
21
- # Uses {Order.active} under the hood.
22
- def self.active
23
- Order.active.select{|o| o.is_a?(self) }
24
- end
25
-
26
- # Find an order in your list of active orders.
27
- # Uses {Order.active} under the hood.
28
- def self.find(id)
29
- from_json(Api.private(:get, "/private#{base_path}/#{id}"))
30
- end
31
-
32
- # @visibility private
33
- def self.create!(specie, amount, price, wait=false)
34
- params = {
35
- amount: amount,
36
- price: price,
37
- specie: {btc: 1, ltc: 2}[specie]
38
- }
39
- order = from_json(Api.private(:post, "/private#{base_path}", params))
40
- retries = 0
41
- while wait && order.status == :received
42
- sleep 0.2
43
- begin
44
- order = find(order.id)
45
- rescue StandardError => e
46
- end
47
- retries += 1
48
- if retries > 5000 # Wait 15 minutes for the order to be accepted.
49
- raise StandardError.new(
50
- "Timed out waiting for #{base_path} ##{order.id}")
51
- end
52
- end
53
- return order
54
- end
55
-
56
- def cancel!
57
- path = "/private#{self.class.base_path}/#{self.id}/cancel"
58
- self.class.from_json(Api.private(:post, path), self)
59
- end
60
-
61
- # @visibility private
62
- def self.from_json(json, order = nil)
63
- status_lookup = {
64
- 1 => :received,
65
- 2 => :executing,
66
- 3 => :cancelling,
67
- 4 => :cancelled,
68
- 5 => :completed,
69
- }
70
- reason_lookup = {
71
- 0 => :not_cancelled,
72
- 1 => :not_enough_funds,
73
- 2 => :user_cancelled,
74
- 3 => :system_cancelled,
75
- }
76
- Api.from_json(order || new, json, true) do |thing|
77
- thing.price = BigDecimal.new(json[6].to_s)
78
- thing.status = status_lookup[json[7]]
79
- thing.reason = reason_lookup[json[8]]
80
- thing.issuer = json[10]
81
- end
82
- end
83
- end
84
-
85
- # A Bid is an order to buy a given specie.
86
- # @see OrderBase
87
- class Bid < OrderBase
88
- # @!attribute id
89
- # @return [Integer] This Bid's unique ID.
90
-
91
- # @!attribute created_at
92
- # @return [Time] Time when this Bid was created.
93
-
94
- # @!attribute specie
95
- # @return [Symbol] :btc or :ltc
96
-
97
- # @!attribute amount
98
- # @return [BigDecimal] Amount of USD to spend in this Bid.
99
- attr_accessor :amount
100
-
101
- # @!attribute remaining_amount
102
- # @return [BigDecimal] Amount of USD left to be spent in this Bid.
103
- attr_accessor :remaining_amount
104
-
105
- # @!attribute price
106
- # @return [BigDecimal] Maximum price to pay per unit.
107
-
108
- # @!attribute status
109
- # The status of this Bid in its lifecycle.
110
- # * :received queued to check if you have enough funds.
111
- # * :executing available in our ourderbook waiting to be matched.
112
- # * :cancelling To be cancelled as soon as our trading engine unlocks it.
113
- # * :cancelled no further executed. May have some Remaining Amount.
114
- # * :completed Fully executed, Remaining Amount should be 0.
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
-
123
- # @!attribute produced_quantity
124
- # @return [BigDecimal] Quantity of specie produced by this bid so far.
125
- attr_accessor :produced_quantity
126
-
127
- # @!attribute issuer
128
- # @return [String] The issuer of this order, helps you tell
129
- # apart orders created from the web UI and the API.
130
-
131
- # @visibility private
132
- def self.base_path
133
- '/bids'
134
- end
135
-
136
- # Create a new Bid for spending Amount USD paying no more than
137
- # price per unit.
138
- # @param specie [Symbol] :btc or :ltc, whatever you're buying.
139
- # @param amount [BigDecimal] Amount to spend buying.
140
- # @param price [BigDecimal] Maximum price to pay per unit.
141
- # @param wait [Boolean] Block the process and wait until this
142
- # bid moves out of the :received state, defaults to false.
143
- # @see https://bitex.la/developers#create-bid
144
- def self.create!(specie, amount, price, wait=false)
145
- super
146
- end
147
-
148
- # @visibility private
149
- def self.from_json(json, order = nil)
150
- super(json, order).tap do |thing|
151
- thing.amount = BigDecimal.new(json[4].to_s)
152
- thing.remaining_amount = BigDecimal.new(json[5].to_s)
153
- thing.produced_quantity = BigDecimal.new(json[9].to_s)
154
- end
155
- end
156
- end
157
-
158
- # An Ask is an order to sell a given specie.
159
- # @see OrderBase
160
- class Ask < OrderBase
161
- # @!attribute id
162
- # @return [Integer] This Ask's unique ID.
163
-
164
- # @!attribute created_at
165
- # @return [Time] Time when this Ask was created.
166
-
167
- # @!attribute specie
168
- # @return [Symbol] :btc or :ltc
169
-
170
- # @!attribute quantity
171
- # @return [BigDecimal] Quantity of specie to sell in this Ask.
172
- attr_accessor :quantity
173
-
174
- # @!attribute remaining_quantity
175
- # @return [BigDecimal] Quantity of specie left to sell in this Ask.
176
- attr_accessor :remaining_quantity
177
-
178
- # @!attribute price
179
- # @return [BigDecimal] Minimum price to charge per unit.
180
-
181
- # @!attribute status
182
- # The status of this Ask in its lifecycle.
183
- # * :received queued to check if you have enough funds.
184
- # * :executing available in our ourderbook waiting to be matched.
185
- # * :cancelling To be cancelled as soon as our trading engine unlocks it.
186
- # * :cancelled no further executed. May have some Remaining Quantity.
187
- # * :completed Fully executed, Remaining Quantity should be 0.
188
-
189
- # @!attribute reason
190
- # The cancellation reason of this Ask.
191
- # * :not_cancelled Has not been cancelled.
192
- # * :not_enough_funds Not enough funds to place this order.
193
- # * :user_cancelled Cancelled per user's request
194
- # * :system_cancelled Bitex cancelled this order, for a good reason.
195
-
196
- # @!attribute produced_amount
197
- # @return [BigDecimal] Amount of USD produced from this sale
198
- attr_accessor :produced_amount
199
-
200
- # @!attribute issuer
201
- # @return [String] The issuer of this order, helps you tell
202
- # apart orders created from the web UI and the API.
203
-
204
- # @visibility private
205
- def self.base_path
206
- '/asks'
207
- end
208
-
209
- # Create a new Ask for selling a Quantity of specie charging no less than
210
- # Price per each.
211
- # @param specie [Symbol] :btc or :ltc, whatever you're selling.
212
- # @param quantity [BigDecimal] Quantity to sell.
213
- # @param price [BigDecimal] Minimum price to charge when selling.
214
- # @param wait [Boolean] Block the process and wait until this
215
- # ask moves out of the :received state, defaults to false.
216
- # @see https://bitex.la/developers#create-ask
217
- def self.create!(specie, quantity, price, wait=false)
218
- super
219
- end
220
-
221
- # @visibility private
222
- def self.from_json(json, order = nil)
223
- super(json, order).tap do |thing|
224
- thing.quantity = BigDecimal.new(json[4].to_s)
225
- thing.remaining_quantity = BigDecimal.new(json[5].to_s)
226
- thing.produced_amount = BigDecimal.new(json[9].to_s)
227
- end
228
- end
229
- end
230
-
231
- # Convenience class for fetching heterogeneous lists with all your Bids and
232
- # Asks.
2
+ # Convenience class for fetching heterogeneous lists with all your Bids and Asks.
233
3
  class Order
234
- # @return [Array<Bitex::Bid, Bitex::Ask>] Returns an heterogeneous array
235
- # with all your active orders and any other order that was active in the
236
- # last 2 hours.
4
+ # @return [Array<Bitex::Bid, Bitex::Ask>] Returns an heterogeneous array with all your active orders and any other order that
5
+ # was active in the last 2 hours.
237
6
  # @see https://bitex.la/developers#orders
238
7
  def self.all
239
- Api.private(:GET, '/private/orders').collect{|o| Api.deserialize(o) }
8
+ Api.private(:GET, '/private/orders').map { |response| Api.deserialize(response) }
240
9
  end
241
10
 
242
- # @return [Array<Bitex::Bid, Bitex::Ask>] Returns an heterogeneous array
243
- # with all your active orders.
11
+ # @return [Array<Bitex::Bid, Bitex::Ask>] Returns an heterogeneous array with all your active orders.
244
12
  # @see https://bitex.la/developers#active-orders
245
13
  def self.active
246
- Api.private(:GET, '/private/orders/active').collect{|o| Api.deserialize(o) }
14
+ Api.private(:GET, '/private/orders/active').map { |response| Api.deserialize(response) }
247
15
  end
248
16
  end
249
17
  end