Module: MtGox::Value

Included in:
Ask, Bid, Client
Defined in:
lib/mtgox/value.rb

Constant Summary collapse

INT_MULTIPLIERS =

We assume here that any other currency than :jpy uses :usd

{btc: 100000000, usd: 100000, jpy: 1000}

Instance Method Summary collapse

Instance Method Details

#floatify(int, currency) ⇒ Object

Convert an int value to a float using the MtGox conversion rules.

param int [Fixnum] to convert param currency [Symbol] currency conversion rule to use amongst [:btc, :usd, :jpy] return a [Float]



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

def floatify(int, currency)
  (int.to_f / INT_MULTIPLIERS[currency])
end

#intify(float, currency) ⇒ Object

Convert a float value to an int using the MtGox conversion rules.

param float [Float] to convert param currency [Symbol] currency conversion rule to use amongst [:btc, :usd, :jpy] return an int



40
41
42
# File 'lib/mtgox/value.rb', line 40

def intify(float, currency)
  (float * INT_MULTIPLIERS[currency]).to_i
end

#value_bitcoin(value, key = 'value_int') ⇒ Float

Takes a hash return by the API and convert some value_int to [Float] BitCoin value . You can specify which key to convert

params key [String] the key from the previous hash to convert, default to 'value_int'

Parameters:

  • value (Hash)

    a hash from the API

Returns:

  • (Float)

    a float BTC value

Requires Authentication:

  • false



31
32
33
# File 'lib/mtgox/value.rb', line 31

def value_bitcoin(value, key = 'value_int')
  floatify(value[key], :btc)
end

#value_currency(value, key = 'value_int') ⇒ Float

Takes a hash return by the API and convert some value_int to a currency value using USD conversion rule. You can specify which key to convert

params key [String] the key from the previous hash to convert, default to 'value_int'

Parameters:

  • value (Hash)

    a hash from the API

Returns:

  • (Float)

Requires Authentication:

  • false



20
21
22
# File 'lib/mtgox/value.rb', line 20

def value_currency(value, key = 'value_int')
  floatify(value[key].to_i, :usd)
end