Class: Bitbot::Trader::Providers::MtGox::HttpClient

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

Overview

MtGox specific http client

Defined Under Namespace

Classes: HmacMiddleware

Constant Summary collapse

HOST =
"https://data.mtgox.com/api/2/"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, nonce_generator = Utils::NonceGenerator) ⇒ 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)
  • nonce_generator (#generate) (defaults to: Utils::NonceGenerator)

    must return a uniq number



73
74
75
76
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 73

def initialize(connection, nonce_generator = Utils::NonceGenerator)
  @connection = connection
  @nonce_generator = nonce_generator
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)


54
55
56
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 54

def connection
  @connection
end

#nonce_generatorObject (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 nonce generator

Returns:

  • (Object)


61
62
63
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 61

def nonce_generator
  @nonce_generator
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.

Builds 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/mt_gox/http_client.rb', line 23

def self.build(options)
  key = options.fetch(:key)
  secret = options.fetch(:secret)

  connection = make_connection(key, secret)
  new(connection)
end

.make_connection(key, secret) ⇒ Faraday::Connection

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

Parameters:

  • key (String)
  • secret (String)

Returns:

  • (Faraday::Connection)


40
41
42
43
44
45
46
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 40

def self.make_connection(key, secret)
  Faraday.new(url: HOST) do |faraday|
    faraday.request :url_encoded
    faraday.request :hmac, key: key, secret: secret
    faraday.adapter :net_http
  end
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. “money/orders”

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

    post request parameters

Returns:

  • (Hash)


89
90
91
92
93
# File 'lib/bitbot/trader/providers/mt_gox/http_client.rb', line 89

def post(path, options = {})
  options = options.merge(nonce: @nonce_generator.generate)
  result  = @connection.post(path, options).body
  JSON.parse(result)
end