Class: Bitmex::Client
- Inherits:
-
Object
- Object
- Bitmex::Client
- Defined in:
- lib/bitmex/client.rb
Overview
Main client interface for Bitmex API.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
-
#announcements(&ablock) ⇒ Array
Get site announcements.
-
#apikey(api_key = nil) ⇒ Bitmex::Apikey
Persistent API Keys for Developers.
-
#chat ⇒ Bitmex::Chat
Trollbox Data.
-
#funding(filters = {}) {|Hash| ... } ⇒ Array
Get funding history.
-
#initialize(testnet: false, api_key: nil, api_secret: nil) ⇒ Client
constructor
Create new client instance.
-
#instrument ⇒ Bitmex::Instrument
Tradeable Contracts, Indices, and History.
-
#insurance(filters = {}) {|Hash| ... } ⇒ Array
Get insurance fund history.
-
#leaderboard(ranking = 'notional') ⇒ Array
Get current leaderboard.
-
#liquidations(filters = {}) {|Hash| ... } ⇒ Array
Get liquidation orders.
-
#order(orderID: nil, clOrdID: nil) ⇒ Bitmex::Order
Get an order by id.
-
#orderbook(symbol, depth: 25) {|Hash| ... } ⇒ Array
Get current Level 2 orderbook in vertical format.
-
#orders ⇒ Bitmex::Order
Order Placement, Cancellation, Amending, and History.
-
#position(symbol) ⇒ Bitmex::Position
Get an open position.
-
#positions ⇒ Array
Summary of Open and Closed Positions.
-
#quotes ⇒ Bitmex::Quote
Best Bid/Offer Snapshots & Historical Bins.
- #rest ⇒ Object
-
#schema ⇒ Hash
Get model schemata for data objects returned by this AP.
-
#settlements {|Hash| ... } ⇒ Array
Get settlement history.
-
#stats ⇒ Bitmex::Stats
Exchange statistics.
-
#trades ⇒ Bitmex::Trade
Individual and bucketed trades.
-
#user ⇒ Bitmex::User
Account operations.
- #websocket ⇒ Object
Constructor Details
#initialize(testnet: false, api_key: nil, api_secret: nil) ⇒ Client
Create new client instance
10 11 12 13 14 |
# File 'lib/bitmex/client.rb', line 10 def initialize(testnet: false, api_key: nil, api_secret: nil) @host = testnet ? TESTNET_HOST : MAINNET_HOST @api_key = api_key @api_secret = api_secret end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/bitmex/client.rb', line 4 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
4 5 6 |
# File 'lib/bitmex/client.rb', line 4 def api_secret @api_secret end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
4 5 6 |
# File 'lib/bitmex/client.rb', line 4 def host @host end |
Instance Method Details
#announcements(&ablock) ⇒ Array
Get site announcements
18 19 20 21 22 23 24 |
# File 'lib/bitmex/client.rb', line 18 def announcements(&ablock) if block_given? websocket.listen announcement: nil, &ablock else rest.get :announcement end end |
#apikey(api_key = nil) ⇒ Bitmex::Apikey
Persistent API Keys for Developers
28 29 30 |
# File 'lib/bitmex/client.rb', line 28 def apikey(api_key = nil) Bitmex::Apikey.new rest, api_key end |
#chat ⇒ Bitmex::Chat
Trollbox Data
34 35 36 |
# File 'lib/bitmex/client.rb', line 34 def chat Bitmex::Chat.new rest, websocket end |
#funding(filters = {}) {|Hash| ... } ⇒ Array
Get funding history
48 49 50 51 52 53 54 |
# File 'lib/bitmex/client.rb', line 48 def funding(filters = {}, &ablock) if block_given? websocket.listen funding: nil, &ablock else rest.get :funding, params: filters end end |
#instrument ⇒ Bitmex::Instrument
Tradeable Contracts, Indices, and History
40 41 42 |
# File 'lib/bitmex/client.rb', line 40 def instrument Bitmex::Instrument.new rest, websocket end |
#insurance(filters = {}) {|Hash| ... } ⇒ Array
Get insurance fund history
60 61 62 63 64 65 66 |
# File 'lib/bitmex/client.rb', line 60 def insurance(filters = {}, &ablock) if block_given? websocket.listen insurance: nil, &ablock else rest.get :insurance, params: filters end end |
#leaderboard(ranking = 'notional') ⇒ Array
Get current leaderboard
71 72 73 |
# File 'lib/bitmex/client.rb', line 71 def leaderboard(ranking = 'notional') rest.get :leaderboard, params: { method: ranking } end |
#liquidations(filters = {}) {|Hash| ... } ⇒ Array
Get liquidation orders
85 86 87 88 89 90 91 |
# File 'lib/bitmex/client.rb', line 85 def liquidations(filters = {}, &ablock) if block_given? websocket.listen liquidation: filters[:symbol], &ablock else rest.get :liquidation, params: filters end end |
#order(orderID: nil, clOrdID: nil) ⇒ Bitmex::Order
Get an order by id
104 105 106 107 108 |
# File 'lib/bitmex/client.rb', line 104 def order(orderID: nil, clOrdID: nil) raise ArgumentError, 'either orderID or clOrdID is required' if orderID.nil? && clOrdID.nil? Bitmex::Order.new rest, websocket, orderID, clOrdID end |
#orderbook(symbol, depth: 25) {|Hash| ... } ⇒ Array
Get current Level 2 orderbook in vertical format
121 122 123 124 125 126 127 128 129 |
# File 'lib/bitmex/client.rb', line 121 def orderbook(symbol, depth: 25, &ablock) raise ArgumentError, 'symbol is required' unless symbol if block_given? websocket.listen orderBookL2: symbol, &ablock else rest.get 'orderbook/L2', params: { symbol: symbol, depth: depth } end end |
#orders ⇒ Bitmex::Order
Order Placement, Cancellation, Amending, and History
95 96 97 98 |
# File 'lib/bitmex/client.rb', line 95 def orders # TODO: use class method Bitmex::Order.new rest, websocket end |
#position(symbol) ⇒ Bitmex::Position
Get an open position
141 142 143 |
# File 'lib/bitmex/client.rb', line 141 def position(symbol) Bitmex::Position.new rest, websocket, symbol end |
#positions ⇒ Array
Summary of Open and Closed Positions
133 134 135 136 |
# File 'lib/bitmex/client.rb', line 133 def positions # TODO: use class method Bitmex::Position.new rest, websocket end |
#quotes ⇒ Bitmex::Quote
Best Bid/Offer Snapshots & Historical Bins
147 148 149 150 |
# File 'lib/bitmex/client.rb', line 147 def quotes # TODO: use class method Bitmex::Quote.new rest, websocket end |
#rest ⇒ Object
191 192 193 |
# File 'lib/bitmex/client.rb', line 191 def rest @rest ||= Rest.new host, api_key: api_key, api_secret: api_secret end |
#schema ⇒ Hash
Get model schemata for data objects returned by this AP
154 155 156 |
# File 'lib/bitmex/client.rb', line 154 def schema rest.get :schema end |
#settlements {|Hash| ... } ⇒ Array
Get settlement history
161 162 163 164 165 166 167 |
# File 'lib/bitmex/client.rb', line 161 def settlements(&ablock) if block_given? websocket.listen settlement: nil, &ablock else rest.get :settlement end end |
#stats ⇒ Bitmex::Stats
Exchange statistics
171 172 173 |
# File 'lib/bitmex/client.rb', line 171 def stats Bitmex::Stats.new rest end |
#trades ⇒ Bitmex::Trade
Individual and bucketed trades
177 178 179 |
# File 'lib/bitmex/client.rb', line 177 def trades Bitmex::Trade.new rest, websocket end |
#user ⇒ Bitmex::User
Account operations
183 184 185 |
# File 'lib/bitmex/client.rb', line 183 def user Bitmex::User.new rest, websocket end |