Class: Bitbot::Trader::Providers::Bitstamp::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbot/trader/providers/bitstamp/http_client.rb

Overview

Bitstamp specific http client

Constant Summary collapse

HOST =
"https://www.bitstamp.net/api/"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, username, password) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes HttpClient object

Parameters:

  • connection (#post)
  • username (String)
  • password (String)


75
76
77
78
79
# File 'lib/bitbot/trader/providers/bitstamp/http_client.rb', line 75

def initialize(connection, username, password)
  @connection = connection
  @username   = username
  @password   = password
end

Instance Attribute Details

#connectionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return connection

Returns:

  • (Object)


47
48
49
# File 'lib/bitbot/trader/providers/bitstamp/http_client.rb', line 47

def connection
  @connection
end

#passwordString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API passsword

Returns:

  • (String)


63
64
65
# File 'lib/bitbot/trader/providers/bitstamp/http_client.rb', line 63

def password
  @password
end

#usernameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API username

Returns:

  • (String)


55
56
57
# File 'lib/bitbot/trader/providers/bitstamp/http_client.rb', line 55

def username
  @username
end

Class Method Details

.build(options) ⇒ HttpClient

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build a new HttpClient object

Parameters:

  • options (Hash)

Options Hash (options):

  • :username (String)
  • :password (String)

Returns:



23
24
25
26
27
28
29
# File 'lib/bitbot/trader/providers/bitstamp/http_client.rb', line 23

def self.build(options)
  username = options.fetch(:username)
  password = options.fetch(:password)

  connection = make_connection
  new(connection, username, password)
end

.make_connectionFaraday

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new faraday connection object

Returns:

  • (Faraday)


37
38
39
# File 'lib/bitbot/trader/providers/bitstamp/http_client.rb', line 37

def self.make_connection
  Faraday.new(url: HOST)
end

Instance Method Details

#post(path, options = {}) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sends post request to given path

Parameters:

  • path (String)

    e.g. “open_orders”

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

    post request parameters

Returns:

  • (Hash)


92
93
94
95
96
# File 'lib/bitbot/trader/providers/bitstamp/http_client.rb', line 92

def post(path, options = {})
  options    = options.merge(user: @username, password: @password)
  result     = @connection.post("#{path}/", options).body
  JSON.parse(result)
end