Module: BTCTurk

Defined in:
lib/btcturk.rb

Constant Summary collapse

BASE_URL =
'https://www.btcturk.com/api/'

Class Method Summary collapse

Class Method Details

.balanceObject


29
30
31
# File 'lib/btcturk.rb', line 29

def self.balance
  get 'balance'
end

.buyObject

Raises:

  • (NotImplementedError)

45
46
47
# File 'lib/btcturk.rb', line 45

def self.buy
  raise NotImplementedError
end

.cancelObject

Raises:

  • (NotImplementedError)

41
42
43
# File 'lib/btcturk.rb', line 41

def self.cancel
  raise NotImplementedError
end

.get(action) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/btcturk.rb', line 53

def self.get(action)
  @settings = get_config

  uri = URI.parse(BASE_URL + action)
  timestamp = Time.now.to_i.to_s

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(uri.request_uri)

  request['X-PCK'] = @settings[:api_key]
  request['X-Stamp'] = timestamp
  request['X-Signature'] = get_signature(timestamp)

  response = http.request(request)
  JSON.parse(response.body)
end

.get_configObject


98
99
100
101
102
103
104
105
# File 'lib/btcturk.rb', line 98

def self.get_config
  file = "#{Dir.home}/.btcturk"
  if File.exist? file
    YAML::load_file file
  else
    set_config
  end
end

.get_signature(timestamp) ⇒ Object


76
77
78
79
80
81
# File 'lib/btcturk.rb', line 76

def self.get_signature(timestamp)
  message = @settings[:api_key] + timestamp
  private_key = Base64.decode64(@settings[:private_key]).strip
  digest = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), private_key, message)
  Base64.encode64(digest).strip
end

.orderbookObject


17
18
19
# File 'lib/btcturk.rb', line 17

def self.orderbook
  get 'orderbook'
end

.ordersObject


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

def self.orders
  get 'openOrders'
end

.postObject

Raises:

  • (NotImplementedError)

72
73
74
# File 'lib/btcturk.rb', line 72

def self.post
  raise NotImplementedError
end

.sellObject

Raises:

  • (NotImplementedError)

49
50
51
# File 'lib/btcturk.rb', line 49

def self.sell
  raise NotImplementedError
end

.set_configObject


83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/btcturk.rb', line 83

def self.set_config
  settings = {}
  printf('Please enter your API key: ')
  settings[:api_key] = gets.chomp
  printf('Please enter your Private key: ')
  settings[:private_key] = gets.chomp
  printf("(Saved under #{Dir.home}/.btcturk ...)\n\n")

  File.open("#{Dir.home}/.btcturk", 'w') do |file|
    file.write settings.to_yaml
  end

  get_config
end

.tickerObject


13
14
15
# File 'lib/btcturk.rb', line 13

def self.ticker
  get 'ticker'
end

.tradesObject


21
22
23
# File 'lib/btcturk.rb', line 21

def self.trades
  get 'trades'
end

.trades_since(id) ⇒ Object


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

def self.trades_since(id)
  get "trades?sinceid=#{id}"
end

.transactionsObject

Raises:

  • (NotImplementedError)

33
34
35
# File 'lib/btcturk.rb', line 33

def self.transactions
  raise NotImplementedError
end