Sha256: 3d50061d43e4e323806266ee51c3017bd3e81a3ba6ab1703660ddd28e774bc87

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

module RbtcArbitrage
  module TraderHelpers
    module Logger
      def logger
        @options[:logger]
      end

      def log_info
        lower_ex = @buy_client.exchange.to_s.capitalize
        higher_ex = @sell_client.exchange.to_s.capitalize
        logger.info "#{lower_ex}: $#{color(buyer[:price].round(2))}"
        logger.info "#{higher_ex}: $#{color(seller[:price].round(2))}"
        logger.info log_string("buying", lower_ex, @paid)
        logger.info log_string("selling", higher_ex, @received)

        log_profit
      end

      private

      def log_string action, exchange, amount
        message = "#{action} #{color @options[:volume]} "
        message << "btc at #{exchange} for $"
        message << color(amount.round(2))
      end

      def color message
        message.to_s.fg("#D5EC28").bg("#000")
      end

      def log_profit
        profit_msg = "profit: $#{color (@received - @paid).round(2)}"
        profit_msg << " (#{color(@percent.round(2))}%)"
        if cutoff = @options[:cutoff]
          profit_msg << " is #{@percent < cutoff ? 'below' : 'above'} cutoff"
          profit_msg << " of #{color(cutoff)}%."
        end
        logger.info profit_msg
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
rbtc_arbitrage-2.2.0 lib/rbtc_arbitrage/trader/logger.rb
rbtc_arbitrage-2.1.2 lib/rbtc_arbitrage/trader/logger.rb
rbtc_arbitrage-2.1.1 lib/rbtc_arbitrage/trader/logger.rb
rbtc_arbitrage_simple-2.1.1 lib/rbtc_arbitrage/trader/logger.rb
rbtc_arbitrage_simple-2.1.0 lib/rbtc_arbitrage/trader/logger.rb