Class: Bitmex::User

Inherits:
Object
  • Object
show all
Defined in:
lib/bitmex/user.rb

Overview

Account Operations

All read-only operations to load user’s data are implemented and work as described in docs. Multiple PUT/POST endpoints return ‘Access Denied’ and are not implemented. It seems that they are meant to be used internally by BitMEX only.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rest, websocket) ⇒ User

Returns a new instance of User.

Parameters:



13
14
15
16
# File 'lib/bitmex/user.rb', line 13

def initialize(rest, websocket)
  @rest = rest
  @websocket = websocket
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args, &_ablock) ⇒ Object (private)



132
133
134
135
# File 'lib/bitmex/user.rb', line 132

def method_missing(name, *_args, &_ablock)
  @data = get '' if @data.nil?
  @data.send name
end

Instance Attribute Details

#restObject (readonly)

Returns the value of attribute rest.



9
10
11
# File 'lib/bitmex/user.rb', line 9

def rest
  @rest
end

#websocketObject (readonly)

Returns the value of attribute websocket.



9
10
11
# File 'lib/bitmex/user.rb', line 9

def websocket
  @websocket
end

Instance Method Details

#affiliate_statusHash

Get your current affiliate/referral status.

Returns:

  • (Hash)

    the affiliate status



20
21
22
# File 'lib/bitmex/user.rb', line 20

def affiliate_status
  get 'affiliateStatus'
end

#check_referral_code(code) ⇒ Decimal?

Check if a referral code is valid. If the code is valid, responds with the referral code’s discount (e.g. 0.1 for 10%) and false otherwise

Parameters:

  • code (String)

    the referral code

Returns:

  • (Decimal, nil)

    the discount or nil



27
28
29
30
31
32
33
# File 'lib/bitmex/user.rb', line 27

def check_referral_code(code)
  get 'checkReferralCode', referralCode: code do |response|
    return nil if !response.success? && [404, 451].include?(response.code)

    response.to_f
  end
end

#commissionHash

Get your account’s commission status

Returns:

  • (Hash)

    the commission by each product



37
38
39
# File 'lib/bitmex/user.rb', line 37

def commission
  get 'commission'
end

#deposit_address(currency = 'XBt') ⇒ String

Get a deposit address

Parameters:

  • currency (String) (defaults to: 'XBt')

    currency symbol

Returns:

  • (String)

    the address



44
45
46
47
48
49
50
# File 'lib/bitmex/user.rb', line 44

def deposit_address(currency = 'XBt')
  get 'depositAddress', currency: currency do |response|
    raise response.body unless response.success?

    response.to_s
  end
end

#events(count: 150, startId: nil) ⇒ Array

Get your user events

Parameters:

  • count (Integer) (defaults to: 150)

    number of results to fetch

  • startId (Double) (defaults to: nil)

    cursor for pagination

Returns:

  • (Array)

    the events



97
98
99
100
# File 'lib/bitmex/user.rb', line 97

def events(count: 150, startId: nil)
  data = get '', resource: 'userEvent', count: count, startId: startId
  data.userEvents
end

#execution_history(symbol = 'XBTUSD', timestamp = Date.today) ⇒ Array

Get the execution history by day

Parameters:

  • symbol (String) (defaults to: 'XBTUSD')

    the symbol to get the history for

  • timestamp (Datetime) (defaults to: Date.today)

    the datetime to filter the history for

Returns:

  • (Array)

    the history



56
57
58
# File 'lib/bitmex/user.rb', line 56

def execution_history(symbol = 'XBTUSD', timestamp = Date.today)
  get 'executionHistory', symbol: symbol, timestamp: timestamp
end

#executions(filters = {}) {|Hash| ... } ⇒ Array

Get all raw executions for your account

Parameters:

  • filters (Hash) (defaults to: {})

    the filters to apply to mostly REST API requests with a few exceptions

Options Hash (filters):

  • :symbol (String)

    the instrument symbol, this filter works in both REST and Websocket APIs

  • :filter (String)

    generic table filter, send key/value pairs Timestamp Filters

  • :columns (String)

    array of column names to fetch; if omitted, will return all columns.

  • :count (Double) — default: 100

    number of results to fetch.

  • :start (Double)

    Starting point for results.

  • :reverse (Boolean) — default: false

    if true, will sort results newest first.

  • :startTime (Datetime, String)

    Starting date filter for results.

  • :endTime (Datetime, String)

    Ending date filter for results

Yields:

  • (Hash)

    the execution

Returns:

  • (Array)

    the raw transactions



122
123
124
125
126
127
128
# File 'lib/bitmex/user.rb', line 122

def executions(filters = {}, &ablock)
  if block_given?
    websocket.listen execution: filters[:symbol], &ablock
  else
    get '', filters.merge(resource: :execution)
  end
end

#margin(currency = 'XBt') ⇒ Hash

Get your account’s margin status

Parameters:

  • currency (String) (defaults to: 'XBt')

    the currency to filter by

Returns:

  • (Hash)

    the margin



63
64
65
# File 'lib/bitmex/user.rb', line 63

def margin(currency = 'XBt')
  get 'margin', currency: currency
end

#min_withdrawal_fee(currency = 'XBt') ⇒ Hash

Get the minimum withdrawal fee for a currency This is changed based on network conditions to ensure timely withdrawals. During network congestion, this may be high. The fee is returned in the same currency.

Parameters:

  • currency (String) (defaults to: 'XBt')

    the currency to get the fee for

Returns:

  • (Hash)

    the fee



71
72
73
# File 'lib/bitmex/user.rb', line 71

def min_withdrawal_fee(currency = 'XBt')
  get 'minWithdrawalFee', currency: currency
end

#nicknameString

Get your alias on the leaderboard

Returns:

  • (String)

    the alias on the leaderboard



104
105
106
107
# File 'lib/bitmex/user.rb', line 104

def nickname
  data = get 'name', resource: 'leaderboard'
  data.name
end

#walletHash

Get your current wallet information

Returns:

  • (Hash)

    the current wallet



77
78
79
# File 'lib/bitmex/user.rb', line 77

def wallet
  get 'wallet'
end

#wallet_historyArray

Get a history of all of your wallet transactions (deposits, withdrawals, PNL)

Returns:

  • (Array)

    the wallet history



83
84
85
# File 'lib/bitmex/user.rb', line 83

def wallet_history
  get 'walletHistory'
end

#wallet_summaryArray

Get a summary of all of your wallet transactions (deposits, withdrawals, PNL)

Returns:

  • (Array)

    the wallet summary



89
90
91
# File 'lib/bitmex/user.rb', line 89

def wallet_summary
  get 'walletSummary'
end