Class: OKEX::Order

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

Constant Summary collapse

POS_LONG =
'long'.freeze
POS_SHORT =
'short'.freeze

Instance Method Summary collapse

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_priceObject

平均开仓价



25
26
27
# File 'lib/okex/order.rb', line 25

def avg_open_price
  dig("avgPx").to_f
end

#closed?Boolean

已经平仓

Returns:

  • (Boolean)


81
82
83
# File 'lib/okex/order.rb', line 81

def closed?
  pos == 0
end

#created_atObject



20
21
22
# File 'lib/okex/order.rb', line 20

def created_at
  Time.at(dig("cTime").to_i / 1000)
end

#est_liq_priceObject

预估强平价



30
31
32
# File 'lib/okex/order.rb', line 30

def est_liq_price
  dig("liqPx").to_f
end

#inst_idObject

合约名称,例如 BTC-USDT-SWAP



11
12
13
# File 'lib/okex/order.rb', line 11

def inst_id
  dig("instId")
end

#last_priceObject

最新成交价



35
36
37
# File 'lib/okex/order.rb', line 35

def last_price
  dig("last").to_f
end

#leverageObject

杠杆倍数



16
17
18
# File 'lib/okex/order.rb', line 16

def leverage
  dig("lever")
end

#long?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/okex/order.rb', line 47

def long?
  position_side == POS_LONG
end

#open?Boolean

是否正在持仓

Returns:

  • (Boolean)


76
77
78
# File 'lib/okex/order.rb', line 76

def open?
  pos > 0
end

#posObject

持仓张数



71
72
73
# File 'lib/okex/order.rb', line 71

def pos
  dig("pos").to_i
end

#position_nameObject

开仓方向名称



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_sideObject

持仓方向



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

Returns:

  • (Boolean)


51
52
53
# File 'lib/okex/order.rb', line 51

def short?
  position_side == POS_SHORT
end

#uplObject

未实现收益



66
67
68
# File 'lib/okex/order.rb', line 66

def upl
  dig("upl").to_f
end