Class: Bitmex::Position
Overview
Summary of Open and Closed Positions
Instance Attribute Summary collapse
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Attributes inherited from Base
Instance Method Summary collapse
-
#all {|Hash| ... } ⇒ Array
Get your positions.
-
#initialize(rest, websocket, symbol = 'XBTUSD') ⇒ Position
constructor
A new instance of Position.
-
#isolate(enabled: true) ⇒ Hash
Enable isolated margin or cross margin per-position.
-
#leverage(leverage) ⇒ Hash
Choose leverage for a position.
-
#risk_limit(risk_limit) ⇒ Hash
Update your risk limit.
-
#transfer_margin(amount) ⇒ Hash
Transfer equity in or out of a position.
Constructor Details
#initialize(rest, websocket, symbol = 'XBTUSD') ⇒ Position
A new instance of Position
10 11 12 13 |
# File 'lib/bitmex/position.rb', line 10 def initialize(rest, websocket, symbol = 'XBTUSD') super rest, websocket @symbol = symbol end |
Instance Attribute Details
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
5 6 7 |
# File 'lib/bitmex/position.rb', line 5 def symbol @symbol end |
Instance Method Details
#all {|Hash| ... } ⇒ Array
Get your positions
24 25 26 27 28 29 30 |
# File 'lib/bitmex/position.rb', line 24 def all(&ablock) if block_given? websocket.listen position: nil, &ablock else rest.get position_path, auth: true end end |
#isolate(enabled: true) ⇒ Hash
Enable isolated margin or cross margin per-position
35 36 37 38 39 40 41 |
# File 'lib/bitmex/position.rb', line 35 def isolate(enabled: true) path = position_path(:isolate) params = { symbol: symbol, enabled: enabled } rest.post path, params: params do |response| response_handler response end end |
#leverage(leverage) ⇒ Hash
Choose leverage for a position
46 47 48 49 50 51 52 53 54 |
# File 'lib/bitmex/position.rb', line 46 def leverage(leverage) raise ArgumentError, "leverage #{leverage} is outside of [0..100] range" unless (0..100).include? leverage path = position_path(:leverage) params = { symbol: symbol, leverage: leverage } rest.post path, params: params do |response| response_handler response end end |
#risk_limit(risk_limit) ⇒ Hash
Update your risk limit
59 60 61 62 63 64 65 |
# File 'lib/bitmex/position.rb', line 59 def risk_limit(risk_limit) path = position_path(:riskLimit) params = { symbol: symbol, riskLimit: risk_limit } rest.post path, params: params do |response| response_handler response end end |
#transfer_margin(amount) ⇒ Hash
Transfer equity in or out of a position
72 73 74 75 76 77 78 |
# File 'lib/bitmex/position.rb', line 72 def transfer_margin(amount) path = position_path(:transferMargin) params = { symbol: symbol, amount: amount } rest.post path, params: params do |response| response_handler response end end |