Class: WavesRubyClient::Order
- Inherits:
-
Object
- Object
- WavesRubyClient::Order
- Includes:
- ActiveModel::Model
- Defined in:
- lib/waves_ruby_client/order.rb
Overview
A limit order
Constant Summary collapse
- JSON_HEADERS =
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json' }.freeze
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#buyer ⇒ Object
Returns the value of attribute buyer.
-
#confirmed ⇒ Object
Returns the value of attribute confirmed.
-
#filled ⇒ Object
filled amount.
-
#id ⇒ Object
Returns the value of attribute id.
-
#matcher ⇒ Object
Returns the value of attribute matcher.
-
#price ⇒ Object
Returns the value of attribute price.
-
#seller ⇒ Object
Returns the value of attribute seller.
-
#status ⇒ Object
Returns the value of attribute status.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.active ⇒ Object
get all orders waiting to be filled for WAVES_PUBLIC_KEY.
-
.all ⇒ Object
get all orders for WAVES_PUBLIC_KEY.
Instance Method Summary collapse
- #amount_asset ⇒ Object
-
#cancel ⇒ Object
cancel order any error is raised.
-
#delete ⇒ Object
delete order after it has been cancelled any error is raised.
-
#pending? ⇒ Boolean
order is waiting to be filled.
-
#place ⇒ Object
place order any error is raised.
- #price_asset ⇒ Object
-
#refresh_status ⇒ Object
query order status.
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
10 11 12 |
# File 'lib/waves_ruby_client/order.rb', line 10 def amount @amount end |
#buyer ⇒ Object
Returns the value of attribute buyer.
11 12 13 |
# File 'lib/waves_ruby_client/order.rb', line 11 def buyer @buyer end |
#confirmed ⇒ Object
Returns the value of attribute confirmed.
11 12 13 |
# File 'lib/waves_ruby_client/order.rb', line 11 def confirmed @confirmed end |
#filled ⇒ Object
filled amount
40 41 42 43 |
# File 'lib/waves_ruby_client/order.rb', line 40 def filled refresh_from_collection @filled end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/waves_ruby_client/order.rb', line 10 def id @id end |
#matcher ⇒ Object
Returns the value of attribute matcher.
11 12 13 |
# File 'lib/waves_ruby_client/order.rb', line 11 def matcher @matcher end |
#price ⇒ Object
Returns the value of attribute price.
10 11 12 |
# File 'lib/waves_ruby_client/order.rb', line 10 def price @price end |
#seller ⇒ Object
Returns the value of attribute seller.
11 12 13 |
# File 'lib/waves_ruby_client/order.rb', line 11 def seller @seller end |
#status ⇒ Object
Returns the value of attribute status.
10 11 12 |
# File 'lib/waves_ruby_client/order.rb', line 10 def status @status end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
10 11 12 |
# File 'lib/waves_ruby_client/order.rb', line 10 def @timestamp end |
#type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/waves_ruby_client/order.rb', line 10 def type @type end |
Class Method Details
.active ⇒ Object
get all orders waiting to be filled for WAVES_PUBLIC_KEY
30 31 32 |
# File 'lib/waves_ruby_client/order.rb', line 30 def self.active all.select { |o| o.status == 'Accepted' || o.status == 'PartiallyFilled' } end |
.all ⇒ Object
get all orders for WAVES_PUBLIC_KEY
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/waves_ruby_client/order.rb', line 15 def self.all url = ['/orderbook', WavesRubyClient::AMOUNT_ASSET.url_id, WavesRubyClient::PRICE_ASSET.url_id, 'publicKey', WavesRubyClient::WAVES_PUBLIC_KEY].join('/') data = WavesRubyClient::OrderData::UserOrders.new.data_with_signature orders = WavesRubyClient::Api.instance.call_matcher(url, :get, headers: data) orders.map do |order_hash| attributes = %i[filled price amount].map do |attribute| { attribute => order_hash[attribute.to_s].to_f / WavesRubyClient::NUMBER_MULTIPLIKATOR } end.reduce({}, :merge) new(order_hash.slice('id', 'status', 'type', 'timestamp').merge(attributes)) end end |
Instance Method Details
#amount_asset ⇒ Object
76 77 78 |
# File 'lib/waves_ruby_client/order.rb', line 76 def amount_asset WavesRubyClient::AMOUNT_ASSET end |
#cancel ⇒ Object
cancel order any error is raised
59 60 61 62 63 |
# File 'lib/waves_ruby_client/order.rb', line 59 def cancel res = remove('cancel') raise WavesRubyClient::OrderAlreadyFilled if res['message']&.match?(/Order is already Filled/) raise res.to_s unless res['status'] == 'OrderCanceled' end |
#delete ⇒ Object
delete order after it has been cancelled any error is raised
67 68 69 70 |
# File 'lib/waves_ruby_client/order.rb', line 67 def delete res = remove('delete') raise res.to_s unless res['status'] == 'OrderDeleted' end |
#pending? ⇒ Boolean
order is waiting to be filled
35 36 37 |
# File 'lib/waves_ruby_client/order.rb', line 35 def pending? status != 'Filled' && status != 'PartiallyFilled' end |
#place ⇒ Object
place order any error is raised
47 48 49 50 51 52 53 54 55 |
# File 'lib/waves_ruby_client/order.rb', line 47 def place data = WavesRubyClient::OrderData::Place.new(self).data_with_signature res = WavesRubyClient::Api.instance.call_matcher('/orderbook', :post, body: data.to_json, headers: JSON_HEADERS) raise res.to_s unless res['status'] == 'OrderAccepted' self.id = res['message']['id'] self end |
#price_asset ⇒ Object
72 73 74 |
# File 'lib/waves_ruby_client/order.rb', line 72 def price_asset WavesRubyClient::PRICE_ASSET end |
#refresh_status ⇒ Object
query order status
81 82 83 84 85 |
# File 'lib/waves_ruby_client/order.rb', line 81 def refresh_status url = "/orderbook/#{amount_asset.url_id}/#{price_asset.url_id}/#{id}" response = WavesRubyClient::Api.instance.call_matcher(url, :get) self.status = response['status'] end |