Module: MtGox::Value

Included in:
Ask, Bid, Client, OrderResult
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

#decimalify(int, currency) ⇒ Object

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

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



51
52
53
# File 'lib/mtgox/value.rb', line 51

def decimalify(int, currency)
  (BigDecimal(int.to_s) / INT_MULTIPLIERS[currency])
end

#intify(decimal, currency) ⇒ Object

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

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



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

def intify(decimal, currency)
  (decimal * 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



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

def value_bitcoin(value, key = 'value_int')
  decimalify(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



22
23
24
# File 'lib/mtgox/value.rb', line 22

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