Class: Itbit::Order
- Inherits:
-
Object
- Object
- Itbit::Order
- Defined in:
- lib/itbit/order.rb
Overview
A limit buy or sell order, translated from itbit api to a more suitable ruby style. Field names are underscored. Values for side, instrument, currency, type and status are underscored and symbolized.
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#amount_filled ⇒ Object
Returns the value of attribute amount_filled.
-
#client_order_identifier ⇒ Object
Returns the value of attribute client_order_identifier.
-
#created_time ⇒ Object
Returns the value of attribute created_time.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#display_amount ⇒ Object
Returns the value of attribute display_amount.
-
#id ⇒ Object
Returns the value of attribute id.
-
#instrument ⇒ Object
Returns the value of attribute instrument.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#price ⇒ Object
Returns the value of attribute price.
-
#side ⇒ Object
Returns the value of attribute side.
-
#status ⇒ Object
Returns the value of attribute status.
-
#type ⇒ Object
Returns the value of attribute type.
-
#volume_weighted_average_price ⇒ Object
Returns the value of attribute volume_weighted_average_price.
-
#wallet_id ⇒ Object
Returns the value of attribute wallet_id.
Class Method Summary collapse
-
.all(opts = {}) ⇒ Array<Itbit::Order>
Lists all orders for a wallet.
-
.create!(side, instrument, amount, price, options = {}) ⇒ Object
Creates a new order.
-
.find(id, wallet_id = Itbit.default_wallet_id) ⇒ Object
Finds an order by id in a given wallet.
Instance Method Summary collapse
-
#cancel! ⇒ Object
Cancel this order.
-
#initialize(attrs) ⇒ Order
constructor
A new instance of Order.
Constructor Details
#initialize(attrs) ⇒ Order
Returns a new instance of Order.
12 13 14 |
# File 'lib/itbit/order.rb', line 12 def initialize(attrs) attrs.each{|k, v| send("#{k.underscore}=", v)} end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def amount @amount end |
#amount_filled ⇒ Object
Returns the value of attribute amount_filled.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def amount_filled @amount_filled end |
#client_order_identifier ⇒ Object
Returns the value of attribute client_order_identifier.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def client_order_identifier @client_order_identifier end |
#created_time ⇒ Object
Returns the value of attribute created_time.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def created_time @created_time end |
#currency ⇒ Object
Returns the value of attribute currency.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def currency @currency end |
#display_amount ⇒ Object
Returns the value of attribute display_amount.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def display_amount @display_amount end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def id @id end |
#instrument ⇒ Object
Returns the value of attribute instrument.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def instrument @instrument end |
#metadata ⇒ Object
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def @metadata end |
#price ⇒ Object
Returns the value of attribute price.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def price @price end |
#side ⇒ Object
Returns the value of attribute side.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def side @side end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def status @status end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def type @type end |
#volume_weighted_average_price ⇒ Object
Returns the value of attribute volume_weighted_average_price.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def volume_weighted_average_price @volume_weighted_average_price end |
#wallet_id ⇒ Object
Returns the value of attribute wallet_id.
7 8 9 |
# File 'lib/itbit/order.rb', line 7 def wallet_id @wallet_id end |
Class Method Details
.all(opts = {}) ⇒ Array<Itbit::Order>
Lists all orders for a wallet. Results can be filtered and paginated by passing in these options.
wallet_id: String, defaults to Itbit.default_wallet_id
instrument: Symbol, either :xbtusd, :xbteur, :xbtsgd
page: Integer, starting page for pagination.
per_page: Integer, how many to show per page.
status: Symbol, either :submitted, :open, :filled, :cancelled, :rejected
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/itbit/order.rb', line 41 def self.all(opts = {}) wallet_id = opts[:wallet_id] || Itbit.default_wallet_id params = {} params[:instrument] = opts[:instrument].upcase if opts[:instrument] params[:page] = opts[:page].to_i if opts[:page] params[:perPage] = opts[:per_page].to_i if opts[:per_page] params[:status] = opts[:status] if opts[:status] Api.request(:get, "/wallets/#{wallet_id}/orders", params) .collect{|o| Order.new(o) } end |
.create!(side, instrument, amount, price, options = {}) ⇒ Object
Creates a new order
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/itbit/order.rb', line 76 def self.create!(side, instrument, amount, price, = {}) wallet_id = [:wallet_id] || Itbit.default_wallet_id params = { side: side, instrument: instrument.to_s.upcase, amount: amount.to_d.to_s('F'), price: price.to_d.to_s('F'), type: [:type] || :limit, currency: [:currency].try(:upcase) || 'XBT' } %w(metadata client_order_identifier).each do |a| params[a.camelize(:lower)] = [a.to_sym] if [a.to_sym] end order = Order.new Api.request(:post, "/wallets/#{wallet_id}/orders", params) retries = 0 while [:wait] && order.status == :submitted sleep 0.2 order = find(order.id) retries += 1 if retries > 5000 # Wait 15 minutes for the order to be accepted. raise StandardError.new( "Timed out waiting for #{base_path} ##{order.id}") end end return order end |