Class: Bitstamper::Models::Order
- Defined in:
- lib/bitstamper/models/order.rb
Constant Summary collapse
- BUY =
0- SELL =
1- MAPPING =
{ "id" => :string, "currency_pair" => :string, "type" => :integer, "price" => :float, "amount" => :float, "event" => :string }
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#currency_pair ⇒ Object
Returns the value of attribute currency_pair.
-
#datetime ⇒ Object
Returns the value of attribute datetime.
-
#error ⇒ Object
Returns the value of attribute error.
-
#event ⇒ Object
Returns the value of attribute event.
-
#id ⇒ Object
Returns the value of attribute id.
-
#message ⇒ Object
Returns the value of attribute message.
-
#order_type ⇒ Object
Returns the value of attribute order_type.
-
#price ⇒ Object
Returns the value of attribute price.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Order
constructor
A new instance of Order.
Methods inherited from Base
Constructor Details
#initialize(hash) ⇒ Order
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bitstamper/models/order.rb', line 19 def initialize(hash) hash["type"] = hash["order_type"] if hash.fetch("type", nil).to_s.empty? && hash.has_key?("order_type") hash.each do |key, value| type = ::Bitstamper::Models::Order::MAPPING.fetch(key, nil) value = value && type ? ::Bitstamper::Utilities::convert_value(value, type) : value self.send("#{key}=", value) if self.respond_to?(key) end datetime = hash.fetch("datetime", nil)&.to_s if !datetime.to_s.empty? && datetime.include?("-") self.datetime = ::Bitstamper::Utilities::convert_value(datetime, :datetime) elsif !datetime.to_s.empty? && ::Bitstamper::Utilities.numeric?(datetime) self.datetime = ::Bitstamper::Utilities::convert_value(datetime, :time) end self.order_type = case self.type when ::Bitstamper::Models::Order::BUY then :buy when ::Bitstamper::Models::Order::SELL then :sell end end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
4 5 6 |
# File 'lib/bitstamper/models/order.rb', line 4 def amount @amount end |
#currency_pair ⇒ Object
Returns the value of attribute currency_pair.
4 5 6 |
# File 'lib/bitstamper/models/order.rb', line 4 def currency_pair @currency_pair end |
#datetime ⇒ Object
Returns the value of attribute datetime.
4 5 6 |
# File 'lib/bitstamper/models/order.rb', line 4 def datetime @datetime end |
#error ⇒ Object
Returns the value of attribute error.
5 6 7 |
# File 'lib/bitstamper/models/order.rb', line 5 def error @error end |
#event ⇒ Object
Returns the value of attribute event.
5 6 7 |
# File 'lib/bitstamper/models/order.rb', line 5 def event @event end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/bitstamper/models/order.rb', line 4 def id @id end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/bitstamper/models/order.rb', line 5 def end |
#order_type ⇒ Object
Returns the value of attribute order_type.
4 5 6 |
# File 'lib/bitstamper/models/order.rb', line 4 def order_type @order_type end |
#price ⇒ Object
Returns the value of attribute price.
4 5 6 |
# File 'lib/bitstamper/models/order.rb', line 4 def price @price end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/bitstamper/models/order.rb', line 4 def type @type end |
Class Method Details
.parse(data) ⇒ Object
42 43 44 |
# File 'lib/bitstamper/models/order.rb', line 42 def self.parse(data) data&.collect { |item| ::Bitstamper::Models::Order.new(item) } end |