Sha256: a4c7efb31afb740671f1214bda4f06ae68b3fc042192d77adc162b805645729b

Contents?: true

Size: 1.58 KB

Versions: 12

Compression:

Stored size: 1.58 KB

Contents

module RbtcArbitrage
  module Clients
    class CoinbaseClient
      include RbtcArbitrage::Client

      # return a symbol as the name
      # of this exchange
      def exchange
        :coinbase
      end

      # Returns an array of Floats.
      # The first element is the balance in BTC;
      # The second is in USD.
      def balance
        if @options[:verbose]
          warning = "Coinbase doesn't provide a USD balance because"
          warning << " it connects to your bank account. Be careful, "
          warning << "because this will withdraw directly from your accounts"
          warning << "when you trade live."
          logger.warn warning
        end
        @balance ||= [max_float, max_float]
      end

      # Configures the client's API keys.
      def validate_env
        validate_keys :coinbase_key, :coinbase_address
      end

      # `action` is :buy or :sell
      def trade action
        interface.send("#{action}!".to_sym, @options[:volume])
      end

      # `action` is :buy or :sell
      # Returns a Numeric type.
      def price action
        method = "#{action}_price".to_sym
        @price ||= interface.send(method).to_f
      end

      # Transfers BTC to the address of a different
      # exchange.
      def transfer client
        interface.send_money client.address, @options[:volume]
      end

      def interface
        @interface ||= Coinbase::Client.new(ENV['COINBASE_KEY'])
      end

      def address
        @address ||= interface.receive_address.address
      end

      private

      def max_float
        Float::MAX
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
rbtc_arbitrage-2.2.1 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage-2.2.0 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage-2.1.2 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage-2.1.1 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage_simple-2.1.1 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage_simple-2.1.0 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage-2.1.0 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage-2.0.2 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage_simple-2.0.1 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage-2.0.1 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage-2.0.0 lib/rbtc_arbitrage/clients/coinbase_client.rb
rbtc_arbitrage-1.4.6 lib/rbtc_arbitrage/clients/coinbase_client.rb