class RbtcArbitrage::Clients::BitstampClient

Public Instance Methods

balance() click to toggle source
# File lib/rbtc_arbitrage/clients/bitstamp_client.rb, line 6
def balance
  return @balance if @balance
  balances = Bitstamp.balance
  @balance = [balances[0].to_f, balances[1].to_f]
end
exchange() click to toggle source
# File lib/rbtc_arbitrage/clients/bitstamp_client.rb, line 21
def exchange
  :bitstamp
end
price(action) click to toggle source
# File lib/rbtc_arbitrage/clients/bitstamp_client.rb, line 25
def price action
  return @price if @price
  action = {
    buy: :ask,
    sell: :bid,
  }[action]
  @price = Bitstamp.ticker.send(action).to_f
end
trade(action) click to toggle source
# File lib/rbtc_arbitrage/clients/bitstamp_client.rb, line 34
def trade action
  price(action) unless @price #memoize
  multiple = {
    buy: 1,
    sell: -1,
  }[action]
  bitstamp_options = {
    price: (@price + 0.001 * multiple),
    amount: @options[:volume],
  }
  Bitstamp.orders.send(action, bitstamp_options)
end
transfer(other_client) click to toggle source
# File lib/rbtc_arbitrage/clients/bitstamp_client.rb, line 47
def transfer other_client
  Bitstamp.transfer(@options[:volume], other_client.address)
end
validate_env() click to toggle source
# File lib/rbtc_arbitrage/clients/bitstamp_client.rb, line 12
def validate_env
  validate_keys :bitstamp_key, :bitstamp_client_id, :bitstamp_secret
  Bitstamp.setup do |config|
    config.client_id = ENV["BITSTAMP_CLIENT_ID"]
    config.key = ENV["BITSTAMP_KEY"]
    config.secret = ENV["BITSTAMP_SECRET"]
  end
end