Class: OKEX::Order
- Inherits:
-
Object
- Object
- OKEX::Order
- Defined in:
- lib/okex/order.rb
Constant Summary collapse
- POS_LONG =
'long'.freeze
- POS_SHORT =
'short'.freeze
Instance Method Summary collapse
-
#avg_open_price ⇒ Object
平均开仓价.
-
#closed? ⇒ Boolean
已经平仓.
- #created_at ⇒ Object
-
#est_liq_price ⇒ Object
预估强平价.
-
#initialize(params) ⇒ Order
constructor
A new instance of Order.
-
#inst_id ⇒ Object
合约名称,例如 BTC-USDT-SWAP.
-
#last_price ⇒ Object
最新成交价.
-
#leverage ⇒ Object
杠杆倍数.
- #long? ⇒ Boolean
-
#open? ⇒ Boolean
是否正在持仓.
-
#pos ⇒ Object
持仓张数.
-
#position_name ⇒ Object
开仓方向名称.
-
#position_side ⇒ Object
持仓方向.
- #short? ⇒ Boolean
-
#upl ⇒ Object
未实现收益.
Constructor Details
#initialize(params) ⇒ Order
Returns a new instance of Order.
6 7 8 |
# File 'lib/okex/order.rb', line 6 def initialize(params) @params = params end |
Instance Method Details
#avg_open_price ⇒ Object
平均开仓价
25 26 27 |
# File 'lib/okex/order.rb', line 25 def avg_open_price dig("avgPx").to_f end |
#closed? ⇒ Boolean
已经平仓
81 82 83 |
# File 'lib/okex/order.rb', line 81 def closed? pos == 0 end |
#created_at ⇒ Object
20 21 22 |
# File 'lib/okex/order.rb', line 20 def created_at Time.at(dig("cTime").to_i / 1000) end |
#est_liq_price ⇒ Object
预估强平价
30 31 32 |
# File 'lib/okex/order.rb', line 30 def est_liq_price dig("liqPx").to_f end |
#inst_id ⇒ Object
合约名称,例如 BTC-USDT-SWAP
11 12 13 |
# File 'lib/okex/order.rb', line 11 def inst_id dig("instId") end |
#last_price ⇒ Object
最新成交价
35 36 37 |
# File 'lib/okex/order.rb', line 35 def last_price dig("last").to_f end |
#leverage ⇒ Object
杠杆倍数
16 17 18 |
# File 'lib/okex/order.rb', line 16 def leverage dig("lever") end |
#long? ⇒ Boolean
47 48 49 |
# File 'lib/okex/order.rb', line 47 def long? position_side == POS_LONG end |
#open? ⇒ Boolean
是否正在持仓
76 77 78 |
# File 'lib/okex/order.rb', line 76 def open? pos > 0 end |
#pos ⇒ Object
持仓张数
71 72 73 |
# File 'lib/okex/order.rb', line 71 def pos dig("pos").to_i end |
#position_name ⇒ Object
开仓方向名称
56 57 58 59 60 61 62 63 |
# File 'lib/okex/order.rb', line 56 def position_name case position_side when POS_SHORT '空' when POS_LONG '多' end end |
#position_side ⇒ Object
持仓方向
40 41 42 43 44 45 |
# File 'lib/okex/order.rb', line 40 def position_side side = dig("posSide") if [POS_SHORT, POS_LONG].include?(side) return side end end |
#short? ⇒ Boolean
51 52 53 |
# File 'lib/okex/order.rb', line 51 def short? position_side == POS_SHORT end |
#upl ⇒ Object
未实现收益
66 67 68 |
# File 'lib/okex/order.rb', line 66 def upl dig("upl").to_f end |