Module: BittrexRuby

Defined in:
lib/bittrex_ruby.rb,
lib/bittrex_ruby/version.rb

Overview

Gem to use Bittrex API

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
'1.0.1'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



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

def configuration
  @configuration
end

Class Method Details

.buylimit(market, quantity, rate) ⇒ Object

Market API



59
60
61
62
# File 'lib/bittrex_ruby.rb', line 59

def self.buylimit(market, quantity, rate)
  get_signed 'market', 'buylimit', market: market,
                                   quantity: quantity, rate: rate
end

.cancel(uuid) ⇒ Object



69
70
71
# File 'lib/bittrex_ruby.rb', line 69

def self.cancel(uuid)
  get_signed 'market', 'cancel', uuid: uuid
end

.create_sign(uri) ⇒ Object



134
135
136
# File 'lib/bittrex_ruby.rb', line 134

def create_sign(uri)
  OpenSSL::HMAC.hexdigest('sha512', configuration.secret, uri.url)
end

.get(api_group, action, params = {}) ⇒ Object



117
118
119
120
# File 'lib/bittrex_ruby.rb', line 117

def get(api_group, action, params = {})
  res = resource[api_group + '/' + action].get params: params.compact
  res_hash res
end

.get_signed(api_group, action, params = {}) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/bittrex_ruby.rb', line 122

def get_signed(api_group, action, params = {})
  params[:nonce] = Time.now.to_i
  params[:apikey] = configuration.key

  # Build Query parameters string
  params_query = params.compact.map { |k, v| "#{k}=#{v}" }.join('&')
  uri = resource[api_group + '/' + action + '?' + params_query]

  res = uri.get apisign: create_sign(uri)
  res_hash res
end

.getbalance(currency) ⇒ Object



82
83
84
# File 'lib/bittrex_ruby.rb', line 82

def self.getbalance(currency)
  get_signed 'account', 'getbalance', currency: currency
end

.getbalancesObject

Account API



78
79
80
# File 'lib/bittrex_ruby.rb', line 78

def self.getbalances
  get_signed 'account', 'getbalances'
end

.getcurrenciesObject



34
35
36
# File 'lib/bittrex_ruby.rb', line 34

def self.getcurrencies
  get 'public', 'getcurrencies'
end

.getdepositaddress(currency) ⇒ Object



86
87
88
# File 'lib/bittrex_ruby.rb', line 86

def self.getdepositaddress(currency)
  get_signed 'account', 'getdepositaddress', currency: currency
end

.getdeposithistory(currency = nil) ⇒ Object



108
109
110
# File 'lib/bittrex_ruby.rb', line 108

def self.getdeposithistory(currency = nil)
  get_signed 'account', 'getdeposithistory', currency: currency
end

.getmarkethistory(market) ⇒ Object



54
55
56
# File 'lib/bittrex_ruby.rb', line 54

def self.getmarkethistory(market)
  get 'public', 'getmarkethistory', market: market
end

.getmarketsObject

Public API



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

def self.getmarkets
  get 'public', 'getmarkets'
end

.getmarketsummariesObject



42
43
44
# File 'lib/bittrex_ruby.rb', line 42

def self.getmarketsummaries
  get 'public', 'getmarketsummaries'
end

.getmarketsummary(market) ⇒ Object



46
47
48
# File 'lib/bittrex_ruby.rb', line 46

def self.getmarketsummary(market)
  get 'public', 'getmarketsummary', market: market
end

.getopenorders(market = nil) ⇒ Object



73
74
75
# File 'lib/bittrex_ruby.rb', line 73

def self.getopenorders(market = nil)
  get_signed 'market', 'getopenorders', market: market
end

.getorder(uuid) ⇒ Object



96
97
98
# File 'lib/bittrex_ruby.rb', line 96

def self.getorder(uuid)
  get_signed 'account', 'getorder', uuid: uuid
end

.getorderbook(market, type) ⇒ Object



50
51
52
# File 'lib/bittrex_ruby.rb', line 50

def self.getorderbook(market, type)
  get 'public', 'getorderbook', market: market, type: type
end

.getorderhistory(market = nil) ⇒ Object



100
101
102
# File 'lib/bittrex_ruby.rb', line 100

def self.getorderhistory(market = nil)
  get_signed 'account', 'getorderhistory', market: market
end

.getticker(market) ⇒ Object



38
39
40
# File 'lib/bittrex_ruby.rb', line 38

def self.getticker(market)
  get 'public', 'getticker', market: market
end

.getwithdrawalhistory(currency = nil) ⇒ Object



104
105
106
# File 'lib/bittrex_ruby.rb', line 104

def self.getwithdrawalhistory(currency = nil)
  get_signed 'account', 'getwithdrawalhistory', currency: currency
end

.res_hash(res) ⇒ Object



138
139
140
141
142
# File 'lib/bittrex_ruby.rb', line 138

def res_hash(res)
  data = JSON.parse(res.body)
  data.extend DeepSymbolizable
  { data: data.deep_symbolize, res: res }
end

.resourceObject



113
114
115
# File 'lib/bittrex_ruby.rb', line 113

def resource
  RestClient::Resource.new('https://bittrex.com/api/v1.1/')
end

.selllimit(market, quantity, rate) ⇒ Object



64
65
66
67
# File 'lib/bittrex_ruby.rb', line 64

def self.selllimit(market, quantity, rate)
  get_signed 'market', 'selllimit', market: market,
                                    quantity: quantity, rate: rate
end

.setup {|configuration| ... } ⇒ Object

Yields:



14
15
16
17
# File 'lib/bittrex_ruby.rb', line 14

def self.setup
  @configuration ||= Configuration.new
  yield(configuration)
end

.withdraw(currency, quantity, address, paymentid = nil) ⇒ Object



90
91
92
93
94
# File 'lib/bittrex_ruby.rb', line 90

def self.withdraw(currency, quantity, address, paymentid = nil)
  get_signed 'account', 'withdraw',
             currency: currency, quantity: quantity,
             address: address, paymentid: paymentid
end