class Fyb::Client

Client class containing all the methods needed to buy and sell btc.

Public Instance Methods

ask() click to toggle source

Returns the current ask price.

# File lib/fyb/client.rb, line 5
def ask
  BigDecimal Fyb.public.ticker.perform.parse['ask'], 2
end
balance() click to toggle source

Returns your currenct balance and the currency you have configured.

# File lib/fyb/client.rb, line 61
def balance
  wallet = Fyb.private.getaccinfo.perform.parse
  btc_label = 'btcBal'
  money_label = Fyb::Configuration.currency.to_s + 'Bal'

  btc = BigDecimal.new wallet[btc_label]
  real_money = BigDecimal.new wallet[money_label]

  { :btc => btc, Fyb::Configuration.currency => real_money }
end
bid() click to toggle source

Returns the current bid price.

# File lib/fyb/client.rb, line 10
def bid
  BigDecimal Fyb.public.ticker.perform.parse['bid'], 2
end
buy!(qty, price) click to toggle source

Creates and performs a buy order.

Returns the order.

# File lib/fyb/client.rb, line 47
def buy!(qty, price)
  order = Fyb::Order.new qty, price, :buy
  order.perform
end
order_history(limit = 10) click to toggle source

Returns your order history.

# File lib/fyb/client.rb, line 73
def order_history(limit = 10)
  plain_orders = Fyb.private.getorderhistory(limit: limit).perform.parse
  error = plain_orders['error']

  fail Exception, error unless error == 0

  plain_orders['orders'].map do |data|
    Order.new data['qty'], data['price'], data['type'] == 'B' ? :buy : :sell, data['ticket']
  end
end
orderbook() click to toggle source

Returns a couple of the last asks and bids.

# File lib/fyb/client.rb, line 15
def orderbook
  Fyb.public.orderbook.perform.parse
end
sell!(qty, price) click to toggle source

Creates and performs a sell order.

Returns the order.

# File lib/fyb/client.rb, line 55
def sell!(qty, price)
  order = Fyb::Order.new qty, price, :sell
  order.perform
end
test() click to toggle source

Returns true if the authorization key and signature was correct.

# File lib/fyb/client.rb, line 39
def test
  data = Fyb.private.test.perform.parse
  data['msg'] == 'success'
end
trades(tid = nil) click to toggle source

Returns trades.

Fyb.trades
Fyb.trades Time.now.to_i
  • tid tradeid to begin history from

# File lib/fyb/client.rb, line 25
def trades(tid = nil)
  params = { since: tid } unless tid.nil?
  params ||= {}

  plain_orders = Fyb.public.trades(params).perform.parse

  return [] if plain_orders.empty?

  plain_orders.map do |data|
    Order.new data['amount'], data['price'], :undefined, data['tid']
  end
end