-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorder.rb
More file actions
40 lines (27 loc) · 1.8 KB
/
order.rb
File metadata and controls
40 lines (27 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module APIv2
module Entities
class Order < Base
expose :id, documentation: "Unique order id."
expose :side, documentation: "Either 'sell' or 'buy'."
expose :ord_type, documentation: "Type of order, either 'limit' or 'market'."
expose :price, documentation: "Price for each unit. e.g. If you want to sell/buy 1 btc at 3000 CNY, the price is '3000.0'"
expose :avg_price, documentation: "Average execution price, average of price in trades."
expose :state, documentation: "One of 'wait', 'done', or 'cancel'. An order in 'wait' is an active order, waiting fullfillment; a 'done' order is an order fullfilled; 'cancel' means the order has been cancelled."
expose :currency, as: :market, documentation: "The market in which the order is placed, e.g. 'btccny'. All available markets can be found at /api/v2/markets."
expose :created_at, format_with: :iso8601, documentation: "Order create time in iso8601 format."
expose :origin_volume, as: :volume, documentation: "The amount user want to sell/buy. An order could be partially executed, e.g. an order sell 5 btc can be matched with a buy 3 btc order, left 2 btc to be sold; in this case the order's volume would be '5.0', its remaining_volume would be '2.0', its executed volume is '3.0'."
expose :volume, as: :remaining_volume, documentation: "The remaining volume, see 'volume'."
expose :executed_volume, documentation: "The executed volume, see 'volume'." do |order, options|
order.origin_volume - order.volume
end
expose :trades_count
expose :trades, if: {type: :full} do |order, options|
::APIv2::Entities::Trade.represent order.trades, side: side
end
private
def side
@side ||= @object.type[-3, 3] == 'Ask' ? 'sell' : 'buy'
end
end
end
end