Class: Coinigy::Order

Inherits:
Model
  • Object
show all
Defined in:
lib/coinigy/order.rb

Overview

Represents an Order in an account

Constant Summary

BUY =

Order types

1.freeze
SELL =
2.freeze
LIMIT =

Price types

3.freeze
STOP_LIMIT =
6.freeze
LIMIT_MARGIN =
8.freeze
STOP_LIMIT_MARGIN =
9.freeze

Instance Attribute Summary collapse

Attributes inherited from Model

#errors

Instance Method Summary collapse

Methods inherited from Model

#errors?, #initialize, #inspect, #save

Constructor Details

This class inherits a constructor from Coinigy::Model

Instance Attribute Details

#auth_idObject

Returns the value of attribute auth_id



14
15
16
# File 'lib/coinigy/order.rb', line 14

def auth_id
  @auth_id
end

#auth_nicknameObject

Returns the value of attribute auth_nickname



14
15
16
# File 'lib/coinigy/order.rb', line 14

def auth_nickname
  @auth_nickname
end

#display_nameObject

Returns the value of attribute display_name



14
15
16
# File 'lib/coinigy/order.rb', line 14

def display_name
  @display_name
end

#exch_codeObject

Returns the value of attribute exch_code



14
15
16
# File 'lib/coinigy/order.rb', line 14

def exch_code
  @exch_code
end

#exch_idObject

Returns the value of attribute exch_id



14
15
16
# File 'lib/coinigy/order.rb', line 14

def exch_id
  @exch_id
end

#exch_nameObject

Returns the value of attribute exch_name



14
15
16
# File 'lib/coinigy/order.rb', line 14

def exch_name
  @exch_name
end

#executed_priceObject

Returns the value of attribute executed_price



14
15
16
# File 'lib/coinigy/order.rb', line 14

def executed_price
  @executed_price
end

#foreign_order_idObject

Returns the value of attribute foreign_order_id



14
15
16
# File 'lib/coinigy/order.rb', line 14

def foreign_order_id
  @foreign_order_id
end

#last_updatedObject

Returns the value of attribute last_updated



14
15
16
# File 'lib/coinigy/order.rb', line 14

def last_updated
  @last_updated
end

#limit_priceObject

Returns the value of attribute limit_price



14
15
16
# File 'lib/coinigy/order.rb', line 14

def limit_price
  @limit_price
end

#mkt_nameObject

Returns the value of attribute mkt_name



14
15
16
# File 'lib/coinigy/order.rb', line 14

def mkt_name
  @mkt_name
end

#operatorObject

Returns the value of attribute operator



14
15
16
# File 'lib/coinigy/order.rb', line 14

def operator
  @operator
end

#order_idObject

Returns the value of attribute order_id



14
15
16
# File 'lib/coinigy/order.rb', line 14

def order_id
  @order_id
end

#order_price_typeObject

Returns the value of attribute order_price_type



14
15
16
# File 'lib/coinigy/order.rb', line 14

def order_price_type
  @order_price_type
end

#order_statusObject

Returns the value of attribute order_status



14
15
16
# File 'lib/coinigy/order.rb', line 14

def order_status
  @order_status
end

#order_timeObject

Returns the value of attribute order_time



14
15
16
# File 'lib/coinigy/order.rb', line 14

def order_time
  @order_time
end

#order_typeObject

Returns the value of attribute order_type



14
15
16
# File 'lib/coinigy/order.rb', line 14

def order_type
  @order_type
end

#price_type_idObject

Returns the value of attribute price_type_id



14
15
16
# File 'lib/coinigy/order.rb', line 14

def price_type_id
  @price_type_id
end

#quantityObject

Returns the value of attribute quantity



14
15
16
# File 'lib/coinigy/order.rb', line 14

def quantity
  @quantity
end

#quantity_remainingObject

Returns the value of attribute quantity_remaining



14
15
16
# File 'lib/coinigy/order.rb', line 14

def quantity_remaining
  @quantity_remaining
end

#stop_priceObject

Returns the value of attribute stop_price



14
15
16
# File 'lib/coinigy/order.rb', line 14

def stop_price
  @stop_price
end

#subscriptionObject

Relations



26
27
28
# File 'lib/coinigy/order.rb', line 26

def subscription
  @subscription
end

#unixtimeObject

Returns the value of attribute unixtime



14
15
16
# File 'lib/coinigy/order.rb', line 14

def unixtime
  @unixtime
end

Instance Method Details

#attributesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/coinigy/order.rb', line 28

def attributes
  { 'exch_id' => exch_id,
    'exch_code' => exch_code,
    'exch_name' => exch_name,
    'mkt_name' => mkt_name,
    'limit_price' => limit_price,
    'operator' => operator,
    'order_id' => order_id,
    'order_type' => order_type,
    'order_price_type' => order_price_type,
    'order_status' => order_status,
    'quantity' => quantity,
    'order_time' => order_time,
    'foreign_order_id' => foreign_order_id,
    'auth_nickname' => auth_nickname,
    'auth_id' => auth_id,
    'quantity_remaining' => quantity_remaining,
    'stop_price' => stop_price,
    'price_type_id' => price_type_id,
    'display_name' => display_name,
    'executed_price' => executed_price,
    'last_updated' => last_updated,
    'unixtime' => unixtime }
end

#cancelObject



72
73
74
# File 'lib/coinigy/order.rb', line 72

def cancel
  subscription.client.cancel_order(order_id)
end

#placeObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/coinigy/order.rb', line 53

def place
  exchange = subscription.exchanges.find { |exchange| exchange.exch_code == exch_code }
  market = exchange.markets.find { |market| market.mkt_name == mkt_name }
  order_type_id = (order_type == 'Buy') ? BUY : SELL
  subscription.client.add_order('auth_id' => auth_id,
                                'exch_id' => exchange.exch_id,
                                'mkt_id' => market.mkt_id,
                                'order_type_id' => order_type_id,
                                'price_type_id' => price_type_id,
                                'limit_price' => limit_price,
                                'order_quantity' => quantity)
end

#replace(changes = {}) ⇒ Object



66
67
68
69
70
# File 'lib/coinigy/order.rb', line 66

def replace(changes = {})
  cancel
  assign_attributes(changes.slice(:limit_price, :quantity))
  place
end